]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Upgrade rust-bitcoin to 0.32.2.
authorArik Sosman <git@arik.io>
Fri, 16 Aug 2024 15:02:50 +0000 (08:02 -0700)
committerArik Sosman <git@arik.io>
Fri, 16 Aug 2024 17:31:45 +0000 (10:31 -0700)
39 files changed:
fuzz/Cargo.toml
fuzz/src/chanmon_consistency.rs
fuzz/src/chanmon_deser.rs
fuzz/src/full_stack.rs
fuzz/src/msg_targets/utils.rs
fuzz/src/onion_hop_data.rs
fuzz/src/onion_message.rs
fuzz/src/router.rs
lightning-background-processor/Cargo.toml
lightning-background-processor/src/lib.rs
lightning-block-sync/Cargo.toml
lightning-block-sync/src/convert.rs
lightning-block-sync/src/init.rs
lightning-block-sync/src/utils.rs
lightning-custom-message/Cargo.toml
lightning-invoice/Cargo.toml
lightning-invoice/src/lib.rs
lightning-net-tokio/Cargo.toml
lightning-persister/Cargo.toml
lightning-persister/src/fs_store.rs
lightning-rapid-gossip-sync/Cargo.toml
lightning-rapid-gossip-sync/src/lib.rs
lightning-transaction-sync/Cargo.toml
lightning-transaction-sync/tests/integration_tests.rs
lightning-types/Cargo.toml
lightning/Cargo.toml
lightning/src/chain/channelmonitor.rs
lightning/src/io/mod.rs
lightning/src/lib.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/msgs.rs
lightning/src/offers/invoice.rs
lightning/src/offers/invoice_request.rs
lightning/src/offers/static_invoice.rs
lightning/src/onion_message/offers.rs
lightning/src/routing/router.rs
lightning/src/sign/mod.rs
lightning/src/util/ser.rs
lightning/src/util/test_utils.rs

index 002cc54a91e04cc726d7a1fed167ad940bfb5abd..666474f5366ea5dac89a276f991742fe00e9e10f 100644 (file)
@@ -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 }
index 4322fccb16f215e658f55a3175114e863cb8f777..1cdd3ff1251b93770c3ef3d559a8a2afef0b1507 100644 (file)
@@ -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};
@@ -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(())
        }
@@ -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);
index b9c0121377245cb73b62a23ca24cea4f97c729d8..4a4e79c83c1a2c51f1264d07f0c3d4618bf0e866 100644 (file)
@@ -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(())
        }
index fa0c2906294abbe72b073130a5ea1bdcb97755a5..97cfe631d8d98b97274fb903959ab662c16aa052 100644 (file)
@@ -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())
index 5fa474cbf02f291c9b66194133111c224228fcab..8bf776193e659307c2886c3da5058cb4eb2a0ad7 100644 (file)
@@ -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(())
        }
@@ -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());
@@ -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[..]);
@@ -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();
@@ -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();
index 36aebb4e194e6181cff4b6310e1c481f51148dbd..dd972501df3cd7010e48d6366f555b51f6e9b5a5 100644 (file)
@@ -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>,
@@ -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>,
index 48f184af7091a002a81e2fced86ab4a3d8adde00..536204edf87a2a3c73e718b7c1cba349e070733d 100644 (file)
@@ -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]
@@ -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>> {
@@ -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(())
        }
index 96046f258426e934f018761d8d58efeb36fbe1f9..ea0476c623ebd7f4e22611763193b742f2ad4676 100644 (file)
@@ -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);
index df4b2c8278e718a56e8f430e4000b0aef4bbbe30..c780cc3d64b4f58bed6f251b3fe9615a0ef4e992 100644 (file)
@@ -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 }
 
index e39ae5a7c7ead3186a4a4bbb9131db22d449e1e4..3b01fb595c96a526e87c217f8d107e1cc759053c 100644 (file)
@@ -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());
                                }
                        }
 
@@ -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());
                                }
                        }
 
@@ -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());
                                }
                        }
 
@@ -2002,7 +2002,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");
                        },
                }
index c3a230967b411b0e92533ce9bdf95a452fbc805a..ecae20d807b2d907db2ba866d9259b516cc5b02b 100644 (file)
@@ -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 }
index ea01039f2cc6c7fee0e8a070d2fa697818f4a116..a31b329a5af1aad7954a4c7e2638480067ab2429 100644 (file)
@@ -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"),
                }
@@ -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"),
                }
index cd414f55d61a6a544bf97cfdafa37f7edbd7614d..623f54042295166800a4c1053100b17a9ce3172f 100644 (file)
@@ -59,7 +59,7 @@ where
 ///
 /// use lightning_block_sync::*;
 ///
