Skip to content

Commit dcd0191

Browse files
committed
update comment and remove invariant
1 parent 8100624 commit dcd0191

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

bindings/napi/proposer_index.zig

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,35 @@ const ComputeIndexUtils = state_transition.committee_indices.ComputeIndexUtils(u
77
const ByteCount = state_transition.committee_indices.ByteCount;
88
const preset = state_transition.preset;
99

10+
/// Compute the proposer index for a given fork, effective balance increments, indices, and seed.
11+
///
12+
/// Arguments:
13+
/// - arg 0: fork (string)
14+
/// - arg 1: effective balance increments for all validators
15+
/// - arg 2: active validator indices
16+
/// - arg 3: random seed
1017
pub fn ProposerIndex_computeProposerIndex(env: napi.Env, cb: napi.CallbackInfo(4)) !napi.Value {
11-
// arg 0: fork (string)
1218
var fork_name_buf: [16]u8 = undefined;
1319
const fork_name = try cb.arg(0).getValueStringUtf8(&fork_name_buf);
1420
const fork = ForkSeq.fromName(fork_name);
1521

16-
// arg 1: effectiveBalanceIncrements (Uint16Array)
1722
const effective_balance_info = try cb.arg(1).getTypedarrayInfo();
1823
if (effective_balance_info.array_type != .uint16) {
1924
return error.InvalidEffectiveBalanceIncrementsType;
2025
}
2126
const effective_balance_increments: []u16 = @alignCast(std.mem.bytesAsSlice(u16, effective_balance_info.data));
2227

23-
// arg 2: indices (Uint32Array)
2428
const indices_info = try cb.arg(2).getTypedarrayInfo();
2529
if (indices_info.array_type != .uint32) {
2630
return error.InvalidIndicesType;
2731
}
2832
const indices: []u32 = @alignCast(std.mem.bytesAsSlice(u32, indices_info.data));
2933

30-
// arg 3: seed (Uint8Array, 32 bytes)
3134
const seed_info = try cb.arg(3).getTypedarrayInfo();
3235
if (seed_info.data.len != 32) {
3336
return error.InvalidSeedLength;
3437
}
3538

36-
// Validate indices don't exceed effective_balance_increments bounds
37-
for (indices) |idx| {
38-
if (idx >= effective_balance_increments.len) {
39-
return error.IndexOutOfBounds;
40-
}
41-
}
42-
4339
// Derive fork-dependent parameters
4440
const rand_byte_count: ByteCount = if (fork.gte(.electra)) .Two else .One;
4541
const max_effective_balance: u64 = if (fork.gte(.electra)) preset.MAX_EFFECTIVE_BALANCE_ELECTRA else preset.MAX_EFFECTIVE_BALANCE;

0 commit comments

Comments
 (0)