moved away from WithState() for the common validator duties in the API - using EpochRef
This commit is contained in:
parent
22998fdfd4
commit
678a7efaaa
|
@ -15,8 +15,8 @@ import
|
||||||
chronicles,
|
chronicles,
|
||||||
|
|
||||||
# Local modules
|
# Local modules
|
||||||
spec/[datatypes, digest, crypto, validator, beaconstate, helpers],
|
spec/[datatypes, digest, crypto, validator, helpers],
|
||||||
block_pools/chain_dag, ssz/merkleization,
|
block_pools/[chain_dag, spec_cache], ssz/merkleization,
|
||||||
beacon_node_common, beacon_node_types,
|
beacon_node_common, beacon_node_types,
|
||||||
validator_duties, eth2_network,
|
validator_duties, eth2_network,
|
||||||
spec/eth2_apis/callsigs_types,
|
spec/eth2_apis/callsigs_types,
|
||||||
|
@ -330,10 +330,10 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
||||||
rpcServer.rpc("get_v1_validator_attestation") do (
|
rpcServer.rpc("get_v1_validator_attestation") do (
|
||||||
slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
|
slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
|
||||||
debug "get_v1_validator_attestation", slot = slot
|
debug "get_v1_validator_attestation", slot = slot
|
||||||
let head = node.doChecksAndGetCurrentHead(slot)
|
let
|
||||||
|
head = node.doChecksAndGetCurrentHead(slot)
|
||||||
node.chainDag.withState(node.chainDag.tmpState, head.atSlot(slot)):
|
epochRef = node.chainDag.getEpochRef(head, slot.epoch)
|
||||||
return makeAttestationData(state, slot, committee_index.uint64, blck.root)
|
return makeAttestationData(epochRef, head.atSlot(slot), committee_index.uint64)
|
||||||
|
|
||||||
rpcServer.rpc("get_v1_validator_aggregate_and_proof") do (
|
rpcServer.rpc("get_v1_validator_aggregate_and_proof") do (
|
||||||
attestation_data: AttestationData)-> Attestation:
|
attestation_data: AttestationData)-> Attestation:
|
||||||
|
@ -348,32 +348,35 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
||||||
rpcServer.rpc("post_v1_validator_duties_attester") do (
|
rpcServer.rpc("post_v1_validator_duties_attester") do (
|
||||||
epoch: Epoch, public_keys: seq[ValidatorPubKey]) -> seq[AttesterDuties]:
|
epoch: Epoch, public_keys: seq[ValidatorPubKey]) -> seq[AttesterDuties]:
|
||||||
debug "post_v1_validator_duties_attester", epoch = epoch
|
debug "post_v1_validator_duties_attester", epoch = epoch
|
||||||
let head = node.doChecksAndGetCurrentHead(epoch)
|
let
|
||||||
|
head = node.doChecksAndGetCurrentHead(epoch)
|
||||||
let attestationHead = head.atEpochStart(epoch)
|
epochRef = node.chainDag.getEpochRef(head, epoch)
|
||||||
node.chainDag.withState(node.chainDag.tmpState, attestationHead):
|
committees_per_slot = get_committee_count_per_slot(epochRef)
|
||||||
for pubkey in public_keys:
|
for i in 0 ..< SLOTS_PER_EPOCH:
|
||||||
let idx = state.validators.asSeq.findIt(it.pubKey.initPubKey == pubkey)
|
let slot = compute_start_slot_at_epoch(epoch) + i
|
||||||
if idx == -1:
|
for committee_index in 0'u64..<committees_per_slot:
|
||||||
continue
|
let committee = get_beacon_committee(
|
||||||
let ca = state.get_committee_assignment(epoch, idx.ValidatorIndex)
|
epochRef, slot, committee_index.CommitteeIndex)
|
||||||
if ca.isSome:
|
for index_in_committee, validatorIdx in committee:
|
||||||
result.add((public_key: pubkey,
|
if validatorIdx < epochRef.validator_keys.len.ValidatorIndex:
|
||||||
committee_index: ca.get.b,
|
let curr_val_pubkey = epochRef.validator_keys[validatorIdx].initPubKey
|
||||||
committee_length: ca.get.a.lenu64,
|
if public_keys.findIt(it == curr_val_pubkey) != -1:
|
||||||
validator_committee_index: ca.get.a.find(idx.ValidatorIndex).uint64,
|
result.add((public_key: curr_val_pubkey,
|
||||||
slot: ca.get.c))
|
committee_index: committee_index.CommitteeIndex,
|
||||||
|
committee_length: committee.lenu64,
|
||||||
|
validator_committee_index: index_in_committee.uint64,
|
||||||
|
slot: slot))
|
||||||
|
|
||||||
rpcServer.rpc("get_v1_validator_duties_proposer") do (
|
rpcServer.rpc("get_v1_validator_duties_proposer") do (
|
||||||
epoch: Epoch) -> seq[ValidatorPubkeySlotPair]:
|
epoch: Epoch) -> seq[ValidatorPubkeySlotPair]:
|
||||||
debug "get_v1_validator_duties_proposer", epoch = epoch
|
debug "get_v1_validator_duties_proposer", epoch = epoch
|
||||||
let head = node.doChecksAndGetCurrentHead(epoch)
|
let
|
||||||
|
head = node.doChecksAndGetCurrentHead(epoch)
|
||||||
|
epochRef = node.chainDag.getEpochRef(head, epoch)
|
||||||
for i in 0 ..< SLOTS_PER_EPOCH:
|
for i in 0 ..< SLOTS_PER_EPOCH:
|
||||||
let currSlot = compute_start_slot_at_epoch(epoch) + i
|
if epochRef.beacon_proposers[i].isSome():
|
||||||
let proposer = node.chainDag.getProposer(head, currSlot)
|
result.add((public_key: epochRef.beacon_proposers[i].get()[1].initPubKey(),
|
||||||
if proposer.isSome():
|
slot: compute_start_slot_at_epoch(epoch) + i))
|
||||||
result.add((public_key: proposer.get()[1].initPubKey(), slot: currSlot))
|
|
||||||
|
|
||||||
rpcServer.rpc("post_v1_validator_beacon_committee_subscriptions") do (
|
rpcServer.rpc("post_v1_validator_beacon_committee_subscriptions") do (
|
||||||
committee_index: CommitteeIndex, slot: Slot, aggregator: bool,
|
committee_index: CommitteeIndex, slot: Slot, aggregator: bool,
|
||||||
|
|
Loading…
Reference in New Issue