629 Commits
Author SHA1 Message Date
Elle Mouton 3fe40c6540 graph/db: add v2 fields to ChannelEdgePolicy model
Extend ChannelEdgePolicy to support v2 channel updates by adding:

- Version field to track gossip protocol version (v1 or v2).
- LastBlockHeight for v2's block-height-based timestamps.
- SecondPeer flag to indicate which peer announced the policy in v2.
- DisableFlags for v2-specific channel disable signaling.
- ExtraSignedFields map for v2 extra signed TLV data.

Add version-aware methods:
- IsNode1() determines if the policy was announced by node_1, handling
  both v1 (via ChannelFlags direction bit) and v2 (via SecondPeer).
- IsDisabled() checks disable status using ChannelFlags for v1 and
  DisableFlags for v2.
- String() provides version-appropriate string representations.

The new fields use zero values for v1 compatibility (Version defaults
to GossipVersion1, LastBlockHeight to 0, SecondPeer to false). This
lays the groundwork for v2 policy support; a subsequent commit will
handle reading and writing these fields from/to the database.
2026-02-13 07:21:24 +02:00
elnosh 34329c684e multi: rename experimental endorsement signal to accountable
Renames the endorsement signal to accountable to
match the latest proposal https://github.com/lightning/blips/pull/67
2026-01-06 09:12:31 -05:00
Erick Cestari 5a7925008e multi: enforce strict TLV length checks
This commit improves TLV decoding safety and consistency across multiple
packages by enforcing fixed-length requirements and adding unit tests to
prevent malformed TLV records from being accepted.

Changes include:

- lnwire:
  * Enforce 8-byte length in Fee TLV decoder.
  * Enforce PubNonceSize in Musig2Nonce TLV decoder.
  * Enforce 8-byte length in ShortChannelID TLV decoder.
  * Added roundtrip and invalid length tests for Fee, Musig2Nonce,
    and ShortChannelID records.

- routing/route:
  * Enforce Vertex TLV length (33 bytes).
  * Added encode/decode and invalid length tests for Vertex.

- tlv:
  * Enforce correct length in DBytes33 decoder (33 bytes).
  * Added tests ensuring all fixed-size primitive decoders reject
    incorrect TLV lengths.

