Skip to content

Commit 1b17081

Browse files
committed
accountsdb fuzz: use getAccountWithAncestors
1 parent b62ad1e commit 1b17081

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/accountsdb/fuzz.zig

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
197197
var largest_rooted_slot: Slot = 0;
198198
var slot: Slot = 0;
199199

200+
var ancestors: sig.core.Ancestors = .EMPTY;
201+
defer ancestors.deinit(allocator);
202+
200203
// get/put a bunch of accounts
201204
while (true) {
202205
if (maybe_max_slots) |max_slots| if (slot >= max_slots) {
@@ -207,6 +210,7 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
207210
0 => slot += random.intRangeAtMost(Slot, 1, 2),
208211
1, 2, 3 => {},
209212
};
213+
try ancestors.addSlot(allocator, slot);
210214

211215
const action = random.enumValue(enum { put, get });
212216
switch (action) {
@@ -261,16 +265,34 @@ pub fn run(seed: u64, args: *std.process.ArgIterator) !void {
261265

262266
break :blk .{ key, tracked_accounts.get(key).? };
263267
};
264-
const account, const ref =
265-
try accounts_db.getAccountAndReference(&tracked_account.pubkey);
268+
269+
var ancestors_sub = try ancestors.clone(allocator);
270+
defer ancestors_sub.deinit(allocator);
271+
for (ancestors_sub.ancestors.keys()) |other_slot| {
272+
if (other_slot <= tracked_account.slot) continue;
273+
_ = ancestors_sub.ancestors.swapRemove(other_slot);
274+
}
275+
ancestors_sub.ancestors.sort(struct {
276+
ancestors_sub: []Slot,
277+
pub fn lessThan(ctx: @This(), a: usize, b: usize) bool {
278+
return ctx.ancestors_sub[a] < ctx.ancestors_sub[b];
279+
}
280+
}{ .ancestors_sub = ancestors_sub.ancestors.keys() });
281+
282+
const account =
283+
try accounts_db.getAccountWithAncestors(&pubkey, &ancestors_sub) orelse {
284+
logger.err().logf("accounts_db missing tracked account '{}': {}", .{ pubkey, tracked_account });
285+
return error.MissingAccount;
286+
};
266287
defer account.deinit(allocator);
267288

268289
if (!account.data.eqlSlice(&tracked_account.data)) {
269-
std.debug.panic(
290+
logger.err().logf(
270291
"found account {} with different data: " ++
271-
"tracked: {any} vs found: {any} ({})\n",
272-
.{ pubkey, tracked_account.data, account.data, ref },
292+
"tracked: {any} vs found: {any}\n",
293+
.{ pubkey, tracked_account.data, account.data },
273294
);
295+
return error.TrackedAccountMismatch;
274296
}
275297
},
276298
}

0 commit comments

Comments
 (0)