From 0904ee7fac04eade1bde7fddd10b0ecf517678cd Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Thu, 27 Jun 2024 10:13:47 -0400 Subject: [PATCH] TODO: FIXME! experimental upgrade to bitcoin 0.32.2 --- fuzz/Cargo.toml | 2 +- lightning-background-processor/Cargo.toml | 4 ++-- lightning-block-sync/Cargo.toml | 2 +- lightning-custom-message/Cargo.toml | 2 +- lightning-invoice/Cargo.toml | 2 +- lightning-net-tokio/Cargo.toml | 2 +- lightning-persister/Cargo.toml | 4 ++-- lightning-rapid-gossip-sync/Cargo.toml | 2 +- lightning-transaction-sync/Cargo.toml | 2 +- lightning/Cargo.toml | 8 +++---- lightning/src/chain/channelmonitor.rs | 4 ++-- lightning/src/ln/chan_utils.rs | 3 +-- lightning/src/offers/invoice.rs | 24 +++++++++---------- lightning/src/util/ser.rs | 28 ++++++++++++++++++++++- 14 files changed, 57 insertions(+), 32 deletions(-) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 4d9f7e0de..894638425 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -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"] } hex = { package = "hex-conservative", version = "0.1.1", default-features = false } afl = { version = "0.12", optional = true } diff --git a/lightning-background-processor/Cargo.toml b/lightning-background-processor/Cargo.toml index df4b2c827..c780cc3d6 100644 --- a/lightning-background-processor/Cargo.toml +++ b/lightning-background-processor/Cargo.toml @@ -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 } diff --git a/lightning-block-sync/Cargo.toml b/lightning-block-sync/Cargo.toml index 2e8270000..c02084c16 100644 --- a/lightning-block-sync/Cargo.toml +++ b/lightning-block-sync/Cargo.toml @@ -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" hex = { package = "hex-conservative", version = "0.1.1", default-features = false } lightning = { version = "0.0.123-beta", path = "../lightning" } tokio = { version = "1.35", features = [ "io-util", "net", "time", "rt" ], optional = true } diff --git a/lightning-custom-message/Cargo.toml b/lightning-custom-message/Cargo.toml index f74ead81c..d3c2e5708 100644 --- a/lightning-custom-message/Cargo.toml +++ b/lightning-custom-message/Cargo.toml @@ -14,7 +14,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [dependencies] -bitcoin = "0.31.2" +bitcoin = "0.32.2" lightning = { version = "0.0.123-beta", path = "../lightning" } [lints] diff --git a/lightning-invoice/Cargo.toml b/lightning-invoice/Cargo.toml index d89f8d08e..e7b14d876 100644 --- a/lightning-invoice/Cargo.toml +++ b/lightning-invoice/Cargo.toml @@ -24,7 +24,7 @@ bech32 = { version = "0.9.1", default-features = false } lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false } secp256k1 = { version = "0.28.0", default-features = false, features = ["recovery", "alloc"] } serde = { version = "1.0.118", optional = true } -bitcoin = { version = "0.31.2", default-features = false } +bitcoin = { version = "0.32.2", default-features = false } [dev-dependencies] lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false, features = ["_test_utils"] } diff --git a/lightning-net-tokio/Cargo.toml b/lightning-net-tokio/Cargo.toml index c56553711..ede8cc0a7 100644 --- a/lightning-net-tokio/Cargo.toml +++ b/lightning-net-tokio/Cargo.toml @@ -15,7 +15,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [dependencies] -bitcoin = "0.31.2" +bitcoin = "0.32.2" lightning = { version = "0.0.123-beta", path = "../lightning" } tokio = { version = "1.35", features = [ "rt", "sync", "net", "time" ] } diff --git a/lightning-persister/Cargo.toml b/lightning-persister/Cargo.toml index 5f1e27740..e315fb791 100644 --- a/lightning-persister/Cargo.toml +++ b/lightning-persister/Cargo.toml @@ -14,7 +14,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [dependencies] -bitcoin = "0.31.2" +bitcoin = "0.32.2" lightning = { version = "0.0.123-beta", path = "../lightning" } [target.'cfg(windows)'.dependencies] @@ -25,7 +25,7 @@ criterion = { version = "0.4", optional = true, default-features = false } [dev-dependencies] lightning = { version = "0.0.123-beta", path = "../lightning", features = ["_test_utils"] } -bitcoin = { version = "0.31.2", default-features = false } +bitcoin = { version = "0.32.2", default-features = false } [lints] workspace = true diff --git a/lightning-rapid-gossip-sync/Cargo.toml b/lightning-rapid-gossip-sync/Cargo.toml index 7ca67a38e..9d9f3d23e 100644 --- a/lightning-rapid-gossip-sync/Cargo.toml +++ b/lightning-rapid-gossip-sync/Cargo.toml @@ -16,7 +16,7 @@ std = ["lightning/std"] [dependencies] lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false } -bitcoin = { version = "0.31.2", default-features = false } +bitcoin = { version = "0.32.2", default-features = false } [target.'cfg(ldk_bench)'.dependencies] criterion = { version = "0.4", optional = true, default-features = false } diff --git a/lightning-transaction-sync/Cargo.toml b/lightning-transaction-sync/Cargo.toml index ab7967499..0243d7604 100644 --- a/lightning-transaction-sync/Cargo.toml +++ b/lightning-transaction-sync/Cargo.toml @@ -24,7 +24,7 @@ async-interface = [] [dependencies] lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false, features = ["std"] } -bitcoin = { version = "0.31.2", default-features = false } +bitcoin = { version = "0.32.2", default-features = false } bdk-macros = "0.6" futures = { version = "0.3", optional = true } esplora-client = { version = "0.7", default-features = false, optional = true } diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index cf4a53294..dfb17b957 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -31,7 +31,7 @@ unsafe_revoked_tx_signing = [] # Override signing to not include randomness when generating signatures for test vectors. _test_vectors = [] -no-std = ["hashbrown", "possiblyrandom", "bitcoin/no-std", "core2/alloc", "libm"] +no-std = ["hashbrown", "possiblyrandom", "core2/alloc", "libm"] std = ["bitcoin/std", "bech32/std"] # Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases @@ -41,7 +41,7 @@ default = ["std", "grind_signatures"] [dependencies] bech32 = { version = "0.9.1", default-features = false } -bitcoin = { version = "0.31.2", default-features = false, features = ["secp-recovery"] } +bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] } hashbrown = { version = "0.13", optional = true, default-features = false } possiblyrandom = { version = "0.2", optional = true, default-features = false } @@ -56,7 +56,7 @@ libm = { version = "0.2", optional = true, default-features = false } regex = "1.5.6" [dev-dependencies.bitcoin] -version = "0.31.2" +version = "0.32.2" default-features = false features = ["bitcoinconsensus", "secp-recovery"] @@ -64,7 +64,7 @@ features = ["bitcoinconsensus", "secp-recovery"] criterion = { version = "0.4", optional = true, default-features = false } [target.'cfg(taproot)'.dependencies] -musig2 = { git = "https://github.com/arik-so/rust-musig2", rev = "739533fc" } +musig2 = { git = "https://github.com/arik-so/rust-musig2", rev = "6f95a05718cbb44d8fe3fa6021aea8117aa38d50" } [lints] workspace = true diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 13f2ff044..36bda0d82 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -32,7 +32,7 @@ use bitcoin::hash_types::{Txid, BlockHash}; use bitcoin::ecdsa::Signature as BitcoinSignature; use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature}; use bitcoin::secp256k1::{SecretKey, PublicKey}; -use bitcoin::secp256k1; +use bitcoin::{CompressedPublicKey, secp256k1}; use crate::ln::channel::INITIAL_COMMITMENT_NUMBER; use crate::ln::types::{PaymentHash, PaymentPreimage, ChannelId}; @@ -4077,7 +4077,7 @@ impl ChannelMonitorImpl { assert_eq!(&bitcoin::Address::p2wsh(&ScriptBuf::from(input.witness.last().unwrap().to_vec()), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey); } else if _script_pubkey.is_p2wpkh() { - assert_eq!(&bitcoin::Address::p2wpkh(&bitcoin::PublicKey::from_slice(&input.witness.last().unwrap()).unwrap(), bitcoin::Network::Bitcoin).unwrap().script_pubkey(), _script_pubkey); + assert_eq!(&bitcoin::Address::p2wpkh(&CompressedPublicKey(bitcoin::PublicKey::from_slice(&input.witness.last().unwrap()).unwrap().inner), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey); } else { panic!(); } } return true; diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index ffdbfe919..c3aa3e17e 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -1844,7 +1844,6 @@ mod tests { use bitcoin::hashes::Hash; use bitcoin::hashes::hex::FromHex; use crate::ln::types::PaymentHash; - use bitcoin::address::Payload; use bitcoin::PublicKey as BitcoinPublicKey; use crate::ln::features::ChannelTypeFeatures; @@ -1917,7 +1916,7 @@ mod tests { // Generate broadcaster and counterparty outputs let tx = builder.build(1000, 2000); assert_eq!(tx.built.transaction.output.len(), 2); - assert_eq!(tx.built.transaction.output[1].script_pubkey, Payload::p2wpkh(&BitcoinPublicKey::new(builder.counterparty_pubkeys.payment_point)).unwrap().script_pubkey()); + assert_eq!(tx.built.transaction.output[1].script_pubkey, BitcoinPublicKey::new(builder.counterparty_pubkeys.payment_point).p2wpkh_script_code().unwrap()); // Generate broadcaster and counterparty outputs as well as two anchors builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(); diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 3f96e703b..c4f4e4a43 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -102,11 +102,12 @@ //! //! ``` -use bitcoin::{WitnessProgram, Network, WitnessVersion}; +use bitcoin::{Network, WitnessVersion}; use bitcoin::blockdata::constants::ChainHash; use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, self}; use bitcoin::secp256k1::schnorr::Signature; -use bitcoin::address::{Address, Payload}; +use bitcoin::address::Address; +use bitcoin::blockdata::script::witness_program::WitnessProgram; use core::time::Duration; use core::hash::{Hash, Hasher}; use crate::io; @@ -1074,12 +1075,11 @@ pub(super) fn filter_fallbacks( Err(_) => return None, }; - let program = address.program.clone(); - let witness_program = match WitnessProgram::new(version, program) { + let witness_program = match WitnessProgram::new(version, &address.program) { Ok(witness_program) => witness_program, Err(_) => return None, }; - Some(Address::new(network, Payload::WitnessProgram(witness_program))) + Some(Address::from_witness_program(witness_program, network.into())) }; fallbacks.iter().filter_map(to_valid_address).collect() @@ -1398,13 +1398,13 @@ pub(super) fn check_invoice_signing_pubkey( mod tests { use super::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, FallbackAddress, FullInvoiceTlvStreamRef, InvoiceTlvStreamRef, SIGNATURE_TAG, UnsignedBolt12Invoice}; - use bitcoin::{WitnessProgram, WitnessVersion}; + use bitcoin::{CompressedPublicKey, WitnessProgram, WitnessVersion}; use bitcoin::blockdata::constants::ChainHash; use bitcoin::blockdata::script::ScriptBuf; use bitcoin::hashes::Hash; use bitcoin::network::Network; use bitcoin::secp256k1::{Keypair, Message, Secp256k1, SecretKey, XOnlyPublicKey, self}; - use bitcoin::address::{Address, Payload}; + use bitcoin::address::Address; use bitcoin::key::TweakedPublicKey; use core::time::Duration; @@ -2242,16 +2242,16 @@ mod tests { match Bolt12Invoice::try_from(buffer) { Ok(invoice) => { - let v1_witness_program = WitnessProgram::new(WitnessVersion::V1, vec![0u8; 33]).unwrap(); - let v2_witness_program = WitnessProgram::new(WitnessVersion::V2, vec![0u8; 40]).unwrap(); + let v1_witness_program = WitnessProgram::new(WitnessVersion::V1, &vec![0u8; 33]).unwrap(); + let v2_witness_program = WitnessProgram::new(WitnessVersion::V2, &vec![0u8; 40]).unwrap(); assert_eq!( invoice.fallbacks(), vec![ Address::p2wsh(&script, Network::Bitcoin), - Address::p2wpkh(&pubkey, Network::Bitcoin).unwrap(), + Address::p2wpkh(&CompressedPublicKey(pubkey.inner), Network::Bitcoin).unwrap(), Address::p2tr_tweaked(tweaked_pubkey, Network::Bitcoin), - Address::new(Network::Bitcoin, Payload::WitnessProgram(v1_witness_program)), - Address::new(Network::Bitcoin, Payload::WitnessProgram(v2_witness_program)), + Address::from_witness_program(v1_witness_program, Network::Bitcoin.into()), + Address::from_witness_program(v2_witness_program, Network::Bitcoin.into()), ], ); }, diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 5f109e1a9..42efdc46d 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -1245,9 +1245,35 @@ macro_rules! impl_consensus_ser { } } } + +impl Into for bitcoin::io::ErrorKind { + fn into(self) -> io::ErrorKind { + todo!() + } +} + +impl Writeable for Witness { + fn write(&self, writer: &mut W) -> Result<(), io::Error> { + match self.consensus_encode(&mut WriterWriteAdaptor(writer)) { + Ok(_) => Ok(()), + Err(e) => Err(e.into()), + } + } +} +impl Readable for Witness { + fn read(r: &mut R) -> Result { + match consensus::encode::Decodable::consensus_decode(r) { + Ok(t) => Ok(t), + Err(consensus::encode::Error::Io(ref e)) if e.kind() == bitcoin::io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead), + Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind())), + Err(_) => Err(DecodeError::InvalidValue), + } + } +} + impl_consensus_ser!(Transaction); impl_consensus_ser!(TxOut); -impl_consensus_ser!(Witness); +// impl_consensus_ser!(Witness); impl Readable for Mutex { fn read(r: &mut R) -> Result { -- 2.39.5