Skip to content

bolt: implement accept_channel2 message codec#37

Open
harsh04044 wants to merge 1 commit intomorehouse:masterfrom
harsh04044:bolt/accept-channel2
Open

bolt: implement accept_channel2 message codec#37
harsh04044 wants to merge 1 commit intomorehouse:masterfrom
harsh04044:bolt/accept-channel2

Conversation

@harsh04044
Copy link
Copy Markdown

Implements the accept_channel2 codec (type 65) for BOLT 2 dual-funded channel establishment.

accept_channel2 introduces a second per-commitment point compared to accept_channel, required for the v2 channel open flow. Tests cover roundtrip, trailing bytes, truncation at each scalar field boundary, and invalid public key detection for both the first and last key fields.

Part of #5.

Copy link
Copy Markdown
Contributor

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI didn't run for this yet, but it would fail because of formatting. Please make sure to run cargo fmt --all (or configure format on save).

@harsh04044 harsh04044 force-pushed the bolt/accept-channel2 branch from 8567b9a to ee7e288 Compare April 7, 2026 11:57
@harsh04044 harsh04044 force-pushed the bolt/accept-channel2 branch from ee7e288 to dedc305 Compare April 7, 2026 11:57
@harsh04044
Copy link
Copy Markdown
Author

The CI didn't run for this yet, but it would fail because of formatting. Please make sure to run cargo fmt --all (or configure format on save).

Done, addressed all suggestions.

Copy link
Copy Markdown
Owner

@morehouse morehouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI isn't passing.


/// TLV extensions for the `accept_channel2` message.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AcceptChannel2Tlvs;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A no-op TLV struct is not helpful. We need to implement the TLVs described in the spec.

Comment on lines +64 to +65
// 32 (channel_id) + 8*4 (u64 fields) + 4 (u32) + 2*2 (u16 fields) + 33*7 (pubkeys) = 303
let mut out = Vec::with_capacity(303);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: currently no other codecs preallocate Vec. For consistency I'd prefer to drop this for now. In the future, if we determine this is a worthwhile optimization, we can do it for all codecs at once.

/// to_self_delay(2) + max_accepted_htlcs(2) = 72 bytes.
const FIRST_PUBKEY_OFFSET: usize = 72;

fn sample_accept_channel2() -> AcceptChannel2 {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should allow TLVs to specified as a parameter, following the pattern of other codecs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants