Skip to content

Commit

Permalink
upgrade bitcoin to 0.32 and related
Browse files Browse the repository at this point in the history
This upgrades bitcoin to 0.32 and related dependencies accordingly.

Note that the bdk_electrum crate has not been upgraded to the most
recent version available as the Electrum syncing there takes much
longer due to the fetching and validation of Merkle proofs. There
are ongoing BDK changes in relation to that and so we can further
upgrade this dependency once those changes have been completed.

Non-BDK changes to the liana and lianad crates are taken from
darosior's commit 20ee8b1 in
draft PR #1228.
  • Loading branch information
jp1ac4 committed Jan 27, 2025
1 parent 15994b8 commit c5f5284
Show file tree
Hide file tree
Showing 33 changed files with 561 additions and 355 deletions.
280 changes: 189 additions & 91 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
arbitrary = { version = "1", features = ["derive"] }
secp256k1 = { version = "0.28", features = ["global-context-less-secure"] }
secp256k1 = { version = "0.29", features = ["global-context-less-secure"] }


[dependencies.liana]
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl PathConfig {
.expect("Valid pubkey: NUMS from BIP341");
let dummy_fg = [0, 0, path_index, 0].into();
let xpub = bip32::Xpub {
network: Network::Bitcoin,
network: Network::Bitcoin.into(),
depth: 0,
parent_fingerprint: dummy_fg,
child_number: 0.into(),
Expand Down
2 changes: 1 addition & 1 deletion liana-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/main.rs"

[dependencies]
async-trait = "0.1"
async-hwi = { version = "0.0.25" }
async-hwi = { version = "0.0.26" }
liana = { path = "../liana" }
lianad = { path = "../lianad", default-features = false, features = ["nonblocking_shutdown"] }
liana-ui = { path = "../liana-ui" }
Expand Down
7 changes: 4 additions & 3 deletions liana-gui/src/app/state/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl Action for BroadcastAction {
return Command::perform(
async move {
daemon
.broadcast_spend_tx(&psbt.unsigned_tx.txid())
.broadcast_spend_tx(&psbt.unsigned_tx.compute_txid())
.await
.map_err(|e| e.into())
},
Expand Down Expand Up @@ -378,7 +378,7 @@ impl Action for DeleteAction {
return Command::perform(
async move {
daemon
.delete_spend_tx(&psbt.unsigned_tx.txid())
.delete_spend_tx(&psbt.unsigned_tx.compute_txid())
.await
.map_err(|e| e.into())
},
Expand Down Expand Up @@ -705,7 +705,8 @@ impl Action for UpdateAction {
Message::View(view::Message::ImportSpend(view::ImportSpendMessage::PsbtEdited(s))) => {
self.updated.value = s;
if let Ok(psbt) = Psbt::from_str(&self.updated.value) {
self.updated.valid = tx.psbt.unsigned_tx.txid() == psbt.unsigned_tx.txid();
self.updated.valid =
tx.psbt.unsigned_tx.compute_txid() == psbt.unsigned_tx.compute_txid();
} else {
self.updated.valid = false;
}
Expand Down
3 changes: 2 additions & 1 deletion liana-gui/src/app/state/psbts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ impl State for PsbtsPanel {
self.spend_txs = txs;
if let Some(tx) = &self.selected_tx {
if let Some(tx) = self.spend_txs.iter().find(|spend_tx| {
spend_tx.psbt.unsigned_tx.txid() == tx.tx.psbt.unsigned_tx.txid()
spend_tx.psbt.unsigned_tx.compute_txid()
== tx.tx.psbt.unsigned_tx.compute_txid()
}) {
let tx = psbt::PsbtState::new(self.wallet.clone(), tx.clone(), true);
let cmd = tx.load(daemon);
Expand Down
14 changes: 8 additions & 6 deletions liana-gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,15 @@ impl Step for DefineSpend {
!recipient.label.value.is_empty()
&& Address::from_str(&recipient.address.value)
.unwrap()
.payload()
.assume_checked()
.matches_script_pubkey(&output.script_pubkey)
&& output.value.to_sat() == recipient.amount().unwrap()
})
.map(|recipient| recipient.label.value.to_string())
{
draft.labels.insert(
OutPoint {
txid: psbt.unsigned_tx.txid(),
txid: psbt.unsigned_tx.compute_txid(),
vout: i as u32,
}
.to_string(),
Expand Down Expand Up @@ -671,7 +671,7 @@ impl Recipient {
}

if let Ok(address) = Address::from_str(&self.address.value) {
if amount <= address.payload().script_pubkey().dust_value() {
if amount <= address.assume_checked().script_pubkey().minimal_non_dust() {
return Err(Error::Unexpected(
"Amount must be superior to script dust value".to_string(),
));
Expand Down Expand Up @@ -761,14 +761,16 @@ impl Step for SaveSpend {

if tx.is_batch() {
if let Some(label) = &draft.batch_label {
tx.labels
.insert(tx.psbt.unsigned_tx.txid().to_string(), label.clone());
tx.labels.insert(
tx.psbt.unsigned_tx.compute_txid().to_string(),
label.clone(),
);
}
} else if let Some(recipient) = draft.recipients.first() {
if !recipient.label.value.is_empty() {
let label = recipient.label.value.clone();
tx.labels
.insert(tx.psbt.unsigned_tx.txid().to_string(), label);
.insert(tx.psbt.unsigned_tx.compute_txid().to_string(), label);
}
}

Expand Down
15 changes: 9 additions & 6 deletions liana-gui/src/app/state/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ impl State for TransactionsPanel {
self.selected_tx = self.txs.get(i).cloned();
// Clear modal if it's for a different tx.
if let TransactionsModal::CreateRbf(modal) = &self.modal {
if Some(modal.tx.tx.txid())
!= self.selected_tx.as_ref().map(|selected| selected.tx.txid())
if Some(modal.tx.tx.compute_txid())
!= self
.selected_tx
.as_ref()
.map(|selected| selected.tx.compute_txid())
{
self.modal = TransactionsModal::None;
}
Expand All @@ -177,7 +180,7 @@ impl State for TransactionsPanel {
let outpoints: Vec<_> = (0..tx.tx.output.len())
.map(|vout| {
OutPoint::new(
tx.tx.txid(),
tx.tx.compute_txid(),
vout.try_into()
.expect("number of transaction outputs must fit in u32"),
)
Expand Down Expand Up @@ -458,7 +461,7 @@ async fn rbf(
is_cancel: bool,
feerate_vb: Option<u64>,
) -> Result<Txid, Error> {
let previous_txid = previous_tx.tx.txid();
let previous_txid = previous_tx.tx.compute_txid();
let psbt = match daemon
.rbf_psbt(&previous_txid, is_cancel, feerate_vb)
.await?
Expand All @@ -474,7 +477,7 @@ async fn rbf(

if !is_cancel {
let mut labels = HashMap::<LabelItem, Option<String>>::new();
let new_txid = psbt.unsigned_tx.txid();
let new_txid = psbt.unsigned_tx.compute_txid();
for item in previous_tx.labelled() {
if let Some(label) = previous_tx.labels.get(&item.to_string()) {
match item {
Expand Down Expand Up @@ -506,5 +509,5 @@ async fn rbf(
}

daemon.update_spend_tx(&psbt).await?;
Ok(psbt.unsigned_tx.txid())
Ok(psbt.unsigned_tx.compute_txid())
}
17 changes: 11 additions & 6 deletions liana-gui/src/app/view/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ pub fn payment_view<'a>(
labels_editing: &'a HashMap<String, form::Value<String>>,
warning: Option<&'a Error>,
) -> Element<'a, Message> {
let txid = tx.tx.txid().to_string();
let txid = tx.tx.compute_txid().to_string();
let outpoint = bitcoin::OutPoint {
txid: tx.tx.txid(),
txid: tx.tx.compute_txid(),
vout: output_index as u32,
}
.to_string();
Expand Down Expand Up @@ -330,10 +330,14 @@ pub fn payment_view<'a>(
.push(
Row::new()
.align_items(Alignment::Center)
.push(Container::new(text(format!("{}", tx.tx.txid())).small()))
.push(Container::new(
text(format!("{}", tx.tx.compute_txid())).small(),
))
.push(
Button::new(icon::clipboard_icon())
.on_press(Message::Clipboard(tx.tx.txid().to_string()))
.on_press(Message::Clipboard(
tx.tx.compute_txid().to_string(),
))
.style(theme::Button::TransparentBorder),
)
.width(Length::Shrink),
Expand All @@ -342,8 +346,9 @@ pub fn payment_view<'a>(
.spacing(5),
))
.push(
button::secondary(None, "See transaction details")
.on_press(Message::Menu(Menu::TransactionPreSelected(tx.tx.txid()))),
button::secondary(None, "See transaction details").on_press(Message::Menu(
Menu::TransactionPreSelected(tx.tx.compute_txid()),
)),
)
.spacing(20),
)
Expand Down
8 changes: 4 additions & 4 deletions liana-gui/src/app/view/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn spend_header<'a>(
tx: &'a SpendTx,
labels_editing: &'a HashMap<String, form::Value<String>>,
) -> Element<'a, Message> {
let txid = tx.psbt.unsigned_tx.txid().to_string();
let txid = tx.psbt.unsigned_tx.compute_txid().to_string();
Column::new()
.spacing(20)
.push(if let Some(outpoint) = tx.is_single_payment() {
Expand Down Expand Up @@ -357,13 +357,13 @@ pub fn spend_overview_view<'a>(
Row::new()
.push(p1_bold("Tx ID").width(Length::Fill))
.push(
p2_regular(tx.psbt.unsigned_tx.txid().to_string())
p2_regular(tx.psbt.unsigned_tx.compute_txid().to_string())
.style(color::GREY_3),
)
.push(
Button::new(icon::clipboard_icon().style(color::GREY_3))
.on_press(Message::Clipboard(
tx.psbt.unsigned_tx.txid().to_string(),
tx.psbt.unsigned_tx.compute_txid().to_string(),
))
.style(theme::Button::TransparentBorder),
)
Expand Down Expand Up @@ -744,7 +744,7 @@ pub fn outputs_view<'a>(
|col: Column<'a, Message>, (i, output)| {
col.spacing(10).push(payment_view(
i,
tx.txid(),
tx.compute_txid(),
output,
network,
labels,
Expand Down
2 changes: 1 addition & 1 deletion liana-gui/src/app/view/psbts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn spend_tx_list_view(i: usize, tx: &SpendTx) -> Element<'_, Message> {
})
.push_maybe(
tx.labels
.get(&tx.psbt.unsigned_tx.txid().to_string())
.get(&tx.psbt.unsigned_tx.compute_txid().to_string())
.map(p1_regular),
)
.spacing(10)
Expand Down
6 changes: 4 additions & 2 deletions liana-gui/src/app/view/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ fn tx_list_view(i: usize, tx: &HistoryTransaction) -> Element<'_, Message> {
.push_maybe(if let Some(outpoint) = tx.is_single_payment() {
tx.labels.get(&outpoint.to_string()).map(p1_regular)
} else {
tx.labels.get(&tx.tx.txid().to_string()).map(p1_regular)
tx.labels
.get(&tx.tx.compute_txid().to_string())
.map(p1_regular)
})
.push_maybe(tx.time.map(|t| {
Container::new(
Expand Down Expand Up @@ -297,7 +299,7 @@ pub fn tx_view<'a>(
labels_editing: &'a HashMap<String, form::Value<String>>,
warning: Option<&'a Error>,
) -> Element<'a, Message> {
let txid = tx.tx.txid().to_string();
let txid = tx.tx.compute_txid().to_string();
dashboard(
&Menu::Transactions,
cache,
Expand Down
8 changes: 4 additions & 4 deletions liana-gui/src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub trait Daemon: Debug {
// TODO: Use filters in `list_spend_txs` command.
let mut txs = self.list_spend_txs().await?.spend_txs;
if let Some(txids) = txids {
txs.retain(|tx| txids.contains(&tx.psbt.unsigned_tx.txid()));
txs.retain(|tx| txids.contains(&tx.psbt.unsigned_tx.compute_txid()));
}
let outpoints: Vec<_> = txs
.iter()
Expand Down Expand Up @@ -201,7 +201,7 @@ pub trait Daemon: Debug {
(0..tx.tx.output.len())
.map(|vout| {
OutPoint::new(
tx.tx.txid(),
tx.tx.compute_txid(),
vout.try_into()
.expect("number of transaction outputs must fit in u32"),
)
Expand All @@ -220,7 +220,7 @@ pub trait Daemon: Debug {
let mut tx_coins = Vec::new();
let mut change_indexes = Vec::new();
for coin in &coins {
if coin.outpoint.txid == tx.tx.txid() {
if coin.outpoint.txid == tx.tx.compute_txid() {
change_indexes.push(coin.outpoint.vout as usize)
} else if tx
.tx
Expand Down Expand Up @@ -298,7 +298,7 @@ pub trait Daemon: Debug {
let mut tx_coins = Vec::new();
let mut change_indexes = Vec::new();
for coin in &coins {
if coin.outpoint.txid == tx.tx.txid() {
if coin.outpoint.txid == tx.tx.compute_txid() {
change_indexes.push(coin.outpoint.vout as usize)
} else if tx
.tx
Expand Down
18 changes: 9 additions & 9 deletions liana-gui/src/daemon/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl SpendTx {
let mut coins_map = HashMap::<OutPoint, Coin>::with_capacity(coins.len());
for coin in coins {
if let Some(info) = coin.spend_info {
if info.txid == psbt.unsigned_tx.txid() {
if info.txid == psbt.unsigned_tx.compute_txid() {
if info.height.is_some() {
status = SpendStatus::Spent
} else {
Expand Down Expand Up @@ -158,7 +158,7 @@ impl SpendTx {
.filter_map(|(i, _)| {
if !change_indexes.contains(&i) {
Some(OutPoint {
txid: psbt.unsigned_tx.txid(),
txid: psbt.unsigned_tx.compute_txid(),
vout: i as u32,
})
} else {
Expand Down Expand Up @@ -247,7 +247,7 @@ impl Labelled for SpendTx {
}
fn labelled(&self) -> Vec<LabelItem> {
let mut items = Vec::new();
let txid = self.psbt.unsigned_tx.txid();
let txid = self.psbt.unsigned_tx.compute_txid();
items.push(LabelItem::Txid(txid));
for coin in self.coins.values() {
items.push(LabelItem::Address(coin.address.clone()));
Expand Down Expand Up @@ -307,15 +307,15 @@ impl HistoryTransaction {
let kind = if coins.is_empty() {
if change_indexes.len() == 1 {
TransactionKind::IncomingSinglePayment(OutPoint {
txid: tx.txid(),
txid: tx.compute_txid(),
vout: change_indexes[0] as u32,
})
} else {
TransactionKind::IncomingPaymentBatch(
change_indexes
.iter()
.map(|i| OutPoint {
txid: tx.txid(),
txid: tx.compute_txid(),
vout: *i as u32,
})
.collect(),
Expand All @@ -331,7 +331,7 @@ impl HistoryTransaction {
.filter_map(|(i, _)| {
if !change_indexes.contains(&i) {
Some(OutPoint {
txid: tx.txid(),
txid: tx.compute_txid(),
vout: i as u32,
})
} else {
Expand All @@ -356,7 +356,7 @@ impl HistoryTransaction {
Self {
labels: HashMap::new(),
kind,
txid: tx.txid(),
txid: tx.compute_txid(),
tx,
coins: coins_map,
change_indexes,
Expand Down Expand Up @@ -481,7 +481,7 @@ pub fn payments_from_tx(history_tx: HistoryTransaction) -> Vec<Payment> {
return array;
}
let outpoint = OutPoint {
txid: history_tx.tx.txid(),
txid: history_tx.tx.compute_txid(),
vout: output_index as u32,
};
let label = history_tx.labels.get(&outpoint.to_string()).cloned();
Expand Down Expand Up @@ -528,7 +528,7 @@ impl Labelled for HistoryTransaction {
}
fn labelled(&self) -> Vec<LabelItem> {
let mut items = Vec::new();
let txid = self.tx.txid();
let txid = self.tx.compute_txid();
items.push(LabelItem::Txid(txid));
for coin in self.coins.values() {
items.push(LabelItem::Address(coin.address.clone()));
Expand Down
Loading

0 comments on commit c5f5284

Please sign in to comment.