Skip to content

Commit 067d659

Browse files
committed
Add fmt::Debug implementation for FundedChannel
To aid with debugging in tests.
1 parent 17f7858 commit 067d659

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
@@ -353,6 +353,7 @@ pub fn build_closing_transaction(to_holder_value_sat: Amount, to_counterparty_va
353353
/// Allows us to keep track of all of the revocation secrets of our counterparty in just 50*32 bytes
354354
/// or so.
355355
#[derive(Clone)]
356+
#[cfg_attr(test, derive(Debug))]
356357
pub struct CounterpartyCommitmentSecrets {
357358
old_secrets: [([u8; 32], u64); 49],
358359
}

lightning/src/ln/channel.rs

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

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

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

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

302+
#[cfg_attr(test, derive(Debug))]
299303
struct InboundHTLCOutput {
300304
htlc_id: u64,
301305
amount_msat: u64,
@@ -304,7 +308,8 @@ struct InboundHTLCOutput {
304308
state: InboundHTLCState,
305309
}
306310

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

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

419-
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
424+
#[derive(Debug)]
425+
#[cfg_attr(test, derive(Clone, PartialEq))]
420426
struct OutboundHTLCOutput {
421427
htlc_id: u64,
422428
amount_msat: u64,
@@ -431,7 +437,8 @@ struct OutboundHTLCOutput {
431437
}
432438

433439
/// See AwaitingRemoteRevoke ChannelState for more info
434-
#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
440+
#[derive(Debug)]
441+
#[cfg_attr(test, derive(Clone, PartialEq))]
435442
enum HTLCUpdateAwaitingACK {
436443
AddHTLC {
437444
// TODO: Time out if we're getting close to cltv_expiry
@@ -1014,7 +1021,7 @@ macro_rules! secp_check {
10141021
/// spamming the network with updates if the connection is flapping. Instead, we "stage" updates to
10151022
/// our channel_update message and track the current state here.
10161023
/// See implementation at [`super::channelmanager::ChannelManager::timer_tick_occurred`].
1017-
#[derive(Clone, Copy, PartialEq)]
1024+
#[derive(Clone, Copy, PartialEq, Debug)]
10181025
pub(super) enum ChannelUpdateStatus {
10191026
/// We've announced the channel as enabled and are connected to our peer.
10201027
Enabled,
@@ -1027,6 +1034,7 @@ pub(super) enum ChannelUpdateStatus {
10271034
}
10281035

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

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

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

@@ -2626,6 +2637,7 @@ impl_writeable_tlv_based!(PendingFunding, {
26262637
(7, received_funding_txid, option),
26272638
});
26282639

2640+
#[derive(Debug)]
26292641
enum FundingNegotiation {
26302642
AwaitingAck {
26312643
context: FundingNegotiationContext,
@@ -2718,6 +2730,7 @@ impl PendingFunding {
27182730
}
27192731
}
27202732

2733+
#[derive(Debug)]
27212734
pub(crate) struct SpliceInstructions {
27222735
adjusted_funding_contribution: SignedAmount,
27232736
our_funding_inputs: Vec<FundingTxInput>,
@@ -2745,6 +2758,7 @@ impl_writeable_tlv_based!(SpliceInstructions, {
27452758
(11, locktime, required),
27462759
});
27472760

2761+
#[derive(Debug)]
27482762
pub(crate) enum QuiescentAction {
27492763
Splice(SpliceInstructions),
27502764
#[cfg(any(test, fuzzing))]
@@ -2791,6 +2805,7 @@ impl<'a> From<&'a Transaction> for ConfirmedTransaction<'a> {
27912805
}
27922806

27932807
/// Contains everything about the channel including state, and various flags.
2808+
#[cfg_attr(test, derive(Debug))]
27942809
pub(super) struct ChannelContext<SP: Deref>
27952810
where
27962811
SP::Target: SignerProvider,
@@ -6585,6 +6600,7 @@ fn check_v2_funding_inputs_sufficient(
65856600
}
65866601

65876602
/// Context for negotiating channels (dual-funded V2 open, splicing)
6603+
#[derive(Debug)]
65886604
pub(super) struct FundingNegotiationContext {
65896605
/// Whether we initiated the funding negotiation.
65906606
pub is_initiator: bool,
@@ -6724,6 +6740,7 @@ impl FundingNegotiationContext {
67246740

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

67456762
#[cfg(any(test, fuzzing))]
6746-
#[derive(Clone, Copy, Default)]
6763+
#[derive(Clone, Copy, Default, Debug)]
67476764
struct PredictedNextFee {
67486765
predicted_feerate: u32,
67496766
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
@@ -1892,6 +1892,7 @@ impl InteractiveTxInput {
18921892
}
18931893
}
18941894

1895+
#[derive(Debug)]
18951896
pub(super) struct InteractiveTxConstructor {
18961897
state_machine: StateMachine,
18971898
is_initiator: bool,
@@ -1904,6 +1905,7 @@ pub(super) struct InteractiveTxConstructor {
19041905
}
19051906

19061907
#[allow(clippy::enum_variant_names)] // Clippy doesn't like the repeated `Tx` prefix here
1908+
#[derive(Debug)]
19071909
pub(crate) enum InteractiveTxMessageSend {
19081910
TxAddInput(msgs::TxAddInput),
19091911
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
@@ -1806,6 +1806,12 @@ pub struct TestKeysInterface {
18061806
pub override_next_keys_id: Mutex<Option<[u8; 32]>>,
18071807
}
18081808

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

0 commit comments

Comments
 (0)