Skip to content

Commit 42613b1

Browse files
committed
remove unused
1 parent d8420af commit 42613b1

File tree

15 files changed

+18
-74
lines changed

15 files changed

+18
-74
lines changed

action/protocol/execution/protocol_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ func (sct *SmartContractTest) prepareBlockchain(
474474
r.NoError(err)
475475
dao := blockdao.NewBlockDAOWithIndexersAndCache(store, []blockdao.BlockIndexer{sf, indexer}, cfg.DB.MaxCacheSize)
476476
r.NotNil(dao)
477-
btcd := testutil.DummyBlockTimeBuilder()
478477
bc := blockchain.NewBlockchain(
479478
cfg.Chain,
480479
cfg.Genesis,
@@ -484,7 +483,6 @@ func (sct *SmartContractTest) prepareBlockchain(
484483
sf,
485484
protocol.NewGenericValidator(sf, accountutil.AccountState),
486485
)),
487-
blockchain.BlockTimeCalculatorBuilderOption(btcd),
488486
)
489487
reward := rewarding.NewProtocol(cfg.Genesis.Rewarding)
490488
r.NoError(reward.Register(registry))
@@ -737,7 +735,6 @@ func TestProtocol_Handle(t *testing.T) {
737735
sf,
738736
protocol.NewGenericValidator(sf, accountutil.AccountState),
739737
)),
740-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
741738
)
742739
exeProtocol := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, getBlockTimeForTest)
743740
require.NoError(exeProtocol.Register(registry))

api/serverV2_integrity_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ func setupChain(cfg testConfig) (blockchain.Blockchain, blockdao.BlockDAO, block
330330
sf,
331331
protocol.NewGenericValidator(sf, accountutil.AccountState),
332332
)),
333-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
334333
)
335334
if bc == nil {
336335
return nil, nil, nil, nil, nil, nil, nil, "", errors.New("failed to create blockchain")

blockchain/blockchain.go

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/iotexproject/iotex-core/v2/pkg/log"
3232
"github.com/iotexproject/iotex-core/v2/pkg/prometheustimer"
3333
"github.com/iotexproject/iotex-core/v2/pkg/unit"
34-
"github.com/iotexproject/iotex-core/v2/pkg/util/blockutil"
3534
)
3635

3736
// const
@@ -133,8 +132,7 @@ type (
133132
timerFactory *prometheustimer.TimerFactory
134133

135134
// used by account-based model
136-
bbf BlockBuilderFactory
137-
btcBuilder *blockutil.BlockTimeCalculatorBuilder
135+
bbf BlockBuilderFactory
138136
}
139137
)
140138

@@ -179,13 +177,6 @@ func ClockOption(clk clock.Clock) Option {
179177
}
180178
}
181179

