Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
.spec_test_version = .{
.type = .string,
.default = "v1.6.0-beta.2",
.default = "v1.7.0-alpha.5",
.description = "Consensus spec tests version tag.",
},
.spec_test_out_dir = .{
Expand Down Expand Up @@ -378,6 +378,7 @@
.bls,
.persistent_merkle_tree,
.hex,
.fork_choice,
},
},
},
Expand Down
14 changes: 12 additions & 2 deletions src/fork_choice/fork_choice.zig
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ pub const ForkChoice = struct {
pub fn onBlock(
self: *ForkChoice,
allocator: Allocator,
io: std.Io,
block: *const AnyBeaconBlock,
state: *CachedBeaconState,
block_delay_sec: u32,
Expand All @@ -403,6 +404,7 @@ pub const ForkChoice = struct {
inline else => |fork| try self.onBlockInner(
fork,
allocator,
io,
block.castToFork(.full, fork),
state,
block_delay_sec,
Expand All @@ -424,6 +426,7 @@ pub const ForkChoice = struct {
self: *ForkChoice,
comptime fork: ForkSeq,
allocator: Allocator,
io: std.Io,
block: *const BeaconBlock(.full, fork),
state: *CachedBeaconState,
block_delay_sec: u32,
Expand Down Expand Up @@ -471,6 +474,9 @@ pub const ForkChoice = struct {
// (before attesting interval = before 1st interval).
const is_timely = self.isBlockTimely(slot, block_delay_sec);
// Only boost the first block we see.
// TODO GLOAS: v1.7.0-alpha.1 added proposer index check in update_proposer_boost_root
// (block.proposer_index == get_beacon_proposer_index(head_state)).
// Not yet implemented — matches Lodestar TS unstable.
if (self.opts.proposer_boost and is_timely and self.proposer_boost_root == null) {
self.proposer_boost_root = block_root;
}
Expand All @@ -494,6 +500,7 @@ pub const ForkChoice = struct {

// 8. Update realized checkpoints.
var realized_ctx = OnBlockBalancesCtx{
.allocator = allocator,
.getter = self.fc_store.justified_balances_getter,
.checkpoint = justified_checkpoint,
.state = state,
Expand Down Expand Up @@ -530,7 +537,7 @@ pub const ForkChoice = struct {
};
} else {
// Compute new, happens ~2/3 first blocks of epoch as monitored in mainnet.
const unrealized = try state_transition.computeUnrealizedCheckpoints(state, allocator);
const unrealized = try state_transition.computeUnrealizedCheckpoints(allocator, io, state);
unrealized_justified_checkpoint = .{
.epoch = unrealized.justified_checkpoint.epoch,
.root = unrealized.justified_checkpoint.root,
Expand All @@ -547,6 +554,7 @@ pub const ForkChoice = struct {

// Update best known unrealized justified & finalized checkpoints.
var unrealized_balances_ctx = OnBlockBalancesCtx{
.allocator = allocator,
.getter = self.fc_store.justified_balances_getter,
.checkpoint = unrealized_justified_checkpoint,
.state = state,
Expand All @@ -560,6 +568,7 @@ pub const ForkChoice = struct {
// checkpoints right away.
if (block_epoch < computeEpochAtSlot(current_slot)) {
var past_epoch_ctx = OnBlockBalancesCtx{
.allocator = allocator,
.getter = self.fc_store.justified_balances_getter,
.checkpoint = unrealized_justified_checkpoint,
.state = state,
Expand Down Expand Up @@ -1334,14 +1343,15 @@ pub const ForkChoice = struct {

/// Closure context for `onBlock` path: calls `getter.get(checkpoint, state)` → wraps in RC.
const OnBlockBalancesCtx = struct {
allocator: Allocator,
getter: store.JustifiedBalancesGetter,
checkpoint: Checkpoint,
state: *CachedBeaconState,

fn call(ctx: ?*anyopaque) error{OutOfMemory}!*EffectiveBalanceIncrementsRc {
const self: *OnBlockBalancesCtx = @ptrCast(@alignCast(ctx.?));
const balances = self.getter.get(self.checkpoint, self.state);
return EffectiveBalanceIncrementsRc.init(balances.allocator, balances);
return EffectiveBalanceIncrementsRc.init(self.allocator, balances);
}
};

Expand Down
1 change: 1 addition & 0 deletions test/spec/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ comptime {
testing.refAllDecls(@import("./test_case/sanity_tests.zig"));
testing.refAllDecls(@import("./test_case/epoch_processing_tests.zig"));
testing.refAllDecls(@import("./test_case/fork_tests.zig"));
testing.refAllDecls(@import("./test_case/fork_choice_tests.zig"));
testing.refAllDecls(@import("./test_case/transition_tests.zig"));
testing.refAllDecls(@import("./test_case/random_tests.zig"));
testing.refAllDecls(@import("./test_case/finality_tests.zig"));
Expand Down
Loading
Loading