* 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:
parent
941eb609ba
commit
3545d4d1e1
|
@ -215,7 +215,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
for idx, pubkey in syncCommittee:
|
for idx, pubkey in syncCommittee:
|
||||||
if pubkey == res[resIdx].pubkey:
|
if pubkey == res[resIdx].pubkey:
|
||||||
res[resIdx].validator_sync_committee_indices.add(
|
res[resIdx].validator_sync_committee_indices.add(
|
||||||
ValidatorIndexInSyncCommittee idx)
|
IndexInSyncCommittee idx)
|
||||||
res
|
res
|
||||||
|
|
||||||
return RestApiResponse.jsonResponse(duties)
|
return RestApiResponse.jsonResponse(duties)
|
||||||
|
|
|
@ -19,9 +19,6 @@ import
|
||||||
|
|
||||||
export extras, forks, validator
|
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
|
# 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) =
|
func increase_balance*(balance: var Gwei, delta: Gwei) =
|
||||||
balance += delta
|
balance += delta
|
||||||
|
@ -864,6 +861,6 @@ func upgrade_to_merge*(cfg: RuntimeConfig, pre: altair.BeaconState):
|
||||||
latest_execution_payload_header: ExecutionPayloadHeader()
|
latest_execution_payload_header: ExecutionPayloadHeader()
|
||||||
)
|
)
|
||||||
|
|
||||||
template isValidInState*(idx: ValidatorIndex, state: SomeBeaconState): bool =
|
template isValidInState*(idx: ValidatorIndex, state: ForkyBeaconState): bool =
|
||||||
idx.int < state.validators.len
|
idx.uint64 < state.validators.lenu64
|
||||||
|
|
||||||
|
|
|
@ -432,7 +432,7 @@ type
|
||||||
SomeBeaconBlockBody* = BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody
|
SomeBeaconBlockBody* = BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody
|
||||||
|
|
||||||
SyncSubcommitteeIndex* = distinct uint8
|
SyncSubcommitteeIndex* = distinct uint8
|
||||||
ValidatorIndexInSyncCommittee* = distinct uint16
|
IndexInSyncCommittee* = distinct uint16
|
||||||
|
|
||||||
BeaconStateDiff* = object
|
BeaconStateDiff* = object
|
||||||
# Small and/or static; always include
|
# Small and/or static; always include
|
||||||
|
@ -501,7 +501,7 @@ template `[]`*(a: auto; i: SyncSubcommitteeIndex): auto =
|
||||||
a[i.asInt]
|
a[i.asInt]
|
||||||
|
|
||||||
template `[]`*(arr: array[SYNC_COMMITTEE_SIZE, any] | seq;
|
template `[]`*(arr: array[SYNC_COMMITTEE_SIZE, any] | seq;
|
||||||
idx: ValidatorIndexInSyncCommittee): auto =
|
idx: IndexInSyncCommittee): auto =
|
||||||
arr[int idx]
|
arr[int idx]
|
||||||
|
|
||||||
template `==`*(x, y: SyncSubcommitteeIndex): bool =
|
template `==`*(x, y: SyncSubcommitteeIndex): bool =
|
||||||
|
|
|
@ -6,16 +6,16 @@
|
||||||
|
|
||||||
import std/typetraits
|
import std/typetraits
|
||||||
import stew/[assign2, results, base10, byteutils, endians2], presto/common,
|
import stew/[assign2, results, base10, byteutils, endians2], presto/common,
|
||||||
libp2p/peerid, serialization,
|
libp2p/peerid, nimcrypto/utils as ncrutils
|
||||||
json_serialization, json_serialization/std/[options, net, sets],
|
|
||||||
nimcrypto/utils as ncrutils
|
|
||||||
import "."/rest_types,
|
import "."/rest_types,
|
||||||
".."/[eth2_ssz_serialization, forks],
|
".."/[eth2_ssz_serialization, forks],
|
||||||
".."/datatypes/[phase0, altair, merge]
|
".."/datatypes/[phase0, altair, merge]
|
||||||
|
|
||||||
|
import serialization, json_serialization, json_serialization/std/[options, net, sets]
|
||||||
|
|
||||||
export
|
export
|
||||||
results, peerid, common, serialization, json_serialization, options, net, sets,
|
eth2_ssz_serialization, results, peerid, common, serialization,
|
||||||
eth2_ssz_serialization, rest_types
|
json_serialization, options, net, sets, rest_types
|
||||||
|
|
||||||
from web3/ethtypes import BlockHash
|
from web3/ethtypes import BlockHash
|
||||||
export ethtypes.BlockHash
|
export ethtypes.BlockHash
|
||||||
|
@ -430,21 +430,21 @@ proc readValue*(reader: var JsonReader[RestJson], value: var ValidatorIndex)
|
||||||
else:
|
else:
|
||||||
reader.raiseUnexpectedValue($res.error())
|
reader.raiseUnexpectedValue($res.error())
|
||||||
|
|
||||||
proc writeValue*(writer: var JsonWriter[RestJson], value: ValidatorIndexInSyncCommittee)
|
proc writeValue*(writer: var JsonWriter[RestJson], value: IndexInSyncCommittee)
|
||||||
{.raises: [IOError, Defect].} =
|
{.raises: [IOError, Defect].} =
|
||||||
writeValue(writer, Base10.toString(distinctBase(value)))
|
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].} =
|
{.raises: [IOError, SerializationError, Defect].} =
|
||||||
let svalue = reader.readValue(string)
|
let svalue = reader.readValue(string)
|
||||||
let res = Base10.decode(uint64, svalue)
|
let res = Base10.decode(uint64, svalue)
|
||||||
if res.isOk():
|
if res.isOk():
|
||||||
let v = res.get()
|
let v = res.get()
|
||||||
if v < SYNC_COMMITTEE_SIZE:
|
if v < SYNC_COMMITTEE_SIZE:
|
||||||
value = ValidatorIndexInSyncCommittee(v)
|
value = IndexInSyncCommittee(v)
|
||||||
else:
|
else:
|
||||||
reader.raiseUnexpectedValue(
|
reader.raiseUnexpectedValue(
|
||||||
"Validator index is bigger then SYNC_COMMITTEE_SIZE")
|
"Index in committee is bigger than SYNC_COMMITTEE_SIZE")
|
||||||
else:
|
else:
|
||||||
reader.raiseUnexpectedValue($res.error())
|
reader.raiseUnexpectedValue($res.error())
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ type
|
||||||
RestSyncCommitteeDuty* = object
|
RestSyncCommitteeDuty* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
validator_index*: ValidatorIndex
|
validator_index*: ValidatorIndex
|
||||||
validator_sync_committee_indices*: seq[ValidatorIndexInSyncCommittee]
|
validator_sync_committee_indices*: seq[IndexInSyncCommittee]
|
||||||
|
|
||||||
RestSyncCommitteeMessage* = object
|
RestSyncCommitteeMessage* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
|
|
Loading…
Reference in New Issue