-/// use std::io::Cursor;
+/// use lightning::io::Cursor;
 ///
 /// async fn init_sync<
 ///    B: BlockSource,
index 494a1e53f34288073cc7928906083789c2d7b786..44027734efb80efed145f4df0e42fe0f6bc7dfb6 100644 (file)
@@ -9,7 +9,6 @@ pub fn hex_to_work(hex: &str) -> Result<Work, HexToArrayError> {
 #[cfg(test)]
 mod tests {
        use super::*;
-       use bitcoin::hex::HexToBytesError;
        use bitcoin::pow::Work;
 
        #[test]
@@ -20,31 +19,25 @@ mod tests {
        #[test]
        fn hex_to_work_too_short_str() {
                let hex = String::from_utf8(vec![b'0'; 32]).unwrap();
-               assert_eq!(hex_to_work(&hex), Err(HexToArrayError::InvalidLength(32, 64)));
+               assert!(hex_to_work(&hex).is_err());
        }
 
        #[test]
        fn hex_to_work_too_long_str() {
                let hex = String::from_utf8(vec![b'0'; 128]).unwrap();
-               assert_eq!(hex_to_work(&hex), Err(HexToArrayError::InvalidLength(128, 64)));
+               assert!(hex_to_work(&hex).is_err());
        }
 
        #[test]
        fn hex_to_work_odd_length_str() {
                let hex = String::from_utf8(vec![b'0'; 65]).unwrap();
-               assert_eq!(
-                       hex_to_work(&hex),
-                       Err(HexToArrayError::Conversion(HexToBytesError::OddLengthString(65)))
-               );
+               assert!(hex_to_work(&hex).is_err());
        }
 
        #[test]
        fn hex_to_work_invalid_char() {
                let hex = String::from_utf8(vec![b'G'; 64]).unwrap();
-               assert_eq!(
-                       hex_to_work(&hex),
-                       Err(HexToArrayError::Conversion(HexToBytesError::InvalidChar(b'G')))
-               );
+               assert!(hex_to_work(&hex).is_err());
        }
 
        #[test]
index f74ead81c9702bab28e4a0b1a669a25ebd952ad0..d3c2e57085e35b96671f98e895bd8a0d423515b2 100644 (file)
@@ -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]
index f73321296d13a002925aa412a6ab335844c14a44..59f411409cbdfffd2d415c89bd52b9bd42834be0 100644 (file)
@@ -16,15 +16,15 @@ rustdoc-args = ["--cfg", "docsrs"]
 
 [features]
 default = ["std"]
-no-std = ["bitcoin/no-std"]
-std = ["bitcoin/std", "bech32/std"]
+no-std = []
+std = ["bech32/std"]
 
 [dependencies]
 bech32 = { version = "0.9.1", default-features = false }
 lightning-types = { version = "0.1", path = "../lightning-types", default-features = false }
-secp256k1 = { version = "0.28.0", default-features = false, features = ["recovery", "alloc"] }
+secp256k1 = { version = "0.29.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]
 serde_json = { version = "1"}
index 56ca21a9b458a9a5d8a1b71ba356b07990282b35..fea0b6850da3c616c0bf08f21eeecb4968627b48 100644 (file)
@@ -39,7 +39,6 @@ use std::time::SystemTime;
 
 use bech32::{FromBase32, u5};
 use bitcoin::{Address, Network, PubkeyHash, ScriptHash, WitnessProgram, WitnessVersion};
-use bitcoin::address::Payload;
 use bitcoin::hashes::{Hash, sha256};
 use lightning_types::features::Bolt11InvoiceFeatures;
 
@@ -1434,22 +1433,22 @@ impl Bolt11Invoice {
        /// Returns a list of all fallback addresses as [`Address`]es
        pub fn fallback_addresses(&self) -> Vec<Address> {
                self.fallbacks().iter().filter_map(|fallback| {
-                       let payload = match fallback {
+                       let address = match fallback {
                                Fallback::SegWitProgram { version, program } => {
-                                       match WitnessProgram::new(*version, program.clone()) {
-                                               Ok(witness_program) => Payload::WitnessProgram(witness_program),
+                                       match WitnessProgram::new(*version, &program) {
+                                               Ok(witness_program) => Address::from_witness_program(witness_program, self.network()),
                                                Err(_) => return None,
                                        }
                                }
                                Fallback::PubKeyHash(pkh) => {
-                                       Payload::PubkeyHash(*pkh)
+                                       Address::p2pkh(*pkh, self.network())
                                }
                                Fallback::ScriptHash(sh) => {
-                                       Payload::ScriptHash(*sh)
+                                       Address::p2sh_from_hash(*sh, self.network())
                                }
                        };
 
-                       Some(Address::new(self.network(), payload))
+                       Some(address)
                }).collect()
        }
 
index c56553711454b4f3aae3885651f0b3793acd9b25..ede8cc0a73a2caae6d7a0fca9bc3bf7b1dd161ad 100644 (file)
@@ -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" ] }
 
index 5f1e2774064f670c624b8d906079701c30f811af..e315fb791b2bd0c3df37703708bf60dccf4b1c09 100644 (file)
@@ -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
index d1e19421c538f0a19b96859dba58dc00b05b2030..dd3a78191c58eb2ff1cf3c1e41ae306ab2a1a53b 100644 (file)
@@ -91,7 +91,7 @@ impl FilesystemStore {
 }
 
 impl KVStore for FilesystemStore {
-       fn read(&self, primary_namespace: &str, secondary_namespace: &str, key: &str) -> std::io::Result<Vec<u8>> {
+       fn read(&self, primary_namespace: &str, secondary_namespace: &str, key: &str) -> lightning::io::Result<Vec<u8>> {
                check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "read")?;
 
                let mut dest_file_path = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
@@ -114,7 +114,7 @@ impl KVStore for FilesystemStore {
                Ok(buf)
        }
 
-       fn write(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
+       fn write(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8]) -> lightning::io::Result<()> {
                check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "write")?;
 
                let mut dest_file_path = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
@@ -191,7 +191,7 @@ impl KVStore for FilesystemStore {
                                                dest_file.sync_all()?;
                                                Ok(())
                                        }
-                                       Err(e) => Err(e),
+                                       Err(e) => Err(e.into()),
                                }
                        }
                };
@@ -201,7 +201,7 @@ impl KVStore for FilesystemStore {
                res
        }
 
-       fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> std::io::Result<()> {
+       fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> lightning::io::Result<()> {
                check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "remove")?;
 
                let mut dest_file_path = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
@@ -290,7 +290,7 @@ impl KVStore for FilesystemStore {
                Ok(())
        }
 
-       fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> std::io::Result<Vec<String>> {
+       fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> lightning::io::Result<Vec<String>> {
                check_namespace_key_validity(primary_namespace, secondary_namespace, None, "list")?;
 
                let prefixed_dest = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
@@ -331,7 +331,7 @@ impl KVStore for FilesystemStore {
                                        PrintableString(primary_namespace), PrintableString(secondary_namespace));
                                let msg = format!("Failed to list keys of {}/{}: file couldn't be accessed.",
                                        PrintableString(primary_namespace), PrintableString(secondary_namespace));
-                               return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
+                               return Err(lightning::io::Error::new(lightning::io::ErrorKind::Other, msg));
                        }
 
                        match p.strip_prefix(&prefixed_dest) {
@@ -345,7 +345,7 @@ impl KVStore for FilesystemStore {
                                                        PrintableString(primary_namespace), PrintableString(secondary_namespace));
                                                let msg = format!("Failed to list keys of {}/{}: file path is not valid UTF-8",
                                                        PrintableString(primary_namespace), PrintableString(secondary_namespace));
-                                               return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
+                                               return Err(lightning::io::Error::new(lightning::io::ErrorKind::Other, msg));
                                        }
                                }
                                Err(e) => {
@@ -353,7 +353,7 @@ impl KVStore for FilesystemStore {
                                                PrintableString(primary_namespace), PrintableString(secondary_namespace), e);
                                        let msg = format!("Failed to list keys of {}/{}: {}",
                                                PrintableString(primary_namespace), PrintableString(secondary_namespace), e);
-                                       return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
+                                       return Err(lightning::io::Error::new(lightning::io::ErrorKind::Other, msg));
                                }
                        }
                }
index 7ca67a38ec8d5faf2507fda441d4917632023a08..9d9f3d23eb0330843a18c32df106df63c6af0597 100644 (file)
@@ -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 }
index 25a94e77692e33d895b3f5c2ae393ffe4cb23c44..04b564f04c08c7c0d16c61662c0ef93a85679147 100644 (file)
@@ -70,9 +70,6 @@ extern crate alloc;
 
 use core::ops::Deref;
 use core::sync::atomic::{AtomicBool, Ordering};
-#[cfg(feature = "std")]
-use std::fs::File;
-
 use lightning::io;
 use lightning::ln::msgs::{DecodeError, LightningError};
 use lightning::routing::gossip::NetworkGraph;
@@ -146,12 +143,16 @@ where
        ///
        /// `sync_path`: Path to the file where the gossip update data is located
        ///
-       #[cfg(feature = "std")]
+       #[cfg(all(feature = "std", not(feature = "no-std")))]
        pub fn sync_network_graph_with_file_path(
                &self, sync_path: &str,
        ) -> Result<u32, GraphSyncError> {
-               let mut file = File::open(sync_path)?;
-               self.update_network_graph_from_byte_stream(&mut file)
+               let file = std::fs::File::open(sync_path).map_err(|e| {
+                       let bitcoin_error: lightning::io::Error = e.into();
+                       bitcoin_error
+               })?;
+               let mut buf_reader = std::io::BufReader::new(file);
+               self.update_network_graph_from_byte_stream(&mut buf_reader)
        }
 
        /// Update network graph from binary data.
@@ -190,7 +191,7 @@ where
        }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", not(feature = "no-std")))]
 #[cfg(test)]
 mod tests {
        use std::fs;
index 5ef9ef3e46f5619daa7612a818a8d1816caabde7..a53e04cc7ee1f1b2b33427c09e64aa9f89e7acc0 100644 (file)
@@ -24,18 +24,18 @@ 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 }
-electrum-client = { version = "0.19.0", optional = true }
+esplora-client = { version = "0.9", default-features = false, optional = true }
+electrum-client = { version = "0.21.0", optional = true }
 
 [dev-dependencies]
 lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false, features = ["std", "_test_utils"] }
 tokio = { version = "1.35.0", features = ["full"] }
 
 [target.'cfg(not(target_os = "windows"))'.dev-dependencies]
-electrsd = { version = "0.27.3", default-features = false, features = ["legacy"] }
+electrsd = { version = "0.28.0", default-features = false, features = ["legacy"] }
 
 [lints]
 workspace = true
index 56c0f6a018f39e3032918a34c013da3ff4de02e3..2cf913b5667fdfb784b9e61ab7ead0a2b0e8a949 100644 (file)
@@ -205,7 +205,7 @@ macro_rules! test_syncing {
                                None,
                        )
                        .unwrap();
-               $tx_sync.register_tx(&txid, &new_address.payload().script_pubkey());
+               $tx_sync.register_tx(&txid, &new_address.script_pubkey());
 
                maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();
 
index a063176ae573a2bec5cdae3bdb2c3805e1b1f813..9e8feedf6efc4def5563b074765f70311f778b02 100644 (file)
@@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
 _test_utils = []
 
 [dependencies]
-bitcoin = { version = "0.31", default-features = false }
+bitcoin = { version = "0.32.2", default-features = false }
 # TODO: Once we switch to bitcoin 0.32 drop this explicit dep:
 hex-conservative = { version = "0.2", default-features = false }
 bech32 = { version = "0.9", default-features = false }
index c6d82113053155a35227cfe23ff3e50c5d2ba4fd..9f310c12dbc0102bc60f81f3865da80934af63d8 100644 (file)
@@ -31,8 +31,8 @@ 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", "lightning-invoice/no-std", "core2/alloc", "libm"]
-std = ["bitcoin/std", "bech32/std", "lightning-invoice/std"]
+no-std = ["hashbrown", "possiblyrandom", "lightning-invoice/no-std", "libm"]
+std = ["lightning-invoice/std", "bech32/std"]
 
 # Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases
 grind_signatures = []
@@ -44,14 +44,13 @@ lightning-types = { version = "0.1", path = "../lightning-types", default-featur
 lightning-invoice = { version = "0.31.0-beta", path = "../lightning-invoice", default-features = false }
 
 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 }
 regex = { version = "1.5.6", optional = true }
 backtrace = { version = "0.3", optional = true }
 
-core2 = { version = "0.3.0", optional = true, default-features = false }
 libm = { version = "0.2", optional = true, default-features = false }
 
 [dev-dependencies]
@@ -59,7 +58,7 @@ regex = "1.5.6"
 lightning-types = { version = "0.1", path = "../lightning-types", features = ["_test_utils"] }
 
 [dev-dependencies.bitcoin]
-version = "0.31.2"
+version = "0.32.2"
 default-features = false
 features = ["bitcoinconsensus", "secp-recovery"]
 
@@ -67,7 +66,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
index b9ced655399dae88977a8667ac546f9cf6569f66..68bdba1c9b88fe67f4e3da2323606577f89ab95e 100644 (file)
@@ -30,9 +30,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 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::secp256k1::{self, SecretKey, PublicKey, Secp256k1, ecdsa::Signature};
 
 use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
 use crate::ln::types::{PaymentHash, PaymentPreimage, ChannelId};
@@ -4235,7 +4233,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
 
                                                                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(&bitcoin::CompressedPublicKey(bitcoin::PublicKey::from_slice(&input.witness.last().unwrap()).unwrap().inner), bitcoin::Network::Bitcoin).script_pubkey(), _script_pubkey);
                                                        } else { panic!(); }
                                                }
                                                return true;
