discovery/gossiper_test: modify TestProcessAnnouncement to process node

ann last

In this commit, we modify TestProcessAnnouncement to process the node
announcement last. We do this due to the recent change in the gossiper
where we'll only forward node announcements of nodes who intend to
advertised themselves within the network.

This change was needed in order to allow the node announcement to be
broadcast to the greater network, as otherwise the gossiper would assume
the node intends to stay private due to not having any advertised edges.
This commit is contained in:
Wilmer Paulino 2018-10-17 15:55:46 -07:00
parent 80196eb20f
commit 748da2f50a
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -616,40 +616,10 @@ func TestProcessAnnouncement(t *testing.T) {
} }
} }
// Create node valid, signed announcement, process it with
// gossiper service, check that valid announcement have been
// propagated farther into the lightning network, and check that we
// added new node into router.
na, err := createNodeAnnouncement(nodeKeyPriv1, timestamp)
if err != nil {
t.Fatalf("can't create node announcement: %v", err)
}
nodePeer := &mockPeer{nodeKeyPriv1.PubKey(), nil, nil} nodePeer := &mockPeer{nodeKeyPriv1.PubKey(), nil, nil}
select { // First, we'll craft a valid remote channel announcement and send it to
case err = <-ctx.gossiper.ProcessRemoteAnnouncement(na, nodePeer): // the gossiper so that it can be processed.
case <-time.After(2 * time.Second):
t.Fatal("remote announcement not processed")
}
if err != nil {
t.Fatalf("can't process remote announcement: %v", err)
}
select {
case msg := <-ctx.broadcastedMessage:
assertSenderExistence(nodePeer.IdentityKey(), msg)
case <-time.After(2 * trickleDelay):
t.Fatal("announcement wasn't proceeded")
}
if len(ctx.router.nodes) != 1 {
t.Fatalf("node wasn't added to router: %v", err)
}
// Pretending that we receive the valid channel announcement from
// remote side, and check that we broadcasted it to the our network,
// and added channel info in the router.
ca, err := createRemoteChannelAnnouncement(0) ca, err := createRemoteChannelAnnouncement(0)
if err != nil { if err != nil {
t.Fatalf("can't create channel announcement: %v", err) t.Fatalf("can't create channel announcement: %v", err)
@ -664,6 +634,8 @@ func TestProcessAnnouncement(t *testing.T) {
t.Fatalf("can't process remote announcement: %v", err) t.Fatalf("can't process remote announcement: %v", err)
} }
// The announcement should be broadcast and included in our local view
// of the graph.
select { select {
case msg := <-ctx.broadcastedMessage: case msg := <-ctx.broadcastedMessage:
assertSenderExistence(nodePeer.IdentityKey(), msg) assertSenderExistence(nodePeer.IdentityKey(), msg)
@ -675,9 +647,8 @@ func TestProcessAnnouncement(t *testing.T) {
t.Fatalf("edge wasn't added to router: %v", err) t.Fatalf("edge wasn't added to router: %v", err)
} }
// Pretending that we received valid channel policy update from remote // We'll then craft the channel policy of the remote party and also send
// side, and check that we broadcasted it to the other network, and // it to the gossiper.
// added updates to the router.
ua, err := createUpdateAnnouncement(0, 0, nodeKeyPriv1, timestamp) ua, err := createUpdateAnnouncement(0, 0, nodeKeyPriv1, timestamp)
if err != nil { if err != nil {
t.Fatalf("can't create update announcement: %v", err) t.Fatalf("can't create update announcement: %v", err)
@ -692,6 +663,7 @@ func TestProcessAnnouncement(t *testing.T) {
t.Fatalf("can't process remote announcement: %v", err) t.Fatalf("can't process remote announcement: %v", err)
} }
// The channel policy should be broadcast to the rest of the network.
select { select {
case msg := <-ctx.broadcastedMessage: case msg := <-ctx.broadcastedMessage:
assertSenderExistence(nodePeer.IdentityKey(), msg) assertSenderExistence(nodePeer.IdentityKey(), msg)
@ -702,6 +674,34 @@ func TestProcessAnnouncement(t *testing.T) {
if len(ctx.router.edges) != 1 { if len(ctx.router.edges) != 1 {
t.Fatalf("edge update wasn't added to router: %v", err) t.Fatalf("edge update wasn't added to router: %v", err)
} }
// Finally, we'll craft the remote party's node announcement.
na, err := createNodeAnnouncement(nodeKeyPriv1, timestamp)
if err != nil {
t.Fatalf("can't create node announcement: %v", err)
}
select {
case err = <-ctx.gossiper.ProcessRemoteAnnouncement(na, nodePeer):
case <-time.After(2 * time.Second):
t.Fatal("remote announcement not processed")
}
if err != nil {
t.Fatalf("can't process remote announcement: %v", err)
}
// It should also be broadcast to the network and included in our local
// view of the graph.
select {
case msg := <-ctx.broadcastedMessage:
assertSenderExistence(nodePeer.IdentityKey(), msg)
case <-time.After(2 * trickleDelay):
t.Fatal("announcement wasn't proceeded")
}
if len(ctx.router.nodes) != 1 {
t.Fatalf("node wasn't added to router: %v", err)
}
} }
// TestPrematureAnnouncement checks that premature announcements are // TestPrematureAnnouncement checks that premature announcements are