]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move `[u8; 32]` wrapper types to a common module
authorMatt Corallo <git@bluematt.me>
Wed, 1 May 2024 15:49:59 +0000 (15:49 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 1 May 2024 19:01:40 +0000 (19:01 +0000)
The `PaymentHash`, `PaymentSecret`, `PaymentPreimage`, and
`ChannelId` types are all small wrappers around `[u8; 32]` and are
used throughout the codebase but were defined in the top-level
`ln/mod.rs` file and the relatively sparsely-populated
`ln/channel_id.rs` file.

Here we move them to a common `types` module and go ahead and
update all our in-crate `use` statements to refer to the new
module for bindings. We do, however, leave a `pub use` alias for
the old paths to avoid upgrade hassle for users.

53 files changed:
lightning-background-processor/src/lib.rs
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/payment.rs
lightning-invoice/src/utils.rs
lightning/src/blinded_path/payment.rs
lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs
lightning/src/chain/mod.rs
lightning/src/chain/onchaintx.rs
lightning/src/chain/package.rs
lightning/src/chain/transaction.rs
lightning/src/events/bump_transaction.rs
lightning/src/events/mod.rs
lightning/src/ln/blinded_payment_tests.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channel.rs
lightning/src/ln/channel_id.rs [deleted file]
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/inbound_payment.rs
lightning/src/ln/interactivetxs.rs
lightning/src/ln/mod.rs
lightning/src/ln/monitor_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onion_payment.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/onion_utils.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/priv_short_conf_tests.rs
lightning/src/ln/reload_tests.rs
lightning/src/ln/reorg_tests.rs
lightning/src/ln/shutdown_tests.rs
lightning/src/ln/types.rs [new file with mode: 0644]
lightning/src/offers/invoice.rs
lightning/src/offers/invoice_request.rs
lightning/src/offers/refund.rs
lightning/src/offers/test_utils.rs
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs
lightning/src/sign/ecdsa.rs
lightning/src/sign/mod.rs
lightning/src/util/logger.rs
lightning/src/util/macro_logger.rs
lightning/src/util/ser.rs
lightning/src/util/sweep.rs
lightning/src/util/test_channel_signer.rs
lightning/src/util/test_utils.rs
rustfmt_excluded_files

index 77c4fb66847a2303f6e10d1fcc24a37fe7c52cd2..ad1056ea92222007c49e4ca7a364a7408e16d570 100644 (file)
@@ -932,7 +932,7 @@ mod tests {
        use lightning::chain::transaction::OutPoint;
        use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
        use lightning::{get_event_msg, get_event};
-       use lightning::ln::{PaymentHash, ChannelId};
+       use lightning::ln::types::{PaymentHash, ChannelId};
        use lightning::ln::channelmanager;
        use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
        use lightning::ln::features::{ChannelFeatures, NodeFeatures};
index 56e5c53ba1f281e01fb274914b108b0f026ff660..674518272d01c72d92e9a535d8e066d9077b5fc2 100644 (file)
@@ -15,7 +15,7 @@ use bitcoin::address::WitnessVersion;
 use bitcoin::hashes::Hash;
 use bitcoin::hashes::sha256;
 use crate::prelude::*;
-use lightning::ln::PaymentSecret;
+use lightning::ln::types::PaymentSecret;
 use lightning::routing::gossip::RoutingFees;
 use lightning::routing::router::{RouteHint, RouteHintHop};
 
index f06eeaa1744bfcf16e5c74d6e61423d8fc44d082..920d44b1561dbf12f8afdc1e3e5105eb8a5aefef 100644 (file)
@@ -65,7 +65,7 @@ use core::str;
 use serde::{Deserialize, Deserializer,Serialize, Serializer, de::Error};
 
 #[doc(no_inline)]
-pub use lightning::ln::PaymentSecret;
+pub use lightning::ln::types::PaymentSecret;
 #[doc(no_inline)]
 pub use lightning::routing::router::{RouteHint, RouteHintHop};
 #[doc(no_inline)]
@@ -162,7 +162,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
 /// use secp256k1::Secp256k1;
 /// use secp256k1::SecretKey;
 ///
-/// use lightning::ln::PaymentSecret;
+/// use lightning::ln::types::PaymentSecret;
 ///
 /// use lightning_invoice::{Currency, InvoiceBuilder};
 ///
@@ -1877,7 +1877,7 @@ mod test {
                         Bolt11SemanticError};
 
                let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
-               let payment_secret = lightning::ln::PaymentSecret([21; 32]);
+               let payment_secret = lightning::ln::types::PaymentSecret([21; 32]);
                let invoice_template = RawBolt11Invoice {
                        hrp: RawHrp {
                                currency: Currency::Bitcoin,
index 8196fa9eb89a81d7df74300484ee96cddee5588f..a8ffce7bbd9604d8583da0fdbaf2a2254f749b17 100644 (file)
@@ -12,7 +12,7 @@
 use crate::Bolt11Invoice;
 use bitcoin::hashes::Hash;
 
-use lightning::ln::PaymentHash;
+use lightning::ln::types::PaymentHash;
 use lightning::ln::channelmanager::RecipientOnionFields;
 use lightning::routing::router::{PaymentParameters, RouteParameters};
 
@@ -85,7 +85,7 @@ mod tests {
        use super::*;
        use crate::{InvoiceBuilder, Currency};
        use bitcoin::hashes::sha256::Hash as Sha256;
-       use lightning::ln::PaymentSecret;
+       use lightning::ln::types::PaymentSecret;
        use lightning::routing::router::Payee;
        use secp256k1::{SecretKey, PublicKey, Secp256k1};
        use core::time::Duration;
index 1d6b9210afd967f58c79e7453f53a3eda856a9ee..22e493ae1c570705da884a22b3c42a4e1ec02c0d 100644 (file)
@@ -8,7 +8,7 @@ use bitcoin::hashes::Hash;
 use lightning::chain;
 use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
 use lightning::sign::{Recipient, NodeSigner, SignerProvider, EntropySource};
-use lightning::ln::{PaymentHash, PaymentSecret};
+use lightning::ln::types::{PaymentHash, PaymentSecret};
 use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, MIN_FINAL_CLTV_EXPIRY_DELTA};
 use lightning::ln::channelmanager::{PhantomRouteHints, MIN_CLTV_EXPIRY_DELTA};
 use lightning::ln::inbound_payment::{create, create_from_hash, ExpandedKey};
@@ -824,9 +824,9 @@ mod test {
        use bitcoin::hashes::sha256::Hash as Sha256;
        use lightning::sign::PhantomKeysManager;
        use lightning::events::{MessageSendEvent, MessageSendEventsProvider};
-       use lightning::ln::PaymentHash;
+       use lightning::ln::types::PaymentHash;
        #[cfg(feature = "std")]
-       use lightning::ln::PaymentPreimage;
+       use lightning::ln::types::PaymentPreimage;
        use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
        use lightning::ln::functional_test_utils::*;
        use lightning::ln::msgs::ChannelMessageHandler;
index ec441c18c986ed4788948dcf09465e07233878d8..dfe89e0ebc6c34e6579fa1cea0ca79f4dc0b7672 100644 (file)
@@ -7,7 +7,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
 use crate::blinded_path::BlindedHop;
 use crate::blinded_path::utils;
 use crate::io;
-use crate::ln::PaymentSecret;
+use crate::ln::types::PaymentSecret;
 use crate::ln::channelmanager::CounterpartyForwardingInfo;
 use crate::ln::features::BlindedHopFeatures;
 use crate::ln::msgs::DecodeError;
@@ -425,7 +425,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
 mod tests {
        use bitcoin::secp256k1::PublicKey;
        use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentContext, PaymentRelay};
-       use crate::ln::PaymentSecret;
+       use crate::ln::types::PaymentSecret;
        use crate::ln::features::BlindedHopFeatures;
        use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
 
index 81ba30ffb83ed964ca4fe13901be979073e2e6ad..f4b284583f4c97b083838e5f7c79edb8d4a6b391 100644 (file)
@@ -31,7 +31,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Filter, WatchedOutput};
 use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
 use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Balance, MonitorEvent, TransactionOutputs, WithChannelMonitor, LATENCY_GRACE_PERIOD_BLOCKS};
 use crate::chain::transaction::{OutPoint, TransactionData};
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::sign::ecdsa::WriteableEcdsaChannelSigner;
 use crate::events;
 use crate::events::{Event, EventHandler};
index a7c88cd08a220ecf4f2698c8ce045759cea6ab27..b8598eabb972daab40551eb3c7ada7f4b6ace80d 100644 (file)
@@ -34,7 +34,7 @@ use bitcoin::secp256k1;
 use bitcoin::sighash::EcdsaSighashType;
 
 use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
-use crate::ln::{PaymentHash, PaymentPreimage, ChannelId};
+use crate::ln::types::{PaymentHash, PaymentPreimage, ChannelId};
 use crate::ln::msgs::DecodeError;
 use crate::ln::channel_keys::{DelayedPaymentKey, DelayedPaymentBasepoint, HtlcBasepoint, HtlcKey, RevocationKey, RevocationBasepoint};
 use crate::ln::chan_utils::{self,CommitmentTransaction, CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HTLCClaim, ChannelTransactionParameters, HolderCommitmentTransaction, TxCreationKeys};
@@ -4811,7 +4811,7 @@ mod tests {
        use crate::chain::package::{weight_offered_htlc, weight_received_htlc, weight_revoked_offered_htlc, weight_revoked_received_htlc, WEIGHT_REVOKED_OUTPUT};
        use crate::chain::transaction::OutPoint;
        use crate::sign::InMemorySigner;
-       use crate::ln::{PaymentPreimage, PaymentHash, ChannelId};
+       use crate::ln::types::{PaymentPreimage, PaymentHash, ChannelId};
        use crate::ln::channel_keys::{DelayedPaymentBasepoint, DelayedPaymentKey, HtlcBasepoint, RevocationBasepoint, RevocationKey};
        use crate::ln::chan_utils::{self,HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
        use crate::ln::channelmanager::{PaymentSendFailure, PaymentId, RecipientOnionFields};
index 1fb30a9aeb5f9375b4e1ecdac2950aea62a9ab37..a8afc7a1acbda8310ad7fb2d6744bca9974465f9 100644 (file)
@@ -17,7 +17,7 @@ use bitcoin::network::constants::Network;
 use bitcoin::secp256k1::PublicKey;
 
 use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, MonitorEvent};
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::sign::ecdsa::WriteableEcdsaChannelSigner;
 use crate::chain::transaction::{OutPoint, TransactionData};
 use crate::impl_writeable_tlv_based;
index 94d6aa35746caa3a6bbc10e991a7161d54aaef2c..4b4a4dcd1e28ca5d211baa28edfae4fb2e0ba7ce 100644 (file)
@@ -25,7 +25,7 @@ use bitcoin::secp256k1;
 use crate::chain::chaininterface::compute_feerate_sat_per_1000_weight;
 use crate::sign::{ChannelDerivationParameters, HTLCDescriptor, ChannelSigner, EntropySource, SignerProvider, ecdsa::WriteableEcdsaChannelSigner};
 use crate::ln::msgs::DecodeError;
-use crate::ln::PaymentPreimage;
+use crate::ln::types::PaymentPreimage;
 use crate::ln::chan_utils::{self, ChannelTransactionParameters, HTLCOutputInCommitment, HolderCommitmentTransaction};
 use crate::chain::ClaimId;
 use crate::chain::chaininterface::{ConfirmationTarget, FeeEstimator, BroadcasterInterface, LowerBoundedFeeEstimator};
index 3023be604d3f9d0f47fd3538ea5bcb8aaf3c640c..1bbcd6e04515081ce60a6bba4f1eeaa2c1f89849 100644 (file)
@@ -22,7 +22,7 @@ use bitcoin::hash_types::Txid;
 use bitcoin::secp256k1::{SecretKey,PublicKey};
 use bitcoin::sighash::EcdsaSighashType;
 
-use crate::ln::PaymentPreimage;
+use crate::ln::types::PaymentPreimage;
 use crate::ln::chan_utils::{self, TxCreationKeys, HTLCOutputInCommitment};
 use crate::ln::features::ChannelTypeFeatures;
 use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint};
@@ -1195,7 +1195,7 @@ mod tests {
        use crate::chain::package::{CounterpartyOfferedHTLCOutput, CounterpartyReceivedHTLCOutput, HolderHTLCOutput, PackageTemplate, PackageSolvingData, RevokedOutput, WEIGHT_REVOKED_OUTPUT, weight_offered_htlc, weight_received_htlc};
        use crate::chain::Txid;
        use crate::ln::chan_utils::HTLCOutputInCommitment;
-       use crate::ln::{PaymentPreimage, PaymentHash};
+       use crate::ln::types::{PaymentPreimage, PaymentHash};
        use crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint};
 
        use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
index 7a447dd5d9083bc959b9bacca4289715b116ad71..5450586ee96725a2519a911515fc9c2c9f9e1aea 100644 (file)
@@ -88,7 +88,7 @@ impl MaybeSignedTransaction {
 #[cfg(test)]
 mod tests {
        use crate::chain::transaction::OutPoint;
-       use crate::ln::ChannelId;
+       use crate::ln::types::ChannelId;
 
        use bitcoin::blockdata::transaction::Transaction;
        use bitcoin::consensus::encode;
index 8b52af69fe331527a43ae38e0a67cd94e4ea4139..9c24e00f13e8a3c907c522a64cf7d4ca5843fefc 100644 (file)
@@ -18,7 +18,7 @@ use crate::chain::chaininterface::{BroadcasterInterface, fee_for_weight};
 use crate::chain::ClaimId;
 use crate::io_extras::sink;
 use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::ln::chan_utils;
 use crate::ln::chan_utils::{
        ANCHOR_INPUT_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT,
index e72bc0228fd18fe43319744c550e295c5efa5fe7..2a1f698782bd3901589c5459fe2b23dc05463d62 100644 (file)
@@ -24,7 +24,7 @@ use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
 use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
 use crate::ln::features::ChannelTypeFeatures;
 use crate::ln::msgs;
-use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
+use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
 use crate::chain::transaction;
 use crate::routing::gossip::NetworkUpdate;
 use crate::util::errors::APIError;
index a0438b2447a004a1fc2261c036c673d363968a37..12e91b421728c07665f44a01620934385a0ee77f 100644 (file)
@@ -11,7 +11,7 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
 use crate::blinded_path::BlindedPath;
 use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay, ReceiveTlvs};
 use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PaymentFailureReason};
-use crate::ln::PaymentSecret;
+use crate::ln::types::PaymentSecret;
 use crate::ln::channelmanager;
 use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
 use crate::ln::features::BlindedHopFeatures;
index b7676ddff15290b876854b007c3f1a05572f1be4..3c99cdb0943c1f1ddd44d444eee5c0f255f0fab8 100644 (file)
@@ -25,7 +25,7 @@ use bitcoin::hash_types::{Txid, PubkeyHash, WPubkeyHash};
 use crate::chain::chaininterface::fee_for_weight;
 use crate::chain::package::WEIGHT_REVOKED_OUTPUT;
 use crate::sign::EntropySource;
-use crate::ln::{PaymentHash, PaymentPreimage};
+use crate::ln::types::{PaymentHash, PaymentPreimage};
 use crate::ln::msgs::DecodeError;
 use crate::util::ser::{Readable, RequiredWrapper, Writeable, Writer};
 use crate::util::transaction_utils;
@@ -1826,7 +1826,7 @@ mod tests {
        use bitcoin::{Network, Txid, ScriptBuf};
        use bitcoin::hashes::Hash;
        use bitcoin::hashes::hex::FromHex;
-       use crate::ln::PaymentHash;
+       use crate::ln::types::PaymentHash;
        use bitcoin::address::Payload;
        use bitcoin::PublicKey as BitcoinPublicKey;
        use crate::ln::features::ChannelTypeFeatures;
index 11ab1fbb85158a40f6e796ab1b26856df16c8458..7d332f2ad78b8897fa3d27e00ae23745a2d49f5b 100644 (file)
@@ -21,7 +21,8 @@ use crate::chain::{ChannelMonitorUpdateStatus, Listen, Watch};
 use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason, HTLCDestination};
 use crate::ln::channelmanager::{RAACommitmentOrder, PaymentSendFailure, PaymentId, RecipientOnionFields};
 use crate::ln::channel::{AnnouncementSigsState, ChannelPhase};
-use crate::ln::{msgs, ChannelId};
+use crate::ln::msgs;
+use crate::ln::types::ChannelId;
 use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
 use crate::util::test_channel_signer::TestChannelSigner;
 use crate::util::errors::APIError;
index 66301c95bd6d378d828003ae9260a54eb9ade578..afe265c8a6afb74f531252231e01e29230dcb333 100644 (file)
@@ -24,7 +24,7 @@ use bitcoin::secp256k1::{PublicKey,SecretKey};
 use bitcoin::secp256k1::{Secp256k1,ecdsa::Signature};
 use bitcoin::secp256k1;
 
-use crate::ln::{ChannelId, PaymentPreimage, PaymentHash};
+use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash};
 use crate::ln::features::{ChannelTypeFeatures, InitFeatures};
 use crate::ln::msgs;
 use crate::ln::msgs::DecodeError;
@@ -9338,7 +9338,7 @@ mod tests {
        use bitcoin::blockdata::opcodes;
        use bitcoin::network::constants::Network;
        use crate::ln::onion_utils::INVALID_ONION_BLINDING;
-       use crate::ln::{PaymentHash, PaymentPreimage};
+       use crate::ln::types::{PaymentHash, PaymentPreimage};
        use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
        use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
        use crate::ln::channel::InitFeatures;
diff --git a/lightning/src/ln/channel_id.rs b/lightning/src/ln/channel_id.rs
deleted file mode 100644 (file)
index 90efe3c..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-// This file is Copyright its original authors, visible in version control
-// history.
-//
-// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
-// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
-// You may not use this file except in accordance with one or both of these
-// licenses.
-
-//! ChannelId definition.
-
-use crate::chain::transaction::OutPoint;
-use crate::io;
-use crate::ln::msgs::DecodeError;
-use crate::sign::EntropySource;
-use crate::util::ser::{Readable, Writeable, Writer};
-use super::channel_keys::RevocationBasepoint;
-
-use bitcoin::hashes::{
-       Hash as _,
-       HashEngine as _,
-       sha256::Hash as Sha256,
-};
-use core::fmt;
-use core::ops::Deref;
-
-/// A unique 32-byte identifier for a channel.
-/// Depending on how the ID is generated, several varieties are distinguished
-/// (but all are stored as 32 bytes):
-///   _v1_ and _temporary_.
-/// A _v1_ channel ID is generated based on funding tx outpoint (txid & index).
-/// A _temporary_ ID is generated randomly.
-/// (Later revocation-point-based _v2_ is a possibility.)
-/// The variety (context) is not stored, it is relevant only at creation.
-///
-/// This is not exported to bindings users as we just use [u8; 32] directly.
-#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
-pub struct ChannelId(pub [u8; 32]);
-
-impl ChannelId {
-       /// Create _v1_ channel ID based on a funding TX ID and output index
-       pub fn v1_from_funding_txid(txid: &[u8; 32], output_index: u16) -> Self {
-               let mut res = [0; 32];
-               res[..].copy_from_slice(&txid[..]);
-               res[30] ^= ((output_index >> 8) & 0xff) as u8;
-               res[31] ^= ((output_index >> 0) & 0xff) as u8;
-               Self(res)
-       }
-
-       /// Create _v1_ channel ID from a funding tx outpoint
-       pub fn v1_from_funding_outpoint(outpoint: OutPoint) -> Self {
-               Self::v1_from_funding_txid(outpoint.txid.as_byte_array(), outpoint.index)
-       }
-
-       /// Create a _temporary_ channel ID randomly, based on an entropy source.
-       pub fn temporary_from_entropy_source<ES: Deref>(entropy_source: &ES) -> Self
-       where ES::Target: EntropySource {
-               Self(entropy_source.get_secure_random_bytes())
-       }
-
-       /// Generic constructor; create a new channel ID from the provided data.
-       /// Use a more specific `*_from_*` constructor when possible.
-       pub fn from_bytes(data: [u8; 32]) -> Self {
-               Self(data)
-       }
-
-       /// Create a channel ID consisting of all-zeros data (e.g. when uninitialized or a placeholder).
-       pub fn new_zero() -> Self {
-               Self([0; 32])
-       }
-
-       /// Check whether ID is consisting of all zeros (uninitialized)
-       pub fn is_zero(&self) -> bool {
-               self.0[..] == [0; 32]
-       }
-
-       /// Create _v2_ channel ID by concatenating the holder revocation basepoint with the counterparty
-       /// revocation basepoint and hashing the result. The basepoints will be concatenated in increasing
-       /// sorted order.
-       pub fn v2_from_revocation_basepoints(
-               ours: &RevocationBasepoint,
-               theirs: &RevocationBasepoint,
-       ) -> Self {
-               let ours = ours.0.serialize();
-               let theirs = theirs.0.serialize();
-               let (lesser, greater) = if ours < theirs {
-                       (ours, theirs)
-               } else {
-                       (theirs, ours)
-               };
-               let mut engine = Sha256::engine();
-               engine.input(&lesser[..]);
-               engine.input(&greater[..]);
-               Self(Sha256::from_engine(engine).to_byte_array())
-       }
-
-       /// Create temporary _v2_ channel ID by concatenating a zeroed out basepoint with the holder
-       /// revocation basepoint and hashing the result.
-       pub fn temporary_v2_from_revocation_basepoint(our_revocation_basepoint: &RevocationBasepoint) -> Self {
-               Self(Sha256::hash(&[[0u8; 33], our_revocation_basepoint.0.serialize()].concat()).to_byte_array())
-       }
-}
-
-impl Writeable for ChannelId {
-       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
-               self.0.write(w)
-       }
-}
-
-impl Readable for ChannelId {
-       fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
-               let buf: [u8; 32] = Readable::read(r)?;
-               Ok(ChannelId(buf))
-       }
-}
-
-impl fmt::Display for ChannelId {
-       fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-               crate::util::logger::DebugBytes(&self.0).fmt(f)
-       }
-}
-
-#[cfg(test)]
-mod tests {
-       use bitcoin::hashes::{
-               Hash as _,
-               HashEngine as _,
-               hex::FromHex as _,
-               sha256::Hash as Sha256,
-       };
-       use bitcoin::secp256k1::PublicKey;
-       use hex::DisplayHex;
-
-       use crate::ln::ChannelId;
-       use crate::ln::channel_keys::RevocationBasepoint;
-       use crate::util::ser::{Readable, Writeable};
-       use crate::util::test_utils;
-       use crate::prelude::*;
-       use crate::io;
-
-       #[test]
-       fn test_channel_id_v1_from_funding_txid() {
-               let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
-               assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
-       }
-
-       #[test]
-       fn test_channel_id_new_from_data() {
-               let data: [u8; 32] = [2; 32];
-               let channel_id = ChannelId::from_bytes(data.clone());
-               assert_eq!(channel_id.0, data);
-       }
-
-       #[test]
-       fn test_channel_id_equals() {
-               let channel_id11 = ChannelId::v1_from_funding_txid(&[2; 32], 2);
-               let channel_id12 = ChannelId::v1_from_funding_txid(&[2; 32], 2);
-               let channel_id21 = ChannelId::v1_from_funding_txid(&[2; 32], 42);
-               assert_eq!(channel_id11, channel_id12);
-               assert_ne!(channel_id11, channel_id21);
-       }
-
-       #[test]
-       fn test_channel_id_write_read() {
-               let data: [u8; 32] = [2; 32];
-               let channel_id = ChannelId::from_bytes(data.clone());
-
-               let mut w = test_utils::TestVecWriter(Vec::new());
-               channel_id.write(&mut w).unwrap();
-
-               let channel_id_2 = ChannelId::read(&mut io::Cursor::new(&w.0)).unwrap();
-               assert_eq!(channel_id_2, channel_id);
-               assert_eq!(channel_id_2.0, data);
-       }
-
-       #[test]
-       fn test_channel_id_display() {
-               let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
-               assert_eq!(format!("{}", &channel_id), "0202020202020202020202020202020202020202020202020202020202020203");
-       }
-
-       #[test]
-       fn test_channel_id_v2_from_basepoints() {
-               // Ours greater than theirs
-               let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap());
-               let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
-
-               let mut engine = Sha256::engine();
-               engine.input(&theirs.0.serialize());
-               engine.input(&ours.0.serialize());
-               let expected_id = ChannelId(Sha256::from_engine(engine).to_byte_array());
-
-               assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
-
-               // Theirs greater than ours
-               let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap());
-               let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
-
-               let mut engine = Sha256::engine();
-               engine.input(&ours.0.serialize());
-               engine.input(&theirs.0.serialize());
-               let expected_id = ChannelId(Sha256::from_engine(engine).to_byte_array());
-
-               assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
-       }
-}
index 51555c7a0ac6e199fe25f6ec17315edd48f2cb9b..7bc62463b36feb7a271294f309edf34a9ec8367e 100644 (file)
@@ -42,7 +42,8 @@ use crate::events;
 use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination, PaymentFailureReason};
 // Since this struct is returned in `list_channels` methods, expose it here in case users want to
 // construct one themselves.
