mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 22:36:01 +00:00
63e621c27d
* rename compute_epoch_of_slot(...) to compute_epoch_at_slot(...) * remove some unnecessary imports; remove some crosslink-related code and tests; complete renaming of compute_epoch_of_slot(...) to compute_epoch_at_slot(...) * rm more transfer-related code and tests; rm more unnecessary strutils imports * rm remaining unused imports * remove useless get_empty_per_epoch_cache(...)/compute_start_slot_of_epoch(...) calls * rename compute_start_slot_of_epoch(...) to compute_start_slot_at_epoch(...) * rename ACTIVATION_EXIT_DELAY to MAX_SEED_LOOKAHEAD * update domain types to 0.9.0 * mark AttesterSlashing, IndexedAttestation, AttestationDataAndCustodyBit, DepositData, BeaconBlockHeader, Fork, integer_squareroot(...), and process_voluntary_exit(...) as 0.9.0 * mark increase_balance(...), decrease_balance(...), get_block_root(...), CheckPoint, Deposit, PendingAttestation, HistoricalBatch, is_active_validator(...), and is_slashable_attestation_data(...) as 0.9.0 * mark compute_activation_exit_epoch(...), bls_verify(...), Validator, get_active_validator_indices(...), get_current_epoch(...), get_total_active_balance(...), and get_previous_epoch(...) as 0.9.0 * mark get_block_root_at_slot(...), ProposerSlashing, get_domain(...), VoluntaryExit, mainnet preset Gwei values, minimal preset max operations, process_block_header(...), and is_slashable_validator(...) as 0.9.0 * mark makeWithdrawalCredentials(...), get_validator_churn_limit(...), get_total_balance(...), is_valid_indexed_attestation(...), bls_aggregate_pubkeys(...), initial genesis value/constants, Attestation, get_randao_mix(...), mainnet preset max operations per block constants, minimal preset Gwei values and time parameters, process_eth1_data(...), get_shuffled_seq(...), compute_committee(...), and process_slots(...) as 0.9.0; partially update get_indexed_attestation(...) to 0.9.0 by removing crosslink refs and associated tests * mark initiate_validator_exit(...), process_registry_updates(...), BeaconBlock, Eth1Data, compute_domain(...), process_randao(...), process_attester_slashing(...), get_base_reward(...), and process_slot(...) as 0.9.0
78 lines
2.8 KiB
Nim
78 lines
2.8 KiB
Nim
import
|
|
tables,
|
|
chronos, chronicles,
|
|
spec/[datatypes, crypto, digest, helpers], ssz,
|
|
beacon_node_types
|
|
|
|
proc init*(T: type ValidatorPool): T =
|
|
result.validators = initTable[ValidatorPubKey, AttachedValidator]()
|
|
|
|
template count*(pool: ValidatorPool): int =
|
|
pool.validators.len
|
|
|
|
proc addLocalValidator*(pool: var ValidatorPool,
|
|
idx: ValidatorIndex,
|
|
pubKey: ValidatorPubKey,
|
|
privKey: ValidatorPrivKey) =
|
|
let v = AttachedValidator(idx: idx,
|
|
pubKey: pubKey,
|
|
kind: inProcess,
|
|
privKey: privKey)
|
|
pool.validators[pubKey] = v
|
|
|
|
info "Local validator attached", pubKey, validator = shortLog(v)
|
|
|
|
proc getValidator*(pool: ValidatorPool,
|
|
validatorKey: ValidatorPubKey): AttachedValidator =
|
|
pool.validators.getOrDefault(validatorKey)
|
|
|
|
proc signBlockProposal*(v: AttachedValidator, state: BeaconState, slot: Slot,
|
|
blockRoot: Eth2Digest): Future[ValidatorSig] {.async.} =
|
|
|
|
if v.kind == inProcess:
|
|
# TODO state might become invalid after any async calls - it's fragile to
|
|
# care about this in here
|
|
let
|
|
domain =
|
|
get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(slot))
|
|
# TODO this is an ugly hack to fake a delay and subsequent async reordering
|
|
# for the purpose of testing the external validator delay - to be
|
|
# replaced by something more sensible
|
|
await sleepAsync(chronos.milliseconds(1))
|
|
|
|
result = bls_sign(v.privKey, blockRoot.data, domain)
|
|
else:
|
|
error "Unimplemented"
|
|
quit 1
|
|
|
|
proc signAttestation*(v: AttachedValidator,
|
|
attestation: AttestationData,
|
|
state: BeaconState): Future[ValidatorSig] {.async.} =
|
|
if v.kind == inProcess:
|
|
let
|
|
attestationRoot = hash_tree_root(
|
|
AttestationDataAndCustodyBit(data: attestation, custody_bit: false))
|
|
domain = get_domain(state, DOMAIN_BEACON_ATTESTER, attestation.target.epoch)
|
|
|
|
# TODO this is an ugly hack to fake a delay and subsequent async reordering
|
|
# for the purpose of testing the external validator delay - to be
|
|
# replaced by something more sensible
|
|
await sleepAsync(chronos.milliseconds(1))
|
|
|
|
result = bls_sign(v.privKey, attestationRoot.data, domain)
|
|
else:
|
|
error "Unimplemented"
|
|
quit 1
|
|
|
|
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
|
|
ValidatorSig =
|
|
let
|
|
domain = get_domain(state, DOMAIN_RANDAO, compute_epoch_at_slot(slot))
|
|
root = hash_tree_root(compute_epoch_at_slot(slot).uint64).data
|
|
|
|
bls_sign(k, root, domain)
|
|
|
|
func genRandaoReveal*(v: AttachedValidator, state: BeaconState, slot: Slot):
|
|
ValidatorSig =
|
|
genRandaoReveal(v.privKey, state, slot)
|