Skip to content

Commit

Permalink
fix(genesis,params): moving genesis params to genesis module
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Aug 7, 2024
1 parent 5ee7d91 commit 38eaf62
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 22 deletions.
3 changes: 1 addition & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/pactus-project/pactus/genesis"
"github.com/pactus-project/pactus/node"
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/wallet"
Expand Down Expand Up @@ -440,7 +439,7 @@ func makeLocalGenesis(w wallet.Wallet) *genesis.Genesis {
}

// create genesis
params := param.DefaultGenParams()
params := genesis.DefaultGenParams()
params.BlockVersion = 0
gen := genesis.MakeGenesis(util.RoundNow(60), accs, vals, params)

Expand Down
3 changes: 1 addition & 2 deletions consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/block"
"github.com/pactus-project/pactus/types/certificate"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/proposal"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/validator"
Expand Down Expand Up @@ -86,7 +85,7 @@ func setupWithSeed(t *testing.T, seed int64) *testData {
acc := account.NewAccount(0)
acc.AddToBalance(21 * 1e14)
accs := map[crypto.Address]*account.Account{crypto.TreasuryAddress: acc}
params := param.DefaultGenParams()
params := genesis.DefaultGenParams()
params.CommitteeSize = 4

// To prevent triggering timers before starting the tests and
Expand Down
13 changes: 6 additions & 7 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/pactus-project/pactus/crypto/hash"
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
)
Expand Down Expand Up @@ -56,10 +55,10 @@ type Genesis struct {
}

type genesisData struct {
GenesisTime time.Time `cbor:"1,keyasint" json:"genesis_time"`
Params *param.GenParams `cbor:"2,keyasint" json:"params"`
Accounts []genAccount `cbor:"3,keyasint" json:"accounts"`
Validators []genValidator `cbor:"4,keyasint" json:"validators"`
GenesisTime time.Time `cbor:"1,keyasint" json:"genesis_time"`
Params *GenParams `cbor:"2,keyasint" json:"params"`
Accounts []genAccount `cbor:"3,keyasint" json:"accounts"`
Validators []genValidator `cbor:"4,keyasint" json:"validators"`
}

func (gen *Genesis) Hash() hash.Hash {
Expand All @@ -72,7 +71,7 @@ func (gen *Genesis) GenesisTime() time.Time {
return gen.data.GenesisTime
}

func (gen *Genesis) Params() *param.GenParams {
func (gen *Genesis) Params() *GenParams {
return gen.data.Params
}

Expand Down Expand Up @@ -124,7 +123,7 @@ func makeGenesisValidator(val *validator.Validator) genValidator {
}

func MakeGenesis(genesisTime time.Time, accounts map[crypto.Address]*account.Account,
validators []*validator.Validator, params *param.GenParams,
validators []*validator.Validator, params *GenParams,
) *Genesis {
genAccs := make([]genAccount, len(accounts))
for addr, acc := range accounts {
Expand Down
2 changes: 1 addition & 1 deletion types/param/genesis_param.go → genesis/genesis_param.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package param
package genesis

import (
"time"
Expand Down
5 changes: 2 additions & 3 deletions genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/pactus-project/pactus/genesis"
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/testsuite"
Expand All @@ -26,7 +25,7 @@ func TestMarshaling(t *testing.T) {
val, _ := ts.GenerateTestValidator(0)
gen1 := genesis.MakeGenesis(util.RoundNow(10),
map[crypto.Address]*account.Account{prv: acc},
[]*validator.Validator{val}, param.DefaultGenParams())
[]*validator.Validator{val}, genesis.DefaultGenParams())
gen2 := new(genesis.Genesis)

assert.Equal(t, 10, gen1.Params().BlockIntervalInSecond)
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestCheckGenesisAccountAndValidator(t *testing.T) {
accs[pub.AccountAddress()] = acc
vals = append(vals, val)
}
gen := genesis.MakeGenesis(time.Now(), accs, vals, param.DefaultGenParams())
gen := genesis.MakeGenesis(time.Now(), accs, vals, genesis.DefaultGenParams())

for addr, acc := range gen.Accounts() {
assert.Equal(t, accs[addr], acc)
Expand Down
3 changes: 1 addition & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/pactus-project/pactus/crypto/hash"
"github.com/pactus-project/pactus/genesis"
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/logger"
Expand All @@ -30,7 +29,7 @@ func TestRunningNode(t *testing.T) {
val := validator.NewValidator(pub, 0)
gen := genesis.MakeGenesis(time.Now(),
map[crypto.Address]*account.Account{crypto.TreasuryAddress: acc},
[]*validator.Validator{val}, param.DefaultGenParams())
[]*validator.Validator{val}, genesis.DefaultGenParams())
conf := config.DefaultConfigMainnet()
conf.GRPC.Enable = true
conf.GRPC.Listen = "0.0.0.0:0"
Expand Down
3 changes: 1 addition & 2 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/block"
"github.com/pactus-project/pactus/types/certificate"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
Expand Down Expand Up @@ -55,7 +54,7 @@ func setup(t *testing.T) *testData {

genTime := util.RoundNow(10).Add(-8640 * time.Second)

params := param.DefaultGenParams()
params := genesis.DefaultGenParams()
params.CommitteeSize = 7
params.BondInterval = 10

Expand Down
2 changes: 1 addition & 1 deletion sync/firewall/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestNetworkFlagsTestnet(t *testing.T) {

func TestNetworkFlagsLocalnet(t *testing.T) {
td := setup(t, nil)
td.state.TestParams.BlockVersion = 0x3f // changing genesis hash
td.state.Genesis().Params().BlockVersion = 0x3f // changing genesis hash

bdl := bundle.NewBundle(message.NewQueryVoteMessage(td.RandHeight(), td.RandRound(), td.RandValAddress()))
bdl.Flags = util.SetFlag(bdl.Flags, bundle.BundleFlagNetworkTestnet)
Expand Down
3 changes: 1 addition & 2 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/pactus-project/pactus/store"
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/logger"
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestMain(m *testing.M) {
vals[1] = validator.NewValidator(tValKeys[tNodeIdx2][0].PublicKey(), 1)
vals[2] = validator.NewValidator(tValKeys[tNodeIdx3][0].PublicKey(), 2)
vals[3] = validator.NewValidator(tValKeys[tNodeIdx4][0].PublicKey(), 3)
params := param.DefaultGenParams()
params := genesis.DefaultGenParams()
params.MinimumStake = 1000
params.BlockIntervalInSecond = 2
params.BondInterval = 8
Expand Down

0 comments on commit 38eaf62

Please sign in to comment.