Skip to content

Commit b414c06

Browse files
authored
Merge pull request #1658 from lightning-signer/2022-08-bitcoin-0-29
Update bitcoin crate to 0.29.0
2 parents d2191d9 + 11166aa commit b414c06

39 files changed

+232
-210
lines changed

fuzz/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stdin_fuzz = []
2020
afl = { version = "0.4", optional = true }
2121
lightning = { path = "../lightning", features = ["regex"] }
2222
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
23-
bitcoin = { version = "0.28.1", features = ["secp-lowmemory"] }
23+
bitcoin = { version = "0.29.0", features = ["secp-lowmemory"] }
2424
hex = "0.3"
2525
honggfuzz = { version = "0.5", optional = true }
2626
libfuzzer-sys = { version = "0.4", optional = true }

fuzz/src/chanmon_consistency.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
//! send-side handling is correct, other peers. We consider it a failure if any action results in a
1919
//! channel being force-closed.
2020
21+
use bitcoin::TxMerkleNode;
2122
use bitcoin::blockdata::block::BlockHeader;
2223
use bitcoin::blockdata::constants::genesis_block;
2324
use bitcoin::blockdata::transaction::{Transaction, TxOut};
2425
use bitcoin::blockdata::script::{Builder, Script};
2526
use bitcoin::blockdata::opcodes;
27+
use bitcoin::blockdata::locktime::PackedLockTime;
2628
use bitcoin::network::constants::Network;
2729

2830
use bitcoin::hashes::Hash as TraitImport;
@@ -53,7 +55,7 @@ use lightning::routing::router::{Route, RouteHop};
5355
use utils::test_logger::{self, Output};
5456
use utils::test_persister::TestPersister;
5557

56-
use bitcoin::secp256k1::{PublicKey,SecretKey};
58+
use bitcoin::secp256k1::{PublicKey, SecretKey, Scalar};
5759
use bitcoin::secp256k1::ecdh::SharedSecret;
5860
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
5961
use bitcoin::secp256k1::Secp256k1;
@@ -166,10 +168,10 @@ impl KeysInterface for KeyProvider {
166168
Ok(SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_id]).unwrap())
167169
}
168170

169-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
171+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
170172
let mut node_secret = self.get_node_secret(recipient)?;
171173
if let Some(tweak) = tweak {
172-
node_secret.mul_assign(tweak).map_err(|_| ())?;
174+
node_secret = node_secret.mul_tweak(tweak).unwrap();
173175
}
174176
Ok(SharedSecret::new(other_key, &node_secret))
175177
}
@@ -447,7 +449,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
447449
let events = $source.get_and_clear_pending_events();
448450
assert_eq!(events.len(), 1);
449451
if let events::Event::FundingGenerationReady { ref temporary_channel_id, ref channel_value_satoshis, ref output_script, .. } = events[0] {
450-
let tx = Transaction { version: $chan_id, lock_time: 0, input: Vec::new(), output: vec![TxOut {
452+
let tx = Transaction { version: $chan_id, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
451453
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
452454
}]};
453455
funding_output = OutPoint { txid: tx.txid(), index: 0 };
@@ -481,11 +483,11 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
481483
macro_rules! confirm_txn {
482484
($node: expr) => { {
483485
let chain_hash = genesis_block(Network::Bitcoin).block_hash();
484-
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: chain_hash, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
486+
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: chain_hash, merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
485487
let txdata: Vec<_> = channel_txn.iter().enumerate().map(|(i, tx)| (i + 1, tx)).collect();
486488
$node.transactions_confirmed(&header, &txdata, 1);
487489
for _ in 2..100 {
488-
header = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
490+
header = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
489491
}
490492
$node.best_block_updated(&header, 99);
491493
} }

fuzz/src/full_stack.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
//! or payments to send/ways to handle events generated.
1414
//! This test has been very useful, though due to its complexity good starting inputs are critical.
1515
16+
use bitcoin::TxMerkleNode;
1617
use bitcoin::blockdata::block::BlockHeader;
18+
use bitcoin::blockdata::constants::genesis_block;
1719
use bitcoin::blockdata::transaction::{Transaction, TxOut};
1820
use bitcoin::blockdata::script::{Builder, Script};
1921
use bitcoin::blockdata::opcodes;
22+
use bitcoin::blockdata::locktime::PackedLockTime;
2023
use bitcoin::consensus::encode::deserialize;
2124
use bitcoin::network::constants::Network;
22-
use bitcoin::blockdata::constants::genesis_block;
2325

2426
use bitcoin::hashes::Hash as TraitImport;
2527
use bitcoin::hashes::HashEngine as TraitImportEngine;
@@ -50,7 +52,7 @@ use lightning::util::ser::ReadableArgs;
5052
use utils::test_logger;
5153
use utils::test_persister::TestPersister;
5254

53-
use bitcoin::secp256k1::{PublicKey,SecretKey};
55+
use bitcoin::secp256k1::{PublicKey, SecretKey, Scalar};
5456
use bitcoin::secp256k1::ecdh::SharedSecret;
5557
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
5658
use bitcoin::secp256k1::Secp256k1;
@@ -213,7 +215,7 @@ impl<'a> MoneyLossDetector<'a> {
213215
}
214216

215217
self.blocks_connected += 1;
216-
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height].0, merkle_root: Default::default(), time: self.blocks_connected, bits: 42, nonce: 42 };
218+
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height].0, merkle_root: TxMerkleNode::all_zeros(), time: self.blocks_connected, bits: 42, nonce: 42 };
217219
self.height += 1;
218220
self.manager.transactions_confirmed(&header, &txdata, self.height as u32);
219221
self.manager.best_block_updated(&header, self.height as u32);
@@ -230,7 +232,7 @@ impl<'a> MoneyLossDetector<'a> {
230232

231233
fn disconnect_block(&mut self) {
232234
if self.height > 0 && (self.max_height < 6 || self.height >= self.max_height - 6) {
233-
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height - 1].0, merkle_root: Default::default(), time: self.header_hashes[self.height].1, bits: 42, nonce: 42 };
235+
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height - 1].0, merkle_root: TxMerkleNode::all_zeros(), time: self.header_hashes[self.height].1, bits: 42, nonce: 42 };
234236
self.manager.block_disconnected(&header, self.height as u32);
235237
self.monitor.block_disconnected(&header, self.height as u32);
236238
self.height -= 1;
@@ -270,10 +272,10 @@ impl KeysInterface for KeyProvider {
270272
Ok(self.node_secret.clone())
271273
}
272274

