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

Add subnet check #36

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading