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
After Node::setup_channel
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
impl Channel
Sourcepub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys
pub fn counterparty_pubkeys(&self) -> &ChannelPublicKeys
Get the counterparty’s public keys
Source§impl Channel
impl Channel
Sourcepub fn make_counterparty_tx_keys(
&self,
per_commitment_point: &PublicKey,
) -> TxCreationKeys
pub fn make_counterparty_tx_keys( &self, per_commitment_point: &PublicKey, ) -> TxCreationKeys
Public for testing purposes
Sourcepub 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>
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.
Sourcepub 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
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
Sourcepub 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
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
Sourcepub 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>
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.
Sourcepub fn revoke_previous_holder_commitment(
&mut self,
new_current_commitment_number: u64,
) -> Result<(PublicKey, Option<SecretKey>), Status>
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.
Sourcepub fn sign_holder_commitment_tx_phase2(
&mut self,
commitment_number: u64,
) -> Result<Signature, Status>
pub fn sign_holder_commitment_tx_phase2( &mut self, commitment_number: u64, ) -> Result<Signature, Status>
Sign a holder commitment when force-closing
Sourcepub fn sign_holder_commitment_tx_for_recovery(
&mut self,
) -> Result<(Transaction, Vec<Transaction>, ScriptBuf, (SecretKey, Vec<Vec<u8>>), PublicKey), Status>
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
Sourcepub 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>
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.
Sourcepub fn htlcs_info2_to_oic(
offered_htlcs: Vec<HTLCInfo2>,
received_htlcs: Vec<HTLCInfo2>,
) -> Vec<HTLCOutputInCommitment>
pub fn htlcs_info2_to_oic( offered_htlcs: Vec<HTLCInfo2>, received_htlcs: Vec<HTLCInfo2>, ) -> Vec<HTLCOutputInCommitment>
Public for testing purposes
Sourcepub fn make_channel_parameters(&self) -> ChannelTransactionParameters
pub fn make_channel_parameters(&self) -> ChannelTransactionParameters
Build channel parameters, used to further build a commitment transaction
Sourcepub fn get_ldk_shutdown_script(&self) -> ScriptBuf
pub fn get_ldk_shutdown_script(&self) -> ScriptBuf
Get the shutdown script where our funds will go when we mutual-close
Sourcepub 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>
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
Sourcepub fn sign_delayed_sweep(
&self,
tx: &Transaction,
input: usize,
commitment_number: u64,
redeemscript: &Script,
amount_sat: u64,
wallet_path: &[u32],
) -> Result<Signature, Status>
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
Sourcepub 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>
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.
Sourcepub fn sign_justice_sweep(
&self,
tx: &Transaction,
input: usize,
revocation_secret: &SecretKey,
redeemscript: &Script,
amount_sat: u64,
wallet_path: &[u32],
) -> Result<Signature, Status>
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
Sourcepub fn sign_channel_announcement_with_funding_key(
&self,
announcement: &[u8],
) -> Signature
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
Sourcepub fn funding_signed(&self, tx: &Transaction, _vout: u32)
pub fn funding_signed(&self, tx: &Transaction, _vout: u32)
The node has signed our funding transaction
Sourcepub fn forget(&self) -> Result<(), Status>
pub fn forget(&self) -> Result<(), Status>
Mark this channel as forgotten by the node allowing it to be pruned
Sourcepub fn balance(&self) -> ChannelBalance
pub fn balance(&self) -> ChannelBalance
Return channel balances
Sourcepub fn sign_holder_anchor_input(
&self,
anchor_tx: &Transaction,
input: usize,
) -> Result<Signature, Status>
pub fn sign_holder_anchor_input( &self, anchor_tx: &Transaction, input: usize, ) -> Result<Signature, Status>
Sign a transaction that spends the anchor output
Sourcepub fn get_anchor_redeemscript(&self) -> ScriptBuf
pub fn get_anchor_redeemscript(&self) -> ScriptBuf
Get the anchor redeemscript
Source§impl Channel
impl Channel
Sourcepub 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>
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
Sourcepub 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>
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.
Sourcepub fn activate_initial_commitment(&mut self) -> Result<PublicKey, Status>
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.
Sourcepub fn validate_counterparty_revocation(
&mut self,
revoke_num: u64,
old_secret: &SecretKey,
) -> Result<(), Status>
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.
Sourcepub fn sign_mutual_close_tx(
&mut self,
tx: &Transaction,
opaths: &[Vec<u32>],
) -> Result<Signature, Status>
pub fn sign_mutual_close_tx( &mut self, tx: &Transaction, opaths: &[Vec<u32>], ) -> Result<Signature, Status>
Phase 1
Sourcepub 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>
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
Sourcepub 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>
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
Sourcepub 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>
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
Sourcepub 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>
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
Sourcepub fn get_unilateral_close_key(
&self,
commitment_point: &Option<PublicKey>,
revocation_pubkey: &Option<RevocationKey>,
) -> Result<(SecretKey, Vec<Vec<u8>>), Status>
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.
Sourcepub fn htlcs_fulfilled(&mut self, preimages: Vec<PaymentPreimage>)
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
impl ChannelBase for Channel
Source§fn get_channel_basepoints(&self) -> ChannelPublicKeys
fn get_channel_basepoints(&self) -> ChannelPublicKeys
Source§fn get_per_commitment_point(
&self,
commitment_number: u64,
) -> Result<PublicKey, Status>
fn get_per_commitment_point( &self, commitment_number: u64, ) -> Result<PublicKey, Status>
Source§fn get_per_commitment_secret(
&self,
commitment_number: u64,
) -> Result<SecretKey, Status>
fn get_per_commitment_secret( &self, commitment_number: u64, ) -> Result<SecretKey, Status>
Source§fn get_per_commitment_secret_or_none(
&self,
commitment_number: u64,
) -> Option<SecretKey>
fn get_per_commitment_secret_or_none( &self, commitment_number: u64, ) -> Option<SecretKey>
Auto Trait Implementations§
impl !Freeze for Channel
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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