Skip to content

Commit

Permalink
remove bip32 derivation filter for upstream fix
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Oct 24, 2023
1 parent 42636d5 commit 67f4538
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 67 deletions.
9 changes: 1 addition & 8 deletions gui/src/app/state/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,7 @@ impl State for RecoveryPanel {
.any(|input| input.previous_output == coin.outpoint)
})
.collect();
Ok(SpendTx::new(
None,
psbt,
coins,
&desc,
desc.max_sat_vbytes(),
network,
))
Ok(SpendTx::new(None, psbt, coins, &desc, network))
},
Message::Recovery,
);
Expand Down
1 change: 0 additions & 1 deletion gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ impl Step for SaveSpend {
psbt,
draft.inputs.clone(),
&self.wallet.main_descriptor,
self.wallet.main_descriptor.max_sat_vbytes(),
draft.network,
);
tx.labels = draft.labels.clone();
Expand Down
1 change: 0 additions & 1 deletion gui/src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ pub trait Daemon: Debug {
tx.psbt,
coins,
&info.descriptors.main,
info.descriptors.main.max_sat_vbytes(),
info.network,
));
}
Expand Down
59 changes: 2 additions & 57 deletions gui/src/daemon/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ pub enum SpendStatus {
impl SpendTx {
pub fn new(
updated_at: Option<u32>,
mut psbt: Psbt,
psbt: Psbt,
coins: Vec<Coin>,
desc: &LianaDescriptor,
max_sat_vbytes: usize,
network: Network,
) -> Self {
let max_sat_vbytes = desc.max_sat_vbytes();
let mut change_indexes = Vec::new();
let (change_amount, spend_amount) = psbt.unsigned_tx.output.iter().enumerate().fold(
(Amount::from_sat(0), Amount::from_sat(0)),
Expand Down Expand Up @@ -97,8 +97,6 @@ impl SpendTx {
.partial_spend_info(&psbt)
.expect("PSBT must be generated by Liana");

remove_useless_bip32_derivation(&coins, &desc.policy(), &sigs, &mut psbt);

Self {
labels: HashMap::new(),
kind: if spend_amount == Amount::from_sat(0) {
Expand Down Expand Up @@ -219,59 +217,6 @@ impl Labelled for SpendTx {
}
}

/// we remove all bip32_derivation that are not possible to use for the current primary path
/// or the enabled recovery paths.
/// Todo: maybe fix it upstream in lianad
fn remove_useless_bip32_derivation(
coins: &[Coin],
policy: &LianaPolicy,
spend_info: &PartialSpendInfo,
psbt: &mut Psbt,
) {
let enabled_recovery_paths = spend_info.recovery_paths();
let mut origins: Vec<HashMap<Fingerprint, HashSet<DerivationPath>>> = policy
.recovery_paths()
.iter()
.filter_map(|(timelock, path)| {
if enabled_recovery_paths.get(timelock).is_some() {
Some(path.thresh_origins().1)
} else {
None
}
})
.collect();
origins.push(policy.primary_path().thresh_origins().1);
for (i, input) in psbt.inputs.iter_mut().enumerate() {
// remove bip32_derivation only for our coins.
if psbt
.unsigned_tx
.input
.get(i)
.map(|input| {
coins
.iter()
.any(|coin| coin.outpoint == input.previous_output)
})
.unwrap_or(false)
{
input.bip32_derivation.retain(|_, (fg, path)| {
for origin in &origins {
if let Some(parents) = origin.get(fg) {
let path = path.to_string();
if parents
.iter()
.any(|parent| path.contains(&parent.to_string()))
{
return true;
}
}
}
false
})
}
}
}

#[derive(Debug, Clone)]
pub struct HistoryTransaction {
pub network: Network,
Expand Down

0 comments on commit 67f4538

Please sign in to comment.