Browse Source

blockchain/v2: remove peers from the processor (#5607)

after they were pruned by the scheduler

Closes #5513
pull/5621/head
Anton Kaliaev 4 years ago
parent
commit
54a0940e40
3 changed files with 6 additions and 3 deletions
  1. +4
    -0
      blockchain/v2/reactor.go
  2. +1
    -1
      blockchain/v2/scheduler.go
  3. +1
    -2
      blockchain/v2/scheduler_test.go

+ 4
- 0
blockchain/v2/reactor.go View File

@ -389,6 +389,10 @@ func (r *BlockchainReactor) demux(events <-chan Event) {
case scSchedulerFail:
r.logger.Error("Scheduler failure", "err", event.reason.Error())
case scPeersPruned:
// Remove peers from the processor.
for _, peerID := range event.peers {
r.processor.send(scPeerError{peerID: peerID, reason: errors.New("peer was pruned")})
}
r.logger.Debug("Pruned peers", "count", len(event.peers))
case noOpEvent:
default:


+ 1
- 1
blockchain/v2/scheduler.go View File

@ -302,7 +302,7 @@ func (sc *scheduler) setPeerRange(peerID p2p.ID, base int64, height int64) error
peer := sc.ensurePeer(peerID)
if peer.state == peerStateRemoved {
return fmt.Errorf("cannot set peer height for a peer in peerStateRemoved")
return nil // noop
}
if height < peer.height {


+ 1
- 2
blockchain/v2/scheduler_test.go View File

@ -531,7 +531,6 @@ func TestScSetPeerRange(t *testing.T) {
peers: map[string]*scPeer{"P1": {height: 2, state: peerStateRemoved}}},
args: args{peerID: "P1", height: 4},
wantFields: scTestParams{peers: map[string]*scPeer{"P1": {height: 2, state: peerStateRemoved}}},
wantErr: true,
},
{
name: "decrease height of single peer",
@ -1995,7 +1994,7 @@ func TestScHandleStatusResponse(t *testing.T) {
name: "increase height of removed peer",
fields: scTestParams{peers: map[string]*scPeer{"P1": {height: 2, state: peerStateRemoved}}},
args: args{event: statusRespP1Ev},
wantEvent: scPeerError{peerID: "P1", reason: fmt.Errorf("some error")},
wantEvent: noOpEvent{},
},
{


Loading…
Cancel
Save