prysm-pulse/beacon-chain/db/state.go

46 lines
1.4 KiB
Go
Raw Normal View History

2018-10-05 17:14:50 +00:00
package db
import (
"github.com/prysmaticlabs/prysm/beacon-chain/types"
)
// GetActiveState contains the current state of attestations and changes every block.
func (db *BeaconDB) GetActiveState() *types.ActiveState {
return db.state.aState
}
// GetCrystallizedState contains cycle dependent validator information, changes every cycle.
func (db *BeaconDB) GetCrystallizedState() *types.CrystallizedState {
return db.state.cState
}
// SaveActiveState is a convenience method which sets and persists the active state on the beacon chain.
func (db *BeaconDB) SaveActiveState(activeState *types.ActiveState) error {
db.state.aState = activeState
encodedState, err := db.GetCrystallizedState().Marshal()
if err != nil {
return err
}
return db.put(activeStateLookupKey, encodedState)
}
// SaveCrystallizedState is a convenience method which sets and persists the crystallized state on the beacon chain.
func (db *BeaconDB) SaveCrystallizedState(crystallizedState *types.CrystallizedState) error {
db.state.cState = crystallizedState
encodedState, err := db.GetActiveState().Marshal()
if err != nil {
return err
}
return db.put(crystallizedStateLookupKey, encodedState)
}
// HasStoredState checks if state has been stored to the database.
func (db *BeaconDB) HasStoredState() (bool, error) {
hasState, err := db.has(crystallizedStateLookupKey)
if err != nil {
return false, err
}
return hasState, nil
}