Skip to content

Commit

Permalink
Add Has to Peertracker, filter pubsub blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Sep 6, 2019
1 parent 67fd2f3 commit 62110fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions net/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func (tracker *PeerTracker) Track(ci *types.ChainInfo) {
logPeerTracker.Infof("Tracking %s, new=%t, count=%d", ci, !tracking, len(tracker.peers))
}

// Has returns true if this peerID is tracked
func (tracker *PeerTracker) Has(pid peer.ID) bool {
tracker.mu.Lock()
defer tracker.mu.Unlock()

pidKey := pid.Pretty()
_, ok := tracker.peers[pidKey]
return ok
}

// List returns the chain info of the currently tracked peers. The info
// tracked by the tracker can change arbitrarily after this is called -- there
// is no guarantee that the peers returned will be tracked when they are used
Expand Down
7 changes: 7 additions & 0 deletions node/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func (node *Node) processBlock(ctx context.Context, pubSubMsg pubsub.Message) (e
if err != nil {
return errors.Wrap(err, "got bad block data")
}

// ignore messages from peers not yet tracked
if !node.PeerTracker.Has(from) {
log.Debugf("ignoring new block cid: %s from unconnected peer: %s", blk.Cid().String(), from.Pretty())
return nil
}

span.AddAttributes(trace.StringAttribute("block", blk.Cid().String()))

log.Infof("Received new block from network cid: %s", blk.Cid().String())
Expand Down

0 comments on commit 62110fc

Please sign in to comment.