By strictly validating TLV lengths, we prevent malformed or corrupted
TLV records from being silently accepted, improving protocol safety.
2025-12-29 19:18:49 -03:00
ziggie 84504fa8c5 lnwire: implement SerializedSize for onion messages 2025-11-16 09:28:12 +01:00
Gijs van Dam cb2d8abe40 lnwire: add onion message type
This message type is a message that carries an onion-encrypted payload
used for BOLT12 messages.
2025-11-12 22:54:03 +08:00
Elle Mouton ef0e6b78bb lnwire: let gossip messages implement GossipMessage 2025-11-12 22:54:03 +08:00
Elle Mouton 4d3bf6379a lnwire: define GossipVersion and GossipMessage
Define a GossipVersion enum along with a GossipMessage interface to be
satisfied by all gossip related messages. This will be useful later on
when we want to make decisions based on the protocol version that a
message is part of.
2025-11-12 22:54:02 +08:00
Elle Mouton 70054ac402 lnwire: add NodeAnnouncement interface
And ensure that both versions 1 and 2 implement it.
2025-11-12 22:54:02 +08:00
ziggie d2d56f2968 linter: remove unsupported linters from the codebase 2025-11-12 22:54:02 +08:00
ziggie 870d603ce5 multi: allow invalid tlv data when decoding payment fail info
Older payments might have a invalid tlv stream, we now catch this
case and add a unit test.
2025-11-03 12:54:29 +01:00
Elle Mouton b8ff9fbef3 lnwire: define NodeAnnouncement2
In this commit, the lnwire.NodeAnnouncement2 type is defined. This will
be used to represent the `node_announcement_2` message used in the
Gossip 2 (1.75) protocol.
2025-10-02 12:15:16 +02:00
Elle Mouton e24dd2f9e0 lnwire: let DNSAddress implement RecordProducer
In preparation for using this type as a TLV record, we let it implement
the RecordProducer interface.
2025-10-01 13:49:15 +02:00
Elle Mouton e9a4f22dd6 lnwire: add inbound fee to ChannelUpdate2
We leave a TODO that should be addressed after a discussion at the spec
meeting. For now, having the incorrect TLV type is not a problem since
this ChannelUpdate2 type is not used in production.
2025-10-01 13:13:32 +02:00
Elle Mouton b8abe130a5 multi: rename lnwire.NodeAnnouncement
In preparation for adding a NodeAnnouncement2 struct along with a
NodeAnnouncement interface, this commit renames the existing
NodeAnnouncment struct to NodeAnnouncement1.
2025-10-01 13:13:32 +02:00
Elle Mouton 8372524edf lnwire: add Outpoint to ChannelAnnouncement2
The latest version of the spec has the outpoint included in the
`channel_announcement2` message.
2025-10-01 13:13:32 +02:00
Elle Mouton 004a68e524 lnwire: add OutPoint type with TLV encoding support
Add a new OutPoint type that wraps wire.OutPoint and provides TLV
encoding/decoding capabilities through the tlv.RecordProducer interface.
This enables OutPoint to be used in TLV streams of messages.
2025-10-01 13:13:32 +02:00
Elle Mouton 769b44bfc6 lnwire: shorten method name 2025-10-01 13:13:31 +02:00
George Tsagkarelis 68bd35f7ad lnwire: update tests for init message 2025-09-23 19:05:46 +02:00
George Tsagkarelis 7724d0fa6d lnwire: add custom records to init
Before calling the new interface we first add the ability for the peer
message itself to encode the new data records.
2025-09-23 19:02:59 +02:00
Elle 055fb436e1 Merge pull request #9175 from ellemouton/g175UpdateMessageStructure
lnwire+netann: update structure of g175 messages to be pure TLV
2025-09-22 10:04:44 +02:00
Yong d1d3a82010 Merge pull request #9884 from ellemouton/relaxFeatureBitCheck
multi: use relaxed feature bit `Set` method for peer features
2025-09-10 17:22:16 +08:00
Elle Mouton d61a8af4c4 lnwire: re-usable address descriptor parsers
In this commit, the logic in ReadElements that is used to read a single
address descriptor from a io.Reader is separated out into a new function
so that the logic can be re-used elsewhere.
2025-09-03 08:32:37 +02:00
Elle Mouton f0a20c9d04 netadd: split ValidatenodeAnn into sig and field checks
Check that the node ann doesnt contain more than 1 DNS addr.
This will ensure that we now start rejecting new node announcements
with multiple DNS addrs since this check is called in the gossiper
before persisting a node ann to our local graph.

It also validates the DNS fields according to BOLT #7 specs.
2025-09-03 01:11:34 +00:00
Elle Mouton 670b26ba3d lnwire: add encoding/decoding for DNS addr
Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
2025-09-02 17:51:31 +00:00
Mohamed Awnallah a0057c2026 lnwire: add DNSAddress type 2025-09-02 17:51:31 +00:00
Mohamed AwnallahandElle Mouton 7acd6018c9 lnwire: remove AddrLen helper
In this commit, we remove `AddrLen` as prepration step
before adding DNS address type which will have a var length.

Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
2025-09-02 17:51:31 +00:00
Elle Mouton b77b698b9d lnwire: update AnnounceSigs2 to use pure TLV 2025-09-01 12:10:30 +02:00
Elle Mouton b6b764da71 lnwire+netann: update ChannelUpdate2
such that all fields are now TLV including the signature.
2025-09-01 12:10:30 +02:00
Elle Mouton 1f71f14587 lnwire+netann: update ChannelAnnouncement2 structure
Such that all fields are now TLV (including the signature).
2025-09-01 12:06:18 +02:00
Elle Mouton 5e7ca548aa lnwire: let ChannelID implement RecordProducer
So that we can use it as a TLV record type.
2025-09-01 11:05:23 +02:00
Elle Mouton 4addfd1d1f lnwire: introduce PureTLVMessage
PureTLVMessage describes an LN message that is a pure TLV stream. If the
message includes a signature, it will sign all the TLV records in the
inclusive ranges: 0 to 159 and 1000000000 to 2999999999.

