Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Integrate the most recent SC changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal authored and goran-ethernal committed Oct 31, 2023
1 parent 776132b commit 210b4e2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 41 deletions.
2 changes: 1 addition & 1 deletion command/rootchain/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ var (
NewChildERC20Predicate: contracts.ChildERC20PredicateContract,
NewChildTokenTemplate: contracts.ChildERC20Contract,
// map root native token address should be non-zero only if native token is non-mintable on a childchain
NativeTokenRootAddress: config.RootNativeERC20Address,
NewNativeTokenRoot: config.RootNativeERC20Address,
}

return initContract(fmt, relayer, inputParams,
Expand Down
4 changes: 2 additions & 2 deletions command/rootchain/premine/premine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
func GetCommand() *cobra.Command {
premineCmd := &cobra.Command{
Use: "premine",
Short: "Premine native root token to the caller. " +
Short: "Premine native root token to the caller, which determines genesis balances. " +
"This command is used in case Supernets native token is rootchain originated.",
PreRunE: runPreRun,
RunE: runCommand,
Expand Down Expand Up @@ -128,7 +128,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("approve transaction failed on block %d", receipt.BlockNumber)
}

premineFn := &contractsapi.PremineCustomSupernetManagerFn{
premineFn := &contractsapi.AddGenesisBalanceCustomSupernetManagerFn{
Amount: params.amountValue,
}

Expand Down
52 changes: 27 additions & 25 deletions command/rootchain/supernet/supernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,16 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/helper/hex"
"github.com/0xPolygon/polygon-edge/txrelayer"
"github.com/0xPolygon/polygon-edge/types"
)

type genesisAccount struct {
Address types.Address
Stake *big.Int
Balance *big.Int
}

func (g *genesisAccount) String() string {
return fmt.Sprintf("%s %d %d", g.Address, g.Stake, g.Balance)
}

var (
params supernetParams
genesisSetABIFn = contractsapi.CustomSupernetManager.Abi.Methods["genesisSet"]
params supernetParams
genesisSetABIFn = contractsapi.CustomSupernetManager.Abi.Methods["genesisSet"]
genesisBalancesABIFn = contractsapi.CustomSupernetManager.Abi.Methods["genesisBalances"]
)

func GetCommand() *cobra.Command {
Expand Down Expand Up @@ -178,14 +170,30 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return err
}

genesisAccsMap := make(map[types.Address]*genesisAccount, len(genesisAccounts))
genesisAccsMap := make(map[types.Address]*validator.GenesisValidator, len(genesisAccounts))
for _, genesisAcc := range genesisAccounts {

Check failure on line 174 in command/rootchain/supernet/supernet.go

View workflow job for this annotation

GitHub Actions / golangci_lint

ranges should only be cuddled with assignments used in the iteration (wsl)

Check failure on line 174 in command/rootchain/supernet/supernet.go

View workflow job for this annotation

GitHub Actions / golangci_lint

ranges should only be cuddled with assignments used in the iteration (wsl)
genesisBalanceInput, err := genesisBalancesABIFn.Encode(genesisAcc.Address)
if err != nil {
return err
}

genesisBalanceRaw, err := txRelayer.Call(ethgo.ZeroAddress, supernetAddr, genesisBalanceInput)
if err != nil {
return err
}

genesisBalance, err := common.ParseUint256orHex(&genesisBalanceRaw)
if err != nil {
return fmt.Errorf("failed to convert genesis balance '%s' to number: %w",
genesisBalanceRaw, err)
}

genesisAccsMap[genesisAcc.Address] = genesisAcc

if genesisAcc.Balance.Sign() > 0 {
if genesisBalance.Sign() > 0 {
// premine genesis accounts
chainConfig.Genesis.Alloc[genesisAcc.Address] =
&chain.GenesisAccount{Balance: genesisAcc.Balance}
&chain.GenesisAccount{Balance: genesisBalance}
}
}

Expand Down Expand Up @@ -258,8 +266,8 @@ func runCommand(cmd *cobra.Command, _ []string) error {
}

// decodeGenesisAccounts decodes genesis set retrieved from CustomSupernetManager contract
func decodeGenesisAccounts(genesisSetRaw string) ([]*genesisAccount, error) {
decodeAccount := func(rawAccount map[string]interface{}) (*genesisAccount, error) {
func decodeGenesisAccounts(genesisSetRaw string) ([]*validator.GenesisValidator, error) {
decodeAccount := func(rawAccount map[string]interface{}) (*validator.GenesisValidator, error) {
addr, ok := rawAccount["validator"].(ethgo.Address)
if !ok {
return nil, errors.New("failed to retrieve genesis account address")
Expand All @@ -270,15 +278,9 @@ func decodeGenesisAccounts(genesisSetRaw string) ([]*genesisAccount, error) {
return nil, errors.New("failed to retrieve genesis account stake")
}

balance, ok := rawAccount["balance"].(*big.Int)
if !ok {
return nil, errors.New("failed to retrieve genesis account balance")
}

return &genesisAccount{
return &validator.GenesisValidator{
Address: types.Address(addr),
Stake: stake,
Balance: balance,
}, nil
}

Expand All @@ -302,7 +304,7 @@ func decodeGenesisAccounts(genesisSetRaw string) ([]*genesisAccount, error) {
return nil, errors.New("failed to convert genesis set to slice")
}

genesisAccounts := make([]*genesisAccount, len(decodedGenesisSetSliceMap))
genesisAccounts := make([]*validator.GenesisValidator, len(decodedGenesisSetSliceMap))
for i, rawGenesisAccount := range decodedGenesisSetSliceMap {
genesisAccounts[i], err = decodeAccount(rawGenesisAccount)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/checkpoint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
var (
// currentCheckpointBlockNumMethod is an ABI method object representation for
// currentCheckpointBlockNumber getter function on CheckpointManager contract
currentCheckpointBlockNumMethod, _ = contractsapi.CheckpointManager.Abi.Methods["currentCheckpointBlockNumber"]
currentCheckpointBlockNumMethod = contractsapi.CheckpointManager.Abi.Methods["currentCheckpointBlockNumber"]
// frequency at which checkpoints are sent to the rootchain (in blocks count)
defaultCheckpointsOffset = uint64(900)
)
Expand Down
2 changes: 1 addition & 1 deletion consensus/polybft/contractsapi/bindings-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func main() {
"whitelistValidators",
"register",
"getValidator",
"premine",
"addGenesisBalance",
},
[]string{
"ValidatorRegistered",
Expand Down
32 changes: 24 additions & 8 deletions consensus/polybft/contractsapi/contractsapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 210b4e2

Please sign in to comment.