prysm-pulse/beacon-chain/state/stategen/setter.go
terence tsao 7a27d89e68
Reduce memory usage for new-state-mgmt at init sync (#5778)
* Add `GetWithoutCopy`
* Add `StateByRootInitialSync`
* Use `StateByRootInitialSync` for initial syncing using new-state-mgmt
* Merge branch 'master' into new-state-init-sync-mem
* Skip if split slot is 0
* Merge branch 'new-state-init-sync-mem' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
* Make sure we invalidate cache
* Add test part 1
* Add tests part 2
* Update beacon-chain/cache/hot_state_cache.go

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
* Comment
* Merge branch 'new-state-init-sync-mem' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
* Merge branch 'master' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
* Dont need to run fork choice and save head during intial sync
* Invalidate cache at onBlockInitialSyncStateTransition
* Merge branch 'new-state-init-sync-mem' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
* Revert saveHeadNoDB changes
* Add back DeleteHotStateInCache
* Removed extra deletion
* Merge branch 'master' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
* Proper set splitslot for tests
* Merge branch 'master' into new-state-init-sync-mem
* Merge branch 'master' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
* Merge branch 'new-state-init-sync-mem' of github.com:prysmaticlabs/prysm into new-state-init-sync-mem
2020-05-08 19:02:48 +00:00

28 lines
779 B
Go

package stategen
import (
"context"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"go.opencensus.io/trace"
)
// SaveState saves the state in the DB.
// It knows which cold and hot state section the input state should belong to.
func (s *State) SaveState(ctx context.Context, root [32]byte, state *state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "stateGen.SaveState")
defer span.End()
// The state belongs to the cold section if it's below the split slot threshold.
if state.Slot() < s.splitInfo.slot {
return s.saveColdState(ctx, root, state)
}
return s.saveHotState(ctx, root, state)
}
// DeleteHotStateInCache deletes the hot state entry from the cache.
func (s *State) DeleteHotStateInCache(root [32]byte) {
s.hotStateCache.Delete(root)
}