diff --git a/beacon_chain/rpc/rest_validator_api.nim b/beacon_chain/rpc/rest_validator_api.nim index 5c45dbbf1..ce3e31f62 100644 --- a/beacon_chain/rpc/rest_validator_api.nim +++ b/beacon_chain/rpc/rest_validator_api.nim @@ -215,7 +215,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = for idx, pubkey in syncCommittee: if pubkey == res[resIdx].pubkey: res[resIdx].validator_sync_committee_indices.add( - ValidatorIndexInSyncCommittee idx) + IndexInSyncCommittee idx) res return RestApiResponse.jsonResponse(duties) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index c1d84e664..afa6ac3ff 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -19,9 +19,6 @@ import export extras, forks, validator -type - SomeBeaconState* = phase0.BeaconState | altair.BeaconState | merge.BeaconState - # https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/phase0/beacon-chain.md#increase_balance func increase_balance*(balance: var Gwei, delta: Gwei) = balance += delta @@ -864,6 +861,6 @@ func upgrade_to_merge*(cfg: RuntimeConfig, pre: altair.BeaconState): latest_execution_payload_header: ExecutionPayloadHeader() ) -template isValidInState*(idx: ValidatorIndex, state: SomeBeaconState): bool = - idx.int < state.validators.len +template isValidInState*(idx: ValidatorIndex, state: ForkyBeaconState): bool = + idx.uint64 < state.validators.lenu64 diff --git a/beacon_chain/spec/datatypes/altair.nim b/beacon_chain/spec/datatypes/altair.nim index f5e4b9a90..13d3c95d1 100644 --- a/beacon_chain/spec/datatypes/altair.nim +++ b/beacon_chain/spec/datatypes/altair.nim @@ -432,7 +432,7 @@ type SomeBeaconBlockBody* = BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody SyncSubcommitteeIndex* = distinct uint8 - ValidatorIndexInSyncCommittee* = distinct uint16 + IndexInSyncCommittee* = distinct uint16 BeaconStateDiff* = object # Small and/or static; always include @@ -501,7 +501,7 @@ template `[]`*(a: auto; i: SyncSubcommitteeIndex): auto = a[i.asInt] template `[]`*(arr: array[SYNC_COMMITTEE_SIZE, any] | seq; - idx: ValidatorIndexInSyncCommittee): auto = + idx: IndexInSyncCommittee): auto = arr[int idx] template `==`*(x, y: SyncSubcommitteeIndex): bool = diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 7bb6f18c6..3ca9edb2d 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -6,16 +6,16 @@ import std/typetraits import stew/[assign2, results, base10, byteutils, endians2], presto/common, - libp2p/peerid, serialization, - json_serialization, json_serialization/std/[options, net, sets], - nimcrypto/utils as ncrutils + libp2p/peerid, nimcrypto/utils as ncrutils import "."/rest_types, ".."/[eth2_ssz_serialization, forks], ".."/datatypes/[phase0, altair, merge] +import serialization, json_serialization, json_serialization/std/[options, net, sets] + export - results, peerid, common, serialization, json_serialization, options, net, sets, - eth2_ssz_serialization, rest_types + eth2_ssz_serialization, results, peerid, common, serialization, + json_serialization, options, net, sets, rest_types from web3/ethtypes import BlockHash export ethtypes.BlockHash @@ -430,21 +430,21 @@ proc readValue*(reader: var JsonReader[RestJson], value: var ValidatorIndex) else: reader.raiseUnexpectedValue($res.error()) -proc writeValue*(writer: var JsonWriter[RestJson], value: ValidatorIndexInSyncCommittee) +proc writeValue*(writer: var JsonWriter[RestJson], value: IndexInSyncCommittee) {.raises: [IOError, Defect].} = writeValue(writer, Base10.toString(distinctBase(value))) -proc readValue*(reader: var JsonReader[RestJson], value: var ValidatorIndexInSyncCommittee) +proc readValue*(reader: var JsonReader[RestJson], value: var IndexInSyncCommittee) {.raises: [IOError, SerializationError, Defect].} = let svalue = reader.readValue(string) let res = Base10.decode(uint64, svalue) if res.isOk(): let v = res.get() if v < SYNC_COMMITTEE_SIZE: - value = ValidatorIndexInSyncCommittee(v) + value = IndexInSyncCommittee(v) else: reader.raiseUnexpectedValue( - "Validator index is bigger then SYNC_COMMITTEE_SIZE") + "Index in committee is bigger than SYNC_COMMITTEE_SIZE") else: reader.raiseUnexpectedValue($res.error()) diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index bd670fecb..f18fc0185 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -105,7 +105,7 @@ type RestSyncCommitteeDuty* = object pubkey*: ValidatorPubKey validator_index*: ValidatorIndex - validator_sync_committee_indices*: seq[ValidatorIndexInSyncCommittee] + validator_sync_committee_indices*: seq[IndexInSyncCommittee] RestSyncCommitteeMessage* = object slot*: Slot