Skip to content

Commit

Permalink
Merge branch 'master' into dev_node_delegate_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderZhi authored Jun 25, 2022
2 parents ec3cf13 + e3afa71 commit c61ae2d
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 58 deletions.
25 changes: 0 additions & 25 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,35 +145,10 @@ func BlockValidatorOption(blockValidator block.Validator) Option {
}
}

// BoltDBDaoOption sets blockchain's dao with BoltDB from config.Chain.ChainDBPath
func BoltDBDaoOption(indexers ...blockdao.BlockIndexer) Option {
return func(bc *blockchain, cfg config.Config) error {
if bc.dao != nil {
return nil
}
cfg.DB.DbPath = cfg.Chain.ChainDBPath // TODO: remove this after moving TrieDBPath from cfg.Chain to cfg.DB
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
bc.dao = blockdao.NewBlockDAO(indexers, cfg.DB)
return nil
}
}

// InMemDaoOption sets blockchain's dao with MemKVStore
func InMemDaoOption(indexers ...blockdao.BlockIndexer) Option {
return func(bc *blockchain, cfg config.Config) error {
if bc.dao != nil {
return nil
}
bc.dao = blockdao.NewBlockDAOInMemForTest(indexers)
return nil
}
}

// ClockOption overrides the default clock
func ClockOption(clk clock.Clock) Option {
return func(bc *blockchain, conf config.Config) error {
bc.clk = clk

return nil
}
}
Expand Down
1 change: 0 additions & 1 deletion blockchain/integrity/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func newChainInDB() (blockchain.Blockchain, actpool.ActPool, error) {
cfg.Genesis.InitBalanceMap[identityset.Address(27).String()] = unit.ConvertIotxToRau(1000000000000).String()
// create BlockDAO
cfg.DB.DbPath = cfg.Chain.ChainDBPath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
dao := blockdao.NewBlockDAO(indexers, cfg.DB)
if dao == nil {
return nil, nil, errors.New("pointer is nil")
Expand Down
26 changes: 16 additions & 10 deletions blockchain/integrity/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ func TestConstantinople(t *testing.T) {
require.NoError(err)
// create BlockDAO
cfg.DB.DbPath = cfg.Chain.ChainDBPath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
dao := blockdao.NewBlockDAO([]blockdao.BlockIndexer{sf, indexer}, cfg.DB)
require.NotNil(dao)
bc := blockchain.NewBlockchain(
Expand Down Expand Up @@ -1112,7 +1111,6 @@ func TestLoadBlockchainfromDB(t *testing.T) {
cfg.Genesis.InitBalanceMap[identityset.Address(27).String()] = unit.ConvertIotxToRau(10000000000).String()
// create BlockDAO
cfg.DB.DbPath = cfg.Chain.ChainDBPath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
dao := blockdao.NewBlockDAO(indexers, cfg.DB)
require.NotNil(dao)
bc := blockchain.NewBlockchain(
Expand Down Expand Up @@ -1409,11 +1407,13 @@ func TestBlockchainInitialCandidate(t *testing.T) {
require.NoError(err)
accountProtocol := account.NewProtocol(rewarding.DepositGas)
require.NoError(accountProtocol.Register(registry))
dbcfg := cfg.DB
dbcfg.DbPath = cfg.Chain.ChainDBPath
dao := blockdao.NewBlockDAO([]blockdao.BlockIndexer{sf}, dbcfg)
bc := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf, ap),
blockchain.BoltDBDaoOption(sf),
blockchain.BlockValidatorOption(sf),
)
rolldposProtocol := rolldpos.NewProtocol(
Expand Down Expand Up @@ -1453,7 +1453,8 @@ func TestBlockchain_AccountState(t *testing.T) {
require.NoError(err)
ap, err := actpool.NewActPool(sf, cfg.ActPool)
require.NoError(err)
bc := blockchain.NewBlockchain(cfg, nil, factory.NewMinter(sf, ap), blockchain.InMemDaoOption(sf))
dao := blockdao.NewBlockDAOInMemForTest([]blockdao.BlockIndexer{sf})
bc := blockchain.NewBlockchain(cfg, dao, factory.NewMinter(sf, ap))
require.NoError(bc.Start(context.Background()))
require.NotNil(bc)
s, err := accountutil.AccountState(sf, identityset.Address(0))
Expand Down Expand Up @@ -1495,9 +1496,12 @@ func TestBlocks(t *testing.T) {
require.NoError(err)
ap, err := actpool.NewActPool(sf, cfg.ActPool)
require.NoError(err)
dbcfg := cfg.DB
dbcfg.DbPath = cfg.Chain.ChainDBPath
dao := blockdao.NewBlockDAO([]blockdao.BlockIndexer{sf}, dbcfg)

// Create a blockchain from scratch
bc := blockchain.NewBlockchain(cfg, nil, factory.NewMinter(sf, ap), blockchain.BoltDBDaoOption(sf))
bc := blockchain.NewBlockchain(cfg, dao, factory.NewMinter(sf, ap))
require.NoError(bc.Start(context.Background()))
defer func() {
require.NoError(bc.Stop(context.Background()))
Expand Down Expand Up @@ -1564,12 +1568,14 @@ func TestActions(t *testing.T) {
require.NoError(err)
ap, err := actpool.NewActPool(sf, cfg.ActPool)
require.NoError(err)
dbcfg := cfg.DB
dbcfg.DbPath = cfg.Chain.ChainDBPath
dao := blockdao.NewBlockDAO([]blockdao.BlockIndexer{sf}, dbcfg)
// Create a blockchain from scratch
bc := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf, ap),
blockchain.BoltDBDaoOption(sf),
blockchain.BlockValidatorOption(block.NewValidator(
sf,
protocol.NewGenericValidator(sf, accountutil.AccountState),
Expand Down Expand Up @@ -1624,7 +1630,8 @@ func TestBlockchain_AddRemoveSubscriber(t *testing.T) {
req.NoError(err)
ap, err := actpool.NewActPool(sf, cfg.ActPool)
req.NoError(err)
bc := blockchain.NewBlockchain(cfg, nil, factory.NewMinter(sf, ap), blockchain.InMemDaoOption(sf))
dao := blockdao.NewBlockDAOInMemForTest([]blockdao.BlockIndexer{sf})
bc := blockchain.NewBlockchain(cfg, dao, factory.NewMinter(sf, ap))
// mock
ctrl := gomock.NewController(t)
mb := mock_blockcreationsubscriber.NewMockBlockCreationSubscriber(ctrl)
Expand Down Expand Up @@ -1848,7 +1855,6 @@ func newChain(t *testing.T, stateTX bool) (blockchain.Blockchain, factory.Factor
cfg.Genesis.InitBalanceMap[identityset.Address(27).String()] = unit.ConvertIotxToRau(10000000000).String()
// create BlockDAO
cfg.DB.DbPath = cfg.Chain.ChainDBPath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
dao := blockdao.NewBlockDAO(indexers, cfg.DB)
require.NotNil(dao)
bc := blockchain.NewBlockchain(
Expand Down
9 changes: 5 additions & 4 deletions blocksync/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/iotexproject/iotex-core/actpool"
"github.com/iotexproject/iotex-core/blockchain"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/blockdao"
"github.com/iotexproject/iotex-core/state/factory"
"github.com/iotexproject/iotex-core/test/identityset"
"github.com/iotexproject/iotex-core/testutil"
Expand All @@ -45,11 +46,11 @@ func TestBlockBufferFlush(t *testing.T) {
require.NotNil(ap)
require.NoError(err)
ap.AddActionEnvelopeValidators(protocol.NewGenericValidator(sf, accountutil.AccountState))
dao := blockdao.NewBlockDAOInMemForTest([]blockdao.BlockIndexer{sf})
chain := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf, ap),
blockchain.InMemDaoOption(sf),
blockchain.BlockValidatorOption(block.NewValidator(sf, ap)),
)
require.NoError(chain.Start(ctx))
Expand Down Expand Up @@ -135,11 +136,11 @@ func TestBlockBufferGetBlocksIntervalsToSync(t *testing.T) {
ap, err := actpool.NewActPool(sf, cfg.ActPool, actpool.EnableExperimentalActions())
require.NotNil(ap)
require.NoError(err)
dao := blockdao.NewBlockDAOInMemForTest([]blockdao.BlockIndexer{sf})
chain := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf, ap),
blockchain.InMemDaoOption(sf),
)
require.NotNil(chain)
require.NoError(chain.Start(ctx))
Expand Down
2 changes: 0 additions & 2 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ func (builder *Builder) buildBlockDAO(forTest bool) error {
} else {
dbConfig := builder.cfg.DB
dbConfig.DbPath = builder.cfg.Chain.ChainDBPath
dbConfig.CompressLegacy = builder.cfg.Chain.CompressBlock

builder.cs.blockdao = blockdao.NewBlockDAO(indexers, dbConfig)
}

Expand Down
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ var (
EnableSystemLogIndexer: false,
EnableStakingProtocol: true,
EnableStakingIndexer: false,
CompressBlock: false,
AllowedBlockGasResidue: 10000,
MaxCacheSize: 0,
PollInitialCandidatesInterval: 10 * time.Second,
Expand Down Expand Up @@ -239,8 +238,6 @@ type (
EnableStakingProtocol bool `yaml:"enableStakingProtocol"`
// EnableStakingIndexer enables staking indexer
EnableStakingIndexer bool `yaml:"enableStakingIndexer"`
// deprecated by DB.CompressBlock
CompressBlock bool `yaml:"compressBlock"`
// AllowedBlockGasResidue is the amount of gas remained when block producer could stop processing more actions
AllowedBlockGasResidue uint64 `yaml:"allowedBlockGasResidue"`
// MaxCacheSize is the max number of blocks that will be put into an LRU cache. 0 means disabled
Expand Down
5 changes: 3 additions & 2 deletions consensus/scheme/rolldpos/rolldpos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/iotexproject/iotex-core/actpool"
"github.com/iotexproject/iotex-core/blockchain"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/blockdao"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
cp "github.com/iotexproject/iotex-core/crypto"
Expand Down Expand Up @@ -417,11 +418,11 @@ func TestRollDPoSConsensus(t *testing.T) {
require.NoError(t, acc.Register(registry))
rp := rolldpos.NewProtocol(cfg.Genesis.NumCandidateDelegates, cfg.Genesis.NumDelegates, cfg.Genesis.NumSubEpochs)
require.NoError(t, rp.Register(registry))
dao := blockdao.NewBlockDAOInMemForTest([]blockdao.BlockIndexer{sf})
chain := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf, actPool),
blockchain.InMemDaoOption(sf),
blockchain.BlockValidatorOption(block.NewValidator(
sf,
protocol.NewGenericValidator(sf, accountutil.AccountState),
Expand Down
7 changes: 5 additions & 2 deletions consensus/scheme/rolldpos/roundcalculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/iotexproject/iotex-core/actpool"
"github.com/iotexproject/iotex-core/blockchain"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/blockdao"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/pkg/unit"
Expand Down Expand Up @@ -183,11 +184,13 @@ func makeChain(t *testing.T) (blockchain.Blockchain, factory.Factory, actpool.Ac
require.NoError(err)
ap, err := actpool.NewActPool(sf, cfg.ActPool)
require.NoError(err)
dbcfg := cfg.DB
dbcfg.DbPath = cfg.Chain.ChainDBPath
dao := blockdao.NewBlockDAO([]blockdao.BlockIndexer{sf}, dbcfg)
chain := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf, ap),
blockchain.BoltDBDaoOption(sf),
blockchain.BlockValidatorOption(block.NewValidator(
sf,
protocol.NewGenericValidator(sf, accountutil.AccountState),
Expand Down
8 changes: 4 additions & 4 deletions e2etest/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ func TestLocalCommit(t *testing.T) {
require.NoError(err)
ap2, err := actpool.NewActPool(sf2, cfg.ActPool)
require.NoError(err)
dbcfg := cfg.DB
dbcfg.DbPath = cfg.Chain.ChainDBPath
dao := blockdao.NewBlockDAO([]blockdao.BlockIndexer{sf2}, dbcfg)
chain := blockchain.NewBlockchain(
cfg,
nil,
dao,
factory.NewMinter(sf2, ap2),
blockchain.BoltDBDaoOption(sf2),
blockchain.BlockValidatorOption(block.NewValidator(
sf2,
protocol.NewGenericValidator(sf2, accountutil.AccountState),
Expand Down Expand Up @@ -474,7 +476,6 @@ func TestStartExistingBlockchain(t *testing.T) {

// Recover to height 3 from empty state DB
cfg.DB.DbPath = cfg.Chain.ChainDBPath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
dao := blockdao.NewBlockDAO(nil, cfg.DB)
require.NoError(dao.Start(protocol.WithBlockchainCtx(
genesis.WithGenesisContext(ctx, cfg.Genesis),
Expand All @@ -497,7 +498,6 @@ func TestStartExistingBlockchain(t *testing.T) {
// Recover to height 2 from an existing state DB with Height 3
require.NoError(svr.Stop(ctx))
cfg.DB.DbPath = cfg.Chain.ChainDBPath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
dao = blockdao.NewBlockDAO(nil, cfg.DB)
require.NoError(dao.Start(protocol.WithBlockchainCtx(
genesis.WithGenesisContext(ctx, cfg.Genesis),
Expand Down
3 changes: 1 addition & 2 deletions e2etest/rewarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ func newConfig(
cfg.Chain.ChainDBPath = chainDBPath
cfg.Chain.TrieDBPath = trieDBPath
cfg.Chain.IndexDBPath = indexDBPath
cfg.Chain.CompressBlock = true
cfg.Chain.ProducerPrivKey = producerPriKey.HexString()
cfg.Chain.EnableAsyncIndexWrite = false

Expand All @@ -607,9 +606,9 @@ func newConfig(
cfg.Genesis.Blockchain.NumDelegates = numNodes
cfg.Genesis.Blockchain.TimeBasedRotation = true
cfg.Genesis.Delegates = cfg.Genesis.Delegates[0:numNodes]

cfg.Genesis.BlockInterval = 500 * time.Millisecond
cfg.Genesis.EnableGravityChainVoting = true
cfg.Genesis.Rewarding.FoundationBonusLastEpoch = 2

return cfg
}
1 change: 0 additions & 1 deletion tools/iomigrater/cmds/check-height.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func checkDbFileHeight(filePath string) (uint64, error) {
}

cfg.DB.DbPath = filePath
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
blockDao := blockdao.NewBlockDAO(nil, cfg.DB)

// Load height value.
Expand Down
1 change: 0 additions & 1 deletion tools/iomigrater/cmds/migrate-db.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func migrateDbFile() error {
}

cfg.DB.DbPath = oldFile
cfg.DB.CompressLegacy = cfg.Chain.CompressBlock
oldDAO := blockdao.NewBlockDAO(nil, cfg.DB)

cfg.DB.DbPath = newFile
Expand Down
2 changes: 1 addition & 1 deletion tools/minicluster/minicluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ func newConfig(
cfg.Network.BootstrapNodes = []string{"/ip4/127.0.0.1/tcp/4689/ipfs/12D3KooWJwW6pUpTkxPTMv84RPLPMQVEAjZ6fvJuX4oZrvW5DAGQ"}

cfg.Chain.ID = 1
cfg.Chain.CompressBlock = true
cfg.Chain.ProducerPrivKey = producerPriKey.HexString()

cfg.ActPool.MinGasPriceStr = big.NewInt(0).String()
Expand All @@ -438,5 +437,6 @@ func newConfig(
cfg.Genesis.Delegates = cfg.Genesis.Delegates[3 : _numNodes+3]
cfg.Genesis.EnableGravityChainVoting = false
cfg.Genesis.PollMode = "lifeLong"

return cfg
}

0 comments on commit c61ae2d

Please sign in to comment.