Skip to content

Commit

Permalink
Merge pull request #36 from ava-labs/add-subnet-check
Browse files Browse the repository at this point in the history
Add subnet check
  • Loading branch information
sukantoraymond authored Jun 4, 2024
2 parents c74b518 + b3b4a8b commit 8ccb4dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion subnet/add_validator_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -72,7 +72,7 @@ type SubnetEVMParams struct {
// information on AWM Relayer
EnableRelayer bool

GenesisParams EVMGenesisParams
GenesisParams *EVMGenesisParams
}

type CustomVMParams struct {
Expand Down Expand Up @@ -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,
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion subnet/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8ccb4dc

Please sign in to comment.