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

Add mempool feature flag #4903

Merged
merged 1 commit into from Feb 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions shared/featureconfig/config.go
Expand Up @@ -42,6 +42,7 @@ type Flags struct {
ProtectAttester bool // ProtectAttester prevents the validator client from signing any attestations that would be considered a slashable offense.
DisableStrictAttestationPubsubVerification bool // DisableStrictAttestationPubsubVerification will disabling strict signature verification in pubsub.
DisableUpdateHeadPerAttestation bool // DisableUpdateHeadPerAttestation will disabling update head on per attestation basis.
EnableByteMempool bool // EnaableByteMempool memory management.

// DisableForkChoice disables using LMD-GHOST fork choice to update
// the head of the chain based on attestations and instead accepts any valid received block
Expand Down Expand Up @@ -143,6 +144,10 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Disabled update head on per attestation basis")
cfg.DisableUpdateHeadPerAttestation = true
}
if ctx.GlobalBool(enableByteMempool.Name) {
log.Warn("Enabling experimental memory management for beacon state")
cfg.EnableByteMempool = true
}

Init(cfg)
}
Expand Down
6 changes: 6 additions & 0 deletions shared/featureconfig/flags.go
Expand Up @@ -94,6 +94,10 @@ var (
Name: "disable-update-head-attestation",
Usage: "Disable update fork choice head on per attestation. See PR 4802 for details.",
}
enableByteMempool = cli.BoolFlag{
Name: "enable-byte-mempool",
Usage: "Enable use of sync.Pool for certain byte arrays in the beacon state",
}
)

// Deprecated flags list.
Expand Down Expand Up @@ -257,6 +261,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
cacheFilteredBlockTreeFlag,
disableStrictAttestationPubsubVerificationFlag,
disableUpdateHeadPerAttestation,
enableByteMempool,
}...)

// E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E.
Expand All @@ -268,4 +273,5 @@ var E2EBeaconChainFlags = []string{
"--enable-eth1-data-vote-cache",
"--initial-sync-cache-state",
"--proto-array-forkchoice",
"--enable-byte-mempool",
}
1 change: 1 addition & 0 deletions shared/memorypool/BUILD.bazel
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = ["memorypool.go"],
importpath = "github.com/prysmaticlabs/prysm/shared/memorypool",
visibility = ["//visibility:public"],
deps = ["//shared/featureconfig:go_default_library"],
)

go_test(
Expand Down
14 changes: 12 additions & 2 deletions shared/memorypool/memorypool.go
@@ -1,6 +1,10 @@
package memorypool

import "sync"
import (
"sync"

"github.com/prysmaticlabs/prysm/shared/featureconfig"
)

// DoubleByteSlicePool represents the memory pool
// for 2d byte slices.
Expand All @@ -9,6 +13,10 @@ var DoubleByteSlicePool = new(sync.Pool)
// GetDoubleByteSlice retrieves the 2d byte slice of
// the desired size from the memory pool.
func GetDoubleByteSlice(size int) [][]byte {
if !featureconfig.Get().EnableByteMempool {
return make([][]byte, size)
}

rawObj := DoubleByteSlicePool.Get()
if rawObj == nil {
return make([][]byte, size)
Expand All @@ -23,5 +31,7 @@ func GetDoubleByteSlice(size int) [][]byte {
// PutDoubleByteSlice places the provided 2d byte slice
// in the memory pool.
func PutDoubleByteSlice(data [][]byte) {
DoubleByteSlicePool.Put(data)
if featureconfig.Get().EnableByteMempool {
DoubleByteSlicePool.Put(data)
}
}