X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmsgs.rs;h=c617d97fe52705c8673c6f4a68f331bb8ed644a6;hb=24db35eeea7049a3abde9766baf8dda69b462c3f;hp=df6a2aba3b9df821f742421aa90feca5f4a31069;hpb=ec3de62bc754ea6cf512488415b6e787e58e7337;p=rust-lightning diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index df6a2aba..c617d97f 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -24,27 +24,34 @@ //! raw socket events into your non-internet-facing system and then send routing events back to //! track the network on the less-secure system. +use bitcoin::blockdata::constants::ChainHash; use bitcoin::secp256k1::PublicKey; use bitcoin::secp256k1::ecdsa::Signature; -use bitcoin::secp256k1; +use bitcoin::{secp256k1, Witness}; use bitcoin::blockdata::script::Script; use bitcoin::hash_types::{Txid, BlockHash}; +use crate::blinded_path::payment::ReceiveTlvs; +use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret}; use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; use crate::ln::onion_utils; use crate::onion_message; +use crate::sign::{NodeSigner, Recipient}; use crate::prelude::*; +use core::convert::TryFrom; use core::fmt; use core::fmt::Debug; -use crate::io::{self, Read}; +use core::ops::Deref; +use core::str::FromStr; +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::util::logger; -use crate::util::ser::{LengthReadable, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname}; - -use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; +use crate::util::ser::{LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname, TransactionU16LenLimited, BigSize}; +use crate::util::base32; use crate::routing::gossip::{NodeAlias, NodeId}; @@ -88,13 +95,17 @@ pub enum DecodeError { pub struct Init { /// The relevant features which the sender supports. pub features: InitFeatures, + /// Indicates chains the sender is interested in. + /// + /// If there are no common chains, the connection will be closed. + pub networks: Option>, /// The receipient's network address. /// /// This adds the option to report a remote IP address back to a connecting peer using the init /// message. A node can decide to use that information to discover a potential update to its /// public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing /// the new address. - pub remote_network_address: Option, + pub remote_network_address: Option, } /// An [`error`] message to be sent to or received from a peer. @@ -106,7 +117,7 @@ pub struct ErrorMessage { /// /// All-0s indicates a general error unrelated to a specific channel, after which all channels /// with the sending peer should be closed. - pub channel_id: [u8; 32], + pub channel_id: ChannelId, /// A possibly human-readable error description. /// /// The string should be sanitized before it is used (e.g., emitted to logs or printed to @@ -123,7 +134,7 @@ pub struct WarningMessage { /// The channel ID involved in the warning. /// /// All-0s indicates a warning unrelated to a specific channel. - pub channel_id: [u8; 32], + pub channel_id: ChannelId, /// A possibly human-readable warning description. /// /// The string should be sanitized before it is used (e.g. emitted to logs or printed to @@ -158,13 +169,15 @@ pub struct Pong { /// An [`open_channel`] message to be sent to or received from a peer. /// +/// Used in V1 channel establishment +/// /// [`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 { /// The genesis hash of the blockchain where the channel is to be opened pub chain_hash: BlockHash, /// A temporary channel ID, until the funding outpoint is announced - pub temporary_channel_id: [u8; 32], + pub temporary_channel_id: ChannelId, /// The channel value pub funding_satoshis: u64, /// The amount to push to the counterparty as part of the open, in milli-satoshi @@ -208,13 +221,74 @@ pub struct OpenChannel { pub channel_type: Option, } +/// An open_channel2 message to be sent by or received from the channel initiator. +/// +/// Used in V2 channel establishment +/// +// TODO(dual_funding): Add spec link for `open_channel2`. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct OpenChannelV2 { + /// The genesis hash of the blockchain where the channel is to be opened + pub chain_hash: BlockHash, + /// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint + pub temporary_channel_id: ChannelId, + /// The feerate for the funding transaction set by the channel initiator + pub funding_feerate_sat_per_1000_weight: u32, + /// The feerate for the commitment transaction set by the channel initiator + pub commitment_feerate_sat_per_1000_weight: u32, + /// Part of the channel value contributed by the channel initiator + pub funding_satoshis: u64, + /// 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 channel initiator, in milli-satoshi + pub max_htlc_value_in_flight_msat: u64, + /// The minimum HTLC size incoming to channel initiator, in milli-satoshi + pub htlc_minimum_msat: u64, + /// 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 channel initiator + pub max_accepted_htlcs: u16, + /// The locktime for the funding transaction + pub locktime: u32, + /// 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 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 channel initiator + pub htlc_basepoint: PublicKey, + /// The first to-be-broadcast-by-channel-initiator transaction's per commitment point + pub first_per_commitment_point: PublicKey, + /// The second to-be-broadcast-by-channel-initiator transaction's per commitment point + pub second_per_commitment_point: PublicKey, + /// Channel flags + pub channel_flags: u8, + /// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we + /// collaboratively close + pub shutdown_scriptpubkey: Option