mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
stateroot: add and use DataMPTAux for auxiliary data
Use DataMPT for nodes only, otherwise with 1M blocks with have 1M height-stateroot mapping entries that our GC has to iterate over for no reason.
This commit is contained in:
parent
ad606101c7
commit
ccdda21718
4 changed files with 14 additions and 20 deletions
|
@ -44,7 +44,7 @@ import (
|
|||
// Tuning parameters.
|
||||
const (
|
||||
headerBatchCount = 2000
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
|
||||
defaultInitialGAS = 52000000_00000000
|
||||
defaultGCPeriod = 10000
|
||||
|
|
|
@ -118,7 +118,7 @@ func (s *Module) CurrentValidatedHeight() uint32 {
|
|||
|
||||
// Init initializes state root module at the given height.
|
||||
func (s *Module) Init(height uint32) error {
|
||||
data, err := s.Store.Get([]byte{byte(storage.DataMPT), prefixValidated})
|
||||
data, err := s.Store.Get([]byte{byte(storage.DataMPTAux), prefixValidated})
|
||||
if err == nil {
|
||||
s.validatedHeight.Store(binary.LittleEndian.Uint32(data))
|
||||
}
|
||||
|
@ -156,16 +156,6 @@ func (s *Module) CleanStorage() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to remove outdated MPT-reated items: %w", err)
|
||||
}
|
||||
currentLocal := s.currentLocal.Load().(util.Uint256)
|
||||
if !currentLocal.Equals(util.Uint256{}) {
|
||||
err := s.addLocalStateRoot(s.Store, &state.MPTRoot{
|
||||
Index: s.localHeight.Load(),
|
||||
Root: currentLocal,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to store current local stateroot: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -177,7 +167,7 @@ func (s *Module) JumpToState(sr *state.MPTRoot) error {
|
|||
|
||||
data := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(data, sr.Index)
|
||||
if err := s.Store.Put([]byte{byte(storage.DataMPT), prefixValidated}, data); err != nil {
|
||||
if err := s.Store.Put([]byte{byte(storage.DataMPTAux), prefixValidated}, data); err != nil {
|
||||
return fmt.Errorf("failed to store validated height: %w", err)
|
||||
}
|
||||
s.validatedHeight.Store(sr.Index)
|
||||
|
|
|
@ -29,7 +29,7 @@ func (s *Module) addLocalStateRoot(store *storage.MemCachedStore, sr *state.MPTR
|
|||
|
||||
data := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(data, sr.Index)
|
||||
return store.Put([]byte{byte(storage.DataMPT), prefixLocal}, data)
|
||||
return store.Put([]byte{byte(storage.DataMPTAux), prefixLocal}, data)
|
||||
}
|
||||
|
||||
func putStateRoot(store *storage.MemCachedStore, key []byte, sr *state.MPTRoot) error {
|
||||
|
@ -52,7 +52,7 @@ func (s *Module) getStateRoot(key []byte) (*state.MPTRoot, error) {
|
|||
|
||||
func makeStateRootKey(index uint32) []byte {
|
||||
key := make([]byte, 5)
|
||||
key[0] = byte(storage.DataMPT)
|
||||
key[0] = byte(storage.DataMPTAux)
|
||||
binary.BigEndian.PutUint32(key, index)
|
||||
return key
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func (s *Module) AddStateRoot(sr *state.MPTRoot) error {
|
|||
|
||||
data := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(data, sr.Index)
|
||||
if err := s.Store.Put([]byte{byte(storage.DataMPT), prefixValidated}, data); err != nil {
|
||||
if err := s.Store.Put([]byte{byte(storage.DataMPTAux), prefixValidated}, data); err != nil {
|
||||
return err
|
||||
}
|
||||
s.validatedHeight.Store(sr.Index)
|
||||
|
|
|
@ -11,10 +11,14 @@ import (
|
|||
// KeyPrefix constants.
|
||||
const (
|
||||
DataExecutable KeyPrefix = 0x01
|
||||
DataMPT KeyPrefix = 0x03
|
||||
STAccount KeyPrefix = 0x40
|
||||
STContractID KeyPrefix = 0x51
|
||||
STStorage KeyPrefix = 0x70
|
||||
// DataMPT is used for MPT node entries identified by Uint256.
|
||||
DataMPT KeyPrefix = 0x03
|
||||
// DataMPTAux is used to store additional MPT data like height-root
|
||||
// mappings and local/validated heights.
|
||||
DataMPTAux KeyPrefix = 0x04
|
||||
STAccount KeyPrefix = 0x40
|
||||
STContractID KeyPrefix = 0x51
|
||||
STStorage KeyPrefix = 0x70
|
||||
// STTempStorage is used to store contract storage items during state sync process
|
||||
// in order not to mess up the previous state which has its own items stored by
|
||||
// STStorage prefix. Once state exchange process is completed, all items with
|
||||
|
|
Loading…
Reference in a new issue