Revert "Merge pull request #4895 from wpaulino/disallow-premature-chan-updates"
This reverts commit6e6384114c, reversing changes made to98ea433271.
This commit is contained in:
1 parent
5cec468ff4
commit
555de44d9f
2 files changed
+333
-33
No files matched your search
+237
-18
@@ -908,10 +908,8 @@ func TestPrematureAnnouncement(t *testing.T) {
|
||||
}
|
||||
|
||||
select {
|
||||
case err = <-ctx.gossiper.ProcessRemoteAnnouncement(ca, nodePeer):
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case <-ctx.gossiper.ProcessRemoteAnnouncement(ca, nodePeer):
|
||||
t.Fatal("announcement was proceeded")
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
|
||||
@@ -928,10 +926,8 @@ func TestPrematureAnnouncement(t *testing.T) {
|
||||
}
|
||||
|
||||
select {
|
||||
case err = <-ctx.gossiper.ProcessRemoteAnnouncement(ua, nodePeer):
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case <-ctx.gossiper.ProcessRemoteAnnouncement(ua, nodePeer):
|
||||
t.Fatal("announcement was proceeded")
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
|
||||
@@ -2377,13 +2373,27 @@ func TestProcessZombieEdgeNowLive(t *testing.T) {
|
||||
|
||||
// The channel update cannot be successfully processed and broadcast
|
||||
// until the channel announcement is. Since the channel update indicates
|
||||
// a fresh new update, the gossiper should mark the channel as live and
|
||||
// allow it once it sees it again.
|
||||
errChan := ctx.gossiper.ProcessRemoteAnnouncement(
|
||||
// a fresh new update, the gossiper should stash it until it sees the
|
||||
// corresponding channel announcement.
|
||||
updateErrChan := ctx.gossiper.ProcessRemoteAnnouncement(
|
||||
batch.chanUpdAnn2, remotePeer,
|
||||
)
|
||||
|
||||
select {
|
||||
case err := <-errChan:
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("expected to not broadcast live channel update " +
|
||||
"without announcement")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
// We'll go ahead and process the channel announcement to ensure the
|
||||
// channel update is processed thereafter.
|
||||
processAnnouncement(batch.remoteChanAnn, false, false)
|
||||
|
||||
// After successfully processing the announcement, the channel update
|
||||
// should have been processed and broadcast successfully as well.
|
||||
select {
|
||||
case err := <-updateErrChan:
|
||||
if err != nil {
|
||||
t.Fatalf("expected to process live channel update: %v",
|
||||
err)
|
||||
@@ -2392,17 +2402,226 @@ func TestProcessZombieEdgeNowLive(t *testing.T) {
|
||||
t.Fatal("expected to process announcement")
|
||||
}
|
||||
|
||||
select {
|
||||
case msgWithSenders := <-ctx.broadcastedMessage:
|
||||
assertMessage(t, batch.chanUpdAnn2, msgWithSenders.msg)
|
||||
case <-time.After(2 * trickleDelay):
|
||||
t.Fatal("expected to broadcast live channel update")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReceiveRemoteChannelUpdateFirst tests that if we receive a ChannelUpdate
|
||||
// from the remote before we have processed our own ChannelAnnouncement, it will
|
||||
// be reprocessed later, after our ChannelAnnouncement.
|
||||
func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cleanup, err := createTestCtx(uint32(proofMatureDelta))
|
||||
if err != nil {
|
||||
t.Fatalf("can't create context: %v", err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
batch, err := createAnnouncements(0)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
// Set up a channel that we can use to inspect the messages sent
|
||||
// directly from the gossiper.
|
||||
sentMsgs := make(chan lnwire.Message, 10)
|
||||
remotePeer := &mockPeer{remoteKey, sentMsgs, ctx.gossiper.quit}
|
||||
|
||||
// Override NotifyWhenOnline to return the remote peer which we expect
|
||||
// meesages to be sent to.
|
||||
ctx.gossiper.reliableSender.cfg.NotifyWhenOnline = func(peer [33]byte,
|
||||
peerChan chan<- lnpeer.Peer) {
|
||||
|
||||
peerChan <- remotePeer
|
||||
}
|
||||
|
||||
// Recreate the case where the remote node is sending us its ChannelUpdate
|
||||
// before we have been able to process our own ChannelAnnouncement and
|
||||
// ChannelUpdate.
|
||||
errRemoteAnn := ctx.gossiper.ProcessRemoteAnnouncement(
|
||||
batch.chanUpdAnn2, remotePeer,
|
||||
)
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("expected to not broadcast live channel update " +
|
||||
"without announcement")
|
||||
t.Fatal("channel update announcement was broadcast")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
// Re-process the channel announcement and update. Both should be
|
||||
// applied to the graph and broadcast.
|
||||
processAnnouncement(batch.remoteChanAnn, false, false)
|
||||
processAnnouncement(batch.chanUpdAnn2, false, false)
|
||||
err = <-ctx.gossiper.ProcessRemoteAnnouncement(batch.nodeAnn2, remotePeer)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process node ann: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("node announcement was broadcast")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
// Since the remote ChannelUpdate was added for an edge that
|
||||
// we did not already know about, it should have been added
|
||||
// to the map of premature ChannelUpdates. Check that nothing
|
||||
// was added to the graph.
|
||||
chanInfo, e1, e2, err := ctx.router.GetChannelByID(batch.chanUpdAnn1.ShortChannelID)
|
||||
if err != channeldb.ErrEdgeNotFound {
|
||||
t.Fatalf("Expected ErrEdgeNotFound, got: %v", err)
|
||||
}
|
||||
if chanInfo != nil {
|
||||
t.Fatalf("chanInfo was not nil")
|
||||
}
|
||||
if e1 != nil {
|
||||
t.Fatalf("e1 was not nil")
|
||||
}
|
||||
if e2 != nil {
|
||||
t.Fatalf("e2 was not nil")
|
||||
}
|
||||
|
||||
// Recreate lightning network topology. Initialize router with channel
|
||||
// between two nodes.
|
||||
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.localChanAnn, localKey)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process :%v", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("channel announcement was broadcast")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.chanUpdAnn1, localKey)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process :%v", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("channel update announcement was broadcast")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
err = <-ctx.gossiper.ProcessLocalAnnouncement(batch.nodeAnn1, localKey)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process :%v", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("node announcement was broadcast")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
// The local ChannelUpdate should now be sent directly to the remote peer,
|
||||
// such that the edge can be used for routing, regardless if this channel
|
||||
// is announced or not (private channel).
|
||||
select {
|
||||
case msg := <-sentMsgs:
|
||||
assertMessage(t, batch.chanUpdAnn1, msg)
|
||||
case <-time.After(1 * time.Second):
|
||||
t.Fatal("gossiper did not send channel update to peer")
|
||||
}
|
||||
|
||||
// At this point the remote ChannelUpdate we received earlier should
|
||||
// be reprocessed, as we now have the necessary edge entry in the graph.
|
||||
select {
|
||||
case err := <-errRemoteAnn:
|
||||
if err != nil {
|
||||
t.Fatalf("error re-processing remote update: %v", err)
|
||||
}
|
||||
case <-time.After(2 * trickleDelay):
|
||||
t.Fatalf("remote update was not processed")
|
||||
}
|
||||
|
||||
// Check that the ChannelEdgePolicy was added to the graph.
|
||||
chanInfo, e1, e2, err = ctx.router.GetChannelByID(
|
||||
batch.chanUpdAnn1.ShortChannelID,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get channel from router: %v", err)
|
||||
}
|
||||
if chanInfo == nil {
|
||||
t.Fatalf("chanInfo was nil")
|
||||
}
|
||||
if e1 == nil {
|
||||
t.Fatalf("e1 was nil")
|
||||
}
|
||||
if e2 == nil {
|
||||
t.Fatalf("e2 was nil")
|
||||
}
|
||||
|
||||
// Pretending that we receive local channel announcement from funding
|
||||
// manager, thereby kick off the announcement exchange process.
|
||||
err = <-ctx.gossiper.ProcessLocalAnnouncement(
|
||||
batch.localProofAnn, localKey,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process :%v", err)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
t.Fatal("announcements were broadcast")
|
||||
case <-time.After(2 * trickleDelay):
|
||||
}
|
||||
|
||||
number := 0
|
||||
if err := ctx.gossiper.cfg.WaitingProofStore.ForAll(
|
||||
func(*channeldb.WaitingProof) error {
|
||||
number++
|
||||
return nil
|
||||
},
|
||||
func() {
|
||||
number = 0
|
||||
},
|
||||
); err != nil {
|
||||
t.Fatalf("unable to retrieve objects from store: %v", err)
|
||||
}
|
||||
|
||||
if number != 1 {
|
||||
t.Fatal("wrong number of objects in storage")
|
||||
}
|
||||
|
||||
err = <-ctx.gossiper.ProcessRemoteAnnouncement(
|
||||
batch.remoteProofAnn, remotePeer,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process :%v", err)
|
||||
}
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
select {
|
||||
case <-ctx.broadcastedMessage:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("announcement wasn't broadcast")
|
||||
}
|
||||
}
|
||||
|
||||
number = 0
|
||||
if err := ctx.gossiper.cfg.WaitingProofStore.ForAll(
|
||||
func(*channeldb.WaitingProof) error {
|
||||
number++
|
||||
return nil
|
||||
},
|
||||
func() {
|
||||
number = 0
|
||||
},
|
||||
); err != nil && err != channeldb.ErrWaitingProofNotFound {
|
||||
t.Fatalf("unable to retrieve objects from store: %v", err)
|
||||
}
|
||||
|
||||
if number != 0 {
|
||||
t.Fatal("waiting proof should be removed from storage")
|
||||
}
|
||||
}
|
||||
|
||||
// TestExtraDataChannelAnnouncementValidation tests that we're able to properly
|
||||
|
||||
Reference in new issue
Block a user