Skip to content

Commit

Permalink
Add default premine for validators (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal authored Nov 28, 2023
1 parent daa678a commit c6ae2d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 20 additions & 12 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions consensus/polybft/stake_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c6ae2d7

Please sign in to comment.