index 1efcd451101e239ec873b3e0c3f49c196e9c2a88..2f742e2426fa394ef2f1302f131e480b72a25c0d 100644 (file)
@@ -1,9 +1,4 @@
-#[cfg(not(feature = "std"))]
-/// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag.
-pub use core2::io::*;
-#[cfg(feature = "std")]
-/// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag.
-pub use std::io::*;
+pub use bitcoin::io::*;
 
 /// Emulation of std::io::Cursor
 #[derive(Clone, Debug, Default, Eq, PartialEq)]
index fc860adaabf361978f5d6d7f2e1257a4643cbda8..2215f82bda75e7582360f71dfcef7ac1ae493e66 100644 (file)
@@ -70,7 +70,6 @@ extern crate core;
 
 #[cfg(any(test, feature = "_test_utils"))] extern crate regex;
 
-#[cfg(not(feature = "std"))] extern crate core2;
 #[cfg(not(feature = "std"))] extern crate libm;
 
 #[cfg(ldk_bench)] extern crate criterion;
@@ -91,35 +90,15 @@ pub(crate) mod crypto;
 /// Extension of the bitcoin::io module
 pub mod io;
 
-#[cfg(not(feature = "std"))]
 #[doc(hidden)]
 /// IO utilities public only for use by in-crate macros. These should not be used externally
 ///
 /// This is not exported to bindings users as it is not intended for public consumption.
 pub mod io_extras {
-       use core2::io::{self, Read, Write};
-
-       /// A writer which will move data into the void.
-       pub struct Sink {
-               _priv: (),
-       }
+       use bitcoin::io::{self, Read, Write};
 
        /// Creates an instance of a writer which will successfully consume all data.
-       pub const fn sink() -> Sink {
-               Sink { _priv: () }
-       }
-
-       impl core2::io::Write for Sink {
-               #[inline]
-               fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> {
-                       Ok(buf.len())
-               }
-
-               #[inline]
-               fn flush(&mut self) -> core2::io::Result<()> {
-                       Ok(())
-               }
-       }
+       pub use bitcoin::io::sink;
 
        pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> Result<u64, io::Error>
                where
@@ -155,21 +134,6 @@ pub mod io_extras {
        }
 }
 
