@@ -28,6 +28,7 @@ import (
28
28
"github.com/ava-labs/avalanchego/genesis"
29
29
"github.com/ava-labs/avalanchego/ids"
30
30
"github.com/ava-labs/avalanchego/subnets"
31
+ "github.com/ava-labs/avalanchego/utils/constants"
31
32
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
32
33
"github.com/ava-labs/avalanchego/utils/logging"
33
34
"github.com/ava-labs/avalanchego/utils/perms"
@@ -106,7 +107,7 @@ type Network struct {
106
107
Genesis * genesis.UnparsedConfig
107
108
108
109
// Configuration for primary subnets
109
- PrimarySubnetConfigs map [ids. ID ] subnets.Config
110
+ PrimarySubnetConfig * subnets.Config
110
111
111
112
// Configuration for primary network chains (P, X, C)
112
113
PrimaryChainConfigs map [string ]FlagsMap
@@ -197,6 +198,9 @@ func ReadNetwork(dir string) (*Network, error) {
197
198
if err := network .Read (); err != nil {
198
199
return nil , fmt .Errorf ("failed to read network: %w" , err )
199
200
}
201
+ if network .DefaultFlags == nil {
202
+ network .DefaultFlags = FlagsMap {}
203
+ }
200
204
return network , nil
201
205
}
202
206
@@ -212,17 +216,9 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger, avalancheGoPath string
212
216
n .UUID = uuid .NewString ()
213
217
}
214
218
215
- // Ensure default flags
216
219
if n .DefaultFlags == nil {
217
220
n .DefaultFlags = FlagsMap {}
218
221
}
219
- n .DefaultFlags .SetDefaults (DefaultTmpnetFlags ())
220
-
221
- if len (n .Nodes ) == 1 {
222
- // Sybil protection needs to be disabled for a single node network to start
223
- log .Info ("starting a single-node network with sybil protection disabled" )
224
- n .DefaultFlags [config .SybilProtectionEnabledKey ] = false
225
- }
226
222
227
223
// Only configure the plugin dir with a non-empty value to ensure
228
224
// the use of the default value (`[datadir]/plugins`) when
@@ -505,7 +501,7 @@ func (n *Network) StartNode(ctx context.Context, log logging.Logger, node *Node)
505
501
return err
506
502
}
507
503
508
- if err := n .writeNodeFlags (node ); err != nil {
504
+ if err := n .writeNodeFlags (log , node ); err != nil {
509
505
return fmt .Errorf ("writing node flags: %w" , err )
510
506
}
511
507
@@ -769,12 +765,12 @@ func (n *Network) CreateSubnets(ctx context.Context, log logging.Logger, apiURI
769
765
return err
770
766
}
771
767
772
- // Persist the subnet
773
768
if err := subnet .Write (n .GetSubnetDir ()); err != nil {
774
769
return err
775
770
}
776
- log .Info ("wrote subnet" ,
771
+ log .Info ("wrote subnet configuration " ,
777
772
zap .String ("name" , subnet .Name ),
773
+ zap .Stringer ("id" , subnet .SubnetID ),
778
774
)
779
775
780
776
// If one or more of the subnets chains have explicit configuration, the
@@ -877,7 +873,11 @@ func (n *Network) GetGenesisFileContent() (string, error) {
877
873
// GetSubnetConfigContent returns the base64-encoded and
878
874
// JSON-marshaled map of subnetID to subnet configuration.
879
875
func (n * Network ) GetSubnetConfigContent () (string , error ) {
880
- subnetConfigs := maps .Clone (n .PrimarySubnetConfigs )
876
+ subnetConfigs := map [ids.ID ]subnets.Config {}
877
+
878
+ if n .PrimarySubnetConfig != nil {
879
+ subnetConfigs [constants .PrimaryNetworkID ] = * n .PrimarySubnetConfig
880
+ }
881
881
882
882
// Collect configuration for non-primary subnets
883
883
for _ , subnet := range n .Subnets {
@@ -940,22 +940,24 @@ func (n *Network) GetChainConfigContent() (string, error) {
940
940
941
941
// writeNodeFlags determines the set of flags that should be used to
942
942
// start the given node and writes them to a file in the node path.
943
- func (n * Network ) writeNodeFlags (node * Node ) error {
943
+ func (n * Network ) writeNodeFlags (log logging. Logger , node * Node ) error {
944
944
flags := maps .Clone (node .Flags )
945
945
946
946
// Convert the network id to a string to ensure consistency in JSON round-tripping.
947
- flags [ config .NetworkNameKey ] = strconv .FormatUint (uint64 (n .GetNetworkID ()), 10 )
947
+ flags . SetDefault ( config .NetworkNameKey , strconv .FormatUint (uint64 (n .GetNetworkID ()), 10 ) )
948
948
949
- // Set the network defaults
950
- flags .SetDefaults (n .DefaultFlags )
949
+ if n .Genesis != nil && len (n .Genesis .InitialStakers ) == 1 {
950
+ log .Info ("disabling sybil protection to enable a single-node network to start" )
951
+ flags [config .SybilProtectionEnabledKey ] = false
952
+ }
951
953
952
954
// Set the bootstrap configuration
953
955
bootstrapIPs , bootstrapIDs , err := n .GetBootstrapIPsAndIDs (node )
954
956
if err != nil {
955
957
return fmt .Errorf ("failed to determine bootstrap configuration: %w" , err )
956
958
}
957
- flags [ config .BootstrapIDsKey ] = strings .Join (bootstrapIDs , "," )
958
- flags [ config .BootstrapIPsKey ] = strings .Join (bootstrapIPs , "," )
959
+ flags . SetDefault ( config .BootstrapIDsKey , strings .Join (bootstrapIDs , "," ) )
960
+ flags . SetDefault ( config .BootstrapIPsKey , strings .Join (bootstrapIPs , "," ) )
959
961
960
962
// TODO(marun) Maybe avoid computing content flags for each node start?
961
963
@@ -983,6 +985,10 @@ func (n *Network) writeNodeFlags(node *Node) error {
983
985
flags .SetDefault (config .ChainConfigContentKey , chainConfigContent )
984
986
}
985
987
988
+ // Set the network and tmpnet defaults last to ensure they can be overridden
989
+ flags .SetDefaults (n .DefaultFlags )
990
+ flags .SetDefaults (DefaultTmpnetFlags ())
991
+
986
992
// Write the flags to disk
987
993
return node .writeFlags (flags )
988
994
}
0 commit comments