mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-26 14:32:24 +00:00
* fixed #1663 - Interger overflow in compute_start_slot_at_epoch through RPC * changed the way the overflow check is done - took the approach from PR #1797 - see the comment in PR #1810 for more details
This commit is contained in:
parent
00a500ef3c
commit
8c59b92081
@ -39,6 +39,12 @@ proc parsePubkey(str: string): ValidatorPubKey =
|
|||||||
raise newException(CatchableError, "Not a valid public key")
|
raise newException(CatchableError, "Not a valid public key")
|
||||||
return pubkeyRes[]
|
return pubkeyRes[]
|
||||||
|
|
||||||
|
func checkEpochToSlotOverflow(epoch: Epoch) =
|
||||||
|
const maxEpoch = compute_epoch_at_slot(not 0'u64)
|
||||||
|
if epoch >= maxEpoch:
|
||||||
|
raise newException(
|
||||||
|
CatchableError, "Requesting epoch for which slot would overflow")
|
||||||
|
|
||||||
proc doChecksAndGetCurrentHead(node: BeaconNode, slot: Slot): BlockRef =
|
proc doChecksAndGetCurrentHead(node: BeaconNode, slot: Slot): BlockRef =
|
||||||
result = node.chainDag.head
|
result = node.chainDag.head
|
||||||
if not node.isSynced(result):
|
if not node.isSynced(result):
|
||||||
@ -48,6 +54,7 @@ proc doChecksAndGetCurrentHead(node: BeaconNode, slot: Slot): BlockRef =
|
|||||||
raise newException(CatchableError, "Requesting way ahead of the current head")
|
raise newException(CatchableError, "Requesting way ahead of the current head")
|
||||||
|
|
||||||
proc doChecksAndGetCurrentHead(node: BeaconNode, epoch: Epoch): BlockRef =
|
proc doChecksAndGetCurrentHead(node: BeaconNode, epoch: Epoch): BlockRef =
|
||||||
|
checkEpochToSlotOverflow(epoch)
|
||||||
node.doChecksAndGetCurrentHead(epoch.compute_start_slot_at_epoch)
|
node.doChecksAndGetCurrentHead(epoch.compute_start_slot_at_epoch)
|
||||||
|
|
||||||
# TODO currently this function throws if the validator isn't found - is this OK?
|
# TODO currently this function throws if the validator isn't found - is this OK?
|
||||||
@ -229,6 +236,7 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
|||||||
rpcServer.rpc("get_v1_beacon_states_stateId_committees_epoch") do (
|
rpcServer.rpc("get_v1_beacon_states_stateId_committees_epoch") do (
|
||||||
stateId: string, epoch: uint64, index: uint64, slot: uint64) ->
|
stateId: string, epoch: uint64, index: uint64, slot: uint64) ->
|
||||||
seq[BeaconStatesCommitteesTuple]:
|
seq[BeaconStatesCommitteesTuple]:
|
||||||
|
checkEpochToSlotOverflow(epoch.Epoch)
|
||||||
withStateForStateId(stateId):
|
withStateForStateId(stateId):
|
||||||
proc getCommittee(slot: Slot, index: CommitteeIndex): BeaconStatesCommitteesTuple =
|
proc getCommittee(slot: Slot, index: CommitteeIndex): BeaconStatesCommitteesTuple =
|
||||||
let vals = get_beacon_committee(state, slot, index, cache).mapIt(it.uint64)
|
let vals = get_beacon_committee(state, slot, index, cache).mapIt(it.uint64)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user