Skip to content

Conversation

@ValuedMammal
Copy link
Collaborator

Description

This is a draft PR refactoring build_fee_bump in attempt to resolve #325.

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@ValuedMammal ValuedMammal requested a review from nymius October 29, 2025 17:39
@ValuedMammal ValuedMammal marked this pull request as draft October 29, 2025 17:39
@coveralls
Copy link

Pull Request Test Coverage Report for Build 18917041894

Details

  • 43 of 43 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 85.136%

Totals Coverage Status
Change from base Build 18891447990: 0.1%
Covered Lines: 7005
Relevant Lines: 8228

💛 - Coveralls

Copy link
Contributor

@nymius nymius left a comment

Choose a reason for hiding this comment

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

Concept ACK 8a08bf5

let fee_rate = self
.calculate_fee_rate(&tx)
.map_err(|_| BuildFeeBumpError::FeeRateUnavailable)?;
let fee_rate = fee / tx.weight();
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale to not use calculate_fee_rate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seemed redundant since calculate_fee_rate already calls calculate_fee, so I chose to inline the implementation here.

.script_pubkey();
let witness_utxo = TxOut {
value: Amount::ZERO,
script_pubkey: ScriptBuf::new_p2a(),
Copy link
Contributor

Choose a reason for hiding this comment

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

new_p2a is not in rust-bitcoin 0.32.6, but in rust-bitcoin 0.32.7. Missing Cargo.toml update I guess

}

#[test]
fn test_add_foreign_utxo_bump_fee() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would mention the type of script used in the first tx input, as I think is important for discoverability and also to illustrate the context of what this test is doing.

let tx = psbt.unsigned_tx.clone();
assert!(tx.input.iter().any(|txin| txin.previous_output == outpoint));
let txid1 = tx.compute_txid();
insert_tx(&mut wallet, tx);
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment about the state in which this Tx is inserted from the perspective of the wallet would be helpful.
Like assume tx was broadcasted and is in mempool

};

let mut tx_builder = wallet.build_tx();
tx_builder
Copy link
Contributor

Choose a reason for hiding this comment

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

The default fee rate of this tx is important but not expressed in the creation of the first tx of the test. A comment may be necessary here.

graph
// Get previous transaction.
.get_tx(txin.previous_output.txid)
.ok_or(BuildFeeBumpError::UnknownUtxo(txin.previous_output))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the source of the issue for #325, right?

}) {
// This is a local utxo.
Some(&(keychain, derivation_index)) => {
let txout = prev_txout.ok_or(BuildFeeBumpError::UnknownUtxo(outpoint))?;
Copy link
Contributor

@nymius nymius Oct 31, 2025

Choose a reason for hiding this comment

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

I think the error here is impossible to reach.
If the spk is present on the index, then this wallet collaborated on the creation of the transaction with the signature of that input, then that UTXO should have been already known by this wallet, right?
Also, we are getting this from the TxGraph itself and using an and_then call. All UnknownUtxos will be transformed into None and parsed by the other match arm before reaching this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will look for a way to rewrite it for clarity. I agree we should always have the txout, as otherwise we'd fail at calculate_fee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Can't build a fee bump transaction if spending a P2A output

3 participants