-use crate::ln::{inbound_payment, ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
+use crate::ln::inbound_payment;
+use crate::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
 use crate::ln::channel::{self, Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
 pub use crate::ln::channel::{InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
 use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
@@ -1387,7 +1388,7 @@ where
 ///
 /// ```
 /// # use bitcoin::secp256k1::PublicKey;
-/// # use lightning::ln::ChannelId;
+/// # use lightning::ln::types::ChannelId;
 /// # use lightning::ln::channelmanager::AChannelManager;
 /// # use lightning::events::{Event, EventsProvider};
 /// #
@@ -1490,7 +1491,7 @@ where
 ///
 /// ```
 /// # use lightning::events::{Event, EventsProvider};
-/// # use lightning::ln::PaymentHash;
+/// # use lightning::ln::types::PaymentHash;
 /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
 /// # use lightning::routing::router::RouteParameters;
 /// #
@@ -12358,8 +12359,7 @@ mod tests {
        use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
        use core::sync::atomic::Ordering;
        use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
-       use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
-       use crate::ln::ChannelId;
+       use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
        use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
        use crate::ln::functional_test_utils::*;
        use crate::ln::msgs::{self, ErrorAction};
index cf52d946e34e0832e640b9d175dc1e98fff34cf4..c5361318fca7c59ec5f726b228e1754c2dc2338c 100644 (file)
@@ -15,7 +15,7 @@ use crate::chain::channelmonitor::ChannelMonitor;
 use crate::chain::transaction::OutPoint;
 use crate::events::{ClaimedHTLC, ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, PaymentFailureReason};
 use crate::events::bump_transaction::{BumpTransactionEvent, BumpTransactionEventHandler, Wallet, WalletSource};
-use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
+use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
 use crate::ln::channelmanager::{AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, PaymentId, MIN_CLTV_EXPIRY_DELTA};
 use crate::ln::features::InitFeatures;
 use crate::ln::msgs;
index 465d6288d9d3e764662edb2276d7bb5bef477cb3..106cd811b10b782dd185c654d0d9a0624352ac01 100644 (file)
@@ -19,7 +19,7 @@ use crate::chain::channelmonitor::{CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER,
 use crate::chain::transaction::OutPoint;
 use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, SignerProvider};
 use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
-use crate::ln::{ChannelId, PaymentPreimage, PaymentSecret, PaymentHash};
+use crate::ln::types::{ChannelId, PaymentPreimage, PaymentSecret, PaymentHash};
 use crate::ln::channel::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC, CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY, ChannelPhase};
 use crate::ln::channelmanager::{self, PaymentId, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, BREAKDOWN_TIMEOUT, ENABLE_GOSSIP_TICKS, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA};
 use crate::ln::channel::{DISCONNECT_PEER_AWAITING_RESPONSE_TICKS, ChannelError};
index f27d8aab1195284a0a03c74e9af2e093e8482a65..a85d93b7135e5c9b0e41d2750359c2f335654827 100644 (file)
@@ -14,7 +14,7 @@ use bitcoin::hashes::cmp::fixed_time_eq;
 use bitcoin::hashes::hmac::{Hmac, HmacEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use crate::sign::{KeyMaterial, EntropySource};
-use crate::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
+use crate::ln::types::{PaymentHash, PaymentPreimage, PaymentSecret};
 use crate::ln::msgs;
 use crate::ln::msgs::MAX_VALUE_MSAT;
 use crate::crypto::chacha20::ChaCha20;
index 5f01bcd163ba3ba410e023334f424fca3762c8e8..60341620887b59dc3fcadd06e5d6b5d7f1f2b21b 100644 (file)
@@ -22,8 +22,9 @@ use bitcoin::{
 use crate::chain::chaininterface::fee_for_weight;
 use crate::events::bump_transaction::{BASE_INPUT_WEIGHT, EMPTY_SCRIPT_SIG_WEIGHT};
 use crate::ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS;
+use crate::ln::msgs;
 use crate::ln::msgs::SerialId;
-use crate::ln::{msgs, ChannelId};
+use crate::ln::types::ChannelId;
 use crate::sign::{EntropySource, P2TR_KEY_PATH_WITNESS_WEIGHT, P2WPKH_WITNESS_WEIGHT};
 use crate::util::ser::TransactionU16LenLimited;
 
@@ -1023,7 +1024,7 @@ mod tests {
                InteractiveTxMessageSend, MAX_INPUTS_OUTPUTS_COUNT, MAX_RECEIVED_TX_ADD_INPUT_COUNT,
                MAX_RECEIVED_TX_ADD_OUTPUT_COUNT,
        };
-       use crate::ln::ChannelId;
+       use crate::ln::types::ChannelId;
        use crate::sign::EntropySource;
        use crate::util::atomic_counter::AtomicCounter;
        use crate::util::ser::TransactionU16LenLimited;
index 26a384dffd4768d9bb9e836c28fff2fa1849585a..7cbb2ce5ebe1b9eb22b3ac957dbb99b88d72afbc 100644 (file)
@@ -22,7 +22,9 @@ pub mod peer_handler;
 pub mod chan_utils;
 pub mod features;
 pub mod script;
-mod channel_id;
+pub mod types;
+
+pub use types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
 
 #[cfg(fuzzing)]
 pub mod peer_channel_encryptor;
@@ -34,9 +36,6 @@ pub mod channel;
 #[cfg(not(fuzzing))]
 pub(crate) mod channel;
 
-// Re-export ChannelId
-pub use channel_id::ChannelId;
-
 pub(crate) mod onion_utils;
 mod outbound_payment;
 pub mod wire;
@@ -86,75 +85,3 @@ mod offers_tests;
 pub(crate) mod interactivetxs;
 
 pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
-
-use bitcoin::hashes::{sha256::Hash as Sha256, Hash};
-
-/// payment_hash type, use to cross-lock hop
-///
-/// This is not exported to bindings users as we just use [u8; 32] directly
-#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
-pub struct PaymentHash(pub [u8; 32]);
-
-impl core::fmt::Display for PaymentHash {
-       fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-               crate::util::logger::DebugBytes(&self.0).fmt(f)
-       }
-}
-
-/// payment_preimage type, use to route payment between hop
-///
-/// This is not exported to bindings users as we just use [u8; 32] directly
-#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
-pub struct PaymentPreimage(pub [u8; 32]);
-
-impl core::fmt::Display for PaymentPreimage {
-       fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-               crate::util::logger::DebugBytes(&self.0).fmt(f)
-       }
-}
-
-/// Converts a `PaymentPreimage` into a `PaymentHash` by hashing the preimage with SHA256.
-impl From<PaymentPreimage> for PaymentHash {
-       fn from(value: PaymentPreimage) -> Self {
-               PaymentHash(Sha256::hash(&value.0).to_byte_array())
-       }
-}
-
-/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
-///
-/// This is not exported to bindings users as we just use [u8; 32] directly
-#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
-pub struct PaymentSecret(pub [u8; 32]);
-
-#[allow(unused_imports)]
-use crate::prelude::*;
-
-use bitcoin::bech32;
-use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
-
-impl FromBase32 for PaymentSecret {
-       type Err = bech32::Error;
-
-       fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
-               if field_data.len() != 52 {
-                       return Err(bech32::Error::InvalidLength)
-               } else {
-                       let data_bytes = Vec::<u8>::from_base32(field_data)?;
-                       let mut payment_secret = [0; 32];
-                       payment_secret.copy_from_slice(&data_bytes);
-                       Ok(PaymentSecret(payment_secret))
-               }
-       }
-}
-
-impl ToBase32 for PaymentSecret {
-       fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
-               (&self.0[..]).write_base32(writer)
-       }
-}
-
-impl Base32Len for PaymentSecret {
-       fn base32_len(&self) -> usize {
-               52
-       }
-}
index d5f28c23b4e6271510f78a741e038deeb3e05c3a..52bda8185837eab9a5543467e48ce7abf8bae532 100644 (file)
@@ -15,7 +15,8 @@ use crate::chain::transaction::OutPoint;
 use crate::chain::chaininterface::{LowerBoundedFeeEstimator, compute_feerate_sat_per_1000_weight};
 use crate::events::bump_transaction::{BumpTransactionEvent, WalletSource};
 use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination};
