diff --git a/beacon_chain/validator_api.nim b/beacon_chain/validator_api.nim index 661cf2e2f..c139356c3 100644 --- a/beacon_chain/validator_api.nim +++ b/beacon_chain/validator_api.nim @@ -15,8 +15,8 @@ import chronicles, # Local modules - spec/[datatypes, digest, crypto, validator, beaconstate, helpers], - block_pools/chain_dag, ssz/merkleization, + spec/[datatypes, digest, crypto, validator, helpers], + block_pools/[chain_dag, spec_cache], ssz/merkleization, beacon_node_common, beacon_node_types, validator_duties, eth2_network, spec/eth2_apis/callsigs_types, @@ -330,10 +330,10 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = rpcServer.rpc("get_v1_validator_attestation") do ( slot: Slot, committee_index: CommitteeIndex) -> AttestationData: debug "get_v1_validator_attestation", slot = slot - let head = node.doChecksAndGetCurrentHead(slot) - - node.chainDag.withState(node.chainDag.tmpState, head.atSlot(slot)): - return makeAttestationData(state, slot, committee_index.uint64, blck.root) + let + head = node.doChecksAndGetCurrentHead(slot) + epochRef = node.chainDag.getEpochRef(head, slot.epoch) + return makeAttestationData(epochRef, head.atSlot(slot), committee_index.uint64) rpcServer.rpc("get_v1_validator_aggregate_and_proof") do ( attestation_data: AttestationData)-> Attestation: @@ -348,32 +348,35 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = rpcServer.rpc("post_v1_validator_duties_attester") do ( epoch: Epoch, public_keys: seq[ValidatorPubKey]) -> seq[AttesterDuties]: debug "post_v1_validator_duties_attester", epoch = epoch - let head = node.doChecksAndGetCurrentHead(epoch) - - let attestationHead = head.atEpochStart(epoch) - node.chainDag.withState(node.chainDag.tmpState, attestationHead): - for pubkey in public_keys: - let idx = state.validators.asSeq.findIt(it.pubKey.initPubKey == pubkey) - if idx == -1: - continue - let ca = state.get_committee_assignment(epoch, idx.ValidatorIndex) - if ca.isSome: - result.add((public_key: pubkey, - committee_index: ca.get.b, - committee_length: ca.get.a.lenu64, - validator_committee_index: ca.get.a.find(idx.ValidatorIndex).uint64, - slot: ca.get.c)) + let + head = node.doChecksAndGetCurrentHead(epoch) + epochRef = node.chainDag.getEpochRef(head, epoch) + committees_per_slot = get_committee_count_per_slot(epochRef) + for i in 0 ..< SLOTS_PER_EPOCH: + let slot = compute_start_slot_at_epoch(epoch) + i + for committee_index in 0'u64.. seq[ValidatorPubkeySlotPair]: 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: - let currSlot = compute_start_slot_at_epoch(epoch) + i - let proposer = node.chainDag.getProposer(head, currSlot) - if proposer.isSome(): - result.add((public_key: proposer.get()[1].initPubKey(), slot: currSlot)) + if epochRef.beacon_proposers[i].isSome(): + result.add((public_key: epochRef.beacon_proposers[i].get()[1].initPubKey(), + slot: compute_start_slot_at_epoch(epoch) + i)) rpcServer.rpc("post_v1_validator_beacon_committee_subscriptions") do ( committee_index: CommitteeIndex, slot: Slot, aggregator: bool,