discovery/gossiper: remove source pubkey from ProcessLocalAnnouncement params

This commit is contained in:
Johan T. Halseth 2021-01-06 10:48:07 +01:00
parent 69770f15e4
commit f047c3517f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 43 additions and 110 deletions

@ -574,7 +574,7 @@ func (d *AuthenticatedGossiper) ProcessRemoteAnnouncement(msg lnwire.Message,
// entire channel announcement and update messages will be re-constructed and
// broadcast to the rest of the network.
func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
source *btcec.PublicKey, optionalFields ...OptionalMsgField) chan error {
optionalFields ...OptionalMsgField) chan error {
optionalMsgFields := &optionalMsgFields{}
optionalMsgFields.apply(optionalFields...)
@ -583,7 +583,7 @@ func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
msg: msg,
optionalMsgFields: optionalMsgFields,
isRemote: false,
source: source,
source: d.selfKey,
err: make(chan error, 1),
}

@ -975,10 +975,6 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
t.Fatalf("can't generate announcements: %v", err)
}
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -988,9 +984,7 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
// Recreate lightning network topology. Initialize router with channel
// between two nodes.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localChanAnn, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1004,9 +998,7 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
}
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.chanUpdAnn1, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1020,9 +1012,7 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
}
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.nodeAnn1, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.nodeAnn1):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1080,9 +1070,7 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
// Pretending that we receive local channel announcement from funding
// manager, thereby kick off the announcement exchange process.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localProofAnn, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn):
case <-time.After(2 * time.Second):
t.Fatal("did not process remote announcement")
}
@ -1180,10 +1168,6 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
t.Fatalf("can't generate announcements: %v", err)
}
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -1224,8 +1208,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
// Recreate lightning network topology. Initialize router with channel
// between two nodes.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn,
localKey):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1241,8 +1224,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
}
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1,
localKey):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1257,9 +1239,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
}
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.nodeAnn1, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.nodeAnn1):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1316,8 +1296,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
// After that we process local announcement, and waiting to receive
// the channel announcement.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn,
localKey):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn):
case <-time.After(2 * time.Second):
t.Fatal("did not process remote announcement")
}
@ -1379,10 +1358,6 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
t.Fatalf("can't generate announcements: %v", err)
}
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -1405,9 +1380,7 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
// Recreate lightning network topology. Initialize router with channel
// between two nodes.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localChanAnn, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
}
@ -1424,7 +1397,7 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
// manager, thereby kick off the announcement exchange process.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localProofAnn, localKey,
batch.localProofAnn,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process remote announcement")
@ -1599,10 +1572,6 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
t.Fatalf("can't generate announcements: %v", err)
}
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -1625,7 +1594,7 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
// between two nodes.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localChanAnn, localKey,
batch.localChanAnn,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
@ -1641,7 +1610,7 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.chanUpdAnn1, localKey,
batch.chanUpdAnn1,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
@ -1664,7 +1633,7 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.nodeAnn1, localKey,
batch.nodeAnn1,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
@ -1714,7 +1683,7 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
// manager, thereby kick off the announcement exchange process.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localProofAnn, localKey,
batch.localProofAnn,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
@ -2080,7 +2049,7 @@ func TestForwardPrivateNodeAnnouncement(t *testing.T) {
pubKey := nodeKeyPriv1.PubKey()
select {
case err := <-ctx.gossiper.ProcessLocalAnnouncement(chanAnn, pubKey):
case err := <-ctx.gossiper.ProcessLocalAnnouncement(chanAnn):
if err != nil {
t.Fatalf("unable to process local announcement: %v", err)
}
@ -2102,7 +2071,7 @@ func TestForwardPrivateNodeAnnouncement(t *testing.T) {
}
select {
case err := <-ctx.gossiper.ProcessLocalAnnouncement(nodeAnn, pubKey):
case err := <-ctx.gossiper.ProcessLocalAnnouncement(nodeAnn):
if err != nil {
t.Fatalf("unable to process remote announcement: %v", err)
}
@ -2436,10 +2405,6 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
t.Fatalf("can't generate announcements: %v", err)
}
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -2500,7 +2465,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
// Recreate lightning network topology. Initialize router with channel
// between two nodes.
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn, localKey)
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn)
if err != nil {
t.Fatalf("unable to process :%v", err)
}
@ -2510,7 +2475,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
case <-time.After(2 * trickleDelay):
}
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1, localKey)
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1)
if err != nil {
t.Fatalf("unable to process :%v", err)
}
@ -2520,7 +2485,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
case <-time.After(2 * trickleDelay):
}
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.nodeAnn1, localKey)
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.nodeAnn1)
if err != nil {
t.Fatalf("unable to process :%v", err)
}
@ -2570,9 +2535,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
// Pretending that we receive local channel announcement from funding
// manager, thereby kick off the announcement exchange process.
err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localProofAnn, localKey,
)
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn)
if err != nil {
t.Fatalf("unable to process :%v", err)
}
@ -2827,10 +2790,6 @@ func TestRetransmit(t *testing.T) {
t.Fatalf("can't generate announcements: %v", err)
}
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -2841,23 +2800,17 @@ func TestRetransmit(t *testing.T) {
// announcement. No messages should be broadcasted yet, since no proof
// has been exchanged.
assertProcessAnnouncement(
t, ctx.gossiper.ProcessLocalAnnouncement(
batch.localChanAnn, localKey,
),
t, ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn),
)
assertBroadcast(t, ctx, 0)
assertProcessAnnouncement(
t, ctx.gossiper.ProcessLocalAnnouncement(
batch.chanUpdAnn1, localKey,
),
t, ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1),
)
assertBroadcast(t, ctx, 0)
assertProcessAnnouncement(
t, ctx.gossiper.ProcessLocalAnnouncement(
batch.nodeAnn1, localKey,
),
t, ctx.gossiper.ProcessLocalAnnouncement(batch.nodeAnn1),
)
assertBroadcast(t, ctx, 0)
@ -2873,9 +2826,7 @@ func TestRetransmit(t *testing.T) {
// Now add the local and remote proof to the gossiper, which should
// trigger a broadcast of the announcements.
assertProcessAnnouncement(
t, ctx.gossiper.ProcessLocalAnnouncement(
batch.localProofAnn, localKey,
),
t, ctx.gossiper.ProcessLocalAnnouncement(batch.localProofAnn),
)
assertBroadcast(t, ctx, 0)
@ -3145,10 +3096,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
// We'll also create two keys, one for ourselves and another for the
// remote party.
localKey, err := btcec.ParsePubKey(batch.nodeAnn1.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
}
remoteKey, err := btcec.ParsePubKey(batch.nodeAnn2.NodeID[:], btcec.S256())
if err != nil {
t.Fatalf("unable to parse pubkey: %v", err)
@ -3195,9 +3143,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
// Process the channel announcement for which we'll send a channel
// update for.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localChanAnn, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn):
case <-time.After(2 * time.Second):
t.Fatal("did not process local channel announcement")
}
@ -3214,9 +3160,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
// Now, we'll process the channel update.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.chanUpdAnn1, localKey,
):
case err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1):
case <-time.After(2 * time.Second):
t.Fatal("did not process local channel update")
}
@ -3277,7 +3221,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
// With the new update created, we'll go ahead and process it.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.chanUpdAnn1, localKey,
batch.chanUpdAnn1,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local channel update")
@ -3318,7 +3262,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
// the channel.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
batch.localProofAnn, localKey,
batch.localProofAnn,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local channel proof")
@ -3375,7 +3319,7 @@ func TestSendChannelUpdateReliably(t *testing.T) {
// not announced.
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
newChannelUpdate, localKey,
newChannelUpdate,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local channel update")
@ -3448,14 +3392,14 @@ func TestSendChannelUpdateReliably(t *testing.T) {
}
func sendLocalMsg(t *testing.T, ctx *testCtx, msg lnwire.Message,
localPub *btcec.PublicKey, optionalMsgFields ...OptionalMsgField) {
optionalMsgFields ...OptionalMsgField) {
t.Helper()
var err error
select {
case err = <-ctx.gossiper.ProcessLocalAnnouncement(
msg, localPub, optionalMsgFields...,
msg, optionalMsgFields...,
):
case <-time.After(2 * time.Second):
t.Fatal("did not process local announcement")
@ -3529,7 +3473,6 @@ func TestPropagateChanPolicyUpdate(t *testing.T) {
channelsToAnnounce = append(channelsToAnnounce, newChan)
}
localKey := nodeKeyPriv1.PubKey()
remoteKey := nodeKeyPriv2.PubKey()
sentMsgs := make(chan lnwire.Message, 10)
@ -3565,9 +3508,9 @@ func TestPropagateChanPolicyUpdate(t *testing.T) {
// each channel has a unique channel point.
channelPoint := ChannelPoint(wire.OutPoint{Index: uint32(i)})
sendLocalMsg(t, ctx, batch.localChanAnn, localKey, channelPoint)
sendLocalMsg(t, ctx, batch.chanUpdAnn1, localKey)
sendLocalMsg(t, ctx, batch.nodeAnn1, localKey)
sendLocalMsg(t, ctx, batch.localChanAnn, channelPoint)
sendLocalMsg(t, ctx, batch.chanUpdAnn1)
sendLocalMsg(t, ctx, batch.nodeAnn1)
sendRemoteMsg(t, ctx, batch.chanUpdAnn2, remotePeer)
sendRemoteMsg(t, ctx, batch.nodeAnn2, remotePeer)
@ -3578,7 +3521,7 @@ func TestPropagateChanPolicyUpdate(t *testing.T) {
continue
}
sendLocalMsg(t, ctx, batch.localProofAnn, localKey)
sendLocalMsg(t, ctx, batch.localProofAnn)
sendRemoteMsg(t, ctx, batch.remoteProofAnn, remotePeer)
}
@ -3702,7 +3645,6 @@ func TestProcessChannelAnnouncementOptionalMsgFields(t *testing.T) {
chanAnn1 := createAnnouncementWithoutProof(100)
chanAnn2 := createAnnouncementWithoutProof(101)
localKey := nodeKeyPriv1.PubKey()
// assertOptionalMsgFields is a helper closure that ensures the optional
// message fields were set as intended.
@ -3727,7 +3669,7 @@ func TestProcessChannelAnnouncementOptionalMsgFields(t *testing.T) {
// We'll process the first announcement without any optional fields. We
// should see the channel's capacity and outpoint have a zero value.
sendLocalMsg(t, ctx, chanAnn1, localKey)
sendLocalMsg(t, ctx, chanAnn1)
assertOptionalMsgFields(chanAnn1.ShortChannelID, 0, wire.OutPoint{})
// Providing the capacity and channel point as optional fields should
@ -3735,7 +3677,7 @@ func TestProcessChannelAnnouncementOptionalMsgFields(t *testing.T) {
capacity := btcutil.Amount(1000)
channelPoint := wire.OutPoint{Index: 1}
sendLocalMsg(
t, ctx, chanAnn2, localKey, ChannelCapacity(capacity),
t, ctx, chanAnn2, ChannelCapacity(capacity),
ChannelPoint(channelPoint),
)
assertOptionalMsgFields(chanAnn2.ShortChannelID, capacity, channelPoint)
@ -3880,9 +3822,7 @@ func TestBroadcastAnnsAfterGraphSynced(t *testing.T) {
msg, nodePeer,
)
} else {
errChan = ctx.gossiper.ProcessLocalAnnouncement(
msg, nodePeer.pk,
)
errChan = ctx.gossiper.ProcessLocalAnnouncement(msg)
}
select {

@ -1026,13 +1026,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) {
return s.genNodeAnnouncement(true)
},
SendAnnouncement: func(msg lnwire.Message,
optionalFields ...discovery.OptionalMsgField) chan error {
return s.authGossiper.ProcessLocalAnnouncement(
msg, nodeKeyECDH.PubKey(), optionalFields...,
)
},
SendAnnouncement: s.authGossiper.ProcessLocalAnnouncement,
NotifyWhenOnline: s.NotifyWhenOnline,
TempChanIDSeed: chanIDSeed,
FindChannel: func(chanID lnwire.ChannelID) (
@ -3792,8 +3786,7 @@ func (s *server) fetchLastChanUpdate() func(lnwire.ShortChannelID) (
// applyChannelUpdate applies the channel update to the different sub-systems of
// the server.
func (s *server) applyChannelUpdate(update *lnwire.ChannelUpdate) error {
pubKey := s.identityECDH.PubKey()
errChan := s.authGossiper.ProcessLocalAnnouncement(update, pubKey)
errChan := s.authGossiper.ProcessLocalAnnouncement(update)
select {
case err := <-errChan:
return err