Skip to content

[tmpnet] Switch back to using maps for subnet config #3877

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

Merged
merged 1 commit into from
Apr 14, 2025
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 subnets/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Config struct {
// AllowedNodes is the set of node IDs that are explicitly allowed to connect to this Subnet when
// ValidatorOnly is enabled.
AllowedNodes set.Set[ids.NodeID] `json:"allowedNodes" yaml:"allowedNodes"`
ConsensusParameters snowball.Parameters `json:"consensusParameters" yaml:"consensusParameters,omitempty"`
ConsensusParameters snowball.Parameters `json:"consensusParameters" yaml:"consensusParameters"`

// ProposerMinBlockDelay is the minimum delay this node will enforce when
// building a snowman++ block.
Expand Down
4 changes: 4 additions & 0 deletions tests/fixture/subnet/xsvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func NewXSVMOrPanic(name string, key *secp256k1.PrivateKey, nodes ...*tmpnet.Nod

return &tmpnet.Subnet{
Name: name,
Config: tmpnet.FlagsMap{
// Reducing this from the 1s default speeds up tx acceptance
"proposerMinBlockDelay": 0,
},
Comment on lines +36 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a no-op - the default is 1s.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include a non no-op config change in this PR? Just looking to understand here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addition ensures tmpnet usage of subnet configuration for non-primary subnets.

Chains: []*tmpnet.Chain{
{
VMID: constants.XSVMID,
Expand Down
13 changes: 6 additions & 7 deletions tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -108,7 +107,7 @@ type Network struct {
Genesis *genesis.UnparsedConfig

// Configuration for primary subnets
PrimarySubnetConfig *subnets.Config
PrimarySubnetConfig FlagsMap

// Configuration for primary network chains (P, X, C)
PrimaryChainConfigs map[string]FlagsMap
Expand Down Expand Up @@ -871,10 +870,10 @@ func (n *Network) GetGenesisFileContent() (string, error) {
// GetSubnetConfigContent returns the base64-encoded and
// JSON-marshaled map of subnetID to subnet configuration.
func (n *Network) GetSubnetConfigContent() (string, error) {
subnetConfigs := map[ids.ID]subnets.Config{}
subnetConfigs := map[ids.ID]FlagsMap{}

if n.PrimarySubnetConfig != nil {
subnetConfigs[constants.PrimaryNetworkID] = *n.PrimarySubnetConfig
if len(n.PrimarySubnetConfig) > 0 {
subnetConfigs[constants.PrimaryNetworkID] = n.PrimarySubnetConfig
}

// Collect configuration for non-primary subnets
Expand All @@ -884,10 +883,10 @@ func (n *Network) GetSubnetConfigContent() (string, error) {
// possible to supply configuration without an ID.
continue
}
if subnet.Config == nil {
if len(subnet.Config) == 0 {
continue
}
subnetConfigs[subnet.SubnetID] = *subnet.Config
subnetConfigs[subnet.SubnetID] = subnet.Config
}

if len(subnetConfigs) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions tests/fixture/tmpnet/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path/filepath"

"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/perms"
)
Expand Down Expand Up @@ -131,7 +130,7 @@ func (n *Network) readConfig() error {
type serializedNetworkConfig struct {
UUID string `json:",omitempty"`
Owner string `json:",omitempty"`
PrimarySubnetConfig *subnets.Config `json:",omitempty"`
PrimarySubnetConfig FlagsMap `json:",omitempty"`
PrimaryChainConfigs map[string]FlagsMap `json:",omitempty"`
DefaultFlags FlagsMap `json:",omitempty"`
DefaultRuntimeConfig NodeRuntimeConfig `json:",omitempty"`
Expand Down
8 changes: 2 additions & 6 deletions tests/fixture/tmpnet/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
)

func TestNetworkSerialization(t *testing.T) {
Expand All @@ -21,9 +18,8 @@ func TestNetworkSerialization(t *testing.T) {

network := NewDefaultNetwork("testnet")
// Validate round-tripping of primary subnet configuration
network.PrimarySubnetConfig = &subnets.Config{
ValidatorOnly: true,
AllowedNodes: set.Set[ids.NodeID]{},
network.PrimarySubnetConfig = FlagsMap{
"validatorOnly": true,
}
require.NoError(network.EnsureDefaultConfig(logging.NoLog{}, "/path/to/avalanche/go", ""))
require.NoError(network.Create(tmpDir))
Expand Down
3 changes: 1 addition & 2 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -56,7 +55,7 @@ type Subnet struct {
// networks (since the SubnetID will be different every time the subnet is created)
Name string

Config *subnets.Config
Config FlagsMap

// The ID of the transaction that created the subnet
SubnetID ids.ID
Expand Down