Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove manifest init step from network bootstrap workflow #1389

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,3 @@ func importChain(content []byte) (*Chain, error) {

return chain, nil
}

// GetGenesisAccountBalance returns balance for genesis account based on its address (expressed in weis).
// If not found in provided allocations map, 0 is returned.
func GetGenesisAccountBalance(address types.Address, allocations map[types.Address]*GenesisAccount) (*big.Int, error) {
if genesisAcc, ok := allocations[address]; ok {
return genesisAcc.Balance, nil
}

return nil, fmt.Errorf("genesis account %s is not found among genesis allocations", address)
}
47 changes: 0 additions & 47 deletions chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package chain

import (
"encoding/json"
"fmt"
"math/big"
"reflect"
"testing"

"github.com/0xPolygon/polygon-edge/types"
"github.com/stretchr/testify/require"
)

var emptyAddr types.Address
Expand Down Expand Up @@ -152,48 +150,3 @@ func TestGenesisX(t *testing.T) {
})
}
}

func TestGetGenesisAccountBalance(t *testing.T) {
t.Parallel()

testAddr := types.Address{0x2}
cases := []struct {
name string
address types.Address
allocs map[types.Address]*GenesisAccount
expectedBalance *big.Int
shouldFail bool
}{
{
name: "Query existing account",
address: testAddr,
allocs: map[types.Address]*GenesisAccount{
testAddr: {Balance: big.NewInt(50)},
},
expectedBalance: big.NewInt(50),
shouldFail: false,
},
{
name: "Query non-existing account",
address: testAddr,
allocs: nil,
expectedBalance: nil,
shouldFail: true,
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()

actualBalance, err := GetGenesisAccountBalance(c.address, c.allocs)
if c.shouldFail {
require.Equal(t, err.Error(), fmt.Errorf("genesis account %s is not found among genesis allocations", c.address).Error())
} else {
require.NoError(t, err)
}
require.Equal(t, c.expectedBalance, actualBalance)
})
}
}
5 changes: 3 additions & 2 deletions command/bridge/withdraw/withdraw_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ func run(cmd *cobra.Command, _ []string) {

receipt, err := txRelayer.SendTransaction(txn, senderAccount)
if err != nil {
outputter.SetError(fmt.Errorf("receiver: %s, amount: %s, error: %w", receiver, amount, err))
outputter.SetError(fmt.Errorf("failed to send withdraw transaction (receiver: %s, amount: %s). error: %w)",
receiver, amount, err))

return
}

if receipt.Status == uint64(types.ReceiptFailed) {
outputter.SetError(fmt.Errorf("receiver: %s, amount: %s", receiver, amount))
outputter.SetError(fmt.Errorf("failed to execute withdrawal (receiver: %s, amount: %s)", receiver, amount))

return
}
Expand Down
60 changes: 36 additions & 24 deletions command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GetCommand() *cobra.Command {
genesisCmd := &cobra.Command{
Use: "genesis",
Short: "Generates the genesis configuration file with the passed in parameters",
PreRunE: runPreRun,
PreRunE: preRunCommand,
Run: runCommand,
}

Expand Down Expand Up @@ -60,7 +60,7 @@ func setFlags(cmd *cobra.Command) {
premineFlag,
[]string{},
fmt.Sprintf(
"the premined accounts and balances (format: <address>:<balance>). Default premined balance: %d",
"the premined accounts and balances (format: <address>[:<balance>]). Default premined balance: %d",
command.DefaultPremineBalance,
),
)
Expand Down Expand Up @@ -150,12 +150,39 @@ func setFlags(cmd *cobra.Command) {
// PolyBFT
{
cmd.Flags().StringVar(
&params.manifestPath,
manifestPathFlag,
defaultManifestPath,
"the manifest file path, which contains genesis metadata",
&params.validatorsPath,
validatorsPathFlag,
"./",
"root path containing polybft validators secrets",
)

cmd.Flags().StringVar(
&params.validatorsPrefixPath,
validatorsPrefixFlag,
defaultValidatorPrefixPath,
"folder prefix names for polybft validators secrets",
)

cmd.Flags().StringArrayVar(
&params.validators,
validatorsFlag,
[]string{},
"validators defined by user (format: <P2P multi address>:<ECDSA address>:<public BLS key>:<BLS signature>)",
)

cmd.Flags().StringArrayVar(
&params.stakes,
stakeFlag,
[]string{},
fmt.Sprintf(
"validators staked amount (format: <address>[:<amount>]). Default stake amount: %d",
command.DefaultStake,
),
)

cmd.MarkFlagsMutuallyExclusive(validatorsFlag, validatorsPathFlag)
cmd.MarkFlagsMutuallyExclusive(validatorsFlag, validatorsPrefixFlag)

cmd.Flags().Uint64Var(
&params.sprintSize,
sprintSizeFlag,
Expand All @@ -170,29 +197,14 @@ func setFlags(cmd *cobra.Command) {
"the predefined period which determines block creation frequency",
)

cmd.Flags().StringVar(
&params.bridgeJSONRPCAddr,
bridgeFlag,
"",
"the rootchain JSON RPC endpoint",
)

cmd.Flags().Uint64Var(
&params.epochReward,
epochRewardFlag,
defaultEpochReward,
"reward size for block sealing",
)

cmd.Flags().StringArrayVar(
&params.eventTrackerStartBlocks,
trackerStartBlocksFlag,
[]string{},
"event tracker starting block configuration, which is specified per contract address "+
"(format: <contract address>:<start block>)",
)

//Regenesis flag that allows to start from non-empty database
// regenesis flag that allows to start from non-empty database
cmd.Flags().StringVar(
&params.initialStateRoot,
trieRootFlag,
Expand Down Expand Up @@ -255,13 +267,13 @@ func setLegacyFlags(cmd *cobra.Command) {
&params.chainID,
chainIDFlagLEGACY,
command.DefaultChainID,
"the ID of the chain (not-applicable for Polybft consensus protocol as chain id is defined in manifest.json)",
"the ID of the chain",
)

_ = cmd.Flags().MarkHidden(chainIDFlagLEGACY)
}

func runPreRun(cmd *cobra.Command, _ []string) error {
func preRunCommand(cmd *cobra.Command, _ []string) error {
if err := params.validateFlags(); err != nil {
return err
}
Expand Down
31 changes: 18 additions & 13 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"math"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -90,12 +91,13 @@ type genesisParams struct {
genesisConfig *chain.Chain

// PolyBFT
manifestPath string
sprintSize uint64
blockTime time.Duration
bridgeJSONRPCAddr string
epochReward uint64
eventTrackerStartBlocks []string
validatorsPath string
validatorsPrefixPath string
stakes []string
validators []string
sprintSize uint64
blockTime time.Duration
epochReward uint64

initialStateRoot string

Expand Down Expand Up @@ -142,12 +144,15 @@ func (p *genesisParams) validateFlags() error {
return errInvalidEpochSize
}

// Validate min and max validators number
if err := command.ValidateMinMaxValidatorsNumber(p.minNumValidators, p.maxNumValidators); err != nil {
return err
// Validate validatorsPath only if validators information were not provided via CLI flag
if len(p.validators) == 0 {
if _, err := os.Stat(p.validatorsPath); errors.Is(err, os.ErrNotExist) {
igorcrevar marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("provided validators path '%s' doesn't exist", p.validatorsPath)
}
}

return nil
// Validate min and max validators number
return command.ValidateMinMaxValidatorsNumber(p.minNumValidators, p.maxNumValidators)
}

func (p *genesisParams) isIBFTConsensus() bool {
Expand Down Expand Up @@ -368,13 +373,13 @@ func (p *genesisParams) initGenesisConfig() error {
}

for _, premineRaw := range p.premine {
premineInfo, err := ParsePremineInfo(premineRaw)
premineInfo, err := parsePremineInfo(premineRaw)
if err != nil {
return err
}

chainConfig.Genesis.Alloc[premineInfo.Address] = &chain.GenesisAccount{
Balance: premineInfo.Amount,
chainConfig.Genesis.Alloc[premineInfo.address] = &chain.GenesisAccount{
Balance: premineInfo.amount,
}
}

Expand Down
Loading