Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions bindings/napi/BeaconStateView.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1130,20 +1130,19 @@ pub fn loadOtherState(
if (try raw.hasNamedProperty("preloadValidatorsAndBalances") and
(try (try raw.getNamedProperty("preloadValidatorsAndBalances")).getValueBool()))
{
//TODO(bing): These unnecessarily allocate and return memory that we throw away.
// This doesn't matter for typescript lodestar because GC clears it anyway,
// but we're losing some savings here. Consider implementating something like
// a `prefetchAll` that only does `populateAllNodes` that returns void
// Warm the view caches only; the returned slices are scratch and freed immediately.
var validators_view = try new_cached_state.state.validators();
_ = validators_view.getAllReadonlyValues(allocator) catch |err| {
const validator_views = validators_view.getAllReadonly(allocator) catch |err| {
try js.env().throwError("STATE_ERROR", "Failed to preload validators");
return err;
};
allocator.free(validator_views);
var balances_view = try new_cached_state.state.balances();
_ = balances_view.getAll(allocator) catch |err| {
const balance_values = balances_view.getAll(allocator) catch |err| {
try js.env().throwError("STATE_ERROR", "Failed to preload balances");
return err;
};
allocator.free(balance_values);
}
}

Expand Down
Loading