182-
func BlockTimeCalculatorBuilderOption(builder *blockutil.BlockTimeCalculatorBuilder) Option {
183-
return func(bc *blockchain) error {
184-
bc.btcBuilder = builder
185-
return nil
186-
}
187-
}
188-
189180
type (
190181
BlockValidationCfg struct {
191182
skipSidecarValidation bool
@@ -229,9 +220,6 @@ func NewBlockchain(cfg Config, g genesis.Genesis, dao blockdao.BlockDAO, bbf Blo
229220
if chain.dao == nil {
230221
log.L().Panic("blockdao is nil")
231222
}
232-
if chain.btcBuilder == nil {
233-
log.L().Panic("block time calculator builder is nil")
234-
}
235223
chain.lifecycle.Add(chain.dao)
236224
chain.lifecycle.Add(chain.pubSubManager)
237225

@@ -254,10 +242,6 @@ func (bc *blockchain) ChainAddress() string {
254242
func (bc *blockchain) Start(ctx context.Context) error {
255243
bc.mu.Lock()
256244
defer bc.mu.Unlock()
257-
btc, err := bc.buildBlockTimeCalculator()
258-
if err != nil {
259-
return err
260-
}
261245
// pass registry to be used by state factory's initialization
262246
ctx = protocol.WithFeatureWithHeightCtx(genesis.WithGenesisContext(
263247
protocol.WithBlockchainCtx(
@@ -266,7 +250,7 @@ func (bc *blockchain) Start(ctx context.Context) error {
266250
ChainID: bc.ChainID(),
267251
EvmNetworkID: bc.EvmNetworkID(),
268252
GetBlockHash: bc.dao.GetBlockHash,
269-
GetBlockTime: btc.CalculateBlockTime,
253+
GetBlockTime: bc.getBlockTime,
270254
},
271255
), bc.genesis))
272256
return bc.lifecycle.OnStart(ctx)
@@ -423,10 +407,6 @@ func (bc *blockchain) context(ctx context.Context, height uint64) (context.Conte
423407
if err != nil {
424408
return nil, err
425409
}
426-
btc, err := bc.buildBlockTimeCalculator()
427-
if err != nil {
428-
return nil, err
429-
}
430410
ctx = genesis.WithGenesisContext(
431411
protocol.WithBlockchainCtx(
432412
ctx,
@@ -435,7 +415,7 @@ func (bc *blockchain) context(ctx context.Context, height uint64) (context.Conte
435415
ChainID: bc.ChainID(),
436416
EvmNetworkID: bc.EvmNetworkID(),
437417
GetBlockHash: bc.dao.GetBlockHash,
438-
GetBlockTime: btc.CalculateBlockTime,
418+
GetBlockTime: bc.getBlockTime,
439419
},
440420
),
441421
bc.genesis,
@@ -598,15 +578,13 @@ func (bc *blockchain) emitToSubscribers(blk *block.Block) {
598578
bc.pubSubManager.SendBlockToSubscribers(blk)
599579
}
600580

601-
func (bc *blockchain) buildBlockTimeCalculator() (*blockutil.BlockTimeCalculator, error) {
602-
return bc.btcBuilder.Clone().SetTipHeight(bc.TipHeight).SetHistoryBlockTime(func(height uint64) (time.Time, error) {
603-
if height == 0 {
604-
return time.Unix(bc.genesis.Timestamp, 0), nil
605-
}
606-
header, err := bc.dao.HeaderByHeight(height)
607-
if err != nil {
608-
return time.Time{}, err
609-
}
610-
return header.Timestamp(), nil
611-
}).Build()
581+
func (bc *blockchain) getBlockTime(height uint64) (time.Time, error) {
582+
if height == 0 {
583+
return time.Unix(bc.genesis.Timestamp, 0), nil
584+
}
585+
header, err := bc.dao.HeaderByHeight(height)
586+
if err != nil {
587+
return time.Time{}, err
588+
}
589+
return header.Timestamp(), nil
612590
}

blockchain/integrity/benchmark_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ func newChainInDB() (blockchain.Blockchain, actpool.ActPool, error) {
278278
sf,
279279
protocol.NewGenericValidator(sf, accountutil.AccountState),
280280
)),
281-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
282281
)
283282
if bc == nil {
284283
return nil, nil, errors.New("pointer is nil")

blockchain/integrity/integrity_test.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ func TestCreateBlockchain(t *testing.T) {
506506
sf,
507507
protocol.NewGenericValidator(sf, accountutil.AccountState),
508508
)),
509-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
510509
)
511510
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, fakeGetBlockTime)
512511
require.NoError(ep.Register(registry))
@@ -563,7 +562,6 @@ func TestGetBlockHash(t *testing.T) {
563562
sf,
564563
protocol.NewGenericValidator(sf, accountutil.AccountState),
565564
)),
566-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
567565
)
568566
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, fakeGetBlockTime)
569567
require.NoError(ep.Register(registry))
@@ -729,7 +727,6 @@ func TestBlockchain_MintNewBlock(t *testing.T) {
729727
sf,
730728
protocol.NewGenericValidator(sf, accountutil.AccountState),
731729
)),
732-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
733730
)
734731
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, fakeGetBlockTime)
735732
require.NoError(t, ep.Register(registry))
@@ -800,7 +797,6 @@ func TestBlockchain_MintNewBlock_PopAccount(t *testing.T) {
800797
sf,
801798
protocol.NewGenericValidator(sf, accountutil.AccountState),
802799
)),
803-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
804800
)
805801
rp := rolldpos.NewProtocol(cfg.Genesis.NumCandidateDelegates, cfg.Genesis.NumDelegates, cfg.Genesis.NumSubEpochs)
806802
require.NoError(t, rp.Register(registry))
@@ -944,7 +940,6 @@ func createChain(cfg config.Config, inMem bool) (blockchain.Blockchain, factory.
944940
sf,
945941
protocol.NewGenericValidator(sf, accountutil.AccountState),
946942
)),
947-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder().SetBlockInterval(func(height uint64) time.Duration { return time.Second })),
948943
)
949944
btc, err := blockutil.NewBlockTimeCalculator(func(uint64) time.Duration { return time.Second },
950945
bc.TipHeight, func(height uint64) (time.Time, error) {
@@ -1490,7 +1485,6 @@ func TestConstantinople(t *testing.T) {
14901485
sf,
14911486
protocol.NewGenericValidator(sf, accountutil.AccountState),
14921487
)),
1493-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
14941488
)
14951489
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, fakeGetBlockTime)
14961490
require.NoError(ep.Register(registry))
@@ -1745,7 +1739,6 @@ func TestLoadBlockchainfromDB(t *testing.T) {
17451739
sf,
17461740
protocol.NewGenericValidator(sf, accountutil.AccountState),
17471741
)),
1748-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
17491742
)
17501743
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, fakeGetBlockTime)
17511744
require.NoError(ep.Register(registry))
@@ -1775,7 +1768,6 @@ func TestLoadBlockchainfromDB(t *testing.T) {
17751768
sf,
17761769
protocol.NewGenericValidator(sf, accountutil.AccountState),
17771770
)),
1778-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
17791771
)
17801772
require.NoError(bc.Start(ctx))
17811773
defer func() {
@@ -2054,7 +2046,6 @@ func TestBlockchainInitialCandidate(t *testing.T) {
20542046
dao,
20552047
factory.NewMinter(sf, ap),
20562048
blockchain.BlockValidatorOption(sf),
2057-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
20582049
)
20592050
rolldposProtocol := rolldpos.NewProtocol(
20602051
cfg.Genesis.NumCandidateDelegates,
@@ -2096,7 +2087,7 @@ func TestBlockchain_AccountState(t *testing.T) {
20962087
store, err := filedao.NewFileDAOInMemForTest()
20972088
require.NoError(err)
20982089
dao := blockdao.NewBlockDAOWithIndexersAndCache(store, []blockdao.BlockIndexer{sf}, cfg.DB.MaxCacheSize)
2099-
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap), blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()))
2090+
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap))
21002091
require.NoError(bc.Start(ctx))
21012092
require.NotNil(bc)
21022093
defer func() {
@@ -2128,7 +2119,7 @@ func TestNewAccountAction(t *testing.T) {
21282119
store, err := filedao.NewFileDAOInMemForTest()
21292120
require.NoError(err)
21302121
dao := blockdao.NewBlockDAOWithIndexersAndCache(store, []blockdao.BlockIndexer{sf}, cfg.DB.MaxCacheSize)
2131-
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap), blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()))
2122+
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap))
21322123
require.NoError(bc.Start(ctx))
21332124
require.NotNil(bc)
21342125
defer func() {
@@ -2173,7 +2164,7 @@ func TestNewAccountAction(t *testing.T) {
21732164
store, err := filedao.NewFileDAOInMemForTest()
21742165
require.NoError(err)
21752166
dao1 := blockdao.NewBlockDAOWithIndexersAndCache(store, []blockdao.BlockIndexer{sf1}, cfg.DB.MaxCacheSize)
2176-
bc1 := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao1, factory.NewMinter(sf1, ap), blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()))
2167+
bc1 := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao1, factory.NewMinter(sf1, ap))
21772168
require.NoError(bc1.Start(ctx))
21782169
require.NotNil(bc1)
21792170
defer func() {
@@ -2242,7 +2233,7 @@ func TestBlocks(t *testing.T) {
22422233
dao := blockdao.NewBlockDAOWithIndexersAndCache(store, []blockdao.BlockIndexer{sf}, dbcfg.MaxCacheSize)
22432234

22442235
// Create a blockchain from scratch
2245-
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap), blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()))
2236+
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap))
22462237
require.NoError(bc.Start(context.Background()))
22472238
defer func() {
22482239
require.NoError(bc.Stop(context.Background()))
@@ -2325,7 +2316,6 @@ func TestActions(t *testing.T) {
23252316
sf,
23262317
protocol.NewGenericValidator(sf, accountutil.AccountState),
23272318
)),
2328-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
23292319
)
23302320
require.NoError(bc.Start(context.Background()))
23312321
defer func() {
@@ -2381,7 +2371,7 @@ func TestBlockchain_AddRemoveSubscriber(t *testing.T) {
23812371
store, err := filedao.NewFileDAOInMemForTest()
23822372
req.NoError(err)
23832373
dao := blockdao.NewBlockDAOWithIndexersAndCache(store, []blockdao.BlockIndexer{sf}, cfg.DB.MaxCacheSize)
2384-
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap), blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()))
2374+
bc := blockchain.NewBlockchain(cfg.Chain, cfg.Genesis, dao, factory.NewMinter(sf, ap))
23852375
// mock
23862376
ctrl := gomock.NewController(t)
23872377
mb := mock_blockcreationsubscriber.NewMockBlockCreationSubscriber(ctrl)
@@ -2621,7 +2611,6 @@ func newChain(t *testing.T, stateTX bool) (blockchain.Blockchain, factory.Factor
26212611
sf,
26222612
protocol.NewGenericValidator(sf, accountutil.AccountState),
26232613
)),
2624-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
26252614
)
26262615
require.NotNil(bc)
26272616
ep := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, fakeGetBlockTime)

