Compare commits

...

1 Commits

Author SHA1 Message Date
terence tsao
503c1ca465 Dont gen attestation pre state 2025-12-03 20:15:35 -08:00
5 changed files with 25 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/transition"
forkchoicetypes "github.com/OffchainLabs/prysm/v7/beacon-chain/forkchoice/types"
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
"github.com/OffchainLabs/prysm/v7/config/features"
"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
@@ -19,6 +20,8 @@ import (
"github.com/sirupsen/logrus"
)
var ErrStopAttestationStateGen = errors.New("stopped attestation state generation")
// The caller of this function must have a lock on forkchoice.
func (s *Service) getRecentPreState(ctx context.Context, c *ethpb.Checkpoint) state.ReadOnlyBeaconState {
headEpoch := slots.ToEpoch(s.HeadSlot())
@@ -59,7 +62,7 @@ func (s *Service) getRecentPreState(ctx context.Context, c *ethpb.Checkpoint) st
if err != nil {
return nil
}
// Try if we have already set the checkpoint cache. This will be tried again if we fail here but the check is cheap anyway.
epochKey := strconv.FormatUint(uint64(c.Epoch), 10 /* base 10 */)
lock := async.NewMultilock(string(c.Root) + epochKey)
lock.Lock()
@@ -135,6 +138,10 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (stat
return nil, errors.Wrap(ErrNotCheckpoint, fmt.Sprintf("epoch %d root %#x", c.Epoch, c.Root))
}
if features.Get().DisableAttestationStateGen {
return nil, ErrStopAttestationStateGen
}
// Fallback to state regeneration.
log.WithFields(logrus.Fields{"epoch": c.Epoch, "root": fmt.Sprintf("%#x", c.Root)}).Debug("Regenerating attestation pre-state")
baseState, err := s.cfg.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(c.Root))

View File

@@ -173,6 +173,9 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed ethpb.Signed
bs, err := s.cfg.chain.AttestationTargetState(ctx, data.Target)
if err != nil {
if errors.Is(err, blockchain.ErrStopAttestationStateGen) {
return pubsub.ValidationIgnore, errors.New("ignored attestation, state generation is disabled")
}
tracing.AnnotateError(span, err)
return pubsub.ValidationIgnore, err
}

View File

@@ -138,6 +138,9 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(
preState, err := s.cfg.chain.AttestationTargetState(ctx, data.Target)
if err != nil {
if errors.Is(err, blockchain.ErrStopAttestationStateGen) {
return pubsub.ValidationIgnore, errors.New("ignored attestation, state generation is disabled")
}
tracing.AnnotateError(span, err)
return pubsub.ValidationIgnore, err
}

View File

@@ -72,6 +72,7 @@ type Flags struct {
DisableResourceManager bool // Disables running the node with libp2p's resource manager.
DisableStakinContractCheck bool // Disables check for deposit contract when proposing blocks
DisableLastEpochTargets bool // Disables processing of states for attestations to old blocks.
DisableAttestationStateGen bool // Disables generating attestation pre-states from the head state path.
EnableVerboseSigVerification bool // EnableVerboseSigVerification specifies whether to verify individual signature if batch verification fails
@@ -285,6 +286,10 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
logEnabled(disableLastEpochTargets)
cfg.DisableLastEpochTargets = true
}
if ctx.IsSet(disableAttestationStateGen.Name) {
logEnabled(disableAttestationStateGen)
cfg.DisableAttestationStateGen = true
}
if ctx.IsSet(EnableStateDiff.Name) {
logEnabled(EnableStateDiff)

View File

@@ -206,6 +206,11 @@ var (
Name: "disable-last-epoch-targets",
Usage: "Disables processing of last epoch targets.",
}
// disableAttestationStateGen is a flag to skip generating attestation states from the head state path.
disableAttestationStateGen = &cli.BoolFlag{
Name: "disable-attestation-state-gen",
Usage: "Skips generating attestation pre-states from the head state when handling attestations.",
}
)
// devModeFlags holds list of flags that are set when development mode is on.
@@ -267,6 +272,7 @@ var BeaconChainFlags = combinedFlags([]cli.Flag{
forceHeadFlag,
blacklistRoots,
disableLastEpochTargets,
disableAttestationStateGen,
}, deprecatedBeaconFlags, deprecatedFlags, upcomingDeprecation)
func combinedFlags(flags ...[]cli.Flag) []cli.Flag {