From c6ae2d748806a7feaf2d37a29d4f0984cf9f051c Mon Sep 17 00:00:00 2001 From: Goran Rojovic <100121253+goran-ethernal@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:20:01 +0100 Subject: [PATCH] Add default premine for validators (#26) --- command/genesis/polybft_params.go | 32 +++++++++++++++---------- consensus/polybft/stake_manager_test.go | 8 +++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/command/genesis/polybft_params.go b/command/genesis/polybft_params.go index 6e7b3eaa2e..3e999074d4 100644 --- a/command/genesis/polybft_params.go +++ b/command/genesis/polybft_params.go @@ -172,18 +172,6 @@ func (p *genesisParams) generateChainConfig(o command.OutputFormatter) error { return err } - // premine other accounts - for _, premine := range premineBalances { - // validators have already been premined, so no need to premine them again - if _, ok := allocs[premine.Address]; ok { - continue - } - - allocs[premine.Address] = &chain.GenesisAccount{ - Balance: premine.Amount, - } - } - validatorMetadata := make([]*validator.ValidatorMetadata, len(initialValidators)) for i, validator := range initialValidators { @@ -199,6 +187,26 @@ func (p *genesisParams) generateChainConfig(o command.OutputFormatter) error { if len(p.bootnodes) == 0 { chainConfig.Bootnodes = append(chainConfig.Bootnodes, validator.MultiAddr) } + + // add default premine for a validator if it is not specified in genesis command + if _, exists := premineBalances[validator.Address]; !exists { + premineBalances[validator.Address] = &helper.PremineInfo{ + Address: validator.Address, + Amount: command.DefaultPremineBalance, + } + } + } + + // premine other accounts + for _, premine := range premineBalances { + // validators have already been premined, so no need to premine them again + if _, ok := allocs[premine.Address]; ok { + continue + } + + allocs[premine.Address] = &chain.GenesisAccount{ + Balance: premine.Amount, + } } genesisExtraData, err := GenerateExtraDataPolyBft(validatorMetadata) diff --git a/consensus/polybft/stake_manager_test.go b/consensus/polybft/stake_manager_test.go index a3ec387d37..9ab3c07dd4 100644 --- a/consensus/polybft/stake_manager_test.go +++ b/consensus/polybft/stake_manager_test.go @@ -501,10 +501,10 @@ func TestStakeManager_UpdateOnInit(t *testing.T) { func createTestLogForStakeAddedEvent(t *testing.T, validatorSet, to types.Address, stake uint64) *types.Log { t.Helper() - var transferEvent contractsapi.StakeAddedEvent + var stakeAddedEvent contractsapi.StakeAddedEvent topics := make([]types.Hash, 2) - topics[0] = types.Hash(transferEvent.Sig()) + topics[0] = types.Hash(stakeAddedEvent.Sig()) topics[1] = types.BytesToHash(to.Bytes()) encodedData, err := abi.MustNewType("uint256").Encode(new(big.Int).SetUint64(stake)) require.NoError(t, err) @@ -519,10 +519,10 @@ func createTestLogForStakeAddedEvent(t *testing.T, validatorSet, to types.Addres func createTestLogForStakeRemovedEvent(t *testing.T, validatorSet, to types.Address, unstake uint64) *types.Log { t.Helper() - var transferEvent contractsapi.StakeRemovedEvent + var stakeRemovedEvent contractsapi.StakeRemovedEvent topics := make([]types.Hash, 2) - topics[0] = types.Hash(transferEvent.Sig()) + topics[0] = types.Hash(stakeRemovedEvent.Sig()) topics[1] = types.BytesToHash(to.Bytes()) encodedData, err := abi.MustNewType("uint256").Encode(new(big.Int).SetUint64(unstake)) require.NoError(t, err)