From fb78c5902034adc44cf3af8d3c0e062250cf73d5 Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Mon, 3 Jun 2024 20:30:38 -0400 Subject: [PATCH 1/2] add subnet check --- subnet/add_validator_subnet_test.go | 2 +- subnet/join_subnet.go | 2 +- subnet/subnet.go | 14 ++++++++++---- subnet/subnet_test.go | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/subnet/add_validator_subnet_test.go b/subnet/add_validator_subnet_test.go index 16944a7..ae32a8b 100644 --- a/subnet/add_validator_subnet_test.go +++ b/subnet/add_validator_subnet_test.go @@ -21,7 +21,7 @@ func TestAddValidatorDeploy(_ *testing.T) { // like logging, metrics preferences, etc baseApp := avalanche.New(avalanche.DefaultLeveledLogger) subnetParams := SubnetParams{ - SubnetEVM: SubnetEVMParams{ + SubnetEVM: &SubnetEVMParams{ EvmChainID: 1234567, EvmDefaults: true, EnableWarp: true, diff --git a/subnet/join_subnet.go b/subnet/join_subnet.go index e493d6b..455c254 100644 --- a/subnet/join_subnet.go +++ b/subnet/join_subnet.go @@ -1,4 +1,4 @@ -// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +4// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package subnet diff --git a/subnet/subnet.go b/subnet/subnet.go index 0c5968b..7866337 100644 --- a/subnet/subnet.go +++ b/subnet/subnet.go @@ -37,11 +37,11 @@ type SubnetParams struct { // Subnet-EVM parameters to use // Do not set SubnetEVM value if you are using Custom VM - SubnetEVM SubnetEVMParams + SubnetEVM *SubnetEVMParams // Custom VM parameters to use // Do not set CustomVM value if you are using Subnet-EVM - CustomVM CustomVMParams + CustomVM *CustomVMParams Name string } @@ -72,7 +72,7 @@ type SubnetEVMParams struct { // information on AWM Relayer EnableRelayer bool - GenesisParams EVMGenesisParams + GenesisParams *EVMGenesisParams } type CustomVMParams struct { @@ -129,6 +129,12 @@ type EVMGenesisParams struct { } func New(client *avalanche.BaseApp, subnetParams *SubnetParams) (*Subnet, error) { + if subnetParams.GenesisFilePath != "" && (subnetParams.CustomVM != nil || subnetParams.SubnetEVM != nil) { + return nil, fmt.Errorf("genesis file path cannot be non-empty if either CustomVM params or SubnetEVM params is not empty") + } + if subnetParams.SubnetEVM == nil && subnetParams.CustomVM != nil { + return nil, fmt.Errorf("SubnetEVM params and CustomVM params cannot both be non-empty") + } genesisBytes, err := createEvmGenesis( subnetParams.SubnetEVM.EvmChainID, subnetParams.SubnetEVM.GenesisParams, @@ -146,7 +152,7 @@ func New(client *avalanche.BaseApp, subnetParams *SubnetParams) (*Subnet, error) // removed usewarp from argument, to use warp add it manualluy to precompile func createEvmGenesis( chainID uint64, - genesisParams EVMGenesisParams, + genesisParams *EVMGenesisParams, ) ([]byte, error) { genesis := core.Genesis{} genesis.Timestamp = *utils.TimeToNewUint64(time.Now()) diff --git a/subnet/subnet_test.go b/subnet/subnet_test.go index 9c34501..08c8e1b 100644 --- a/subnet/subnet_test.go +++ b/subnet/subnet_test.go @@ -20,7 +20,7 @@ func TestSubnetDeploy(_ *testing.T) { // like logging, metrics preferences, etc baseApp := avalanche.New(avalanche.DefaultLeveledLogger) subnetParams := SubnetParams{ - SubnetEVM: SubnetEVMParams{ + SubnetEVM: &SubnetEVMParams{ EvmChainID: 1234567, EvmDefaults: true, EnableWarp: true, From b3b4a8bfcd18c1d0734471a284b7dcba7fbc084f Mon Sep 17 00:00:00 2001 From: Raymond Sukanto Date: Mon, 3 Jun 2024 20:33:28 -0400 Subject: [PATCH 2/2] fix lint --- subnet/join_subnet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subnet/join_subnet.go b/subnet/join_subnet.go index 455c254..e493d6b 100644 --- a/subnet/join_subnet.go +++ b/subnet/join_subnet.go @@ -1,4 +1,4 @@ -4// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package subnet