breez / breez-sdk-greenlight

MIT License
244 stars 43 forks source link

Fix reverse swap claim tx fee estimation #1055

Closed ok300 closed 3 months ago

ok300 commented 4 months ago

When estimating the claim tx fee for reverse swaps (send onchain), we used a dummy tx with a simple input and a simple output. This was a non-segwit tx with a size of 60 Bytes.

However, this tx structure is simpler than the actual claim tx, which is a segwit tx where the input has a witness with 3 elements: a signature, the preimage and the redeem script. A claim tx has approx. 310 Bytes / 148 vBytes. The actual size varies within a few bytes, depending on the output type and on signature size fluctuations (+/-1 Byte).

This PR extracts the low-level creation of the claim tx in it's own build_claim_tx_inner, which it then re-uses

This way, the claim tx fee estimation is based on a realistic tx.

The PR is split in 2 commits, for easier review: extracting the low-level build_claim_tx_inner and adding build_fake_claim_tx on top.

Fixes #1054