-
Notifications
You must be signed in to change notification settings - Fork 46
fix(wallet): Don't fail in build_fee_bump for missing parent txid
#337
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
Open
ValuedMammal
wants to merge
2
commits into
bitcoindevkit:master
Choose a base branch
from
ValuedMammal:fix/build_fee_bump_foreign_utxo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−67
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1711,15 +1711,15 @@ impl Wallet { | |
| &mut self, | ||
| txid: Txid, | ||
| ) -> Result<TxBuilder<'_, DefaultCoinSelectionAlgorithm>, BuildFeeBumpError> { | ||
| let graph = self.indexed_graph.graph(); | ||
| let tx_graph = self.indexed_graph.graph(); | ||
| let txout_index = &self.indexed_graph.index; | ||
| let chain_tip = self.chain.tip().block_id(); | ||
| let chain_positions = graph | ||
| let chain_positions: HashMap<Txid, ChainPosition<_>> = tx_graph | ||
| .list_canonical_txs(&self.chain, chain_tip, CanonicalizationParams::default()) | ||
| .map(|canon_tx| (canon_tx.tx_node.txid, canon_tx.chain_position)) | ||
| .collect::<HashMap<Txid, _>>(); | ||
| .collect(); | ||
|
|
||
| let mut tx = graph | ||
| let mut tx = tx_graph | ||
| .get_tx(txid) | ||
| .ok_or(BuildFeeBumpError::TransactionNotFound(txid))? | ||
| .as_ref() | ||
|
|
@@ -1746,73 +1746,62 @@ impl Wallet { | |
| let fee = self | ||
| .calculate_fee(&tx) | ||
| .map_err(|_| BuildFeeBumpError::FeeRateUnavailable)?; | ||
| let fee_rate = self | ||
| .calculate_fee_rate(&tx) | ||
| .map_err(|_| BuildFeeBumpError::FeeRateUnavailable)?; | ||
| let fee_rate = fee / tx.weight(); | ||
ValuedMammal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Remove the inputs from the tx and process them. | ||
| let utxos = tx | ||
| let utxos: Vec<WeightedUtxo> = tx | ||
| .input | ||
| .drain(..) | ||
| .map(|txin| -> Result<_, BuildFeeBumpError> { | ||
| graph | ||
| // Get previous transaction. | ||
| .get_tx(txin.previous_output.txid) | ||
| .ok_or(BuildFeeBumpError::UnknownUtxo(txin.previous_output)) | ||
ValuedMammal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Get chain position. | ||
| .and_then(|prev_tx| { | ||
| let outpoint = txin.previous_output; | ||
| let prev_txout = tx_graph | ||
| .get_txout(outpoint) | ||
| .cloned() | ||
| .ok_or(BuildFeeBumpError::UnknownUtxo(outpoint))?; | ||
| match txout_index.index_of_spk(prev_txout.script_pubkey.clone()) { | ||
| Some(&(keychain, derivation_index)) => { | ||
| let txout = prev_txout; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not rename |
||
| let chain_position = chain_positions | ||
| .get(&txin.previous_output.txid) | ||
| .get(&outpoint.txid) | ||
| .cloned() | ||
| .ok_or(BuildFeeBumpError::UnknownUtxo(txin.previous_output))?; | ||
| let prev_txout = prev_tx | ||
| .output | ||
| .get(txin.previous_output.vout as usize) | ||
| .ok_or(BuildFeeBumpError::InvalidOutputIndex(txin.previous_output)) | ||
| .cloned()?; | ||
| Ok((prev_tx, prev_txout, chain_position)) | ||
| }) | ||
| .map(|(prev_tx, prev_txout, chain_position)| { | ||
| match txout_index.index_of_spk(prev_txout.script_pubkey.clone()) { | ||
| Some(&(keychain, derivation_index)) => WeightedUtxo { | ||
| satisfaction_weight: self | ||
| .public_descriptor(keychain) | ||
| .max_weight_to_satisfy() | ||
| .unwrap(), | ||
| utxo: Utxo::Local(LocalOutput { | ||
| outpoint: txin.previous_output, | ||
| txout: prev_txout.clone(), | ||
| keychain, | ||
| is_spent: true, | ||
| derivation_index, | ||
| chain_position, | ||
| }), | ||
| }, | ||
| None => { | ||
| let satisfaction_weight = Weight::from_wu_usize( | ||
| serialize(&txin.script_sig).len() * 4 | ||
| + serialize(&txin.witness).len(), | ||
| ); | ||
| WeightedUtxo { | ||
| utxo: Utxo::Foreign { | ||
| outpoint: txin.previous_output, | ||
| sequence: txin.sequence, | ||
| psbt_input: Box::new(psbt::Input { | ||
| witness_utxo: prev_txout | ||
| .script_pubkey | ||
| .witness_version() | ||
| .map(|_| prev_txout.clone()), | ||
| non_witness_utxo: Some(prev_tx.as_ref().clone()), | ||
| ..Default::default() | ||
| }), | ||
| }, | ||
| satisfaction_weight, | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| .ok_or(BuildFeeBumpError::TransactionNotFound(outpoint.txid))?; | ||
| Ok(WeightedUtxo { | ||
| satisfaction_weight: self | ||
| .public_descriptor(keychain) | ||
| .max_weight_to_satisfy() | ||
| .expect("descriptor should be satisfiable"), | ||
| utxo: Utxo::Local(LocalOutput { | ||
| outpoint, | ||
| txout, | ||
| keychain, | ||
| is_spent: true, | ||
| derivation_index, | ||
| chain_position, | ||
| }), | ||
| }) | ||
| } | ||
| None => Ok(WeightedUtxo { | ||
| satisfaction_weight: Weight::from_wu_usize( | ||
| serialize(&txin.script_sig).len() * 4 + serialize(&txin.witness).len(), | ||
| ), | ||
| utxo: Utxo::Foreign { | ||
| outpoint, | ||
| sequence: txin.sequence, | ||
| psbt_input: Box::new(psbt::Input { | ||
| witness_utxo: prev_txout | ||
| .script_pubkey | ||
| .witness_version() | ||
| .map(|_| prev_txout), | ||
| non_witness_utxo: tx_graph | ||
| .get_tx(outpoint.txid) | ||
| .map(|tx| tx.as_ref().clone()), | ||
| ..Default::default() | ||
| }), | ||
| }, | ||
| }), | ||
| } | ||
| }) | ||
| .collect::<Result<Vec<WeightedUtxo>, BuildFeeBumpError>>()?; | ||
| .collect::<Result<_, _>>()?; | ||
|
|
||
| if tx.output.len() > 1 { | ||
| let mut change_index = None; | ||
|
|
@@ -1832,7 +1821,6 @@ impl Wallet { | |
| } | ||
|
|
||
| let params = TxParams { | ||
| // TODO: figure out what rbf option should be? | ||
| version: Some(tx.version), | ||
| recipients: tx | ||
| .output | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 tx request here and the conditional below could be reduced to the same thing.