Skip to content

Commit 8eeca7f

Browse files
committed
[tmpnet] Switch back to using maps for subnet config
Using subnet.Config to define subnet configuration initially seemed like a good idea - typing for the win - but went down in flames due to a combination the semantics of JSON marshaling and how subnet config defaults are set by the node. So, back to maps we go.
1 parent 001ff19 commit 8eeca7f

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

subnets/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Config struct {
2424
// AllowedNodes is the set of node IDs that are explicitly allowed to connect to this Subnet when
2525
// ValidatorOnly is enabled.
2626
AllowedNodes set.Set[ids.NodeID] `json:"allowedNodes" yaml:"allowedNodes"`
27-
ConsensusParameters snowball.Parameters `json:"consensusParameters" yaml:"consensusParameters,omitempty"`
27+
ConsensusParameters snowball.Parameters `json:"consensusParameters" yaml:"consensusParameters"`
2828

2929
// ProposerMinBlockDelay is the minimum delay this node will enforce when
3030
// building a snowman++ block.

tests/fixture/subnet/xsvm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func NewXSVMOrPanic(name string, key *secp256k1.PrivateKey, nodes ...*tmpnet.Nod
3333

3434
return &tmpnet.Subnet{
3535
Name: name,
36+
Config: tmpnet.FlagsMap{
37+
// Reducing this from the 1s default speeds up tx acceptance
38+
"proposerMinBlockDelay": 0,
39+
},
3640
Chains: []*tmpnet.Chain{
3741
{
3842
VMID: constants.XSVMID,

tests/fixture/tmpnet/network.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/ava-labs/avalanchego/config"
2929
"github.com/ava-labs/avalanchego/genesis"
3030
"github.com/ava-labs/avalanchego/ids"
31-
"github.com/ava-labs/avalanchego/subnets"
3231
"github.com/ava-labs/avalanchego/utils/constants"
3332
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
3433
"github.com/ava-labs/avalanchego/utils/logging"
@@ -108,7 +107,7 @@ type Network struct {
108107
Genesis *genesis.UnparsedConfig
109108

110109
// Configuration for primary subnets
111-
PrimarySubnetConfig *subnets.Config
110+
PrimarySubnetConfig FlagsMap
112111

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

876-
if n.PrimarySubnetConfig != nil {
877-
subnetConfigs[constants.PrimaryNetworkID] = *n.PrimarySubnetConfig
875+
if len(n.PrimarySubnetConfig) > 0 {
876+
subnetConfigs[constants.PrimaryNetworkID] = n.PrimarySubnetConfig
878877
}
879878

880879
// Collect configuration for non-primary subnets
@@ -884,10 +883,10 @@ func (n *Network) GetSubnetConfigContent() (string, error) {
884883
// possible to supply configuration without an ID.
885884
continue
886885
}
887-
if subnet.Config == nil {
886+
if len(subnet.Config) == 0 {
888887
continue
889888
}
890-
subnetConfigs[subnet.SubnetID] = *subnet.Config
889+
subnetConfigs[subnet.SubnetID] = subnet.Config
891890
}
892891

893892
if len(subnetConfigs) == 0 {

tests/fixture/tmpnet/network_config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"path/filepath"
1212

1313
"github.com/ava-labs/avalanchego/genesis"
14-
"github.com/ava-labs/avalanchego/subnets"
1514
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
1615
"github.com/ava-labs/avalanchego/utils/perms"
1716
)
@@ -131,7 +130,7 @@ func (n *Network) readConfig() error {
131130
type serializedNetworkConfig struct {
132131
UUID string `json:",omitempty"`
133132
Owner string `json:",omitempty"`
134-
PrimarySubnetConfig *subnets.Config `json:",omitempty"`
133+
PrimarySubnetConfig FlagsMap `json:",omitempty"`
135134
PrimaryChainConfigs map[string]FlagsMap `json:",omitempty"`
136135
DefaultFlags FlagsMap `json:",omitempty"`
137136
DefaultRuntimeConfig NodeRuntimeConfig `json:",omitempty"`

tests/fixture/tmpnet/network_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import (
88

99
"github.com/stretchr/testify/require"
1010

11-
"github.com/ava-labs/avalanchego/ids"
12-
"github.com/ava-labs/avalanchego/subnets"
1311
"github.com/ava-labs/avalanchego/utils/logging"
14-
"github.com/ava-labs/avalanchego/utils/set"
1512
)
1613

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

2219
network := NewDefaultNetwork("testnet")
2320
// Validate round-tripping of primary subnet configuration
24-
network.PrimarySubnetConfig = &subnets.Config{
25-
ValidatorOnly: true,
26-
AllowedNodes: set.Set[ids.NodeID]{},
21+
network.PrimarySubnetConfig = FlagsMap{
22+
"validatorOnly": true,
2723
}
2824
require.NoError(network.EnsureDefaultConfig(logging.NoLog{}, "/path/to/avalanche/go", ""))
2925
require.NoError(network.Create(tmpDir))

tests/fixture/tmpnet/subnet.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"go.uber.org/zap"
1616

1717
"github.com/ava-labs/avalanchego/ids"
18-
"github.com/ava-labs/avalanchego/subnets"
1918
"github.com/ava-labs/avalanchego/utils/constants"
2019
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
2120
"github.com/ava-labs/avalanchego/utils/logging"
@@ -56,7 +55,7 @@ type Subnet struct {
5655
// networks (since the SubnetID will be different every time the subnet is created)
5756
Name string
5857

59-
Config *subnets.Config
58+
Config FlagsMap
6059

6160
// The ID of the transaction that created the subnet
6261
SubnetID ids.ID

0 commit comments

Comments
 (0)