Skip to content

Bitcoin 0.32.2 upgrade #3239

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

Merged
merged 12 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_ut
lightning-invoice = { path = "../lightning-invoice" }
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
bech32 = "0.9.1"
bitcoin = { version = "0.31.2", features = ["secp-lowmemory"] }
bitcoin = { version = "0.32.2", features = ["secp-lowmemory"] }

afl = { version = "0.12", optional = true }
honggfuzz = { version = "0.5", optional = true, default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};

use lightning::io::Cursor;
use std::cmp::{self, Ordering};
use std::io::Cursor;
use std::mem;
use std::sync::atomic;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -154,7 +154,7 @@ impl BroadcasterInterface for TestBroadcaster {

pub struct VecWriter(pub Vec<u8>);
impl Writer for VecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
Expand Down Expand Up @@ -394,7 +394,7 @@ impl SignerProvider for KeyProvider {
}

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

let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?;
let state = self.make_enforcement_state_cell(inner.commitment_seed);
Expand Down Expand Up @@ -880,7 +880,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
script_pubkey: output_script,
}],
};
funding_output = OutPoint { txid: tx.txid(), index: 0 };
funding_output = OutPoint { txid: tx.compute_txid(), index: 0 };
$source
.funding_transaction_generated(
temporary_channel_id,
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/chanmon_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use lightning::util::test_utils::OnlyReadsKeysInterface;

use crate::utils::test_logger;

use std::io::Cursor;
use lightning::io::Cursor;

struct VecWriter(Vec<u8>);
impl Writer for VecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl InputData {
Some(&self.data[old_pos..old_pos + len])
}
}
impl std::io::Read for &InputData {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
impl lightning::io::Read for &InputData {
fn read(&mut self, buf: &mut [u8]) -> lightning::io::Result<usize> {
if let Some(sl) = self.get_slice(buf.len()) {
buf.copy_from_slice(sl);
Ok(buf.len())
Expand Down Expand Up @@ -306,7 +306,7 @@ impl<'a> MoneyLossDetector<'a> {
fn connect_block(&mut self, all_txn: &[Transaction]) {
let mut txdata = Vec::with_capacity(all_txn.len());
for (idx, tx) in all_txn.iter().enumerate() {
let txid = tx.txid();
let txid = tx.compute_txid();
self.txids_confirmed.entry(txid).or_insert_with(|| {
txdata.push((idx + 1, tx));
self.height
Expand Down Expand Up @@ -898,7 +898,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
if tx.version.0 > 0xff {
break;
}
let funding_txid = tx.txid();
let funding_txid = tx.compute_txid();
if loss_detector.txids_confirmed.get(&funding_txid).is_none() {
let outpoint = OutPoint { txid: funding_txid, index: 0 };
for chan in channelmanager.list_channels() {
Expand All @@ -923,7 +923,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
panic!();
}
}
let funding_txid = tx.txid();
let funding_txid = tx.compute_txid();
for idx in 0..tx.output.len() {
let outpoint = OutPoint { txid: funding_txid, index: idx as u16 };
pending_funding_signatures.insert(outpoint, tx.clone());
Expand Down
13 changes: 7 additions & 6 deletions fuzz/src/msg_targets/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use lightning::util::ser::Writer;
pub struct VecWriter(pub Vec<u8>);
impl Writer for VecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
Expand All @@ -31,7 +31,7 @@ impl Writer for VecWriter {
macro_rules! test_msg {
($MsgType: path, $data: ident) => {{
use lightning::util::ser::{Readable, Writeable};
let mut r = ::std::io::Cursor::new($data);
let mut r = ::lightning::io::Cursor::new($data);
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
let p = r.position() as usize;
let mut w = VecWriter(Vec::new());
Expand All @@ -50,13 +50,14 @@ macro_rules! test_msg {
macro_rules! test_msg_simple {
($MsgType: path, $data: ident) => {{
use lightning::util::ser::{Readable, Writeable};
let mut r = ::std::io::Cursor::new($data);
let mut r = ::lightning::io::Cursor::new($data);
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
let mut w = VecWriter(Vec::new());
msg.write(&mut w).unwrap();
assert_eq!(msg.serialized_length(), w.0.len());

let msg = <$MsgType as Readable>::read(&mut ::std::io::Cursor::new(&w.0)).unwrap();
let msg =
<$MsgType as Readable>::read(&mut ::lightning::io::Cursor::new(&w.0)).unwrap();
let mut w_two = VecWriter(Vec::new());
msg.write(&mut w_two).unwrap();
assert_eq!(&w.0[..], &w_two.0[..]);
Expand All @@ -70,7 +71,7 @@ macro_rules! test_msg_simple {
macro_rules! test_msg_exact {
($MsgType: path, $data: ident) => {{
use lightning::util::ser::{Readable, Writeable};
let mut r = ::std::io::Cursor::new($data);
let mut r = ::lightning::io::Cursor::new($data);
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
let mut w = VecWriter(Vec::new());
msg.write(&mut w).unwrap();
Expand All @@ -86,7 +87,7 @@ macro_rules! test_msg_exact {
macro_rules! test_msg_hole {
($MsgType: path, $data: ident, $hole: expr, $hole_len: expr) => {{
use lightning::util::ser::{Readable, Writeable};
let mut r = ::std::io::Cursor::new($data);
let mut r = ::lightning::io::Cursor::new($data);
if let Ok(msg) = <$MsgType as Readable>::read(&mut r) {
let mut w = VecWriter(Vec::new());
msg.write(&mut w).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/onion_hop_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lightning::util::test_utils;
pub fn onion_hop_data_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
use bitcoin::secp256k1::PublicKey;
use lightning::util::ser::ReadableArgs;
let mut r = ::std::io::Cursor::new(data);
let mut r = ::lightning::io::Cursor::new(data);
let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
Option<PublicKey>,
Expand All @@ -30,7 +30,7 @@ pub extern "C" fn onion_hop_data_run(data: *const u8, datalen: usize) {
use bitcoin::secp256k1::PublicKey;
use lightning::util::ser::ReadableArgs;
let data = unsafe { std::slice::from_raw_parts(data, datalen) };
let mut r = ::std::io::Cursor::new(data);
let mut r = ::lightning::io::Cursor::new(data);
let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
Option<PublicKey>,
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use lightning_invoice::RawBolt11Invoice;

use crate::utils::test_logger;

use std::io::{self, Cursor};
use lightning::io::{self, Cursor};
use std::sync::atomic::{AtomicU64, Ordering};

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

pub struct VecWriter(pub Vec<u8>);
impl Writer for VecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::lightning::io::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {

macro_rules! decode_msg {
($MsgType: path, $len: expr) => {{
let mut reader = ::std::io::Cursor::new(get_slice!($len));
let mut reader = ::lightning::io::Cursor::new(get_slice!($len));
match <$MsgType>::read(&mut reader) {
Ok(msg) => {
assert_eq!(reader.position(), $len as u64);
Expand Down
4 changes: 2 additions & 2 deletions lightning-background-processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
futures = [ ]
std = ["bitcoin/std", "lightning/std", "lightning-rapid-gossip-sync/std"]
no-std = ["bitcoin/no-std", "lightning/no-std", "lightning-rapid-gossip-sync/no-std"]
no-std = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"]

default = ["std"]

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

Expand Down
25 changes: 14 additions & 11 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ mod tests {
&& key == CHANNEL_MANAGER_PERSISTENCE_KEY
{
if let Some((error, message)) = self.manager_error {
return Err(std::io::Error::new(error, message));
return Err(std::io::Error::new(error, message).into());
}
}

Expand All @@ -1344,7 +1344,7 @@ mod tests {
};

if let Some((error, message)) = self.graph_error {
return Err(std::io::Error::new(error, message));
return Err(std::io::Error::new(error, message).into());
}
}

Expand All @@ -1353,7 +1353,7 @@ mod tests {
&& key == SCORER_PERSISTENCE_KEY
{
if let Some((error, message)) = self.scorer_error {
return Err(std::io::Error::new(error, message));
return Err(std::io::Error::new(error, message).into());
}
}

Expand Down Expand Up @@ -1866,7 +1866,10 @@ mod tests {
nodes[0]
.node
.force_close_broadcasting_latest_txn(
&ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.txid(), index: 0 }),
&ChannelId::v1_from_funding_outpoint(OutPoint {
txid: tx.compute_txid(),
index: 0,
}),
&nodes[1].node.get_our_node_id(),
error_message.to_string(),
)
Expand Down Expand Up @@ -2002,7 +2005,7 @@ mod tests {
match bp_future.await {
Ok(_) => panic!("Expected error persisting manager"),
Err(e) => {
assert_eq!(e.kind(), std::io::ErrorKind::Other);
assert_eq!(e.kind(), lightning::io::ErrorKind::Other);
assert_eq!(e.get_ref().unwrap().to_string(), "test");
},
}
Expand Down Expand Up @@ -2134,7 +2137,7 @@ mod tests {
get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_0_id);
let broadcast_funding =
nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
assert_eq!(broadcast_funding.txid(), funding_tx.txid());
assert_eq!(broadcast_funding.compute_txid(), funding_tx.compute_txid());
assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty());

if !std::thread::panicking() {
Expand Down Expand Up @@ -2212,7 +2215,7 @@ mod tests {
let sweep_tx_0 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
match tracked_output.status {
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
assert_eq!(sweep_tx_0.txid(), latest_spending_tx.txid());
assert_eq!(sweep_tx_0.compute_txid(), latest_spending_tx.compute_txid());
},
_ => panic!("Unexpected status"),
}
Expand All @@ -2224,7 +2227,7 @@ mod tests {
let sweep_tx_1 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
match tracked_output.status {
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
assert_eq!(sweep_tx_1.txid(), latest_spending_tx.txid());
assert_eq!(sweep_tx_1.compute_txid(), latest_spending_tx.compute_txid());
},
_ => panic!("Unexpected status"),
}
Expand All @@ -2236,7 +2239,7 @@ mod tests {
let sweep_tx_2 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
match tracked_output.status {
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
assert_eq!(sweep_tx_2.txid(), latest_spending_tx.txid());
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());
},
_ => panic!("Unexpected status"),
}
Expand All @@ -2249,7 +2252,7 @@ mod tests {
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
match tracked_output.status {
OutputSpendStatus::PendingThresholdConfirmations { latest_spending_tx, .. } => {
assert_eq!(sweep_tx_2.txid(), latest_spending_tx.txid());
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());
},
_ => panic!("Unexpected status"),
}
Expand All @@ -2264,7 +2267,7 @@ mod tests {
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
match tracked_output.status {
OutputSpendStatus::PendingThresholdConfirmations { latest_spending_tx, .. } => {
assert_eq!(sweep_tx_2.txid(), latest_spending_tx.txid());
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());
},
_ => panic!("Unexpected status"),
}
Expand Down
2 changes: 1 addition & 1 deletion lightning-block-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rest-client = [ "serde_json", "chunked_transfer" ]
rpc-client = [ "serde_json", "chunked_transfer" ]

[dependencies]
bitcoin = "0.31.2"
bitcoin = "0.32.2"
lightning = { version = "0.0.123-beta", path = "../lightning" }
tokio = { version = "1.35", features = [ "io-util", "net", "time", "rt" ], optional = true }
serde_json = { version = "1.0", optional = true }
Expand Down
10 changes: 2 additions & 8 deletions lightning-block-sync/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,7 @@ pub(crate) mod tests {
match TryInto::<Txid>::try_into(response) {
Err(e) => {
assert_eq!(e.kind(), io::ErrorKind::InvalidData);
assert_eq!(
e.get_ref().unwrap().to_string(),
"bad hex string length 6 (expected 64)"
);
assert_eq!(e.get_ref().unwrap().to_string(), "failed to parse hex");
},
Ok(_) => panic!("Expected error"),
}
Expand All @@ -637,10 +634,7 @@ pub(crate) mod tests {
match TryInto::<Txid>::try_into(response) {
Err(e) => {
assert_eq!(e.kind(), io::ErrorKind::InvalidData);
assert_eq!(
e.get_ref().unwrap().to_string(),
"bad hex string length 4 (expected 64)"
);
assert_eq!(e.get_ref().unwrap().to_string(), "failed to parse hex");
},
Ok(_) => panic!("Expected error"),
}
Expand Down
2 changes: 1 addition & 1 deletion lightning-block-sync/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ where
return Err(UtxoLookupError::UnknownTx);
}

outpoint = OutPoint::new(transaction.txid(), output_index.into());
outpoint = OutPoint::new(transaction.compute_txid(), output_index.into());
output = transaction.output[output_index as usize].clone();
}};
}
Expand Down
2 changes: 1 addition & 1 deletion lightning-block-sync/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
///
/// use lightning_block_sync::*;
///
/// use std::io::Cursor;
/// use lightning::io::Cursor;
///
/// async fn init_sync<
/// B: BlockSource,
Expand Down
4 changes: 2 additions & 2 deletions lightning-block-sync/src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ impl ValidatedBlockHeader {
if self.height % 2016 == 0 {
let target = self.header.target();
let previous_target = previous_header.header.target();
let min_target = previous_target.min_difficulty_transition_threshold();
let max_target = previous_target.max_difficulty_transition_threshold();
let min_target = previous_target.min_transition_threshold();
let max_target = previous_target.max_transition_threshold_unchecked();
if target > max_target || target < min_target {
return Err(BlockSourceError::persistent("invalid difficulty transition"));
}
Expand Down
2 changes: 1 addition & 1 deletion lightning-block-sync/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Blockchain {
input: vec![],
output: vec![],
};
let merkle_root = TxMerkleNode::from_raw_hash(coinbase.txid().to_raw_hash());
let merkle_root = TxMerkleNode::from_raw_hash(coinbase.compute_txid().to_raw_hash());
self.blocks.push(Block {
header: Header {
version: Version::NO_SOFT_FORK_SIGNALLING,
Expand Down
Loading
Loading