From fb9777fd92066016365b31fe085b9fff262cfcc0 Mon Sep 17 00:00:00 2001 From: envestcc Date: Tue, 25 Mar 2025 20:17:23 +0800 Subject: [PATCH] move block util funcs into blockchain context --- action/protocol/context.go | 4 ++ action/protocol/execution/protocol.go | 16 +++---- action/protocol/poll/consortium.go | 7 ++-- action/protocol/poll/governance_protocol.go | 11 ++--- .../protocol/poll/governance_protocol_test.go | 6 +++ action/protocol/poll/protocol.go | 10 ++--- .../protocol/poll/staking_committee_test.go | 24 +++++++++++ api/coreservice.go | 16 ++++--- api/coreservice_test.go | 2 +- api/grpcserver_integrity_test.go | 10 +++-- api/serverV2.go | 4 +- api/serverV2_integrity_test.go | 2 +- blockchain/blockchain.go | 17 +++++++- chainservice/builder.go | 42 ++++--------------- chainservice/chainservice.go | 9 +--- e2etest/local_test.go | 2 + state/factory/factory_test.go | 4 +- .../internal/client/client_test.go | 3 +- 18 files changed, 107 insertions(+), 82 deletions(-) diff --git a/action/protocol/context.go b/action/protocol/context.go index f5030c3275..64677f67f7 100644 --- a/action/protocol/context.go +++ b/action/protocol/context.go @@ -54,6 +54,10 @@ type ( ChainID uint32 // EvmNetworkID is the EVM network ID EvmNetworkID uint32 + // GetBlockHash is the function to get block hash by height + GetBlockHash func(uint64) (hash.Hash256, error) + // GetBlockTime is the function to get block time by height + GetBlockTime func(uint64) (time.Time, error) } // BlockCtx provides block auxiliary information. diff --git a/action/protocol/execution/protocol.go b/action/protocol/execution/protocol.go index ccd871c1f2..52c676cd6e 100644 --- a/action/protocol/execution/protocol.go +++ b/action/protocol/execution/protocol.go @@ -29,20 +29,19 @@ const ( // Protocol defines the protocol of handling executions type Protocol struct { - getBlockHash evm.GetBlockHash - getBlockTime evm.GetBlockTime - depositGas protocol.DepositGas - addr address.Address + depositGas protocol.DepositGas + addr address.Address } // NewProtocol instantiates the protocol of exeuction -func NewProtocol(getBlockHash evm.GetBlockHash, depositGas protocol.DepositGas, getBlockTime evm.GetBlockTime) *Protocol { +// TODO: remove unused getBlockHash and getBlockTime +func NewProtocol(_ evm.GetBlockHash, depositGas protocol.DepositGas, _ evm.GetBlockTime) *Protocol { h := hash.Hash160b([]byte(_protocolID)) addr, err := address.FromBytes(h[:]) if err != nil { log.L().Panic("Error when constructing the address of vote protocol", zap.Error(err)) } - return &Protocol{getBlockHash: getBlockHash, depositGas: depositGas, addr: addr, getBlockTime: getBlockTime} + return &Protocol{depositGas: depositGas, addr: addr} } // FindProtocol finds the registered protocol from registry @@ -66,9 +65,10 @@ func (p *Protocol) Handle(ctx context.Context, elp action.Envelope, sm protocol. if _, ok := elp.Action().(*action.Execution); !ok { return nil, nil } + bcCtx := protocol.MustGetBlockchainCtx(ctx) ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: p.getBlockHash, - GetBlockTime: p.getBlockTime, + GetBlockHash: bcCtx.GetBlockHash, + GetBlockTime: bcCtx.GetBlockTime, DepositGasFunc: p.depositGas, }) _, receipt, err := evm.ExecuteContract(ctx, sm, elp) diff --git a/action/protocol/poll/consortium.go b/action/protocol/poll/consortium.go index 6596f6665a..d18fd807ac 100644 --- a/action/protocol/poll/consortium.go +++ b/action/protocol/poll/consortium.go @@ -50,11 +50,11 @@ type consortiumCommittee struct { bufferResult state.CandidateList indexer *CandidateIndexer addr address.Address - getBlockHash evm.GetBlockHash } // NewConsortiumCommittee creates a committee for consorium chain -func NewConsortiumCommittee(indexer *CandidateIndexer, readContract ReadContract, getBlockHash evm.GetBlockHash) (Protocol, error) { +// TODO: remove unused getBlockHash +func NewConsortiumCommittee(indexer *CandidateIndexer, readContract ReadContract, _ evm.GetBlockHash) (Protocol, error) { abi, err := abi.JSON(strings.NewReader(ConsortiumManagementABI)) if err != nil { return nil, err @@ -73,7 +73,6 @@ func NewConsortiumCommittee(indexer *CandidateIndexer, readContract ReadContract abi: abi, addr: addr, indexer: indexer, - getBlockHash: getBlockHash, }, nil } @@ -143,7 +142,7 @@ func (cc *consortiumCommittee) CreateGenesisStates(ctx context.Context, sm proto cc.contract = receipt.ContractAddress ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: cc.getBlockHash, + GetBlockHash: protocol.MustGetBlockchainCtx(ctx).GetBlockHash, GetBlockTime: getBlockTime, }) r := getContractReaderForGenesisStates(ctx, sm) diff --git a/action/protocol/poll/governance_protocol.go b/action/protocol/poll/governance_protocol.go index d627432149..2b7c1006fa 100644 --- a/action/protocol/poll/governance_protocol.go +++ b/action/protocol/poll/governance_protocol.go @@ -25,7 +25,6 @@ import ( ) type governanceChainCommitteeProtocol struct { - getBlockTime GetBlockTime electionCommittee committee.Committee initGravityChainHeight uint64 addr address.Address @@ -35,20 +34,18 @@ type governanceChainCommitteeProtocol struct { } // NewGovernanceChainCommitteeProtocol creates a Poll Protocol which fetch result from governance chain +// TODO: remove getBlockTime func NewGovernanceChainCommitteeProtocol( candidatesIndexer *CandidateIndexer, electionCommittee committee.Committee, initGravityChainHeight uint64, - getBlockTime GetBlockTime, + _ GetBlockTime, initialCandidatesInterval time.Duration, sh *Slasher, ) (Protocol, error) { if electionCommittee == nil { return nil, ErrNoElectionCommittee } - if getBlockTime == nil { - return nil, errors.New("getBlockTime api is not provided") - } h := hash.Hash160b([]byte(_protocolID)) addr, err := address.FromBytes(h[:]) @@ -59,7 +56,6 @@ func NewGovernanceChainCommitteeProtocol( return &governanceChainCommitteeProtocol{ electionCommittee: electionCommittee, initGravityChainHeight: initGravityChainHeight, - getBlockTime: getBlockTime, addr: addr, initialCandidatesInterval: initialCandidatesInterval, sh: sh, @@ -234,7 +230,8 @@ func (p *governanceChainCommitteeProtocol) getGravityHeight(ctx context.Context, rp := rolldpos.MustGetProtocol(protocol.MustGetRegistry(ctx)) epochNumber := rp.GetEpochNum(height) epochHeight := rp.GetEpochHeight(epochNumber) - blkTime, err := p.getBlockTime(epochHeight) + bcCtx := protocol.MustGetBlockchainCtx(ctx) + blkTime, err := bcCtx.GetBlockTime(epochHeight) if err != nil { return 0, err } diff --git a/action/protocol/poll/governance_protocol_test.go b/action/protocol/poll/governance_protocol_test.go index e93a5e5411..0e08786442 100644 --- a/action/protocol/poll/governance_protocol_test.go +++ b/action/protocol/poll/governance_protocol_test.go @@ -65,6 +65,12 @@ func initConstruct(ctrl *gomock.Controller) (Protocol, context.Context, protocol Tip: protocol.TipInfo{ Height: epochStartHeight - 1, }, + GetBlockHash: func(u uint64) (hash.Hash256, error) { + return hash.Hash256b([]byte{0}), nil + }, + GetBlockTime: func(h uint64) (time.Time, error) { + return time.Unix(1562382522, 0), nil + }, }, ), cfg.Genesis, diff --git a/action/protocol/poll/protocol.go b/action/protocol/poll/protocol.go index 257325288c..098d32d05c 100644 --- a/action/protocol/poll/protocol.go +++ b/action/protocol/poll/protocol.go @@ -133,10 +133,10 @@ func NewProtocol( getUnproductiveDelegate GetUnproductiveDelegate, electionCommittee committee.Committee, stakingProto *staking.Protocol, - getBlockTimeFunc GetBlockTime, + _ GetBlockTime, productivity Productivity, - getBlockHash evm.GetBlockHash, - getBlockTime evm.GetBlockTime, + _ evm.GetBlockHash, + _ evm.GetBlockTime, ) (Protocol, error) { if scheme != _rollDPoSScheme { return nil, nil @@ -184,7 +184,7 @@ func NewProtocol( candidateIndexer, electionCommittee, genesisConfig.GravityChainStartHeight, - getBlockTimeFunc, + nil, chainConfig.PollInitialCandidatesInterval, slasher, ) @@ -220,7 +220,7 @@ func NewProtocol( } return NewStakingCommand(stakingV1, stakingV2) case _modeConsortium: - return NewConsortiumCommittee(candidateIndexer, readContract, getBlockHash) + return NewConsortiumCommittee(candidateIndexer, readContract, nil) default: return nil, errors.Errorf("unsupported poll mode %s", genesisConfig.PollMode) } diff --git a/action/protocol/poll/staking_committee_test.go b/action/protocol/poll/staking_committee_test.go index f0d17f116e..0df2a0d0b5 100644 --- a/action/protocol/poll/staking_committee_test.go +++ b/action/protocol/poll/staking_committee_test.go @@ -180,6 +180,14 @@ func TestCreatePostSystemActions_StakingCommittee(t *testing.T) { psac, ok := p.(protocol.PostSystemActionsCreator) require.True(ok) ctx = protocol.WithFeatureWithHeightCtx(ctx) + ctx = protocol.WithBlockchainCtx(ctx, protocol.BlockchainCtx{ + GetBlockHash: func(uint64) (hash.Hash256, error) { + return hash.ZeroHash256, nil + }, + GetBlockTime: func(uint64) (time.Time, error) { + return time.Now(), nil + }, + }) elp, err := psac.CreatePostSystemActions(ctx, sr) require.NoError(err) require.Equal(1, len(elp)) @@ -331,6 +339,14 @@ func TestHandle_StakingCommittee(t *testing.T) { }, ) ctx4 = protocol.WithFeatureWithHeightCtx(ctx4) + ctx4 = protocol.WithBlockchainCtx(ctx4, protocol.BlockchainCtx{ + GetBlockHash: func(uint64) (hash.Hash256, error) { + return hash.ZeroHash256, nil + }, + GetBlockTime: func(uint64) (time.Time, error) { + return time.Now(), nil + }, + }) err = p4.Validate(ctx4, elp4, sm4) require.Contains(err.Error(), "the proposed delegate list length") }) @@ -361,6 +377,14 @@ func TestHandle_StakingCommittee(t *testing.T) { Caller: caller, }, ) + ctx5 = protocol.WithBlockchainCtx(ctx5, protocol.BlockchainCtx{ + GetBlockHash: func(uint64) (hash.Hash256, error) { + return hash.ZeroHash256, nil + }, + GetBlockTime: func(uint64) (time.Time, error) { + return time.Now(), nil + }, + }) err = p5.Validate(ctx5, elp5, sm5) require.Contains(err.Error(), "delegates are not as expected") }) diff --git a/api/coreservice.go b/api/coreservice.go index 1069f8822c..f276445c2f 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -211,7 +211,6 @@ type ( readCache *ReadCache actionRadio *ActionRadio apiStats *nodestats.APILocalStats - getBlockTime evm.GetBlockTime } // jobDesc provides a struct to get and store logs in core.LogsInRange @@ -275,7 +274,6 @@ func newCoreService( bfIndexer blockindex.BloomFilterIndexer, actPool actpool.ActPool, registry *protocol.Registry, - getBlockTime evm.GetBlockTime, opts ...Option, ) (CoreService, error) { if cfg == (Config{}) { @@ -300,7 +298,6 @@ func newCoreService( chainListener: NewChainListener(cfg.ListenerLimit), gs: gasstation.NewGasStation(chain, dao, cfg.GasStation), readCache: NewReadCache(), - getBlockTime: getBlockTime, } for _, opt := range opts { @@ -953,6 +950,10 @@ func (core *coreService) readState(ctx context.Context, p protocol.Protocol, hei } // TODO: need to complete the context + ctx, err := core.bc.Context(ctx) + if err != nil { + return nil, 0, err + } ctx = protocol.WithBlockCtx(ctx, protocol.BlockCtx{ BlockHeight: tipHeight, }) @@ -2008,6 +2009,11 @@ func (core *coreService) simulateExecution( ctx = protocol.WithFeatureCtx(protocol.WithBlockCtx(ctx, protocol.BlockCtx{ BlockHeight: height, })) + ctx, err = core.bc.Context(ctx) + if err != nil { + return nil, nil, status.Error(codes.Internal, err.Error()) + } + bcCtx := protocol.MustGetBlockchainCtx(ctx) if protocol.MustGetFeatureCtx(ctx).UseZeroNonceForFreshAccount { pendingNonce = state.PendingNonceConsideringFreshAccount() } else { @@ -2015,8 +2021,8 @@ func (core *coreService) simulateExecution( } elp.SetNonce(pendingNonce) ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: core.dao.GetBlockHash, - GetBlockTime: core.getBlockTime, + GetBlockHash: bcCtx.GetBlockHash, + GetBlockTime: bcCtx.GetBlockTime, DepositGasFunc: rewarding.DepositGas, }) return evm.SimulateExecution(ctx, ws, addr, elp, opts...) diff --git a/api/coreservice_test.go b/api/coreservice_test.go index b695b3ef57..fa242edb12 100644 --- a/api/coreservice_test.go +++ b/api/coreservice_test.go @@ -200,7 +200,7 @@ func setupTestCoreService() (CoreService, blockchain.Blockchain, blockdao.BlockD opts := []Option{WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error { return nil })} - svr, err := newCoreService(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, func(u uint64) (time.Time, error) { return time.Time{}, nil }, opts...) + svr, err := newCoreService(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, opts...) if err != nil { panic(err) } diff --git a/api/grpcserver_integrity_test.go b/api/grpcserver_integrity_test.go index e650f96286..e65ce3e041 100644 --- a/api/grpcserver_integrity_test.go +++ b/api/grpcserver_integrity_test.go @@ -2064,7 +2064,11 @@ func TestGrpcServer_GetEpochMetaIntegrity(t *testing.T) { } else if test.pollProtocolType == "governanceChainCommittee" { committee := mock_committee.NewMockCommittee(ctrl) mbc := mock_blockchain.NewMockBlockchain(ctrl) - mbc.EXPECT().Genesis().Return(cfg.genesis).Times(3) + mbc.EXPECT().Genesis().Return(cfg.genesis).AnyTimes() + mbc.EXPECT().Context(gomock.Any()).Return(protocol.WithBlockchainCtx(context.Background(), protocol.BlockchainCtx{ + GetBlockHash: func(uint64) (hash.Hash256, error) { return hash.ZeroHash256, nil }, + GetBlockTime: func(uint64) (time.Time, error) { return time.Now(), nil }, + }), nil).AnyTimes() indexer, err := poll.NewCandidateIndexer(db.NewMemKVStore()) require.NoError(err) slasher, _ := poll.NewSlasher( @@ -2123,9 +2127,9 @@ func TestGrpcServer_GetEpochMetaIntegrity(t *testing.T) { cfg.chain.PollInitialCandidatesInterval, slasher) require.NoError(pol.ForceRegister(registry)) - committee.EXPECT().HeightByTime(gomock.Any()).Return(test.epochData.GravityChainStartHeight, nil) + committee.EXPECT().HeightByTime(gomock.Any()).Return(test.epochData.GravityChainStartHeight, nil).AnyTimes() - mbc.EXPECT().TipHeight().Return(uint64(4)).Times(4) + mbc.EXPECT().TipHeight().Return(uint64(4)).AnyTimes() mbc.EXPECT().BlockHeaderByHeight(gomock.Any()).DoAndReturn(func(height uint64) (*block.Header, error) { if height > 0 && height <= 4 { pk := identityset.PrivateKey(int(height)) diff --git a/api/serverV2.go b/api/serverV2.go index 1916d666ff..64122a2a69 100644 --- a/api/serverV2.go +++ b/api/serverV2.go @@ -45,10 +45,10 @@ func NewServerV2( bfIndexer blockindex.BloomFilterIndexer, actPool actpool.ActPool, registry *protocol.Registry, - getBlockTime evm.GetBlockTime, + _ evm.GetBlockTime, // TODO: remove unused getBlockTime opts ...Option, ) (*ServerV2, error) { - coreAPI, err := newCoreService(cfg, chain, bs, sf, dao, indexer, bfIndexer, actPool, registry, getBlockTime, opts...) + coreAPI, err := newCoreService(cfg, chain, bs, sf, dao, indexer, bfIndexer, actPool, registry, opts...) if err != nil { return nil, err } diff --git a/api/serverV2_integrity_test.go b/api/serverV2_integrity_test.go index 3dbdcfe080..4d35225bd3 100644 --- a/api/serverV2_integrity_test.go +++ b/api/serverV2_integrity_test.go @@ -455,7 +455,7 @@ func createServerV2(cfg testConfig, needActPool bool) (*ServerV2, blockchain.Blo opts := []Option{WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error { return nil })} - svr, err := NewServerV2(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, func(u uint64) (time.Time, error) { return time.Time{}, nil }, opts...) + svr, err := NewServerV2(cfg.api, bc, nil, sf, dao, indexer, bfIndexer, ap, registry, nil, opts...) if err != nil { return nil, nil, nil, nil, nil, nil, "", err } diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index b314d951fc..0f863e0796 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -242,7 +242,6 @@ func (bc *blockchain) ChainAddress() string { func (bc *blockchain) Start(ctx context.Context) error { bc.mu.Lock() defer bc.mu.Unlock() - // pass registry to be used by state factory's initialization ctx = protocol.WithFeatureWithHeightCtx(genesis.WithGenesisContext( protocol.WithBlockchainCtx( @@ -250,6 +249,8 @@ func (bc *blockchain) Start(ctx context.Context) error { protocol.BlockchainCtx{ ChainID: bc.ChainID(), EvmNetworkID: bc.EvmNetworkID(), + GetBlockHash: bc.dao.GetBlockHash, + GetBlockTime: bc.getBlockTime, }, ), bc.genesis)) return bc.lifecycle.OnStart(ctx) @@ -406,7 +407,6 @@ func (bc *blockchain) context(ctx context.Context, height uint64) (context.Conte if err != nil { return nil, err } - ctx = genesis.WithGenesisContext( protocol.WithBlockchainCtx( ctx, @@ -414,6 +414,8 @@ func (bc *blockchain) context(ctx context.Context, height uint64) (context.Conte Tip: *tip, ChainID: bc.ChainID(), EvmNetworkID: bc.EvmNetworkID(), + GetBlockHash: bc.dao.GetBlockHash, + GetBlockTime: bc.getBlockTime, }, ), bc.genesis, @@ -575,3 +577,14 @@ func (bc *blockchain) emitToSubscribers(blk *block.Block) { } bc.pubSubManager.SendBlockToSubscribers(blk) } + +func (bc *blockchain) getBlockTime(height uint64) (time.Time, error) { + if height == 0 { + return time.Unix(bc.genesis.Timestamp, 0), nil + } + header, err := bc.dao.HeaderByHeight(height) + if err != nil { + return time.Time{}, err + } + return header.Timestamp(), nil +} diff --git a/chainservice/builder.go b/chainservice/builder.go index 71825d9cc3..2e692f229c 100644 --- a/chainservice/builder.go +++ b/chainservice/builder.go @@ -504,12 +504,12 @@ func (builder *Builder) createBlockchain(forSubChain, forTest bool) blockchain.B } else { chainOpts = append(chainOpts, blockchain.BlockValidatorOption(builder.cs.factory)) } - var mintOpts []factory.MintOption if builder.cfg.Consensus.Scheme == config.RollDPoSScheme { mintOpts = append(mintOpts, factory.WithTimeoutOption(builder.cfg.Chain.MintTimeout)) } - return blockchain.NewBlockchain(builder.cfg.Chain, builder.cfg.Genesis, builder.cs.blockdao, factory.NewMinter(builder.cs.factory, builder.cs.actpool, mintOpts...), chainOpts...) + minter := factory.NewMinter(builder.cs.factory, builder.cs.actpool, mintOpts...) + return blockchain.NewBlockchain(builder.cfg.Chain, builder.cfg.Genesis, builder.cs.blockdao, minter, chainOpts...) } func (builder *Builder) buildNodeInfoManager() error { @@ -702,14 +702,7 @@ func (builder *Builder) registerAccountProtocol() error { } func (builder *Builder) registerExecutionProtocol() error { - dao := builder.cs.BlockDAO() - return execution.NewProtocol(builder.cs.blockdao.GetBlockHash, rewarding.DepositGas, func(u uint64) (time.Time, error) { - header, err := dao.HeaderByHeight(u) - if err != nil { - return time.Time{}, err - } - return header.Timestamp(), nil - }).Register(builder.cs.registry) + return execution.NewProtocol(nil, rewarding.DepositGas, nil).Register(builder.cs.registry) } func (builder *Builder) registerRollDPoSProtocol() error { @@ -725,15 +718,7 @@ func (builder *Builder) registerRollDPoSProtocol() error { return err } factory := builder.cs.factory - dao := builder.cs.blockdao chain := builder.cs.chain - getBlockTime := func(height uint64) (time.Time, error) { - header, err := chain.BlockHeaderByHeight(height) - if err != nil { - return time.Time{}, err - } - return header.Timestamp(), nil - } pollProtocol, err := poll.NewProtocol( builder.cfg.Consensus.Scheme, builder.cfg.Chain, @@ -751,10 +736,10 @@ func (builder *Builder) registerRollDPoSProtocol() error { if err != nil { return nil, err } - + bcCtx := protocol.MustGetBlockchainCtx(ctx) ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ - GetBlockHash: dao.GetBlockHash, - GetBlockTime: getBlockTime, + GetBlockHash: bcCtx.GetBlockHash, + GetBlockTime: bcCtx.GetBlockTime, DepositGasFunc: rewarding.DepositGas, }) ws, err := factory.WorkingSet(ctx) @@ -769,21 +754,12 @@ func (builder *Builder) registerRollDPoSProtocol() error { candidatesutil.UnproductiveDelegateFromDB, builder.cs.electionCommittee, staking.FindProtocol(builder.cs.registry), - func(height uint64) (time.Time, error) { - header, err := chain.BlockHeaderByHeight(height) - if err != nil { - return time.Now(), errors.Wrapf( - err, "error when getting the block at height: %d", - height, - ) - } - return header.Timestamp(), nil - }, + nil, func(start, end uint64) (map[string]uint64, error) { return blockchain.Productivity(chain, start, end) }, - dao.GetBlockHash, - getBlockTime, + nil, + nil, ) if err != nil { return errors.Wrap(err, "failed to generate poll protocol") diff --git a/chainservice/chainservice.go b/chainservice/chainservice.go index 78571e3f2e..cd4f09d89b 100644 --- a/chainservice/chainservice.go +++ b/chainservice/chainservice.go @@ -7,7 +7,6 @@ package chainservice import ( "context" - "time" "github.com/libp2p/go-libp2p/core/peer" "github.com/pkg/errors" @@ -241,13 +240,7 @@ func (cs *ChainService) NewAPIServer(cfg api.Config, archive bool) (*api.ServerV cs.bfIndexer, cs.actpool, cs.registry, - func(u uint64) (time.Time, error) { - header, err := cs.chain.BlockHeaderByHeight(u) - if err != nil { - return time.Time{}, err - } - return header.Timestamp(), nil - }, + nil, apiServerOptions..., ) if err != nil { diff --git a/e2etest/local_test.go b/e2etest/local_test.go index 6e1f1533fc..d388f6ae08 100644 --- a/e2etest/local_test.go +++ b/e2etest/local_test.go @@ -64,6 +64,7 @@ func TestLocalCommit(t *testing.T) { testTriePath := cfg.Chain.TrieDBPath testDBPath := cfg.Chain.ChainDBPath indexDBPath := cfg.Chain.IndexDBPath + cfg.ActPool.Store = nil // create server ctx := genesis.WithGenesisContext(context.Background(), cfg.Genesis) @@ -454,6 +455,7 @@ func TestStartExistingBlockchain(t *testing.T) { cfg.Chain.BlobStoreDBPath = testBlobIndexPath cfg.Chain.ContractStakingIndexDBPath = testContractStakeIndexPath cfg.Chain.EnableAsyncIndexWrite = false + cfg.ActPool.Store = nil cfg.Genesis = genesis.TestDefault() cfg.ActPool.MinGasPriceStr = "0" cfg.Consensus.Scheme = config.NOOPScheme diff --git a/state/factory/factory_test.go b/state/factory/factory_test.go index 4d8c08defb..458eb81d6d 100644 --- a/state/factory/factory_test.go +++ b/state/factory/factory_test.go @@ -330,7 +330,9 @@ func testCandidates(sf Factory, t *testing.T) { }, ), protocol.BlockchainCtx{ - ChainID: 1, + ChainID: 1, + GetBlockHash: func(uint64) (hash.Hash256, error) { return hash.ZeroHash256, nil }, + GetBlockTime: func(uint64) (time.Time, error) { return time.Now(), nil }, }, ), ), diff --git a/tools/actioninjector.v2/internal/client/client_test.go b/tools/actioninjector.v2/internal/client/client_test.go index 29a4be0a80..a8cb674029 100644 --- a/tools/actioninjector.v2/internal/client/client_test.go +++ b/tools/actioninjector.v2/internal/client/client_test.go @@ -5,7 +5,6 @@ import ( "fmt" "math/big" "testing" - "time" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -86,7 +85,7 @@ func TestClient(t *testing.T) { require.NoError(err) bfIndexer, err := blockindex.NewBloomfilterIndexer(db.NewMemKVStore(), cfg.Indexer) require.NoError(err) - apiServer, err := api.NewServerV2(cfg.API, bc, nil, sf, nil, indexer, bfIndexer, ap, nil, func(u uint64) (time.Time, error) { return time.Time{}, nil }, newOption) + apiServer, err := api.NewServerV2(cfg.API, bc, nil, sf, nil, indexer, bfIndexer, ap, nil, nil, newOption) require.NoError(err) require.NoError(apiServer.Start(ctx)) // test New()