diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 3b083a81b..0d1ae9944 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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 diff --git a/pkg/core/blockchainer/state_root.go b/pkg/core/blockchainer/state_root.go index 0ba680da0..69bff1817 100644 --- a/pkg/core/blockchainer/state_root.go +++ b/pkg/core/blockchainer/state_root.go @@ -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) } diff --git a/pkg/core/native/designate.go b/pkg/core/native/designate.go index ccf5767b8..08ed87013 100644 --- a/pkg/core/native/designate.go +++ b/pkg/core/native/designate.go @@ -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 { diff --git a/pkg/core/statesync/module.go b/pkg/core/statesync/module.go index ccacd3f61..e664fe9e2 100644 --- a/pkg/core/statesync/module.go +++ b/pkg/core/statesync/module.go @@ -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 {