mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +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.
|
// Tuning parameters.
|
||||||
const (
|
const (
|
||||||
headerBatchCount = 2000
|
headerBatchCount = 2000
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
|
|
||||||
defaultInitialGAS = 52000000_00000000
|
defaultInitialGAS = 52000000_00000000
|
||||||
defaultGCPeriod = 10000
|
defaultGCPeriod = 10000
|
||||||
|
|
|
@ -118,7 +118,7 @@ func (s *Module) CurrentValidatedHeight() uint32 {
|
||||||
|
|
||||||
// Init initializes state root module at the given height.
|
// Init initializes state root module at the given height.
|
||||||
func (s *Module) Init(height uint32) error {
|
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 {
|
if err == nil {
|
||||||
s.validatedHeight.Store(binary.LittleEndian.Uint32(data))
|
s.validatedHeight.Store(binary.LittleEndian.Uint32(data))
|
||||||
}
|
}
|
||||||
|
@ -156,16 +156,6 @@ func (s *Module) CleanStorage() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to remove outdated MPT-reated items: %w", err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +167,7 @@ func (s *Module) JumpToState(sr *state.MPTRoot) error {
|
||||||
|
|
||||||
data := make([]byte, 4)
|
data := make([]byte, 4)
|
||||||
binary.LittleEndian.PutUint32(data, sr.Index)
|
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)
|
return fmt.Errorf("failed to store validated height: %w", err)
|
||||||
}
|
}
|
||||||
s.validatedHeight.Store(sr.Index)
|
s.validatedHeight.Store(sr.Index)
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (s *Module) addLocalStateRoot(store *storage.MemCachedStore, sr *state.MPTR
|
||||||
|
|
||||||
data := make([]byte, 4)
|
data := make([]byte, 4)
|
||||||
binary.LittleEndian.PutUint32(data, sr.Index)
|
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 {
|
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 {
|
func makeStateRootKey(index uint32) []byte {
|
||||||
key := make([]byte, 5)
|
key := make([]byte, 5)
|
||||||
key[0] = byte(storage.DataMPT)
|
key[0] = byte(storage.DataMPTAux)
|
||||||
binary.BigEndian.PutUint32(key, index)
|
binary.BigEndian.PutUint32(key, index)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func (s *Module) AddStateRoot(sr *state.MPTRoot) error {
|
||||||
|
|
||||||
data := make([]byte, 4)
|
data := make([]byte, 4)
|
||||||
binary.LittleEndian.PutUint32(data, sr.Index)
|
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
|
return err
|
||||||
}
|
}
|
||||||
s.validatedHeight.Store(sr.Index)
|
s.validatedHeight.Store(sr.Index)
|
||||||
|
|
|
@ -11,7 +11,11 @@ import (
|
||||||
// KeyPrefix constants.
|
// KeyPrefix constants.
|
||||||
const (
|
const (
|
||||||
DataExecutable KeyPrefix = 0x01
|
DataExecutable KeyPrefix = 0x01
|
||||||
|
// DataMPT is used for MPT node entries identified by Uint256.
|
||||||
DataMPT KeyPrefix = 0x03
|
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
|
STAccount KeyPrefix = 0x40
|
||||||
STContractID KeyPrefix = 0x51
|
STContractID KeyPrefix = 0x51
|
||||||
STStorage KeyPrefix = 0x70
|
STStorage KeyPrefix = 0x70
|
||||||
|
|
Loading…
Reference in a new issue