-
Notifications
You must be signed in to change notification settings - Fork 20
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
Calculate cooperative tx sizes #89
Conversation
c078f59
to
cc2762f
Compare
src/swaps/bitcoin.rs
Outdated
pub fn size( | ||
&self, | ||
keys: &Keypair, | ||
preimage: Option<&Preimage>, |
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.
The preimage is always 32 bytes. Imho there is no need to actually pass the real value
src/swaps/bitcoin.rs
Outdated
preimage: Option<&Preimage>, | ||
is_cooperative: bool, |
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 either be two booleans, is_claim
and is_cooperative
or an enum
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.
Why do we need an is_claim
? We can stub the preimage only if its a SwapTxKind::Claim
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.
You are right, we can get that info from self
src/swaps/liquid.rs
Outdated
/// 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>, |
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.
Same thing here
src/swaps/bitcoin.rs
Outdated
@@ -1205,16 +1205,17 @@ impl BtcSwapTx { | |||
} | |||
|
|||
/// Calculate the size of a transaction. | |||
/// The `preimage` is only required when calculating the claim tx size. |
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.
You removed the preimage parameter
src/swaps/liquid.rs
Outdated
@@ -1262,26 +1262,22 @@ impl LBtcSwapTx { | |||
} | |||
|
|||
/// Calculate the size of a transaction. | |||
/// The `preimage` is only required when calculating the claim tx size. |
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.
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); |
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.
84 bytes for a cooperative claim transaction? That does not look right. Could you double check that? Are you adding an output?
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.
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]); |
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 catch!
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