Skip to content
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

Merging in update_spend_tx. #391

Merged
merged 1 commit into from
May 27, 2022
Merged

Conversation

Zshan0
Copy link
Collaborator

@Zshan0 Zshan0 commented Apr 27, 2022

Currently, update_spend_tx over-writes the partial signatures that are present in the database with the signatures of the given spend_tx. To avoid this, the suggested change in #312 was to merge the older and the newer signatures together and save it in the database.

The corresponding test and the API documentation have been updated with the same

@Zshan0
Copy link
Collaborator Author

Zshan0 commented Apr 27, 2022

Hey, I noticed that I am still passing spend_tx to db_update_spend, but it must be unwrapped_tx. I was unable to find a db_update_spend version that takes DbSpendTransaction. Should I make one?

@darosior
Copy link
Member

You could use the psbt member of old_tx if that's a DbSpendTransaction:

/// A row in the "spend_transactions" table
#[derive(Debug, PartialEq)]
pub struct DbSpendTransaction {
pub id: i64,
pub psbt: SpendTransaction,
pub broadcasted: Option<bool>,
pub has_priority: bool,
// txid is intentionally not there as it's already part of the psbt
}

@Zshan0 Zshan0 marked this pull request as ready for review May 9, 2022 18:50
Copy link
Member

@darosior darosior left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request. Since you are a new contributor, i'm very nit-picky and trying to comment on every small thing i notice. Don't worry, i won't do that every time and especially not for larger PRs but i think it's useful to increase communication a bit at first when someone joins the project. :-)

First a meta comment. A PR description like "as mentioned in issue #XXX" adds another indirection for an observer (which might well be us in 6 months) to get the context for a changeset. It's better to give a short (or not) summary of the rationale for this patch in the PR description. For instance here: "the current behaviour of updatespendtx would replace existing signatures if they are not present in the given Spend transaction. Instead of discarding signatures that are in database but not in the given transaction, merge the two PSBTs to keep all signatures in database.". Another motive for this is that we consider Github as transient, and the PR description is included in the git merge commit.
The same goes for commit messages. For a small PR like this one it's fine as it would be redundant to have it twice in the commit message and the PR description. But better for the rationale to be redundant than absent.

Now, on the patch. The approach is good. And i think the code is right. I've left a few things that should be addressed but it goes in the right direction.
However, a new feature should always come with a test that exercises it. Here, a new functional test_updatespendtx_merge test would be appropriate.
You should also update the API documentation in doc/API.md since it is a description of what the user should expect from this command. Just a small line saying signatures would be merged is enough.

src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/mod.rs Show resolved Hide resolved
src/commands/mod.rs Outdated Show resolved Hide resolved
@Zshan0
Copy link
Collaborator Author

Zshan0 commented May 17, 2022

To test if the merge is happening I have planned the following steps:

  1. Create the same transaction spend_tx as created in test_spendtx_management
  2. Push it to the database the first time using man.rpc.updatespendtx(spend_tx)
  3. Obtain the corresponding psbt by deserializing spend_tx
  4. Remove a signature from the only input of spend_tx, i.e. psbt.tx.vin[0]
  5. Serialize it and call updatespendtx on new_spend_tx
  6. Fetch it from the backend and assert if the transaction still has all the signatures

I'm kind of stuck on step 4 since I'm not sure how I can access the signatures from a CTxIn object, is there a simple way to do so?

@darosior
Copy link
Member

darosior commented May 17, 2022 via email

@Zshan0 Zshan0 force-pushed the merge_updatespendtx branch 3 times, most recently from 05ad2d1 to 3c3fc4c Compare May 18, 2022 07:51
@Zshan0 Zshan0 closed this May 18, 2022
Along with doc change & the required test.
@Zshan0 Zshan0 reopened this May 18, 2022
Copy link
Member

@darosior darosior left a comment

Choose a reason for hiding this comment

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

Nice.

ACK 0e80faf

@@ -190,6 +194,7 @@ impl CommandError {
CommandError::Bitcoind(_) => ErrorCode::BITCOIND_ERROR,
CommandError::Tx(_) => ErrorCode::INTERNAL_ERROR,
CommandError::SpendFeerateTooLow(_, _) => ErrorCode::INVALID_PARAMS,
CommandError::SpendSignaturesUpdate(_) => ErrorCode::INVALID_PARAMS,
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can use this syntax to avoid repetition:

CommandError::SpendFeerateTooLow(_, _) | CommandError::SpendSignaturesUpdate(_) => ErrorCode::INVALID_PARAMS,

Note: "nit" review comment are "Not Important Things". We use them to convey or discuss something, without it being an explicit request to the PR author to address it. In other words: feel free to address, or not.

revault_network.deploy(
n_stakeholders=2, n_managers=3, managers_threshold=3, csv=CSV
)
managers = [revault_network.man(i) for i in range(3)]
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can just use the mans method :)

def mans(self):
return self.stkman_wallets + self.man_wallets
def stks(self):
return self.stkman_wallets + self.stk_wallets
def participants(self):
return self.stkman_wallets + self.stk_wallets + self.man_wallets
def man(self, n):
"""Get the {n}th manager (including the stakeholder-managers first)"""
mans = self.stkman_wallets + self.man_wallets
return mans[n]

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.

2 participants