Skip to content

Commit 23ae902

Browse files
committed
multi: use ChannelUpdate interface in various places
1 parent 3df0edc commit 23ae902

File tree

8 files changed

+80
-50
lines changed

8 files changed

+80
-50
lines changed

discovery/gossiper.go

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,9 @@ type channelUpdateID struct {
909909
// retrieve all necessary data to validate the channel existence.
910910
channelID lnwire.ShortChannelID
911911

912-
// Flags least-significant bit must be set to 0 if the creating node
913-
// corresponds to the first node in the previously sent channel
914-
// announcement and 1 otherwise.
915-
flags lnwire.ChanUpdateChanFlags
912+
disabled bool
913+
914+
direction bool
916915
}
917916

918917
// msgWithSenders is a wrapper struct around a message, and the set of peers
@@ -1021,32 +1020,49 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
10211020

10221021
// Channel updates are identified by the (short channel id,
10231022
// channelflags) tuple.
1024-
case *lnwire.ChannelUpdate1:
1023+
case lnwire.ChannelUpdate:
10251024
sender := route.NewVertex(message.source)
10261025
deDupKey := channelUpdateID{
1027-
msg.ShortChannelID,
1028-
msg.ChannelFlags,
1026+
msg.SCID(),
1027+
msg.IsDisabled(),
1028+
msg.IsNode1(),
10291029
}
10301030

1031-
oldTimestamp := uint32(0)
1031+
var (
1032+
older = false
1033+
newer = true
1034+
)
10321035
mws, ok := d.channelUpdates[deDupKey]
10331036
if ok {
10341037
// If we already have seen this message, record its
10351038
// timestamp.
1036-
update, ok := mws.msg.(*lnwire.ChannelUpdate1)
1039+
oldMsg, ok := mws.msg.(lnwire.ChannelUpdate)
10371040
if !ok {
1038-
log.Errorf("Expected *lnwire.ChannelUpdate1, "+
1039-
"got: %T", mws.msg)
1041+
log.Errorf("expected type "+
1042+
"lnwire.ChannelUpdate, got: %T",
1043+
mws.msg)
1044+
1045+
return
1046+
}
10401047

1048+
cmp, err := msg.CmpAge(oldMsg)
1049+
if err != nil {
10411050
return
10421051
}
10431052

1044-
oldTimestamp = update.Timestamp
1053+
newer = false
1054+
switch cmp {
1055+
case -1:
1056+
older = true
1057+
case 1:
1058+
newer = true
1059+
default:
1060+
}
10451061
}
10461062

