Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
refactor(fork_choice): move metric observation to updateAndGetHead
Pull the `computeDeltas` metric block out of the private `updateHead` and
into its only non-init caller `updateAndGetHead`, mirroring the TS layering
where metric observation lives one level above the compute step. As a
consequence `updateHead` no longer needs `io: std.Io` and returns the
`ComputeDeltasResult` so the caller can read counter fields.

`init` also drops `io`: the startup head computation is one-shot and not
metric-observed, matching how TS skips the constructor call from
`addCollect` tracking.

Addresses review feedback (PR #309): `updateHead`'s `io` parameter was an
overweight surface area for what amounted to two `timestampNow` calls.
  • Loading branch information
GrapeBaBa committed May 12, 2026
commit bfeb3a1e62523d353e0379bfd45c1ca1a119d44e
2 changes: 1 addition & 1 deletion bench/fork_choice/on_attestation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const OnAttestationBench = struct {
/// 3. Advance current_slot to 64 so attestations at slot 63 are past-slot.
/// 4. Pre-build 405 unaggregated + 704 aggregated attestations with per-committee roots.
fn setupBench(allocator: std.mem.Allocator, io: std.Io) !OnAttestationBench {
const fc = try util.initializeForkChoice(allocator, io, .{
const fc = try util.initializeForkChoice(allocator, .{
.initial_block_count = 64,
.initial_validator_count = 600_000,
.initial_equivocated_count = 0,
Expand Down
2 changes: 1 addition & 1 deletion bench/fork_choice/update_head.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const UpdateHeadBench = struct {

/// Helper: set up one benchmark instance from the given parameters.
fn setupBench(allocator: std.mem.Allocator, io: std.Io, opts: util.Opts) !UpdateHeadBench {
const fc = try util.initializeForkChoice(allocator, io, opts);
const fc = try util.initializeForkChoice(allocator, opts);

const vote1 = fc.proto_array.getDefaultNodeIndex(fc.head.block_root).?;
const vote2 = fc.proto_array.getDefaultNodeIndex(fc.head.parent_root).?;
Expand Down
3 changes: 1 addition & 2 deletions bench/fork_choice/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn makeBlock(slot: u64, root: [32]u8, parent_root: [32]u8) ProtoBlock {
///
/// Allocates a ProtoArray, ForkChoiceStore, and ForkChoice on the heap.
/// The returned pointer must be freed via `deinitForkChoice`.
pub fn initializeForkChoice(allocator: Allocator, io: std.Io, opts: Opts) !*ForkChoice {
pub fn initializeForkChoice(allocator: Allocator, opts: Opts) !*ForkChoice {
// -- Balances: every validator has effective balance = 32 ETH (increment = 32) --
const balances = try allocator.alloc(u16, opts.initial_validator_count);
defer allocator.free(balances);
Expand Down Expand Up @@ -117,7 +117,6 @@ pub fn initializeForkChoice(allocator: Allocator, io: std.Io, opts: Opts) !*Fork
errdefer allocator.destroy(fc);
try fc.init(
allocator,
io,
&config.mainnet.config,
fc_store,
pa,
Expand Down
Loading
Loading