Struct Channel

Source
pub struct Channel {
    pub node: Weak<Node>,
    pub keys: InMemorySigner,
    pub enforcement_state: EnforcementState,
    pub setup: ChannelSetup,
    pub id0: ChannelId,
    pub id: Option<ChannelId>,
    pub monitor: ChainMonitorBase,
    /* private fields */
}
Expand description

Fields§

§node: Weak<Node>

A backpointer to the node

§keys: InMemorySigner

The signer for this channel

§enforcement_state: EnforcementState

Channel state for policy enforcement purposes

§setup: ChannelSetup

The negotiated channel setup

§id0: ChannelId

The initial channel ID

§id: Option<ChannelId>

The optional permanent channel ID

§monitor: ChainMonitorBase

The chain monitor base

Implementations§

Source§

impl Channel

Source

pub fn id(&self) -> ChannelId

The channel ID

Source

pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys

Get the counterparty’s public keys

Source§

impl Channel

Source

pub fn make_counterparty_tx_keys( &self, per_commitment_point: &PublicKey, ) -> TxCreationKeys

Public for testing purposes

Source

pub fn sign_counterparty_commitment_tx_phase2( &mut self, remote_per_commitment_point: &PublicKey, commitment_number: u64, feerate_per_kw: u32, to_holder_value_sat: u64, to_counterparty_value_sat: u64, offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, ) -> Result<(Signature, Vec<Signature>), Status>

Sign a counterparty commitment transaction after rebuilding it from the supplied arguments.

Source

pub fn make_counterparty_commitment_tx_with_keys( &self, keys: TxCreationKeys, commitment_number: u64, feerate_per_kw: u32, to_holder_value_sat: u64, to_counterparty_value_sat: u64, htlcs: Vec<HTLCOutputInCommitment>, ) -> CommitmentTransaction

Public for testing purposes

Source

pub fn make_counterparty_commitment_tx( &self, remote_per_commitment_point: &PublicKey, commitment_number: u64, feerate_per_kw: u32, to_holder_value_sat: u64, to_counterparty_value_sat: u64, htlcs: Vec<HTLCOutputInCommitment>, ) -> CommitmentTransaction

Public for testing purposes

Source

pub fn validate_holder_commitment_tx_phase2( &mut self, commitment_number: u64, feerate_per_kw: u32, to_holder_value_sat: u64, to_counterparty_value_sat: u64, offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, counterparty_commit_sig: &Signature, counterparty_htlc_sigs: &[Signature], ) -> Result<(), Status>

Validate the counterparty’s signatures on the holder’s commitment and HTLCs when the commitment_signed message is received.

Source

pub fn revoke_previous_holder_commitment( &mut self, new_current_commitment_number: u64, ) -> Result<(PublicKey, Option<SecretKey>), Status>

Revoke holder commitment N - 1 by disclosing its commitment secret. After this, N is the current holder commitment and N + 1 is the next holder commitment.

Returns the per_commitment_point for commitment N + 1 and the holder’s revocation secret for commitment N - 1 if N > 0.

[validate_holder_commitment_tx] (or the phase2 version) must be called before this method.

The node should have persisted this state change first, because we cannot safely roll back a revocation.

Source

pub fn sign_holder_commitment_tx_phase2( &mut self, commitment_number: u64, ) -> Result<Signature, Status>

Sign a holder commitment when force-closing

Source

pub fn sign_holder_commitment_tx_for_recovery( &mut self, ) -> Result<(Transaction, Vec<Transaction>, ScriptBuf, (SecretKey, Vec<Vec<u8>>), PublicKey), Status>

Sign a holder commitment and HTLCs when recovering from node failure Also returns the revocable scriptPubKey so we can identify our outputs Also returns the unilateral close key material

Source

pub fn sign_holder_commitment_tx_phase2_redundant( &mut self, commitment_number: u64, feerate_per_kw: u32, to_holder_value_sat: u64, to_counterparty_value_sat: u64, offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, ) -> Result<Signature, Status>