10471063
// If we already had this message with a strictly newer
10481064
// timestamp, then we'll just discard the message we got.
1049-
if oldTimestamp > msg.Timestamp {
1065+
if older {
10501066
log.Debugf("Ignored outdated network message: "+
10511067
"peer=%v, msg=%s", message.peer, msg.MsgType())
10521068
return
@@ -1055,7 +1071,7 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
10551071
// If the message we just got is newer than what we previously
10561072
// have seen, or this is the first time we see it, then we'll
10571073
// add it to our map of announcements.
1058-
if oldTimestamp < msg.Timestamp {
1074+
if newer {
10591075
mws = msgWithSenders{
10601076
msg: msg,
10611077
isLocal: !message.isRemote,
@@ -1585,8 +1601,8 @@ func (d *AuthenticatedGossiper) isRecentlyRejectedMsg(msg lnwire.Message,
15851601

15861602
var scid uint64
15871603
switch m := msg.(type) {
1588-
case *lnwire.ChannelUpdate1:
1589-
scid = m.ShortChannelID.ToUint64()
1604+
case lnwire.ChannelUpdate:
1605+
scid = m.SCID().ToUint64()
15901606

15911607
case lnwire.ChannelAnnouncement:
15921608
scid = m.SCID().ToUint64()
@@ -2077,7 +2093,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
20772093
// should be inspected.
20782094
func (d *AuthenticatedGossiper) processZombieUpdate(
20792095
chanInfo models.ChannelEdgeInfo, scid lnwire.ShortChannelID,
2080-
msg *lnwire.ChannelUpdate1) error {
2096+
msg lnwire.ChannelUpdate) error {
20812097

20822098
// Since we've deemed the update as not stale above, before marking it
20832099
// live, we'll make sure it has been signed by the correct party. If we
@@ -2093,15 +2109,14 @@ func (d *AuthenticatedGossiper) processZombieUpdate(
20932109
}
20942110
if pubKey == nil {
20952111
return fmt.Errorf("incorrect pubkey to resurrect zombie "+
2096-
"with chan_id=%v", msg.ShortChannelID)
2112+
"with chan_id=%v", msg.SCID())
20972113
}
20982114

20992115
err := routing.VerifyChannelUpdateSignature(msg, pubKey)
21002116
if err != nil {
21012117
return fmt.Errorf("unable to verify channel "+
21022118
"update signature: %v", err)
21032119
}
2104-
21052120
// With the signature valid, we'll proceed to mark the
21062121
// edge as live and wait for the channel announcement to
21072122
// come through again.
@@ -2116,13 +2131,13 @@ func (d *AuthenticatedGossiper) processZombieUpdate(
21162131
case err != nil:
21172132
return fmt.Errorf("unable to remove edge with "+
21182133
"chan_id=%v from zombie index: %v",
2119-
msg.ShortChannelID, err)
2134+
msg.SCID(), err)
21202135

21212136
default:
21222137
}
21232138

21242139
log.Debugf("Removed edge with chan_id=%v from zombie "+
2125-
"index", msg.ShortChannelID)
2140+
"index", msg.SCID())
21262141

21272142
return nil
21282143
}
@@ -2704,7 +2719,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
27042719
// Reprocess the message, making sure we return an
27052720
// error to the original caller in case the gossiper
27062721
// shuts down.
2707-
case *lnwire.ChannelUpdate1:
2722+
case lnwire.ChannelUpdate:
27082723
log.Debugf("Reprocessing ChannelUpdate for "+
27092724
"shortChanID=%v",
27102725
msg.SCID().ToUint64())

discovery/gossiper_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,8 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
18561856
assertChannelUpdate := func(channelUpdate *lnwire.ChannelUpdate1) {
18571857
channelKey := channelUpdateID{
18581858
ua3.ShortChannelID,
1859-
ua3.ChannelFlags,
1859+
ua3.IsDisabled(),
1860+
ua3.IsNode1(),
18601861
}
18611862

18621863
mws, ok := announcements.channelUpdates[channelKey]
@@ -2791,7 +2792,7 @@ func TestRetransmit(t *testing.T) {
27912792
switch msg.(type) {
27922793
case lnwire.ChannelAnnouncement:
27932794
chanAnn++
2794-
case *lnwire.ChannelUpdate1:
2795+
case lnwire.ChannelUpdate:
27952796
chanUpd++
27962797
case *lnwire.NodeAnnouncement1:
27972798
nodeAnn++
@@ -3276,7 +3277,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
32763277
}
32773278

32783279
switch msg := msg.(type) {
3279-
case *lnwire.ChannelUpdate1:
3280+
case lnwire.ChannelUpdate:
32803281
assertMessage(t, staleChannelUpdate, msg)
32813282
case *lnwire.AnnounceSignatures1:
32823283
assertMessage(t, batch.localProofAnn, msg)

discovery/message_store.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func msgShortChanID(msg lnwire.Message) (lnwire.ShortChannelID, error) {
8585
switch msg := msg.(type) {
8686
case lnwire.AnnounceSignatures:
8787
shortChanID = msg.SCID()
88-
case *lnwire.ChannelUpdate1:
89-
shortChanID = msg.ShortChannelID
88+
case lnwire.ChannelUpdate:
89+
shortChanID = msg.SCID()
9090
default:
9191
return shortChanID, ErrUnsupportedMessage
9292
}
@@ -160,7 +160,7 @@ func (s *MessageStore) DeleteMessage(msg lnwire.Message,
160160
// In the event that we're attempting to delete a ChannelUpdate1
161161
// from the store, we'll make sure that we're actually deleting
162162
// the correct one as it can be overwritten.
163-
if msg, ok := msg.(*lnwire.ChannelUpdate1); ok {
163+
if msg, ok := msg.(lnwire.ChannelUpdate); ok {
164164
// Deleting a value from a bucket that doesn't exist
165165
// acts as a NOP, so we'll return if a message doesn't
166166
// exist under this key.
@@ -176,13 +176,18 @@ func (s *MessageStore) DeleteMessage(msg lnwire.Message,
176176

177177
// If the timestamps don't match, then the update stored
178178
// should be the latest one, so we'll avoid deleting it.
179-
m, ok := dbMsg.(*lnwire.ChannelUpdate1)
179+
m, ok := dbMsg.(lnwire.ChannelUpdate)
180180
if !ok {
181181
return fmt.Errorf("expected "+
182-
"*lnwire.ChannelUpdate1, got: %T",
183-
dbMsg)
182+
"lnwire.ChannelUpdate, got: %T", dbMsg)
183+
}
184+
185+
diff, err := msg.CmpAge(m)
186+
if err != nil {
187+
return err
184188
}
185-
if msg.Timestamp != m.Timestamp {
189+
190+
if diff != 0 {
186191
return nil
187192
}
188193
}

discovery/message_store_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ func TestMessageStoreMessages(t *testing.T) {
116116
for _, msg := range peerMsgs {
117117
var shortChanID uint64
118118
switch msg := msg.(type) {
119-
case *lnwire.AnnounceSignatures1:
120-
shortChanID = msg.ShortChannelID.ToUint64()
121-
case *lnwire.ChannelUpdate1:
122-
shortChanID = msg.ShortChannelID.ToUint64()
119+
case lnwire.AnnounceSignatures:
120+
shortChanID = msg.SCID().ToUint64()
121+
case lnwire.ChannelUpdate:
122+
shortChanID = msg.SCID().ToUint64()
123123
default:
124124
t.Fatalf("found unexpected message type %T", msg)
125125
}

funding/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ func (f *Manager) ensureInitialForwardingPolicy(chanID lnwire.ChannelID,
40514051
// send out to the network after a new channel has been created locally.
40524052
type chanAnnouncement struct {
40534053
chanAnn lnwire.ChannelAnnouncement
4054-
chanUpdateAnn *lnwire.ChannelUpdate1
4054+
chanUpdateAnn lnwire.ChannelUpdate
40554055
chanProof lnwire.AnnounceSignatures
40564056
}
40574057

funding/manager_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
11971197
switch m := msg.(type) {
11981198
case lnwire.ChannelAnnouncement:
11991199
gotChannelAnnouncement = true
1200-
case *lnwire.ChannelUpdate1:
1200+
case lnwire.ChannelUpdate:
12011201

12021202
// The channel update sent by the node should
12031203
// advertise the MinHTLC value required by the
@@ -1212,31 +1212,33 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
12121212
baseFee := aliceCfg.DefaultRoutingPolicy.BaseFee
12131213
feeRate := aliceCfg.DefaultRoutingPolicy.FeeRate
12141214

1215-
require.EqualValues(t, 1, m.MessageFlags)
1215+
pol := m.ForwardingPolicy()
1216+
1217+
require.True(t, pol.HasMaxHTLC)
12161218

12171219
// We might expect a custom MinHTLC value.
12181220
if len(customMinHtlc) > 0 {
12191221
minHtlc = customMinHtlc[j]
12201222
}
1221-
require.Equal(t, minHtlc, m.HtlcMinimumMsat)
1223+
require.Equal(t, minHtlc, pol.MinHTLC)
12221224

12231225
// We might expect a custom MaxHltc value.
12241226
if len(customMaxHtlc) > 0 {
12251227
maxHtlc = customMaxHtlc[j]
12261228
}
1227-
require.Equal(t, maxHtlc, m.HtlcMaximumMsat)
1229+
require.Equal(t, maxHtlc, pol.MaxHTLC)
12281230

12291231
// We might expect a custom baseFee value.
12301232
if len(baseFees) > 0 {
12311233
baseFee = baseFees[j]
12321234
}
1233-
require.EqualValues(t, baseFee, m.BaseFee)
1235+
require.EqualValues(t, baseFee, pol.BaseFee)
12341236

12351237
// We might expect a custom feeRate value.
12361238
if len(feeRates) > 0 {
12371239
feeRate = feeRates[j]
12381240
}
1239-
require.EqualValues(t, feeRate, m.FeeRate)
1241+
require.EqualValues(t, feeRate, pol.FeeRate)
12401242

12411243
gotChannelUpdate = true
12421244
}

peer/brontide.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,7 @@ out:
17211721
}
17221722

17231723
case *lnwire.ChannelUpdate1,
1724+
*lnwire.ChannelUpdate2,
17241725
*lnwire.ChannelAnnouncement1,
17251726
*lnwire.ChannelAnnouncement2,
17261727
*lnwire.NodeAnnouncement1,
@@ -1986,6 +1987,12 @@ func messageSummary(msg lnwire.Message) string {
19861987
msg.ShortChannelID.ToUint64(), msg.MessageFlags,
19871988
msg.ChannelFlags, time.Unix(int64(msg.Timestamp), 0))
19881989

1990+
case *lnwire.ChannelUpdate2:
1991+
return fmt.Sprintf("chain_hash=%v, short_chan_id=%v, "+
1992+
"is_disabled=%v, is_node_1=%v, block_height=%v",
1993+
msg.ChainHash, msg.ShortChannelID.ToUint64(),
1994+
msg.IsDisabled(), msg.IsNode1(), msg.BlockHeight)
1995+
19891996
case *lnwire.NodeAnnouncement1:
19901997
return fmt.Sprintf("node=%x, update_time=%v",
19911998
msg.NodeID, time.Unix(int64(msg.Timestamp), 0))

routing/validation_barrier.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (v *ValidationBarrier) InitJobDependencies(job interface{}) {
147147
// initialization needs to be done beyond just occupying a job slot.
148148
case models.ChannelEdgePolicy:
149149
return
150-
case *lnwire.ChannelUpdate1:
150+
case lnwire.ChannelUpdate:
151151
return
152152
case *lnwire.NodeAnnouncement1:
153153
// TODO(roasbeef): node ann needs to wait on existing channel updates
@@ -202,11 +202,11 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
202202
jobDesc = fmt.Sprintf("job=channeldb.LightningNode, pub=%s",
203203
vertex)
204204

205-
case *lnwire.ChannelUpdate1:
206-
signals, ok = v.chanEdgeDependencies[msg.ShortChannelID]
205+
case lnwire.ChannelUpdate:
206+
signals, ok = v.chanEdgeDependencies[msg.SCID()]
207207

208-
jobDesc = fmt.Sprintf("job=lnwire.ChannelUpdate1, scid=%v",
209-
msg.ShortChannelID.ToUint64())
208+
jobDesc = fmt.Sprintf("job=lnwire.ChannelUpdate, scid=%v",
209+
msg.SCID().ToUint64())
210210

211211
case *lnwire.NodeAnnouncement1:
212212
vertex := route.Vertex(msg.NodeID)
@@ -297,8 +297,8 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
297297
delete(v.nodeAnnDependencies, route.Vertex(msg.PubKeyBytes))
298298
case *lnwire.NodeAnnouncement1:
299299
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
300-
case *lnwire.ChannelUpdate1:
301-
delete(v.chanEdgeDependencies, msg.ShortChannelID)
300+
case lnwire.ChannelUpdate:
301+
delete(v.chanEdgeDependencies, msg.SCID())
302302
case models.ChannelEdgePolicy:
303303
delete(v.chanEdgeDependencies, msg.SCID())
304304

0 commit comments

Comments
 (0)