core/state*: drop blockchainer.Blockchainer use

This commit is contained in:
Roman Khimov 2022-01-13 04:34:14 +03:00
parent 44fd7af044
commit 380e706255
4 changed files with 36 additions and 17 deletions

View file

@ -267,7 +267,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
contracts: *native.NewContracts(cfg),
}
bc.stateRoot = stateroot.NewModule(bc, bc.log, bc.dao.Store)
bc.stateRoot = stateroot.NewModule(bc.GetConfig(), bc.VerifyWitness, bc.log, bc.dao.Store)
bc.contracts.Designate.StateRootService = bc.stateRoot
if err := bc.init(); err != nil {

View file

@ -6,11 +6,13 @@ import (
"fmt"
"sync"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"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/util"
"go.uber.org/atomic"
@ -18,13 +20,17 @@ import (
)
type (
// VerifierFunc is a function that allows to check witness of account
// for Hashable item with GAS limit.
VerifierFunc func(util.Uint160, hash.Hashable, *transaction.Witness, int64) (int64, error)
// Module represents module for local processing of state roots.
Module struct {
Store *storage.MemCachedStore
network netmode.Magic
mpt *mpt.Trie
bc blockchainer.Blockchainer
log *zap.Logger
Store *storage.MemCachedStore
network netmode.Magic
srInHead bool
mpt *mpt.Trie
verifier VerifierFunc
log *zap.Logger
currentLocal atomic.Value
localHeight atomic.Uint32
@ -45,12 +51,13 @@ type (
)
// NewModule returns new instance of stateroot module.
func NewModule(bc blockchainer.Blockchainer, log *zap.Logger, s *storage.MemCachedStore) *Module {
func NewModule(cfg config.ProtocolConfiguration, verif VerifierFunc, log *zap.Logger, s *storage.MemCachedStore) *Module {
return &Module{
network: bc.GetConfig().Magic,
bc: bc,
log: log,
Store: s,
network: cfg.Magic,
srInHead: cfg.StateRootInHeader,
verifier: verif,
log: log,
Store: s,
}
}
@ -191,7 +198,7 @@ func (s *Module) UpdateCurrentLocal(mpt *mpt.Trie, sr *state.MPTRoot) {
s.mpt = mpt
s.currentLocal.Store(sr.Root)
s.localHeight.Store(sr.Index)
if s.bc.GetConfig().StateRootInHeader {
if s.srInHead {
s.validatedHeight.Store(sr.Index)
updateStateHeightMetric(sr.Index)
}
@ -216,6 +223,6 @@ func (s *Module) verifyWitness(r *state.MPTRoot) error {
s.mtx.Lock()
h := s.getKeyCacheForHeight(r.Index).validatorsHash
s.mtx.Unlock()
_, err := s.bc.VerifyWitness(h, r, &r.Witness[0], maxVerificationGAS)
_, err := s.verifier(h, r, &r.Witness[0], maxVerificationGAS)
return err
}

View file

@ -83,7 +83,7 @@ func (s *Module) AddStateRoot(sr *state.MPTRoot) error {
return err
}
s.validatedHeight.Store(sr.Index)
if !s.bc.GetConfig().StateRootInHeader {
if !s.srInHead {
updateStateHeightMetric(sr.Index)
}
return nil

View file

@ -23,6 +23,7 @@ import (
"fmt"
"sync"
"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"
@ -59,6 +60,17 @@ const (
blocksSynced
)
// Ledger is the interface required from Blockchain for Module to operate.
type Ledger interface {
AddHeaders(...*block.Header) error
BlockHeight() uint32
GetConfig() config.ProtocolConfiguration
GetHeader(hash util.Uint256) (*block.Header, error)
GetHeaderHash(int) util.Uint256
GetStateModule() blockchainer.StateRoot
HeaderHeight() uint32
}
// Module represents state sync module and aimed to gather state-related data to
// perform an atomic state jump.
type Module struct {
@ -75,7 +87,7 @@ type Module struct {
blockHeight uint32
dao *dao.Simple
bc blockchainer.Blockchainer
bc Ledger
mptpool *Pool
billet *mpt.Billet
@ -84,7 +96,7 @@ type Module struct {
}
// NewModule returns new instance of statesync module.
func NewModule(bc blockchainer.Blockchainer, log *zap.Logger, s *dao.Simple, jumpCallback func(p uint32) error) *Module {
func NewModule(bc Ledger, log *zap.Logger, s *dao.Simple, jumpCallback func(p uint32) error) *Module {
if !(bc.GetConfig().P2PStateExchangeExtensions && bc.GetConfig().RemoveUntraceableBlocks) {
return &Module{
dao: s,