Skip to content

Commit 8302203

Browse files
committed
Drop claimable from Balance::claimable_amount_satoshis fields
In Java/TypeScript, we map enums as a base class and each variant as a class which extends the base. In Java/TypeScript, functions and fields share the same namespace, which means we cannot have functions on an enum which have the same name as any fields in any enum variants. `Balance`'s `claimable_amount_satoshis` method aliases with fields in each variant, and thus ultimately doesn't compile in TypeScript. Because `Balance::claimable_amount_satoshis` has the same name as the fields, it's also a bit confusing, as it doesn't return the field for each variant, but sometimes returns zero if we're not sure we can claim the balance. Instead, we rename the fields in each enum variant to simply `amount_satoshis`, to avoid implying that we can definitely claim the balance.
1 parent 685f266 commit 8302203

File tree

2 files changed

+134
-147
lines changed

2 files changed

+134
-147
lines changed

lightning/src/chain/channelmonitor.rs

+30-43
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,14 @@ pub enum Balance {
576576
ClaimableOnChannelClose {
577577
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
578578
/// required to do so.
579-
claimable_amount_satoshis: u64,
579+
amount_satoshis: u64,
580580
},
581581
/// The channel has been closed, and the given balance is ours but awaiting confirmations until
582582
/// we consider it spendable.
583583
ClaimableAwaitingConfirmations {
584584
/// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
585585
/// were spent in broadcasting the transaction.
586-
claimable_amount_satoshis: u64,
586+
amount_satoshis: u64,
587587
/// The height at which an [`Event::SpendableOutputs`] event will be generated for this
588588
/// amount.
589589
confirmation_height: u32,
@@ -598,7 +598,7 @@ pub enum Balance {
598598
ContentiousClaimable {
599599
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
600600
/// required to do so.
601-
claimable_amount_satoshis: u64,
601+
amount_satoshis: u64,
602602
/// The height at which the counterparty may be able to claim the balance if we have not
603603
/// done so.
604604
timeout_height: u32,
@@ -613,7 +613,7 @@ pub enum Balance {
613613
MaybeTimeoutClaimableHTLC {
614614
/// The amount potentially available to claim, in satoshis, excluding the on-chain fees
615615
/// which will be required to do so.
616-
claimable_amount_satoshis: u64,
616+
amount_satoshis: u64,
617617
/// The height at which we will be able to claim the balance if our counterparty has not
618618
/// done so.
619619
claimable_height: u32,
@@ -626,7 +626,7 @@ pub enum Balance {
626626
MaybePreimageClaimableHTLC {
627627
/// The amount potentially available to claim, in satoshis, excluding the on-chain fees
628628
/// which will be required to do so.
629-
claimable_amount_satoshis: u64,
629+
amount_satoshis: u64,
630630
/// The height at which our counterparty will be able to claim the balance if we have not
631631
/// yet received the preimage and claimed it ourselves.
632632
expiry_height: u32,
@@ -643,7 +643,7 @@ pub enum Balance {
643643
///
644644
/// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
645645
/// were already spent.
646-
claimable_amount_satoshis: u64,
646+
amount_satoshis: u64,
647647
},
648648
}
649649

@@ -656,27 +656,14 @@ impl Balance {
656656
/// On-chain fees required to claim the balance are not included in this amount.
657657
pub fn claimable_amount_satoshis(&self) -> u64 {
658658
match self {
659-
Balance::ClaimableOnChannelClose {
660-
claimable_amount_satoshis,
661-
} => *claimable_amount_satoshis,
662-
Balance::ClaimableAwaitingConfirmations {
663-
claimable_amount_satoshis,
664-
..
665-
} => *claimable_amount_satoshis,
666-
Balance::ContentiousClaimable {
667-
claimable_amount_satoshis,
668-
..
669-
} => *claimable_amount_satoshis,
670-
Balance::MaybeTimeoutClaimableHTLC {
671-
..
672-
} => 0,
673-
Balance::MaybePreimageClaimableHTLC {
674-
..
675-
} => 0,
676-
Balance::CounterpartyRevokedOutputClaimable {
677-
claimable_amount_satoshis,
678-
..
679-
} => *claimable_amount_satoshis,
659+
Balance::ClaimableOnChannelClose { amount_satoshis, .. }|
660+
Balance::ClaimableAwaitingConfirmations { amount_satoshis, .. }|
661+
Balance::ContentiousClaimable { amount_satoshis, .. }|
662+
Balance::CounterpartyRevokedOutputClaimable { amount_satoshis, .. }
663+
=> *amount_satoshis,
664+
Balance::MaybeTimeoutClaimableHTLC { .. }|
665+
Balance::MaybePreimageClaimableHTLC { .. }
666+
=> 0,
680667
}
681668
}
682669
}
@@ -1672,7 +1659,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
16721659
if let Some(conf_thresh) = holder_delayed_output_pending {
16731660
debug_assert!(holder_commitment);
16741661
return Some(Balance::ClaimableAwaitingConfirmations {
1675-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1662+
amount_satoshis: htlc.amount_msat / 1000,
16761663
confirmation_height: conf_thresh,
16771664
});
16781665
} else if htlc_resolved.is_some() && !htlc_output_spend_pending {
@@ -1710,7 +1697,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
17101697
debug_assert!(!htlc.offered || htlc_spend_pending.is_none() || !htlc_spend_pending.unwrap().1,
17111698
"We don't (currently) generate preimage claims against revoked outputs, where did you get one?!");
17121699
return Some(Balance::CounterpartyRevokedOutputClaimable {
1713-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1700+
amount_satoshis: htlc.amount_msat / 1000,
17141701
});
17151702
}
17161703
} else if htlc.offered == holder_commitment {
@@ -1719,12 +1706,12 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
17191706
// and awaiting confirmations on it.
17201707
if let Some(conf_thresh) = holder_timeout_spend_pending {
17211708
return Some(Balance::ClaimableAwaitingConfirmations {
1722-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1709+
amount_satoshis: htlc.amount_msat / 1000,
17231710
confirmation_height: conf_thresh,
17241711
});
17251712
} else {
17261713
return Some(Balance::MaybeTimeoutClaimableHTLC {
1727-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1714+
amount_satoshis: htlc.amount_msat / 1000,
17281715
claimable_height: htlc.cltv_expiry,
17291716
payment_hash: htlc.payment_hash,
17301717
});
@@ -1738,20 +1725,20 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
17381725
debug_assert!(holder_timeout_spend_pending.is_none());
17391726
if let Some((conf_thresh, true)) = htlc_spend_pending {
17401727
return Some(Balance::ClaimableAwaitingConfirmations {
1741-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1728+
amount_satoshis: htlc.amount_msat / 1000,
17421729
confirmation_height: conf_thresh,
17431730
});
17441731
} else {
17451732
return Some(Balance::ContentiousClaimable {
1746-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1733+
amount_satoshis: htlc.amount_msat / 1000,
17471734
timeout_height: htlc.cltv_expiry,
17481735
payment_hash: htlc.payment_hash,
17491736
payment_preimage: *payment_preimage,
17501737
});
17511738
}
17521739
} else if htlc_resolved.is_none() {
17531740
return Some(Balance::MaybePreimageClaimableHTLC {
1754-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1741+
amount_satoshis: htlc.amount_msat / 1000,
17551742
expiry_height: htlc.cltv_expiry,
17561743
payment_hash: htlc.payment_hash,
17571744
});
@@ -1824,7 +1811,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
18241811
} else { None }
18251812
}) {
18261813
res.push(Balance::ClaimableAwaitingConfirmations {
1827-
claimable_amount_satoshis: value,
1814+
amount_satoshis: value,
18281815
confirmation_height: conf_thresh,
18291816
});
18301817
} else {
@@ -1847,7 +1834,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
18471834
descriptor: SpendableOutputDescriptor::StaticOutput { output, .. }
18481835
} = &event.event {
18491836
res.push(Balance::ClaimableAwaitingConfirmations {
1850-
claimable_amount_satoshis: output.value,
1837+
amount_satoshis: output.value,
18511838
confirmation_height: event.confirmation_threshold(),
18521839
});
18531840
if let Some(confirmed_to_self_idx) = confirmed_counterparty_output.map(|(idx, _)| idx) {
@@ -1866,7 +1853,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
18661853
.is_output_spend_pending(&BitcoinOutPoint::new(txid, confirmed_to_self_idx));
18671854
if output_spendable {
18681855
res.push(Balance::CounterpartyRevokedOutputClaimable {
1869-
claimable_amount_satoshis: amt,
1856+
amount_satoshis: amt,
18701857
});
18711858
}
18721859
} else {
@@ -1879,7 +1866,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
18791866
walk_htlcs!(true, false, us.current_holder_commitment_tx.htlc_outputs.iter().map(|(a, _, _)| a));
18801867
if let Some(conf_thresh) = pending_commitment_tx_conf_thresh {
18811868
res.push(Balance::ClaimableAwaitingConfirmations {
1882-
claimable_amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat,
1869+
amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat,
18831870
confirmation_height: conf_thresh,
18841871
});
18851872
}
@@ -1889,7 +1876,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
18891876
walk_htlcs!(true, false, prev_commitment.htlc_outputs.iter().map(|(a, _, _)| a));
18901877
if let Some(conf_thresh) = pending_commitment_tx_conf_thresh {
18911878
res.push(Balance::ClaimableAwaitingConfirmations {
1892-
claimable_amount_satoshis: prev_commitment.to_self_value_sat,
1879+
amount_satoshis: prev_commitment.to_self_value_sat,
18931880
confirmation_height: conf_thresh,
18941881
});
18951882
}
@@ -1902,7 +1889,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
19021889
// neither us nor our counterparty misbehaved. At worst we've under-estimated
19031890
// the amount we can claim as we'll punish a misbehaving counterparty.
19041891
res.push(Balance::ClaimableAwaitingConfirmations {
1905-
claimable_amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat,
1892+
amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat,
19061893
confirmation_height: conf_thresh,
19071894
});
19081895
}
@@ -1913,7 +1900,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
19131900
if htlc.transaction_output_index.is_none() { continue; }
19141901
if htlc.offered {
19151902
res.push(Balance::MaybeTimeoutClaimableHTLC {
1916-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1903+
amount_satoshis: htlc.amount_msat / 1000,
19171904
claimable_height: htlc.cltv_expiry,
19181905
payment_hash: htlc.payment_hash,
19191906
});
@@ -1923,14 +1910,14 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
19231910
// As long as the HTLC is still in our latest commitment state, treat
19241911
// it as potentially claimable, even if it has long-since expired.
19251912
res.push(Balance::MaybePreimageClaimableHTLC {
1926-
claimable_amount_satoshis: htlc.amount_msat / 1000,
1913+
amount_satoshis: htlc.amount_msat / 1000,
19271914
expiry_height: htlc.cltv_expiry,
19281915
payment_hash: htlc.payment_hash,
19291916
});
19301917
}
19311918
}
19321919
res.push(Balance::ClaimableOnChannelClose {
1933-
claimable_amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat + claimable_inbound_htlc_value_sat,
1920+
amount_satoshis: us.current_holder_commitment_tx.to_self_value_sat + claimable_inbound_htlc_value_sat,
19341921
});
19351922
}
19361923

0 commit comments

Comments
 (0)