Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save invalid block to temp save-invalid-block-temp #13722

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beacon-chain/sync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ go_library(
"//crypto/rand:go_default_library",
"//encoding/bytesutil:go_default_library",
"//encoding/ssz/equality:go_default_library",
"//io/file:go_default_library",
"//monitoring/tracing:go_default_library",
"//network/forks:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
Expand Down
27 changes: 27 additions & 0 deletions beacon-chain/sync/subscriber_beacon_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ package sync

import (
"context"
"fmt"
"os"
"path"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition/interop"
"github.com/prysmaticlabs/prysm/v5/config/features"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/io/file"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -33,7 +39,10 @@ func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message)
if r != [32]byte{} {
s.setBadBlock(ctx, r) // Setting head block as bad.
} else {
// TODO(13721): Remove this once we can deprecate the flag.
interop.WriteBlockToDisk(signed, true /*failed*/)

saveInvalidBlockToTemp(signed)
s.setBadBlock(ctx, root)
}
}
Expand All @@ -45,3 +54,21 @@ func (s *Service) beaconBlockSubscriber(ctx context.Context, msg proto.Message)
}
return err
}

// WriteInvalidBlockToDisk as a block ssz. Writes to temp directory.
func saveInvalidBlockToTemp(block interfaces.ReadOnlySignedBeaconBlock) {
if !features.Get().SaveInvalidBlock {
return
}
filename := fmt.Sprintf("beacon_block_%d.ssz", block.Block().Slot())
fp := path.Join(os.TempDir(), filename)
log.Warnf("Writing invalid block to disk at %s", fp)
enc, err := block.MarshalSSZ()
if err != nil {
log.WithError(err).Error("Failed to ssz encode block")
return
}
if err := file.WriteFile(fp, enc); err != nil {
log.WithError(err).Error("Failed to write to disk")
}
}
8 changes: 8 additions & 0 deletions config/features/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type Flags struct {
PrepareAllPayloads bool // PrepareAllPayloads informs the engine to prepare a block on every slot.
// BlobSaveFsync requires blob saving to block on fsync to ensure blobs are durably persisted before passing DA.
BlobSaveFsync bool

SaveInvalidBlock bool // SaveInvalidBlock saves invalid block to temp.

// KeystoreImportDebounceInterval specifies the time duration the validator waits to reload new keys if they have
// changed on disk. This feature is for advanced use cases only.
KeystoreImportDebounceInterval time.Duration
Expand Down Expand Up @@ -187,6 +190,11 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
cfg.WriteSSZStateTransitions = true
}

if ctx.Bool(saveInvalidBlockTempFlag.Name) {
logEnabled(saveInvalidBlockTempFlag)
cfg.SaveInvalidBlock = true
}

if ctx.IsSet(disableGRPCConnectionLogging.Name) {
logDisabled(disableGRPCConnectionLogging)
cfg.DisableGRPCConnectionLogs = true
Expand Down
5 changes: 5 additions & 0 deletions config/features/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ var (
Name: "interop-write-ssz-state-transitions",
Usage: "Writes SSZ states to disk after attempted state transitio.",
}
saveInvalidBlockTempFlag = &cli.BoolFlag{
Name: "save-invalid-block-temp",
Usage: "Writes invalid blocks to temp directory.",
}
disableGRPCConnectionLogging = &cli.BoolFlag{
Name: "disable-grpc-connection-logging",
Usage: "Disables displaying logs for newly connected grpc clients.",
Expand Down Expand Up @@ -196,6 +200,7 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c
devModeFlag,
enableExperimentalState,
writeSSZStateTransitionsFlag,
saveInvalidBlockTempFlag,
disableGRPCConnectionLogging,
HoleskyTestnet,
PraterTestnet,
Expand Down
Loading