-#[cfg(feature = "std")]
-#[doc(hidden)]
-/// IO utilities public only for use by in-crate macros. These should not be used externally
-///
-/// This is not exported to bindings users as it is not intended for public consumption.
-mod io_extras {
-       pub fn read_to_end<D: ::std::io::Read>(mut d: D) -> Result<Vec<u8>, ::std::io::Error> {
-               let mut buf = Vec::new();
-               d.read_to_end(&mut buf)?;
-               Ok(buf)
-       }
-
-       pub use std::io::{copy, sink};
-}
-
 mod prelude {
        #![allow(unused_imports)]
 
index 6d47e1b9d4411a0695672ea52bc2a0b59c67cad0..407bfd3db708907c2fc1af2c1b250639feb56423 100644 (file)
@@ -766,7 +766,7 @@ pub fn build_htlc_input_witness(
        let mut witness = Witness::new();
        // First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
        witness.push(vec![]);
-       witness.push_ecdsa_signature(&BitcoinSignature { sig: *remote_sig, hash_ty: remote_sighash_type });
+       witness.push_ecdsa_signature(&BitcoinSignature { signature: *remote_sig, sighash_type: remote_sighash_type });
        witness.push_ecdsa_signature(&BitcoinSignature::sighash_all(*local_sig));
        if let Some(preimage) = preimage {
                witness.push(preimage.0.to_vec());
@@ -1872,11 +1872,10 @@ mod tests {
        use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
        use crate::util::test_utils;
        use crate::sign::{ChannelSigner, SignerProvider};
-       use bitcoin::{Network, Txid, ScriptBuf};
+       use bitcoin::{Network, Txid, ScriptBuf, CompressedPublicKey};
        use bitcoin::hashes::Hash;
        use bitcoin::hex::FromHex;
        use crate::ln::types::PaymentHash;
-       use bitcoin::address::Payload;
        use bitcoin::PublicKey as BitcoinPublicKey;
        use crate::ln::features::ChannelTypeFeatures;
 
@@ -1949,7 +1948,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, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
 
                // Generate broadcaster and counterparty outputs as well as two anchors
                builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
index d04cfa7faf7e3ebcb30e6699ac63d527cd0c8635..9fa130006f2fde26a11d331fb97a5f27543e6fb1 100644 (file)
@@ -2786,7 +2786,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload w
                }, |msg_type: u64, msg_reader: &mut FixedLengthReader<_>| -> Result<bool, DecodeError> {
                        if msg_type < 1 << 16 { return Ok(false) }
                        let mut value = Vec::new();
-                       msg_reader.read_to_end(&mut value)?;
+                       msg_reader.read_to_limit(&mut value, u64::MAX)?;
                        custom_tlvs.push((msg_type, value));
                        Ok(true)
                });
@@ -4007,11 +4007,11 @@ mod tests {
                                output: vec![
                                        TxOut {
                                                value: Amount::from_sat(12704566),
-                                               script_pubkey: Address::from_str("bc1qzlffunw52jav8vwdu5x3jfk6sr8u22rmq3xzw2").unwrap().payload().script_pubkey(),
+                                               script_pubkey: Address::from_str("bc1qzlffunw52jav8vwdu5x3jfk6sr8u22rmq3xzw2").unwrap().assume_checked().script_pubkey(),
                                        },
                                        TxOut {
                                                value: Amount::from_sat(245148),
-                                               script_pubkey: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().payload().script_pubkey(),
+                                               script_pubkey: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().assume_checked().script_pubkey(),
                                        },
                                ],
                        }).unwrap(),
@@ -4030,7 +4030,7 @@ mod tests {
                        channel_id: ChannelId::from_bytes([2; 32]),
                        serial_id: 4886718345,
                        sats: 4886718345,
-                       script: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().payload().script_pubkey(),
+                       script: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().assume_checked().script_pubkey(),
                };
                let encoded_value = tx_add_output.encode();
                let target_value = <Vec<u8>>::from_hex("0202020202020202020202020202020202020202020202020202020202020202000000012345678900000001234567890016001436ec78d514df462da95e6a00c24daa8915362d42").unwrap();
@@ -4179,7 +4179,7 @@ mod tests {
                        scriptpubkey:
                                if script_type == 1 { Address::p2pkh(&::bitcoin::PublicKey{compressed: true, inner: pubkey_1}, Network::Testnet).script_pubkey() }
                                else if script_type == 2 { Address::p2sh(&script, Network::Testnet).unwrap().script_pubkey() }
-                               else if script_type == 3 { Address::p2wpkh(&::bitcoin::PublicKey{compressed: true, inner: pubkey_1}, Network::Testnet).unwrap().script_pubkey() }
+                               else if script_type == 3 { Address::p2wpkh(&::bitcoin::CompressedPublicKey(pubkey_1), Network::Testnet).script_pubkey() }
                                else { Address::p2wsh(&script, Network::Testnet).script_pubkey() },
                };
                let encoded_value = shutdown.encode();
index 39423f94c810f5a971c21e20bd8a4cfa931d89a6..c948511354f548088c3a607bc6c2938f72febcb2 100644 (file)
@@ -106,7 +106,7 @@ use bitcoin::{WitnessProgram, Network, WitnessVersion};
 use bitcoin::constants::ChainHash;
 use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, self};
 use bitcoin::secp256k1::schnorr::Signature;
