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

Calculate cooperative tx sizes #89

Merged
merged 3 commits into from
Feb 7, 2025

Conversation

dangeross
Copy link
Contributor

@dangeross dangeross commented Feb 4, 2025

Now that the claim and refund txs are created with stubbed witness data, we should be able to calculate the cooperative tx size without performing a cooperate sign

Also fixes the stubbed witness data

@dangeross dangeross force-pushed the savage-coop-size-calc branch from c078f59 to cc2762f Compare February 4, 2025 17:04
pub fn size(
&self,
keys: &Keypair,
preimage: Option<&Preimage>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The preimage is always 32 bytes. Imho there is no need to actually pass the real value

Comment on lines 1214 to 1215
preimage: Option<&Preimage>,
is_cooperative: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should either be two booleans, is_claim and is_cooperative or an enum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we need an is_claim? We can stub the preimage only if its a SwapTxKind::Claim

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right, we can get that info from self

/// Use this before calling drain to help calculate the absolute fees.
/// Multiply the size by the fee_rate to get the absolute fees.
pub fn size(
&self,
keys: &Keypair,
preimage: &Preimage,
preimage: Option<&Preimage>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing here

@@ -1205,16 +1205,17 @@ impl BtcSwapTx {
}

/// Calculate the size of a transaction.
/// The `preimage` is only required when calculating the claim tx size.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You removed the preimage parameter

@@ -1262,26 +1262,22 @@ impl LBtcSwapTx {
}

/// Calculate the size of a transaction.
/// The `preimage` is only required when calculating the claim tx size.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

tests/regtest.rs Outdated
prepare_btc_claim();

let coop_claim_tx_size = swap_tx.size(&recvr_keypair, true).unwrap();
assert_eq!(coop_claim_tx_size, 84);
Copy link
Collaborator

Choose a reason for hiding this comment

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

84 bytes for a cooperative claim transaction? That does not look right. Could you double check that? Are you adding an output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out the witness stub was incorrect 8710a0a

@@ -1200,21 +1200,21 @@ impl BtcSwapTx {
let mut witness = Witness::new();
// Stub because we don't want to create cooperative signatures here
// but still be able to have an accurate size estimation
witness.push([0, 64]);
witness.push([0; 64]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

@michael1011 michael1011 merged commit 12c9e54 into SatoshiPortal:trunk Feb 7, 2025
4 checks passed
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