diff --git a/beacon-chain/state/BUILD.bazel b/beacon-chain/state/BUILD.bazel index 7904ab7923f..f3c12a45e82 100644 --- a/beacon-chain/state/BUILD.bazel +++ b/beacon-chain/state/BUILD.bazel @@ -27,7 +27,6 @@ go_library( "//shared/bytesutil:go_default_library", "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", - "//shared/memorypool:go_default_library", "//shared/params:go_default_library", "//shared/sliceutil:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", diff --git a/beacon-chain/state/field_trie.go b/beacon-chain/state/field_trie.go index d442d011b9d..1890c7c1d51 100644 --- a/beacon-chain/state/field_trie.go +++ b/beacon-chain/state/field_trie.go @@ -10,7 +10,6 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/memorypool" ) // FieldTrie is the representation of the representative @@ -109,17 +108,7 @@ func (f *FieldTrie) CopyTrie() *FieldTrie { Mutex: new(sync.Mutex), } } - dstFieldTrie := [][]*[32]byte{} - switch f.field { - case randaoMixes: - dstFieldTrie = memorypool.GetRandaoMixesTrie(len(f.fieldLayers)) - case blockRoots, stateRoots: - dstFieldTrie = memorypool.GetRootsTrie(len(f.fieldLayers)) - case validators: - dstFieldTrie = memorypool.GetValidatorsTrie(len(f.fieldLayers)) - default: - dstFieldTrie = make([][]*[32]byte, len(f.fieldLayers)) - } + dstFieldTrie := make([][]*[32]byte, len(f.fieldLayers)) for i, layer := range f.fieldLayers { if len(dstFieldTrie[i]) < len(layer) { diff --git a/beacon-chain/state/getters.go b/beacon-chain/state/getters.go index 3b45b940a42..f36a21ab2cb 100644 --- a/beacon-chain/state/getters.go +++ b/beacon-chain/state/getters.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/go-bitfield" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" - "github.com/prysmaticlabs/prysm/shared/memorypool" "github.com/prysmaticlabs/prysm/shared/params" ) @@ -579,7 +578,7 @@ func (b *BeaconState) RandaoMixes() [][]byte { b.lock.RLock() defer b.lock.RUnlock() - mixes := memorypool.GetDoubleByteSlice(len(b.state.RandaoMixes)) + mixes := make([][]byte, len(b.state.RandaoMixes)) for i, r := range b.state.RandaoMixes { tmpRt := make([]byte, len(r)) copy(tmpRt, r) diff --git a/beacon-chain/state/setters.go b/beacon-chain/state/setters.go index 88d8c44da17..52ad7f94d78 100644 --- a/beacon-chain/state/setters.go +++ b/beacon-chain/state/setters.go @@ -11,7 +11,6 @@ import ( pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/memorypool" ) // SetGenesisTime for the beacon state. @@ -456,7 +455,7 @@ func (b *BeaconState) UpdateRandaoMixesAtIndex(idx uint64, val []byte) error { mixes := b.state.RandaoMixes if refs := b.sharedFieldReferences[randaoMixes].refs; refs > 1 { if featureconfig.Get().EnableStateRefCopy { - mixes = memorypool.GetDoubleByteSlice(len(b.state.RandaoMixes)) + mixes = make([][]byte, len(b.state.RandaoMixes)) copy(mixes, b.state.RandaoMixes) } else { mixes = b.RandaoMixes() diff --git a/beacon-chain/state/state_trie.go b/beacon-chain/state/state_trie.go index eed0cf81b1b..1f5b975dd83 100644 --- a/beacon-chain/state/state_trie.go +++ b/beacon-chain/state/state_trie.go @@ -14,7 +14,6 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/memorypool" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/sliceutil" "go.opencensus.io/trace" @@ -162,18 +161,6 @@ func (b *BeaconState) Copy() *BeaconState { if b.stateFieldLeaves[field].reference != nil { b.stateFieldLeaves[field].MinusRef() } - if field == randaoMixes && v.refs == 0 { - memorypool.PutDoubleByteSlice(b.state.RandaoMixes) - if b.stateFieldLeaves[field].refs == 0 { - memorypool.PutRandaoMixesTrie(b.stateFieldLeaves[randaoMixes].fieldLayers) - } - } - if (field == blockRoots || field == stateRoots) && v.refs == 0 && b.stateFieldLeaves[field].refs == 0 { - memorypool.PutRootsTrie(b.stateFieldLeaves[field].fieldLayers) - } - if field == validators && v.refs == 0 && b.stateFieldLeaves[field].refs == 0 { - memorypool.PutValidatorsTrie(b.stateFieldLeaves[validators].fieldLayers) - } } }) diff --git a/shared/featureconfig/config.go b/shared/featureconfig/config.go index 4a2ba6af72c..bd99b6a0af0 100644 --- a/shared/featureconfig/config.go +++ b/shared/featureconfig/config.go @@ -42,7 +42,6 @@ type Flags struct { SlasherProtection bool // SlasherProtection protects validator fron sending over a slashable offense over the network using external slasher. 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. EnableDomainDataCache bool // EnableDomainDataCache caches validator calls to DomainData per epoch. EnableStateGenSigVerify bool // EnableStateGenSigVerify verifies proposer and randao signatures during state gen. CheckHeadState bool // CheckHeadState checks the current headstate before retrieving the desired state from the db. @@ -166,10 +165,6 @@ func ConfigureBeaconChain(ctx *cli.Context) { log.Warn("Disabled update head on per attestation basis") cfg.DisableUpdateHeadPerAttestation = true } - if ctx.Bool(enableByteMempool.Name) { - log.Warn("Enabling experimental memory management for beacon state") - cfg.EnableByteMempool = true - } if ctx.Bool(enableStateGenSigVerify.Name) { log.Warn("Enabling sig verify for state gen") cfg.EnableStateGenSigVerify = true diff --git a/shared/featureconfig/flags.go b/shared/featureconfig/flags.go index 6afe686eff9..58378fab3df 100644 --- a/shared/featureconfig/flags.go +++ b/shared/featureconfig/flags.go @@ -93,10 +93,6 @@ 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", - } disableDomainDataCacheFlag = &cli.BoolFlag{ Name: "disable-domain-data-cache", Usage: "Disable caching of domain data requests per epoch. This feature reduces the total " + @@ -356,6 +352,11 @@ var ( Usage: deprecatedUsage, Hidden: true, } + deprecatedEnableByteMempool = &cli.BoolFlag{ + Name: "enable-byte-mempool", + Usage: deprecatedUsage, + Hidden: true, + } ) var deprecatedFlags = []cli.Flag{ @@ -396,6 +397,7 @@ var deprecatedFlags = []cli.Flag{ deprecatedEnableEth1DataVoteCacheFlag, deprecatedAccountMetricsFlag, deprecatedEnableDomainDataCacheFlag, + deprecatedEnableByteMempool, } // ValidatorFlags contains a list of all the feature flags that apply to the validator client. @@ -438,7 +440,6 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{ cacheFilteredBlockTreeFlag, disableStrictAttestationPubsubVerificationFlag, disableUpdateHeadPerAttestation, - enableByteMempool, enableStateGenSigVerify, checkHeadState, enableNoiseHandshake, diff --git a/shared/memorypool/BUILD.bazel b/shared/memorypool/BUILD.bazel deleted file mode 100644 index 3a8cba99888..00000000000 --- a/shared/memorypool/BUILD.bazel +++ /dev/null @@ -1,16 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") -load("@io_bazel_rules_go//go:def.bzl", "go_test") - -go_library( - name = "go_default_library", - srcs = ["memorypool.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/memorypool", - visibility = ["//visibility:public"], - deps = ["//shared/featureconfig:go_default_library"], -) - -go_test( - name = "go_default_test", - srcs = ["memorypool_test.go"], - embed = [":go_default_library"], -) diff --git a/shared/memorypool/memorypool.go b/shared/memorypool/memorypool.go deleted file mode 100644 index 5539c36787e..00000000000 --- a/shared/memorypool/memorypool.go +++ /dev/null @@ -1,140 +0,0 @@ -// Package memorypool includes useful tools for creating common -// data structures in eth2 with optimal memory allocation. -package memorypool - -import ( - "sync" - - "github.com/prysmaticlabs/prysm/shared/featureconfig" -) - -// DoubleByteSlicePool represents the memory pool -// for 2d byte slices. -var DoubleByteSlicePool = new(sync.Pool) - -// RootsMemoryPool represents the memory pool -// for state roots/block roots trie. -var RootsMemoryPool = new(sync.Pool) - -// RandaoMixesMemoryPool represents the memory pool -// for randao mixes trie. -var RandaoMixesMemoryPool = new(sync.Pool) - -// ValidatorsMemoryPool represents the memory pool -// for 3d byte slices. -var ValidatorsMemoryPool = 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) - } - byteSlice, ok := rawObj.([][]byte) - if !ok { - return nil - } - if len(byteSlice) >= size { - return byteSlice[:size] - } - return append(byteSlice, make([][]byte, size-len(byteSlice))...) -} - -// PutDoubleByteSlice places the provided 2d byte slice -// in the memory pool. -func PutDoubleByteSlice(data [][]byte) { - if featureconfig.Get().EnableByteMempool { - DoubleByteSlicePool.Put(data) - } -} - -// GetRootsTrie retrieves the 3d byte trie of -// the desired size from the memory pool. -func GetRootsTrie(size int) [][]*[32]byte { - if !featureconfig.Get().EnableByteMempool { - return make([][]*[32]byte, size) - } - - rawObj := RootsMemoryPool.Get() - if rawObj == nil { - return make([][]*[32]byte, size) - } - byteSlice, ok := rawObj.([][]*[32]byte) - if !ok { - return nil - } - if len(byteSlice) >= size { - return byteSlice[:size] - } - return append(byteSlice, make([][]*[32]byte, size-len(byteSlice))...) -} - -// PutRootsTrie places the provided 3d byte trie -// in the memory pool. -func PutRootsTrie(data [][]*[32]byte) { - if featureconfig.Get().EnableByteMempool { - RootsMemoryPool.Put(data) - } -} - -// GetRandaoMixesTrie retrieves the 3d byte slice of -// the desired size from the memory pool. -func GetRandaoMixesTrie(size int) [][]*[32]byte { - if !featureconfig.Get().EnableByteMempool { - return make([][]*[32]byte, size) - } - - rawObj := RandaoMixesMemoryPool.Get() - if rawObj == nil { - return make([][]*[32]byte, size) - } - byteSlice, ok := rawObj.([][]*[32]byte) - if !ok { - return nil - } - if len(byteSlice) >= size { - return byteSlice[:size] - } - return append(byteSlice, make([][]*[32]byte, size-len(byteSlice))...) -} - -// PutRandaoMixesTrie places the provided 3d byte slice -// in the memory pool. -func PutRandaoMixesTrie(data [][]*[32]byte) { - if featureconfig.Get().EnableByteMempool { - RandaoMixesMemoryPool.Put(data) - } -} - -// GetValidatorsTrie retrieves the 3d byte slice of -// the desired size from the memory pool. -func GetValidatorsTrie(size int) [][]*[32]byte { - if !featureconfig.Get().EnableByteMempool { - return make([][]*[32]byte, size) - } - rawObj := ValidatorsMemoryPool.Get() - if rawObj == nil { - return make([][]*[32]byte, size) - } - byteSlice, ok := rawObj.([][]*[32]byte) - if !ok { - return nil - } - if len(byteSlice) >= size { - return byteSlice[:size] - } - return append(byteSlice, make([][]*[32]byte, size-len(byteSlice))...) -} - -// PutValidatorsTrie places the provided 3d byte slice -// in the memory pool. -func PutValidatorsTrie(data [][]*[32]byte) { - if featureconfig.Get().EnableByteMempool { - ValidatorsMemoryPool.Put(data) - } -} diff --git a/shared/memorypool/memorypool_test.go b/shared/memorypool/memorypool_test.go deleted file mode 100644 index 16519c9e1a4..00000000000 --- a/shared/memorypool/memorypool_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package memorypool - -import ( - "testing" -) - -func TestRoundTripMemoryRetrieval(t *testing.T) { - byteSlice := make([][]byte, 1000) - PutDoubleByteSlice(byteSlice) - newSlice := GetDoubleByteSlice(1000) - - if len(newSlice) != 1000 { - t.Errorf("Wanted same slice object, but got different object. "+ - "Wanted slice with length %d but got length %d", 1000, len(newSlice)) - } -}