Sign a holder commitment transaction after rebuilding it from the supplied arguments. Use Channel::sign_counterparty_commitment_tx_phase2() instead of this, since that one uses the last counter-signed holder tx, which is simpler and doesn’t require re-validation of the holder tx.

Source

pub fn htlcs_info2_to_oic( offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, ) -> Vec<HTLCOutputInCommitment>

Public for testing purposes

Source

pub fn make_channel_parameters(&self) -> ChannelTransactionParameters

Build channel parameters, used to further build a commitment transaction

Source

pub fn get_ldk_shutdown_script(&self) -> ScriptBuf

Get the shutdown script where our funds will go when we mutual-close

Source

pub fn sign_mutual_close_tx_phase2( &mut self, to_holder_value_sat: u64, to_counterparty_value_sat: u64, holder_script: &Option<ScriptBuf>, counterparty_script: &Option<ScriptBuf>, holder_wallet_path_hint: &[u32], ) -> Result<Signature, Status>

Sign a mutual close transaction after rebuilding it from the supplied arguments

Source

pub fn sign_delayed_sweep( &self, tx: &Transaction, input: usize, commitment_number: u64, redeemscript: &Script, amount_sat: u64, wallet_path: &[u32], ) -> Result<Signature, Status>

Sign a delayed output that goes to us while sweeping a transaction we broadcast

Source

pub fn sign_counterparty_htlc_sweep( &self, tx: &Transaction, input: usize, remote_per_commitment_point: &PublicKey, redeemscript: &ScriptBuf, htlc_amount_sat: u64, wallet_path: &[u32], ) -> Result<Signature, Status>

Sign an offered or received HTLC output from a commitment the counterparty broadcast.

Source

pub fn sign_justice_sweep( &self, tx: &Transaction, input: usize, revocation_secret: &SecretKey, redeemscript: &Script, amount_sat: u64, wallet_path: &[u32], ) -> Result<Signature, Status>

Sign a justice transaction on an old state that the counterparty broadcast

Source

pub fn sign_channel_announcement_with_funding_key( &self, announcement: &[u8], ) -> Signature

Sign a channel announcement with both the node key and the funding key

Source

pub fn network(&self) -> Network

The node’s network

Source

pub fn funding_signed(&self, tx: &Transaction, _vout: u32)

The node has signed our funding transaction

Source

pub fn forget(&self) -> Result<(), Status>

Mark this channel as forgotten by the node allowing it to be pruned

Source

pub fn balance(&self) -> ChannelBalance

Return channel balances

Source

pub fn sign_holder_anchor_input( &self, anchor_tx: &Transaction, input: usize, ) -> Result<Signature, Status>

Sign a transaction that spends the anchor output

Source

pub fn get_anchor_redeemscript(&self) -> ScriptBuf

Get the anchor redeemscript

Source§

impl Channel

Source

pub fn sign_counterparty_commitment_tx( &mut self, tx: &Transaction, output_witscripts: &[Vec<u8>], remote_per_commitment_point: &PublicKey, commitment_number: u64, feerate_per_kw: u32, offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, ) -> Result<Signature, Status>

Phase 1

Source

pub fn validate_holder_commitment_tx( &mut self, tx: &Transaction, output_witscripts: &[Vec<u8>], commitment_number: u64, feerate_per_kw: u32, offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, counterparty_commit_sig: &Signature, counterparty_htlc_sigs: &[Signature], ) -> Result<(), Status>

Validate the counterparty’s signatures on the holder’s commitment and HTLCs when the commitment_signed message is received. Returns the next per_commitment_point and the holder’s revocation secret for the prior commitment. This method advances the expected next holder commitment number in the signer’s state.

Source

pub fn activate_initial_commitment(&mut self) -> Result<PublicKey, Status>

Activate commitment 0 explicitly

Commitment 0 is special because it doesn’t have a predecessor commitment. Since the revocation of the prior commitment normally makes a new commitment “current” this final step must be invoked explicitly.

