diff --git a/docs/specification/new-spec/reactors/pex/pex.md b/docs/specification/new-spec/reactors/pex/pex.md index 1c0ba1c3d..c879c336a 100644 --- a/docs/specification/new-spec/reactors/pex/pex.md +++ b/docs/specification/new-spec/reactors/pex/pex.md @@ -35,22 +35,22 @@ Peers listen on a configurable ListenAddr that they self-report in their NodeInfo during handshakes with other peers. Peers accept up to (MaxNumPeers - MinNumOutboundPeers) incoming peers. - ## Address Book Peers are tracked via their ID (their PubKey.Address()). -For each ID, the address book keeps the most recent IP:PORT. Peers are added to the address book from the PEX when they first connect to us or when we hear about them from other peers. The address book is arranged in sets of buckets, and distinguishes between vetted (old) and unvetted (new) peers. It keeps different sets of buckets for vetted and -unvetted peers. Buckets provide randomization over peer selection. +unvetted peers. Buckets provide randomization over peer selection. Peers are put +in buckets according to their IP groups. -A vetted peer can only be in one bucket. An unvetted peer can be in multiple buckets. +A vetted peer can only be in one bucket. An unvetted peer can be in multiple buckets, and +each instance of the peer can have a different IP:PORT. -If there's no space in the book, we check the bucket for bad peers, which include peers we've attempted to -dial 3 times, and then remove them from only that bucket. +If we're trying to add a new peer but there's no space in its bucket, we'll +remove the worst peer from that bucket to make room. ## Vetting diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index e34bd5ab9..6521b6491 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -496,7 +496,7 @@ func (a *addrBook) getBucket(bucketType byte, bucketIdx int) map[string]*knownAd func (a *addrBook) addToNewBucket(ka *knownAddress, bucketIdx int) { // Sanity check if ka.isOld() { - a.Logger.Error("Failed Sanity Check! Cant add old address to new bucket", "ka", knownAddress, "bucket", bucketIdx) + a.Logger.Error("Failed Sanity Check! Cant add old address to new bucket", "ka", ka, "bucket", bucketIdx) return } @@ -679,8 +679,6 @@ func (a *addrBook) moveToOld(ka *knownAddress) { return } - // Remember one of the buckets in which ka is in. - freedBucket := ka.Buckets[0] // Remove from all (new) buckets. a.removeFromAllBuckets(ka) // It's officially old now.