-use bitcoin::address::{Address, Payload};
+use bitcoin::address::Address;
 use core::time::Duration;
 use core::hash::{Hash, Hasher};
 use crate::io;
@@ -1098,12 +1098,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))
        };
 
        fallbacks.iter().filter_map(to_valid_address).collect()
@@ -1422,13 +1421,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::constants::ChainHash;
        use bitcoin::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;
@@ -1993,7 +1992,7 @@ mod tests {
                        invoice.fallbacks(),
                        vec![
                                Address::p2wsh(&script, Network::Bitcoin),
-                               Address::p2wpkh(&pubkey, Network::Bitcoin).unwrap(),
+                               Address::p2wpkh(&CompressedPublicKey(pubkey.inner), Network::Bitcoin),
                                Address::p2tr_tweaked(tweaked_pubkey, Network::Bitcoin),
                        ],
                );
@@ -2063,7 +2062,7 @@ mod tests {
                        .sign(payer_sign)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SignError::Verification(secp256k1::Error::InvalidSignature)),
+                       Err(e) => assert_eq!(e, SignError::Verification(secp256k1::Error::IncorrectSignature)),
                }
        }
 
@@ -2301,16 +2300,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, &[0u8; 33]).unwrap();
+                               let v2_witness_program = WitnessProgram::new(WitnessVersion::V2, &[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),
                                                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),
