Address review comments in #3057 (#3069)

* Address review comments in #3057

* reorder imports in rest_utils

maybe this will help with the mysterious serialization issues

Co-authored-by: Jacek Sieka <jacek@status.im>
This commit is contained in:
zah 2021-11-09 21:21:36 +02:00 committed by GitHub
parent 941eb609ba
commit 3545d4d1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 18 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 =

View File

@ -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())

View File

@ -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