core: drop dangerous methods from blockchainer.StateRoot
CleanStorage and UpdateStateValidators should only be availabe to appropriate core modules.
This commit is contained in:
parent
380e706255
commit
077d5ccb03
4 changed files with 13 additions and 13 deletions
|
@ -928,7 +928,7 @@ func (bc *Blockchain) GetStateModule() blockchainer.StateRoot {
|
||||||
|
|
||||||
// GetStateSyncModule returns new state sync service instance.
|
// GetStateSyncModule returns new state sync service instance.
|
||||||
func (bc *Blockchain) GetStateSyncModule() *statesync.Module {
|
func (bc *Blockchain) GetStateSyncModule() *statesync.Module {
|
||||||
return statesync.NewModule(bc, bc.log, bc.dao, bc.jumpToState)
|
return statesync.NewModule(bc, bc.stateRoot, bc.log, bc.dao, bc.jumpToState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// storeBlock performs chain update using the block given, it executes all
|
// storeBlock performs chain update using the block given, it executes all
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
// StateRoot represents local state root module.
|
// StateRoot represents local state root module.
|
||||||
type StateRoot interface {
|
type StateRoot interface {
|
||||||
AddStateRoot(root *state.MPTRoot) error
|
AddStateRoot(root *state.MPTRoot) error
|
||||||
CleanStorage() error
|
|
||||||
CurrentLocalHeight() uint32
|
CurrentLocalHeight() uint32
|
||||||
CurrentLocalStateRoot() util.Uint256
|
CurrentLocalStateRoot() util.Uint256
|
||||||
CurrentValidatedHeight() uint32
|
CurrentValidatedHeight() uint32
|
||||||
|
@ -20,5 +19,4 @@ type StateRoot interface {
|
||||||
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||||
GetStateValidators(height uint32) keys.PublicKeys
|
GetStateValidators(height uint32) keys.PublicKeys
|
||||||
SetUpdateValidatorsCallback(func(uint32, keys.PublicKeys))
|
SetUpdateValidatorsCallback(func(uint32, keys.PublicKeys))
|
||||||
UpdateStateValidators(height uint32, pubs keys.PublicKeys)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
|
@ -16,6 +15,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/stateroot"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
|
@ -43,7 +43,7 @@ type Designate struct {
|
||||||
// NotaryService represents Notary node module.
|
// NotaryService represents Notary node module.
|
||||||
NotaryService atomic.Value
|
NotaryService atomic.Value
|
||||||
// StateRootService represents StateRoot node module.
|
// StateRootService represents StateRoot node module.
|
||||||
StateRootService blockchainer.StateRoot
|
StateRootService *stateroot.Module
|
||||||
}
|
}
|
||||||
|
|
||||||
type roleData struct {
|
type roleData struct {
|
||||||
|
|
|
@ -25,9 +25,9 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/stateroot"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -67,7 +67,6 @@ type Ledger interface {
|
||||||
GetConfig() config.ProtocolConfiguration
|
GetConfig() config.ProtocolConfiguration
|
||||||
GetHeader(hash util.Uint256) (*block.Header, error)
|
GetHeader(hash util.Uint256) (*block.Header, error)
|
||||||
GetHeaderHash(int) util.Uint256
|
GetHeaderHash(int) util.Uint256
|
||||||
GetStateModule() blockchainer.StateRoot
|
|
||||||
HeaderHeight() uint32
|
HeaderHeight() uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +85,10 @@ type Module struct {
|
||||||
// blockHeight is the index of the latest stored block.
|
// blockHeight is the index of the latest stored block.
|
||||||
blockHeight uint32
|
blockHeight uint32
|
||||||
|
|
||||||
dao *dao.Simple
|
dao *dao.Simple
|
||||||
bc Ledger
|
bc Ledger
|
||||||
mptpool *Pool
|
stateMod *stateroot.Module
|
||||||
|
mptpool *Pool
|
||||||
|
|
||||||
billet *mpt.Billet
|
billet *mpt.Billet
|
||||||
|
|
||||||
|
@ -96,17 +96,19 @@ type Module struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewModule returns new instance of statesync module.
|
// NewModule returns new instance of statesync module.
|
||||||
func NewModule(bc Ledger, log *zap.Logger, s *dao.Simple, jumpCallback func(p uint32) error) *Module {
|
func NewModule(bc Ledger, stateMod *stateroot.Module, log *zap.Logger, s *dao.Simple, jumpCallback func(p uint32) error) *Module {
|
||||||
if !(bc.GetConfig().P2PStateExchangeExtensions && bc.GetConfig().RemoveUntraceableBlocks) {
|
if !(bc.GetConfig().P2PStateExchangeExtensions && bc.GetConfig().RemoveUntraceableBlocks) {
|
||||||
return &Module{
|
return &Module{
|
||||||
dao: s,
|
dao: s,
|
||||||
bc: bc,
|
bc: bc,
|
||||||
|
stateMod: stateMod,
|
||||||
syncStage: inactive,
|
syncStage: inactive,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &Module{
|
return &Module{
|
||||||
dao: s,
|
dao: s,
|
||||||
bc: bc,
|
bc: bc,
|
||||||
|
stateMod: stateMod,
|
||||||
log: log,
|
log: log,
|
||||||
syncInterval: uint32(bc.GetConfig().StateSyncInterval),
|
syncInterval: uint32(bc.GetConfig().StateSyncInterval),
|
||||||
mptpool: NewPool(),
|
mptpool: NewPool(),
|
||||||
|
@ -158,7 +160,7 @@ func (s *Module) Init(currChainHeight uint32) error {
|
||||||
// current chain's state until new state is completely fetched, outdated state-related data
|
// current chain's state until new state is completely fetched, outdated state-related data
|
||||||
// will be removed from storage during (*Blockchain).jumpToState(...) execution.
|
// will be removed from storage during (*Blockchain).jumpToState(...) execution.
|
||||||
// All we need to do right now is to remove genesis-related MPT nodes.
|
// All we need to do right now is to remove genesis-related MPT nodes.
|
||||||
err = s.bc.GetStateModule().CleanStorage()
|
err = s.stateMod.CleanStorage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to remove outdated MPT data from storage: %w", err)
|
return fmt.Errorf("failed to remove outdated MPT data from storage: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +215,7 @@ func (s *Module) defineSyncStage() error {
|
||||||
if s.blockHeight > s.syncPoint {
|
if s.blockHeight > s.syncPoint {
|
||||||
s.syncStage |= mptSynced
|
s.syncStage |= mptSynced
|
||||||
s.log.Info("MPT is in sync",
|
s.log.Info("MPT is in sync",
|
||||||
zap.Uint32("stateroot height", s.bc.GetStateModule().CurrentLocalHeight()))
|
zap.Uint32("stateroot height", s.stateMod.CurrentLocalHeight()))
|
||||||
} else if s.syncStage&headersSynced != 0 {
|
} else if s.syncStage&headersSynced != 0 {
|
||||||
header, err := s.bc.GetHeader(s.bc.GetHeaderHash(int(s.syncPoint + 1)))
|
header, err := s.bc.GetHeader(s.bc.GetHeaderHash(int(s.syncPoint + 1)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue