-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix ExtraData field and use BigSize encodine
#10027
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
Merged
Roasbeef
merged 11 commits into
lightningnetwork:master
from
yyforyongyu:dyn-bigsize-msg
Jul 16, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f1cb54
lnwire: use `BigSize` for encoding btc amount
yyforyongyu 61ef83e
lnwire: patch unit test for `DynPropose`
yyforyongyu 5e93655
lnwire: fix encoding `ExtraData` in `DynPropose`
yyforyongyu e94ca84
lnwire: fix encoding of `MilliSatoshi`
yyforyongyu 5961f7a
lnwire: add method `ParseAndExtractExtraData`
yyforyongyu b7d2f68
lnwire: patch uint test for `DynAck`
yyforyongyu f39c367
lnwire: make `LocalNonce` an optional tlv record and fix extra data
yyforyongyu e6ab373
lnwire: add missing record `LocalNonce`
yyforyongyu 91797ad
lnwire: patch test and fix extra data in `DynCommit`
yyforyongyu 7a9f197
lnwire: simplify dyn decode methods
yyforyongyu 18916da
docs: update release notes
yyforyongyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package lnwire | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/lightningnetwork/lnd/lnutils" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestDynAckEncodeDecode checks that the Encode and Decode methods for DynAck | ||
| // work as expected. | ||
| func TestDynAckEncodeDecode(t *testing.T) { | ||
|
Collaborator
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. lovely lovely |
||
| t.Parallel() | ||
|
|
||
| // Generate random channel ID. | ||
| chanIDBytes, err := generateRandomBytes(32) | ||
| require.NoError(t, err) | ||
|
|
||
| var chanID ChannelID | ||
| copy(chanID[:], chanIDBytes) | ||
|
|
||
| // Generate random sig. | ||
| sigBytes, err := generateRandomBytes(64) | ||
| require.NoError(t, err) | ||
|
|
||
| var sig Sig | ||
| copy(sig.bytes[:], sigBytes) | ||
|
|
||
| // Create test data for the TLVs. The actual value doesn't matter, as we | ||
| // only care about that the raw bytes can be decoded into a msg, and the | ||
| // msg can be encoded into the exact same raw bytes. | ||
| testTlvData := []byte{ | ||
| // ExtraData - unknown tlv record. | ||
| // | ||
| // NOTE: This record is optional and occupies the type 1. | ||
| 0x1, // type. | ||
| 0x2, // length. | ||
| 0x79, 0x79, // value. | ||
|
|
||
| // LocalNonce tlv. | ||
| 0x14, // type. | ||
| 0x42, // length. | ||
| 0x2c, 0xd4, 0x53, 0x7d, 0xaa, 0x7b, // value. | ||
| 0x7e, 0xae, 0x18, 0x32, 0xa6, 0xc4, 0x29, 0xe9, 0xe0, 0x91, | ||
| 0x32, 0x7a, 0xaf, 0xd1, 0x1c, 0x2b, 0x04, 0xa0, 0x4d, 0xb5, | ||
| 0x6a, 0x6f, 0x8b, 0x6c, 0xdc, 0xd1, 0x80, 0x2d, 0xff, 0x72, | ||
| 0xd8, 0x3c, 0xfc, 0x01, 0x6e, 0x7c, 0x1a, 0xc8, 0x5e, 0x3a, | ||
| 0x16, 0x98, 0xbc, 0x9b, 0x6e, 0x22, 0x58, 0x96, 0x96, 0xad, | ||
| 0x88, 0xbf, 0xff, 0x59, 0x90, 0xbd, 0x36, 0x0b, 0x0b, 0x4d, | ||
|
|
||
| // ExtraData - unknown tlv. | ||
| 0x6f, // type. | ||
| 0x2, // length. | ||
| 0x79, 0x79, // value. | ||
| } | ||
|
|
||
| msg := &DynAck{} | ||
|
|
||
| // Pre-allocate a new slice with enough capacity for all three parts for | ||
| // efficiency. | ||
| totalLen := len(chanIDBytes) + len(sigBytes) + len(testTlvData) | ||
| rawBytes := make([]byte, 0, totalLen) | ||
|
|
||
| // Append each slice to the new rawBytes slice. | ||
| rawBytes = append(rawBytes, chanIDBytes...) | ||
| rawBytes = append(rawBytes, sigBytes...) | ||
| rawBytes = append(rawBytes, testTlvData...) | ||
|
|
||
| // Decode the raw bytes. | ||
| r := bytes.NewBuffer(rawBytes) | ||
| err = msg.Decode(r, 0) | ||
| require.NoError(t, err) | ||
|
|
||
| t.Logf("Encoded msg is %v", lnutils.SpewLogClosure(msg)) | ||
|
|
||
| // Encode the msg into raw bytes and assert the encoded bytes equal to | ||
| // the rawBytes. | ||
| w := new(bytes.Buffer) | ||
| err = msg.Encode(w, 0) | ||
| require.NoError(t, err) | ||
|
|
||
| require.Equal(t, rawBytes, w.Bytes()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.