273-
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&[u8; 32]>) -> Result<SharedSecret, ()> {
275+
fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
274276
let mut node_secret = self.get_node_secret(recipient)?;
275277
if let Some(tweak) = tweak {
276-
node_secret.mul_assign(tweak).map_err(|_| ())?;
278+
node_secret = node_secret.mul_tweak(tweak).unwrap();
277279
}
278280
Ok(SharedSecret::new(other_key, &node_secret))
279281
}
@@ -564,7 +566,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
564566
},
565567
10 => {
566568
'outer_loop: for funding_generation in pending_funding_generation.drain(..) {
567-
let mut tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: vec![TxOut {
569+
let mut tx = Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
568570
value: funding_generation.2, script_pubkey: funding_generation.3,
569571
}] };
570572
let funding_output = 'search_loop: loop {

fuzz/src/process_network_graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Imports that need to be added manually
22
use lightning_rapid_gossip_sync::RapidGossipSync;
3+
use bitcoin::hashes::Hash as TraitImport;
34

45
use utils::test_logger;
56

67
/// Actual fuzz test, method signature and name are fixed
78
fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
8-
let block_hash = bitcoin::BlockHash::default();
9+
let block_hash = bitcoin::BlockHash::all_zeros();
910
let logger = test_logger::TestLogger::new("".to_owned(), out);
1011
let network_graph = lightning::routing::gossip::NetworkGraph::new(block_hash, &logger);
1112
let rapid_sync = RapidGossipSync::new(&network_graph);

lightning-background-processor/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ all-features = true
1414
rustdoc-args = ["--cfg", "docsrs"]
1515

1616
[dependencies]
17-
bitcoin = "0.28.1"
17+
bitcoin = "0.29.0"
1818
lightning = { version = "0.0.110", path = "../lightning", features = ["std"] }
1919
lightning-rapid-gossip-sync = { version = "0.0.110", path = "../lightning-rapid-gossip-sync" }
2020

