@@ -244,6 +244,9 @@ var (
244
244
245
245
// This is the externally reachable address advertised over gossip for guardian p2p and ccq p2p.
246
246
gossipAdvertiseAddress * string
247
+
248
+ // env is the mode we are running in, Mainnet, Testnet or UnsafeDevnet.
249
+ env common.Environment
247
250
)
248
251
249
252
func init () {
@@ -490,13 +493,11 @@ func initConfig(cmd *cobra.Command, args []string) error {
490
493
}
491
494
492
495
func runNode (cmd * cobra.Command , args []string ) {
493
- if Build == "dev" && ! * unsafeDevMode {
494
- fmt .Println ("This is a development build. --unsafeDevMode must be enabled." )
495
- os .Exit (1 )
496
+ if * unsafeDevMode && * testnetMode {
497
+ fmt .Println ("Cannot be in unsafeDevMode and testnetMode at the same time." )
496
498
}
497
499
498
500
// Determine execution mode
499
- var env common.Environment
500
501
if * unsafeDevMode {
501
502
env = common .UnsafeDevNet
502
503
} else if * testnetMode {
@@ -505,11 +506,16 @@ func runNode(cmd *cobra.Command, args []string) {
505
506
env = common .MainNet
506
507
}
507
508
508
- if * unsafeDevMode {
509
+ if Build == "dev" && env != common .UnsafeDevNet {
510
+ fmt .Println ("This is a development build. --unsafeDevMode must be enabled." )
511
+ os .Exit (1 )
512
+ }
513
+
514
+ if env == common .UnsafeDevNet {
509
515
fmt .Print (devwarning )
510
516
}
511
517
512
- if * testnetMode || * unsafeDevMode {
518
+ if env != common . MainNet {
513
519
fmt .Println ("Not locking in memory." )
514
520
} else {
515
521
common .LockMemory ()
@@ -518,7 +524,7 @@ func runNode(cmd *cobra.Command, args []string) {
518
524
common .SetRestrictiveUmask ()
519
525
520
526
// Refuse to run as root in production mode.
521
- if ! * unsafeDevMode && os .Geteuid () == 0 {
527
+ if env != common . UnsafeDevNet && os .Geteuid () == 0 {
522
528
fmt .Println ("can't run as uid 0" )
523
529
os .Exit (1 )
524
530
}
@@ -537,7 +543,7 @@ func runNode(cmd *cobra.Command, args []string) {
537
543
zapcore .AddSync (zapcore .Lock (os .Stderr )),
538
544
zap .NewAtomicLevelAt (zapcore .Level (lvl ))))
539
545
540
- if * unsafeDevMode {
546
+ if env == common . UnsafeDevNet {
541
547
// Use the hostname as nodeName. For production, we don't want to do this to
542
548
// prevent accidentally leaking sensitive hostnames.
543
549
hostname , err := os .Hostname ()
@@ -550,15 +556,11 @@ func runNode(cmd *cobra.Command, args []string) {
550
556
logger = logger .Named (* nodeName )
551
557
}
552
558
553
- if * unsafeDevMode && * testnetMode {
554
- logger .Fatal ("Cannot be in unsafeDevMode and testnetMode at the same time." )
555
- }
556
-
557
559
// Override the default go-log config, which uses a magic environment variable.
558
560
ipfslog .SetAllLoggers (lvl )
559
561
560
562
// In devnet mode, we automatically set a number of flags that rely on deterministic keys.
561
- if * unsafeDevMode {
563
+ if env == common . UnsafeDevNet {
562
564
g0key , err := peer .IDFromPrivateKey (devnet .DeterministicP2PPrivKeyByIndex (0 ))
563
565
if err != nil {
564
566
panic (err )
@@ -602,7 +604,7 @@ func runNode(cmd *cobra.Command, args []string) {
602
604
603
605
// Verify flags
604
606
605
- if * nodeKeyPath == "" && ! * unsafeDevMode { // In devnet mode, keys are deterministically generated.
607
+ if * nodeKeyPath == "" && env != common . UnsafeDevNet { // In devnet mode, keys are deterministically generated.
606
608
logger .Fatal ("Please specify --nodeKey" )
607
609
}
608
610
if * guardianKeyPath == "" {
@@ -657,7 +659,7 @@ func runNode(cmd *cobra.Command, args []string) {
657
659
658
660
// Linea requires a couple of additional parameters.
659
661
* lineaContract = checkEvmArgs (logger , * lineaRPC , * lineaContract , "linea" , false )
660
- if (* lineaRPC != "" ) && (* lineaRollUpUrl == "" || * lineaRollUpContract == "" ) && ! * unsafeDevMode {
662
+ if (* lineaRPC != "" ) && (* lineaRollUpUrl == "" || * lineaRollUpContract == "" ) && env != common . UnsafeDevNet {
661
663
logger .Fatal ("If --lineaRPC is specified, --lineaRollUpUrl and --lineaRollUpContract must also be specified" )
662
664
}
663
665
@@ -753,7 +755,7 @@ func runNode(cmd *cobra.Command, args []string) {
753
755
}
754
756
755
757
// In devnet mode, we generate a deterministic guardian key and write it to disk.
756
- if * unsafeDevMode {
758
+ if env == common . UnsafeDevNet {
757
759
err := devnet .GenerateAndStoreDevnetGuardianKey (* guardianKeyPath )
758
760
if err != nil {
759
761
logger .Fatal ("failed to generate devnet guardian key" , zap .Error (err ))
@@ -765,7 +767,7 @@ func runNode(cmd *cobra.Command, args []string) {
765
767
defer db .Close ()
766
768
767
769
// Guardian key
768
- gk , err := common .LoadGuardianKey (* guardianKeyPath , * unsafeDevMode )
770
+ gk , err := common .LoadGuardianKey (* guardianKeyPath , env == common . UnsafeDevNet )
769
771
if err != nil {
770
772
logger .Fatal ("failed to load guardian key" , zap .Error (err ))
771
773
}
@@ -775,7 +777,7 @@ func runNode(cmd *cobra.Command, args []string) {
775
777
776
778
// Load p2p private key
777
779
var p2pKey libp2p_crypto.PrivKey
778
- if * unsafeDevMode {
780
+ if env == common . UnsafeDevNet {
779
781
idx , err := devnet .GetDevnetIndex ()
780
782
if err != nil {
781
783
logger .Fatal ("Failed to parse hostname - are we running in devnet?" )
@@ -887,7 +889,7 @@ func runNode(cmd *cobra.Command, args []string) {
887
889
var hasTelemetryCredential bool = usingLoki
888
890
889
891
// Telemetry is enabled by default in mainnet/testnet. In devnet it is disabled by default
890
- if ! * disableTelemetry && (! * unsafeDevMode || * unsafeDevMode && hasTelemetryCredential ) {
892
+ if ! * disableTelemetry && (env != common . UnsafeDevNet || ( env == common . UnsafeDevNet && hasTelemetryCredential ) ) {
891
893
if ! hasTelemetryCredential {
892
894
logger .Fatal ("Please specify --telemetryLokiURL or set --disableTelemetry=false" )
893
895
}
@@ -932,7 +934,7 @@ func runNode(cmd *cobra.Command, args []string) {
932
934
ipfslog .SetPrimaryCore (logger .Core ())
933
935
934
936
wormchainId := "wormchain"
935
- if * testnetMode {
937
+ if env == common . TestNet {
936
938
wormchainId = "wormchain-testnet-0"
937
939
}
938
940
@@ -951,7 +953,7 @@ func runNode(cmd *cobra.Command, args []string) {
951
953
}
952
954
953
955
keyPathName := * accountantKeyPath
954
- if * unsafeDevMode {
956
+ if env == common . UnsafeDevNet {
955
957
idx , err := devnet .GetDevnetIndex ()
956
958
if err != nil {
957
959
logger .Fatal ("failed to get devnet index" , zap .Error (err ), zap .String ("component" , "gacct" ))
@@ -987,7 +989,7 @@ func runNode(cmd *cobra.Command, args []string) {
987
989
}
988
990
989
991
keyPathName := * accountantNttKeyPath
990
- if * unsafeDevMode {
992
+ if env == common . UnsafeDevNet {
991
993
idx , err := devnet .GetDevnetIndex ()
992
994
if err != nil {
993
995
logger .Fatal ("failed to get devnet index" , zap .Error (err ), zap .String ("component" , "gacct" ))
@@ -1022,7 +1024,7 @@ func runNode(cmd *cobra.Command, args []string) {
1022
1024
}
1023
1025
1024
1026
wormchainKeyPathName := * gatewayRelayerKeyPath
1025
- if * unsafeDevMode {
1027
+ if env == common . UnsafeDevNet {
1026
1028
idx , err := devnet .GetDevnetIndex ()
1027
1029
if err != nil {
1028
1030
logger .Fatal ("failed to get devnet index" , zap .Error (err ), zap .String ("component" , "gwrelayer" ))
@@ -1466,7 +1468,7 @@ func runNode(cmd *cobra.Command, args []string) {
1466
1468
watcherConfigs = append (watcherConfigs , wc )
1467
1469
}
1468
1470
1469
- if * testnetMode || * unsafeDevMode {
1471
+ if env == common . TestNet || env == common . UnsafeDevNet {
1470
1472
if shouldStart (sepoliaRPC ) {
1471
1473
wc := & evm.WatcherConfig {
1472
1474
NetworkID : "sepolia" ,
@@ -1599,7 +1601,7 @@ func shouldStart(rpc *string) bool {
1599
1601
// checkEvmArgs verifies that the RPC and contract address parameters for an EVM chain make sense, given the environment.
1600
1602
// If we are in devnet mode and the contract address is not specified, it returns the deterministic one for tilt.
1601
1603
func checkEvmArgs (logger * zap.Logger , rpc string , contractAddr , chainLabel string , mainnetSupported bool ) string {
1602
- if ! * unsafeDevMode {
1604
+ if env != common . UnsafeDevNet {
1603
1605
// In mainnet / testnet, if either parameter is specified, they must both be specified.
1604
1606
if (rpc == "" ) != (contractAddr == "" ) {
1605
1607
logger .Fatal (fmt .Sprintf ("Both --%sContract and --%sRPC must be set or both unset" , chainLabel , chainLabel ))
@@ -1616,16 +1618,12 @@ func checkEvmArgs(logger *zap.Logger, rpc string, contractAddr, chainLabel strin
1616
1618
}
1617
1619
}
1618
1620
}
1619
- if contractAddr != "" && ! mainnetSupported && mainnetMode () {
1621
+ if contractAddr != "" && ! mainnetSupported && env == common . MainNet {
1620
1622
logger .Fatal (fmt .Sprintf ("Chain %s not supported in mainnet" , chainLabel ))
1621
1623
}
1622
1624
return contractAddr
1623
1625
}
1624
1626
1625
- func mainnetMode () bool {
1626
- return (! * unsafeDevMode && ! * testnetMode )
1627
- }
1628
-
1629
1627
// argsConsistent verifies that the arguments in the array are all set or all unset.
1630
1628
// Note that it doesn't validate the values, just whether they are blank or not.
1631
1629
func argsConsistent (args []string ) bool {
0 commit comments