File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ const std = @import ("std" );
2+ const primitives = @import ("../../primitives/types.zig" );
3+ const consensus = @import ("../../consensus/types.zig" );
4+ const configs = @import ("../../configs/config.zig" );
5+ const constants = @import ("../../primitives/constants.zig" );
6+ const preset = @import ("../../presets/preset.zig" );
7+ const phase0 = @import ("../../consensus/phase0/types.zig" );
8+ const altair = @import ("../../consensus/altair/types.zig" );
9+ const electra = @import ("../../consensus/electra/types.zig" );
10+ const epoch_helper = @import ("../../consensus/helpers/epoch.zig" );
11+
12+ pub fn getFinalizationDelay (state : * const consensus.BeaconState ) u64 {
13+ return epoch_helper .getPreviousEpoch (state ) - state .finalizedCheckpointEpoch ();
14+ }
15+
16+ pub fn isInInactivityLeak (state : * const consensus.BeaconState ) bool {
17+ return getFinalizationDelay (state ) > preset .ActivePreset .get ().MIN_EPOCHS_TO_INACTIVITY_PENALTY ;
18+ }
Original file line number Diff line number Diff line change @@ -539,6 +539,22 @@ pub fn getUnslashedParticipatingIndices(
539539 return result_slice ;
540540}
541541
542+ pub fn getEligibleValidatorIndices (state : * consensus.BeaconState ,allocator :std.mem.Allocator ) ! []primitives.ValidatorIndex {
543+ const previous_epoch = epoch_helper .getPreviousEpoch (state );
544+ var eligible = std .ArrayList (primitives .ValidatorIndex ).init (allocator );
545+ defer eligible .deinit ();
546+
547+ for (state .validators (), 0.. ) | v , index | {
548+ if (isActiveValidator (& v , previous_epoch ) or
549+ (v .slashed and previous_epoch + 1 < v .withdrawable_epoch )) {
550+ try eligible .append (@as (primitives .ValidatorIndex , index ));
551+ }
552+ }
553+
554+ return eligible .toOwnedSlice ();
555+ }
556+
557+
542558test "test getBalanceChurnLimit" {
543559 preset .ActivePreset .set (preset .Presets .minimal );
544560 defer preset .ActivePreset .reset ();
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ pub const bls = @import("./bls/bls.zig");
3030pub const deposit_helper = @import ("consensus/helpers/deposit.zig" );
3131pub const voluntary_exit_helper = @import ("consensus/helpers/voluntary_exit.zig" );
3232pub const justification_finalization_helper = @import ("consensus/helpers/justification_finalization.zig" );
33+ pub const finality = @import ("consensus/helpers/finality.zig" );
3334
3435test {
3536 @import ("std" ).testing .refAllDeclsRecursive (@This ());
You can’t perform that action at this time.
0 commit comments