Skip to content

Commit

Permalink
Release state trie ref flag
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed May 27, 2020
1 parent 43632f1 commit 7faacae
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 94 deletions.
134 changes: 56 additions & 78 deletions beacon-chain/state/state_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
Expand Down Expand Up @@ -245,111 +244,90 @@ func (b *BeaconState) rootSelector(field fieldIndex) ([32]byte, error) {
case latestBlockHeader:
return stateutil.BlockHeaderRoot(b.state.LatestBlockHeader)
case blockRoots:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.BlockRoots, params.BeaconConfig().SlotsPerHistoricalRoot)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.BlockRoots, params.BeaconConfig().SlotsPerHistoricalRoot)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(blockRoots, b.state.BlockRoots)
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.RootsArrayHashTreeRoot(b.state.BlockRoots, params.BeaconConfig().SlotsPerHistoricalRoot, "BlockRoots")
return b.recomputeFieldTrie(blockRoots, b.state.BlockRoots)
case stateRoots:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.StateRoots, params.BeaconConfig().SlotsPerHistoricalRoot)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.StateRoots, params.BeaconConfig().SlotsPerHistoricalRoot)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(stateRoots, b.state.StateRoots)
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.RootsArrayHashTreeRoot(b.state.StateRoots, params.BeaconConfig().SlotsPerHistoricalRoot, "StateRoots")
return b.recomputeFieldTrie(stateRoots, b.state.StateRoots)
case historicalRoots:
return stateutil.HistoricalRootsRoot(b.state.HistoricalRoots)
case eth1Data:
return stateutil.Eth1Root(hasher, b.state.Eth1Data)
case eth1DataVotes:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.Eth1DataVotes, params.BeaconConfig().EpochsPerEth1VotingPeriod*params.BeaconConfig().SlotsPerEpoch)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.Eth1DataVotes, params.BeaconConfig().EpochsPerEth1VotingPeriod*params.BeaconConfig().SlotsPerEpoch)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(field, b.state.Eth1DataVotes)
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.Eth1DataVotesRoot(b.state.Eth1DataVotes)
return b.recomputeFieldTrie(field, b.state.Eth1DataVotes)
case validators:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.Validators, params.BeaconConfig().ValidatorRegistryLimit)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[validators] = []uint64{}
delete(b.rebuildTrie, validators)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.Validators, params.BeaconConfig().ValidatorRegistryLimit)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(validators, b.state.Validators)
b.dirtyIndices[validators] = []uint64{}
delete(b.rebuildTrie, validators)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.ValidatorRegistryRoot(b.state.Validators)
return b.recomputeFieldTrie(validators, b.state.Validators)
case balances:
return stateutil.ValidatorBalancesRoot(b.state.Balances)
case randaoMixes:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.RandaoMixes, params.BeaconConfig().EpochsPerHistoricalVector)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.RandaoMixes, params.BeaconConfig().EpochsPerHistoricalVector)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(randaoMixes, b.state.RandaoMixes)
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.RootsArrayHashTreeRoot(b.state.RandaoMixes, params.BeaconConfig().EpochsPerHistoricalVector, "RandaoMixes")
return b.recomputeFieldTrie(randaoMixes, b.state.RandaoMixes)
case slashings:
return stateutil.SlashingsRoot(b.state.Slashings)
case previousEpochAttestations:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.PreviousEpochAttestations, params.BeaconConfig().MaxAttestations*params.BeaconConfig().SlotsPerEpoch)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.PreviousEpochAttestations, params.BeaconConfig().MaxAttestations*params.BeaconConfig().SlotsPerEpoch)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(field, b.state.PreviousEpochAttestations)
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.EpochAttestationsRoot(b.state.PreviousEpochAttestations)
return b.recomputeFieldTrie(field, b.state.PreviousEpochAttestations)
case currentEpochAttestations:
if featureconfig.Get().EnableFieldTrie {
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.CurrentEpochAttestations, params.BeaconConfig().MaxAttestations*params.BeaconConfig().SlotsPerEpoch)
if err != nil {
return [32]byte{}, err
}
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
if b.rebuildTrie[field] {
err := b.resetFieldTrie(field, b.state.CurrentEpochAttestations, params.BeaconConfig().MaxAttestations*params.BeaconConfig().SlotsPerEpoch)
if err != nil {
return [32]byte{}, err
}
return b.recomputeFieldTrie(field, b.state.CurrentEpochAttestations)
b.dirtyIndices[field] = []uint64{}
delete(b.rebuildTrie, field)
return b.stateFieldLeaves[field].TrieRoot()
}
return stateutil.EpochAttestationsRoot(b.state.CurrentEpochAttestations)
return b.recomputeFieldTrie(field, b.state.CurrentEpochAttestations)
case justificationBits:
return bytesutil.ToBytes32(b.state.JustificationBits), nil
case previousJustifiedCheckpoint:
Expand Down
4 changes: 0 additions & 4 deletions beacon-chain/state/state_trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
Expand Down Expand Up @@ -179,9 +178,6 @@ func TestBeaconState_HashTreeRoot(t *testing.T) {
}

