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: more efficient bitcoin transaction packages #1181

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

djordon
Copy link
Contributor

@djordon djordon commented Jan 2, 2025

Description

Closes #1151 and closes #1047.

Changes

  • Ensure that the number of deposit inputs into each transaction is capped.
  • Implement an "optimal" packaging algorithm. This new algorithm doesn't make the conservative assumptions as the current algorithm, leading to more "compact" transactions.

Testing Information

Added new unit tests for the new packager.

Checklist:

  • I have performed a self-review of my code

@djordon djordon added sbtc signer binary The sBTC Bootstrap Signer. utxo consolidation Tickets related to how we consolidate deposit and withdrawal BTC transactions labels Jan 2, 2025
@djordon djordon added this to the sBTC: Key rotation milestone Jan 2, 2025
@djordon djordon requested a review from Jiloc January 2, 2025 03:26
@djordon djordon self-assigned this Jan 2, 2025
signer/src/bitcoin/packaging.rs Outdated Show resolved Hide resolved
signer/src/bitcoin/packaging.rs Outdated Show resolved Hide resolved
signer/src/bitcoin/packaging.rs Show resolved Hide resolved
let above_limits = item_votes.count_ones() > self.max_votes_against
|| self.total_vsize.saturating_add(item_vsize) > self.max_vsize;

if above_limits {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we add to the fn docstring that the item may not be inserted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 1bd451a.

Copy link
Collaborator

Choose a reason for hiding this comment

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

mmm without having context the If no bag can fit the item then it is not added to any bag and is dropped may seem contradicting the preceding Creates a new one if no bag exists that can fit the item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦🏽

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in af48259

signer/src/bitcoin/packaging.rs Show resolved Hide resolved
signer/src/bitcoin/packaging.rs Outdated Show resolved Hide resolved
};

let transactions = requests.construct_transactions().unwrap();
assert_eq!(transactions.len(), 25);
assert_eq!(transactions.len(), 15);
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIUC this test was to check that we don't create a chain of more than MAX_TX_PER_BITCOIN_BLOCK txs, if so we should probably change the votes in deposits and withdrawals to force creating singleton transactions (eg, adding a | 0b111 and incrementing both shifts by 3).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, I thought that it was to check that the vsize was capped by MEMPOOL_MAX_PACKAGE_SIZE, but maybe it's both? Yeah, let's check both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh whoops, it's supposed to check that MAX_TX_PER_BITCOIN_BLOCK is capped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 22eb346.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: the comment we should generate 60 distinct transactions is no longer true, given SbtcRequests allow for up to 4 votes against it should generate only ~30 transactions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4641ddc

signer/src/config/mod.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sbtc signer binary The sBTC Bootstrap Signer. utxo consolidation Tickets related to how we consolidate deposit and withdrawal BTC transactions
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

[Bug]: Bitcoin transactions can be too large [Feature]: Add a smarter request packager
2 participants