A comprehensive test is added that shows how two versions of the same
message remain forward compatible.
2025-09-01 11:04:47 +02:00
Olaoluwa Osuntokun 47e9f05ddf Merge pull request #10027 from yyforyongyu/dyn-bigsize-msg
Fix `ExtraData` field and use `BigSize` encodine
2025-07-16 10:56:30 -07:00
Elle Mouton ed17574196 lnwire: fix RandNodeAlias to produce valid UTF-8
To ensure that the RandNodeAlias helper can be used elsewhere to
generate random aliases, we adjust it in this test to only produce valid
UTF-8 strings as required by the spec.
2025-07-15 18:06:05 +02:00
yyforyongyu 7a9f197de8 lnwire: simplify dyn decode methods
Remove the unnecessary convertions as suggested by Gemini.
2025-07-11 04:11:31 +03:00
yyforyongyu 91797ad1d2 lnwire: patch test and fix extra data in DynCommit 2025-07-11 04:11:31 +03:00
yyforyongyu e6ab37305c lnwire: add missing record LocalNonce
This record was never added to the `DynCommit`, but it's inherited from
the embedding msg `DynAck`.
2025-07-11 04:11:30 +03:00
yyforyongyu f39c3679f2 lnwire: make LocalNonce an optional tlv record and fix extra data
It should be an optional record instead of an fn option. In addition,
its tlv type is bumped to be 14 as this record is also included in the
`DynCommit`. If we use tlv type 0, it will create a conflict in the msg
`DynCommit`, which is fixed in the following commit.
2025-07-11 04:11:30 +03:00
yyforyongyu b7d2f68ed0 lnwire: patch uint test for DynAck 2025-07-11 04:11:30 +03:00
yyforyongyu 5961f7a1bd lnwire: add method ParseAndExtractExtraData
Similar to `ParseAndExtractCustomRecords`, we now add this helper method
to make sure the extra data is parsed correctly.
2025-07-11 04:11:30 +03:00
yyforyongyu e94ca84449 lnwire: fix encoding of MilliSatoshi
`MilliSatoshi` itself is already a `BigSize`, we just need to change the
decoding and encoding types to use that.
2025-07-11 04:11:29 +03:00
yyforyongyu 5e9365552c lnwire: fix encoding ExtraData in DynPropose
Previously we encode all the fields plus extra data to the field
`ExtraData`, this is now fixed by encoding only unknown data to extra
data. For known records, they are already encoded into the message
fields.
2025-07-11 04:11:29 +03:00
yyforyongyu 61ef83e9c2 lnwire: patch unit test for DynPropose 2025-07-11 04:09:11 +03:00
yyforyongyu 0f1cb54eb2 lnwire: use BigSize for encoding btc amount 2025-07-11 04:09:11 +03:00
Elle Mouton 8cf567b948 multi: use the "errors" package everywhere
Replace all usages of the "github.com/go-errors/errors" and
"github.com/pkg/errors" packages with the standard lib's "errors"
package. This ensures that error wrapping and `errors.Is` checks will
work as expected.
2025-06-30 09:46:55 +02:00
Elle Mouton b41a079901 multi: use relaxed feature bit Set method for peer features
The spec says: `The origin node MUST NOT set both the optional and
mandatory bits`. and so this is why we have the SafeSet method which
prevents us from accidentally setting both optional and required bits
for any of our own feature bits. But the spec then also says `if both
the optional and the mandatory feature bits in a pair are set, the
feature should be treated as mandatory.` which means that when we read
the feature vectors of our peers or from a payment request, we should be
a bit less strict and not error out. We should just set both bits which
will result in "IsRequired" returning true.

Update the `TestExtractIntentFromSendRequest` test to show the new
behaviour.
2025-06-25 13:14:31 +02:00
yyforyongyu c64e3a6c34 lnwire: fix linter 2025-06-25 14:53:22 +08:00
yyforyongyu 828486e35a lnwire: fix unit test for DynCommit 2025-06-25 14:53:20 +08:00
Keagan McClelland a72cadf2ed lnwire: convert DynPropose and DynCommit to use typed tlv records 2025-06-25 02:22:22 +08:00
Keagan McClelland 79e4e74447 lnwire: change DynPropose/DynCommit TLV numbers to align with spec 2025-06-25 02:09:08 +08:00
Keagan McClelland 72582d4acc lnwire: add HtlcMinimum to DynPropose and DynCommit 2025-06-25 02:08:58 +08:00