func TestBeaconState_HashTreeRoot_EnableFieldTrie(t *testing.T) {
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{EnableFieldTrie: true})
defer resetCfg()

testState, _ := testutil.DeterministicGenesisState(t, 64)

type test struct {
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/sync/validate_proposer_slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, *stateTr
StateRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot),
LatestBlockHeader: &ethpb.BeaconBlockHeader{},
JustificationBits: []byte{0},
})
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 0 additions & 5 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type Flags struct {
EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer.
DontPruneStateStartUp bool // DontPruneStateStartUp disables pruning state upon beacon node start up.
NewStateMgmt bool // NewStateMgmt enables the new state mgmt service.
EnableFieldTrie bool // EnableFieldTrie enables the state from using field specific tries when computing the root.
NoInitSyncBatchSaveBlocks bool // NoInitSyncBatchSaveBlocks disables batch save blocks mode during initial syncing.
WaitForSynced bool // WaitForSynced uses WaitForSynced in validator startup to ensure it can communicate with the beacon node as soon as possible.
SkipRegenHistoricalStates bool // SkipRegenHistoricalState skips regenerating historical states from genesis to last finalized. This enables a quick switch over to using new-state-mgmt.
Expand Down Expand Up @@ -188,10 +187,6 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Enabling state management service")
cfg.NewStateMgmt = true
}
if ctx.Bool(enableFieldTrie.Name) {
log.Warn("Enabling state field trie")
cfg.EnableFieldTrie = true
}
if ctx.Bool(disableInitSyncBatchSaveBlocks.Name) {
log.Warn("Disabling init sync batch save blocks mode")
cfg.NoInitSyncBatchSaveBlocks = true
Expand Down
13 changes: 6 additions & 7 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ var (
Name: "enable-new-state-mgmt",
Usage: "This enable the usage of state mgmt service across Prysm",
}
enableFieldTrie = &cli.BoolFlag{
Name: "enable-state-field-trie",
Usage: "Enables the usage of state field tries to compute the state root",
}
disableInitSyncBatchSaveBlocks = &cli.BoolFlag{
Name: "disable-init-sync-batch-save-blocks",
Usage: "Instead of saving batch blocks to the DB during initial syncing, this disables batch saving of blocks",
Expand Down Expand Up @@ -156,7 +152,6 @@ var (

// devModeFlags holds list of flags that are set when development mode is on.
var devModeFlags = []cli.Flag{
enableFieldTrie,
enableNewStateMgmt,
enableInitSyncWeightedRoundRobin,
}
Expand Down Expand Up @@ -371,6 +366,11 @@ var (
Usage: deprecatedUsage,
Hidden: true,
}
deprecateEnableFieldTrie = &cli.BoolFlag{
Name: "enable-state-field-trie",
Usage: deprecatedUsage,
Hidden: true,
}
)

var deprecatedFlags = []cli.Flag{
Expand Down Expand Up @@ -415,6 +415,7 @@ var deprecatedFlags = []cli.Flag{
deprecatedBroadcastSlashingFlag,
deprecatedDisableHistoricalDetectionFlag,
deprecateEnableStateRefCopy,
deprecateEnableFieldTrie,
}

// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
Expand Down Expand Up @@ -466,7 +467,6 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
dontPruneStateStartUp,
disableBroadcastSlashingFlag,
enableNewStateMgmt,
enableFieldTrie,
disableInitSyncBatchSaveBlocks,
waitForSyncedFlag,
skipRegenHistoricalStates,
Expand All @@ -478,7 +478,6 @@ var E2EBeaconChainFlags = []string{
"--cache-filtered-block-tree",
"--enable-state-gen-sig-verify",
"--check-head-state",
"--enable-state-field-trie",
"--enable-new-state-mgmt",
"--enable-init-sync-wrr",
}

0 comments on commit 7faacae

Please sign in to comment.