Skip to content

Commit 2849ae2

Browse files
authored
Merge pull request #4183 from joostjager/debug-fmt
Add fmt::Debug implementation for FundedChannel
2 parents d53d6b4 + 067d659 commit 2849ae2

File tree

7 files changed

+48
-9
lines changed

7 files changed

+48
-9
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ pub fn build_closing_transaction(to_holder_value_sat: Amount, to_counterparty_va
393393
/// Allows us to keep track of all of the revocation secrets of our counterparty in just 50*32 bytes
394394
/// or so.
395395
#[derive(Clone)]
396+
#[cfg_attr(test, derive(Debug))]
396397
pub struct CounterpartyCommitmentSecrets {
397398
old_secrets: [([u8; 32], u64); 49],
398399
}

lightning/src/ln/channel.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ enum FeeUpdateState {
138138
Outbound,
139139
}
140140

141+
#[derive(Debug)]
141142
enum InboundHTLCRemovalReason {
142143
FailRelay(msgs::OnionErrorPacket),
143144
FailMalformed(([u8; 32], u16)),
144145
Fulfill(PaymentPreimage, Option<AttributionData>),
145146
}
146147

147148
/// Represents the resolution status of an inbound HTLC.
149+
#[cfg_attr(test, derive(Debug))]
148150
#[derive(Clone)]
149151
enum InboundHTLCResolution {
150152
/// Resolved implies the action we must take with the inbound HTLC has already been determined,
@@ -168,6 +170,7 @@ impl_writeable_tlv_based_enum!(InboundHTLCResolution,
168170
},
169171
);
170172

173+
#[cfg_attr(test, derive(Debug))]
171174
enum InboundHTLCState {
172175
/// Offered by remote, to be included in next local commitment tx. I.e., the remote sent an
173176
/// update_add_htlc message for this HTLC.
@@ -295,6 +298,7 @@ impl InboundHTLCState {
295298
}
296299
}
297300

301+
#[cfg_attr(test, derive(Debug))]
298302
struct InboundHTLCOutput {
299303
htlc_id: u64,
300304
amount_msat: u64,
@@ -303,7 +307,8 @@ struct InboundHTLCOutput {
303307
state: InboundHTLCState,
304308
}
305309

306-
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
310+
#[derive(Debug)]
311+
#[cfg_attr(test, derive(Clone, PartialEq))]
307312
enum OutboundHTLCState {
308313
/// Added by us and included in a commitment_signed (if we were AwaitingRemoteRevoke when we
309314
/// created it we would have put it in the holding cell instead). When they next revoke_and_ack
@@ -397,8 +402,8 @@ impl OutboundHTLCState {
397402
}
398403
}
399404

400-
#[derive(Clone)]
401-
#[cfg_attr(test, derive(Debug, PartialEq))]
405+
#[derive(Clone, Debug)]
406+
#[cfg_attr(test, derive(PartialEq))]
402407
enum OutboundHTLCOutcome {
403408
/// We started always filling in the preimages here in 0.0.105, and the requirement
404409
/// that the preimages always be filled in was added in 0.2.
@@ -415,7 +420,8 @@ impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
415420
}
416421
}
417422

418-
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
423+
#[derive(Debug)]
424+
#[cfg_attr(test, derive(Clone, PartialEq))]
419425
struct OutboundHTLCOutput {
420426
htlc_id: u64,
421427
amount_msat: u64,
@@ -430,7 +436,8 @@ struct OutboundHTLCOutput {
430436
}
431437

432438
/// See AwaitingRemoteRevoke ChannelState for more info
433-
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
439+
#[derive(Debug)]
440+
#[cfg_attr(test, derive(Clone, PartialEq))]
434441
enum HTLCUpdateAwaitingACK {
435442
AddHTLC {
436443
// TODO: Time out if we're getting close to cltv_expiry
@@ -1013,7 +1020,7 @@ macro_rules! secp_check {
10131020
/// spamming the network with updates if the connection is flapping. Instead, we "stage" updates to
10141021
/// our channel_update message and track the current state here.
10151022
/// See implementation at [`super::channelmanager::ChannelManager::timer_tick_occurred`].
1016-
#[derive(Clone, Copy, PartialEq)]
1023+
#[derive(Clone, Copy, PartialEq, Debug)]
10171024
pub(super) enum ChannelUpdateStatus {
10181025
/// We've announced the channel as enabled and are connected to our peer.
10191026
Enabled,
@@ -1026,6 +1033,7 @@ pub(super) enum ChannelUpdateStatus {
10261033
}
10271034

10281035
/// We track when we sent an `AnnouncementSignatures` to our peer in a few states, described here.
1036+
#[cfg_attr(test, derive(Debug))]
10291037
#[derive(PartialEq)]
10301038
pub enum AnnouncementSigsState {
10311039
/// We have not sent our peer an `AnnouncementSignatures` yet, or our peer disconnected since
@@ -1395,6 +1403,7 @@ pub(crate) const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 14 * 24 * 6 * 4;
13951403
#[cfg(test)]
13961404
pub(crate) const CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY: u32 = 144;
13971405

1406+
#[derive(Debug)]
13981407
struct PendingChannelMonitorUpdate {
13991408
update: ChannelMonitorUpdate,
14001409
}
@@ -2277,6 +2286,7 @@ impl UnfundedChannelContext {
22772286
/// Information pertaining to an attempt at funding the channel. This is typically constructed
22782287
/// during channel establishment and may be replaced during channel splicing or if the attempted
22792288
/// funding transaction is replaced using tx_init_rbf.
2289+
#[derive(Debug)]
22802290
pub(super) struct FundingScope {
22812291
value_to_self_msat: u64, // Excluding all pending_htlcs, fees, and anchor outputs
22822292

@@ -2604,6 +2614,7 @@ impl FundingScope {
26042614
/// Information about pending attempts at funding a channel. This includes funding currently under
26052615
/// negotiation and any negotiated attempts waiting enough on-chain confirmations. More than one
26062616
/// such attempt indicates use of RBF to increase the chances of confirmation.
2617+
#[derive(Debug)]
26072618
struct PendingFunding {
26082619
funding_negotiation: Option<FundingNegotiation>,
26092620

@@ -2625,6 +2636,7 @@ impl_writeable_tlv_based!(PendingFunding, {
26252636
(7, received_funding_txid, option),
26262637
});
26272638

2639+
#[derive(Debug)]
26282640
enum FundingNegotiation {
26292641
AwaitingAck {
26302642
context: FundingNegotiationContext,
@@ -2717,6 +2729,7 @@ impl PendingFunding {
27172729
}
27182730
}
27192731

2732+
#[derive(Debug)]
27202733
pub(crate) struct SpliceInstructions {
27212734
adjusted_funding_contribution: SignedAmount,
27222735
our_funding_inputs: Vec<FundingTxInput>,
@@ -2744,6 +2757,7 @@ impl_writeable_tlv_based!(SpliceInstructions, {
27442757
(11, locktime, required),
27452758
});
27462759

2760+
#[derive(Debug)]
27472761
pub(crate) enum QuiescentAction {
27482762
Splice(SpliceInstructions),
27492763
#[cfg(any(test, fuzzing))]
@@ -2790,6 +2804,7 @@ impl<'a> From<&'a Transaction> for ConfirmedTransaction<'a> {
27902804
}
27912805

27922806
/// Contains everything about the channel including state, and various flags.
2807+
#[cfg_attr(test, derive(Debug))]
27932808
pub(super) struct ChannelContext<SP: Deref>
27942809
where
27952810
SP::Target: SignerProvider,
@@ -6584,6 +6599,7 @@ fn check_v2_funding_inputs_sufficient(
65846599
}
65856600

65866601
/// Context for negotiating channels (dual-funded V2 open, splicing)
6602+
#[derive(Debug)]
65876603
pub(super) struct FundingNegotiationContext {
65886604
/// Whether we initiated the funding negotiation.
65896605
pub is_initiator: bool,
@@ -6723,6 +6739,7 @@ impl FundingNegotiationContext {
67236739

67246740
// Holder designates channel data owned for the benefit of the user client.
67256741
// Counterparty designates channel data owned by the another channel participant entity.
6742+
#[cfg_attr(test, derive(Debug))]
67266743
pub(super) struct FundedChannel<SP: Deref>
67276744
where
67286745
SP::Target: SignerProvider,
@@ -6742,7 +6759,7 @@ where
67426759
}
67436760

67446761
#[cfg(any(test, fuzzing))]
6745-
#[derive(Clone, Copy, Default)]
6762+
#[derive(Clone, Copy, Default, Debug)]
67466763
struct PredictedNextFee {
67476764
predicted_feerate: u32,
67486765
predicted_nondust_htlc_count: usize,

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,14 @@ pub struct PendingHTLCInfo {
431431
pub skimmed_fee_msat: Option<u64>,
432432
}
433433

434-
#[derive(Clone)] // See FundedChannel::revoke_and_ack for why, tl;dr: Rust bug
434+
#[derive(Clone, Debug)] // See FundedChannel::revoke_and_ack for why, tl;dr: Rust bug
435435
pub(super) enum HTLCFailureMsg {
436436
Relay(msgs::UpdateFailHTLC),
437437
Malformed(msgs::UpdateFailMalformedHTLC),
438438
}
439439

440440
/// Stores whether we can't forward an HTLC or relevant forwarding info
441+
#[cfg_attr(test, derive(Debug))]
441442
#[derive(Clone)] // See FundedChannel::revoke_and_ack for why, tl;dr: Rust bug
442443
pub(super) enum PendingHTLCStatus {
443444
Forward(PendingHTLCInfo),

lightning/src/ln/interactivetxs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ impl InteractiveTxInput {
18931893
}
18941894
}
18951895

1896+
#[derive(Debug)]
18961897
pub(super) struct InteractiveTxConstructor {
18971898
state_machine: StateMachine,
18981899
is_initiator: bool,
@@ -1905,6 +1906,7 @@ pub(super) struct InteractiveTxConstructor {
19051906
}
19061907

19071908
#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
1909+
#[derive(Debug)]
19081910
pub(crate) enum InteractiveTxMessageSend {
19091911
TxAddInput(msgs::TxAddInput),
19101912
TxAddOutput(msgs::TxAddOutput),

lightning/src/ln/script.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::prelude::*;
2121
/// A script pubkey for shutting down a channel as defined by [BOLT #2].
2222
///
2323
/// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
24+
#[cfg_attr(test, derive(Debug))]
2425
#[derive(Clone, PartialEq, Eq)]
2526
pub struct ShutdownScript(ShutdownScriptImpl);
2627

@@ -33,7 +34,7 @@ pub struct InvalidShutdownScript {
3334
pub script: ScriptBuf,
3435
}
3536

36-
#[derive(Clone, PartialEq, Eq)]
37+
#[derive(Clone, PartialEq, Eq, Debug)]
3738
enum ShutdownScriptImpl {
3839
/// [`PublicKey`] used to form a P2WPKH script pubkey. Used to support backward-compatible
3940
/// serialization.

lightning/src/sign/type_resolver.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ where
1212
Taproot(<SP::Target as SignerProvider>::TaprootSigner),
1313
}
1414

15+
#[cfg(test)]
16+
impl<SP> std::fmt::Debug for ChannelSignerType<SP>
17+
where
18+
SP: Deref,
19+
SP::Target: SignerProvider,
20+
{
21+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22+
f.debug_struct("ChannelSignerType").finish()
23+
}
24+
}
25+
1526
impl<SP: Deref> ChannelSignerType<SP>
1627
where
1728
SP::Target: SignerProvider,

lightning/src/util/test_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,12 @@ pub struct TestKeysInterface {
18071807
pub override_next_keys_id: Mutex<Option<[u8; 32]>>,
18081808
}
18091809

1810+
impl std::fmt::Debug for TestKeysInterface {
1811+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1812+
f.debug_struct("TestKeysInterface").finish()
1813+
}
1814+
}
1815+
18101816
impl EntropySource for TestKeysInterface {
18111817
fn get_secure_random_bytes(&self) -> [u8; 32] {
18121818
let override_random_bytes = self.override_random_bytes.lock().unwrap();

0 commit comments

Comments
 (0)