also pack attestations where LMD vote is orphaned (#5002)

* also pack attestations where LMD vote is orphaned

When `attestation.data.beacon_block_root` gets orphaned, attestations
with a good `attestation.data.target.root` may still be valuable.
The LMD GHOST vote is not relevant for attestation rewards.

Switch to use the FFG vote (`attestation.data.target.root`) instead,
gossip validation ensures it is an ancestor of `beacon_block_root`.

* lint
This commit is contained in:
Etan Kissling 2023-06-04 12:39:12 +02:00 committed by GitHub
parent f86febc111
commit 12381d5f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 19 deletions

View File

@ -537,26 +537,21 @@ func score(
proc check_attestation_compatible*( proc check_attestation_compatible*(
dag: ChainDAGRef, dag: ChainDAGRef,
state: ForkyBeaconState, state: ForkyHashedBeaconState,
attestation: SomeAttestation): Result[void, cstring] = attestation: SomeAttestation): Result[void, cstring] =
let targetEpoch = attestation.data.target.epoch
if targetEpoch <= MIN_SEED_LOOKAHEAD:
return ok()
let let
attestedBlck = targetEpoch = attestation.data.target.epoch
dag.getBlockRef(attestation.data.beacon_block_root).valueOr: compatibleRoot = state.dependent_root(targetEpoch.get_previous_epoch)
return err("Unknown `beacon_block_root`")
dependentSlot = (targetEpoch - MIN_SEED_LOOKAHEAD).start_slot - 1 attestedBlck = dag.getBlockRef(attestation.data.target.root).valueOr:
return err("Unknown `target.root`")
dependentSlot = targetEpoch.attester_dependent_slot
dependentBid = dag.atSlot(attestedBlck.bid, dependentSlot).valueOr: dependentBid = dag.atSlot(attestedBlck.bid, dependentSlot).valueOr:
return err("Dependent root not found") return err("Dependent root not found")
dependentRoot = dependentBid.bid.root dependentRoot = dependentBid.bid.root
compatibleRoot = state.get_block_root_at_slot(dependentSlot)
if dependentRoot != compatibleRoot: if dependentRoot != compatibleRoot:
return err("Incompatible shuffling") return err("Incompatible shuffling")
ok() ok()
proc getAttestationsForBlock*(pool: var AttestationPool, proc getAttestationsForBlock*(pool: var AttestationPool,
@ -610,8 +605,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
# Filter out attestations that were created with a different shuffling. # Filter out attestations that were created with a different shuffling.
# As we don't re-check signatures, this needs to be done separately # As we don't re-check signatures, this needs to be done separately
if not check_attestation_compatible( if not pool.dag.check_attestation_compatible(state, attestation).isOk():
pool.dag, state.data, attestation).isOk():
continue continue
# Attestations are checked based on the state that we're adding the # Attestations are checked based on the state that we're adding the

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018-2022 Status Research & Development GmbH # Copyright (c) 2018-2023 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -164,12 +164,12 @@ suite "Attestation pool processing" & preset():
# An additional compatibility check catches that (used in block production) # An additional compatibility check catches that (used in block production)
withState(state[]): withState(state[]):
check: check:
check_attestation_compatible(dag, forkyState.data, att1).isOk check_attestation_compatible(dag, forkyState, att1).isOk
check_attestation_compatible(dag, forkyState.data, att2).isErr check_attestation_compatible(dag, forkyState, att2).isErr
withState(state2[]): withState(state2[]):
check: check:
check_attestation_compatible(dag, forkyState.data, att1).isErr check_attestation_compatible(dag, forkyState, att1).isErr
check_attestation_compatible(dag, forkyState.data, att2).isOk check_attestation_compatible(dag, forkyState, att2).isOk
test "Can add and retrieve simple attestations" & preset(): test "Can add and retrieve simple attestations" & preset():
let let