From 925b2948f03ac6b5082165f1cf8c07bc9704894c Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 28 Sep 2020 09:20:54 +0200 Subject: [PATCH] blockchain/v1: add noBlockResponse handling (#5401) Add simple `NoBlockResponse` handling to blockchain reactor v1. I tested before and after with erik's e2e testing and was not able to reproduce the inability to sync after the changes were applied Closes: #5394 --- blockchain/v1/reactor.go | 11 +++++++++++ blockchain/v1/reactor_fsm.go | 9 +++++++++ blockchain/v1/reactor_fsm_test.go | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/blockchain/v1/reactor.go b/blockchain/v1/reactor.go index 480b87f34..b35932330 100644 --- a/blockchain/v1/reactor.go +++ b/blockchain/v1/reactor.go @@ -256,6 +256,17 @@ func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) bcR.Logger.Info("Received", "src", src, "height", msg.Block.Height) bcR.messagesForFSMCh <- msgForFSM + case *bcNoBlockResponseMessage: + msgForFSM := bcReactorMessage{ + event: noBlockResponseEv, + data: bReactorEventData{ + peerID: src.ID(), + height: msg.Height, + }, + } + bcR.Logger.Debug("Peer does not have requested block", "peer", src, "height", msg.Height) + bcR.messagesForFSMCh <- msgForFSM + case *bcStatusResponseMessage: // Got a peer status. Unverified. msgForFSM := bcReactorMessage{ diff --git a/blockchain/v1/reactor_fsm.go b/blockchain/v1/reactor_fsm.go index 8d3a363ae..83305539c 100644 --- a/blockchain/v1/reactor_fsm.go +++ b/blockchain/v1/reactor_fsm.go @@ -73,6 +73,7 @@ const ( startFSMEv = iota + 1 statusResponseEv blockResponseEv + noBlockResponseEv processedBlockEv makeRequestsEv stopFSMEv @@ -93,6 +94,9 @@ func (msg *bcReactorMessage) String() string { case blockResponseEv: dataStr = fmt.Sprintf("peer=%v block.height=%v length=%v", msg.data.peerID, msg.data.block.Height, msg.data.length) + case noBlockResponseEv: + dataStr = fmt.Sprintf("peer=%v requested height=%v", + msg.data.peerID, msg.data.height) case processedBlockEv: dataStr = fmt.Sprintf("error=%v", msg.data.err) case makeRequestsEv: @@ -118,6 +122,8 @@ func (ev bReactorEvent) String() string { return "statusResponseEv" case blockResponseEv: return "blockResponseEv" + case noBlockResponseEv: + return "noBlockResponseEv" case processedBlockEv: return "processedBlockEv" case makeRequestsEv: @@ -268,7 +274,10 @@ func init() { return waitForPeer, err } return waitForBlock, err + case noBlockResponseEv: + fsm.logger.Error("peer does not have requested block", "peer", data.peerID) + return waitForBlock, nil case processedBlockEv: if data.err != nil { first, second, _ := fsm.pool.FirstTwoBlocksAndPeers() diff --git a/blockchain/v1/reactor_fsm_test.go b/blockchain/v1/reactor_fsm_test.go index 7dff5bbaf..6f2a4dc88 100644 --- a/blockchain/v1/reactor_fsm_test.go +++ b/blockchain/v1/reactor_fsm_test.go @@ -820,7 +820,7 @@ const ( maxRequestsPerPeerTest = 20 maxTotalPendingRequestsTest = 600 maxNumPeersTest = 1000 - maxNumBlocksInChainTest = 10000 //should be smaller than 9999999 + maxNumBlocksInChainTest = 10000 // should be smaller than 9999999 ) func makeCorrectTransitionSequenceWithRandomParameters() testFields {