-use crate::ln::{channel, ChannelId};
+use crate::ln::channel;
+use crate::ln::types::ChannelId;
 use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, PaymentId, RecipientOnionFields};
 use crate::ln::msgs::ChannelMessageHandler;
 use crate::util::config::UserConfig;
index 136ed4d317b35bfdc43618a0109e7c3ed1a729a1..87e8a814d33c11db0abb494ff16de1c79f6dcb92 100644 (file)
@@ -32,7 +32,7 @@ use bitcoin::blockdata::script::ScriptBuf;
 use bitcoin::hash_types::Txid;
 
 use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs};
-use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
+use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
 use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
 use crate::ln::onion_utils;
 use crate::onion_message;
@@ -1678,7 +1678,7 @@ pub struct FinalOnionHopData {
 mod fuzzy_internal_msgs {
        use bitcoin::secp256k1::PublicKey;
        use crate::blinded_path::payment::{PaymentConstraints, PaymentContext, PaymentRelay};
-       use crate::ln::{PaymentPreimage, PaymentSecret};
+       use crate::ln::types::{PaymentPreimage, PaymentSecret};
        use crate::ln::features::BlindedHopFeatures;
        use super::{FinalOnionHopData, TrampolineOnionPacket};
 
@@ -3176,8 +3176,7 @@ impl_writeable_msg!(GossipTimestampFilter, {
 mod tests {
        use bitcoin::{Transaction, TxIn, ScriptBuf, Sequence, Witness, TxOut};
        use hex::DisplayHex;
-       use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
-       use crate::ln::ChannelId;
+       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};
        use crate::ln::msgs::SocketAddress;
index db8c4cd033708fd36413aaf4b8c30ec05e4075e8..8293a32021e3285dd91a651274c2ca11b902552c 100644 (file)
@@ -11,7 +11,7 @@ use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1};
 use crate::blinded_path;
 use crate::blinded_path::payment::{PaymentConstraints, PaymentRelay};
 use crate::chain::channelmonitor::{HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
 use crate::ln::channelmanager::{BlindedFailure, BlindedForward, CLTV_FAR_FAR_AWAY, HTLCFailureMsg, MIN_CLTV_EXPIRY_DELTA, PendingHTLCInfo, PendingHTLCRouting};
 use crate::ln::features::BlindedHopFeatures;
 use crate::ln::msgs;
@@ -504,8 +504,7 @@ mod tests {
        use bitcoin::hashes::Hash;
        use bitcoin::hashes::sha256::Hash as Sha256;
        use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
-       use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
-       use crate::ln::ChannelId;
+       use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
        use crate::ln::channelmanager::RecipientOnionFields;
        use crate::ln::features::{ChannelFeatures, NodeFeatures};
        use crate::ln::msgs;
index aeb175bc62660b6091c0a71a3960e4dc6ca1bc5e..5ca4b4d5722ae2adbd8da3e3d83a49fc6d2b040f 100644 (file)
@@ -14,7 +14,7 @@
 use crate::chain::channelmonitor::{CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
 use crate::sign::{EntropySource, NodeSigner, Recipient};
 use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason};
-use crate::ln::{PaymentHash, PaymentSecret};
+use crate::ln::types::{PaymentHash, PaymentSecret};
 use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS;
 use crate::ln::channelmanager::{HTLCForwardInfo, FailureCode, CLTV_FAR_FAR_AWAY, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA, PendingAddHTLCInfo, PendingHTLCInfo, PendingHTLCRouting, PaymentId, RecipientOnionFields};
 use crate::ln::onion_utils;
index f2b5c69e9e677fb10e3886e4240b58bacd66395a..0abcb7de26df55468001afff373a0d5281e81e59 100644 (file)
@@ -11,8 +11,8 @@ use crate::crypto::chacha20::ChaCha20;
 use crate::crypto::streams::ChaChaReader;
 use crate::ln::channelmanager::{HTLCSource, RecipientOnionFields};
 use crate::ln::msgs;
+use crate::ln::types::{PaymentHash, PaymentPreimage};
 use crate::ln::wire::Encode;
-use crate::ln::{PaymentHash, PaymentPreimage};
 use crate::routing::gossip::NetworkUpdate;
 use crate::routing::router::{BlindedTail, Path, RouteHop};
 use crate::sign::NodeSigner;
@@ -1240,7 +1240,7 @@ mod tests {
        use crate::io;
        use crate::ln::features::{ChannelFeatures, NodeFeatures};
        use crate::ln::msgs;
-       use crate::ln::PaymentHash;
+       use crate::ln::types::PaymentHash;
        use crate::routing::router::{Path, Route, RouteHop};
        use crate::util::ser::{VecWriter, Writeable, Writer};
 
index b05d6f3f7290110b5aed103faef370203350a8fc..79b743f167568a15e633536589c151b8a06a050a 100644 (file)
@@ -15,7 +15,7 @@ use bitcoin::secp256k1::{self, Secp256k1, SecretKey};
 
 use crate::sign::{EntropySource, NodeSigner, Recipient};
 use crate::events::{self, PaymentFailureReason};
-use crate::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
+use crate::ln::types::{PaymentHash, PaymentPreimage, PaymentSecret};
 use crate::ln::channelmanager::{ChannelDetails, EventCompletionAction, HTLCSource, PaymentId};
 use crate::ln::onion_utils::{DecodedOnionFailure, HTLCFailReason};
 use crate::offers::invoice::Bolt12Invoice;
@@ -1837,7 +1837,7 @@ mod tests {
        use core::time::Duration;
 
        use crate::events::{Event, PathFailure, PaymentFailureReason};
-       use crate::ln::PaymentHash;
+       use crate::ln::types::PaymentHash;
        use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
        use crate::ln::features::{ChannelFeatures, NodeFeatures};
        use crate::ln::msgs::{ErrorAction, LightningError};
index d1fa58372dd93dbe7e86c2af853d6b55f150d508..c9329c147bb3682f55bd8ae71e564ce5a5ba3466 100644 (file)
@@ -19,7 +19,8 @@ use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, Mes
 use crate::ln::channel::{EXPIRE_PREV_CONFIG_TICKS, commit_tx_fee_msat, get_holder_selected_channel_reserve_satoshis, ANCHOR_OUTPUT_VALUE_SATOSHI};
 use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, RecentPaymentDetails, RecipientOnionFields, HTLCForwardInfo, PendingHTLCRouting, PendingAddHTLCInfo};
 use crate::ln::features::{Bolt11InvoiceFeatures, ChannelTypeFeatures};
-use crate::ln::{msgs, ChannelId, PaymentHash, PaymentSecret, PaymentPreimage};
+use crate::ln::msgs;
+use crate::ln::types::{ChannelId, PaymentHash, PaymentSecret, PaymentPreimage};
 use crate::ln::msgs::ChannelMessageHandler;
 use crate::ln::onion_utils;
 use crate::ln::outbound_payment::{IDEMPOTENCY_TIMEOUT_TICKS, Retry};
index 9ce230861456927f53bf4a2b65dd33e800e17e5d..17e46a274b19275a3992a9141a60fe5ba53a9c18 100644 (file)
@@ -20,7 +20,7 @@ use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey};
 
 use crate::sign::{NodeSigner, Recipient};
 use crate::events::{EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::ln::features::{InitFeatures, NodeFeatures};
 use crate::ln::msgs;
 use crate::ln::msgs::{ChannelMessageHandler, LightningError, SocketAddress, OnionMessageHandler, RoutingMessageHandler};
@@ -2676,7 +2676,7 @@ mod tests {
        use crate::sign::{NodeSigner, Recipient};
        use crate::events;
        use crate::io;
-       use crate::ln::ChannelId;
+       use crate::ln::types::ChannelId;
        use crate::ln::features::{InitFeatures, NodeFeatures};
        use crate::ln::peer_channel_encryptor::PeerChannelEncryptor;
        use crate::ln::peer_handler::{CustomMessageHandler, PeerManager, MessageHandler, SocketDescriptor, IgnoringMessageHandler, filter_addresses, ErroringMessageHandler, MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER};
index 6fd8623d317376b5b6d156869c2a5949bca7e33d..fba97eae382905d8d28f544b6afc65897f440ecc 100644 (file)
@@ -18,7 +18,8 @@ use crate::ln::channelmanager::{MIN_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnion
 use crate::routing::gossip::RoutingFees;
 use crate::routing::router::{PaymentParameters, RouteHint, RouteHintHop};
 use crate::ln::features::ChannelTypeFeatures;
-use crate::ln::{msgs, ChannelId};
+use crate::ln::msgs;
+use crate::ln::types::ChannelId;
 use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ChannelUpdate, ErrorAction};
 use crate::ln::wire::Encode;
 use crate::util::config::{UserConfig, MaxDustHTLCExposure};
index 8b25f7701be5a2a48dad594c5bc48442c49e3253..36b620c6bab7bb21317ee04cf5e42174463c5a1b 100644 (file)
@@ -16,7 +16,8 @@ use crate::sign::EntropySource;
 use crate::chain::transaction::OutPoint;
 use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider};
 use crate::ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, RecipientOnionFields};
-use crate::ln::{msgs, ChannelId};
+use crate::ln::msgs;
+use crate::ln::types::ChannelId;
 use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ErrorAction};
 use crate::util::test_channel_signer::TestChannelSigner;
 use crate::util::test_utils;
index c15365629015cb3b54600efab1486532c3a888fc..571521291b69c7ab533c284408013c82ef7d6967 100644 (file)
@@ -15,6 +15,7 @@ use crate::chain::transaction::OutPoint;
 use crate::chain::Confirm;
 use crate::events::{Event, MessageSendEventsProvider, ClosureReason, HTLCDestination, MessageSendEvent};
 use crate::ln::msgs::{ChannelMessageHandler, Init};
+use crate::ln::types::ChannelId;
 use crate::sign::OutputSpender;
 use crate::util::test_utils;
 use crate::util::ser::Writeable;
@@ -26,7 +27,7 @@ use bitcoin::secp256k1::Secp256k1;
 
 use crate::prelude::*;
 
-use crate::ln::{functional_test_utils::*, ChannelId};
+use crate::ln::functional_test_utils::*;
 
 fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) {
        // Our on-chain HTLC-claim learning has a few properties worth testing:
index 7f004948ffeb5cb10790673e5fa36680950bef23..782a991535f6f6e927aef9479260902d4df2f618 100644 (file)
@@ -16,7 +16,8 @@ use crate::chain::transaction::OutPoint;
 use crate::events::{Event, MessageSendEvent, HTLCDestination, MessageSendEventsProvider, ClosureReason};
 use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, Retry, ChannelShutdownState, ChannelDetails};
 use crate::routing::router::{PaymentParameters, get_route, RouteParameters};
-use crate::ln::{ChannelId, msgs};
+use crate::ln::msgs;
+use crate::ln::types::ChannelId;
 use crate::ln::msgs::{ChannelMessageHandler, ErrorAction};
 use crate::ln::onion_utils::INVALID_ONION_BLINDING;
 use crate::ln::script::ShutdownScript;
diff --git a/lightning/src/ln/types.rs b/lightning/src/ln/types.rs
new file mode 100644 (file)
index 0000000..d3eb204
--- /dev/null
@@ -0,0 +1,277 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+//! Various wrapper types (most around 32-byte arrays) for use in lightning.
+
+use crate::chain::transaction::OutPoint;
+use crate::io;
+use crate::ln::msgs::DecodeError;
+use crate::sign::EntropySource;
+use crate::util::ser::{Readable, Writeable, Writer};
+use super::channel_keys::RevocationBasepoint;
+
+#[allow(unused_imports)]
+use crate::prelude::*;
+
+use bitcoin::hashes::{
+       Hash as _,
+       HashEngine as _,
+       sha256::Hash as Sha256,
+};
+use core::fmt;
+use core::ops::Deref;
+
+/// A unique 32-byte identifier for a channel.
+/// Depending on how the ID is generated, several varieties are distinguished
+/// (but all are stored as 32 bytes):
+///   _v1_ and _temporary_.
+/// A _v1_ channel ID is generated based on funding tx outpoint (txid & index).
+/// A _temporary_ ID is generated randomly.
+/// (Later revocation-point-based _v2_ is a possibility.)
+/// The variety (context) is not stored, it is relevant only at creation.
+///
+/// This is not exported to bindings users as we just use [u8; 32] directly.
+#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
+pub struct ChannelId(pub [u8; 32]);
+
+impl ChannelId {
+       /// Create _v1_ channel ID based on a funding TX ID and output index
+       pub fn v1_from_funding_txid(txid: &[u8; 32], output_index: u16) -> Self {
+               let mut res = [0; 32];
+               res[..].copy_from_slice(&txid[..]);
+               res[30] ^= ((output_index >> 8) & 0xff) as u8;
+               res[31] ^= ((output_index >> 0) & 0xff) as u8;
+               Self(res)
+       }
+
+       /// Create _v1_ channel ID from a funding tx outpoint
+       pub fn v1_from_funding_outpoint(outpoint: OutPoint) -> Self {
+               Self::v1_from_funding_txid(outpoint.txid.as_byte_array(), outpoint.index)
+       }
+
+       /// Create a _temporary_ channel ID randomly, based on an entropy source.
+       pub fn temporary_from_entropy_source<ES: Deref>(entropy_source: &ES) -> Self
+       where ES::Target: EntropySource {
+               Self(entropy_source.get_secure_random_bytes())
+       }
+
+       /// Generic constructor; create a new channel ID from the provided data.
+       /// Use a more specific `*_from_*` constructor when possible.
+       pub fn from_bytes(data: [u8; 32]) -> Self {
+               Self(data)
+       }
+
+       /// Create a channel ID consisting of all-zeros data (e.g. when uninitialized or a placeholder).
+       pub fn new_zero() -> Self {
+               Self([0; 32])
+       }
+
+       /// Check whether ID is consisting of all zeros (uninitialized)
+       pub fn is_zero(&self) -> bool {
+               self.0[..] == [0; 32]
+       }
+
+       /// Create _v2_ channel ID by concatenating the holder revocation basepoint with the counterparty
+       /// revocation basepoint and hashing the result. The basepoints will be concatenated in increasing
+       /// sorted order.
+       pub fn v2_from_revocation_basepoints(
+               ours: &RevocationBasepoint,
+               theirs: &RevocationBasepoint,
+       ) -> Self {
+               let ours = ours.0.serialize();
+               let theirs = theirs.0.serialize();
+               let (lesser, greater) = if ours < theirs {
+                       (ours, theirs)
+               } else {
+                       (theirs, ours)
+               };
+               let mut engine = Sha256::engine();
+               engine.input(&lesser[..]);
+               engine.input(&greater[..]);
+               Self(Sha256::from_engine(engine).to_byte_array())
+       }
+
+       /// Create temporary _v2_ channel ID by concatenating a zeroed out basepoint with the holder
+       /// revocation basepoint and hashing the result.
+       pub fn temporary_v2_from_revocation_basepoint(our_revocation_basepoint: &RevocationBasepoint) -> Self {
+               Self(Sha256::hash(&[[0u8; 33], our_revocation_basepoint.0.serialize()].concat()).to_byte_array())
+       }
+}
+
+impl Writeable for ChannelId {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               self.0.write(w)
+       }
+}
+
+impl Readable for ChannelId {
+       fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let buf: [u8; 32] = Readable::read(r)?;
+               Ok(ChannelId(buf))
+       }
+}
+
+impl fmt::Display for ChannelId {
+       fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+               crate::util::logger::DebugBytes(&self.0).fmt(f)
+       }
+}
+
+
+/// payment_hash type, use to cross-lock hop
+///
+/// This is not exported to bindings users as we just use [u8; 32] directly
+#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
+pub struct PaymentHash(pub [u8; 32]);
+
+impl core::fmt::Display for PaymentHash {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+               crate::util::logger::DebugBytes(&self.0).fmt(f)
+       }
+}
+
+/// payment_preimage type, use to route payment between hop
+///
+/// This is not exported to bindings users as we just use [u8; 32] directly
+#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
+pub struct PaymentPreimage(pub [u8; 32]);
+
+impl core::fmt::Display for PaymentPreimage {
+       fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+               crate::util::logger::DebugBytes(&self.0).fmt(f)
+       }
+}
+
+/// Converts a `PaymentPreimage` into a `PaymentHash` by hashing the preimage with SHA256.
+impl From<PaymentPreimage> for PaymentHash {
+       fn from(value: PaymentPreimage) -> Self {
+               PaymentHash(Sha256::hash(&value.0).to_byte_array())
+       }
+}
+
+/// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
+///
+/// This is not exported to bindings users as we just use [u8; 32] directly
+#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
+pub struct PaymentSecret(pub [u8; 32]);
+
+use bitcoin::bech32;
+use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
+
+impl FromBase32 for PaymentSecret {
+       type Err = bech32::Error;
+
+       fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
+               if field_data.len() != 52 {
+                       return Err(bech32::Error::InvalidLength)
+               } else {
+                       let data_bytes = Vec::<u8>::from_base32(field_data)?;
+                       let mut payment_secret = [0; 32];
+                       payment_secret.copy_from_slice(&data_bytes);
+                       Ok(PaymentSecret(payment_secret))
+               }
+       }
+}
+
+impl ToBase32 for PaymentSecret {
+       fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
+               (&self.0[..]).write_base32(writer)
+       }
+}
+
+impl Base32Len for PaymentSecret {
+       fn base32_len(&self) -> usize {
+               52
+       }
+}
+
+#[cfg(test)]
+mod tests {
+       use bitcoin::hashes::{
+               Hash as _,
+               HashEngine as _,
+               hex::FromHex as _,
+               sha256::Hash as Sha256,
+       };
+       use bitcoin::secp256k1::PublicKey;
+       use hex::DisplayHex;
+
+       use super::ChannelId;
+       use crate::ln::channel_keys::RevocationBasepoint;
+       use crate::util::ser::{Readable, Writeable};
+       use crate::util::test_utils;
+       use crate::prelude::*;
+       use crate::io;
+
+       #[test]
+       fn test_channel_id_v1_from_funding_txid() {
+               let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
+               assert_eq!(channel_id.0.as_hex().to_string(), "0202020202020202020202020202020202020202020202020202020202020203");
+       }
+
+       #[test]
+       fn test_channel_id_new_from_data() {
+               let data: [u8; 32] = [2; 32];
+               let channel_id = ChannelId::from_bytes(data.clone());
+               assert_eq!(channel_id.0, data);
+       }
+
+       #[test]
+       fn test_channel_id_equals() {
+               let channel_id11 = ChannelId::v1_from_funding_txid(&[2; 32], 2);
+               let channel_id12 = ChannelId::v1_from_funding_txid(&[2; 32], 2);
+               let channel_id21 = ChannelId::v1_from_funding_txid(&[2; 32], 42);
+               assert_eq!(channel_id11, channel_id12);
+               assert_ne!(channel_id11, channel_id21);
+       }
+
+       #[test]
+       fn test_channel_id_write_read() {
+               let data: [u8; 32] = [2; 32];
+               let channel_id = ChannelId::from_bytes(data.clone());
+
+               let mut w = test_utils::TestVecWriter(Vec::new());
+               channel_id.write(&mut w).unwrap();
+
+               let channel_id_2 = ChannelId::read(&mut io::Cursor::new(&w.0)).unwrap();
+               assert_eq!(channel_id_2, channel_id);
+               assert_eq!(channel_id_2.0, data);
+       }
+
+       #[test]
+       fn test_channel_id_display() {
+               let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
+               assert_eq!(format!("{}", &channel_id), "0202020202020202020202020202020202020202020202020202020202020203");
+       }
+
+       #[test]
+       fn test_channel_id_v2_from_basepoints() {
+               // Ours greater than theirs
+               let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap());
+               let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
+
+               let mut engine = Sha256::engine();
+               engine.input(&theirs.0.serialize());
+               engine.input(&ours.0.serialize());
+               let expected_id = ChannelId(Sha256::from_engine(engine).to_byte_array());
+
+               assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
+
+               // Theirs greater than ours
+               let ours = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap());
+               let theirs = RevocationBasepoint(PublicKey::from_slice(&<Vec<u8>>::from_hex("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap());
+
+               let mut engine = Sha256::engine();
+               engine.input(&ours.0.serialize());
+               engine.input(&theirs.0.serialize());
+               let expected_id = ChannelId(Sha256::from_engine(engine).to_byte_array());
+
+               assert_eq!(ChannelId::v2_from_revocation_basepoints(&ours, &theirs), expected_id);
+       }
+}
index 75bbcab93f8e21f493c71c173e05dbe210c30149..01aae89138ff9a8ce9a18a595dafa28e96d3df8d 100644 (file)
@@ -28,7 +28,7 @@
 //! use lightning::offers::refund::Refund;
 //! use lightning::util::ser::Writeable;
 //!
-//! # use lightning::ln::PaymentHash;
+//! # use lightning::ln::types::PaymentHash;
 //! # use lightning::offers::invoice::{BlindedPayInfo, ExplicitSigningPubkey, InvoiceBuilder};
 //! # use lightning::blinded_path::BlindedPath;
 //! #
@@ -113,7 +113,7 @@ use core::time::Duration;
 use core::hash::{Hash, Hasher};
 use crate::io;
 use crate::blinded_path::BlindedPath;
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
 use crate::ln::channelmanager::PaymentId;
 use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures};
 use crate::ln::inbound_payment::ExpandedKey;
