Skip to content

Commit

Permalink
Merge pull request #158 from Syndica/ink/log-flaky-test-seed
Browse files Browse the repository at this point in the history
improvement(gossip): Take random interface param and log bad seeds for `filterSignedGossipDatas`
  • Loading branch information
InKryption authored Jun 5, 2024
2 parents a5d1f34 + 5f85100 commit 3d6a7b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/gossip/pull_response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const deinitGossipPullFilters = _pull_request.deinitGossipPullFilters;
pub const GOSSIP_PULL_TIMEOUT_MS: u64 = 15000;

pub fn filterSignedGossipDatas(
/// It is advised to use a PRNG, and not a true RNG, otherwise
/// the runtime of this function may be unbounded.
rand: std.Random,
allocator: std.mem.Allocator,
gossip_table: *const GossipTable,
filter: *const GossipPullFilter,
Expand All @@ -30,11 +33,7 @@ pub fn filterSignedGossipDatas(
return ArrayList(SignedGossipData).init(allocator);
}

const seed: u64 = @intCast(std.time.milliTimestamp());
var rand = std.rand.DefaultPrng.init(seed);
const rng = rand.random();

const jitter = rng.intRangeAtMost(u64, 0, GOSSIP_PULL_TIMEOUT_MS / 4);
const jitter = rand.intRangeAtMost(u64, 0, GOSSIP_PULL_TIMEOUT_MS / 4);
const caller_wallclock_with_jitter = caller_wallclock + jitter;

var bloom = filter.filter;
Expand Down Expand Up @@ -130,7 +129,10 @@ test "gossip.pull_response: test filtering values works" {
try lg.mut().insert(v2, 0);
}

const maybe_failing_seed: u64 = @intCast(std.time.milliTimestamp());
var maybe_failing_prng = std.Random.Xoshiro256.init(maybe_failing_seed);
var values = try filterSignedGossipDatas(
maybe_failing_prng.random(),
std.testing.allocator,
lg.get(),
&filter,
Expand All @@ -140,5 +142,8 @@ test "gossip.pull_response: test filtering values works" {
defer values.deinit();
lg.unlock();

try std.testing.expect(values.items.len > 0);
std.testing.expect(values.items.len > 0) catch |err| {
std.log.err("\nThe failing seed is: '{d}'\n", .{maybe_failing_seed});
return err;
};
}
3 changes: 3 additions & 0 deletions src/gossip/service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,10 @@ pub const GossipService = struct {
return;
}

const filter_rng_seed: u64 = @intCast(std.time.milliTimestamp());
var filter_prng = std.Random.Xoshiro256.init(filter_rng_seed);
const response_gossip_values = pull_response.filterSignedGossipDatas(
filter_prng.random(),
self.allocator,
self.gossip_table,
self.filter,
Expand Down

0 comments on commit 3d6a7b3

Please sign in to comment.