+                                               Address::from_witness_program(v2_witness_program, Network::Bitcoin),
                                        ],
                                );
                        },
@@ -2474,7 +2473,7 @@ mod tests {
                match Bolt12Invoice::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
+                               assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::IncorrectSignature));
                        },
                }
        }
index f8815beb6d3bf7c456685a406161a37815014ed6..4b73231f62b36964fc143dfa2368e49e443660fd 100644 (file)
@@ -1889,7 +1889,7 @@ mod tests {
                        .sign(recipient_sign)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SignError::Verification(secp256k1::Error::InvalidSignature)),
+                       Err(e) => assert_eq!(e, SignError::Verification(secp256k1::Error::IncorrectSignature)),
                }
        }
 
@@ -2276,7 +2276,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
+                               assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::IncorrectSignature));
                        },
                }
        }
index 93014fce22aa7ca1f9b1540b7b1d06f9313808ce..a49b20bdff2606aa36c7bcea98ad7551165d1e24 100644 (file)
@@ -1128,7 +1128,7 @@ mod tests {
                        Err(e) => {
                                assert_eq!(
                                        e,
-                                       Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature)
+                                       Bolt12ParseError::InvalidSignature(secp256k1::Error::IncorrectSignature)
                                );
                        },
                }
index 6884ca77e069cdbdac5afb44fe0c9fbedcc9a684..d1ed089ed35ad910bbf1ee7b365ddfd389329839 100644 (file)
@@ -172,7 +172,7 @@ impl<L: Logger + ?Sized> ReadableArgs<(u64, &L)> for OffersMessage {
                }
 
                let mut bytes = Vec::new();
