Skip to content

bitcoin-wallet: Consider unconfirmed parent fees during PSBT fee estimation#977

Open
xn1xn1 wants to merge 4 commits intoeigenwallet:masterfrom
xn1xn1:master
Open

bitcoin-wallet: Consider unconfirmed parent fees during PSBT fee estimation#977
xn1xn1 wants to merge 4 commits intoeigenwallet:masterfrom
xn1xn1:master

Conversation

@xn1xn1
Copy link
Copy Markdown

@xn1xn1 xn1xn1 commented May 3, 2026

Closes #456.

@binarybaron
Copy link
Copy Markdown

binarybaron commented May 3, 2026

thank you for the contribution!

please disclose the extend to which this was LLM generated.

@xn1xn1 xn1xn1 force-pushed the master branch 3 times, most recently from 83e19fd to f0d5114 Compare May 3, 2026 19:43
@xn1xn1
Copy link
Copy Markdown
Author

xn1xn1 commented May 3, 2026

thank you for the contribution!

please disclose the extend to which this was LLM generated.

Hi there. I did use Claude (and gpt5) with adaptive thinking to generate some barebones pseudocode which I used to work on further, as I'm not familiar with this code base. I rechecked and reviewed the output multiple times though. Let me know if there are any issues. If this repo is strictly no AI, then feel free to close this pull request.

Comment thread bitcoin-wallet/src/wallet.rs
Comment thread bitcoin-wallet/src/wallet.rs Outdated
Comment thread bitcoin-wallet/src/wallet.rs Outdated
@xn1xn1
Copy link
Copy Markdown
Author

xn1xn1 commented May 5, 2026

Can squash once you review the new commit.

@binarybaron
Copy link
Copy Markdown

Have you tested this manually ?

@xn1xn1
Copy link
Copy Markdown
Author

xn1xn1 commented May 5, 2026

Have you tested this manually ?

I did before making some minor change, looks like I misplaced a semicolon. I did now, sorry. 😓

@binarybaron
Copy link
Copy Markdown

@Einliterflasche Review would be good here.

@binarybaron
Copy link
Copy Markdown

bugbot run

@Einliterflasche
Copy link
Copy Markdown

Einliterflasche commented May 8, 2026

We need a testcase for this. In the regtest environment, broadcast a tx with low fee and then check if the child tx has increased the fee accordingly.

@xn1xn1
Copy link
Copy Markdown
Author

xn1xn1 commented May 8, 2026

We need a testcase for this. In the regtest environment, broadcast a tx with low fee and then check if the child tx has increased the fee accordingly.

And where should that testcase be?

@Einliterflasche
Copy link
Copy Markdown

The bitcoin test harness is in swap/tests/harness atm. For now you can just add another test case in swap/tests. You don't need the setup_harness function, I think, as we don't need an alice / bob instance to test a Bitcoin transaction. But you can use it if it's easier. At some point we should move the Bitocin harness to it's own crate

@xn1xn1
Copy link
Copy Markdown
Author

xn1xn1 commented May 11, 2026

@Einliterflasche Can you have a look at the test?

Comment on lines +7 to +29
fn psbt_fee_sats(psbt: &bitcoin::psbt::Psbt) -> u64 {
let input_value: u64 = psbt
.inputs
.iter()
.map(|input| {
input
.witness_utxo
.as_ref()
.expect("missing witness_utxo")
.value
.to_sat()
})
.sum();

let output_value: u64 = psbt
.unsigned_tx
.output
.iter()
.map(|output| output.value.to_sat())
.sum();

input_value.saturating_sub(output_value)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

there is a function Psbt::fee which does the same


let parent_tx = wallet.sign_and_finalize(parent_psbt).await?;
let parent_txid = parent_tx.compute_txid();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

add an assert_eq! here to make sure this tx actually has the fee we think it has (parent_fee).

Ok(())
})
.await;

Copy link
Copy Markdown

@Einliterflasche Einliterflasche May 11, 2026

Choose a reason for hiding this comment

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

This test requires that:

  1. the child fee makes the fee rate of the package at least 1sat/vB
  2. the child increases the package fee rate

We should also require that:

  1. the child fee rate is greater than the parent fee rate

and test this with 2 level of transaction depth (child pays for parent and grand parent) and also test that the negative cases. Like testing that we only pay for the parent and grand parent but not great-grand parent etc. and also testing that a sanity limit on the fee is still enforced.

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.

[0.25 XMR] Take fee of unconfirmed parent into consideration when deciding fee

3 participants