blockchainer/network: move StateSync interface to the user
Only network package cares about it.
This commit is contained in:
parent
af87cb082f
commit
bf1604454c
11 changed files with 16 additions and 22 deletions
|
@ -83,7 +83,7 @@ func newTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockch
|
|||
}
|
||||
|
||||
serverConfig := network.NewServerConfig(cfg)
|
||||
netSrv, err := network.NewServer(serverConfig, chain, zap.NewNop())
|
||||
netSrv, err := network.NewServer(serverConfig, chain, chain.GetStateSyncModule(), zap.NewNop())
|
||||
require.NoError(t, err)
|
||||
cons, err := consensus.NewService(consensus.Config{
|
||||
Logger: zap.NewNop(),
|
||||
|
|
|
@ -409,7 +409,7 @@ func startServer(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
serv, err := network.NewServer(serverConfig, chain, log)
|
||||
serv, err := network.NewServer(serverConfig, chain, chain.GetStateSyncModule(), log)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to create network server: %w", err), 1)
|
||||
}
|
||||
|
|
|
@ -321,11 +321,6 @@ func (chain *FakeChain) GetStateModule() blockchainer.StateRoot {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetStateSyncModule implements Blockchainer interface.
|
||||
func (chain *FakeChain) GetStateSyncModule() blockchainer.StateSync {
|
||||
return &FakeStateSync{}
|
||||
}
|
||||
|
||||
// GetStorageItem implements Blockchainer interface.
|
||||
func (chain *FakeChain) GetStorageItem(id int32, key []byte) state.StorageItem {
|
||||
panic("TODO")
|
||||
|
|
|
@ -927,7 +927,7 @@ func (bc *Blockchain) GetStateModule() blockchainer.StateRoot {
|
|||
}
|
||||
|
||||
// GetStateSyncModule returns new state sync service instance.
|
||||
func (bc *Blockchain) GetStateSyncModule() blockchainer.StateSync {
|
||||
func (bc *Blockchain) GetStateSyncModule() *statesync.Module {
|
||||
return statesync.NewModule(bc, bc.log, bc.dao, bc.jumpToState)
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ type Blockchainer interface {
|
|||
GetStandByCommittee() keys.PublicKeys
|
||||
GetStandByValidators() keys.PublicKeys
|
||||
GetStateModule() StateRoot
|
||||
GetStateSyncModule() StateSync
|
||||
GetStorageItem(id int32, key []byte) state.StorageItem
|
||||
GetStorageItems(id int32) ([]state.StorageItemWithKey, error)
|
||||
GetTestVM(t trigger.Type, tx *transaction.Transaction, b *block.Block) (*vm.VM, func())
|
||||
|
|
|
@ -193,7 +193,7 @@ func newTestServer(t *testing.T, serverConfig ServerConfig) *Server {
|
|||
}
|
||||
|
||||
func newTestServerWithCustomCfg(t *testing.T, serverConfig ServerConfig, protocolCfg func(*config.ProtocolConfiguration)) *Server {
|
||||
s, err := newServerFromConstructors(serverConfig, fakechain.NewFakeChainWithCustomCfg(protocolCfg), zaptest.NewLogger(t),
|
||||
s, err := newServerFromConstructors(serverConfig, fakechain.NewFakeChainWithCustomCfg(protocolCfg), new(fakechain.FakeStateSync), zaptest.NewLogger(t),
|
||||
newFakeTransp, newTestDiscovery)
|
||||
require.NoError(t, err)
|
||||
if serverConfig.Wallet != nil {
|
||||
|
|
|
@ -101,7 +101,7 @@ type (
|
|||
|
||||
syncReached *atomic.Bool
|
||||
|
||||
stateSync blockchainer.StateSync
|
||||
stateSync StateSync
|
||||
|
||||
log *zap.Logger
|
||||
}
|
||||
|
@ -119,13 +119,13 @@ func randomID() uint32 {
|
|||
}
|
||||
|
||||
// NewServer returns a new Server, initialized with the given configuration.
|
||||
func NewServer(config ServerConfig, chain blockchainer.Blockchainer, log *zap.Logger) (*Server, error) {
|
||||
return newServerFromConstructors(config, chain, log, func(s *Server) Transporter {
|
||||
func NewServer(config ServerConfig, chain blockchainer.Blockchainer, stSync StateSync, log *zap.Logger) (*Server, error) {
|
||||
return newServerFromConstructors(config, chain, stSync, log, func(s *Server) Transporter {
|
||||
return NewTCPTransport(s, net.JoinHostPort(s.ServerConfig.Address, strconv.Itoa(int(s.ServerConfig.Port))), s.log)
|
||||
}, newDefaultDiscovery)
|
||||
}
|
||||
|
||||
func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchainer, log *zap.Logger,
|
||||
func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchainer, stSync StateSync, log *zap.Logger,
|
||||
newTransport func(*Server) Transporter,
|
||||
newDiscovery func([]string, time.Duration, Transporter) Discoverer,
|
||||
) (*Server, error) {
|
||||
|
@ -156,6 +156,7 @@ func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchai
|
|||
log: log,
|
||||
transactions: make(chan *transaction.Transaction, 64),
|
||||
extensHandlers: make(map[string]func(*payload.Extensible) error),
|
||||
stateSync: stSync,
|
||||
}
|
||||
if chain.P2PSigExtensionsEnabled() {
|
||||
s.notaryFeer = NewNotaryFeer(chain)
|
||||
|
@ -170,9 +171,7 @@ func newServerFromConstructors(config ServerConfig, chain blockchainer.Blockchai
|
|||
s.tryStartServices()
|
||||
})
|
||||
|
||||
sSync := chain.GetStateSyncModule()
|
||||
s.stateSync = sSync
|
||||
s.bSyncQueue = newBlockQueue(maxBlockBatch, sSync, log, nil)
|
||||
s.bSyncQueue = newBlockQueue(maxBlockBatch, s.stateSync, log, nil)
|
||||
|
||||
if s.MinPeers < 0 {
|
||||
s.log.Info("bad MinPeers configured, using the default value",
|
||||
|
|
|
@ -51,7 +51,7 @@ func TestNewServer(t *testing.T) {
|
|||
P2PStateExchangeExtensions: true,
|
||||
StateRootInHeader: true,
|
||||
}}
|
||||
s, err := newServerFromConstructors(ServerConfig{}, bc, nil, newFakeTransp, newTestDiscovery)
|
||||
s, err := newServerFromConstructors(ServerConfig{}, bc, new(fakechain.FakeStateSync), nil, newFakeTransp, newTestDiscovery)
|
||||
require.Error(t, err)
|
||||
|
||||
t.Run("set defaults", func(t *testing.T) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package blockchainer
|
||||
package network
|
||||
|
||||
import (
|
||||
"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/util"
|
||||
)
|
||||
|
@ -8,7 +9,7 @@ import (
|
|||
// StateSync represents state sync module.
|
||||
type StateSync interface {
|
||||
AddMPTNodes([][]byte) error
|
||||
Blockqueuer // Blockqueuer interface
|
||||
blockchainer.Blockqueuer // Blockqueuer interface
|
||||
Init(currChainHeight uint32) error
|
||||
IsActive() bool
|
||||
IsInitialized() bool
|
|
@ -102,7 +102,7 @@ func initClearServerWithServices(t testing.TB, needOracle bool, needNotary bool)
|
|||
|
||||
serverConfig := network.NewServerConfig(cfg)
|
||||
serverConfig.Port = 0
|
||||
server, err := network.NewServer(serverConfig, chain, logger)
|
||||
server, err := network.NewServer(serverConfig, chain, chain.GetStateSyncModule(), logger)
|
||||
require.NoError(t, err)
|
||||
rpcServer := New(chain, cfg.ApplicationConfiguration.RPC, server, orc, logger)
|
||||
errCh := make(chan error, 2)
|
||||
|
|
|
@ -2325,7 +2325,7 @@ func BenchmarkHandleIn(b *testing.B) {
|
|||
|
||||
serverConfig := network.NewServerConfig(cfg)
|
||||
serverConfig.LogLevel = zapcore.FatalLevel
|
||||
server, err := network.NewServer(serverConfig, chain, logger)
|
||||
server, err := network.NewServer(serverConfig, chain, chain.GetStateSyncModule(), logger)
|
||||
require.NoError(b, err)
|
||||
rpcServer := New(chain, cfg.ApplicationConfiguration.RPC, server, orc, logger)
|
||||
defer chain.Close()
|
||||
|
|
Loading…
Reference in a new issue