blocksync/blocksync_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ func TestBlockSyncerProcessBlockTipHeight(t *testing.T) {
210210
dao,
211211
factory.NewMinter(sf, ap),
212212
blockchain.BlockValidatorOption(block.NewValidator(sf, ap)),
213-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
214213
)
215214
require.NoError(chain.Start(ctx))
216215
require.NotNil(chain)
@@ -277,7 +276,6 @@ func TestBlockSyncerProcessBlockOutOfOrder(t *testing.T) {
277276
dao,
278277
factory.NewMinter(sf, ap1),
279278
blockchain.BlockValidatorOption(block.NewValidator(sf, ap1)),
280-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
281279
)
282280
require.NotNil(chain1)
283281
require.NoError(chain1.Start(ctx))
@@ -305,7 +303,6 @@ func TestBlockSyncerProcessBlockOutOfOrder(t *testing.T) {
305303
dao2,
306304
factory.NewMinter(sf2, ap2),
307305
blockchain.BlockValidatorOption(block.NewValidator(sf2, ap2)),
308-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
309306
)
310307
require.NotNil(chain2)
311308
require.NoError(chain2.Start(ctx))
@@ -381,7 +378,6 @@ func TestBlockSyncerProcessBlock(t *testing.T) {
381378
dao,
382379
factory.NewMinter(sf, ap1),
383380
blockchain.BlockValidatorOption(block.NewValidator(sf, ap1)),
384-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
385381
)
386382
require.NoError(chain1.Start(ctx))
387383
require.NotNil(chain1)
@@ -408,7 +404,6 @@ func TestBlockSyncerProcessBlock(t *testing.T) {
408404
dao2,
409405
factory.NewMinter(sf2, ap2),
410406
blockchain.BlockValidatorOption(block.NewValidator(sf2, ap2)),
411-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
412407
)
413408
require.NoError(chain2.Start(ctx))
414409
require.NotNil(chain2)
@@ -477,7 +472,6 @@ func TestBlockSyncerSync(t *testing.T) {
477472
dao,
478473
factory.NewMinter(sf, ap),
479474
blockchain.BlockValidatorOption(block.NewValidator(sf, ap)),
480-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
481475
)
482476
require.NoError(chain.Start(ctx))
483477
require.NotNil(chain)

