-
Notifications
You must be signed in to change notification settings - Fork 9
refactor: use bosd::Descriptor for operator reimbursement
#286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
b917e06 to
45d8c64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, but I do have a couple of comments:
- We (in the bridge) prefer commits to be atomic. Right now, this PR changes 28 files with a single commit which makes it very difficult to review (since there is no line of reasoning to follow which would be provided by a proper commit history).
- The
typeof theoperator_pubkeyfield has been changed tobosd::Descriptorbut the field name and the associated API docs have not been changed. It's fine if you plan to do this in later commits. If that is the case, you can set this PR to draft and still request for early feedback. - The ticket is specifically about changing the payout transactions . So I'd have expected to see changes only in those transactions (namely,
payoutandpayout_optimistic). I think the reason it affects so many files is because this PR makes the CPFP connector's address generation function fallible. This is not bad per se but I would like you to think about why converting a descriptor to an address would fail and how would the caller handle that error, and so if it is reasonable to even propagate that error from the connector to the transactions to whichever crate is using those transactions.
In particular, all changes in my commit are required for the code to compile. Setting an upper limit on no. of files changed (I don't see any such limit in our definition of atomic commits) is in this case a contradiction to the second point above. Let me know how you exactly want me to split the commit, and still make it compile, and I will gladly do it!
A |
Rajil1213
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, all changes in my commit are required for the code to compile. Setting an upper limit on no. of files changed (I don't see any such limit in our definition of atomic commits) is in this case a contradiction to the second point above. Let me know how you exactly want me to split the commit, and still make it compile, and I will gladly do it!
You're right in that atomic commits are not defined by the number of files changed but there is more than one way to make the code compile while making sure that commits are small enough to make reviews easier. For example, you could start by changing the XOnlyPublicKey to bosd::Descriptor and yet, not change the .public_key() API on the CpfpConnector (you could .expect() it and eat up any errors). You can then reason about whether it makes sense to propagate the error to the caller and decide to include any such changes in the next commit. Then, you could have a separate commit for any documentation changes (then, any review comments on the documentation can be amended onto this comment). I do not want to be too prescriptive here but this is how I'd go about splitting commits.
Which documentation needs to change? AFAIU, the doc comment is still correct. The type has changed, but this is just a refactor, there is no real change in functionality.
There is a change in functionality. This is a strictly more useful API than the previous one. In fact, now that I think about it, this PR might need to be redone. As far as I can see, the API accepts a descriptor but ultimately converts it to a P2TR address. The purpose of using descriptors is to allow for any address type (not just P2TR/taproot addresses). For the payout transactions, this can technically also be an OP_RETURN.
...if the configuration is incorrect, and the user passed a different type of descriptor, operations on the descriptor can fail. Of course, we can do this validation early, and then unwrap later. The end result is that we replaced a more precise type (XOnlyPublicKey) with a less precise type (bosd::Descriptor) and switched from compile-time guarantees to runtime checking. Would you prefer me to do it that way?
Yes. This is a fairly low level implementation detail and the current API expects a developer to trace their way all the way from the top of the stack to the very bottom where the descriptor to public key conversion would fail. You might not even need this conversion because as far as I can tell, the only reason we are getting this error is because we are going from Descriptor to public key to taproot address whereas we should just go directly to the address instead of enforcing the use of taproot address's (as mentioned in the earlier comment).
I've done a second pass of this PR to point out some of the things I mentioned in the earlier review. I haven't gone through all the changes though so use your discretion on the rest of the changes as well.
The biggest blocker for this PR though is the change required to go from P2TR addresses to just descriptors.
45d8c64 to
aa4fb56
Compare
aa4fb56 to
16f79ec
Compare
|
Thanks for your review @Rajil1213! I largely re-did the PR, leaving a single commit right now, without error handling. Error handling will be added in a follow-up commit like you suggested. The number of changed files is pretty big, but most of it is renames, |
storopoli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 16f79ec
Agree with @Rajil1213's comments on atomicity and have commits being very specific.
Rajil1213
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're making a lot of progress here but I've left a few comments on the ergonomics of some of the changes and on some matters of hygiene.
16f79ec to
3f2e909
Compare
|
Thanks for your review @Rajil1213! I have addressed your comments. To avoid redundant work, I have still not implemented error handling. Let me know if the |
Rajil1213
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some final set of changes and I think, we should be good to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this regression still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can probably ignore the regressions in git, right? b19eab6
| let starting_tx_outs = create_tx_outs([ | ||
| ( | ||
| connector.generate_address().script_pubkey(), | ||
| connector.generate_locking_script(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Now, try commenting out the generate_address() method and see if there is anywhere in the codebase where this is used directly. If it isn't used anywhere, then we can remove descriptor_address from the ConnectorCpfp struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't really remove descriptor_address because generate_locking_script uses it. But we can actually remove the generate_address fn: 2978fa9
bin/alpen-bridge/src/rpc_server.rs
Outdated
| stake_hash: graph_input.stake_hash, | ||
| operator_descriptor: graph_input.operator_descriptor.clone(), | ||
| // TODO: (@sistemd) Return error instead of unwrapping in next commit | ||
| operator_pubkey: descriptor_to_x_only_pubkey(&graph_input.operator_descriptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should stay as descriptor. This struct holds all the information required to generate the transaction graph. Ultimately, this feeds into the graph API (aka the generate_graph function in the tx-graph crate). That API expects a descriptor (I think).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0d492b6 to
105a45f
Compare
|
Thanks for the review! Here's the error handling commit: 105a45f. |
Description
Change the operator reimbursement address type to
bosd::Descriptor. Because some of the descriptor operations are fallible, there is a new error that has to be propagated throughout some parts of the call stack.Type of Change
Checklist
Related Issues
Closes STR-1150.