-
Notifications
You must be signed in to change notification settings - Fork 471
Fix peer storage size cap to account for encryption overhead #4746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7017,7 +7017,7 @@ pub(super) fn dummy_monitor<S: EcdsaChannelSigner + 'static>( | |
| let shutdown_script = crate::ln::script::ShutdownScript::new_p2wpkh_from_pubkey(dummy_key); | ||
| let best_block = BlockLocator::from_network(Network::Testnet); | ||
| let signer = wrap_signer(keys); | ||
| ChannelMonitor::new( | ||
| let monitor = ChannelMonitor::new( | ||
| secp_ctx, | ||
| signer, | ||
| Some(shutdown_script.into_inner()), | ||
|
|
@@ -7031,7 +7031,13 @@ pub(super) fn dummy_monitor<S: EcdsaChannelSigner + 'static>( | |
| dummy_key, | ||
| channel_id, | ||
| false, | ||
| ) | ||
| ); | ||
| // The production constructor sets current_counterparty_commitment_number to 1 << 48 as a | ||
| // sentinel meaning "counterparty commitment not yet received". This value (2^48) exceeds the | ||
| // 48-bit field in be48_to_array and causes a panic on serialization. Since dummy monitors | ||
| // may be serialized in tests, reset it to a valid value. | ||
| monitor.inner.lock().unwrap().current_counterparty_commitment_number = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems ok, even though in reality commitment numbers start high and go down. So 0 isn't really the default for a fresh channel. But it is consistent with the dummy holder commitment.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that 0 isn't the real-world default — commitment numbers start high and decrement. It is consistent with the other dummy values (e.g., the dummy holder commitment uses commitment number 0), and being a valid 48-bit value that serializes without panicking is the main objective here. Happy to change it to INITIAL_COMMITMENT_NUMBER (= (1 << 48) - 1) if you'd prefer greater realism. |
||
| monitor | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make sure this test tests right on the boundary. Currently it also passes if I manually set overhead to 0 again.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With 200 monitors the total serialized_length() was insufficient to reach the cap, so the test passed regardless of the overhead value. I've increased num_monitors to 600 and added a lower-bound assertion (msg.data.len() > MAX_PEER_STORAGE_SIZE - 500) to verify the boundary is actually exercised. Fixed in ff9c956.