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

Check for non empty genesis #40

Merged
merged 11 commits into from
Jun 5, 2024
1 change: 0 additions & 1 deletion subnet/add_validator_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestAddValidatorDeploy(_ *testing.T) {
subnetParams := SubnetParams{
SubnetEVM: &SubnetEVMParams{
EvmChainID: 1234567,
EvmDefaults: true,
EnableWarp: true,
EnableTeleporter: true,
EnableRelayer: true,
Expand Down
34 changes: 19 additions & 15 deletions subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"encoding/json"
"errors"
"fmt"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"

Check failure on line 11 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
"math/big"
"os"
"time"

Check failure on line 14 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 15 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
"github.com/ava-labs/avalanche-tooling-sdk-go/avalanche"
"github.com/ava-labs/avalanche-tooling-sdk-go/key"
"github.com/ava-labs/avalanche-tooling-sdk-go/teleporter"
Expand All @@ -23,7 +24,6 @@
"github.com/ava-labs/subnet-evm/core"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -51,9 +51,6 @@
// Chain ID to use in Subnet-EVM
EvmChainID uint64

// Use default settings for fees, airdrop, precompiles and teleporter in Subnet-EVM
EvmDefaults bool

// Enable Avalanche Warp Messaging (AWM) when deploying a VM

// See https://docs.avax.network/build/cross-chain/awm/overview for
Expand Down Expand Up @@ -136,6 +133,14 @@
if subnetParams.SubnetEVM == nil && subnetParams.CustomVM != nil {
return nil, fmt.Errorf("SubnetEVM params and CustomVM params cannot both be non-empty")
}
if subnetParams.SubnetEVM != nil {
if subnetParams.SubnetEVM.GenesisParams == nil {
return nil, fmt.Errorf("SubnetEVM Genesis params cannot be empty")
}
if subnetParams.SubnetEVM.EvmChainID == 0 {
return nil, fmt.Errorf("SubnetEVM EvmChainID cannot be empty")
}
}
var genesisBytes []byte
var err error
switch {
Expand All @@ -145,6 +150,7 @@
genesisBytes, err = createEvmGenesis(
subnetParams.SubnetEVM.EvmChainID,
subnetParams.SubnetEVM.GenesisParams,
subnetParams.SubnetEVM.EnableWarp,
)
case subnetParams.CustomVM != nil:
genesisBytes, err = createCustomVMGenesis()
Expand All @@ -160,10 +166,10 @@
return &subnet, nil
}

// removed usewarp from argument, to use warp add it manualluy to precompile
func createEvmGenesis(
chainID uint64,
genesisParams *EVMGenesisParams,
useWarp bool,
) ([]byte, error) {
genesis := core.Genesis{}
genesis.Timestamp = *utils.TimeToNewUint64(time.Now())
Expand All @@ -174,30 +180,28 @@
var err error

if genesisParams.FeeConfig == commontype.EmptyFeeConfig {
conf.FeeConfig = vm.StarterFeeConfig
} else {
conf.FeeConfig = genesisParams.FeeConfig
return nil, fmt.Errorf("genesis params fee config cannot be empty")
}
allocation := core.GenesisAlloc{}

if genesisParams.Allocation == nil {
allocation, err = getNewAllocation(vm.DefaultEvmAirdropAmount, genesisParams.AllocationKey)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("genesis params allocation cannot be empty")
}

allocation := genesisParams.Allocation
if genesisParams.TeleporterInfo != nil {
allocation = addTeleporterAddressToAllocations(
allocation,
genesisParams.TeleporterInfo.FundedAddress,
genesisParams.TeleporterInfo.FundedBalance,
)
}

if genesisParams.Precompiles == nil {
return nil, fmt.Errorf("genesis params precompiles cannot be empty")
}
if useWarp {
warpConfig := vm.ConfigureWarp(&genesis.Timestamp)
conf.GenesisPrecompiles[warp.ConfigKey] = &warpConfig
}

if genesisParams.TeleporterInfo != nil {
*conf = vm.AddTeleporterAddressesToAllowLists(
*conf,
Expand Down Expand Up @@ -262,7 +266,7 @@
)
}

func getNewAllocation(defaultAirdropAmount string, key *key.SoftKey) (core.GenesisAlloc, error) {

Check failure on line 269 in subnet/subnet.go

View workflow job for this annotation

GitHub Actions / Lint

func `getNewAllocation` is unused (unused)
allocation := core.GenesisAlloc{}
defaultAmount, ok := new(big.Int).SetString(defaultAirdropAmount, 10)
if !ok {
Expand Down
1 change: 0 additions & 1 deletion subnet/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestSubnetDeploy(_ *testing.T) {
subnetParams := SubnetParams{
SubnetEVM: &SubnetEVMParams{
EvmChainID: 1234567,
EvmDefaults: true,
EnableWarp: true,
EnableTeleporter: true,
EnableRelayer: true,
Expand Down
Loading