From e3f121299b8c2366f6085c52e4fe6bcdb0397303 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Thu, 9 Nov 2023 10:08:59 -0700 Subject: [PATCH] Genesis validators cleanup (#2282) --- genesis/genesis.go | 4 +-- tests/e2e/static-handlers/suites.go | 6 ++-- vms/platformvm/api/static_service.go | 30 +++++++++++------ vms/platformvm/api/static_service_test.go | 32 +++++++++---------- vms/platformvm/block/builder/helpers_test.go | 6 ++-- vms/platformvm/block/executor/helpers_test.go | 6 ++-- vms/platformvm/txs/executor/helpers_test.go | 6 ++-- vms/platformvm/validator_set_property_test.go | 6 ++-- .../validators/manager_benchmark_test.go | 4 +-- vms/platformvm/vm_test.go | 12 +++---- 10 files changed, 62 insertions(+), 50 deletions(-) diff --git a/genesis/genesis.go b/genesis/genesis.go index 821f72502488..e59b8c6fbbbc 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -418,8 +418,8 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) { delegationFee := json.Uint32(staker.DelegationFee) platformvmArgs.Validators = append(platformvmArgs.Validators, - api.PermissionlessValidator{ - Staker: api.Staker{ + api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(genesisTime.Unix()), EndTime: json.Uint64(endStakingTime.Unix()), NodeID: staker.NodeID, diff --git a/tests/e2e/static-handlers/suites.go b/tests/e2e/static-handlers/suites.go index 52c0f50a9436..2351b32e09ed 100644 --- a/tests/e2e/static-handlers/suites.go +++ b/tests/e2e/static-handlers/suites.go @@ -141,13 +141,13 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() { } } - genesisValidators := make([]api.PermissionlessValidator, len(keys)) + genesisValidators := make([]api.GenesisPermissionlessValidator, len(keys)) for i, key := range keys { id := key.PublicKey().Address() addr, err := address.FormatBech32(hrp, id.Bytes()) require.NoError(err) - genesisValidators[i] = api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(time.Date(1997, 1, 1, 0, 0, 0, 0, time.UTC).Unix()), EndTime: json.Uint64(time.Date(1997, 1, 30, 0, 0, 0, 0, time.UTC).Unix()), NodeID: ids.NodeID(id), diff --git a/vms/platformvm/api/static_service.go b/vms/platformvm/api/static_service.go index d06c2e757962..1cf2fbe29096 100644 --- a/vms/platformvm/api/static_service.go +++ b/vms/platformvm/api/static_service.go @@ -98,6 +98,9 @@ type Staker struct { StakeAmount *json.Uint64 `json:"stakeAmount,omitempty"` } +// GenesisValidator should to be used for genesis validators only. +type GenesisValidator Staker + // Owner is the repr. of a reward owner sent over APIs. type Owner struct { Locktime json.Uint64 `json:"locktime"` @@ -132,6 +135,15 @@ type PermissionlessValidator struct { Delegators *[]PrimaryDelegator `json:"delegators,omitempty"` } +// GenesisPermissionlessValidator should to be used for genesis validators only. +type GenesisPermissionlessValidator struct { + GenesisValidator + RewardOwner *Owner `json:"rewardOwner,omitempty"` + DelegationFee json.Float32 `json:"delegationFee"` + ExactDelegationFee *json.Uint32 `json:"exactDelegationFee,omitempty"` + Staked []UTXO `json:"staked,omitempty"` +} + // PermissionedValidator is the repr. of a permissioned validator sent over APIs. type PermissionedValidator struct { Staker @@ -170,15 +182,15 @@ type Chain struct { // [Chains] are the chains that exist at genesis. // [Time] is the Platform Chain's time at network genesis. type BuildGenesisArgs struct { - AvaxAssetID ids.ID `json:"avaxAssetID"` - NetworkID json.Uint32 `json:"networkID"` - UTXOs []UTXO `json:"utxos"` - Validators []PermissionlessValidator `json:"validators"` - Chains []Chain `json:"chains"` - Time json.Uint64 `json:"time"` - InitialSupply json.Uint64 `json:"initialSupply"` - Message string `json:"message"` - Encoding formatting.Encoding `json:"encoding"` + AvaxAssetID ids.ID `json:"avaxAssetID"` + NetworkID json.Uint32 `json:"networkID"` + UTXOs []UTXO `json:"utxos"` + Validators []GenesisPermissionlessValidator `json:"validators"` + Chains []Chain `json:"chains"` + Time json.Uint64 `json:"time"` + InitialSupply json.Uint64 `json:"initialSupply"` + Message string `json:"message"` + Encoding formatting.Encoding `json:"encoding"` } // BuildGenesisReply is the reply from BuildGenesis diff --git a/vms/platformvm/api/static_service_test.go b/vms/platformvm/api/static_service_test.go index 12bdb91bfa60..8bcbf4e766db 100644 --- a/vms/platformvm/api/static_service_test.go +++ b/vms/platformvm/api/static_service_test.go @@ -27,8 +27,8 @@ func TestBuildGenesisInvalidUTXOBalance(t *testing.T) { Amount: 0, } weight := json.Uint64(987654321) - validator := PermissionlessValidator{ - Staker: Staker{ + validator := GenesisPermissionlessValidator{ + GenesisValidator: GenesisValidator{ EndTime: 15, Weight: weight, NodeID: nodeID, @@ -47,7 +47,7 @@ func TestBuildGenesisInvalidUTXOBalance(t *testing.T) { UTXOs: []UTXO{ utxo, }, - Validators: []PermissionlessValidator{ + Validators: []GenesisPermissionlessValidator{ validator, }, Time: 5, @@ -71,8 +71,8 @@ func TestBuildGenesisInvalidStakeWeight(t *testing.T) { Amount: 123456789, } weight := json.Uint64(0) - validator := PermissionlessValidator{ - Staker: Staker{ + validator := GenesisPermissionlessValidator{ + GenesisValidator: GenesisValidator{ StartTime: 0, EndTime: 15, NodeID: nodeID, @@ -91,7 +91,7 @@ func TestBuildGenesisInvalidStakeWeight(t *testing.T) { UTXOs: []UTXO{ utxo, }, - Validators: []PermissionlessValidator{ + Validators: []GenesisPermissionlessValidator{ validator, }, Time: 5, @@ -116,8 +116,8 @@ func TestBuildGenesisInvalidEndtime(t *testing.T) { } weight := json.Uint64(987654321) - validator := PermissionlessValidator{ - Staker: Staker{ + validator := GenesisPermissionlessValidator{ + GenesisValidator: GenesisValidator{ StartTime: 0, EndTime: 5, NodeID: nodeID, @@ -136,7 +136,7 @@ func TestBuildGenesisInvalidEndtime(t *testing.T) { UTXOs: []UTXO{ utxo, }, - Validators: []PermissionlessValidator{ + Validators: []GenesisPermissionlessValidator{ validator, }, Time: 5, @@ -161,8 +161,8 @@ func TestBuildGenesisReturnsSortedValidators(t *testing.T) { } weight := json.Uint64(987654321) - validator1 := PermissionlessValidator{ - Staker: Staker{ + validator1 := GenesisPermissionlessValidator{ + GenesisValidator: GenesisValidator{ StartTime: 0, EndTime: 20, NodeID: nodeID, @@ -177,8 +177,8 @@ func TestBuildGenesisReturnsSortedValidators(t *testing.T) { }}, } - validator2 := PermissionlessValidator{ - Staker: Staker{ + validator2 := GenesisPermissionlessValidator{ + GenesisValidator: GenesisValidator{ StartTime: 3, EndTime: 15, NodeID: nodeID, @@ -193,8 +193,8 @@ func TestBuildGenesisReturnsSortedValidators(t *testing.T) { }}, } - validator3 := PermissionlessValidator{ - Staker: Staker{ + validator3 := GenesisPermissionlessValidator{ + GenesisValidator: GenesisValidator{ StartTime: 1, EndTime: 10, NodeID: nodeID, @@ -214,7 +214,7 @@ func TestBuildGenesisReturnsSortedValidators(t *testing.T) { UTXOs: []UTXO{ utxo, }, - Validators: []PermissionlessValidator{ + Validators: []GenesisPermissionlessValidator{ validator1, validator2, validator3, diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index a773fc964ef6..8da4c45b4639 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -357,13 +357,13 @@ func buildGenesisTest(t *testing.T, ctx *snow.Context) []byte { } } - genesisValidators := make([]api.PermissionlessValidator, len(preFundedKeys)) + genesisValidators := make([]api.GenesisPermissionlessValidator, len(preFundedKeys)) for i, key := range preFundedKeys { nodeID := ids.NodeID(key.PublicKey().Address()) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) - genesisValidators[i] = api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(defaultValidateStartTime.Unix()), EndTime: json.Uint64(defaultValidateEndTime.Unix()), NodeID: nodeID, diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 9448cdde44eb..4f452f1144c0 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -399,15 +399,15 @@ func buildGenesisTest(ctx *snow.Context) []byte { } } - genesisValidators := make([]api.PermissionlessValidator, len(preFundedKeys)) + genesisValidators := make([]api.GenesisPermissionlessValidator, len(preFundedKeys)) for i, key := range preFundedKeys { nodeID := ids.NodeID(key.PublicKey().Address()) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) if err != nil { panic(err) } - genesisValidators[i] = api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(defaultValidateStartTime.Unix()), EndTime: json.Uint64(defaultValidateEndTime.Unix()), NodeID: nodeID, diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index b1993584cb7a..409fe79c7002 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -366,15 +366,15 @@ func buildGenesisTest(ctx *snow.Context) []byte { } } - genesisValidators := make([]api.PermissionlessValidator, len(preFundedKeys)) + genesisValidators := make([]api.GenesisPermissionlessValidator, len(preFundedKeys)) for i, key := range preFundedKeys { nodeID := ids.NodeID(key.PublicKey().Address()) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) if err != nil { panic(err) } - genesisValidators[i] = api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(defaultValidateStartTime.Unix()), EndTime: json.Uint64(defaultValidateEndTime.Unix()), NodeID: nodeID, diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index fab84cc6d50b..be3962f36701 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -849,8 +849,8 @@ func buildCustomGenesis() ([]byte, error) { starTime := mockable.MaxTime.Add(-1 * defaultMinStakingDuration) endTime := mockable.MaxTime - genesisValidator := api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidator := api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(starTime.Unix()), EndTime: json.Uint64(endTime.Unix()), NodeID: nodeID, @@ -871,7 +871,7 @@ func buildCustomGenesis() ([]byte, error) { NetworkID: json.Uint32(constants.UnitTestID), AvaxAssetID: avaxAssetID, UTXOs: genesisUTXOs, - Validators: []api.PermissionlessValidator{genesisValidator}, + Validators: []api.GenesisPermissionlessValidator{genesisValidator}, Chains: nil, Time: json.Uint64(defaultGenesisTime.Unix()), InitialSupply: json.Uint64(360 * units.MegaAvax), diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index d88fca7d7e32..0664c085c942 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -65,8 +65,8 @@ func BenchmarkGetValidatorSet(b *testing.B) { addr, err := address.FormatBech32(constants.UnitTestHRP, ids.GenerateTestShortID().Bytes()) require.NoError(err) - genesisValidators := []api.PermissionlessValidator{{ - Staker: api.Staker{ + genesisValidators := []api.GenesisPermissionlessValidator{{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(genesisTime.Unix()), EndTime: json.Uint64(genesisEndTime.Unix()), NodeID: ids.GenerateTestNodeID(), diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 31dfcfbda183..d4dcb20b4264 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -175,13 +175,13 @@ func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) { } } - genesisValidators := make([]api.PermissionlessValidator, len(keys)) + genesisValidators := make([]api.GenesisPermissionlessValidator, len(keys)) for i, key := range keys { nodeID := ids.NodeID(key.PublicKey().Address()) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) - genesisValidators[i] = api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(defaultValidateStartTime.Unix()), EndTime: json.Uint64(defaultValidateEndTime.Unix()), NodeID: nodeID, @@ -243,14 +243,14 @@ func BuildGenesisTestWithArgs(t *testing.T, args *api.BuildGenesisArgs) (*api.Bu } } - genesisValidators := make([]api.PermissionlessValidator, len(keys)) + genesisValidators := make([]api.GenesisPermissionlessValidator, len(keys)) for i, key := range keys { nodeID := ids.NodeID(key.PublicKey().Address()) addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes()) require.NoError(err) - genesisValidators[i] = api.PermissionlessValidator{ - Staker: api.Staker{ + genesisValidators[i] = api.GenesisPermissionlessValidator{ + GenesisValidator: api.GenesisValidator{ StartTime: json.Uint64(defaultValidateStartTime.Unix()), EndTime: json.Uint64(defaultValidateEndTime.Unix()), NodeID: nodeID,