Skip to content

Commit

Permalink
Save invalid blob to temp under new flag
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Mar 12, 2024
1 parent 02cbcf8 commit 889a5db
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
23 changes: 23 additions & 0 deletions beacon-chain/sync/validate_blob.go
Expand Up @@ -3,17 +3,21 @@ package sync
import (
"context"
"fmt"
"os"
"path"
"strings"

pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/verification"
"github.com/prysmaticlabs/prysm/v5/config/features"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/rand"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/io/file"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
prysmTime "github.com/prysmaticlabs/prysm/v5/time"
"github.com/prysmaticlabs/prysm/v5/time/slots"
Expand Down Expand Up @@ -109,6 +113,7 @@ func (s *Service) validateBlob(ctx context.Context, pid peer.ID, msg *pubsub.Mes
}

if err := vf.SidecarKzgProofVerified(); err != nil {
saveInvalidBlobToTemp(blob)
return pubsub.ValidationReject, err
}

Expand Down Expand Up @@ -165,3 +170,21 @@ func blobFields(b blocks.ROBlob) logrus.Fields {
func computeSubnetForBlobSidecar(index uint64) uint64 {
return index % params.BeaconConfig().BlobsidecarSubnetCount
}

// saveInvalidBlobToTemp as a block ssz. Writes to temp directory.
func saveInvalidBlobToTemp(b blocks.ROBlob) {
if !features.Get().SaveInvalidBlob {
return
}
filename := fmt.Sprintf("blob_sidecar_%d.ssz", b.Slot())
fp := path.Join(os.TempDir(), filename)
log.Warnf("Writing invalid blob sidecar to disk at %s", fp)
enc, err := b.MarshalSSZ()
if err != nil {
log.WithError(err).Error("Failed to ssz encode blob sidecar")
return
}
if err := file.WriteFile(fp, enc); err != nil {
log.WithError(err).Error("Failed to write to disk")
}
}
6 changes: 6 additions & 0 deletions config/features/config.go
Expand Up @@ -74,6 +74,7 @@ type Flags struct {
BlobSaveFsync bool

SaveInvalidBlock bool // SaveInvalidBlock saves invalid block to temp.
SaveInvalidBlob bool // SaveInvalidBlob saves invalid blob 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.
Expand Down Expand Up @@ -195,6 +196,11 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
cfg.SaveInvalidBlock = true
}

if ctx.Bool(saveInvalidBlobTempFlag.Name) {
logEnabled(saveInvalidBlobTempFlag)
cfg.SaveInvalidBlob = true
}

if ctx.IsSet(disableGRPCConnectionLogging.Name) {
logDisabled(disableGRPCConnectionLogging)
cfg.DisableGRPCConnectionLogs = true
Expand Down
5 changes: 5 additions & 0 deletions config/features/flags.go
Expand Up @@ -46,6 +46,10 @@ var (
Name: "save-invalid-block-temp",
Usage: "Writes invalid blocks to temp directory.",
}
saveInvalidBlobTempFlag = &cli.BoolFlag{
Name: "save-invalid-blob-temp",
Usage: "Writes invalid blobs to temp directory.",
}
disableGRPCConnectionLogging = &cli.BoolFlag{
Name: "disable-grpc-connection-logging",
Usage: "Disables displaying logs for newly connected grpc clients.",
Expand Down Expand Up @@ -201,6 +205,7 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c
enableExperimentalState,
writeSSZStateTransitionsFlag,
saveInvalidBlockTempFlag,
saveInvalidBlobTempFlag,
disableGRPCConnectionLogging,
HoleskyTestnet,
PraterTestnet,
Expand Down

0 comments on commit 889a5db

Please sign in to comment.