index 68683e5d36333d261acb58cdc8241ba74f364405..b8e64b5376862ea82402eae6a717c134bab2855d 100644 (file)
@@ -65,7 +65,7 @@ use core::ops::Deref;
 use crate::sign::EntropySource;
 use crate::io;
 use crate::blinded_path::BlindedPath;
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
 use crate::ln::channelmanager::PaymentId;
 use crate::ln::features::InvoiceRequestFeatures;
 use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
index f9aa90ba0500af0b23da09b30289931877aa9949..13a2d4854baf0b2ee9e6547a97f00c42a2c3d553 100644 (file)
@@ -91,7 +91,7 @@ use core::time::Duration;
 use crate::sign::EntropySource;
 use crate::io;
 use crate::blinded_path::BlindedPath;
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
 use crate::ln::channelmanager::PaymentId;
 use crate::ln::features::InvoiceRequestFeatures;
 use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
index 149ba15c3a2392d4caa98c5d63db02a1c988ab8b..ee8cf3a7c1764e018bfd7d096218c8e67aff09c4 100644 (file)
@@ -15,7 +15,7 @@ use bitcoin::secp256k1::schnorr::Signature;
 use core::time::Duration;
 use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode};
 use crate::sign::EntropySource;
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
 use crate::ln::features::BlindedHopFeatures;
 use crate::offers::invoice::BlindedPayInfo;
 use crate::offers::merkle::TaggedHash;
