improves expired squelch deletion

This commit is contained in:
Vito
2025-07-30 18:16:27 +02:00
parent 762fd3b6a5
commit 3ca6dda72d
9 changed files with 99 additions and 51 deletions

View File

@@ -19,19 +19,33 @@
#include <test/jtx/Env.h>
#include <xrpld/overlay/ReduceRelayCommon.h>
#include <xrpld/overlay/SquelchStore.h>
#include <xrpl/beast/unit_test.h>
#include <xrpl/protocol/PublicKey.h>
#include "xrpld/overlay/ReduceRelayCommon.h"
#include <chrono>
namespace ripple {
namespace test {
class TestSquelchStore : public reduce_relay::SquelchStore
{
public:
TestSquelchStore(beast::Journal journal, TestStopwatch& clock)
: reduce_relay::SquelchStore(journal, clock)
{
}
hash_map<PublicKey, TestStopwatch::time_point> const&
getSquelched() const
{
return squelched_;
}
};
class squelch_store_test : public beast::unit_test::suite
{
using seconds = std::chrono::seconds;
@@ -49,7 +63,7 @@ public:
testcase("SquelchStore handleSquelch");
TestStopwatch clock;
auto store = reduce_relay::SquelchStore(env_.journal, clock);
auto store = TestSquelchStore(env_.journal, clock);
auto const validator = randomKeyPair(KeyType::ed25519).first;
@@ -58,8 +72,7 @@ public:
validator, true, reduce_relay::MIN_UNSQUELCH_EXPIRE - seconds{1});
// the peer must not be squelched
BEAST_EXPECTS(
!store.expireAndIsSquelched(validator), "peer is squelched");
BEAST_EXPECTS(!store.isSquelched(validator), "peer is squelched");
// attempt to squelch the peer with a too big duration
store.handleSquelch(
@@ -68,8 +81,7 @@ public:
reduce_relay::MAX_UNSQUELCH_EXPIRE_PEERS + seconds{1});
// the peer must not be squelched
BEAST_EXPECTS(
!store.expireAndIsSquelched(validator), "peer is squelched");
BEAST_EXPECTS(!store.isSquelched(validator), "peer is squelched");
// squelch the peer with a good duration
store.handleSquelch(
@@ -77,22 +89,21 @@ public:
// the peer for the validator should be squelched
BEAST_EXPECTS(
store.expireAndIsSquelched(validator),
store.isSquelched(validator),
"peer and validator are not squelched");
// unsquelch the validator
store.handleSquelch(validator, false, seconds{0});
BEAST_EXPECTS(
!store.expireAndIsSquelched(validator), "peer is squelched");
BEAST_EXPECTS(!store.isSquelched(validator), "peer is squelched");
}
void
testExpireAndIsSquelched()
testIsSquelched()
{
testcase("SquelchStore expireAndIsSquelched");
testcase("SquelchStore IsSquelched");
TestStopwatch clock;
auto store = reduce_relay::SquelchStore(env_.journal, clock);
auto store = TestSquelchStore(env_.journal, clock);
auto const validator = randomKeyPair(KeyType::ed25519).first;
auto const duration = reduce_relay::MIN_UNSQUELCH_EXPIRE + seconds{1};
@@ -100,21 +111,50 @@ public:
store.handleSquelch(
validator, true, reduce_relay::MIN_UNSQUELCH_EXPIRE + seconds{1});
BEAST_EXPECTS(
store.expireAndIsSquelched(validator),
store.isSquelched(validator),
"peer and validator are not squelched");
clock.advance(duration + seconds{1});
// the peer with short squelch duration must be not squelched
BEAST_EXPECTS(
!store.expireAndIsSquelched(validator),
"peer and validator are squelched");
!store.isSquelched(validator), "peer and validator are squelched");
}
void
testClearExpiredSquelches()
{
testcase("SquelchStore testClearExpiredSquelches");
TestStopwatch clock;
auto store = TestSquelchStore(env_.journal, clock);
auto const validator = randomKeyPair(KeyType::ed25519).first;
auto const duration = reduce_relay::MIN_UNSQUELCH_EXPIRE + seconds{1};
store.handleSquelch(validator, true, duration);
BEAST_EXPECTS(
store.getSquelched().size() == 1,
"validators were not registered in the store");
clock.advance(duration + seconds{1});
auto const validator2 = randomKeyPair(KeyType::ed25519).first;
auto const duration2 = reduce_relay::MIN_UNSQUELCH_EXPIRE + seconds{2};
store.handleSquelch(validator2, true, duration2);
BEAST_EXPECTS(
!store.getSquelched().contains(validator),
"expired squelch was not deleted");
BEAST_EXPECTS(
store.getSquelched().contains(validator2),
"validators were not registered in the store");
}
void
run() override
{
testHandleSquelch();
testExpireAndIsSquelched();
testIsSquelched();
testClearExpiredSquelches();
}
};