smite: add commitment_signed message codec implementation#24
smite: add commitment_signed message codec implementation#24kartikangiras wants to merge 1 commit into
Conversation
|
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. |
morehouse
left a comment
There was a problem hiding this comment.
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)
c0dfbac to
35607c7
Compare
morehouse
left a comment
There was a problem hiding this comment.
Please squash into one commit.
326f594 to
88aab2a
Compare
88aab2a to
b9d0980
Compare
|
@morehouse I have made all the necessary changes and ran all the checks locally. |
|
CI still doesn't pass... |
b9d0980 to
8a5a344
Compare
|
@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. |
8a5a344 to
6f941d0
Compare
|
@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). |
6f941d0 to
e01403c
Compare
e01403c to
a600125
Compare
a600125 to
215b12f
Compare
|
@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()); |
There was a problem hiding this comment.
We should create and use a TLV_FUNDING_TXID constant like we do for other codecs.
| Some(Txid::from_byte_array( | ||
| bytes.try_into().expect("length checked above"), |
There was a problem hiding this comment.
We should be using the WireFormat methods for Txid in encode and decode.
| htlc_signatures.push(sig); | ||
| } | ||
|
|
||
| let tlvs = CommitmentSignedTlvs::decode(cursor)?; |
There was a problem hiding this comment.
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.
| /// Returns `Truncated` if the payload is too short for any fixed field, also can return | ||
| /// `InvalidSignature` and TLV errors. |
There was a problem hiding this comment.
| /// 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() { |
There was a problem hiding this comment.
| fn funding_txid_roundtrip() { | |
| fn roundtrip_with_funding_txid() { |
| } | ||
|
|
||
| #[test] | ||
| fn different_funding_txids() { |
There was a problem hiding this comment.
| 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Why did you get rid of the exact length check here?
| 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); |
There was a problem hiding this comment.
Looks like a helper function for creating signatures could save several lines of code.
| } | ||
|
|
||
| #[test] | ||
| fn funding_txid_with_htlcs_roundtrip() { |
There was a problem hiding this comment.
| fn funding_txid_with_htlcs_roundtrip() { | |
| fn roundtrip_funding_txid_with_htlcs() { |
Add support for
commitment-signedcodec for BOLT 2 message.