index 42bf20a78a51684056f896b50fc510d18b279d0f..db35ff01bf096184fd40ed61d16d38426d069809 100644 (file)
@@ -21,7 +21,7 @@ use bitcoin::hashes::Hash;
 use bitcoin::network::constants::Network;
 
 use crate::events::{MessageSendEvent, MessageSendEventsProvider};
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
 use crate::ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, SocketAddress, MAX_VALUE_MSAT};
 use crate::ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter};
index 59ec3f6186236d07b13ec3ae7a74b3b74dce3b58..8744761e72d01aaf5bc5ad1e6961f03123fe8c8b 100644 (file)
@@ -13,7 +13,7 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
 
 use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode};
 use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
 use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA};
 use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
 use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
@@ -3291,7 +3291,7 @@ mod tests {
        use crate::routing::test_utils::{add_channel, add_or_update_node, build_graph, build_line_graph, id_to_feature_flags, get_nodes, update_channel};
        use crate::chain::transaction::OutPoint;
        use crate::sign::EntropySource;
-       use crate::ln::ChannelId;
+       use crate::ln::types::ChannelId;
        use crate::ln::features::{BlindedHopFeatures, ChannelFeatures, InitFeatures, NodeFeatures};
        use crate::ln::msgs::{ErrorAction, LightningError, UnsignedChannelUpdate, MAX_VALUE_MSAT};
        use crate::ln::channelmanager;
@@ -8413,7 +8413,7 @@ pub(crate) mod bench_utils {
        use crate::chain::transaction::OutPoint;
        use crate::routing::scoring::ScoreUpdate;
        use crate::sign::KeysManager;
-       use crate::ln::ChannelId;
+       use crate::ln::types::ChannelId;
        use crate::ln::channelmanager::{self, ChannelCounterparty};
        use crate::util::config::UserConfig;
        use crate::util::test_utils::TestLogger;
index aa22eb366f3065e23199678988329bc63bab347a..a0409e545059280b4e413fbf583702414aa5237d 100644 (file)
@@ -10,7 +10,7 @@ use crate::ln::chan_utils::{
        ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction,
 };
 use crate::ln::msgs::UnsignedChannelAnnouncement;
-use crate::ln::PaymentPreimage;
+use crate::ln::types::PaymentPreimage;
 use crate::util::ser::Writeable;
 
 #[allow(unused_imports)]
index 1ff9db8d19886a30c3d4dff399d31e1c595c142c..79edf0aed2ef1f508e63694484b5095a48966373 100644 (file)
@@ -39,6 +39,7 @@ use bitcoin::{secp256k1, Sequence, Txid, Witness};
 
 use crate::chain::transaction::OutPoint;
 use crate::crypto::utils::{hkdf_extract_expand_twice, sign, sign_with_aux_rand};
+use crate::ln::chan_utils;
 use crate::ln::chan_utils::{
        get_revokeable_redeemscript, make_funding_redeemscript, ChannelPublicKeys,
        ChannelTransactionParameters, ClosingTransaction, CommitmentTransaction,
@@ -53,7 +54,7 @@ use crate::ln::channel_keys::{
 use crate::ln::msgs::PartialSignatureWithNonce;
 use crate::ln::msgs::{UnsignedChannelAnnouncement, UnsignedGossipMessage};
 use crate::ln::script::ShutdownScript;
-use crate::ln::{chan_utils, PaymentPreimage};
+use crate::ln::types::PaymentPreimage;
 use crate::offers::invoice::UnsignedBolt12Invoice;
 use crate::offers::invoice_request::UnsignedInvoiceRequest;
 use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
index e48cefaa0443ff9c0a1f731a35fdc73fba57d17b..904b7edd2f164f98b3a2572112fa033aa914a082 100644 (file)
@@ -20,7 +20,7 @@ use core::cmp;
 use core::fmt;
 use core::ops::Deref;
 
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 #[cfg(c_bindings)]
 use crate::prelude::*; // Needed for String
 
@@ -244,7 +244,7 @@ impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display fo
 #[cfg(test)]
 mod tests {
        use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
-       use crate::ln::ChannelId;
+       use crate::ln::types::ChannelId;
        use crate::util::logger::{Logger, Level, WithContext};
        use crate::util::test_utils::TestLogger;
        use crate::sync::Arc;
index f962251cd65bd7baf072a9bcbfa0d731d4bfec64..f6de098720f15c6e1c8e6893c97286df4524d794 100644 (file)
@@ -7,7 +7,7 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::sign::SpendableOutputDescriptor;
 
 use bitcoin::blockdata::transaction::Transaction;
index f88d9f36a72832ef1161c4ff65b48abb9e66a14a..5e7c6f8565946a938d198fd412583c07922372da 100644 (file)
@@ -39,7 +39,7 @@ use crate::chain::ClaimId;
 use crate::ln::msgs::DecodeError;
 #[cfg(taproot)]
 use crate::ln::msgs::PartialSignatureWithNonce;
-use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
+use crate::ln::types::{PaymentPreimage, PaymentHash, PaymentSecret};
 
 use crate::util::byte_utils::{be48_to_array, slice_to_be48};
 use crate::util::string::UntrustedString;
index 398216c0cef08449045d66170106abc116ca3784..5135549689ca52731d2f9212278fd77c488f9068 100644 (file)
@@ -13,7 +13,7 @@ use crate::chain::channelmonitor::ANTI_REORG_DELAY;
 use crate::chain::{self, BestBlock, Confirm, Filter, Listen, WatchedOutput};
 use crate::io;
 use crate::ln::msgs::DecodeError;
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::prelude::Vec;
 use crate::sign::{ChangeDestinationSource, OutputSpender, SpendableOutputDescriptor};
 use crate::sync::Mutex;
index 43ac9ff87e95f20d792aead9348a341dbb25b9e5..64320bbbaf55eb08f295296abc3109c5b23697ab 100644 (file)
@@ -10,7 +10,8 @@
 use crate::ln::channel::{ANCHOR_OUTPUT_VALUE_SATOSHI, MIN_CHAN_DUST_LIMIT_SATOSHIS};
 use crate::ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, HolderCommitmentTransaction, CommitmentTransaction, ChannelTransactionParameters, TrustedCommitmentTransaction, ClosingTransaction};
 use crate::ln::channel_keys::{HtlcKey};
-use crate::ln::{msgs, PaymentPreimage};
+use crate::ln::msgs;
+use crate::ln::types::PaymentPreimage;
 use crate::sign::{InMemorySigner, ChannelSigner};
 use crate::sign::ecdsa::{EcdsaChannelSigner, WriteableEcdsaChannelSigner};
 
index 95bc2a7c661982ea9062497f1647af434111dcd6..6b4d2acd4d993263674d0f987a6b53bf62276609 100644 (file)
@@ -24,7 +24,7 @@ use crate::routing::router::{CandidateRouteHop, FirstHopCandidate, PublicHopCand
 use crate::sign;
 use crate::events;
 use crate::events::bump_transaction::{WalletSource, Utxo};
-use crate::ln::ChannelId;
+use crate::ln::types::ChannelId;
 use crate::ln::channelmanager::{ChannelDetails, self};
 #[cfg(test)]
 use crate::ln::chan_utils::CommitmentTransaction;
index 51731c40d092dc3e706354c79e01568624569348..29f075c0a74dd4acb9ae41d0920805ae0a4f97a0 100644 (file)
 ./lightning/src/ln/reorg_tests.rs
 ./lightning/src/ln/script.rs
 ./lightning/src/ln/shutdown_tests.rs
+./lightning/src/ln/types.rs
 ./lightning/src/ln/wire.rs
 ./lightning/src/offers/invoice.rs
 ./lightning/src/offers/invoice_error.rs