mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-10 13:36:40 +00:00
REST server shouldn't create validation objects when optimistically synced (#4361)
This commit is contained in:
parent
806b4fd649
commit
898684c175
@ -1609,7 +1609,7 @@ proc pruneBlocksDAG(dag: ChainDAGRef) =
|
|||||||
prunedHeads = hlen - dag.heads.len,
|
prunedHeads = hlen - dag.heads.len,
|
||||||
dagPruneDur = Moment.now() - startTick
|
dagPruneDur = Moment.now() - startTick
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/sync/optimistic.md#helpers
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/sync/optimistic.md#helpers
|
||||||
template is_optimistic*(dag: ChainDAGRef, root: Eth2Digest): bool =
|
template is_optimistic*(dag: ChainDAGRef, root: Eth2Digest): bool =
|
||||||
root in dag.optimisticRoots
|
root in dag.optimisticRoots
|
||||||
|
|
||||||
|
@ -36,8 +36,12 @@ func match(data: openArray[char], charset: set[char]): int =
|
|||||||
proc getSyncedHead*(node: BeaconNode, slot: Slot): Result[BlockRef, cstring] =
|
proc getSyncedHead*(node: BeaconNode, slot: Slot): Result[BlockRef, cstring] =
|
||||||
let head = node.dag.head
|
let head = node.dag.head
|
||||||
|
|
||||||
if slot > head.slot and node.isSynced(head) != SyncStatus.synced:
|
if node.isSynced(head) != SyncStatus.synced:
|
||||||
return err("Requesting way ahead of the current head")
|
return err("Beacon node not fully and non-optimistically synced")
|
||||||
|
|
||||||
|
# Enough ahead not to know the shuffling
|
||||||
|
if slot > head.slot + SLOTS_PER_EPOCH * 2:
|
||||||
|
return err("Requesting far ahead of the current head")
|
||||||
|
|
||||||
ok(head)
|
ok(head)
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ proc getSyncedHead*(node: BeaconNode,
|
|||||||
return err("Requesting epoch for which slot would overflow")
|
return err("Requesting epoch for which slot would overflow")
|
||||||
node.getSyncedHead(epoch.start_slot())
|
node.getSyncedHead(epoch.start_slot())
|
||||||
|
|
||||||
proc getBlockSlotId*(node: BeaconNode,
|
func getBlockSlotId*(node: BeaconNode,
|
||||||
stateIdent: StateIdent): Result[BlockSlotId, cstring] =
|
stateIdent: StateIdent): Result[BlockSlotId, cstring] =
|
||||||
case stateIdent.kind
|
case stateIdent.kind
|
||||||
of StateQueryKind.Slot:
|
of StateQueryKind.Slot:
|
||||||
@ -118,7 +122,7 @@ proc getForkedBlock*(node: BeaconNode, id: BlockIdent):
|
|||||||
|
|
||||||
node.dag.getForkedBlock(bid)
|
node.dag.getForkedBlock(bid)
|
||||||
|
|
||||||
proc disallowInterruptionsAux(body: NimNode) =
|
func disallowInterruptionsAux(body: NimNode) =
|
||||||
for n in body:
|
for n in body:
|
||||||
const because =
|
const because =
|
||||||
"because the `state` variable may be mutated (and thus invalidated) " &
|
"because the `state` variable may be mutated (and thus invalidated) " &
|
||||||
@ -197,7 +201,7 @@ template strData*(body: ContentBody): string =
|
|||||||
bind fromBytes
|
bind fromBytes
|
||||||
string.fromBytes(body.data)
|
string.fromBytes(body.data)
|
||||||
|
|
||||||
proc toValidatorIndex*(value: RestValidatorIndex): Result[ValidatorIndex,
|
func toValidatorIndex*(value: RestValidatorIndex): Result[ValidatorIndex,
|
||||||
ValidatorIndexError] =
|
ValidatorIndexError] =
|
||||||
when sizeof(ValidatorIndex) == 4:
|
when sizeof(ValidatorIndex) == 4:
|
||||||
if uint64(value) < VALIDATOR_REGISTRY_LIMIT:
|
if uint64(value) < VALIDATOR_REGISTRY_LIMIT:
|
||||||
|
@ -146,10 +146,10 @@ const
|
|||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#broadcast-sync-committee-contribution
|
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#broadcast-sync-committee-contribution
|
||||||
syncContributionSlotOffset* = TimeDiff(nanoseconds:
|
syncContributionSlotOffset* = TimeDiff(nanoseconds:
|
||||||
NANOSECONDS_PER_SLOT.int64 * 2 div INTERVALS_PER_SLOT)
|
NANOSECONDS_PER_SLOT.int64 * 2 div INTERVALS_PER_SLOT)
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#sync-committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/light-client/p2p-interface.md#sync-committee
|
||||||
lightClientFinalityUpdateSlotOffset* = TimeDiff(nanoseconds:
|
lightClientFinalityUpdateSlotOffset* = TimeDiff(nanoseconds:
|
||||||
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
|
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#sync-committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/light-client/p2p-interface.md#sync-committee
|
||||||
lightClientOptimisticUpdateSlotOffset* = TimeDiff(nanoseconds:
|
lightClientOptimisticUpdateSlotOffset* = TimeDiff(nanoseconds:
|
||||||
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
|
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
|
||||||
|
|
||||||
|
@ -152,13 +152,13 @@ func get_slashing_penalty*(state: ForkyBeaconState,
|
|||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#modified-slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||||
func get_whistleblower_reward*(validator_effective_balance: Gwei): Gwei =
|
func get_whistleblower_reward*(validator_effective_balance: Gwei): Gwei =
|
||||||
validator_effective_balance div WHISTLEBLOWER_REWARD_QUOTIENT
|
validator_effective_balance div WHISTLEBLOWER_REWARD_QUOTIENT
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#modified-slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||||
func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): Gwei =
|
func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): Gwei =
|
||||||
when state is phase0.BeaconState:
|
when state is phase0.BeaconState:
|
||||||
whistleblower_reward div PROPOSER_REWARD_QUOTIENT
|
whistleblower_reward div PROPOSER_REWARD_QUOTIENT
|
||||||
@ -900,7 +900,7 @@ func upgrade_to_altair*(cfg: RuntimeConfig, pre: phase0.BeaconState):
|
|||||||
|
|
||||||
post
|
post
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/fork.md#upgrading-the-state
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/fork.md#upgrading-the-state
|
||||||
func upgrade_to_bellatrix*(cfg: RuntimeConfig, pre: altair.BeaconState):
|
func upgrade_to_bellatrix*(cfg: RuntimeConfig, pre: altair.BeaconState):
|
||||||
ref bellatrix.BeaconState =
|
ref bellatrix.BeaconState =
|
||||||
let epoch = get_current_epoch(pre)
|
let epoch = get_current_epoch(pre)
|
||||||
|
@ -108,7 +108,7 @@ type
|
|||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
## Signature by the validator over the block root of `slot`
|
## Signature by the validator over the block root of `slot`
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#synccommitteecontribution
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/validator.md#synccommitteecontribution
|
||||||
SyncCommitteeAggregationBits* =
|
SyncCommitteeAggregationBits* =
|
||||||
BitArray[SYNC_SUBCOMMITTEE_SIZE]
|
BitArray[SYNC_SUBCOMMITTEE_SIZE]
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ type
|
|||||||
contribution*: SyncCommitteeContribution
|
contribution*: SyncCommitteeContribution
|
||||||
selection_proof*: ValidatorSig
|
selection_proof*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#signedcontributionandproof
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/validator.md#signedcontributionandproof
|
||||||
SignedContributionAndProof* = object
|
SignedContributionAndProof* = object
|
||||||
message*: ContributionAndProof
|
message*: ContributionAndProof
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
@ -215,7 +215,7 @@ type
|
|||||||
state_root*: Eth2Digest
|
state_root*: Eth2Digest
|
||||||
body*: TrustedBeaconBlockBody
|
body*: TrustedBeaconBlockBody
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#beaconblockbody
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#beaconblockbody
|
||||||
BeaconBlockBody* = object
|
BeaconBlockBody* = object
|
||||||
randao_reveal*: ValidatorSig
|
randao_reveal*: ValidatorSig
|
||||||
eth1_data*: Eth1Data
|
eth1_data*: Eth1Data
|
||||||
|
@ -30,14 +30,14 @@ type
|
|||||||
SignedBLSToExecutionChangeList* =
|
SignedBLSToExecutionChangeList* =
|
||||||
List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES]
|
List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#withdrawal
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#withdrawal
|
||||||
Withdrawal* = object
|
Withdrawal* = object
|
||||||
index*: WithdrawalIndex
|
index*: WithdrawalIndex
|
||||||
validator_index*: uint64
|
validator_index*: uint64
|
||||||
address*: ExecutionAddress
|
address*: ExecutionAddress
|
||||||
amount*: Gwei
|
amount*: Gwei
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#blstoexecutionchange
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#blstoexecutionchange
|
||||||
BLSToExecutionChange* = object
|
BLSToExecutionChange* = object
|
||||||
validator_index*: uint64
|
validator_index*: uint64
|
||||||
from_bls_pubkey*: ValidatorPubKey
|
from_bls_pubkey*: ValidatorPubKey
|
||||||
@ -91,7 +91,7 @@ type
|
|||||||
ExecutePayload* = proc(
|
ExecutePayload* = proc(
|
||||||
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].}
|
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#beaconstate
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time*: uint64
|
genesis_time*: uint64
|
||||||
|
@ -315,7 +315,7 @@ proc verify_sync_committee_selection_proof*(
|
|||||||
|
|
||||||
blsVerify(pubkey, signing_root.data, signature)
|
blsVerify(pubkey, signing_root.data, signature)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#signature
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/validator.md#signature
|
||||||
func compute_contribution_and_proof_signing_root*(
|
func compute_contribution_and_proof_signing_root*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
msg: ContributionAndProof): Eth2Digest =
|
msg: ContributionAndProof): Eth2Digest =
|
||||||
|
@ -620,12 +620,12 @@ proc process_execution_payload*(
|
|||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#has_eth1_withdrawal_credential
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#has_eth1_withdrawal_credential
|
||||||
func has_eth1_withdrawal_credential(validator: Validator): bool =
|
func has_eth1_withdrawal_credential(validator: Validator): bool =
|
||||||
## Check if ``validator`` has an 0x01 prefixed "eth1" withdrawal credential.
|
## Check if ``validator`` has an 0x01 prefixed "eth1" withdrawal credential.
|
||||||
validator.withdrawal_credentials.data[0] == ETH1_ADDRESS_WITHDRAWAL_PREFIX
|
validator.withdrawal_credentials.data[0] == ETH1_ADDRESS_WITHDRAWAL_PREFIX
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#is_fully_withdrawable_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#is_fully_withdrawable_validator
|
||||||
func is_fully_withdrawable_validator(
|
func is_fully_withdrawable_validator(
|
||||||
validator: Validator, balance: Gwei, epoch: Epoch): bool =
|
validator: Validator, balance: Gwei, epoch: Epoch): bool =
|
||||||
## Check if ``validator`` is fully withdrawable.
|
## Check if ``validator`` is fully withdrawable.
|
||||||
|
@ -859,7 +859,7 @@ func process_registry_updates*(
|
|||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#slashings
|
||||||
func get_adjusted_total_slashing_balance*(
|
func get_adjusted_total_slashing_balance*(
|
||||||
state: ForkyBeaconState, total_balance: Gwei): Gwei =
|
state: ForkyBeaconState, total_balance: Gwei): Gwei =
|
||||||
const multiplier =
|
const multiplier =
|
||||||
@ -886,7 +886,7 @@ func slashing_penalty_applies*(validator: Validator, epoch: Epoch): bool =
|
|||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#slashings
|
||||||
func get_slashing_penalty*(validator: Validator,
|
func get_slashing_penalty*(validator: Validator,
|
||||||
adjusted_total_slashing_balance,
|
adjusted_total_slashing_balance,
|
||||||
total_balance: Gwei): Gwei =
|
total_balance: Gwei): Gwei =
|
||||||
@ -898,7 +898,7 @@ func get_slashing_penalty*(validator: Validator,
|
|||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#slashings
|
||||||
func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
||||||
let
|
let
|
||||||
epoch = get_current_epoch(state)
|
epoch = get_current_epoch(state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user