Only write interop ssz states to disk with flag ON (#3566)

* only write SSZ states to disk with flag on

* lint

* also write blocks
This commit is contained in:
Preston Van Loon 2019-09-23 16:36:12 -07:00 committed by Raul Jordan
parent 305d0299dd
commit ad47817bcd
6 changed files with 48 additions and 0 deletions

View File

@ -4,12 +4,15 @@ go_library(
name = "go_default_library",
srcs = [
"log.go",
"write_block_to_disk.go",
"write_state_to_disk.go",
],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/featureconfig:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],

View File

@ -0,0 +1,30 @@
package interop
import (
"fmt"
"io/ioutil"
"os"
"path"
"github.com/prysmaticlabs/go-ssz"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
// WriteBlockToDisk as a block ssz. Writes to temp directory. Debug!
func WriteBlockToDisk(block *ethpb.BeaconBlock) {
if !featureconfig.FeatureConfig().WriteSSZStateTransitions {
return
}
fp := path.Join(os.TempDir(), fmt.Sprintf("beacon_block_%d.ssz", block.Slot))
log.Warnf("Writing block to disk at %s", fp)
enc, err := ssz.Marshal(block)
if err != nil {
log.WithError(err).Error("Failed to ssz encode block")
return
}
if err := ioutil.WriteFile(fp, enc, 0664); err != nil {
log.WithError(err).Error("Failed to write to disk")
}
}

View File

@ -8,10 +8,14 @@ import (
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
// WriteStateToDisk as a state ssz. Writes to temp directory. Debug!
func WriteStateToDisk(state *pb.BeaconState) {
if !featureconfig.FeatureConfig().WriteSSZStateTransitions {
return
}
fp := path.Join(os.TempDir(), fmt.Sprintf("beacon_state_%d.ssz", state.Slot))
log.Warnf("Writing state to disk at %s", fp)
enc, err := ssz.Marshal(state)

View File

@ -63,6 +63,7 @@ func ExecuteStateTransition(
}
}
interop.WriteBlockToDisk(block)
interop.WriteStateToDisk(state)
postStateRoot, err := ssz.HashTreeRoot(state)

View File

@ -27,6 +27,7 @@ var log = logrus.WithField("prefix", "flags")
type FeatureFlagConfig struct {
NoGenesisDelay bool // NoGenesisDelay when processing a chain start genesis event.
DemoConfig bool // DemoConfig with lower deposit thresholds.
WriteSSZStateTransitions bool // WriteSSZStateTransitions to tmp directory.
// Cache toggles.
EnableActiveBalanceCache bool // EnableActiveBalanceCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
@ -65,6 +66,10 @@ func ConfigureBeaconFeatures(ctx *cli.Context) {
log.Warn("Using non standard genesis delay. This may cause problems in a multi-node environment.")
cfg.NoGenesisDelay = true
}
if ctx.GlobalBool(writeSSZStateTransitionsFlag.Name) {
log.Warn("Writing SSZ states and blocks after state transitions")
cfg.WriteSSZStateTransitions = true
}
if ctx.GlobalBool(EnableActiveBalanceCacheFlag.Name) {
log.Warn("Enabled unsafe active balance cache")
cfg.EnableActiveBalanceCache = true

View File

@ -15,6 +15,10 @@ var (
Name: "demo-config",
Usage: "Use demo config with lower deposit thresholds.",
}
writeSSZStateTransitionsFlag = cli.BoolFlag {
Name: "interop-write-ssz-state-transitions",
Usage: "Write ssz states to disk after attempted state transition",
}
// EnableActiveBalanceCacheFlag see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableActiveBalanceCacheFlag = cli.BoolFlag{
Name: "enable-active-balance-cache",
@ -61,6 +65,7 @@ var ValidatorFlags = []cli.Flag{
var BeaconChainFlags = []cli.Flag{
NoGenesisDelayFlag,
DemoConfigFlag,
writeSSZStateTransitionsFlag,
EnableActiveBalanceCacheFlag,
EnableAttestationCacheFlag,
EnableAncestorBlockCacheFlag,