Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/cn/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func New(ctx *node.ServiceContext, config *Config) (*CN, error) {
if !ok {
return nil, errUnsupportedEnginePolicy
}
if cn.protocolManager, err = NewProtocolManager(cn.chainConfig, config.SyncMode, config.NetworkId, cn.eventMux, cn.txPool, handler, cn.blockchain, chainDB, cacheLimit, ctx.NodeType(), config); err != nil {
if cn.protocolManager, err = NewProtocolManager(cn.chainConfig, config.SyncMode, config.NetworkId, cn.eventMux, cn.txPool, handler, cn.blockchain, chainDB, cacheLimit, ctx.NodeType(), config, cn.stakingModule); err != nil {
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion node/cn/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type ProtocolManager struct {
// with the Kaia network.
func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, networkId uint64, mux *event.TypeMux,
txpool work.TxPool, handler consensus.Handler, blockchain work.BlockChain, chainDB database.DBManager, cacheLimit int,
nodetype common.ConnType, cnconfig *Config,
nodetype common.ConnType, cnconfig *Config, stakingModule staking.StakingModule,
) (*ProtocolManager, error) {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
Expand All @@ -217,6 +217,7 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
quitResendCh: make(chan struct{}),
handler: handler,
nodetype: nodetype,
stakingModule: stakingModule,
txResendUseLegacy: cnconfig.TxResendUseLegacy,
verifiedBlobTxs: newKnownHashSet(maxVerifiedBlobTxs),
blobSidecarReqManager: &sidecarReqManager{
Expand Down
29 changes: 27 additions & 2 deletions node/cn/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/kaiachain/kaia/crypto"
"github.com/kaiachain/kaia/datasync/downloader"
"github.com/kaiachain/kaia/event"
staking_mock "github.com/kaiachain/kaia/kaiax/staking/mock"
"github.com/kaiachain/kaia/networks/p2p"
"github.com/kaiachain/kaia/networks/p2p/discover"
"github.com/kaiachain/kaia/node/cn/mocks"
Expand Down Expand Up @@ -158,13 +159,37 @@ func TestNewProtocolManager(t *testing.T) {

pm, err := NewProtocolManager(params.TestChainConfig, downloader.FastSync, 0, nil, mockTxPool,
&testConsensusHandler{}, mockBlockChain, nil, 1, common.CONSENSUSNODE,
&Config{DownloaderDisable: true, FetcherDisable: true})
&Config{DownloaderDisable: true, FetcherDisable: true}, nil)

assert.NotNil(t, pm)
assert.NoError(t, err)
}
}

// The downloader must be constructed with a live staking module.
func TestNewProtocolManager_downloaderHoldsStakingModule(t *testing.T) {
mockCtrl, mockBlockChain, mockTxPool := newMocks(t)
defer mockCtrl.Finish()

// Staking info recovery refuses ranges at or after the Kaia fork, so use a config with none.
config := params.TestKaiaConfig("istanbul")
mockBlockChain.EXPECT().Config().Return(config).AnyTimes()
mockBlockChain.EXPECT().CurrentBlock().Return(newBlock(0)).AnyTimes()

db := database.NewMemoryDBManager()
db.WriteCanonicalHash(common.HexToHash("0x1"), 0)

mStaking := staking_mock.NewMockStakingModule(mockCtrl)
mStaking.EXPECT().GetStakingInfoFromDB(uint64(0)).Return(nil).Times(1)

pm, err := NewProtocolManager(config, downloader.FullSync, 0, nil, mockTxPool,
&testConsensusHandler{}, mockBlockChain, db, 1, common.CONSENSUSNODE,
&Config{FetcherDisable: true}, mStaking)
assert.NoError(t, err)

assert.Error(t, pm.Downloader().SyncStakingInfo("no-such-peer", 0, 0))
}

func TestProtocolManager_RegisterValidator(t *testing.T) {
pm := &ProtocolManager{}
mockCtrl := gomock.NewController(t)
Expand Down Expand Up @@ -1382,7 +1407,7 @@ func TestGetBlockHeaders(t *testing.T) {
},
}

pm, err := NewProtocolManager(params.TestChainConfig, downloader.FullSync, 1, nil, nil, faker.NewFaker(), backend, db, 1, common.ENDPOINTNODE, &Config{TxResendUseLegacy: false, TxResendInterval: 1, TxResendCount: 0})
pm, err := NewProtocolManager(params.TestChainConfig, downloader.FullSync, 1, nil, nil, faker.NewFaker(), backend, db, 1, common.ENDPOINTNODE, &Config{TxResendUseLegacy: false, TxResendInterval: 1, TxResendCount: 0}, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading