Blockstream / gdk

Blockstream Green Development Kit
Other
159 stars 58 forks source link

size calculation is wrong for large transactions #210

Open jackstar12 opened 4 days ago

jackstar12 commented 4 days ago

The internal size calculation seems to be off for large transactions. https://liquid.network/tx/06be290faffd9e56b12bea7729d979d21e60351cccb4acc76a099614a607fcc1 This transaction was created with a fee rate of 102 sat/kvbyte, but resulted in an actual rate of 100 sat/kvbyte. I manually checked that https://github.com/Blockstream/gdk/blob/master/src/ga_tx.cpp#L1171 is right, since: (61760+3)/4 = 15440,75 So the problem should be somewhere inside https://github.com/Blockstream/gdk/blob/master/src/ga_tx.cpp#L1099

jgriffiths commented 3 days ago

Hi @jackstar12

Can you confirm the following please?:

On initial tx creation, the size estimation typically overestimates the tx size compared to the final size by 1-2 vbytes per expected signature per input, (depending on the signer). This is because some signatures will end up 1-2 vbytes smaller as a quirk of the DER encoding for ECDSA sigs. The expected result of this is that the actual fee rate will be slightly higher than the desired fee rate in some cases. This is reflected in the calculated_fee_rate (actual) vs fee_rate (desired) fields of the JSON returned by GA_create_transaction. Once the tx is signed these values will be updated to the actual value of the final signed tx.

If calculated_fee_rate is lower than fee_rate after calling GA_create_transaction then I can confirm that is a bug, meaning gdk has underestimated the size rather than overestimating it. If you can reproduce this behaviour it should be easy to determine the cause if you can send me the full resulting transaction JSON. I've asked one of our team to reach out to you with my contact details so you can pass that to me privately.

jackstar12 commented 3 days ago
  • The version of gdk that you used

0.73.2

  • How the transaction was created (e.g. GA_create_transaction/GA_create_redeposit_transaction)

GA_create_transaction

  • Whether or not a hardware wallet/external signer was used vs the default software wallet

Default software wallet, singlesig

If you can reproduce this behaviour it should be easy to determine the cause if you can send me the full resulting transaction JSON.

Havent been able to reproduce it locally yet. The issue has only occured on mainnet so far

jgriffiths commented 2 days ago

Hi @jackstar12

We have reproduced this and are working on a fix now.

jgriffiths commented 15 hours ago

Hi @jackstar12 this issue is fixed in https://github.com/Blockstream/gdk/pull/211 which will be released shortly as v0.73.3.

Thanks for reporting!