add errIgnore helper and refactor errReject helper (#2808)
This commit is contained in:
parent
d9f7ba7153
commit
0a61d1112e
|
@ -162,7 +162,7 @@ template errReject(msg: cstring): untyped =
|
||||||
# an internal consistency/correctness check only, and effectively never has
|
# an internal consistency/correctness check only, and effectively never has
|
||||||
# false positives. These don't, for example, arise from timeouts.
|
# false positives. These don't, for example, arise from timeouts.
|
||||||
raiseAssert $msg
|
raiseAssert $msg
|
||||||
err((ValidationResult.Reject, msg))
|
err((ValidationResult.Reject, cstring msg))
|
||||||
|
|
||||||
template errReject(error: (ValidationResult, cstring)): untyped =
|
template errReject(error: (ValidationResult, cstring)): untyped =
|
||||||
doAssert error[0] == ValidationResult.Reject
|
doAssert error[0] == ValidationResult.Reject
|
||||||
|
@ -173,6 +173,9 @@ template errReject(error: (ValidationResult, cstring)): untyped =
|
||||||
raiseAssert $error[1]
|
raiseAssert $error[1]
|
||||||
err(error)
|
err(error)
|
||||||
|
|
||||||
|
template errIgnore(msg: cstring): untyped =
|
||||||
|
err((ValidationResult.Ignore, cstring msg))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||||
proc validateAttestation*(
|
proc validateAttestation*(
|
||||||
pool: ref AttestationPool,
|
pool: ref AttestationPool,
|
||||||
|
@ -314,7 +317,7 @@ proc validateAttestation*(
|
||||||
var x = (await cryptoFut)
|
var x = (await cryptoFut)
|
||||||
case x
|
case x
|
||||||
of BatchResult.Invalid:
|
of BatchResult.Invalid:
|
||||||
return errReject(cstring("validateAttestation: invalid signature"))
|
return errReject("validateAttestation: invalid signature")
|
||||||
of BatchResult.Timeout:
|
of BatchResult.Timeout:
|
||||||
beacon_attestations_dropped_queue_full.inc()
|
beacon_attestations_dropped_queue_full.inc()
|
||||||
return err((ValidationResult.Ignore, cstring("validateAttestation: timeout checking signature")))
|
return err((ValidationResult.Ignore, cstring("validateAttestation: timeout checking signature")))
|
||||||
|
@ -387,8 +390,7 @@ proc validateAggregate*(
|
||||||
pool.nextAttestationEpoch[
|
pool.nextAttestationEpoch[
|
||||||
aggregate_and_proof.aggregator_index].aggregate >
|
aggregate_and_proof.aggregator_index].aggregate >
|
||||||
aggregate.data.target.epoch:
|
aggregate.data.target.epoch:
|
||||||
return err((ValidationResult.Ignore, cstring(
|
return errIgnore("validateAggregate: Validator has already aggregated in epoch")
|
||||||
"Validator has already aggregated in epoch")))
|
|
||||||
|
|
||||||
# [REJECT] The attestation has participants -- that is,
|
# [REJECT] The attestation has participants -- that is,
|
||||||
# len(get_attesting_indices(state, aggregate.data, aggregate.aggregation_bits)) >= 1.
|
# len(get_attesting_indices(state, aggregate.data, aggregate.aggregation_bits)) >= 1.
|
||||||
|
@ -477,8 +479,7 @@ proc validateAggregate*(
|
||||||
var x = await cryptoFuts.aggregatorCheck
|
var x = await cryptoFuts.aggregatorCheck
|
||||||
case x
|
case x
|
||||||
of BatchResult.Invalid:
|
of BatchResult.Invalid:
|
||||||
return errReject(cstring(
|
return errReject("validateAggregate: invalid aggregator signature")
|
||||||
"validateAggregate: invalid aggregator signature"))
|
|
||||||
of BatchResult.Timeout:
|
of BatchResult.Timeout:
|
||||||
beacon_aggregates_dropped_queue_full.inc()
|
beacon_aggregates_dropped_queue_full.inc()
|
||||||
return err((ValidationResult.Reject, cstring("validateAggregate: timeout checking aggregator signature")))
|
return err((ValidationResult.Reject, cstring("validateAggregate: timeout checking aggregator signature")))
|
||||||
|
@ -490,8 +491,7 @@ proc validateAggregate*(
|
||||||
var x = await cryptoFuts.aggregateCheck
|
var x = await cryptoFuts.aggregateCheck
|
||||||
case x
|
case x
|
||||||
of BatchResult.Invalid:
|
of BatchResult.Invalid:
|
||||||
return errReject(cstring(
|
return errReject("validateAggregate: invalid aggregate signature")
|
||||||
"validateAggregate: invalid aggregate signature"))
|
|
||||||
of BatchResult.Timeout:
|
of BatchResult.Timeout:
|
||||||
beacon_aggregates_dropped_queue_full.inc()
|
beacon_aggregates_dropped_queue_full.inc()
|
||||||
return err((ValidationResult.Reject, cstring("validateAggregate: timeout checking aggregate signature")))
|
return err((ValidationResult.Reject, cstring("validateAggregate: timeout checking aggregate signature")))
|
||||||
|
|
Loading…
Reference in New Issue