mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
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.
|
||||
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
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
// StateRoot represents local state root module.
|
||||
type StateRoot interface {
|
||||
AddStateRoot(root *state.MPTRoot) error
|
||||
CleanStorage() error
|
||||
CurrentLocalHeight() uint32
|
||||
CurrentLocalStateRoot() util.Uint256
|
||||
CurrentValidatedHeight() uint32
|
||||
|
@ -20,5 +19,4 @@ type StateRoot interface {
|
|||
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||
GetStateValidators(height uint32) keys.PublicKeys
|
||||
SetUpdateValidatorsCallback(func(uint32, keys.PublicKeys))
|
||||
UpdateStateValidators(height uint32, pubs keys.PublicKeys)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"sort"
|
||||
"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/dao"
|
||||
"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/noderoles"
|
||||
"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/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -43,7 +43,7 @@ type Designate struct {
|
|||
// NotaryService represents Notary node module.
|
||||
NotaryService atomic.Value
|
||||
// StateRootService represents StateRoot node module.
|
||||
StateRootService blockchainer.StateRoot
|
||||
StateRootService *stateroot.Module
|
||||
}
|
||||
|
||||
type roleData struct {
|
||||
|
|
|
@ -25,9 +25,9 @@ import (
|
|||
|
||||
"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/blockchainer"
|
||||
"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/stateroot"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -67,7 +67,6 @@ type Ledger interface {
|
|||
GetConfig() config.ProtocolConfiguration
|
||||
GetHeader(hash util.Uint256) (*block.Header, error)
|
||||
GetHeaderHash(int) util.Uint256
|
||||
GetStateModule() blockchainer.StateRoot
|
||||
HeaderHeight() uint32
|
||||
}
|
||||
|
||||
|
@ -86,9 +85,10 @@ type Module struct {
|
|||
// blockHeight is the index of the latest stored block.
|
||||
blockHeight uint32
|
||||
|
||||
dao *dao.Simple
|
||||
bc Ledger
|
||||
mptpool *Pool
|
||||
dao *dao.Simple
|
||||
bc Ledger
|
||||
stateMod *stateroot.Module
|
||||
mptpool *Pool
|
||||
|
||||
billet *mpt.Billet
|
||||
|
||||
|
@ -96,17 +96,19 @@ type Module struct {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
return &Module{
|
||||
dao: s,
|
||||
bc: bc,
|
||||
stateMod: stateMod,
|
||||
syncStage: inactive,
|
||||
}
|
||||
}
|
||||
return &Module{
|
||||
dao: s,
|
||||
bc: bc,
|
||||
stateMod: stateMod,
|
||||
log: log,
|
||||
syncInterval: uint32(bc.GetConfig().StateSyncInterval),
|
||||
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
|
||||
// will be removed from storage during (*Blockchain).jumpToState(...) execution.
|
||||
// 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 {
|
||||
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 {
|
||||
s.syncStage |= mptSynced
|
||||
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 {
|
||||
header, err := s.bc.GetHeader(s.bc.GetHeaderHash(int(s.syncPoint + 1)))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue