-
Notifications
You must be signed in to change notification settings - Fork 2.3k
DynComms [2/n]: lnwire: add authenticated wire messages for Dyn* #9148
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 12 commits into
lightningnetwork:master
from
ProofOfKeags:lnwire-dyncomms-update
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c686177
lnwire: remove no longer used initiator field
ProofOfKeags 60887ad
lnwire: add signature to DynAck
ProofOfKeags 42089b1
lnwire: add DynCommit message to match spec
yyforyongyu 36f53d7
lnwire: add convenience functions for protocol validation
ProofOfKeags cbca5b1
lnwire: remove kickoff feerate from propose/commit
ProofOfKeags f40530e
lnwire: remove FundingKey from DynPropose and DynCommit
ProofOfKeags 72582d4
lnwire: add HtlcMinimum to DynPropose and DynCommit
ProofOfKeags 79e4e74
lnwire: change DynPropose/DynCommit TLV numbers to align with spec
ProofOfKeags a72cadf
lnwire: convert DynPropose and DynCommit to use typed tlv records
ProofOfKeags 8456aef
gitignore: ignore test data from rapid
yyforyongyu 828486e
lnwire: fix unit test for `DynCommit`
yyforyongyu c64e3a6
lnwire: fix linter
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,3 +82,6 @@ coverage.txt | |
| /lnd-*/ | ||
|
|
||
| .aider* | ||
|
|
||
| # All test data generated from rapid. | ||
| */testdata | ||
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,146 @@ | ||
| package lnwire | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "io" | ||
|
|
||
| "github.com/btcsuite/btcd/btcutil" | ||
| "github.com/lightningnetwork/lnd/tlv" | ||
| ) | ||
|
|
||
| // DynCommit is a composite message that is used to irrefutably execute a | ||
| // dynamic commitment update. | ||
| type DynCommit struct { | ||
| // DynPropose is an embedded version of the original DynPropose message | ||
| // that initiated this negotiation. | ||
| DynPropose | ||
|
|
||
| // DynAck is an embedded version of the original DynAck message that | ||
| // countersigned this negotiation. | ||
| DynAck | ||
|
|
||
| // ExtraData is the set of data that was appended to this message to | ||
| // fill out the full maximum transport message size. These fields can | ||
| // be used to specify optional data such as custom TLV fields. | ||
| ExtraData ExtraOpaqueData | ||
| } | ||
|
|
||
| // A compile time check to ensure DynCommit implements the lnwire.Message | ||
| // interface. | ||
| var _ Message = (*DynCommit)(nil) | ||
|
|
||
| // A compile time check to ensure DynCommit implements the | ||
| // lnwire.SizeableMessage interface. | ||
| var _ SizeableMessage = (*DynCommit)(nil) | ||
|
|
||
| // Encode serializes the target DynAck into the passed io.Writer. Serialization | ||
| // will observe the rules defined by the passed protocol version. | ||
| // | ||
| // This is a part of the lnwire.Message interface. | ||
| func (dc *DynCommit) Encode(w *bytes.Buffer, _ uint32) error { | ||
| if err := WriteChannelID(w, dc.DynPropose.ChanID); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := WriteSig(w, dc.Sig); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| var extra ExtraOpaqueData | ||
| err := extra.PackRecords(dynProposeRecords(&dc.DynPropose)...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| dc.ExtraData = extra | ||
|
|
||
| return WriteBytes(w, dc.ExtraData) | ||
| } | ||
|
|
||
| // Decode deserializes the serialized DynCommit stored in the passed io.Reader | ||
| // into the target DynAck using the deserialization rules defined by the passed | ||
| // protocol version. | ||
| // | ||
| // This is a part of the lnwire.Message interface. | ||
| func (dc *DynCommit) Decode(r io.Reader, _ uint32) error { | ||
| // Parse out main message. | ||
| if err := ReadElements(r, &dc.DynPropose.ChanID, &dc.Sig); err != nil { | ||
| return err | ||
| } | ||
| dc.DynAck.ChanID = dc.DynPropose.ChanID | ||
|
|
||
| // Parse out TLV records. | ||
| var tlvRecords ExtraOpaqueData | ||
| if err := ReadElement(r, &tlvRecords); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Prepare receiving buffers to be filled by TLV extraction. | ||
| var dustLimit tlv.RecordT[tlv.TlvType0, uint64] | ||
| var maxValue tlv.RecordT[tlv.TlvType2, uint64] | ||
| var htlcMin tlv.RecordT[tlv.TlvType4, uint64] | ||
| var reserve tlv.RecordT[tlv.TlvType6, uint64] | ||
| csvDelay := dc.CsvDelay.Zero() | ||
| maxHtlcs := dc.MaxAcceptedHTLCs.Zero() | ||
| chanType := dc.ChannelType.Zero() | ||
|
|
||
| typeMap, err := tlvRecords.ExtractRecords( | ||
| &dustLimit, &maxValue, &htlcMin, &reserve, &csvDelay, &maxHtlcs, | ||
| &chanType, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Check the results of the TLV Stream decoding and appropriately set | ||
| // message fields. | ||
| if val, ok := typeMap[dc.DustLimit.TlvType()]; ok && val == nil { | ||
| var rec tlv.RecordT[tlv.TlvType0, btcutil.Amount] | ||
| rec.Val = btcutil.Amount(dustLimit.Val) | ||
| dc.DustLimit = tlv.SomeRecordT(rec) | ||
| } | ||
| if val, ok := typeMap[dc.MaxValueInFlight.TlvType()]; ok && val == nil { | ||
| var rec tlv.RecordT[tlv.TlvType2, MilliSatoshi] | ||
| rec.Val = MilliSatoshi(maxValue.Val) | ||
| dc.MaxValueInFlight = tlv.SomeRecordT(rec) | ||
| } | ||
| if val, ok := typeMap[dc.HtlcMinimum.TlvType()]; ok && val == nil { | ||
| var rec tlv.RecordT[tlv.TlvType4, MilliSatoshi] | ||
| rec.Val = MilliSatoshi(htlcMin.Val) | ||
| dc.HtlcMinimum = tlv.SomeRecordT(rec) | ||
| } | ||
| if val, ok := typeMap[dc.ChannelReserve.TlvType()]; ok && val == nil { | ||
| var rec tlv.RecordT[tlv.TlvType6, btcutil.Amount] | ||
| rec.Val = btcutil.Amount(reserve.Val) | ||
| dc.ChannelReserve = tlv.SomeRecordT(rec) | ||
| } | ||
| if val, ok := typeMap[dc.CsvDelay.TlvType()]; ok && val == nil { | ||
| dc.CsvDelay = tlv.SomeRecordT(csvDelay) | ||
| } | ||
| if val, ok := typeMap[dc.MaxAcceptedHTLCs.TlvType()]; ok && val == nil { | ||
| dc.MaxAcceptedHTLCs = tlv.SomeRecordT(maxHtlcs) | ||
| } | ||
| if val, ok := typeMap[dc.ChannelType.TlvType()]; ok && val == nil { | ||
| dc.ChannelType = tlv.SomeRecordT(chanType) | ||
| } | ||
|
|
||
| if len(tlvRecords) != 0 { | ||
| dc.ExtraData = tlvRecords | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // MsgType returns the MessageType code which uniquely identifies this message | ||
| // as a DynCommit on the wire. | ||
| // | ||
| // This is part of the lnwire.Message interface. | ||
| func (dc *DynCommit) MsgType() MessageType { | ||
| return MsgDynCommit | ||
| } | ||
|
|
||
| // SerializedSize returns the serialized size of the message in bytes. | ||
| // | ||
| // This is part of the lnwire.SizeableMessage interface. | ||
| func (dc *DynCommit) SerializedSize() (uint32, error) { | ||
| return MessageSerializedSize(dc) | ||
| } | ||
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.