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
|
info "Local validators attached ", count = node.attachedValidators.count
|
||||||
|
|
||||||
proc getAttachedValidator(
|
proc getAttachedValidator(
|
||||||
node: BeaconNode, state: BeaconState, idx: int): AttachedValidator =
|
node: BeaconNode, state: BeaconState, idx: ValidatorIndex): AttachedValidator =
|
||||||
let validatorKey = state.validators[idx].pubkey
|
let validatorKey = state.validators[idx].pubkey
|
||||||
node.attachedValidators.getValidator(validatorKey)
|
node.attachedValidators.getValidator(validatorKey)
|
||||||
|
|
||||||
|
|
|
@ -621,7 +621,7 @@ proc process_attestation*(
|
||||||
data: attestation.data,
|
data: attestation.data,
|
||||||
aggregation_bits: attestation.aggregation_bits,
|
aggregation_bits: attestation.aggregation_bits,
|
||||||
inclusion_delay: state.slot - attestation_slot,
|
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):
|
if attestation.data.target.epoch == get_current_epoch(state):
|
||||||
|
|
|
@ -73,7 +73,14 @@ template maxSize*(n: int) {.pragma.}
|
||||||
type
|
type
|
||||||
Bytes = seq[byte]
|
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
|
Shard* = uint64
|
||||||
Gwei* = uint64
|
Gwei* = uint64
|
||||||
|
|
||||||
|
@ -517,6 +524,24 @@ template ethTimeUnit(typ: type) {.dirty.} =
|
||||||
proc `%`*(i: uint64): JsonNode =
|
proc `%`*(i: uint64): JsonNode =
|
||||||
% int(i)
|
% 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 Slot
|
||||||
ethTimeUnit Epoch
|
ethTimeUnit Epoch
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ type
|
||||||
SszWriter* = object
|
SszWriter* = object
|
||||||
stream: OutputStreamVar
|
stream: OutputStreamVar
|
||||||
|
|
||||||
BasicType = char|bool|SomeUnsignedInt|StUint
|
BasicType = char|bool|SomeUnsignedInt|StUint|ValidatorIndex
|
||||||
|
|
||||||
SszChunksMerkelizer = ref object of RootObj
|
SszChunksMerkelizer = ref object of RootObj
|
||||||
combinedChunks: array[maxChunkTreeDepth, Eth2Digest]
|
combinedChunks: array[maxChunkTreeDepth, Eth2Digest]
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
os, unittest,
|
os, unittest, sequtils,
|
||||||
# Beacon chain internals
|
# Beacon chain internals
|
||||||
../../beacon_chain/spec/[datatypes, validator, digest],
|
../../beacon_chain/spec/[datatypes, validator, digest],
|
||||||
# Test utilities
|
# Test utilities
|
||||||
|
@ -18,7 +18,7 @@ type
|
||||||
Shuffling* = object
|
Shuffling* = object
|
||||||
seed*: Eth2Digest
|
seed*: Eth2Digest
|
||||||
count*: uint64
|
count*: uint64
|
||||||
mapping*: seq[ValidatorIndex]
|
mapping*: seq[uint64]
|
||||||
|
|
||||||
const ShufflingDir = JsonTestsDir/const_preset/"phase0"/"shuffling"/"core"/"shuffle"
|
const ShufflingDir = JsonTestsDir/const_preset/"phase0"/"shuffling"/"core"/"shuffle"
|
||||||
|
|
||||||
|
@ -27,4 +27,4 @@ suite "Official - Shuffling tests [Preset: " & preset():
|
||||||
for file in walkDirRec(ShufflingDir):
|
for file in walkDirRec(ShufflingDir):
|
||||||
let t = parseTest(file, Json, Shuffling)
|
let t = parseTest(file, Json, Shuffling)
|
||||||
let implResult = get_shuffled_seq(t.seed, t.count)
|
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