forked from TrueCloudLab/neoneo-go
network: prevent disconnects during initial sync
Node receiving extensible payload from the future is confused and drops connection. Note that this can still happen if the node is to loose its synchrony. Calling `IsInSync()` is quite expensive, so we stop doing that once synchrony is reached (hence bool flag).
This commit is contained in:
parent
1ee21666b5
commit
686f983ccf
1 changed files with 8 additions and 0 deletions
|
@ -86,6 +86,7 @@ type (
|
|||
transactions chan *transaction.Transaction
|
||||
|
||||
consensusStarted *atomic.Bool
|
||||
canHandleExtens *atomic.Bool
|
||||
|
||||
oracle *oracle.Oracle
|
||||
|
||||
|
@ -131,6 +132,7 @@ func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchai
|
|||
unregister: make(chan peerDrop),
|
||||
peers: make(map[Peer]bool),
|
||||
consensusStarted: atomic.NewBool(false),
|
||||
canHandleExtens: atomic.NewBool(false),
|
||||
extensiblePool: extpool.New(chain),
|
||||
log: log,
|
||||
transactions: make(chan *transaction.Transaction, 64),
|
||||
|
@ -786,6 +788,12 @@ func (s *Server) handleGetHeadersCmd(p Peer, gh *payload.GetBlockByIndex) error
|
|||
|
||||
// handleExtensibleCmd processes received extensible payload.
|
||||
func (s *Server) handleExtensibleCmd(e *payload.Extensible) error {
|
||||
if !s.canHandleExtens.Load() {
|
||||
if !s.IsInSync() {
|
||||
return nil
|
||||
}
|
||||
s.canHandleExtens.Store(true)
|
||||
}
|
||||
ok, err := s.extensiblePool.Add(e)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue