Skip to content

Commit 29285c8

Browse files
committed
errything
1 parent 72831aa commit 29285c8

30 files changed

+5429
-817
lines changed

channeldb/edge_info.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const (
2828
const (
2929
// EdgeInfo2MsgType is the tlv type used within the serialisation of
3030
// ChannelEdgeInfo2 for storing the serialisation of the associated
31-
// lnwire.ChannelAnnouncement2 message.
31+
// lnwire.ChannelAnnouncement2 message. This will exclude the signature
32+
// TLV record.
3233
EdgeInfo2MsgType = tlv.Type(0)
3334

3435
// EdgeInfo2Sig is the tlv type used within the serialisation of
@@ -182,17 +183,18 @@ func serializeChanEdgeInfo1(w io.Writer,
182183
}
183184

184185
func serializeChanEdgeInfo2(w io.Writer, edge *models.ChannelEdgeInfo2) error {
185-
if len(edge.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes {
186-
return ErrTooManyExtraOpaqueBytes(len(edge.ExtraOpaqueData))
187-
}
186+
//if len(edge.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes {
187+
// return ErrTooManyExtraOpaqueBytes(len(edge.ExtraOpaqueData))
188+
//}
188189

189-
serializedMsg, err := edge.DataToSign()
190-
if err != nil {
190+
var msgBuff bytes.Buffer
191+
if err := edge.EncodeAllNonSigFields(&msgBuff); err != nil {
191192
return err
192193
}
193194

195+
msgBytes := msgBuff.Bytes()
194196
records := []tlv.Record{
195-
tlv.MakePrimitiveRecord(EdgeInfo2MsgType, &serializedMsg),
197+
tlv.MakePrimitiveRecord(EdgeInfo2MsgType, &msgBytes),
196198
}
197199

198200
if edge.AuthProof != nil {
@@ -380,7 +382,7 @@ func deserializeChanEdgeInfo2(r io.Reader) (*models.ChannelEdgeInfo2, error) {
380382
}
381383

382384
reader := bytes.NewReader(msgBytes)
383-
err = edgeInfo.ChannelAnnouncement2.DecodeTLVRecords(reader)
385+
err = edgeInfo.ChannelAnnouncement2.DecodeNonSigTLVRecords(reader)
384386
if err != nil {
385387
return nil, err
386388
}

channeldb/edge_info_test.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ func TestEdgeInfoSerialisation(t *testing.T) {
133133
return mainScenario(&m)
134134
},
135135
genValue: func(v []reflect.Value, r *rand.Rand) {
136-
ann := lnwire.ChannelAnnouncement2{
137-
ExtraOpaqueData: make([]byte, 0),
138-
}
136+
var ann lnwire.ChannelAnnouncement2
137+
138+
ann.ExtraFieldsInSignedRange = randTLVMap(
139+
t, r, 1000000000,
140+
)
139141

140142
features := randRawFeatureVector(r)
141143
ann.Features.Val = *features
@@ -186,15 +188,6 @@ func TestEdgeInfoSerialisation(t *testing.T) {
186188
)
187189
}
188190

189-
numExtraBytes := r.Int31n(1000)
190-
if numExtraBytes > 0 {
191-
ann.ExtraOpaqueData = make(
192-
[]byte, numExtraBytes,
193-
)
194-
_, err := r.Read(ann.ExtraOpaqueData[:])
195-
require.NoError(t, err)
196-
}
197-
198191
info := &models.ChannelEdgeInfo2{
199192
ChannelAnnouncement2: ann,
200193
ChannelPoint: wire.OutPoint{
@@ -262,3 +255,31 @@ func randRawFeatureVector(r *rand.Rand) *lnwire.RawFeatureVector {
262255

263256
return featureVec
264257
}
258+
259+
func randTLVMap(t *testing.T, r *rand.Rand,
260+
rangeStart uint64) map[uint64][]byte {
261+
262+
var (
263+
m = make(map[uint64][]byte)
264+
265+
// We'll generate a random number of records, between 1 and 10.
266+
numRecords = r.Intn(9) + 1
267+
)
268+
269+
// For each record, we'll generate a random key and value.
270+
for i := 0; i < numRecords; i++ {
271+
// Keys must be equal to or greater than
272+
// MinCustomRecordsTlvType.
273+
keyOffset := uint64(r.Intn(100))
274+
key := rangeStart + keyOffset
275+
276+
// Values are byte slices of any length.
277+
value := make([]byte, r.Intn(10))
278+
_, err := r.Read(value)
279+
require.NoError(t, err)
280+
281+
m[key] = value
282+
}
283+
284+
return m
285+
}

channeldb/edge_policy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ func serializeChanEdgePolicy1(w io.Writer,
394394
func serializeChanEdgePolicy2(w io.Writer,
395395
edge *models.ChannelEdgePolicy2) error {
396396

397-
if len(edge.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes {
398-
return ErrTooManyExtraOpaqueBytes(len(edge.ExtraOpaqueData))
399-
}
397+
//if len(edge.ExtraOpaqueData) > MaxAllowedExtraOpaqueBytes {
398+
// return ErrTooManyExtraOpaqueBytes(len(edge.ExtraOpaqueData))
399+
//}
400400

401401
var b bytes.Buffer
402402
if err := edge.Encode(&b, 0); err != nil {

channeldb/edge_policy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ func TestEdgePolicySerialisation(t *testing.T) {
104104
policy := &models.ChannelEdgePolicy2{
105105
//nolint:lll
106106
ChannelUpdate2: lnwire.ChannelUpdate2{
107-
Signature: testSchnorrSig,
108107
ExtraOpaqueData: make([]byte, 0),
109108
},
110109
ToNode: [33]byte{},
111110
}
112111

112+
policy.Signature.Val = testSchnorrSig
113113
policy.ShortChannelID.Val = lnwire.NewShortChanIDFromInt( //nolint:lll
114114
uint64(r.Int63()),
115115
)

channeldb/models/channel_edge_info.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,16 @@ type ChannelEdgeInfo2 struct {
341341
func (c *ChannelEdgeInfo2) Copy() ChannelEdgeInfo {
342342
return &ChannelEdgeInfo2{
343343
ChannelAnnouncement2: lnwire.ChannelAnnouncement2{
344-
ChainHash: c.ChainHash,
345-
Features: c.Features,
346-
ShortChannelID: c.ShortChannelID,
347-
Capacity: c.Capacity,
348-
NodeID1: c.NodeID1,
349-
NodeID2: c.NodeID2,
350-
BitcoinKey1: c.BitcoinKey1,
351-
BitcoinKey2: c.BitcoinKey2,
352-
MerkleRootHash: c.MerkleRootHash,
353-
ExtraOpaqueData: c.ExtraOpaqueData,
344+
ChainHash: c.ChainHash,
345+
Features: c.Features,
346+
ShortChannelID: c.ShortChannelID,
347+
Capacity: c.Capacity,
348+
NodeID1: c.NodeID1,
349+
NodeID2: c.NodeID2,
350+
BitcoinKey1: c.BitcoinKey1,
351+
BitcoinKey2: c.BitcoinKey2,
352+
MerkleRootHash: c.MerkleRootHash,
353+
ExtraFieldsInSignedRange: c.ExtraFieldsInSignedRange,
354354
},
355355
ChannelPoint: c.ChannelPoint,
356356
AuthProof: c.AuthProof,

channeldb/models/channel_edge_policy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ func (c *ChannelEdgePolicy1) AfterUpdateMsg(msg lnwire.ChannelUpdate) (bool,
188188
return c.LastUpdate.After(timestamp), nil
189189
}
190190

191-
func (c *ChannelEdgePolicy1) ExtraData() lnwire.ExtraOpaqueData {
192-
return c.ExtraOpaqueData
191+
func (c *ChannelEdgePolicy1) ExtraData() (lnwire.ExtraOpaqueData, error) {
192+
return c.ExtraOpaqueData, nil
193193
}
194194

195195
// Sig returns the signature of the update message.
@@ -213,7 +213,7 @@ type ChannelEdgePolicy2 struct {
213213
//
214214
// NOTE: This is part of the ChannelEdgePolicy interface.
215215
func (c *ChannelEdgePolicy2) Sig() (input.Signature, error) {
216-
return c.Signature.ToSignature()
216+
return c.Signature.Val.ToSignature()
217217
}
218218

219219
// AfterUpdateMsg compares this update against the passed lnwire.ChannelUpdate

channeldb/models/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ type ChannelEdgePolicy interface {
9595
// Sig returns the signature of the update message.
9696
Sig() (input.Signature, error)
9797

98-
ExtraData() lnwire.ExtraOpaqueData
98+
ExtraData() (lnwire.ExtraOpaqueData, error)
9999
}

channeldb/waitingproof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ type TaprootWaitingProof struct {
265265
//
266266
// NOTE: this is part of the WaitingProofInterface.
267267
func (t *TaprootWaitingProof) SCID() lnwire.ShortChannelID {
268-
return t.ShortChannelID
268+
return t.ShortChannelID.Val
269269
}
270270

271271
// Decode parses the bytes from the given reader to reconstruct the

channeldb/waitingproof_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ func TestWaitingProofStore(t *testing.T) {
2525
})
2626

2727
// No agg nonce.
28-
proof2 := NewTaprootWaitingProof(true, &lnwire.AnnounceSignatures2{
29-
ShortChannelID: lnwire.ShortChannelID{
30-
BlockHeight: 2000,
31-
},
32-
PartialSignature: *randPartialSig(t),
33-
ExtraOpaqueData: make([]byte, 0),
34-
}, nil)
28+
proof2 := NewTaprootWaitingProof(
29+
true, lnwire.NewAnnSigs2(
30+
lnwire.ChannelID{},
31+
lnwire.ShortChannelID{BlockHeight: 2000},
32+
*randPartialSig(t),
33+
), nil,
34+
)
3535

3636
// With agg nonce.
3737
priv, err := btcec.NewPrivateKey()
3838
require.NoError(t, err)
3939

40-
proof3 := NewTaprootWaitingProof(true, &lnwire.AnnounceSignatures2{
41-
ShortChannelID: lnwire.ShortChannelID{
42-
BlockHeight: 2000,
43-
},
44-
PartialSignature: *randPartialSig(t),
45-
ExtraOpaqueData: make([]byte, 0),
46-
}, priv.PubKey())
40+
proof3 := NewTaprootWaitingProof(
41+
true, lnwire.NewAnnSigs2(
42+
lnwire.ChannelID{},
43+
lnwire.ShortChannelID{BlockHeight: 2000},
44+
*randPartialSig(t),
45+
), priv.PubKey(),
46+
)
4747

4848
proofs := []*WaitingProof{
4949
proof1,

discovery/gossiper.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,9 +2511,19 @@ func IsKeepAliveUpdate(update lnwire.ChannelUpdate,
25112511
if fwd.MaxHTLC != prevFwd.MinHTLC {
25122512
return false, nil
25132513
}
2514-
if !bytes.Equal(upd.ExtraOpaqueData, prev.ExtraOpaqueData) {
2514+
if len(upd.ExtraFieldsInSignedRange) != len(prev.ExtraFieldsInSignedRange) {
25152515
return false, nil
25162516
}
2517+
for t, b := range upd.ExtraFieldsInSignedRange {
2518+
bb, ok := prev.ExtraFieldsInSignedRange[t]
2519+
if !ok {
2520+
return false, nil
2521+
}
2522+
2523+
if !bytes.Equal(bb, b) {
2524+
return false, nil
2525+
}
2526+
}
25172527

25182528
return true, nil
25192529

@@ -3723,11 +3733,11 @@ func (d *AuthenticatedGossiper) handleAnnSig(nMsg *networkMsg,
37233733
}
37243734

37253735
ps1 := musig2.NewPartialSignature(
3726-
&a.PartialSignature.Sig, aggNonce,
3736+
&a.PartialSignature.Val.Sig, aggNonce,
37273737
)
37283738

37293739
ps2 := musig2.NewPartialSignature(
3730-
&oppProof.PartialSignature.Sig, aggNonce,
3740+
&oppProof.PartialSignature.Val.Sig, aggNonce,
37313741
)
37323742

37333743
// Now aggregate the partial sigs.
@@ -3933,7 +3943,7 @@ func buildChanProof(ann lnwire.ChannelAnnouncement) (
39333943

39343944
case *lnwire.ChannelAnnouncement2:
39353945
return &models.ChannelAuthProof2{
3936-
SchnorrSigBytes: a.Signature.ToSignatureBytes(),
3946+
SchnorrSigBytes: a.Signature.Val.ToSignatureBytes(),
39373947
}, nil
39383948

39393949
default:

funding/manager.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,7 +4774,7 @@ func (f *Manager) newTaprootChanAnnouncement(localPubKey,
47744774
// signature that signs a double-sha digest of the announcement.
47754775
// This'll serve to authenticate this announcement and any other future
47764776
// updates we may send.
4777-
chanUpdateMsg, err := chanUpdateAnn.DataToSign()
4777+
chanUpdateMsg, err := lnwire.SerialiseFieldsToSign(&chanUpdateAnn)
47784778
if err != nil {
47794779
return nil, err
47804780
}
@@ -4786,7 +4786,7 @@ func (f *Manager) newTaprootChanAnnouncement(localPubKey,
47864786
return nil, errors.Errorf("unable to generate channel "+
47874787
"update announcement signature: %v", err)
47884788
}
4789-
chanUpdateAnn.Signature, err = lnwire.NewSigFromSignature(sig)
4789+
chanUpdateAnn.Signature.Val, err = lnwire.NewSigFromSignature(sig)
47904790
if err != nil {
47914791
return nil, errors.Errorf("unable to generate channel "+
47924792
"update announcement signature: %v", err)
@@ -4894,11 +4894,9 @@ func (f *Manager) newTaprootChanAnnouncement(localPubKey,
48944894
// Finally, we'll generate the announcement proof which we'll use to
48954895
// provide the other side with the necessary signatures required to
48964896
// allow them to reconstruct the full channel announcement.
4897-
proof := &lnwire.AnnounceSignatures2{
4898-
ChannelID: chanID,
4899-
ShortChannelID: shortChanID,
4900-
PartialSignature: lnwire.NewPartialSig(*ps.S),
4901-
}
4897+
proof := lnwire.NewAnnSigs2(
4898+
chanID, shortChanID, lnwire.NewPartialSig(*ps.S),
4899+
)
49024900

49034901
return &chanAnnouncement{
49044902
chanAnn: &chanAnn,

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,5 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d
210210
go 1.22.6
211211

212212
retract v0.0.2
213+
214+
replace github.com/lightningnetwork/lnd/tlv => ./tlv

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,6 @@ github.com/lightningnetwork/lnd/sqldb v1.0.4 h1:9cMwPxcrLQG8UmyZO4q8SpR7NmxSwBMb
465465
github.com/lightningnetwork/lnd/sqldb v1.0.4/go.mod h1:4cQOkdymlZ1znnjuRNvMoatQGJkRneTj2CoPSPaQhWo=
466466
github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM=
467467
github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA=
468-
github.com/lightningnetwork/lnd/tlv v1.2.6 h1:icvQG2yDr6k3ZuZzfRdG3EJp6pHurcuh3R6dg0gv/Mw=
469-
github.com/lightningnetwork/lnd/tlv v1.2.6/go.mod h1:/CmY4VbItpOldksocmGT4lxiJqRP9oLxwSZOda2kzNQ=
470468
github.com/lightningnetwork/lnd/tor v1.1.2 h1:3zv9z/EivNFaMF89v3ciBjCS7kvCj4ZFG7XvD2Qq0/k=
471469
github.com/lightningnetwork/lnd/tor v1.1.2/go.mod h1:j7T9uJ2NLMaHwE7GiBGnpYLn4f7NRoTM6qj+ul6/ycA=
472470
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=

graph/notifications.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ func addToTopologyChange(graph DB, update *TopologyChange,
372372
return err
373373
}
374374

375+
extra, err := m.ExtraData()
376+
if err != nil {
377+
return err
378+
}
379+
375380
policy := m.ForwardingPolicy()
376381
edgeUpdate := &ChannelEdgeUpdate{
377382
ChanID: m.SCID().ToUint64(),
@@ -385,7 +390,7 @@ func addToTopologyChange(graph DB, update *TopologyChange,
385390
AdvertisingNode: aNode,
386391
ConnectingNode: cNode,
387392
Disabled: m.IsDisabled(),
388-
ExtraOpaqueData: m.ExtraData(),
393+
ExtraOpaqueData: extra,
389394
}
390395

391396
// TODO(roasbeef): add bit to toggle

htlcswitch/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error)
176176
case *lnwire.ChannelUpdate1:
177177
u.Signature = s
178178
case *lnwire.ChannelUpdate2:
179-
u.Signature = s
179+
u.Signature.Val = s
180180
}
181181

182182
return nil

lnrpc/routerrpc/router_backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ func marshallChannelUpdate(update lnwire.ChannelUpdate) (*lnrpc.ChannelUpdate,
17001700

17011701
case *lnwire.ChannelUpdate2:
17021702
return nil, &lnrpc.ChannelUpdate2{
1703-
Signature: upd.Signature.RawBytes(),
1703+
Signature: upd.Signature.Val.RawBytes(),
17041704
ChainHash: upd.ChainHash.Val[:],
17051705
ChanId: upd.ShortChannelID.Val.ToUint64(),
17061706
BlockHeight: upd.BlockHeight.Val,
@@ -1711,7 +1711,7 @@ func marshallChannelUpdate(update lnwire.ChannelUpdate) (*lnrpc.ChannelUpdate,
17111711
FeeRate: upd.FeeProportionalMillionths.Val,
17121712
HtlcMinimumMsat: uint64(upd.HTLCMinimumMsat.Val),
17131713
HtlcMaximumMsat: uint64(upd.HTLCMaximumMsat.Val),
1714-
ExtraOpaqueData: upd.ExtraOpaqueData,
1714+
//ExtraOpaqueData: upd.ExtraOpaqueData,
17151715
}, nil
17161716

17171717
default:

0 commit comments

Comments
 (0)