lightning-background-processor/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ impl Drop for BackgroundProcessor {
491491
mod tests {
492492
use bitcoin::blockdata::block::BlockHeader;
493493
use bitcoin::blockdata::constants::genesis_block;
494+
use bitcoin::blockdata::locktime::PackedLockTime;
494495
use bitcoin::blockdata::transaction::{Transaction, TxOut};
495496
use bitcoin::network::constants::Network;
496497
use lightning::chain::{BestBlock, Confirm, chainmonitor};
@@ -516,6 +517,8 @@ mod tests {
516517
use std::sync::{Arc, Mutex};
517518
use std::sync::mpsc::SyncSender;
518519
use std::time::Duration;
520+
use bitcoin::hashes::Hash;
521+
use bitcoin::TxMerkleNode;
519522
use lightning::routing::scoring::{FixedPenaltyScorer};
520523
use lightning_rapid_gossip_sync::RapidGossipSync;
521524
use super::{BackgroundProcessor, GossipSync, FRESHNESS_TIMER};
@@ -703,7 +706,7 @@ mod tests {
703706
assert_eq!(channel_value_satoshis, $channel_value);
704707
assert_eq!(user_channel_id, 42);
705708

706-
let tx = Transaction { version: 1 as i32, lock_time: 0, input: Vec::new(), output: vec![TxOut {
709+
let tx = Transaction { version: 1 as i32, lock_time: PackedLockTime(0), input: Vec::new(), output: vec![TxOut {
707710
value: channel_value_satoshis, script_pubkey: output_script.clone(),
708711
}]};
709712
(temporary_channel_id, tx)
@@ -725,7 +728,7 @@ mod tests {
725728
for i in 1..=depth {
726729
let prev_blockhash = node.best_block.block_hash();
727730
let height = node.best_block.height() + 1;
728-
let header = BlockHeader { version: 0x20000000, prev_blockhash, merkle_root: Default::default(), time: height, bits: 42, nonce: 42 };
731+
let header = BlockHeader { version: 0x20000000, prev_blockhash, merkle_root: TxMerkleNode::all_zeros(), time: height, bits: 42, nonce: 42 };
729732
let txdata = vec![(0, tx)];
730733
node.best_block = BestBlock::new(header.block_hash(), height);
731734
match i {

lightning-block-sync/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rest-client = [ "serde", "serde_json", "chunked_transfer" ]
1818
rpc-client = [ "serde", "serde_json", "chunked_transfer" ]
1919

2020
[dependencies]
21-
bitcoin = "0.28.1"
21+
bitcoin = "0.29.0"
2222
lightning = { version = "0.0.110", path = "../lightning" }
2323
futures = { version = "0.3" }
2424
tokio = { version = "1.0", features = [ "io-util", "net", "time" ], optional = true }

lightning-block-sync/src/convert.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use serde_json;
1515
use std::convert::From;
1616
use std::convert::TryFrom;
1717
use std::convert::TryInto;
18+
use bitcoin::hashes::Hash;
1819

1920
/// Conversion from `std::io::Error` into `BlockSourceError`.
2021
impl From<std::io::Error> for BlockSourceError {
@@ -57,7 +58,7 @@ impl TryInto<BlockHeaderData> for JsonResponse {
5758

5859
// Add an empty previousblockhash for the genesis block.
5960
if let None = header.get("previousblockhash") {
60-
let hash: BlockHash = Default::default();
61+
let hash: BlockHash = BlockHash::all_zeros();
6162
header.as_object_mut().unwrap().insert("previousblockhash".to_string(), serde_json::json!(hash.to_hex()));
6263
}
6364

lightning-block-sync/src/test_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bitcoin::hash_types::BlockHash;
77
use bitcoin::network::constants::Network;
88
use bitcoin::util::uint::Uint256;
99
use bitcoin::util::hash::bitcoin_merkle_root;
10-
use bitcoin::Transaction;
10+
use bitcoin::{PackedLockTime, Transaction};
1111

1212
use lightning::chain;
1313

@@ -45,7 +45,7 @@ impl Blockchain {
4545
// but that's OK because those tests don't trigger the check.
4646
let coinbase = Transaction {
4747
version: 0,
48-
lock_time: 0,
48+
lock_time: PackedLockTime::ZERO,
4949
input: vec![],
5050
output: vec![]
5151
};

lightning-invoice/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ no-std = ["hashbrown", "lightning/no-std", "core2/alloc"]
1919
std = ["bitcoin_hashes/std", "num-traits/std", "lightning/std", "bech32/std"]
2020

2121
[dependencies]
22-
bech32 = { version = "0.8", default-features = false }
22+
bech32 = { version = "0.9.0", default-features = false }
2323
lightning = { version = "0.0.110", path = "../lightning", default-features = false }
24-
secp256k1 = { version = "0.22", default-features = false, features = ["recovery", "alloc"] }
24+
secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"] }
2525
num-traits = { version = "0.2.8", default-features = false }
2626
bitcoin_hashes = { version = "0.10", default-features = false }
2727
hashbrown = { version = "0.11", optional = true }

lightning-invoice/fuzz/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ honggfuzz = { version = "0.5", optional = true }
1616
afl = { version = "0.4", optional = true }
1717
lightning-invoice = { path = ".." }
1818
lightning = { path = "../../lightning", features = ["regex"] }
19-
bech32 = "0.8"
19+
bech32 = "0.9.0"
2020

2121
# Prevent this from interfering with workspaces
2222
[workspace]

lightning-net-tokio/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ all-features = true
1515
rustdoc-args = ["--cfg", "docsrs"]
1616

1717
[dependencies]
18-
bitcoin = "0.28.1"
18+
bitcoin = "0.29.0"
1919
lightning = { version = "0.0.110", path = "../lightning" }
2020
tokio = { version = "1.0", features = [ "io-util", "macros", "rt", "sync", "net", "time" ] }
2121

lightning-persister/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1616
_bench_unstable = ["lightning/_bench_unstable"]
1717

1818
[dependencies]
19-
bitcoin = "0.28.1"
19+
bitcoin = "0.29.0"
2020
lightning = { version = "0.0.110", path = "../lightning" }
2121
libc = "0.2"
2222

lightning-persister/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ mod tests {
137137
use crate::FilesystemPersister;
138138
use bitcoin::blockdata::block::{Block, BlockHeader};
139139
use bitcoin::hashes::hex::FromHex;
140-
use bitcoin::Txid;
140+
use bitcoin::{Txid, TxMerkleNode};
141141
use lightning::chain::ChannelMonitorUpdateErr;
142142
use lightning::chain::chainmonitor::Persist;
143143
use lightning::chain::transaction::OutPoint;
@@ -147,6 +147,7 @@ mod tests {
147147
use lightning::util::events::{ClosureReason, MessageSendEventsProvider};
148148
use lightning::util::test_utils;
149149
use std::fs;
150+
use bitcoin::hashes::Hash;
150151
#[cfg(target_os = "windows")]
151152
use {
152153
lightning::get_event_msg,
@@ -224,7 +225,7 @@ mod tests {
224225
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
225226
assert_eq!(node_txn.len(), 1);
226227

227-
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
228+
let header = BlockHeader { version: 0x20000000, prev_blockhash: nodes[0].best_block_hash(), merkle_root: TxMerkleNode::all_zeros(), time: 42, bits: 42, nonce: 42 };
228229
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[0].clone(), node_txn[0].clone()]});
229230
check_closed_broadcast!(nodes[1], true);
230231
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);

lightning-rapid-gossip-sync/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _bench_unstable = []
1414

1515
[dependencies]
1616
lightning = { version = "0.0.110", path = "../lightning" }
17-
bitcoin = { version = "0.28.1", default-features = false }
17+
bitcoin = { version = "0.29.0", default-features = false }
1818

1919
[dev-dependencies]
2020
lightning = { version = "0.0.110", path = "../lightning", features = ["_test_utils"] }

lightning/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ grind_signatures = []
3838
default = ["std", "grind_signatures"]
3939

4040
[dependencies]
41-
bitcoin = { version = "0.28.1", default-features = false, features = ["secp-recovery"] }
41+
bitcoin = { version = "0.29.0", default-features = false, features = ["secp-recovery"] }
4242

4343
hashbrown = { version = "0.11", optional = true }
4444
hex = { version = "0.4", optional = true }
@@ -52,6 +52,6 @@ hex = "0.4"
5252
regex = "1.5.6"
5353

5454
[dev-dependencies.bitcoin]
55-
version = "0.28.1"
55+
version = "0.29.0"
5656
default-features = false
5757
features = ["bitcoinconsensus", "secp-recovery"]

lightning/src/chain/chainmonitor.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref> even
733733

734734
#[cfg(test)]
735735
mod tests {
736-
use bitcoin::BlockHeader;
736+
use bitcoin::{BlockHeader, TxMerkleNode};
737+
use bitcoin::hashes::Hash;
737738
use ::{check_added_monitors, check_closed_broadcast, check_closed_event};
738739
use ::{expect_payment_sent, expect_payment_claimed, expect_payment_sent_without_paths, expect_payment_path_successful, get_event_msg};
739740
use ::{get_htlc_update_msgs, get_local_commitment_txn, get_revoke_commit_msgs, get_route_and_payment_hash, unwrap_send_err};
@@ -900,7 +901,7 @@ mod tests {
900901
let new_header = BlockHeader {
901902
version: 2, time: 0, bits: 0, nonce: 0,
902903
prev_blockhash: nodes[0].best_block_info().0,
903-
merkle_root: Default::default() };
904+
merkle_root: TxMerkleNode::all_zeros() };
904905
nodes[0].chain_monitor.chain_monitor.transactions_confirmed(&new_header,
905906
&[(0, &remote_txn[0]), (1, &remote_txn[1])], nodes[0].best_block_info().1 + 1);
906907
assert!(nodes[0].chain_monitor.release_pending_monitor_events().is_empty());
@@ -926,7 +927,7 @@ mod tests {
926927
let latest_header = BlockHeader {
927928
version: 2, time: 0, bits: 0, nonce: 0,
928929
prev_blockhash: nodes[0].best_block_info().0,
929-
merkle_root: Default::default() };
930+
merkle_root: TxMerkleNode::all_zeros() };
930931
nodes[0].chain_monitor.chain_monitor.best_block_updated(&latest_header, nodes[0].best_block_info().1 + LATENCY_GRACE_PERIOD_BLOCKS);
931932
} else {
932933
let persistences = chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap().clone();

0 commit comments

Comments
 (0)