-               r.read_to_end(&mut bytes).unwrap();
+               r.read_to_limit(&mut bytes, u64::MAX).unwrap();
 
                match Self::parse(tlv_type, bytes) {
                        Ok(message) => Ok(message),
index bf894f0ebb6de49fdae6a62b8078b5644ac36e75..6f378a561ed1cc2191626f90314e170ff18f3bbf 100644 (file)
@@ -8785,7 +8785,7 @@ mod tests {
 pub(crate) mod bench_utils {
        use super::*;
        use std::fs::File;
-
+       use std::io::Read;
        use bitcoin::hashes::Hash;
        use bitcoin::secp256k1::SecretKey;
 
@@ -8845,9 +8845,13 @@ pub(crate) mod bench_utils {
        pub(crate) fn read_graph_scorer(logger: &TestLogger)
        -> Result<(Arc<NetworkGraph<&TestLogger>>, ProbabilisticScorer<Arc<NetworkGraph<&TestLogger>>, &TestLogger>), &'static str> {
                let (mut graph_file, mut scorer_file) = get_graph_scorer_file()?;
-               let graph = Arc::new(NetworkGraph::read(&mut graph_file, logger).unwrap());
+               let mut graph_buffer = Vec::new();
+               let mut scorer_buffer = Vec::new();
+               graph_file.read_to_end(&mut graph_buffer).unwrap();
+               scorer_file.read_to_end(&mut scorer_buffer).unwrap();
+               let graph = Arc::new(NetworkGraph::read(&mut &graph_buffer[..], logger).unwrap());
                let scorer_args = (Default::default(), Arc::clone(&graph), logger);
-               let scorer = ProbabilisticScorer::read(&mut scorer_file, scorer_args).unwrap();
+               let scorer = ProbabilisticScorer::read(&mut &scorer_buffer[..], scorer_args).unwrap();
                Ok((graph, scorer))
        }
 
index 1dd8c90f65f3788484664ab77a3a17b3a3f3a07a..63692bab511d7846a001a19d6e64b967f9006ac2 100644 (file)
@@ -1327,8 +1327,8 @@ impl InMemorySigner {
                                .unwrap()[..]
                );
                let local_delayedsig = EcdsaSignature {
-                       sig: sign_with_aux_rand(secp_ctx, &sighash, &delayed_payment_key, &self),
-                       hash_ty: EcdsaSighashType::All,
+                       signature: sign_with_aux_rand(secp_ctx, &sighash, &delayed_payment_key, &self),
+                       sighash_type: EcdsaSighashType::All,
                };
                let payment_script =
                        bitcoin::Address::p2wsh(&witness_script, Network::Bitcoin).script_pubkey();
@@ -2106,13 +2106,12 @@ impl KeysManager {
                                        };
                                        let pubkey = Xpub::from_priv(&secp_ctx, &secret).to_pub();
                                        if derivation_idx == 2 {
-                                               assert_eq!(pubkey.inner, self.shutdown_pubkey);
+                                               assert_eq!(pubkey.0, self.shutdown_pubkey);
                                        }
                                        let witness_script =
                                                bitcoin::Address::p2pkh(&pubkey, Network::Testnet).script_pubkey();
-                                       let payment_script = bitcoin::Address::p2wpkh(&pubkey, Network::Testnet)
-                                               .expect("uncompressed key found")
-                                               .script_pubkey();
+                                       let payment_script =
+                                               bitcoin::Address::p2wpkh(&pubkey, Network::Testnet).script_pubkey();
 
                                        if payment_script != output.script_pubkey {
                                                return Err(());
@@ -2131,8 +2130,7 @@ impl KeysManager {
                                        let sig = sign_with_aux_rand(secp_ctx, &sighash, &secret.private_key, &self);
                                        let mut sig_ser = sig.serialize_der().to_vec();
                                        sig_ser.push(EcdsaSighashType::All as u8);
-                                       let witness =
-                                               Witness::from_slice(&[&sig_ser, &pubkey.inner.serialize().to_vec()]);
+                                       let witness = Witness::from_slice(&[&sig_ser, &pubkey.0.serialize().to_vec()]);
                                        psbt.inputs[input_idx].final_script_witness = Some(witness);
                                },
                        }
index e3e97f2d6f08b8ad472cd2e24032b5ec1b58dab4..7c1f97071e87c6582fed313594b555ae4c72d598 100644 (file)
@@ -14,7 +14,7 @@
 //! [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
 
 use crate::prelude::*;
-use crate::io::{self, Read, Write};
+use crate::io::{self, BufRead, Read, Write};
 use crate::io_extras::{copy, sink};
 use core::hash::Hash;
 use crate::sync::{Mutex, RwLock};
@@ -64,6 +64,64 @@ impl<W: Write> Writer for W {
        }
 }
 
+/// Wrap buffering support for implementations of Read.
+/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
+/// every read, implementing [`BufRead`].
+///
+/// In order to avoid reading bytes past the first object, and those bytes then ending up getting
+/// dropped, this BufReader operates in one-byte-increments.
+struct BufReader<'a, R: Read> {
+       inner: &'a mut R,
+       buf: [u8; 1],
+       is_consumed: bool
+}
+
+impl<'a, R: Read> BufReader<'a, R> {
+       /// Creates a [`BufReader`] which will read from the given `inner`.
+       pub fn new(inner: &'a mut R) -> Self {
+               BufReader {
+                       inner,
+                       buf: [0; 1],
+                       is_consumed: true
+               }
+       }
+}
+
+impl<'a, R: Read> Read for BufReader<'a, R> {
+       #[inline]
+       fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
+               let input = self.fill_buf()?;
+               let count = cmp::min(input.len(), output.len());
+               output[..count].copy_from_slice(&input[..count]);
+               self.consume(count);
+               Ok(count)
+       }
+}
+
+impl<'a, R: Read> BufRead for BufReader<'a, R> {
+       #[inline]
+       fn fill_buf(&mut self) -> io::Result<&[u8]> {
+               if self.is_consumed {
+                       let count = self.inner.read(&mut self.buf[..])?;
+                       debug_assert!(count <= 1, "read gave us a garbage length");
+
+                       // upon hitting EOF, assume the byte is already consumed
+                       self.is_consumed = count == 0;
+               }
+
+               Ok(&self.buf[..])
+       }
+
+       #[inline]
+       fn consume(&mut self, amount: usize) {
+               if amount >= 1 {
+                       debug_assert_eq!(amount, 1, "Can only consume one byte");
+                       debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
+                       self.is_consumed = true;
+               }
+       }
+}
+
 pub(crate) struct WriterWriteAdaptor<'a, W: Writer + 'a>(pub &'a mut W);
 impl<'a, W: Writer + 'a> Write for WriterWriteAdaptor<'a, W> {
        #[inline]
@@ -1247,10 +1305,11 @@ macro_rules! impl_consensus_ser {
 
                impl Readable for $bitcoin_type {
                        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
-                               match consensus::encode::Decodable::consensus_decode(r) {
+                               let mut reader = BufReader::<_>::new(r);
+                               match consensus::encode::Decodable::consensus_decode(&mut reader) {
                                        Ok(t) => Ok(t),
                                        Err(consensus::encode::Error::Io(ref e)) if e.kind() == io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead),
-                                       Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind())),
+                                       Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind().into())),
                                        Err(_) => Err(DecodeError::InvalidValue),
                                }
                        }
index f5256064edf84a3657f4758e812d7da007798c6e..b639cb67338489abaedab68c668e634530d212f0 100644 (file)
@@ -1592,8 +1592,8 @@ impl WalletSource for TestWalletSource {
                                let sighash = SighashCache::new(&tx)
                                        .legacy_signature_hash(i, &utxo.output.script_pubkey, EcdsaSighashType::All as u32)
                                        .map_err(|_| ())?;
-                               let sig = self.secp.sign_ecdsa(&secp256k1::Message::from_digest(sighash.to_byte_array()), &self.secret_key);
-                               let bitcoin_sig = bitcoin::ecdsa::Signature { sig, hash_ty: EcdsaSighashType::All };
+                               let signature = self.secp.sign_ecdsa(&secp256k1::Message::from_digest(sighash.to_byte_array()), &self.secret_key);
+                               let bitcoin_sig = bitcoin::ecdsa::Signature { signature, sighash_type: EcdsaSighashType::All };
                                tx.input[i].script_sig = Builder::new()
                                        .push_slice(&bitcoin_sig.serialize())
                                        .push_slice(&self.secret_key.public_key(&self.secp).serialize())