Skip to content

Commit

Permalink
[config] Clean up config (#3492)
Browse files Browse the repository at this point in the history
* clean up config
  • Loading branch information
Liuhaai authored Jul 5, 2022
1 parent 91fd545 commit 4e397d3
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 55 deletions.
3 changes: 1 addition & 2 deletions action/protocol/account/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util"
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/identityset"
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestProtocol_Initialize(t *testing.T) {
return 0, nil
}).AnyTimes()

ge := config.Default.Genesis
ge := genesis.Default
ge.Account.InitBalanceMap = map[string]string{
identityset.Address(0).String(): "100",
}
Expand Down
5 changes: 2 additions & 3 deletions action/protocol/account/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/identityset"
"github.com/iotexproject/iotex-core/testutil"
Expand Down Expand Up @@ -63,12 +62,12 @@ func TestProtocol_HandleTransfer(t *testing.T) {

// set-up protocol and genesis states
p := NewProtocol(rewarding.DepositGas)
reward := rewarding.NewProtocol(config.Default.Genesis.Rewarding)
reward := rewarding.NewProtocol(genesis.Default.Rewarding)
registry := protocol.NewRegistry()
require.NoError(reward.Register(registry))
chainCtx := genesis.WithGenesisContext(
protocol.WithRegistry(context.Background(), registry),
config.Default.Genesis,
genesis.Default,
)
ctx := protocol.WithBlockCtx(chainCtx, protocol.BlockCtx{})
ctx = protocol.WithFeatureCtx(ctx)
Expand Down
7 changes: 3 additions & 4 deletions action/protocol/generic_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/identityset"
)
Expand Down Expand Up @@ -53,13 +52,13 @@ func TestActionProtoAndGenericValidator(t *testing.T) {
BlockchainCtx{
Tip: TipInfo{
Height: 0,
Hash: config.Default.Genesis.Hash(),
Timestamp: time.Unix(config.Default.Genesis.Timestamp, 0),
Hash: genesis.Default.Hash(),
Timestamp: time.Unix(genesis.Default.Timestamp, 0),
},
},
)

ctx = WithFeatureCtx(genesis.WithGenesisContext(ctx, config.Default.Genesis))
ctx = WithFeatureCtx(genesis.WithGenesisContext(ctx, genesis.Default))

