abstract over more BeaconState usage (#2496)
This commit is contained in:
parent
3e3137ec14
commit
050e3ac48b
|
@ -167,9 +167,9 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
node.withStateForBlockSlot(bslot):
|
||||
return RestApiResponse.jsonResponse(
|
||||
(
|
||||
previous_version: state().fork.previous_version,
|
||||
current_version: state().fork.current_version,
|
||||
epoch: state().fork.epoch
|
||||
previous_version: getStateField(stateData, fork).previous_version,
|
||||
current_version: getStateField(stateData, fork).current_version,
|
||||
epoch: getStateField(stateData, fork).epoch
|
||||
)
|
||||
)
|
||||
return RestApiResponse.jsonError(Http500, InternalServerError)
|
||||
|
@ -191,9 +191,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
node.withStateForBlockSlot(bslot):
|
||||
return RestApiResponse.jsonResponse(
|
||||
(
|
||||
previous_justified: state().previous_justified_checkpoint,
|
||||
current_justified: state().current_justified_checkpoint,
|
||||
finalized: state().finalized_checkpoint
|
||||
previous_justified:
|
||||
getStateField(stateData, previous_justified_checkpoint),
|
||||
current_justified:
|
||||
getStateField(stateData, current_justified_checkpoint),
|
||||
finalized: getStateField(stateData, finalized_checkpoint)
|
||||
)
|
||||
)
|
||||
return RestApiResponse.jsonError(Http500, InternalServerError)
|
||||
|
@ -268,7 +270,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
node.withStateForBlockSlot(bslot):
|
||||
let current_epoch = get_current_epoch(node.chainDag.headState.data.data)
|
||||
var res: seq[RestValidatorTuple]
|
||||
for index, validator in state().validators.pairs():
|
||||
for index, validator in getStateField(stateData, validators).pairs():
|
||||
let includeFlag =
|
||||
(len(keySet) == 0) and (len(indexSet) == 0) or
|
||||
(len(indexSet) > 0 and (ValidatorIndex(index) in indexSet)) or
|
||||
|
@ -280,7 +282,8 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
if includeFlag and statusFlag:
|
||||
res.add((
|
||||
index: ValidatorIndex(index),
|
||||
balance: Base10.toString(state().balances[index]),
|
||||
balance:
|
||||
Base10.toString(getStateField(stateData, balances)[index]),
|
||||
status: toString(vstatus),
|
||||
validator: validator
|
||||
))
|
||||
|
@ -310,14 +313,15 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let vid = validator_id.get()
|
||||
case vid.kind
|
||||
of ValidatorQueryKind.Key:
|
||||
for index, validator in state().validators.pairs():
|
||||
for index, validator in getStateField(stateData, validators).pairs():
|
||||
if validator.pubkey == vid.key:
|
||||
let sres = validator.getStatus(current_epoch)
|
||||
if sres.isOk():
|
||||
return RestApiResponse.jsonResponse(
|
||||
(
|
||||
index: ValidatorIndex(index),
|
||||
balance: Base10.toString(state().balances[index]),
|
||||
balance:
|
||||
Base10.toString(getStateField(stateData, balances)[index]),
|
||||
status: toString(sres.get()),
|
||||
validator: validator
|
||||
)
|
||||
|
@ -340,15 +344,15 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
UnsupportedValidatorIndexValueError)
|
||||
vres.get()
|
||||
|
||||
if uint64(vindex) >= uint64(len(state().validators)):
|
||||
if uint64(vindex) >= uint64(len(getStateField(stateData, validators))):
|
||||
return RestApiResponse.jsonError(Http404, ValidatorNotFoundError)
|
||||
let validator = state().validators[vindex]
|
||||
let validator = getStateField(stateData, validators)[vindex]
|
||||
let sres = validator.getStatus(current_epoch)
|
||||
if sres.isOk():
|
||||
return RestApiResponse.jsonResponse(
|
||||
(
|
||||
index: vindex,
|
||||
balance: Base10.toString(state().balances[vindex]),
|
||||
balance: Base10.toString(getStateField(stateData, balances)[vindex]),
|
||||
status: toString(sres.get()),
|
||||
validator: validator
|
||||
)
|
||||
|
@ -414,7 +418,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
node.withStateForBlockSlot(bslot):
|
||||
let current_epoch = get_current_epoch(node.chainDag.headState.data.data)
|
||||
var res: seq[RestValidatorBalanceTuple]
|
||||
for index, validator in state().validators.pairs():
|
||||
for index, validator in getStateField(stateData, validators).pairs():
|
||||
let includeFlag =
|
||||
(len(keySet) == 0) and (len(indexSet) == 0) or
|
||||
(len(indexSet) > 0 and (ValidatorIndex(index) in indexSet)) or
|
||||
|
@ -425,7 +429,8 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
if includeFlag:
|
||||
res.add((
|
||||
index: ValidatorIndex(index),
|
||||
balance: Base10.toString(state().balances[index]),
|
||||
balance:
|
||||
Base10.toString(getStateField(stateData, balances)[index]),
|
||||
))
|
||||
return RestApiResponse.jsonResponse(res)
|
||||
|
||||
|
@ -500,7 +505,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
var res: seq[RestBeaconStatesCommitteesTuple]
|
||||
let qepoch =
|
||||
if vepoch.isNone:
|
||||
compute_epoch_at_slot(state().slot)
|
||||
compute_epoch_at_slot(getStateField(stateData, slot))
|
||||
else:
|
||||
vepoch.get()
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) {.
|
|||
|
||||
let proposalState = assignClone(node.chainDag.headState)
|
||||
node.chainDag.withState(proposalState[], head.atSlot(wallSlot)):
|
||||
return node.getBlockProposalEth1Data(state)
|
||||
return node.getBlockProposalEth1Data(stateData)
|
||||
|
||||
rpcServer.rpc("debug_getChronosFutures") do () -> seq[FutureInfo]:
|
||||
when defined(chronosFutureTracking):
|
||||
|
|
|
@ -185,7 +185,8 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
res.get()
|
||||
let proposalState = assignClone(node.chainDag.headState)
|
||||
node.chainDag.withState(proposalState[], head.atSlot(wallSlot)):
|
||||
return RestApiResponse.jsonResponse(node.getBlockProposalEth1Data(state))
|
||||
return RestApiResponse.jsonResponse(
|
||||
node.getBlockProposalEth1Data(stateData))
|
||||
|
||||
router.api(MethodGet, "/api/nimbus/v1/debug/chronos/futures") do (
|
||||
) -> RestApiResponse:
|
||||
|
|
|
@ -231,18 +231,20 @@ proc createAndSendAttestation(node: BeaconNode,
|
|||
beacon_attestation_sent_delay.observe(delayMillis)
|
||||
|
||||
proc getBlockProposalEth1Data*(node: BeaconNode,
|
||||
state: BeaconState): BlockProposalEth1Data =
|
||||
stateData: StateData): BlockProposalEth1Data =
|
||||
if node.eth1Monitor.isNil:
|
||||
var pendingDepositsCount = state.eth1_data.deposit_count -
|
||||
state.eth1_deposit_index
|
||||
var pendingDepositsCount =
|
||||
getStateField(stateData, eth1_data).deposit_count -
|
||||
getStateField(stateData, eth1_deposit_index)
|
||||
if pendingDepositsCount > 0:
|
||||
result.hasMissingDeposits = true
|
||||
else:
|
||||
result.vote = state.eth1_data
|
||||
result.vote = getStateField(stateData, eth1_data)
|
||||
else:
|
||||
let finalizedEpochRef = node.chainDag.getFinalizedEpochRef()
|
||||
result = node.eth1Monitor.getBlockProposalData(
|
||||
state, finalizedEpochRef.eth1_data, finalizedEpochRef.eth1_deposit_index)
|
||||
stateData.data.data, finalizedEpochRef.eth1_data,
|
||||
finalizedEpochRef.eth1_deposit_index)
|
||||
|
||||
proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode,
|
||||
randao_reveal: ValidatorSig,
|
||||
|
@ -258,7 +260,7 @@ proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode,
|
|||
|
||||
node.chainDag.withState(proposalState[], head.atSlot(slot)):
|
||||
let
|
||||
eth1Proposal = node.getBlockProposalEth1Data(state)
|
||||
eth1Proposal = node.getBlockProposalEth1Data(stateData)
|
||||
poolPtr = unsafeAddr node.chainDag # safe because restore is short-lived
|
||||
|
||||
if eth1Proposal.hasMissingDeposits:
|
||||
|
|
Loading…
Reference in New Issue