Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions bench/state_transition/process_epoch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fn ProcessInactivityUpdatesBench(comptime fork: ForkSeq) type {
defer cache.deinit();
state_transition.processInactivityUpdates(
fork,
allocator,
cloned.config,
cloned.getEpochCache(),
cloned.state.castToFork(fork),
Expand Down Expand Up @@ -463,6 +464,7 @@ fn ProcessEpochSegmentedBench(comptime fork: ForkSeq) type {
const inactivity_start = std.time.nanoTimestamp();
state_transition.processInactivityUpdates(
fork,
allocator,
cloned.config,
epoch_cache,
fork_state,
Expand Down
2 changes: 1 addition & 1 deletion src/state_transition/epoch/process_epoch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn processEpoch(

if (comptime fork.gte(.altair)) {
timer = try Timer.start();
try processInactivityUpdates(fork, config, epoch_cache, state, cache);
try processInactivityUpdates(fork, allocator, config, epoch_cache, state, cache);
try observeEpochTransitionStep(.{ .step = .process_inactivity_updates }, timer.read());
}

Expand Down
10 changes: 8 additions & 2 deletions src/state_transition/epoch/process_inactivity_updates.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Node = @import("persistent_merkle_tree").Node;

pub fn processInactivityUpdates(
comptime fork: ForkSeq,
allocator: std.mem.Allocator,
config: *const BeaconConfig,
epoch_cache: *const EpochCache,
state: *BeaconState(fork),
Expand All @@ -30,12 +31,16 @@ pub fn processInactivityUpdates(
const FLAG_PREV_TARGET_ATTESTER_UNSLASHED = attester_status_utils.FLAG_PREV_TARGET_ATTESTER_UNSLASHED;
const FLAG_ELIGIBLE_ATTESTER = attester_status_utils.FLAG_ELIGIBLE_ATTESTER;

// TODO for TreeView, we may want to convert to value and back
var inactivity_scores = try state.inactivityScores();
try inactivity_scores.commit();
const inactivity_scores_values = try inactivity_scores.getAll(allocator);
defer allocator.free(inactivity_scores_values);
Comment on lines +36 to +37
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and make resource management clearer, the repository style guide recommends visually separating resource allocation and deallocation blocks with newlines.


    const inactivity_scores_values = try inactivity_scores.getAll(allocator);
    defer allocator.free(inactivity_scores_values);

References
  1. The style guide recommends using newlines around resource allocation and deallocation blocks to improve readability and help identify potential leaks. (link)


std.debug.assert(flags.len <= inactivity_scores_values.len);
for (0..flags.len) |i| {
const flag = flags[i];
if (hasMarkers(flag, FLAG_ELIGIBLE_ATTESTER)) {
var inactivity_score = try inactivity_scores.get(i);
var inactivity_score = inactivity_scores_values[i];
Comment on lines +39 to +43
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std.debug.assert(flags.len <= inactivity_scores_values.len) is compiled out in release builds; if these lengths ever diverge, the loop will index out of bounds when reading inactivity_scores_values[i]. Prefer a runtime guard (e.g., return an error) before the loop. Since inactivity_scores is expected to track validator count, also consider checking for equality rather than just <=.

Copilot uses AI. Check for mistakes.

const prev_inactivity_score = inactivity_score;
if (hasMarkers(flag, FLAG_PREV_TARGET_ATTESTER_UNSLASHED)) {
Expand Down Expand Up @@ -66,6 +71,7 @@ test "processInactivityUpdates - sanity" {

try processInactivityUpdates(
.electra,
allocator,
test_state.cached_state.config,
test_state.cached_state.getEpochCache(),
test_state.cached_state.state.castToFork(.electra),
Expand Down
2 changes: 1 addition & 1 deletion test/spec/runner/epoch_processing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn TestCase(comptime fork: ForkSeq, comptime epoch_process_fn: EpochProcessi
.effective_balance_updates => _ = try state_transition.processEffectiveBalanceUpdates(fork, allocator, epoch_cache, fork_state, &epoch_transition_cache),
.eth1_data_reset => try state_transition.processEth1DataReset(fork, fork_state, &epoch_transition_cache),
.historical_roots_update => try state_transition.processHistoricalRootsUpdate(fork, fork_state, &epoch_transition_cache),
.inactivity_updates => try state_transition.processInactivityUpdates(fork, config, epoch_cache, fork_state, &epoch_transition_cache),
.inactivity_updates => try state_transition.processInactivityUpdates(fork, allocator, config, epoch_cache, fork_state, &epoch_transition_cache),
.justification_and_finalization => try state_transition.processJustificationAndFinalization(fork, fork_state, &epoch_transition_cache),
.participation_flag_updates => try state_transition.processParticipationFlagUpdates(fork, fork_state),
.participation_record_updates => try state_transition.processParticipationRecordUpdates(fork, fork_state),
Expand Down