Skip to content

Lender decides the absolute block timelock#39

Closed
da-kami wants to merge 2 commits into
comit-network:masterfrom
da-kami:lender-decides-timelock
Closed

Lender decides the absolute block timelock#39
da-kami wants to merge 2 commits into
comit-network:masterfrom
da-kami:lender-decides-timelock

Conversation

@da-kami
Copy link
Copy Markdown
Member

@da-kami da-kami commented Aug 2, 2021

@da-kami da-kami requested a review from luckysori August 2, 2021 04:46
Comment thread src/loan.rs
Comment on lines +443 to +458
pub fn new(
collateral_amount: Amount,
collateral_inputs: Vec<Input>,
fee_sats_per_vbyte: Amount,
borrower_pk: PublicKey,
borrower_address: Address,
) -> Self {
Self {
collateral_amount,
collateral_inputs,
fee_sats_per_vbyte,
borrower_pk,
borrower_address,
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I think we shouldn't need to expose this to consumers of the library.

I agree with the maker being able to set the absolute timelock, rather than taking whatever they get from the borrower in the LoanRequest. But I think you shouldn't need to reconstruct this protocol message.

Looking at the matching PR on waves, you should be able to send your own application-specific message which looks like this:

WavesLoanRequest {
     baru_loan_request: LoanRequest,
     loan_term: u32, // in days
}

Then you can just take the loan request field as is and you don't need to implement From which requires exposing a constructor for this struct.

Copy link
Copy Markdown
Member Author

@da-kami da-kami Aug 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberately wanted to avoid re-using baru's loan request when communicating with Bobtimus. I think the LoanRequest is an implementation detail within Bobtimus - you could change baru, but that would not necessarily have to change Bobtimus' interface. With using the LoanRequest in Bobtimus' interface we have very tight coupling. Is that on purpose?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long-run, I think this state machine of Borrower0 etc should likely be removed from this library. Instead, baru should concern itself with making it easy to create transactions given the appropriate parameters. How those parameters have been created is not really a concern. Once baru provides a wallet, these APIs should get a lot simpler and the state machine can nicely move to the extension.

Instead of making constructors for these types, we could remove them from baru and change all the APIs to just take the data that was contained within these types. That would give the extension the necessary control over the wire messages sent.

API evolution tip (may not be worth it for such a small change): To make the upgrade smoother, instead of just removing APIs like Borrower0::loan_request, mark them as #[deprecated] and add new APIs that should be used instead.

For Borrower0::interpret, you can add a new API that takes all the values directly and have the old, deprecated API forward to the new one. Would need to find a new name because Rust doesn't support fn overloading but that shouldn't be too difficult.

Copy link
Copy Markdown
Collaborator

@luckysori luckysori Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberately wanted to avoid re-using baru's loan request when communicating with Bobtimus. I think the LoanRequest is an implementation detail within Bobtimus - you could change baru, but that would not necessarily have to change Bobtimus' interface. With using the LoanRequest in Bobtimus' interface we have very tight coupling.

I think that makes sense, @da-kami. Although in this instance I would have just treated the protocol message LoanRequest as a black box. That way if baru changes its format you wouldn't have to do anything. You can still have control over the message that you send between your applications, but LoanRequest would be opaque.

Instead of making constructors for these types, we could remove them from baru and change all the APIs to just take the data that was contained within these types. That would give the extension the necessary control over the wire messages sent.

I prefer @thomaseizinger's solution over the constructor because introducing the constructor makes the library confusing to use: when are you even supposed to construct the LoanRequest?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to go for a solution that offers a different / better API.
The only important thing for me is, that Bobtimus' communication and Waves' (as in the web application) communication with baru may want to be more loosely coupled.

@luckysori as an in-between solution we could also go with the solution you proposed.
Is it OK if I hand over this problem to you guys and you come up with a better solution? Happy to adhere to that later.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckysori as an in-between solution we could also go with the solution you proposed.
Is it OK if I hand over this problem to you guys and you come up with a better solution? Happy to adhere to that later.

Absolutely.

da-kami added 2 commits August 3, 2021 11:50
Given that we can have multiple txins the loan contract might not always be at index position 1.
Since we push the loan contract txin into the vec as last element we can be sure it is the last element in the vec when we satisfy the loan repayment.
@da-kami da-kami force-pushed the lender-decides-timelock branch from 782ac49 to 9bb512a Compare August 3, 2021 01:51
@da-kami
Copy link
Copy Markdown
Member Author

da-kami commented Aug 3, 2021

Note: rebased on top of #42

@luckysori
Copy link
Copy Markdown
Collaborator

Superseded by #46 (couldn't push to this one D:)

@luckysori luckysori closed this Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants