Skip to content

Commit 43dcf2f

Browse files
authored
Merge pull request #3239 from arik-so/bitcoin-0.32.2-upgrade
Bitcoin 0.32.2 upgrade
2 parents 8fe3a56 + 36b484a commit 43dcf2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+617
-528
lines changed

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_ut
2222
lightning-invoice = { path = "../lightning-invoice" }
2323
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
2424
bech32 = "0.9.1"
25-
bitcoin = { version = "0.31.2", features = ["secp-lowmemory"] }
25+
bitcoin = { version = "0.32.2", features = ["secp-lowmemory"] }
2626

2727
afl = { version = "0.12", optional = true }
2828
honggfuzz = { version = "0.5", optional = true, default-features = false }

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
8080
use bitcoin::secp256k1::schnorr;
8181
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
8282

83+
use lightning::io::Cursor;
8384
use std::cmp::{self, Ordering};
84-
use std::io::Cursor;
8585
use std::mem;
8686
use std::sync::atomic;
8787
use std::sync::{Arc, Mutex};
@@ -153,7 +153,7 @@ impl BroadcasterInterface for TestBroadcaster {
153153

154154
pub struct VecWriter(pub Vec<u8>);
155155
impl Writer for VecWriter {
156-
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
156+
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
157157
self.0.extend_from_slice(buf);
158158
Ok(())
159159
}
@@ -393,7 +393,7 @@ impl SignerProvider for KeyProvider {
393393
}
394394

395395
fn read_chan_signer(&self, buffer: &[u8]) -> Result<Self::EcdsaSigner, DecodeError> {
396-
let mut reader = std::io::Cursor::new(buffer);
396+
let mut reader = lightning::io::Cursor::new(buffer);
397397

398398
let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?;
399399
let state = self.make_enforcement_state_cell(inner.commitment_seed);
@@ -879,7 +879,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
879879
script_pubkey: output_script,
880880
}],
881881
};
882-
funding_output = OutPoint { txid: tx.txid(), index: 0 };
882+
funding_output = OutPoint { txid: tx.compute_txid(), index: 0 };
883883
$source
884884
.funding_transaction_generated(
885885
temporary_channel_id,

fuzz/src/chanmon_deser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use lightning::util::test_utils::OnlyReadsKeysInterface;
1010

1111
use crate::utils::test_logger;
1212

13-
use std::io::Cursor;
13+
use lightning::io::Cursor;
1414

1515
struct VecWriter(Vec<u8>);
1616
impl Writer for VecWriter {
17-
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
17+
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
1818
self.0.extend_from_slice(buf);
1919
Ok(())
2020
}

fuzz/src/full_stack.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl InputData {
120120
Some(&self.data[old_pos..old_pos + len])
121121
}
122122
}
123-
impl std::io::Read for &InputData {
124-
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
123+
impl lightning::io::Read for &InputData {
124+
fn read(&mut self, buf: &mut [u8]) -> lightning::io::Result<usize> {
125125
if let Some(sl) = self.get_slice(buf.len()) {
126126
buf.copy_from_slice(sl);
127127
Ok(buf.len())
@@ -305,7 +305,7 @@ impl<'a> MoneyLossDetector<'a> {
305305
fn connect_block(&mut self, all_txn: &[Transaction]) {
306306
let mut txdata = Vec::with_capacity(all_txn.len());
307307
for (idx, tx) in all_txn.iter().enumerate() {
308-
let txid = tx.txid();
308+
let txid = tx.compute_txid();
309309
self.txids_confirmed.entry(txid).or_insert_with(|| {
310310
txdata.push((idx + 1, tx));
311311
self.height
@@ -897,7 +897,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
897897
if tx.version.0 > 0xff {
898898
break;
899899
}
900-
let funding_txid = tx.txid();
900+
let funding_txid = tx.compute_txid();
901901
if loss_detector.txids_confirmed.get(&funding_txid).is_none() {
902902
let outpoint = OutPoint { txid: funding_txid, index: 0 };
903903
for chan in channelmanager.list_channels() {
@@ -922,7 +922,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
922922
panic!();
923923
}
924924
}
925-
let funding_txid = tx.txid();
925+
let funding_txid = tx.compute_txid();
926926
for idx in 0..tx.output.len() {
927927
let outpoint = OutPoint { txid: funding_txid, index: idx as u16 };
928928
pending_funding_signatures.insert(outpoint, tx.clone());

fuzz/src/msg_targets/utils.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use lightning::util::ser::Writer;
1313
pub struct VecWriter(pub Vec<u8>);
1414
impl Writer for VecWriter {
15-
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
15+
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
1616
self.0.extend_from_slice(buf);
1717
Ok(())
1818
}
@@ -31,7 +31,7 @@ impl Writer for VecWriter {
3131
macro_rules! test_msg {
3232
($MsgType: path, $data: ident) => {{
3333
use lightning::util::ser::{Readable, Writeable};
34-
let mut r = ::std::io::Cursor::new($data);
34+
let mut r = ::lightning::io::Cursor::new($data);
3535
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
3636
let p = r.position() as usize;
3737
let mut w = VecWriter(Vec::new());
@@ -50,13 +50,14 @@ macro_rules! test_msg {
5050
macro_rules! test_msg_simple {
5151
($MsgType: path, $data: ident) => {{
5252
use lightning::util::ser::{Readable, Writeable};
53-
let mut r = ::std::io::Cursor::new($data);
53+
let mut r = ::lightning::io::Cursor::new($data);
5454
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
5555
let mut w = VecWriter(Vec::new());
5656
msg.write(&mut w).unwrap();
5757
assert_eq!(msg.serialized_length(), w.0.len());
5858

59-
let msg = <$MsgType as Readable>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap();
59+
let msg =
60+
<$MsgType as Readable>::read(&mut ::lightning::io::Cursor::new(&w.0)).unwrap();
6061
let mut w_two = VecWriter(Vec::new());
6162
msg.write(&mut w_two).unwrap();
6263
assert_eq!(&w.0[..], &w_two.0[..]);
@@ -70,7 +71,7 @@ macro_rules! test_msg_simple {
7071
macro_rules! test_msg_exact {
7172
($MsgType: path, $data: ident) => {{
7273
use lightning::util::ser::{Readable, Writeable};
73-
let mut r = ::std::io::Cursor::new($data);
74+
let mut r = ::lightning::io::Cursor::new($data);
7475
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
7576
let mut w = VecWriter(Vec::new());
7677
msg.write(&mut w).unwrap();
@@ -86,7 +87,7 @@ macro_rules! test_msg_exact {
8687
macro_rules! test_msg_hole {
8788
($MsgType: path, $data: ident, $hole: expr, $hole_len: expr) => {{
8889
use lightning::util::ser::{Readable, Writeable};
89-
let mut r = ::std::io::Cursor::new($data);
90+
let mut r = ::lightning::io::Cursor::new($data);
9091
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
9192
let mut w = VecWriter(Vec::new());
9293
msg.write(&mut w).unwrap();

fuzz/src/onion_hop_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use lightning::util::test_utils;
1717
pub fn onion_hop_data_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
1818
use bitcoin::secp256k1::PublicKey;
1919
use lightning::util::ser::ReadableArgs;
20-
let mut r = ::std::io::Cursor::new(data);
20+
let mut r = ::lightning::io::Cursor::new(data);
2121
let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
2222
let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
2323
Option<PublicKey>,
@@ -30,7 +30,7 @@ pub extern "C" fn onion_hop_data_run(data: *const u8, datalen: usize) {
3030
use bitcoin::secp256k1::PublicKey;
3131
use lightning::util::ser::ReadableArgs;
3232
let data = unsafe { std::slice::from_raw_parts(data, datalen) };
33-
let mut r = ::std::io::Cursor::new(data);
33+
let mut r = ::lightning::io::Cursor::new(data);
3434
let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
3535
let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
3636
Option<PublicKey>,

fuzz/src/onion_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use lightning_invoice::RawBolt11Invoice;
3030

3131
use crate::utils::test_logger;
3232

33-
use std::io::{self, Cursor};
33+
use lightning::io::{self, Cursor};
3434
use std::sync::atomic::{AtomicU64, Ordering};
3535

3636
#[inline]
@@ -168,7 +168,7 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
168168
&self, _message_type: u64, buffer: &mut R,
169169
) -> Result<Option<Self::CustomMessage>, msgs::DecodeError> {
170170
let mut buf = Vec::new();
171-
buffer.read_to_end(&mut buf)?;
171+
buffer.read_to_limit(&mut buf, u64::MAX)?;
172172
return Ok(Some(TestCustomMessage {}));
173173
}
174174
fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>> {
@@ -178,7 +178,7 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
178178

179179
pub struct VecWriter(pub Vec<u8>);
180180
impl Writer for VecWriter {
181-
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
181+
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
182182
self.0.extend_from_slice(buf);
183183
Ok(())
184184
}

fuzz/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
147147

148148
macro_rules! decode_msg {
149149
($MsgType: path, $len: expr) => {{
150-
let mut reader = ::std::io::Cursor::new(get_slice!($len));
150+
let mut reader = ::lightning::io::Cursor::new(get_slice!($len));
151151
match <$MsgType>::read(&mut reader) {
152152
Ok(msg) => {
153153
assert_eq!(reader.position(), $len as u64);

lightning-background-processor/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ rustdoc-args = ["--cfg", "docsrs"]
1616
[features]
1717
futures = [ ]
1818
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
19-
no-std = ["bitcoin/no-std", "lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
19+
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
2020

2121
default = ["std"]
2222

2323
[dependencies]
24-
bitcoin = { version = "0.31.2", default-features = false }
24+
bitcoin = { version = "0.32.2", default-features = false }
2525
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
2626
lightning-rapid-gossip-sync = { version = "0.0.123-beta", path = "../lightning-rapid-gossip-sync", default-features = false }
2727

lightning-background-processor/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ mod tests {
13261326
&& key == CHANNEL_MANAGER_PERSISTENCE_KEY
13271327
{
13281328
if let Some((error, message)) = self.manager_error {
1329-
return Err(std::io::Error::new(error, message));
1329+
return Err(std::io::Error::new(error, message).into());
13301330
}
13311331
}
13321332

@@ -1344,7 +1344,7 @@ mod tests {
13441344
};
13451345

13461346
if let Some((error, message)) = self.graph_error {
1347-
return Err(std::io::Error::new(error, message));
1347+
return Err(std::io::Error::new(error, message).into());
13481348
}
13491349
}
13501350

@@ -1353,7 +1353,7 @@ mod tests {
13531353
&& key == SCORER_PERSISTENCE_KEY
13541354
{
13551355
if let Some((error, message)) = self.scorer_error {
1356-
return Err(std::io::Error::new(error, message));
1356+
return Err(std::io::Error::new(error, message).into());
13571357
}
13581358
}
13591359

@@ -1866,7 +1866,10 @@ mod tests {
18661866
nodes[0]
18671867
.node
18681868
.force_close_broadcasting_latest_txn(
1869-
&ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.txid(), index: 0 }),
1869+
&ChannelId::v1_from_funding_outpoint(OutPoint {
1870+
txid: tx.compute_txid(),
1871+
index: 0,
1872+
}),
18701873
&nodes[1].node.get_our_node_id(),
18711874
error_message.to_string(),
18721875
)
@@ -2002,7 +2005,7 @@ mod tests {
20022005
match bp_future.await {
20032006
Ok(_) => panic!("Expected error persisting manager"),
20042007
Err(e) => {
2005-
assert_eq!(e.kind(), std::io::ErrorKind::Other);
2008+
assert_eq!(e.kind(), lightning::io::ErrorKind::Other);
20062009
assert_eq!(e.get_ref().unwrap().to_string(), "test");
20072010
},
20082011
}
@@ -2134,7 +2137,7 @@ mod tests {
21342137
get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_0_id);
21352138
let broadcast_funding =
21362139
nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
2137-
assert_eq!(broadcast_funding.txid(), funding_tx.txid());
2140+
assert_eq!(broadcast_funding.compute_txid(), funding_tx.compute_txid());
21382141
assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty());
21392142

21402143
if !std::thread::panicking() {
@@ -2212,7 +2215,7 @@ mod tests {
22122215
let sweep_tx_0 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
22132216
match tracked_output.status {
22142217
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
2215-
assert_eq!(sweep_tx_0.txid(), latest_spending_tx.txid());
2218+
assert_eq!(sweep_tx_0.compute_txid(), latest_spending_tx.compute_txid());
22162219
},
22172220
_ => panic!("Unexpected status"),
22182221
}
@@ -2224,7 +2227,7 @@ mod tests {
22242227
let sweep_tx_1 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
22252228
match tracked_output.status {
22262229
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
2227-
assert_eq!(sweep_tx_1.txid(), latest_spending_tx.txid());
2230+
assert_eq!(sweep_tx_1.compute_txid(), latest_spending_tx.compute_txid());
22282231
},
22292232
_ => panic!("Unexpected status"),
22302233
}
@@ -2236,7 +2239,7 @@ mod tests {
22362239
let sweep_tx_2 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
22372240
match tracked_output.status {
22382241
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
2239-
assert_eq!(sweep_tx_2.txid(), latest_spending_tx.txid());
2242+
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());
22402243
},
22412244
_ => panic!("Unexpected status"),
22422245
}
@@ -2249,7 +2252,7 @@ mod tests {
22492252
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
22502253
match tracked_output.status {
22512254
OutputSpendStatus::PendingThresholdConfirmations { latest_spending_tx, .. } => {
2252-
assert_eq!(sweep_tx_2.txid(), latest_spending_tx.txid());
2255+
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());
22532256
},
22542257
_ => panic!("Unexpected status"),
22552258
}
@@ -2264,7 +2267,7 @@ mod tests {
22642267
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
22652268
match tracked_output.status {
22662269
OutputSpendStatus::PendingThresholdConfirmations { latest_spending_tx, .. } => {
2267-
assert_eq!(sweep_tx_2.txid(), latest_spending_tx.txid());
2270+
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());
22682271
},
22692272
_ => panic!("Unexpected status"),
22702273
}

lightning-block-sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rest-client = [ "serde_json", "chunked_transfer" ]
1818
rpc-client = [ "serde_json", "chunked_transfer" ]
1919

2020
[dependencies]
21-
bitcoin = "0.31.2"
21+
bitcoin = "0.32.2"
2222
lightning = { version = "0.0.123-beta", path = "../lightning" }
2323
tokio = { version = "1.35", features = [ "io-util", "net", "time", "rt" ], optional = true }
2424
serde_json = { version = "1.0", optional = true }

lightning-block-sync/src/convert.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,7 @@ pub(crate) mod tests {
622622
match TryInto::<Txid>::try_into(response) {
623623
Err(e) => {
624624
assert_eq!(e.kind(), io::ErrorKind::InvalidData);
625-
assert_eq!(
626-
e.get_ref().unwrap().to_string(),
627-
"bad hex string length 6 (expected 64)"
628-
);
625+
assert_eq!(e.get_ref().unwrap().to_string(), "failed to parse hex");
629626
},
630627
Ok(_) => panic!("Expected error"),
631628
}
@@ -637,10 +634,7 @@ pub(crate) mod tests {
637634
match TryInto::<Txid>::try_into(response) {
638635
Err(e) => {
639636
assert_eq!(e.kind(), io::ErrorKind::InvalidData);
640-
assert_eq!(
641-
e.get_ref().unwrap().to_string(),
642-
"bad hex string length 4 (expected 64)"
643-
);
637+
assert_eq!(e.get_ref().unwrap().to_string(), "failed to parse hex");
644638
},
645639
Ok(_) => panic!("Expected error"),
646640
}

lightning-block-sync/src/gossip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ where
198198
return Err(UtxoLookupError::UnknownTx);
199199
}
200200

201-
outpoint = OutPoint::new(transaction.txid(), output_index.into());
201+
outpoint = OutPoint::new(transaction.compute_txid(), output_index.into());
202202
output = transaction.output[output_index as usize].clone();
203203
}};
204204
}

lightning-block-sync/src/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
///
6060
/// use lightning_block_sync::*;
6161
///
62-
/// use std::io::Cursor;
62+
/// use lightning::io::Cursor;
6363
///
6464
/// async fn init_sync<
6565
/// B: BlockSource,

lightning-block-sync/src/poll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ impl ValidatedBlockHeader {
144144
if self.height % 2016 == 0 {
145145
let target = self.header.target();
146146
let previous_target = previous_header.header.target();
147-
let min_target = previous_target.min_difficulty_transition_threshold();
148-
let max_target = previous_target.max_difficulty_transition_threshold();
147+
let min_target = previous_target.min_transition_threshold();
148+
let max_target = previous_target.max_transition_threshold_unchecked();
149149
if target > max_target || target < min_target {
150150
return Err(BlockSourceError::persistent("invalid difficulty transition"));
151151
}

lightning-block-sync/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Blockchain {
5353
input: vec![],
5454
output: vec![],
5555
};
56-
let merkle_root = TxMerkleNode::from_raw_hash(coinbase.txid().to_raw_hash());
56+
let merkle_root = TxMerkleNode::from_raw_hash(coinbase.compute_txid().to_raw_hash());
5757
self.blocks.push(Block {
5858
header: Header {
5959
version: Version::NO_SOFT_FORK_SIGNALLING,

0 commit comments

Comments
 (0)