Returns the next per_commitment_point.

Source

pub fn validate_counterparty_revocation( &mut self, revoke_num: u64, old_secret: &SecretKey, ) -> Result<(), Status>

Process the counterparty’s revocation

When this is provided, we know that the counterparty has committed to the next state.

Source

pub fn sign_mutual_close_tx( &mut self, tx: &Transaction, opaths: &[Vec<u32>], ) -> Result<Signature, Status>

Phase 1

Source

pub fn sign_holder_htlc_tx( &self, tx: &Transaction, commitment_number: u64, opt_per_commitment_point: Option<PublicKey>, redeemscript: &ScriptBuf, htlc_amount_sat: u64, output_witscript: &ScriptBuf, ) -> Result<TypedSignature, Status>

Phase 1

Source

pub fn sign_holder_htlc_tx_phase2( &self, tx: &Transaction, input: u32, commitment_number: u64, feerate: u32, is_offered: bool, cltv_expiry: u32, htlc_amount_msat: u64, payment_hash: PaymentHash, ) -> Result<TypedSignature, Status>

Sign a HTLC transaction hanging off a commitment transaction

Source

pub fn sign_counterparty_htlc_tx( &self, tx: &Transaction, remote_per_commitment_point: &PublicKey, redeemscript: &ScriptBuf, htlc_amount_sat: u64, output_witscript: &ScriptBuf, ) -> Result<TypedSignature, Status>

Phase 1

Source

pub fn sign_htlc_tx( &self, tx: &Transaction, per_commitment_point: &PublicKey, redeemscript: &ScriptBuf, htlc_amount_sat: u64, output_witscript: &ScriptBuf, is_counterparty: bool, txkeys: TxCreationKeys, ) -> Result<TypedSignature, Status>

Sign a 2nd level HTLC transaction hanging off a commitment transaction

Source

pub fn get_unilateral_close_key( &self, commitment_point: &Option<PublicKey>, revocation_pubkey: &Option<RevocationKey>, ) -> Result<(SecretKey, Vec<Vec<u8>>), Status>

Get the unilateral close key and the witness stack suffix, for sweeping our main output from a commitment transaction. If the revocation_pubkey is Some, then we are sweeping a holder commitment transaction, otherwise we are sweeping a counterparty commitment transaction. commitment_point is used to derive the key if it is Some. Since we don’t support legacy channels, commitment_point must be Some iff revocation_pubkey is Some.

Source

pub fn htlcs_fulfilled(&mut self, preimages: Vec<PaymentPreimage>)

Mark any in-flight payments (outgoing HTLCs) on this channel with the given preimage as filled. Any such payments adjust our expected balance downwards.

Trait Implementations§

Source§

impl ChannelBase for Channel

Source§

fn get_channel_basepoints(&self) -> ChannelPublicKeys

Get the channel basepoints and public keys
Source§

fn get_per_commitment_point( &self, commitment_number: u64, ) -> Result<PublicKey, Status>

Get the per-commitment point for a holder commitment transaction. Errors if the commitment number is too high given the current state.
Source§

fn get_per_commitment_secret( &self, commitment_number: u64, ) -> Result<SecretKey, Status>

Get the per-commitment secret for a holder commitment transaction Errors if the commitment number is not ready to be revoked given the current state.
Source§

fn get_per_commitment_secret_or_none( &self, commitment_number: u64, ) -> Option<SecretKey>

Get the per-commitment secret or None if the arg is out of range
Source§

fn check_future_secret( &self, commitment_number: u64, suggested: &SecretKey, ) -> Result<bool, Status>

Check a future secret to support option_data_loss_protect
Source§

fn validator(&self) -> Arc<dyn Validator>

Returns the validator for this channel
Source§

fn chaninfo(&self) -> SlotInfo

Channel information for logging
Source§

impl Clone for Channel

Source§

fn clone(&self) -> Channel

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Channel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more