mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
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:
parent
305d0299dd
commit
ad47817bcd
@ -4,12 +4,15 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"log.go",
|
"log.go",
|
||||||
|
"write_block_to_disk.go",
|
||||||
"write_state_to_disk.go",
|
"write_state_to_disk.go",
|
||||||
],
|
],
|
||||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop",
|
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop",
|
||||||
visibility = ["//beacon-chain:__subpackages__"],
|
visibility = ["//beacon-chain:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"//proto/beacon/p2p/v1:go_default_library",
|
"//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_prysmaticlabs_go_ssz//:go_default_library",
|
||||||
"@com_github_sirupsen_logrus//:go_default_library",
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
],
|
],
|
||||||
|
30
beacon-chain/core/state/interop/write_block_to_disk.go
Normal file
30
beacon-chain/core/state/interop/write_block_to_disk.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,14 @@ import (
|
|||||||
|
|
||||||
"github.com/prysmaticlabs/go-ssz"
|
"github.com/prysmaticlabs/go-ssz"
|
||||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
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!
|
// WriteStateToDisk as a state ssz. Writes to temp directory. Debug!
|
||||||
func WriteStateToDisk(state *pb.BeaconState) {
|
func WriteStateToDisk(state *pb.BeaconState) {
|
||||||
|
if !featureconfig.FeatureConfig().WriteSSZStateTransitions {
|
||||||
|
return
|
||||||
|
}
|
||||||
fp := path.Join(os.TempDir(), fmt.Sprintf("beacon_state_%d.ssz", state.Slot))
|
fp := path.Join(os.TempDir(), fmt.Sprintf("beacon_state_%d.ssz", state.Slot))
|
||||||
log.Warnf("Writing state to disk at %s", fp)
|
log.Warnf("Writing state to disk at %s", fp)
|
||||||
enc, err := ssz.Marshal(state)
|
enc, err := ssz.Marshal(state)
|
||||||
|
@ -63,6 +63,7 @@ func ExecuteStateTransition(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interop.WriteBlockToDisk(block)
|
||||||
interop.WriteStateToDisk(state)
|
interop.WriteStateToDisk(state)
|
||||||
|
|
||||||
postStateRoot, err := ssz.HashTreeRoot(state)
|
postStateRoot, err := ssz.HashTreeRoot(state)
|
||||||
|
@ -27,6 +27,7 @@ var log = logrus.WithField("prefix", "flags")
|
|||||||
type FeatureFlagConfig struct {
|
type FeatureFlagConfig struct {
|
||||||
NoGenesisDelay bool // NoGenesisDelay when processing a chain start genesis event.
|
NoGenesisDelay bool // NoGenesisDelay when processing a chain start genesis event.
|
||||||
DemoConfig bool // DemoConfig with lower deposit thresholds.
|
DemoConfig bool // DemoConfig with lower deposit thresholds.
|
||||||
|
WriteSSZStateTransitions bool // WriteSSZStateTransitions to tmp directory.
|
||||||
|
|
||||||
// Cache toggles.
|
// Cache toggles.
|
||||||
EnableActiveBalanceCache bool // EnableActiveBalanceCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
|
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.")
|
log.Warn("Using non standard genesis delay. This may cause problems in a multi-node environment.")
|
||||||
cfg.NoGenesisDelay = true
|
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) {
|
if ctx.GlobalBool(EnableActiveBalanceCacheFlag.Name) {
|
||||||
log.Warn("Enabled unsafe active balance cache")
|
log.Warn("Enabled unsafe active balance cache")
|
||||||
cfg.EnableActiveBalanceCache = true
|
cfg.EnableActiveBalanceCache = true
|
||||||
|
@ -15,6 +15,10 @@ var (
|
|||||||
Name: "demo-config",
|
Name: "demo-config",
|
||||||
Usage: "Use demo config with lower deposit thresholds.",
|
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 see https://github.com/prysmaticlabs/prysm/issues/3106.
|
||||||
EnableActiveBalanceCacheFlag = cli.BoolFlag{
|
EnableActiveBalanceCacheFlag = cli.BoolFlag{
|
||||||
Name: "enable-active-balance-cache",
|
Name: "enable-active-balance-cache",
|
||||||
@ -61,6 +65,7 @@ var ValidatorFlags = []cli.Flag{
|
|||||||
var BeaconChainFlags = []cli.Flag{
|
var BeaconChainFlags = []cli.Flag{
|
||||||
NoGenesisDelayFlag,
|
NoGenesisDelayFlag,
|
||||||
DemoConfigFlag,
|
DemoConfigFlag,
|
||||||
|
writeSSZStateTransitionsFlag,
|
||||||
EnableActiveBalanceCacheFlag,
|
EnableActiveBalanceCacheFlag,
|
||||||
EnableAttestationCacheFlag,
|
EnableAttestationCacheFlag,
|
||||||
EnableAncestorBlockCacheFlag,
|
EnableAncestorBlockCacheFlag,
|
||||||
|
Loading…
Reference in New Issue
Block a user