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

feat: add bitcoin transaction fee validation #582

Merged
merged 20 commits into from
Oct 2, 2024

Conversation

djordon
Copy link
Contributor

@djordon djordon commented Sep 30, 2024

Description

Closes #552.

Changes

  • Use from instead of as _ casts for integers more
  • Use the crate ScriptPubKey in EncryptedDkgShares
  • Update the test config bitcoin-core endpoint to use the regtest username and password.
  • Add a new function to the DbRead trait for checking whether a script pub key is related to the signers
  • Update the function signature on BitcoinTxInfo. Also update a BitcoinTxInfo's subfield and comment
  • Fix lurking bugs in two queries.
  • Update stacks validation functions to use bitcoin-core for fetching fee information. Also, check that the sweep transaction was created by the signers.
  • Add test helper struct for setting up sweep transactions and making them (hopefully) easier to understand.

Testing Information

This PR updates the integration tests in validation to be a little easier to understand. The downsides to these tests is that the blockchain in the database does not contain forks by default. Nonetheless, the increase in clarity should more than make up for that fact.

Checklist:

  • I have performed a self-review of my code

@djordon djordon added the sbtc bootstrap signer The sBTC Bootstrap Signer. label Sep 30, 2024
@djordon djordon added this to the sBTC MVP Code Complete milestone Sep 30, 2024
Comment on lines +99 to +102
// Normal: we take the deposit transaction as is from the test setup
// and store it in the database. This is necessary for when we fetch
// outstanding unfulfilled deposit requests.
setup.store_deposit_tx(&db).await;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment, I do not think that this step is actually necessary since we get the deposit transaction from bitcoin-core. I discovered this along the way and just decided to keep it in, but I don't mind removing it.

Copy link
Member

@cylewitruk cylewitruk Oct 2, 2024

Choose a reason for hiding this comment

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

I think this hangs a little together with @matteojug's Q regarding using multiple data-sources for the same (types of) information.

signer/src/testing/wallet.rs Outdated Show resolved Hide resolved
signer/tests/integration/complete_deposit.rs Outdated Show resolved Hide resolved
signer/tests/integration/complete_deposit.rs Outdated Show resolved Hide resolved
signer/tests/integration/complete_deposit.rs Outdated Show resolved Hide resolved
signer/tests/integration/setup.rs Outdated Show resolved Hide resolved
signer/tests/integration/setup.rs Show resolved Hide resolved
signer/tests/integration/withdrawal_accept.rs Outdated Show resolved Hide resolved
signer/tests/integration/withdrawal_accept.rs Outdated Show resolved Hide resolved
signer/tests/integration/complete_deposit.rs Outdated Show resolved Hide resolved
signer/src/stacks/contracts.rs Show resolved Hide resolved
Comment on lines +394 to +399
// First we check that bitcoin-core has a record of the transaction
// where we think it should be.
let txid = &self.sweep_txid;
let Some(sweep_tx) = rpc.get_tx_info(txid, &self.sweep_block_hash).await? else {
return Err(DepositErrorMsg::SweepTransactionMissing.into_error(req_ctx, self));
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

qq: here we rely on bitcoin-core, while usually(?) we seem to take our storage as source of truth; mixing the two could cause some not-so-fun-to-track coherence issues, so why are we not trusting our storage here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we usually only reach out to the database for this information. Here I used bitcoin-core because I felt that it was much easier than using the database. Specifically, I had thought that I would need to write and test a few more queries before we could get the information that we need. But, I probably miscalculated and maybe we just need one more query.

And I'm not so worried about coherence issues (well, at least not yet). Here the RPC might succeed while the equivalent queries might fail because we haven't processed the bitcoin block yet (but I'm not worried about that either). However, I am worried about bitcoin-core not computing the "UndoData" that is necessary for the RPC to actually work as intended. So when we have time we should fix this up to use the database.

signer/src/stacks/contracts.rs Show resolved Hide resolved
@djordon djordon merged commit 8f35f57 into main Oct 2, 2024
4 checks passed
@djordon djordon deleted the 552-add-bitcoin-transaction-fee-validation branch October 2, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sbtc bootstrap signer The sBTC Bootstrap Signer.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Feature]: Add bitcoin transaction fee validation
3 participants