From aeee8fe31efd6b34aa9bde2eb852a2462c6c4119 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 31 Jul 2024 05:46:33 -0500 Subject: [PATCH] Remove explicit dependency on hex-conservative The `hex` crate is re-exported by `rust-bitcoin` so we can get it from there instead of explicitly depending on it. Doing so reduces the maintenance burden and helps reduce the likelyhood of getting two versions in the dependency graph. --- fuzz/Cargo.toml | 1 - fuzz/src/lib.rs | 1 - lightning-block-sync/Cargo.toml | 1 - lightning-block-sync/src/convert.rs | 2 +- lightning-invoice/Cargo.toml | 1 - lightning-invoice/tests/ser_de.rs | 1 - lightning/Cargo.toml | 1 - lightning/src/lib.rs | 1 - lightning/src/ln/channel.rs | 2 +- lightning/src/ln/msgs.rs | 2 +- lightning/src/ln/peer_channel_encryptor.rs | 4 ++-- lightning/src/ln/types.rs | 2 +- lightning/src/routing/gossip.rs | 4 ++-- lightning/src/routing/utxo.rs | 2 +- 14 files changed, 9 insertions(+), 16 deletions(-) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 4d9f7e0de..002cc54a9 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -23,7 +23,6 @@ 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"] } -hex = { package = "hex-conservative", version = "0.1.1", default-features = false } afl = { version = "0.12", optional = true } honggfuzz = { version = "0.5", optional = true, default-features = false } diff --git a/fuzz/src/lib.rs b/fuzz/src/lib.rs index 2e132edce..123ee88ea 100644 --- a/fuzz/src/lib.rs +++ b/fuzz/src/lib.rs @@ -8,7 +8,6 @@ // licenses. extern crate bitcoin; -extern crate hex; extern crate lightning; extern crate lightning_rapid_gossip_sync; diff --git a/lightning-block-sync/Cargo.toml b/lightning-block-sync/Cargo.toml index 2e8270000..c3a230967 100644 --- a/lightning-block-sync/Cargo.toml +++ b/lightning-block-sync/Cargo.toml @@ -19,7 +19,6 @@ rpc-client = [ "serde_json", "chunked_transfer" ] [dependencies] bitcoin = "0.31.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 } serde_json = { version = "1.0", optional = true } diff --git a/lightning-block-sync/src/convert.rs b/lightning-block-sync/src/convert.rs index 7a1bc02ac..9ab6ef23c 100644 --- a/lightning-block-sync/src/convert.rs +++ b/lightning-block-sync/src/convert.rs @@ -294,8 +294,8 @@ pub(crate) mod tests { use super::*; use bitcoin::constants::genesis_block; use bitcoin::hashes::Hash; + use bitcoin::hex::DisplayHex; use bitcoin::network::Network; - use hex::DisplayHex; use serde_json::value::Number; use serde_json::Value; diff --git a/lightning-invoice/Cargo.toml b/lightning-invoice/Cargo.toml index d89f8d08e..94b307167 100644 --- a/lightning-invoice/Cargo.toml +++ b/lightning-invoice/Cargo.toml @@ -28,7 +28,6 @@ bitcoin = { version = "0.31.2", default-features = false } [dev-dependencies] lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false, features = ["_test_utils"] } -hex = { package = "hex-conservative", version = "0.1.1", default-features = false } serde_json = { version = "1"} hashbrown = { version = "0.13", default-features = false } diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index 6b5e99476..356cc9ae6 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -2,7 +2,6 @@ extern crate bech32; extern crate lightning; extern crate lightning_invoice; extern crate secp256k1; -extern crate hex; use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion}; use bitcoin::hashes::hex::FromHex; diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index cf4a53294..a0f1e4027 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -45,7 +45,6 @@ bitcoin = { version = "0.31.2", default-features = false, features = ["secp-reco hashbrown = { version = "0.13", optional = true, default-features = false } possiblyrandom = { version = "0.2", optional = true, default-features = false } -hex = { package = "hex-conservative", version = "0.1.1", default-features = false } regex = { version = "1.5.6", optional = true } backtrace = { version = "0.3", optional = true } diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 5274ea0bf..54652e320 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -65,7 +65,6 @@ pub extern crate bitcoin; #[cfg(any(test, feature = "std"))] extern crate core; -extern crate hex; #[cfg(any(test, feature = "_test_utils"))] extern crate regex; #[cfg(not(feature = "std"))] extern crate core2; diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 9abe99789..7dd11b643 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -10274,6 +10274,7 @@ mod tests { use bitcoin::sighash::EcdsaSighashType; use bitcoin::hashes::hex::FromHex; use bitcoin::hash_types::Txid; + use bitcoin::hex::DisplayHex; use bitcoin::secp256k1::Message; use crate::sign::{ChannelDerivationParameters, HTLCDescriptor, ecdsa::EcdsaChannelSigner}; use crate::ln::PaymentPreimage; @@ -10283,7 +10284,6 @@ mod tests { use crate::util::logger::Logger; use crate::sync::Arc; use core::str::FromStr; - use hex::DisplayHex; // Test vectors from BOLT 3 Appendices C and F (anchors): let feeest = TestFeeEstimator{fee_est: 15000}; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index a41072add..82d0e6a83 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -3267,7 +3267,7 @@ impl_writeable_msg!(GossipTimestampFilter, { #[cfg(test)] mod tests { use bitcoin::{Amount, Transaction, TxIn, ScriptBuf, Sequence, Witness, TxOut}; - use hex::DisplayHex; + use bitcoin::hex::DisplayHex; use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret}; use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, CommonOpenChannelFields, CommonAcceptChannelFields, TrampolineOnionPacket}; diff --git a/lightning/src/ln/peer_channel_encryptor.rs b/lightning/src/ln/peer_channel_encryptor.rs index 51e34bdb9..df2a7bd89 100644 --- a/lightning/src/ln/peer_channel_encryptor.rs +++ b/lightning/src/ln/peer_channel_encryptor.rs @@ -17,13 +17,13 @@ use crate::ln::wire; use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::sha256::Hash as Sha256; +use bitcoin::hex::DisplayHex; + use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::{PublicKey,SecretKey}; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1; -use hex::DisplayHex; - use crate::crypto::chacha20poly1305rfc::ChaCha20Poly1305RFC; use crate::crypto::utils::hkdf_extract_expand_twice; use crate::util::ser::VecWriter; diff --git a/lightning/src/ln/types.rs b/lightning/src/ln/types.rs index c6fa59867..b81323978 100644 --- a/lightning/src/ln/types.rs +++ b/lightning/src/ln/types.rs @@ -200,7 +200,7 @@ mod tests { sha256::Hash as Sha256, }; use bitcoin::secp256k1::PublicKey; - use hex::DisplayHex; + use bitcoin::hex::DisplayHex; use super::ChannelId; use crate::ln::channel_keys::RevocationBasepoint; diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index f058aa747..a74a599ae 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -158,10 +158,10 @@ impl TryFrom for PublicKey { } impl FromStr for NodeId { - type Err = hex::parse::HexToArrayError; + type Err = bitcoin::hex::parse::HexToArrayError; fn from_str(s: &str) -> Result { - let data: [u8; PUBLIC_KEY_SIZE] = hex::FromHex::from_hex(s)?; + let data: [u8; PUBLIC_KEY_SIZE] = bitcoin::hex::FromHex::from_hex(s)?; Ok(NodeId(data)) } } diff --git a/lightning/src/routing/utxo.rs b/lightning/src/routing/utxo.rs index a8fe58831..f885c47ef 100644 --- a/lightning/src/routing/utxo.rs +++ b/lightning/src/routing/utxo.rs @@ -17,7 +17,7 @@ use bitcoin::TxOut; use bitcoin::amount::Amount; use bitcoin::constants::ChainHash; -use hex::DisplayHex; +use bitcoin::hex::DisplayHex; use crate::events::MessageSendEvent; use crate::ln::chan_utils::make_funding_redeemscript_from_slices; -- 2.39.5