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

Utilize New SSZ Caching of Arrays of Roots in Beacon Node Runtime #3814

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_go_ssz",
commit = "7e767fb53d02ea220428a6cc0850ee6e17d71bb1",
commit = "29465a17dc86eab12f2dd392ef2aee63e80794f9",
importpath = "github.com/prysmaticlabs/go-ssz",
)

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go_library(
"//shared/version:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//types:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
sszTypes "github.com/prysmaticlabs/go-ssz/types"
"github.com/prysmaticlabs/prysm/beacon-chain/archiver"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
Expand Down Expand Up @@ -95,6 +96,11 @@ func NewBeaconNode(ctx *cli.Context) (*BeaconNode, error) {
}
}

// Enable the ssz hash tree root cache conditionally.
if featureconfig.Get().EnableSSZCache {
sszTypes.ToggleCache(true)
}

if err := beacon.startDB(ctx); err != nil {
return nil, err
}
Expand Down
23 changes: 14 additions & 9 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ type Flag struct {
PruneFinalizedStates bool // PruneFinalizedStates from the database.

// Cache toggles.
EnableAttestationCache bool // EnableAttestationCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableEth1DataVoteCache bool // EnableEth1DataVoteCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableNewCache bool // EnableNewCache enables the node to use the new caching scheme.
EnableBLSPubkeyCache bool // EnableBLSPubkeyCache to improve wall time of PubkeyFromBytes.
EnableShuffledIndexCache bool // EnableShuffledIndexCache to cache expensive shuffled index computation.
EnableSSZCache bool // EnableSSZCache for hash tree root.
EnableAttestationCache bool // EnableAttestationCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableEth1DataVoteCache bool // EnableEth1DataVoteCache; see https://github.com/prysmaticlabs/prysm/issues/3106.
EnableNewCache bool // EnableNewCache enables the node to use the new caching scheme.
EnableBLSPubkeyCache bool // EnableBLSPubkeyCache to improve wall time of PubkeyFromBytes.
EnableShuffledIndexCache bool // EnableShuffledIndexCache to cache expensive shuffled index computation.
EnableSkipSlotsCache bool // EnableSkipSlotsCache caches the state in skipped slots.
EnableCommitteeCache bool // EnableCommitteeCache to cache committee computation.
EnableActiveIndicesCache bool // EnableActiveIndicesCache.
EnableActiveCountCache bool // EnableActiveCountCache.
EnableCommitteeCache bool // EnableCommitteeCache to cache committee computation.
EnableActiveIndicesCache bool // EnableActiveIndicesCache.
EnableActiveCountCache bool // EnableActiveCountCache.
}

var featureConfig *Flag
Expand Down Expand Up @@ -100,7 +101,7 @@ func ConfigureBeaconChain(ctx *cli.Context) {
cfg.SkipBLSVerify = true
}
if ctx.GlobalBool(enableBackupWebhookFlag.Name) {
log.Warn("Allowing database backups to be triggered from HTTP webhook.")
log.Warn("Allowing database backups to be triggered from HTTP webhook")
cfg.EnableBackupWebhook = true
}
if ctx.GlobalBool(enableBLSPubkeyCacheFlag.Name) {
Expand All @@ -111,6 +112,10 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Processing epoch with optimizations")
cfg.OptimizeProcessEpoch = true
}
if ctx.GlobalBool(EnableSSZCacheFlag.Name) {
log.Warn("Enabled ssz hash tree root cache")
cfg.EnableSSZCache = true
}
if ctx.GlobalBool(Scatter.Name) {
log.Warn("Scattering sequential proceses to multiple cores")
cfg.Scatter = true
Expand Down
8 changes: 7 additions & 1 deletion shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ var (
Name: "optimize-process-epoch",
Usage: "Process epoch with optimizations",
}
// EnableSSZCacheFlag for hash tree root.
EnableSSZCacheFlag = cli.BoolFlag{
Name: "enable-ssz-cache",
Usage: "Enable ssz hash tree root caching",
}
// Scatter scatters sequential processes to multiple cores
Scatter = cli.BoolFlag{
Name: "scatter",
Expand All @@ -99,7 +104,7 @@ var (
Hidden: true,
}
deprecatedEnableFinalizedBlockRootIndexFlag = cli.BoolFlag{
Name: "enable-finalized-block-root-index",
Name: "enable-finalized-block-root-index",
Usage: deprecatedUsage,
Hidden: true,
}
Expand All @@ -126,6 +131,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
NewCacheFlag,
SkipBLSVerifyFlag,
OptimizeProcessEpoch,
EnableSSZCacheFlag,
Scatter,
enableBackupWebhookFlag,
enableBLSPubkeyCacheFlag,
Expand Down