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

L1-chain #13

Merged
merged 44 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
edf2af9
apply patch
dusannosovic-ethernal Nov 7, 2023
fe90985
Fix for unit tests
dusannosovic-ethernal Nov 8, 2023
5e73a5a
Merge branch 'develop' into l1-chain
Stefan-Ethernal Nov 8, 2023
6557a97
lint fix
dusannosovic-ethernal Nov 8, 2023
50a9701
lint fix
dusannosovic-ethernal Nov 8, 2023
216b016
contracts fix
dusannosovic-ethernal Nov 9, 2023
0337494
makefile fix
dusannosovic-ethernal Nov 9, 2023
3953944
build fix
dusannosovic-ethernal Nov 9, 2023
146ed7e
Merge remote-tracking branch 'origin/develop' into l1-chain
dusannosovic-ethernal Nov 9, 2023
a1e4ae0
fix some imports
dusannosovic-ethernal Nov 9, 2023
2f5afee
Lint fix
Stefan-Ethernal Nov 10, 2023
d4cadd6
comment fixs
dusannosovic-ethernal Nov 10, 2023
10c9d94
fix imports
dusannosovic-ethernal Nov 10, 2023
24c62cd
Update command/genesis/genesis.go
dusannosovic-ethernal Nov 10, 2023
6a6ff8f
Update command/genesis/params.go
dusannosovic-ethernal Nov 10, 2023
2bf24ea
fix comments
dusannosovic-ethernal Nov 13, 2023
a985763
Linter fixes
Stefan-Ethernal Nov 21, 2023
6b6d3c3
deleted supernet package
dusannosovic-ethernal Nov 21, 2023
942d113
stake fix
goran-ethernal Nov 21, 2023
d14ba8e
stake fix 2
goran-ethernal Nov 21, 2023
02c3d80
comments fix
dusannosovic-ethernal Nov 21, 2023
6e93e25
Use new version of contracts
goran-ethernal Nov 24, 2023
4ad391b
Remove RewardPool address and rename ValidatorSet address to EpochMan…
goran-ethernal Nov 24, 2023
99d9895
Remove burn contract flag
goran-ethernal Nov 24, 2023
4b480b4
Remove non-mintable configuration in genesis
goran-ethernal Nov 24, 2023
fee96c0
Lint fixes
Stefan-Ethernal Nov 27, 2023
f2a7d87
Minor rename
Stefan-Ethernal Nov 27, 2023
66b6aac
Update e2e-polybft/e2e/consensus_test.go
dusannosovic-ethernal Nov 28, 2023
7b67f7f
Fix comment
Stefan-Ethernal Nov 28, 2023
6b95bb1
bridge commands relocation (#19)
dusannosovic-ethernal Nov 28, 2023
013b5f2
Remove IsMintable native token flag (#22)
Stefan-Ethernal Nov 28, 2023
daa678a
UT fix (#25)
goran-ethernal Nov 28, 2023
c6ae2d7
Add default premine for validators (#26)
goran-ethernal Nov 28, 2023
c702e13
Fix consensus `e2e` tests (#28)
goran-ethernal Nov 29, 2023
65cbf8f
Small fixes for e2e tests
goran-ethernal Nov 29, 2023
b6910d8
Move and modify `ChangeVotingPower` `e2e` test (#34)
goran-ethernal Nov 30, 2023
a1be56a
Fix bridge e2e tests (#33)
Stefan-Ethernal Dec 1, 2023
fa34b49
Fix local deployment scripts (#40)
goran-ethernal Dec 4, 2023
159ef96
test fix
goran-ethernal Dec 4, 2023
b1e5567
Remove unnecessary forks (#42)
goran-ethernal Dec 4, 2023
125e425
Remove leftover
Stefan-Ethernal Dec 4, 2023
b51aa9a
Use in-house built event tracker (#41)
goran-ethernal Dec 5, 2023
88b480f
Merge branch 'develop' into l1-chain
Stefan-Ethernal Dec 6, 2023
5c5d529
baseFeeConfig as condition for london fork (#43)
dusannosovic-ethernal Dec 6, 2023
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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
path = tests/tests
url = https://github.com/ethereum/tests.git
shallow = true
[submodule "core-contracts"]
path = core-contracts
url = https://github.com/0xPolygon/core-contracts
[submodule "blade-contracts"]
path = blade-contracts
url = https://github.com/Ethernal-Tech/blade-contracts
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ test-property-polybft: check-go
env EDGE_BINARY=${PWD}/artifacts/blade E2E_TESTS=true E2E_LOGS=true go test -v -timeout=30m ./e2e-polybft/property/... \
-rapid.checks=10

.PHONY: compile-core-contracts
compile-core-contracts: check-npm
cd core-contracts && npm install && npm run compile
.PHONY: compile-blade-contracts
compile-blade-contracts: check-npm
cd blade-contracts && npm install && npm run compile
$(MAKE) generate-smart-contract-bindings

.PHONY: generate-smart-contract-bindings
Expand Down Expand Up @@ -117,7 +117,7 @@ help:
@printf " %-35s - %s\n" "test-e2e" "Run end-to-end tests"
@printf " %-35s - %s\n" "test-e2e-polybft" "Run end-to-end tests for PolyBFT"
@printf " %-35s - %s\n" "test-property-polybft" "Run property tests for PolyBFT"
@printf " %-35s - %s\n" "compile-core-contracts" "Compile core contracts"
@printf " %-35s - %s\n" "compile-blade-contracts" "Compile blade contracts"
@printf " %-35s - %s\n" "generate-smart-contract-bindings" "Generate smart contract bindings"
@printf " %-35s - %s\n" "run-docker" "Run Docker cluster for PolyBFT"
@printf " %-35s - %s\n" "stop-docker" "Stop Docker cluster for PolyBFT"
Expand Down
1 change: 1 addition & 0 deletions blade-contracts
Submodule blade-contracts added at f6f055
19 changes: 11 additions & 8 deletions command/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ func setFlags(cmd *cobra.Command) {
),
)

cmd.Flags().StringArrayVar(
&params.stake,
stakeFlag,
[]string{},
fmt.Sprintf(
"the staked accounts and balances (format: <address>[:<stake>]). Default staked balance: %d",
command.DefaultStake,
),
)

cmd.Flags().Uint64Var(
&params.blockGasLimit,
blockGasLimitFlag,
command.DefaultGenesisGasLimit,
"the maximum amount of gas used by all transactions in a block",
)

cmd.Flags().StringVar(
&params.burnContract,
burnContractFlag,
"",
"the burn contract block and address (format: <block>:<address>[:<burn destination>])",
)

cmd.Flags().StringVar(
&params.baseFeeConfig,
genesisBaseFeeConfigFlag,
Expand Down Expand Up @@ -187,7 +190,7 @@ func setFlags(cmd *cobra.Command) {
nativeTokenConfigFlag,
"",
"native token configuration, provided in the following format: "+
"<name:symbol:decimals count:mintable flag:[mintable token owner address]>",
"<name:symbol:decimals count:mintable token owner address>",
)

cmd.Flags().StringVar(
Expand Down
87 changes: 60 additions & 27 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package genesis
import (
"errors"
"fmt"
"math/big"
"os"
"time"

Expand All @@ -18,11 +19,11 @@ const (
dirFlag = "dir"
nameFlag = "name"
premineFlag = "premine"
stakeFlag = "stake"
chainIDFlag = "chain-id"
epochSizeFlag = "epoch-size"
epochRewardFlag = "epoch-reward"
blockGasLimitFlag = "block-gas-limit"
burnContractFlag = "burn-contract"
genesisBaseFeeConfigFlag = "base-fee-config"
nativeTokenConfigFlag = "native-token-config"
rewardTokenCodeFlag = "reward-token-code"
Expand Down Expand Up @@ -56,14 +57,14 @@ type genesisParams struct {
name string
consensusRaw string
premine []string
stake []string
bootnodes []string

chainID uint64
epochSize uint64

blockGasLimit uint64

burnContract string
baseFeeConfig string
parsedBaseFeeConfig *baseFeeInfo

Expand Down Expand Up @@ -103,6 +104,7 @@ type genesisParams struct {
nativeTokenConfig *polybft.TokenConfig

premineInfos []*helper.PremineInfo
stakeInfos map[types.Address]*big.Int

// rewards
rewardTokenCode string
Expand Down Expand Up @@ -138,7 +140,23 @@ func (p *genesisParams) validateFlags() error {
}

if p.isPolyBFTConsensus() {
if err := p.validatePolyBFTParams(); err != nil {
if err := p.extractNativeTokenMetadata(); err != nil {
return err
}

if err := p.validateRewardWalletAndToken(); err != nil {
return err
}

if err := p.validatePremineInfo(); err != nil {
return err
}

if err := p.validateProxyContractsAdmin(); err != nil {
return err
}

if err := p.parseStakeInfo(); err != nil {
return err
}
}
Expand Down Expand Up @@ -182,11 +200,7 @@ func (p *genesisParams) generateGenesis() error {
}

func (p *genesisParams) initGenesisConfig() error {
// Disable london hardfork if burn contract address is not provided
enabledForks := chain.AllForksEnabled
if !p.isBurnContractEnabled() {
enabledForks.RemoveFork(chain.London)
}

chainConfig := &chain.Chain{
Name: p.name,
Expand All @@ -207,21 +221,8 @@ func (p *genesisParams) initGenesisConfig() error {
Bootnodes: p.bootnodes,
}

// burn contract can be set only for non mintable native token
if p.isBurnContractEnabled() {
chainConfig.Genesis.BaseFee = p.parsedBaseFeeConfig.baseFee
chainConfig.Genesis.BaseFeeEM = p.parsedBaseFeeConfig.baseFeeEM
chainConfig.Genesis.BaseFeeChangeDenom = p.parsedBaseFeeConfig.baseFeeChangeDenom
chainConfig.Params.BurnContract = make(map[uint64]types.Address, 1)

burnContractInfo, err := parseBurnContractInfo(p.burnContract)
if err != nil {
return err
}

chainConfig.Params.BurnContract[burnContractInfo.BlockNumber] = burnContractInfo.Address
chainConfig.Params.BurnContractDestinationAddress = burnContractInfo.DestinationAddress
}
chainConfig.Params.BurnContract = make(map[uint64]types.Address, 1)
chainConfig.Params.BurnContract[0] = types.ZeroAddress

for _, premineInfo := range p.premineInfos {
chainConfig.Genesis.Alloc[premineInfo.Address] = &chain.GenesisAccount{
Expand Down Expand Up @@ -250,6 +251,43 @@ func (p *genesisParams) parsePremineInfo() error {
return nil
}

func (p *genesisParams) parseStakeInfo() error {
p.stakeInfos = make(map[types.Address]*big.Int, len(p.stake))

for _, stake := range p.stake {
stakeInfo, err := helper.ParsePremineInfo(stake)
if err != nil {
return fmt.Errorf("invalid stake amount provided: %w", err)
}

p.stakeInfos[stakeInfo.Address] = stakeInfo.Amount
}

return nil
}

// validatePremineInfo validates whether reserve account (0x0 address) is premined
func (p *genesisParams) validatePremineInfo() error {
for _, premineInfo := range p.premineInfos {
if premineInfo.Address == types.ZeroAddress {
// we have premine of zero address, just return
return nil
}
}

return errReserveAccMustBePremined
}

// validateBlockTrackerPollInterval validates block tracker block interval
// which can not be 0
func (p *genesisParams) validateBlockTrackerPollInterval() error {
if p.blockTrackerPollInterval == 0 {
return helper.ErrBlockTrackerPollInterval
}

return nil
}

func (p *genesisParams) validateGenesisBaseFeeConfig() error {
if p.baseFeeConfig == "" {
return errors.New("invalid input(empty string) for genesis base fee config flag")
Expand Down Expand Up @@ -277,11 +315,6 @@ func (p *genesisParams) validateGenesisBaseFeeConfig() error {
return nil
}

// isBurnContractEnabled returns true in case burn contract info is provided
func (p *genesisParams) isBurnContractEnabled() bool {
return p.burnContract != ""
}

func (p *genesisParams) getResult() command.CommandResult {
return &GenesisResult{
Message: fmt.Sprintf("\nGenesis written to %s\n", p.genesisPath),
Expand Down
44 changes: 5 additions & 39 deletions command/genesis/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,26 @@ func Test_extractNativeTokenMetadata(t *testing.T) {
},
{
name: "empty name provided",
rawConfig: ":TST:18:false",
rawConfig: ":TST:18:0x123456789",
expectErr: true,
},
{
name: "empty symbol provided",
rawConfig: "Test::18:false",
rawConfig: "Test::18:0x123456789",
expectErr: true,
},
{
name: "invalid decimals number provided",
rawConfig: "Test:TST:9999999999999999999999999999999999999999999999999999999999:false",
rawConfig: "Test:TST:9999999999999999999999999999999999999999999999999999999999:false:0x123456789",
expectErr: true,
},
{
name: "invalid mintable flag provided",
rawConfig: "Test:TST:18:bar",
expectErr: true,
},
{
name: "mintable token not enough params provided",
rawConfig: "Test:TST:18:true",
expectErr: true,
},
{
name: "non-mintable valid config",
rawConfig: "MyToken:MTK:9:false",
expectedCfg: &polybft.TokenConfig{
Name: "MyToken",
Symbol: "MTK",
Decimals: 9,
IsMintable: false,
Owner: types.ZeroAddress,
},
expectErr: false,
},
{
name: "non-mintable token config, owner provided but ignored",
rawConfig: "MyToken:MTK:9:false:0x123456789",
name: "valid config",
rawConfig: "MyToken:MTK:9:0x123456789",
expectedCfg: &polybft.TokenConfig{
Name: "MyToken",
Symbol: "MTK",
Decimals: 9,
IsMintable: false,
Owner: types.ZeroAddress,
},
expectErr: false,
},
{
name: "mintable token valid config",
rawConfig: "MyMintToken:MMTK:9:true:0x123456789",
expectedCfg: &polybft.TokenConfig{
Name: "MyMintToken",
Symbol: "MMTK",
Decimals: 9,
IsMintable: true,
Owner: types.StringToAddress("0x123456789"),
},
Expand Down
Loading
Loading