blocksync/buffer_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func TestBlockBufferFlush(t *testing.T) {
5757
dao,
5858
factory.NewMinter(sf, ap),
5959
blockchain.BlockValidatorOption(block.NewValidator(sf, ap)),
60-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
6160
)
6261
require.NoError(chain.Start(ctx))
6362
require.NotNil(chain)
@@ -151,7 +150,6 @@ func TestBlockBufferGetBlocksIntervalsToSync(t *testing.T) {
151150
cfg.Genesis,
152151
dao,
153152
factory.NewMinter(sf, ap),
154-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
155153
)
156154
require.NotNil(chain)
157155
require.NoError(chain.Start(ctx))

chainservice/builder.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"github.com/iotexproject/iotex-core/v2/nodeinfo"
4848
"github.com/iotexproject/iotex-core/v2/p2p"
4949
"github.com/iotexproject/iotex-core/v2/pkg/log"
50-
"github.com/iotexproject/iotex-core/v2/pkg/util/blockutil"
5150
"github.com/iotexproject/iotex-core/v2/server/itx/nodestats"
5251
"github.com/iotexproject/iotex-core/v2/state/factory"
5352
"github.com/iotexproject/iotex-core/v2/systemcontractindex/stakingindex"
@@ -505,8 +504,7 @@ func (builder *Builder) createBlockchain(forSubChain, forTest bool) blockchain.B
505504
} else {
506505
chainOpts = append(chainOpts, blockchain.BlockValidatorOption(builder.cs.factory))
507506
}
508-
consensusCfg := consensusfsm.NewConsensusConfig(builder.cfg.Consensus.RollDPoS.FSM, builder.cfg.DardanellesUpgrade, builder.cfg.Genesis, builder.cfg.Consensus.RollDPoS.Delay)
509-
chainOpts = append(chainOpts, blockchain.BlockTimeCalculatorBuilderOption(blockutil.NewBlockTimeCalculatorBuilder().SetBlockInterval(consensusCfg.BlockInterval)))
507+
chainOpts = append(chainOpts)
510508
var mintOpts []factory.MintOption
511509
if builder.cfg.Consensus.Scheme == config.RollDPoSScheme {
512510
mintOpts = append(mintOpts, factory.WithTimeoutOption(builder.cfg.Chain.MintTimeout))

consensus/scheme/rolldpos/rolldpos_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ func TestRollDPoSConsensus(t *testing.T) {
468468
sf,
469469
protocol.NewGenericValidator(sf, accountutil.AccountState),
470470
)),
471-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
472471
)
473472
chains = append(chains, chain)
474473

consensus/scheme/rolldpos/roundcalculator_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ func makeChain(t *testing.T) (blockchain.Blockchain, factory.Factory, actpool.Ac
198198
sf,
199199
protocol.NewGenericValidator(sf, accountutil.AccountState),
200200
)),
201-
blockchain.BlockTimeCalculatorBuilderOption(testutil.DummyBlockTimeBuilder()),
202201
)
203202
rolldposProtocol := rolldpos.NewProtocol(
204203
g.NumCandidateDelegates,

0 commit comments

Comments
 (0)