Skip to content

Commit d9c3f1e

Browse files
committed
WIP: ChannelContext refactor
1 parent 59739ef commit d9c3f1e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,10 +1574,12 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15741574
announcement_sigs_state: AnnouncementSigsState,
15751575

15761576
secp_ctx: Secp256k1<secp256k1::All>,
1577+
// CHANGES
15771578
channel_value_satoshis: u64,
15781579

15791580
latest_monitor_update_id: u64,
15801581

1582+
// REQUIRES SCOPE
15811583
holder_signer: ChannelSignerType<SP>,
15821584
shutdown_scriptpubkey: Option<ShutdownScript>,
15831585
destination_script: ScriptBuf,
@@ -1587,6 +1589,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
15871589
// cost of others, but should really just be changed.
15881590

15891591
cur_counterparty_commitment_transaction_number: u64,
1592+
// CHANGES
15901593
value_to_self_msat: u64, // Excluding all pending_htlcs, fees, and anchor outputs
15911594
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
15921595
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
@@ -1664,6 +1667,7 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
16641667
/// time.
16651668
update_time_counter: u32,
16661669

1670+
// BOTH NEED TO CHANGE
16671671
#[cfg(debug_assertions)]
16681672
/// Max to_local and to_remote outputs in a locally-generated commitment transaction
16691673
holder_max_commitment_tx_output: Mutex<(u64, u64)>,
@@ -1702,8 +1706,11 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17021706
expecting_peer_commitment_signed: bool,
17031707

17041708
/// The hash of the block in which the funding transaction was included.
1709+
// UPDATE ON APPLYING SCOPE
17051710
funding_tx_confirmed_in: Option<BlockHash>,
1711+
// UPDATE ON APPLYING SCOPE
17061712
funding_tx_confirmation_height: u32,
1713+
// UPDATE ON APPLYING SCOPE
17071714
short_channel_id: Option<u64>,
17081715
/// Either the height at which this channel was created or the height at which it was last
17091716
/// serialized if it was serialized by versions prior to 0.0.103.
@@ -1728,8 +1735,10 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17281735
holder_max_htlc_value_in_flight_msat: u64,
17291736

17301737
/// minimum channel reserve for self to maintain - set by them.
1738+
// CHANGES
17311739
counterparty_selected_channel_reserve_satoshis: Option<u64>,
17321740

1741+
// CHANGES
17331742
#[cfg(test)]
17341743
pub(super) holder_selected_channel_reserve_satoshis: u64,
17351744
#[cfg(not(test))]
@@ -1746,9 +1755,11 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17461755

17471756
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
17481757

1758+
// WILL EVENTUALLY CHANGE
17491759
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
17501760
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
17511761
/// is_manual_broadcast is true) this will be a dummy empty transaction.
1762+
// NEEDS INVESTIGATION
17521763
funding_transaction: Option<Transaction>,
17531764
/// This flag indicates that it is the user's responsibility to validated and broadcast the
17541765
/// funding transaction.
@@ -1776,6 +1787,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
17761787
/// This can be used to rebroadcast the channel_announcement message later.
17771788
announcement_sigs: Option<(Signature, Signature)>,
17781789

1790+
// CHANGES?
1791+
//
17791792
// We save these values so we can make sure `next_local_commit_tx_fee_msat` and
17801793
// `next_remote_commit_tx_fee_msat` properly predict what the next commitment transaction fee will
17811794
// be, by comparing the cached values to the fee of the tranaction generated by
@@ -2768,6 +2781,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27682781
})
27692782
}
27702783

2784+
// CHANGES
27712785
pub(crate) fn get_value_to_self_msat(&self) -> u64 {self.value_to_self_msat}
27722786

27732787
/// Allowed in any state (including after shutdown)
@@ -2913,6 +2927,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29132927
self.outbound_scid_alias = outbound_scid_alias;
29142928
}
29152929

2930+
// CHANGES
29162931
/// Returns the funding_txo we either got from our peer, or were given by
29172932
/// get_funding_created.
29182933
pub fn get_funding_txo(&self) -> Option<OutPoint> {
@@ -3085,6 +3100,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30853100
self.channel_transaction_parameters.holder_selected_contest_delay
30863101
}
30873102

3103+
// NEED TO USE FUNDING PUBKEY FROM SCOPE
30883104
fn get_holder_pubkeys(&self) -> &ChannelPublicKeys {
30893105
&self.channel_transaction_parameters.holder_pubkeys
30903106
}
@@ -3094,6 +3110,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30943110
.as_ref().map(|params| params.selected_contest_delay)
30953111
}
30963112

3113+
// NEED TO USE FUNDING PUBKEY FROM SCOPE
30973114
fn get_counterparty_pubkeys(&self) -> &ChannelPublicKeys {
30983115
&self.channel_transaction_parameters.counterparty_parameters.as_ref().unwrap().pubkeys
30993116
}
@@ -3145,6 +3162,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31453162
})
31463163
}
31473164

3165+
// CHANGES
31483166
pub fn get_value_satoshis(&self) -> u64 {
31493167
self.channel_value_satoshis
31503168
}
@@ -3283,6 +3301,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32833301
/// have not yet committed it. Such HTLCs will only be included in transactions which are being
32843302
/// generated by the peer which proposed adding the HTLCs, and thus we need to understand both
32853303
/// which peer generated this transaction and "to whom" this transaction flows.
3304+
// PASS IN SCOPE
32863305
#[inline]
32873306
fn build_commitment_transaction<L: Deref>(&self, commitment_number: u64, keys: &TxCreationKeys, local: bool, generated_by_local: bool, logger: &L) -> CommitmentStats
32883307
where L::Target: Logger
@@ -3551,6 +3570,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35513570
make_funding_redeemscript(&self.get_holder_pubkeys().funding_pubkey, self.counterparty_funding_pubkey())
35523571
}
35533572

3573+
// CHANGES
35543574
fn counterparty_funding_pubkey(&self) -> &PublicKey {
35553575
&self.get_counterparty_pubkeys().funding_pubkey
35563576
}
@@ -3787,6 +3807,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37873807
/// Doesn't bother handling the
37883808
/// if-we-removed-it-already-but-haven't-fully-resolved-they-can-still-send-an-inbound-HTLC
37893809
/// corner case properly.
3810+
// NEEDS TO CONSIDER ALL SCOPES
37903811
pub fn get_available_balances<F: Deref>(&self, fee_estimator: &LowerBoundedFeeEstimator<F>)
37913812
-> AvailableBalances
37923813
where F::Target: FeeEstimator
@@ -3942,6 +3963,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
39423963
}
39433964
}
39443965

3966+
// CHANGES
39453967
pub fn get_holder_counterparty_selected_channel_reserve_satoshis(&self) -> (u64, Option<u64>) {
39463968
let context = &self;
39473969
(context.holder_selected_channel_reserve_satoshis, context.counterparty_selected_channel_reserve_satoshis)

0 commit comments

Comments
 (0)