valid := NewGenericValidator(nil, func(_ context.Context, sr StateReader, addr address.Address) (*state.Account, error) {
pk := identityset.PrivateKey(27).PublicKey()
Expand Down
5 changes: 2 additions & 3 deletions action/protocol/poll/lifelong_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import (
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/rolldpos"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/state"
"github.com/iotexproject/iotex-core/test/mock/mock_chainmanager"
)

func initLifeLongDelegateProtocol(ctrl *gomock.Controller) (Protocol, context.Context, protocol.StateManager, error) {
genesisConfig := config.Default.Genesis
genesisConfig := genesis.Default
delegates := genesisConfig.Delegates
p := NewLifeLongDelegatesProtocol(delegates)
registry := protocol.NewRegistry()
Expand All @@ -33,7 +32,7 @@ func initLifeLongDelegateProtocol(ctrl *gomock.Controller) (Protocol, context.Co
}
ctx := genesis.WithGenesisContext(
protocol.WithRegistry(context.Background(), registry),
config.Default.Genesis,
genesis.Default,
)
ctx = protocol.WithActionCtx(
ctx,
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/poll/staking_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func initConstructStakingCommittee(ctrl *gomock.Controller) (Protocol, context.C
}
ctx = genesis.WithGenesisContext(
protocol.WithRegistry(ctx, registry),
config.Default.Genesis,
genesis.Default,
)
ctx = protocol.WithBlockchainCtx(ctx, protocol.BlockchainCtx{})
ctx = protocol.WithActionCtx(
Expand Down
9 changes: 4 additions & 5 deletions action/protocol/rewarding/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/iotexproject/iotex-core/action/protocol/poll"
"github.com/iotexproject/iotex-core/action/protocol/rolldpos"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/pkg/unit"
"github.com/iotexproject/iotex-core/state"
Expand All @@ -38,7 +37,7 @@ import (
func TestValidateExtension(t *testing.T) {
r := require.New(t)

g := config.Default.Genesis.Rewarding
g := genesis.Default.Rewarding
r.NoError(validateFoundationBonusExtension(g))

last := g.FoundationBonusP2StartEpoch
Expand All @@ -58,7 +57,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
registry := protocol.NewRegistry()
sm := testdb.NewMockStateManager(ctrl)

g := config.Default.Genesis
g := genesis.Default
// Create a test account with 1000 token
g.InitBalanceMap[identityset.Address(28).String()] = "1000"
g.Rewarding.InitBalanceStr = "0"
Expand Down Expand Up @@ -220,7 +219,7 @@ func testProtocol(t *testing.T, test func(*testing.T, context.Context, protocol.
}

func TestProtocol_Validate(t *testing.T) {
g := config.Default.Genesis
g := genesis.Default
g.NewfoundlandBlockHeight = 0
p := NewProtocol(g.Rewarding)
act := createGrantRewardAction(0, uint64(0)).Action()
Expand Down Expand Up @@ -274,7 +273,7 @@ func TestProtocol_Validate(t *testing.T) {
func TestProtocol_Handle(t *testing.T) {
ctrl := gomock.NewController(t)

g := config.Default.Genesis
g := genesis.Default
registry := protocol.NewRegistry()
sm := mock_chainmanager.NewMockStateManager(ctrl)
cb := batch.NewCachedBatch()
Expand Down
2 changes: 1 addition & 1 deletion action/protocol/rewarding/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func TestProtocol_NoRewardAddr(t *testing.T) {
}).AnyTimes()
sm.EXPECT().Height().Return(uint64(1), nil).AnyTimes()

ge := config.Default.Genesis
ge := genesis.Default
ge.Rewarding.InitBalanceStr = "0"
ge.Rewarding.BlockRewardStr = "10"
ge.Rewarding.EpochRewardStr = "100"
Expand Down
3 changes: 1 addition & 2 deletions blockchain/block/genesis_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/pkg/version"
)

func TestGenesisBlock(t *testing.T) {
r := require.New(t)

g := config.Default.Genesis
g := genesis.Default
genesis.SetGenesisTimestamp(g.Timestamp)
blk := GenesisBlock()
r.EqualValues(version.ProtocolVersion, blk.Version())
Expand Down
8 changes: 4 additions & 4 deletions blockchain/blockdao/blockdao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestBlockDAO(t *testing.T) {

testBlockDao := func(dao BlockDAO, t *testing.T) {
ctx := protocol.WithBlockchainCtx(
genesis.WithGenesisContext(context.Background(), config.Default.Genesis),
genesis.WithGenesisContext(context.Background(), genesis.Default),
protocol.BlockchainCtx{
ChainID: config.Default.Chain.ID,
})
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestBlockDAO(t *testing.T) {

testDeleteDao := func(dao BlockDAO, t *testing.T) {
ctx := protocol.WithBlockchainCtx(
genesis.WithGenesisContext(context.Background(), config.Default.Genesis),
genesis.WithGenesisContext(context.Background(), genesis.Default),
protocol.BlockchainCtx{
ChainID: config.Default.Chain.ID,
})
Expand Down Expand Up @@ -414,8 +414,8 @@ func TestBlockDAO(t *testing.T) {

cfg := db.DefaultConfig
cfg.DbPath = testPath
genesis.SetGenesisTimestamp(config.Default.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
genesis.SetGenesisTimestamp(genesis.Default.Timestamp)
block.LoadGenesisHash(&genesis.Default)
for _, v := range daoList {
testutil.CleanupPath(testPath)
dao, err := createTestBlockDAO(v.inMemory, v.legacy, v.compressBlock, cfg)
Expand Down
4 changes: 2 additions & 2 deletions blockchain/filedao/filedao_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func TestFileDAOLegacy_PutBlock(t *testing.T) {

cfg := db.DefaultConfig
cfg.DbPath = testPath
genesis.SetGenesisTimestamp(config.Default.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
genesis.SetGenesisTimestamp(genesis.Default.Timestamp)
block.LoadGenesisHash(&genesis.Default)
for _, compress := range []bool{false, true} {
cfg.CompressLegacy = compress
t.Run("test fileDAOLegacy interface", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions blockchain/filedao/filedao_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ func TestNewFdInterface(t *testing.T) {
deser := block.NewDeserializer(config.Default.Chain.EVMNetworkID)
_, err = newFileDAOv2(0, cfg, deser)
r.Equal(ErrNotSupported, err)
genesis.SetGenesisTimestamp(config.Default.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
genesis.SetGenesisTimestamp(genesis.Default.Timestamp)
block.LoadGenesisHash(&genesis.Default)

for _, compress := range []string{"", compress.Snappy} {
for _, start := range []uint64{1, 5, _blockStoreBatchSize + 1, 4 * _blockStoreBatchSize} {
Expand Down
3 changes: 2 additions & 1 deletion blockchain/filedao/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db"
"github.com/iotexproject/iotex-core/db/batch"
Expand Down Expand Up @@ -223,7 +224,7 @@ func testVerifyChainDB(t *testing.T, fd FileDAO, start, end uint64) {
}

func createTestingBlock(builder *block.TestingBuilder, height uint64, h hash.Hash256) *block.Block {
block.LoadGenesisHash(&config.Default.Genesis)
block.LoadGenesisHash(&genesis.Default)
r := &action.Receipt{
Status: 1,
BlockHeight: height,
Expand Down
3 changes: 2 additions & 1 deletion blockchain/integrity/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"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/blockindex"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db"
Expand Down Expand Up @@ -220,7 +221,7 @@ func newChainInDB() (blockchain.Blockchain, actpool.ActPool, error) {
cfg.Chain.IndexDBPath = testIndexPath
cfg.Chain.EnableArchiveMode = true
cfg.Consensus.Scheme = config.RollDPoSScheme
cfg.Genesis.BlockGasLimit = config.Default.Genesis.BlockGasLimit * 100
cfg.Genesis.BlockGasLimit = genesis.Default.BlockGasLimit * 100
cfg.ActPool.MinGasPriceStr = "0"
cfg.ActPool.MaxNumActsPerAcct = 1000000000
cfg.Genesis.EnableGravityChainVoting = false
Expand Down
4 changes: 2 additions & 2 deletions blockchain/integrity/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestGetBlockHash(t *testing.T) {
cfg.Genesis.MidwayBlockHeight = 9
cfg.ActPool.MinGasPriceStr = "0"
genesis.SetGenesisTimestamp(cfg.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
block.LoadGenesisHash(&genesis.Default)
// create chain
registry := protocol.NewRegistry()
acc := account.NewProtocol(rewarding.DepositGas)
Expand Down Expand Up @@ -1323,7 +1323,7 @@ func TestLoadBlockchainfromDB(t *testing.T) {
cfg.Genesis.EnableGravityChainVoting = false
cfg.ActPool.MinGasPriceStr = "0"
genesis.SetGenesisTimestamp(cfg.Genesis.Timestamp)
block.LoadGenesisHash(&config.Default.Genesis)
block.LoadGenesisHash(&genesis.Default)

t.Run("load blockchain from DB w/o explorer", func(t *testing.T) {
testValidateBlockchain(cfg, t)
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ type (
// Config is the root config struct, each package's config should be put as its sub struct
Config struct {
Plugins map[int]interface{} `ymal:"plugins"`
Network p2p.Network `yaml:"network"`
Network p2p.Config `yaml:"network"`
Chain Chain `yaml:"chain"`
ActPool ActPool `yaml:"actPool"`
Consensus Consensus `yaml:"consensus"`
Expand Down
14 changes: 7 additions & 7 deletions consensus/scheme/rolldpos/rolldposctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func TestRollDPoSCtx(t *testing.T) {
})

rp := rolldpos.NewProtocol(
config.Default.Genesis.NumCandidateDelegates,
config.Default.Genesis.NumDelegates,
config.Default.Genesis.NumSubEpochs,
genesis.Default.NumCandidateDelegates,
genesis.Default.NumDelegates,
genesis.Default.NumSubEpochs,
)
t.Run("case 3:panic because of clock is nil", func(t *testing.T) {
_, err := newRollDPoSCtx(consensusfsm.NewConsensusConfig(cfg), dbConfig, true, time.Second, true, b, block.NewDeserializer(0), rp, nil, dummyCandidatesByHeightFunc, "", nil, nil, 0)
Expand All @@ -75,7 +75,7 @@ func TestRollDPoSCtx(t *testing.T) {
})

t.Run("case 6:normal", func(t *testing.T) {
bh := config.Default.Genesis.BeringBlockHeight
bh := genesis.Default.BeringBlockHeight
rctx, err := newRollDPoSCtx(consensusfsm.NewConsensusConfig(cfg), dbConfig, true, time.Second, true, b, block.NewDeserializer(0), rp, nil, dummyCandidatesByHeightFunc, "", nil, c, bh)
require.NoError(err)
require.Equal(bh, rctx.roundCalc.beringHeight)
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestCheckVoteEndorser(t *testing.T) {
"",
nil,
c,
config.Default.Genesis.BeringBlockHeight,
genesis.Default.BeringBlockHeight,
)
require.NoError(err)
require.NotNil(rctx)
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestCheckBlockProposer(t *testing.T) {
"",
nil,
c,
config.Default.Genesis.BeringBlockHeight,
genesis.Default.BeringBlockHeight,
)
require.NoError(err)
require.NotNil(rctx)
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestNotProducingMultipleBlocks(t *testing.T) {
"",
identityset.PrivateKey(10),
c,
config.Default.Genesis.BeringBlockHeight,
genesis.Default.BeringBlockHeight,
)
require.NoError(err)
require.NotNil(rctx)
Expand Down
2 changes: 1 addition & 1 deletion consensus/scheme/rolldpos/roundcalculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func makeRoundCalculator(t *testing.T) *roundCalculator {
},
},
),
config.Default.Genesis,
genesis.Default,
)
tipEpochNum := rp.GetEpochNum(tipHeight)
var candidatesList state.CandidateList
Expand Down
2 changes: 1 addition & 1 deletion e2etest/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func TestLocalSync(t *testing.T) {
// bootnode
ctx := context.Background()
bootnodePort := testutil.RandomPort()
bootnode := p2p.NewAgent(p2p.Network{
bootnode := p2p.NewAgent(p2p.Config{
Host: "127.0.0.1",
Port: bootnodePort,
ReconnectInterval: 150 * time.Second},
Expand Down
4 changes: 2 additions & 2 deletions ioctl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/ioctl/output"
"github.com/iotexproject/iotex-core/pkg/log"
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func init() {
completeness = false
}
if ReadConfig.Nsv2height == 0 {
ReadConfig.Nsv2height = config.Default.Genesis.FairbankBlockHeight
ReadConfig.Nsv2height = genesis.Default.FairbankBlockHeight
}
if ReadConfig.AnalyserEndpoint == "" {
ReadConfig.AnalyserEndpoint = _defaultAnalyserEndpoint
Expand Down
Loading

0 comments on commit 4e397d3

Please sign in to comment.