X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmsgs.rs;h=2e682410deb55fe1a86b9317861aef6c0ebb4b92;hb=d3ddf15357589ed10f4c844dc22822755b804306;hp=f86dc74befe255adc64caf31bdf8bff9cf91a697;hpb=34f8dd9a49060676da0cf4157613cfb5fd58cf1e;p=rust-lightning diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index f86dc74b..2e682410 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -28,10 +28,10 @@ use bitcoin::blockdata::constants::ChainHash; use bitcoin::secp256k1::PublicKey; use bitcoin::secp256k1::ecdsa::Signature; use bitcoin::{secp256k1, Witness}; -use bitcoin::blockdata::script::Script; +use bitcoin::blockdata::script::ScriptBuf; use bitcoin::hash_types::Txid; -use crate::blinded_path::payment::ReceiveTlvs; +use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs}; use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret}; use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; use crate::ln::onion_utils; @@ -46,11 +46,14 @@ use core::fmt::Debug; use core::ops::Deref; #[cfg(feature = "std")] use core::str::FromStr; +#[cfg(feature = "std")] +use std::net::SocketAddr; +use core::fmt::Display; use crate::io::{self, Cursor, Read}; use crate::io_extras::read_to_end; -use crate::events::{MessageSendEventsProvider, OnionMessageProvider}; -use crate::util::chacha20poly1305rfc::ChaChaPolyReadAdapter; +use crate::events::{EventsProvider, MessageSendEventsProvider}; +use crate::crypto::streams::ChaChaPolyReadAdapter; use crate::util::logger; use crate::util::ser::{LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname, TransactionU16LenLimited, BigSize}; use crate::util::base32; @@ -62,11 +65,11 @@ pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000; #[cfg(taproot)] /// A partial signature that also contains the Musig2 nonce its signer used -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct PartialSignatureWithNonce(pub musig2::types::PartialSignature, pub musig2::types::PublicNonce); /// An error in decoding a message or struct. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum DecodeError { /// A version byte specified something we don't know how to handle. /// @@ -93,7 +96,7 @@ pub enum DecodeError { /// An [`init`] message to be sent to or received from a peer. /// /// [`init`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-init-message -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct Init { /// The relevant features which the sender supports. pub features: InitFeatures, @@ -113,7 +116,7 @@ pub struct Init { /// An [`error`] message to be sent to or received from a peer. /// /// [`error`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ErrorMessage { /// The channel ID involved in the error. /// @@ -131,7 +134,7 @@ pub struct ErrorMessage { /// A [`warning`] message to be sent to or received from a peer. /// /// [`warning`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct WarningMessage { /// The channel ID involved in the warning. /// @@ -148,7 +151,7 @@ pub struct WarningMessage { /// A [`ping`] message to be sent to or received from a peer. /// /// [`ping`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-ping-and-pong-messages -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct Ping { /// The desired response length. pub ponglen: u16, @@ -161,7 +164,7 @@ pub struct Ping { /// A [`pong`] message to be sent to or received from a peer. /// /// [`pong`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-ping-and-pong-messages -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct Pong { /// The pong packet size. /// @@ -169,53 +172,54 @@ pub struct Pong { pub byteslen: u16, } -/// An [`open_channel`] message to be sent to or received from a peer. -/// -/// Used in V1 channel establishment +/// Contains fields that are both common to [`open_channel`] and `open_channel2` messages. /// /// [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct OpenChannel { +// TODO(dual_funding): Add spec link for `open_channel2`. +#[derive(Clone, Debug, Hash, PartialEq, Eq)] +pub struct CommonOpenChannelFields { /// The genesis hash of the blockchain where the channel is to be opened pub chain_hash: ChainHash, - /// A temporary channel ID, until the funding outpoint is announced + /// A temporary channel ID + /// For V2 channels: derived using a zeroed out value for the channel acceptor's revocation basepoint + /// For V1 channels: a temporary channel ID, until the funding outpoint is announced pub temporary_channel_id: ChannelId, - /// The channel value + /// For V1 channels: The channel value + /// For V2 channels: Part of the channel value contributed by the channel initiator pub funding_satoshis: u64, - /// The amount to push to the counterparty as part of the open, in milli-satoshi - pub push_msat: u64, - /// The threshold below which outputs on transactions broadcast by sender will be omitted + /// The threshold below which outputs on transactions broadcast by the channel initiator will be + /// omitted pub dust_limit_satoshis: u64, - /// The maximum inbound HTLC value in flight towards sender, in milli-satoshi + /// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi pub max_htlc_value_in_flight_msat: u64, - /// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel - pub channel_reserve_satoshis: u64, - /// The minimum HTLC size incoming to sender, in milli-satoshi + /// The minimum HTLC size incoming to channel initiator, in milli-satoshi pub htlc_minimum_msat: u64, - /// The feerate per 1000-weight of sender generated transactions, until updated by + /// The feerate for the commitment transaction set by the channel initiator until updated by /// [`UpdateFee`] - pub feerate_per_kw: u32, - /// The number of blocks which the counterparty will have to wait to claim on-chain funds if - /// they broadcast a commitment transaction + pub commitment_feerate_sat_per_1000_weight: u32, + /// The number of blocks which the counterparty will have to wait to claim on-chain funds if they + /// broadcast a commitment transaction pub to_self_delay: u16, - /// The maximum number of inbound HTLCs towards sender + /// The maximum number of inbound HTLCs towards channel initiator pub max_accepted_htlcs: u16, - /// The sender's key controlling the funding transaction + /// The channel initiator's key controlling the funding transaction pub funding_pubkey: PublicKey, /// Used to derive a revocation key for transactions broadcast by counterparty pub revocation_basepoint: PublicKey, - /// A payment key to sender for transactions broadcast by counterparty - pub payment_point: PublicKey, - /// Used to derive a payment key to sender for transactions broadcast by sender + /// A payment key to channel initiator for transactions broadcast by counterparty + pub payment_basepoint: PublicKey, + /// Used to derive a payment key to channel initiator for transactions broadcast by channel + /// initiator pub delayed_payment_basepoint: PublicKey, - /// Used to derive an HTLC payment key to sender + /// Used to derive an HTLC payment key to channel initiator pub htlc_basepoint: PublicKey, - /// The first to-be-broadcast-by-sender transaction's per commitment point + /// The first to-be-broadcast-by-channel-initiator transaction's per commitment point pub first_per_commitment_point: PublicKey, /// The channel flags to be used pub channel_flags: u8, - /// A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close - pub shutdown_scriptpubkey: Option