fix issue #367 and remove too-small range type usage for ValidatorIndex
This commit is contained in:
parent
2122bb44c9
commit
255980c9f6
|
@ -299,7 +299,7 @@ proc addLocalValidators(node: BeaconNode, state: BeaconState) =
|
|||
info "Local validators attached ", count = node.attachedValidators.count
|
||||
|
||||
proc getAttachedValidator(
|
||||
node: BeaconNode, state: BeaconState, idx: int): AttachedValidator =
|
||||
node: BeaconNode, state: BeaconState, idx: ValidatorIndex): AttachedValidator =
|
||||
let validatorKey = state.validators[idx].pubkey
|
||||
node.attachedValidators.getValidator(validatorKey)
|
||||
|
||||
|
|
|
@ -621,7 +621,7 @@ proc process_attestation*(
|
|||
data: attestation.data,
|
||||
aggregation_bits: attestation.aggregation_bits,
|
||||
inclusion_delay: state.slot - attestation_slot,
|
||||
proposer_index: get_beacon_proposer_index(state, stateCache),
|
||||
proposer_index: get_beacon_proposer_index(state, stateCache).uint64,
|
||||
)
|
||||
|
||||
if attestation.data.target.epoch == get_current_epoch(state):
|
||||
|
|
|
@ -73,7 +73,14 @@ template maxSize*(n: int) {.pragma.}
|
|||
type
|
||||
Bytes = seq[byte]
|
||||
|
||||
ValidatorIndex* = range[0'u32 .. 0xFFFFFF'u32] # TODO: wrap-around
|
||||
# https://github.com/nim-lang/Nim/issues/574 and be consistent across
|
||||
# 32-bit and 64-bit word platforms.
|
||||
# TODO VALIDATOR_REGISTRY_LIMIT is 1 shl 40 in 0.8.3, and
|
||||
# proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.}
|
||||
# in Nim/lib/system/gc.nim quite tightly ties seq addressibility
|
||||
# to the system wordsize. This lifts smaller, and now incorrect,
|
||||
# range-limit.
|
||||
ValidatorIndex* = distinct uint32
|
||||
Shard* = uint64
|
||||
Gwei* = uint64
|
||||
|
||||
|
@ -517,6 +524,24 @@ template ethTimeUnit(typ: type) {.dirty.} =
|
|||
proc `%`*(i: uint64): JsonNode =
|
||||
% int(i)
|
||||
|
||||
# `ValidatorIndex` seq handling.
|
||||
proc max*(a: ValidatorIndex, b: int) : auto =
|
||||
max(a.int, b)
|
||||
|
||||
proc `[]`*[T](a: var seq[T], b: ValidatorIndex): var T =
|
||||
a[b.int]
|
||||
|
||||
proc `[]`*[T](a: seq[T], b: ValidatorIndex): auto =
|
||||
a[b.int]
|
||||
|
||||
proc `[]=`*[T](a: var seq[T], b: ValidatorIndex, c: T) =
|
||||
a[b.int] = c
|
||||
|
||||
# `ValidatorIndex` Nim integration
|
||||
proc `==`*(x, y: ValidatorIndex) : bool {.borrow.}
|
||||
proc hash*(x: ValidatorIndex): Hash {.borrow.}
|
||||
proc `$`*(x: ValidatorIndex): auto = $(x.int64)
|
||||
|
||||
ethTimeUnit Slot
|
||||
ethTimeUnit Epoch
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ type
|
|||
SszWriter* = object
|
||||
stream: OutputStreamVar
|
||||
|
||||
BasicType = char|bool|SomeUnsignedInt|StUint
|
||||
BasicType = char|bool|SomeUnsignedInt|StUint|ValidatorIndex
|
||||
|
||||
SszChunksMerkelizer = ref object of RootObj
|
||||
combinedChunks: array[maxChunkTreeDepth, Eth2Digest]
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import
|
||||
# Standard library
|
||||
os, unittest,
|
||||
os, unittest, sequtils,
|
||||
# Beacon chain internals
|
||||
../../beacon_chain/spec/[datatypes, validator, digest],
|
||||
# Test utilities
|
||||
|
@ -18,7 +18,7 @@ type
|
|||
Shuffling* = object
|
||||
seed*: Eth2Digest
|
||||
count*: uint64
|
||||
mapping*: seq[ValidatorIndex]
|
||||
mapping*: seq[uint64]
|
||||
|
||||
const ShufflingDir = JsonTestsDir/const_preset/"phase0"/"shuffling"/"core"/"shuffle"
|
||||
|
||||
|
@ -27,4 +27,4 @@ suite "Official - Shuffling tests [Preset: " & preset():
|
|||
for file in walkDirRec(ShufflingDir):
|
||||
let t = parseTest(file, Json, Shuffling)
|
||||
let implResult = get_shuffled_seq(t.seed, t.count)
|
||||
check: implResult == t.mapping
|
||||
check: implResult == mapIt(t.mapping, it.ValidatorIndex)
|
||||
|
|
Loading…
Reference in New Issue