Browse Source

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

after they were pruned by the scheduler

Closes #5513
pull/5625/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
335e97433c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
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",
@ -1998,7 +1997,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