mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-07 12:19:22 +00:00
bump libp2p; integrate pubsub.ValidationResult into extended validation (#1893)
This commit is contained in:
parent
e87e0ef179
commit
a136c2e95a
@ -69,18 +69,18 @@ func check_attestation_block_slot(
|
||||
# nuts and keep processing empty slots
|
||||
if not (attestationBlck.slot > pool.chainDag.finalizedHead.slot):
|
||||
const err_str: cstring = "Voting for already-finalized block"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
# we'll also cap it at 4 epochs which is somewhat arbitrary, but puts an
|
||||
# upper bound on the processing done to validate the attestation
|
||||
# TODO revisit with less arbitrary approach
|
||||
if not (attestationSlot >= attestationBlck.slot):
|
||||
const err_str: cstring = "Voting for block that didn't exist at the time"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
if not ((attestationSlot - attestationBlck.slot) <= uint64(4 * SLOTS_PER_EPOCH)):
|
||||
const err_str: cstring = "Voting for very old block"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
ok()
|
||||
|
||||
@ -92,7 +92,7 @@ func check_propagation_slot_range(
|
||||
|
||||
if not futureSlot.afterGenesis or data.slot > futureSlot.slot:
|
||||
const err_str: cstring = "Attestation slot in the future"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
let
|
||||
pastSlot = (wallTime - MAXIMUM_GOSSIP_CLOCK_DISPARITY).toSlot()
|
||||
@ -100,7 +100,7 @@ func check_propagation_slot_range(
|
||||
if pastSlot.afterGenesis and
|
||||
data.slot + ATTESTATION_PROPAGATION_SLOT_RANGE < pastSlot.slot:
|
||||
const err_str: cstring = "Attestation slot in the past"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
ok()
|
||||
|
||||
@ -115,7 +115,7 @@ func check_attestation_beacon_block(
|
||||
if attestationBlck.isNil:
|
||||
pool.quarantine.addMissing(attestation.data.beacon_block_root)
|
||||
const err_msg: cstring = "Attestation block unknown"
|
||||
return err((EVRESULT_IGNORE, err_msg))
|
||||
return err((ValidationResult.Ignore, err_msg))
|
||||
|
||||
# Not in spec - check that rewinding to the state is sane
|
||||
? check_attestation_block_slot(pool, attestation.data.slot, attestationBlck)
|
||||
@ -137,13 +137,13 @@ func check_aggregation_count(
|
||||
if singular: # More than one ok
|
||||
if onesCount > 1:
|
||||
const err_str: cstring = "Attestation has too many aggregation bits"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
else:
|
||||
break # Found the one we needed
|
||||
|
||||
if onesCount < 1:
|
||||
const err_str: cstring = "Attestation has too few aggregation bits"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
ok()
|
||||
|
||||
@ -159,7 +159,7 @@ func check_attestation_subnet(
|
||||
if expectedSubnet != topicCommitteeIndex:
|
||||
const err_str: cstring =
|
||||
"Attestation's committee index not for the correct subnet"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
ok()
|
||||
|
||||
@ -175,7 +175,7 @@ proc validateAttestation*(
|
||||
block:
|
||||
let v = check_attestation_slot_target(attestation.data)
|
||||
if v.isErr():
|
||||
return err((EVRESULT_REJECT, v.error))
|
||||
return err((ValidationResult.Reject, v.error))
|
||||
|
||||
# attestation.data.slot is within the last ATTESTATION_PROPAGATION_SLOT_RANGE
|
||||
# slots (within a MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance) -- i.e.
|
||||
@ -193,7 +193,7 @@ proc validateAttestation*(
|
||||
if tgtBlck.isNil:
|
||||
pool.quarantine.addMissing(attestation.data.target.root)
|
||||
const err_str: cstring = "Attestation target block unknown"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
# The following rule follows implicitly from that we clear out any
|
||||
# unviable blocks from the chain dag:
|
||||
@ -212,7 +212,7 @@ proc validateAttestation*(
|
||||
if not (attestation.data.index < get_committee_count_per_slot(epochRef)):
|
||||
const err_str: cstring =
|
||||
"validateAttestation: committee index not within expected range"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
# [REJECT] The attestation is for the correct subnet -- i.e.
|
||||
# compute_subnet_for_attestation(committees_per_slot,
|
||||
@ -233,7 +233,7 @@ proc validateAttestation*(
|
||||
epochRef, attestation.data.slot, attestation.data.index.CommitteeIndex)):
|
||||
const err_str: cstring =
|
||||
"validateAttestation: number of aggregation bits and committee size mismatch"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
# The block being voted for (attestation.data.beacon_block_root) has been seen
|
||||
# (via both gossip and non-gossip sources) (a client MAY queue aggregates for
|
||||
@ -264,7 +264,7 @@ proc validateAttestation*(
|
||||
(pool.lastVotedEpoch[validator_index.int].get() >=
|
||||
attestation.data.target.epoch):
|
||||
const err_str: cstring = "Validator has already voted in epoch"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
# The signature of attestation is valid.
|
||||
block:
|
||||
@ -272,7 +272,7 @@ proc validateAttestation*(
|
||||
fork, genesis_validators_root, epochRef, attesting_indices,
|
||||
attestation, {})
|
||||
if v.isErr():
|
||||
return err((EVRESULT_REJECT, v.error))
|
||||
return err((ValidationResult.Reject, v.error))
|
||||
|
||||
# [REJECT] The attestation's target block is an ancestor of the block named
|
||||
# in the LMD vote -- i.e. get_ancestor(store,
|
||||
@ -290,7 +290,7 @@ proc validateAttestation*(
|
||||
attestation.data.target.root):
|
||||
const err_str: cstring =
|
||||
"validateAttestation: attestation's target block not an ancestor of LMD vote block"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
# Only valid attestations go in the list
|
||||
if pool.lastVotedEpoch.len <= validator_index.int:
|
||||
@ -311,7 +311,7 @@ proc validateAggregate*(
|
||||
block:
|
||||
let v = check_attestation_slot_target(aggregate.data) # Not in spec
|
||||
if v.isErr():
|
||||
return err((EVRESULT_IGNORE, v.error))
|
||||
return err((ValidationResult.Ignore, v.error))
|
||||
|
||||
# [IGNORE] aggregate.data.slot is within the last
|
||||
# ATTESTATION_PROPAGATION_SLOT_RANGE slots (with a
|
||||
@ -360,7 +360,7 @@ proc validateAggregate*(
|
||||
if tgtBlck.isNil:
|
||||
pool.quarantine.addMissing(aggregate.data.target.root)
|
||||
const err_str: cstring = "Aggregate target block unknown"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
let epochRef = pool.chainDag.getEpochRef(tgtBlck, aggregate.data.target.epoch)
|
||||
|
||||
@ -368,7 +368,7 @@ proc validateAggregate*(
|
||||
epochRef, aggregate.data.slot, aggregate.data.index.CommitteeIndex,
|
||||
aggregate_and_proof.selection_proof):
|
||||
const err_str: cstring = "Incorrect aggregator"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
# [REJECT] The aggregator's validator index is within the committee -- i.e.
|
||||
# aggregate_and_proof.aggregator_index in get_beacon_committee(state,
|
||||
@ -377,7 +377,7 @@ proc validateAggregate*(
|
||||
get_beacon_committee(
|
||||
epochRef, aggregate.data.slot, aggregate.data.index.CommitteeIndex):
|
||||
const err_str: cstring = "Aggregator's validator index not in committee"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
# [REJECT] The aggregate_and_proof.selection_proof is a valid signature of the
|
||||
# aggregate.data.slot by the validator with index
|
||||
@ -385,7 +385,7 @@ proc validateAggregate*(
|
||||
# get_slot_signature(state, aggregate.data.slot, privkey)
|
||||
if aggregate_and_proof.aggregator_index >= epochRef.validator_keys.lenu64:
|
||||
const err_str: cstring = "Invalid aggregator_index"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
let
|
||||
fork = pool.chainDag.headState.data.data.fork
|
||||
@ -396,7 +396,7 @@ proc validateAggregate*(
|
||||
epochRef.validator_keys[aggregate_and_proof.aggregator_index],
|
||||
aggregate_and_proof.selection_proof):
|
||||
const err_str: cstring = "Selection_proof signature verification failed"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
# [REJECT] The aggregator signature, signed_aggregate_and_proof.signature, is valid.
|
||||
if not verify_aggregate_and_proof_signature(
|
||||
@ -405,7 +405,7 @@ proc validateAggregate*(
|
||||
signed_aggregate_and_proof.signature):
|
||||
const err_str: cstring =
|
||||
"signed_aggregate_and_proof signature verification failed"
|
||||
return err((EVRESULT_REJECT, err_str))
|
||||
return err((ValidationResult.Reject, err_str))
|
||||
|
||||
let attesting_indices = get_attesting_indices(
|
||||
epochRef, aggregate.data, aggregate.aggregation_bits)
|
||||
@ -416,7 +416,7 @@ proc validateAggregate*(
|
||||
fork, genesis_validators_root, epochRef, attesting_indices,
|
||||
aggregate, {})
|
||||
if v.isErr():
|
||||
return err((EVRESULT_REJECT, v.error))
|
||||
return err((ValidationResult.Reject, v.error))
|
||||
|
||||
# The following rule follows implicitly from that we clear out any
|
||||
# unviable blocks from the chain dag:
|
||||
|
@ -8,7 +8,9 @@ import
|
||||
fork_choice/fork_choice_types,
|
||||
validator_slashing_protection
|
||||
|
||||
export block_pools_types
|
||||
from libp2p/protocols/pubsub/pubsub import ValidationResult
|
||||
|
||||
export block_pools_types, ValidationResult
|
||||
|
||||
const
|
||||
ATTESTATION_LOOKBACK* =
|
||||
|
@ -14,6 +14,9 @@ import
|
||||
../spec/[datatypes, crypto, digest],
|
||||
../beacon_chain_db, ../extras
|
||||
|
||||
from libp2p/protocols/pubsub/pubsub import ValidationResult
|
||||
export ValidationResult
|
||||
|
||||
# #############################################
|
||||
#
|
||||
# Quarantine & DAG
|
||||
|
@ -8,7 +8,7 @@
|
||||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
std/[tables],
|
||||
std/tables,
|
||||
chronicles,
|
||||
metrics, stew/results,
|
||||
../extras,
|
||||
@ -142,7 +142,7 @@ proc addRawBlock*(
|
||||
# existed in the pool, as that may confuse consumers such as the fork
|
||||
# choice. While the validation result won't be accessed, it's IGNORE,
|
||||
# according to the spec.
|
||||
return err((EVRESULT_IGNORE, Duplicate))
|
||||
return err((ValidationResult.Ignore, Duplicate))
|
||||
|
||||
quarantine.missing.del(blockRoot)
|
||||
|
||||
@ -157,7 +157,7 @@ proc addRawBlock*(
|
||||
|
||||
# Doesn't correspond to any specific validation condition, and still won't
|
||||
# be used, but certainly would be IGNORE.
|
||||
return err((EVRESULT_IGNORE, Unviable))
|
||||
return err((ValidationResult.Ignore, Unviable))
|
||||
|
||||
let parent = dag.blocks.getOrDefault(blck.parent_root)
|
||||
|
||||
@ -168,7 +168,7 @@ proc addRawBlock*(
|
||||
debug "Invalid block slot",
|
||||
parentBlock = shortLog(parent)
|
||||
|
||||
return err((EVRESULT_REJECT, Invalid))
|
||||
return err((ValidationResult.Reject, Invalid))
|
||||
|
||||
if (parent.slot < dag.finalizedHead.slot) or
|
||||
(parent.slot == dag.finalizedHead.slot and
|
||||
@ -185,7 +185,7 @@ proc addRawBlock*(
|
||||
finalizedHead = shortLog(dag.finalizedHead),
|
||||
tail = shortLog(dag.tail)
|
||||
|
||||
return err((EVRESULT_IGNORE, Unviable))
|
||||
return err((ValidationResult.Ignore, Unviable))
|
||||
|
||||
# The block might have been in either of `orphans` or `missing` - we don't
|
||||
# want any more work done on its behalf
|
||||
@ -213,7 +213,7 @@ proc addRawBlock*(
|
||||
cache, dag.updateFlags + {slotProcessed}, restore):
|
||||
info "Invalid block"
|
||||
|
||||
return err((EVRESULT_REJECT, Invalid))
|
||||
return err((ValidationResult.Reject, Invalid))
|
||||
|
||||
# Careful, clearanceState.data has been updated but not blck - we need to
|
||||
# create the BlockRef first!
|
||||
@ -241,7 +241,7 @@ proc addRawBlock*(
|
||||
orphans = quarantine.orphans.len,
|
||||
missing = quarantine.missing.len
|
||||
|
||||
return err((EVRESULT_IGNORE, MissingParent))
|
||||
return err((ValidationResult.Ignore, MissingParent))
|
||||
|
||||
# This is an unresolved block - put its parent on the missing list for now...
|
||||
# TODO if we receive spam blocks, one heurestic to implement might be to wait
|
||||
@ -260,7 +260,7 @@ proc addRawBlock*(
|
||||
orphans = quarantine.orphans.len,
|
||||
missing = quarantine.missing.len
|
||||
|
||||
return err((EVRESULT_IGNORE, MissingParent))
|
||||
return err((ValidationResult.Ignore, MissingParent))
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0-rc.0/specs/phase0/p2p-interface.md#beacon_block
|
||||
proc isValidBeaconBlock*(
|
||||
@ -285,14 +285,14 @@ proc isValidBeaconBlock*(
|
||||
if not (signed_beacon_block.message.slot <= current_slot + 1):
|
||||
debug "block is from a future slot",
|
||||
current_slot
|
||||
return err((EVRESULT_IGNORE, Invalid))
|
||||
return err((ValidationResult.Ignore, Invalid))
|
||||
|
||||
# [IGNORE] The block is from a slot greater than the latest finalized slot --
|
||||
# i.e. validate that signed_beacon_block.message.slot >
|
||||
# compute_start_slot_at_epoch(state.finalized_checkpoint.epoch)
|
||||
if not (signed_beacon_block.message.slot > dag.finalizedHead.slot):
|
||||
debug "block is not from a slot greater than the latest finalized slot"
|
||||
return err((EVRESULT_IGNORE, Invalid))
|
||||
return err((ValidationResult.Ignore, Invalid))
|
||||
|
||||
# [IGNORE] The block is the first block with valid signature received for the
|
||||
# proposer for the slot, signed_beacon_block.message.slot.
|
||||
@ -332,7 +332,7 @@ proc isValidBeaconBlock*(
|
||||
notice "block isn't first block with valid signature received for the proposer",
|
||||
blckRef = slotBlockRef,
|
||||
existing_block = shortLog(blck.message)
|
||||
return err((EVRESULT_IGNORE, Invalid))
|
||||
return err((ValidationResult.Ignore, Invalid))
|
||||
|
||||
# [IGNORE] The block's parent (defined by block.parent_root) has been seen
|
||||
# (via both gossip and non-gossip sources) (a client MAY queue blocks for
|
||||
@ -349,7 +349,7 @@ proc isValidBeaconBlock*(
|
||||
current_slot = shortLog(current_slot)
|
||||
if not quarantine.add(dag, signed_beacon_block):
|
||||
warn "Block quarantine full"
|
||||
return err((EVRESULT_IGNORE, MissingParent))
|
||||
return err((ValidationResult.Ignore, MissingParent))
|
||||
|
||||
# [REJECT] The current finalized_checkpoint is an ancestor of block -- i.e.
|
||||
# get_ancestor(store, block.parent_root,
|
||||
@ -362,11 +362,11 @@ proc isValidBeaconBlock*(
|
||||
|
||||
if ancestor.isNil:
|
||||
debug "couldn't find ancestor block"
|
||||
return err((EVRESULT_IGNORE, Invalid)) # might just not have received block
|
||||
return err((ValidationResult.Ignore, Invalid)) # might not've received block
|
||||
|
||||
if not (finalized_checkpoint.root in [ancestor.root, Eth2Digest()]):
|
||||
debug "block not descendent of finalized block"
|
||||
return err((EVRESULT_REJECT, Invalid))
|
||||
return err((ValidationResult.Reject, Invalid))
|
||||
|
||||
# [REJECT] The block is proposed by the expected proposer_index for the
|
||||
# block's slot in the context of the current shuffling (defined by
|
||||
@ -379,13 +379,13 @@ proc isValidBeaconBlock*(
|
||||
|
||||
if proposer.isNone:
|
||||
warn "cannot compute proposer for message"
|
||||
return err((EVRESULT_IGNORE, Invalid)) # basically an internal issue
|
||||
return err((ValidationResult.Ignore, Invalid)) # internal issue
|
||||
|
||||
if proposer.get()[0] !=
|
||||
ValidatorIndex(signed_beacon_block.message.proposer_index):
|
||||
notice "block had unexpected proposer",
|
||||
expected_proposer = proposer.get()[0]
|
||||
return err((EVRESULT_REJECT, Invalid))
|
||||
return err((ValidationResult.Reject, Invalid))
|
||||
|
||||
# [REJECT] The proposer signature, signed_beacon_block.signature, is valid
|
||||
# with respect to the proposer_index pubkey.
|
||||
@ -399,6 +399,6 @@ proc isValidBeaconBlock*(
|
||||
debug "block failed signature verification",
|
||||
signature = shortLog(signed_beacon_block.signature)
|
||||
|
||||
return err((EVRESULT_REJECT, Invalid))
|
||||
return err((ValidationResult.Reject, Invalid))
|
||||
|
||||
ok()
|
||||
|
@ -4,7 +4,7 @@ import
|
||||
std/options as stdOptions,
|
||||
|
||||
# Status libs
|
||||
stew/[varints, base58, base64, endians2, results, byteutils, io2], bearssl,
|
||||
stew/[varints, base58, endians2, results, byteutils, io2], bearssl,
|
||||
stew/shims/net as stewNet,
|
||||
stew/shims/[macros, tables],
|
||||
faststreams/[inputs, outputs, buffers], snappy, snappy/framing,
|
||||
@ -1366,7 +1366,7 @@ func gossipId(data: openArray[byte]): string =
|
||||
# We don't use non-Snappy-compressed messages, so don't define
|
||||
# MESSAGE_DOMAIN_INVALID_SNAPPY.
|
||||
const MESSAGE_DOMAIN_VALID_SNAPPY = 0x01000000'u64
|
||||
var messageDigest = withEth2Hash:
|
||||
let messageDigest = withEth2Hash:
|
||||
h.update uint_to_bytes4(MESSAGE_DOMAIN_VALID_SNAPPY)
|
||||
h.update data
|
||||
|
||||
@ -1432,21 +1432,21 @@ proc addValidator*[MsgType](node: Eth2Node,
|
||||
ValidationResult {.gcsafe.} ) =
|
||||
# Validate messages as soon as subscribed
|
||||
proc execValidator(
|
||||
topic: string, message: GossipMsg): Future[bool] {.async.} =
|
||||
topic: string, message: GossipMsg): Future[ValidationResult] {.async.} =
|
||||
inc nbc_gossip_messages_received
|
||||
trace "Validating incoming gossip message",
|
||||
len = message.data.len, topic, msgId = gossipId(message.data)
|
||||
try:
|
||||
let decompressed = snappy.decode(message.data, GOSSIP_MAX_SIZE)
|
||||
if decompressed.len > 0:
|
||||
return msgValidator(SSZ.decode(decompressed, MsgType)) == EVRESULT_ACCEPT
|
||||
return msgValidator(SSZ.decode(decompressed, MsgType))
|
||||
else:
|
||||
# TODO penalize peer?
|
||||
debug "Failed to decompress gossip payload"
|
||||
except CatchableError as err:
|
||||
debug "Gossip validation error",
|
||||
msg = err.msg, msgId = gossipId(message.data)
|
||||
return false
|
||||
return ValidationResult.Ignore
|
||||
|
||||
node.pubsub.addValidator(topic & "_snappy", execValidator)
|
||||
|
||||
|
@ -242,7 +242,7 @@ proc blockValidator*(
|
||||
(afterGenesis, wallSlot) = wallTime.toSlot()
|
||||
|
||||
if not afterGenesis:
|
||||
return EVRESULT_IGNORE # not an issue with block, so don't penalize
|
||||
return ValidationResult.Ignore # not an issue with block, so don't penalize
|
||||
|
||||
logScope: wallSlot
|
||||
|
||||
@ -253,7 +253,7 @@ proc blockValidator*(
|
||||
# already-seen data, but it is fairly aggressive about forgetting about
|
||||
# what it has seen already
|
||||
debug "Dropping already-seen gossip block", delay
|
||||
return EVRESULT_IGNORE # "[IGNORE] The block is the first block with ..."
|
||||
return ValidationResult.Ignore # "[IGNORE] The block is the first block ..."
|
||||
|
||||
# Start of block processing - in reality, we have already gone through SSZ
|
||||
# decoding at this stage, which may be significant
|
||||
@ -279,7 +279,7 @@ proc blockValidator*(
|
||||
traceAsyncErrors self.blocksQueue.addLast(
|
||||
BlockEntry(v: SyncBlock(blk: signedBlock)))
|
||||
|
||||
EVRESULT_ACCEPT
|
||||
ValidationResult.Accept
|
||||
|
||||
proc attestationValidator*(
|
||||
self: var Eth2Processor,
|
||||
@ -295,7 +295,7 @@ proc attestationValidator*(
|
||||
|
||||
if not afterGenesis:
|
||||
notice "Attestation before genesis"
|
||||
return EVRESULT_IGNORE
|
||||
return ValidationResult.Ignore
|
||||
|
||||
logScope: wallSlot
|
||||
|
||||
@ -321,7 +321,7 @@ proc attestationValidator*(
|
||||
traceAsyncErrors self.attestationsQueue.addLast(
|
||||
AttestationEntry(v: attestation, attesting_indices: v.get()))
|
||||
|
||||
EVRESULT_ACCEPT
|
||||
ValidationResult.Accept
|
||||
|
||||
proc aggregateValidator*(
|
||||
self: var Eth2Processor,
|
||||
@ -336,7 +336,7 @@ proc aggregateValidator*(
|
||||
|
||||
if not afterGenesis:
|
||||
notice "Aggregate before genesis"
|
||||
return EVRESULT_IGNORE
|
||||
return ValidationResult.Ignore
|
||||
|
||||
logScope: wallSlot
|
||||
|
||||
@ -365,7 +365,7 @@ proc aggregateValidator*(
|
||||
v: signedAggregateAndProof.message.aggregate,
|
||||
attesting_indices: v.get()))
|
||||
|
||||
EVRESULT_ACCEPT
|
||||
ValidationResult.Accept
|
||||
|
||||
proc attesterSlashingValidator*(
|
||||
self: var Eth2Processor, attesterSlashing: AttesterSlashing):
|
||||
@ -380,7 +380,7 @@ proc attesterSlashingValidator*(
|
||||
|
||||
beacon_attester_slashings_received.inc()
|
||||
|
||||
EVRESULT_ACCEPT
|
||||
ValidationResult.Accept
|
||||
|
||||
proc proposerSlashingValidator*(
|
||||
self: var Eth2Processor, proposerSlashing: ProposerSlashing):
|
||||
@ -395,7 +395,7 @@ proc proposerSlashingValidator*(
|
||||
|
||||
beacon_proposer_slashings_received.inc()
|
||||
|
||||
EVRESULT_ACCEPT
|
||||
ValidationResult.Accept
|
||||
|
||||
proc voluntaryExitValidator*(
|
||||
self: var Eth2Processor, signedVoluntaryExit: SignedVoluntaryExit):
|
||||
@ -410,7 +410,7 @@ proc voluntaryExitValidator*(
|
||||
|
||||
beacon_voluntary_exits_received.inc()
|
||||
|
||||
EVRESULT_ACCEPT
|
||||
ValidationResult.Accept
|
||||
|
||||
proc runQueueProcessingLoop*(self: ref Eth2Processor) {.async.} =
|
||||
# Blocks in eth2 arrive on a schedule for every slot:
|
||||
|
@ -161,7 +161,7 @@ proc validateAttesterSlashing*(
|
||||
attester_slashed_indices, pool.prior_seen_attester_slashed_indices):
|
||||
const err_str: cstring =
|
||||
"validateAttesterSlashing: attester-slashed index already attester-slashed"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
# [REJECT] All of the conditions within process_attester_slashing pass
|
||||
# validation.
|
||||
@ -172,7 +172,7 @@ proc validateAttesterSlashing*(
|
||||
check_attester_slashing(
|
||||
pool.chainDag.headState.data.data, attester_slashing, {}, cache)
|
||||
if attester_slashing_validity.isErr:
|
||||
return err((EVRESULT_REJECT, attester_slashing_validity.error))
|
||||
return err((ValidationResult.Reject, attester_slashing_validity.error))
|
||||
|
||||
pool.prior_seen_attester_slashed_indices.incl attester_slashed_indices
|
||||
pool.attester_slashings.addExitMessage(
|
||||
@ -191,7 +191,7 @@ proc validateProposerSlashing*(
|
||||
pool.prior_seen_proposer_slashed_indices:
|
||||
const err_str: cstring =
|
||||
"validateProposerSlashing: proposer-slashed index already proposer-slashed"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
# [REJECT] All of the conditions within process_proposer_slashing pass validation.
|
||||
var cache =
|
||||
@ -201,7 +201,7 @@ proc validateProposerSlashing*(
|
||||
check_proposer_slashing(
|
||||
pool.chainDag.headState.data.data, proposer_slashing, {}, cache)
|
||||
if proposer_slashing_validity.isErr:
|
||||
return err((EVRESULT_REJECT, proposer_slashing_validity.error))
|
||||
return err((ValidationResult.Reject, proposer_slashing_validity.error))
|
||||
|
||||
pool.prior_seen_proposer_slashed_indices.incl(
|
||||
proposer_slashing.signed_header_1.message.proposer_index)
|
||||
@ -219,11 +219,11 @@ proc validateVoluntaryExit*(
|
||||
if signed_voluntary_exit.message.validator_index >=
|
||||
pool.chainDag.headState.data.data.validators.lenu64:
|
||||
const err_str: cstring = "validateVoluntaryExit: validator index too high"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
if signed_voluntary_exit.message.validator_index in
|
||||
pool.prior_seen_voluntary_exit_indices:
|
||||
const err_str: cstring = "validateVoluntaryExit: validator index already voluntarily exited"
|
||||
return err((EVRESULT_IGNORE, err_str))
|
||||
return err((ValidationResult.Ignore, err_str))
|
||||
|
||||
# [REJECT] All of the conditions within process_voluntary_exit pass
|
||||
# validation.
|
||||
@ -234,7 +234,7 @@ proc validateVoluntaryExit*(
|
||||
check_voluntary_exit(
|
||||
pool.chainDag.headState.data.data, signed_voluntary_exit, {}, cache)
|
||||
if voluntary_exit_validity.isErr:
|
||||
return err((EVRESULT_REJECT, voluntary_exit_validity.error))
|
||||
return err((ValidationResult.Reject, voluntary_exit_validity.error))
|
||||
|
||||
pool.prior_seen_voluntary_exit_indices.incl(
|
||||
signed_voluntary_exit.message.validator_index)
|
||||
|
@ -458,12 +458,6 @@ type
|
||||
stabilitySubnet*: uint64
|
||||
stabilitySubnetExpirationEpoch*: Epoch
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.3/specs/phase0/p2p-interface.md#topics-and-messages
|
||||
ValidationResult* = enum
|
||||
EVRESULT_ACCEPT = 0
|
||||
EVRESULT_REJECT = 1
|
||||
EVRESULT_IGNORE = 2
|
||||
|
||||
func shortValidatorKey*(state: BeaconState, validatorIdx: int): string =
|
||||
($state.validators[validatorIdx].pubkey)[0..7]
|
||||
|
||||
|
@ -304,7 +304,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||
# Callback add to fork choice if valid
|
||||
pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot)
|
||||
|
||||
doAssert: b10Add_clone.error == (EVRESULT_IGNORE, Duplicate)
|
||||
doAssert: b10Add_clone.error == (ValidationResult.Ignore, Duplicate)
|
||||
|
||||
wrappedTimedTest "Trying to add a duplicate block from an old pruned epoch is tagged as an error":
|
||||
# Note: very sensitive to stack usage
|
||||
@ -388,7 +388,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||
# Callback add to fork choice if valid
|
||||
pool[].addForkChoice(epochRef, blckRef, signedBlock.message, blckRef.slot)
|
||||
|
||||
doAssert: b10Add_clone.error == (EVRESULT_IGNORE, Duplicate)
|
||||
doAssert: b10Add_clone.error == (ValidationResult.Ignore, Duplicate)
|
||||
|
||||
|
||||
suiteReport "Attestation validation " & preset():
|
||||
@ -443,7 +443,7 @@ suiteReport "Attestation validation " & preset():
|
||||
|
||||
# Same validator again
|
||||
validateAttestation(pool[], attestation, beaconTime, subnet).error()[0] ==
|
||||
EVRESULT_IGNORE
|
||||
ValidationResult.Ignore
|
||||
|
||||
pool[].lastVotedEpoch.setLen(0) # reset for test
|
||||
check:
|
||||
|
@ -221,7 +221,7 @@ suiteReport "Block pool processing" & preset():
|
||||
|
||||
wrappedTimedTest "Reverse order block add & get" & preset():
|
||||
let missing = dag.addRawBlock(quarantine, b2, nil)
|
||||
check: missing.error == (EVRESULT_IGNORE, MissingParent)
|
||||
check: missing.error == (ValidationResult.Ignore, MissingParent)
|
||||
|
||||
check:
|
||||
dag.get(b2.root).isNone() # Unresolved, shouldn't show up
|
||||
@ -267,7 +267,7 @@ suiteReport "Block pool processing" & preset():
|
||||
b11 = dag.addRawBlock(quarantine, b1, nil)
|
||||
|
||||
check:
|
||||
b11.error == (EVRESULT_IGNORE, Duplicate)
|
||||
b11.error == (ValidationResult.Ignore, Duplicate)
|
||||
not b10[].isNil
|
||||
|
||||
wrappedTimedTest "updateHead updates head and headState" & preset():
|
||||
@ -402,7 +402,7 @@ suiteReport "chain DAG finalization tests" & preset():
|
||||
# The late block is a block whose parent was finalized long ago and thus
|
||||
# is no longer a viable head candidate
|
||||
let status = dag.addRawBlock(quarantine, lateBlock, nil)
|
||||
check: status.error == (EVRESULT_IGNORE, Unviable)
|
||||
check: status.error == (ValidationResult.Ignore, Unviable)
|
||||
|
||||
let
|
||||
dag2 = init(ChainDAGRef, defaultRuntimePreset, db)
|
||||
|
2
vendor/nim-libp2p
vendored
2
vendor/nim-libp2p
vendored
@ -1 +1 @@
|
||||
Subproject commit 98d82fce5c0e18cc1c1be3e95635fd6ad3b15d7f
|
||||
Subproject commit 9c58356823dd47591bdd1a0df17345fca16d6719
|
Loading…
x
Reference in New Issue
Block a user