Skip to content

Commit 4fed989

Browse files
committed
fix dummy_monitor current_counterparty_commitment_number in test helper instead of production constructor
The production constructor's 1 << 48 is a sentinel meaning 'counterparty commitment not yet received'. Changing it to (1 << 48) - 1 aligns it with INITIAL_COMMITMENT_NUMBER, which is observable in is_closed_without_updates(). Instead, fix the value in dummy_monitor() after construction so the sentinel is preserved in production code.
1 parent 170e67a commit 4fed989

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lightning/src/chain/channelmonitor.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
19521952
counterparty_hash_commitment_number: new_hash_map(),
19531953
counterparty_fulfilled_htlcs: new_hash_map(),
19541954

1955-
current_counterparty_commitment_number: (1 << 48) - 1,
1955+
current_counterparty_commitment_number: 1 << 48,
19561956
current_holder_commitment_number,
19571957

19581958
payment_preimages: new_hash_map(),
@@ -7017,7 +7017,7 @@ pub(super) fn dummy_monitor<S: EcdsaChannelSigner + 'static>(
70177017
let shutdown_script = crate::ln::script::ShutdownScript::new_p2wpkh_from_pubkey(dummy_key);
70187018
let best_block = BlockLocator::from_network(Network::Testnet);
70197019
let signer = wrap_signer(keys);
7020-
ChannelMonitor::new(
7020+
let monitor = ChannelMonitor::new(
70217021
secp_ctx,
70227022
signer,
70237023
Some(shutdown_script.into_inner()),
@@ -7031,7 +7031,13 @@ pub(super) fn dummy_monitor<S: EcdsaChannelSigner + 'static>(
70317031
dummy_key,
70327032
channel_id,
70337033
false,
7034-
)
7034+
);
7035+
// The production constructor sets current_counterparty_commitment_number to 1 << 48 as a
7036+
// sentinel meaning "counterparty commitment not yet received". This value (2^48) exceeds the
7037+
// 48-bit field in be48_to_array and causes a panic on serialization. Since dummy monitors
7038+
// may be serialized in tests, reset it to a valid value.
7039+
monitor.inner.lock().unwrap().current_counterparty_commitment_number = 0;
7040+
monitor
70357041
}
70367042

70377043
#[cfg(test)]

0 commit comments

Comments
 (0)