diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -14,19 +14,22 @@ struct Slot { private: uint64_t start; - uint64_t stop; + uint64_t score; public: - Slot(uint64_t startIn, uint64_t stopIn) : start(startIn), stop(stopIn) {} + Slot(uint64_t startIn, uint64_t stop) + : start(startIn), score(stop - start) {} - Slot withScore(uint64_t score) { return Slot(start, start + score); } + Slot withScore(uint64_t scoreIn) { return Slot(start, start + scoreIn); } uint64_t getStart() const { return start; } - uint64_t getStop() const { return stop; } + uint64_t getStop() const { return start + score; } - bool contains(uint64_t slot) const { return start <= slot && slot < stop; } - bool precedes(uint64_t slot) const { return slot >= stop; } - bool follows(uint64_t slot) const { return start > slot; } + bool contains(uint64_t slot) const { + return getStart() <= slot && slot < getStop(); + } + bool precedes(uint64_t slot) const { return slot >= getStop(); } + bool follows(uint64_t slot) const { return getStart() > slot; } }; class PeerManager { diff --git a/src/avalanche/test/peermanager_tests.cpp b/src/avalanche/test/peermanager_tests.cpp --- a/src/avalanche/test/peermanager_tests.cpp +++ b/src/avalanche/test/peermanager_tests.cpp @@ -83,8 +83,9 @@ BOOST_CHECK_EQUAL(selectPeerImpl(slots, max, max), NO_PEER); // Update the slots to be heavily skewed toward the last element. - slots[99] = Slot(slots[99].getStart(), 300); - max = 300; + slots[99] = slots[99].withScore(101); + max = slots[99].getStop(); + BOOST_CHECK_EQUAL(max, 300); for (int i = 0; i < 100; i++) { BOOST_CHECK_EQUAL(selectPeerImpl(slots, 2 * i, max), NO_PEER);