Skip to content

smite: add commitment_signed message codec implementation#24

Open
kartikangiras wants to merge 1 commit into
morehouse:masterfrom
kartikangiras:codec-commitment-signed
Open

smite: add commitment_signed message codec implementation#24
kartikangiras wants to merge 1 commit into
morehouse:masterfrom
kartikangiras:codec-commitment-signed

Conversation

@kartikangiras
Copy link
Copy Markdown

Add support for commitment-signed codec for BOLT 2 message.

@kartikangiras
Copy link
Copy Markdown
Author

Hi @morehouse , Could you PTAL into this PR, it is the part of milestone 2 adding support for commitment-signed codec (channel-ready is implemented in other PR by another contributor). Thanks.

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.

Thanks for working on this. Please make sure CI passes before requesting another review. You should be able to run all the CI commands locally (e.g., cargo test, cargo fmt, cargo clippy --all-targets --all-features -- -D warnings)

Comment thread smite/src/bolt.rs Outdated
Comment thread smite/src/bolt.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from c0dfbac to 35607c7 Compare April 6, 2026 18:09
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.

Please squash into one commit.

Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs
@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from 326f594 to 88aab2a Compare April 7, 2026 18:42
@kartikangiras kartikangiras requested a review from morehouse April 8, 2026 19:16
@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from 88aab2a to b9d0980 Compare April 9, 2026 19:35
@kartikangiras
Copy link
Copy Markdown
Author

@morehouse I have made all the necessary changes and ran all the checks locally.

@morehouse
Copy link
Copy Markdown
Owner

CI still doesn't pass...

@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from b9d0980 to 8a5a344 Compare April 11, 2026 07:27
@kartikangiras
Copy link
Copy Markdown
Author

@morehouse The command (cargo clippy --all-targets --all-features -- -D warnings) fails locally on ARM64 based systems such as MacOS. due to which I am not able to cross verify locally my code. I have been facing this issue on all of my PR checks.

@ekzyis
Copy link
Copy Markdown
Contributor

ekzyis commented Apr 13, 2026

@morehouse The command (cargo clippy --all-targets --all-features -- -D warnings) fails locally on ARM64 based systems such as MacOS. due to which I am not able to cross verify locally my code. I have been facing this issue on all of my PR checks.

Oh, interesting! I think this is worth an issue, so we can fix it. Can you create one? Can you also share the logs in the issue then?

@kartikangiras
Copy link
Copy Markdown
Author

kartikangiras commented Apr 13, 2026

@morehouse The command (cargo clippy --all-targets --all-features -- -D warnings) fails locally on ARM64 based systems such as MacOS. due to which I am not able to cross verify locally my code. I have been facing this issue on all of my PR checks.

Oh, interesting! I think this is worth an issue, so we can fix it. Can you create one? Can you also share the logs in the issue then?

@ekzyis I have created an issue for this. While investigating further, I have founded the root cause of this problem and the necessary fix for it.

@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from 8a5a344 to 6f941d0 Compare April 30, 2026 18:49
@kartikangiras
Copy link
Copy Markdown
Author

@morehouse I have locally tested each command on a linux based machine (it took time because i was on a macbook and it natively does not support these commands).

@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from 6f941d0 to e01403c Compare April 30, 2026 19:20
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs
Comment thread smite/src/bolt/commitment_signed.rs Outdated
Comment thread smite/src/bolt/commitment_signed.rs
@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from e01403c to a600125 Compare May 1, 2026 17:50
@kartikangiras kartikangiras requested a review from morehouse May 1, 2026 17:58
@kartikangiras kartikangiras force-pushed the codec-commitment-signed branch from a600125 to 215b12f Compare May 1, 2026 18:20
@kartikangiras
Copy link
Copy Markdown
Author

@morehouse I have made all the necessary require changes as reviewed by you.

let mut stream = TlvStream::new();

if let Some(txid) = self.funding_txid {
stream.add(1, txid.to_byte_array().to_vec());
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 create and use a TLV_FUNDING_TXID constant like we do for other codecs.

Comment on lines +58 to +59
Some(Txid::from_byte_array(
bytes.try_into().expect("length checked above"),
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 be using the WireFormat methods for Txid in encode and decode.

htlc_signatures.push(sig);
}

let tlvs = CommitmentSignedTlvs::decode(cursor)?;
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.

I'd prefer to have consistency between the codecs -- either use the from_stream pattern here, or update all other codecs to move that logic into TLV decode functions.

Comment on lines +96 to +97
/// Returns `Truncated` if the payload is too short for any fixed field, also can return
/// `InvalidSignature` and TLV errors.
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.

Suggested change
/// Returns `Truncated` if the payload is too short for any fixed field, also can return
/// `InvalidSignature` and TLV errors.
/// Returns `Truncated` if the payload is too short, `InvalidSignature` if any signature
/// is malformed, or a TLV error if the TLV stream is malformed.

}

#[test]
fn funding_txid_roundtrip() {
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.

Suggested change
fn funding_txid_roundtrip() {
fn roundtrip_with_funding_txid() {

}

#[test]
fn different_funding_txids() {
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.

Suggested change
fn different_funding_txids() {
fn encode_different_funding_txids() {

fn encode_no_htlcs() {
let msg = sample_commitment_signed_no_htlcs();
let encoded = msg.encode();
assert!(encoded.len() > 96);
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.

Why did you get rid of the exact length check here?

fn encode_with_htlcs() {
let msg = sample_commitment_signed_with_htlcs();
let encoded = msg.encode();
assert!(encoded.len() > 32 + 64 + 2 + 2 * 64);
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.

Why did you get rid of the exact length check here?

Comment on lines +157 to +159
let sk3 = SecretKey::from_byte_array([0x33; 32]).expect("valid secret");
let msg3 = Message::from_digest([0xcc; 32]);
let sig3 = secp.sign_ecdsa(msg3, &sk3);
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.

Looks like a helper function for creating signatures could save several lines of code.

}

#[test]
fn funding_txid_with_htlcs_roundtrip() {
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.

Suggested change
fn funding_txid_with_htlcs_roundtrip() {
fn roundtrip_funding_txid_with_htlcs() {

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