Commit b2e3a8ea authored by Anatolie Lupacescu's avatar Anatolie Lupacescu Committed by GitHub

feat: main net flag (#2159)

parent dee0655c
...@@ -68,6 +68,7 @@ const ( ...@@ -68,6 +68,7 @@ const (
optionNamePriceOracleAddress = "price-oracle-address" optionNamePriceOracleAddress = "price-oracle-address"
optionNameBlockTime = "block-time" optionNameBlockTime = "block-time"
optionWarmUpTime = "warmup-time" optionWarmUpTime = "warmup-time"
optionNameMainNet = "mainnet"
) )
func init() { func init() {
...@@ -209,7 +210,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) { ...@@ -209,7 +210,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionNameNATAddr, "", "NAT exposed address") cmd.Flags().String(optionNameNATAddr, "", "NAT exposed address")
cmd.Flags().Bool(optionNameP2PWSEnable, false, "enable P2P WebSocket transport") cmd.Flags().Bool(optionNameP2PWSEnable, false, "enable P2P WebSocket transport")
cmd.Flags().Bool(optionNameP2PQUICEnable, false, "enable P2P QUIC transport") cmd.Flags().Bool(optionNameP2PQUICEnable, false, "enable P2P QUIC transport")
cmd.Flags().StringSlice(optionNameBootnodes, []string{"/dnsaddr/bootnode.ethswarm.org"}, "initial nodes to connect to") cmd.Flags().StringSlice(optionNameBootnodes, []string{}, "initial nodes to connect to")
cmd.Flags().Bool(optionNameDebugAPIEnable, false, "enable debug HTTP API") cmd.Flags().Bool(optionNameDebugAPIEnable, false, "enable debug HTTP API")
cmd.Flags().String(optionNameDebugAPIAddr, ":1635", "debug HTTP API listen address") cmd.Flags().String(optionNameDebugAPIAddr, ":1635", "debug HTTP API listen address")
cmd.Flags().Uint64(optionNameNetworkID, 10, "ID of the Swarm network") cmd.Flags().Uint64(optionNameNetworkID, 10, "ID of the Swarm network")
...@@ -243,6 +244,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) { ...@@ -243,6 +244,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().Uint64(optionNameBlockTime, 15, "chain block time") cmd.Flags().Uint64(optionNameBlockTime, 15, "chain block time")
cmd.Flags().String(optionNameSwapDeploymentGasPrice, "", "gas price in wei to use for deployment and funding") cmd.Flags().String(optionNameSwapDeploymentGasPrice, "", "gas price in wei to use for deployment and funding")
cmd.Flags().Duration(optionWarmUpTime, time.Minute*10, "time to warmup the node before pull/push protocols can be kicked off.") cmd.Flags().Duration(optionWarmUpTime, time.Minute*10, "time to warmup the node before pull/push protocols can be kicked off.")
cmd.Flags().Bool(optionNameMainNet, false, "triggers connect to main net bootnodes.")
} }
func newLogger(cmd *cobra.Command, verbosity string) (logging.Logger, error) { func newLogger(cmd *cobra.Command, verbosity string) (logging.Logger, error) {
......
...@@ -127,7 +127,18 @@ inability to use, or your interaction with other nodes or the software.`) ...@@ -127,7 +127,18 @@ inability to use, or your interaction with other nodes or the software.`)
return errors.New("boot node must be started as a full node") return errors.New("boot node must be started as a full node")
} }
b, err := node.NewBee(c.config.GetString(optionNameP2PAddr), signerConfig.publicKey, signerConfig.signer, c.config.GetUint64(optionNameNetworkID), logger, signerConfig.libp2pPrivateKey, signerConfig.pssPrivateKey, &node.Options{ mainnet := c.config.GetBool(optionNameMainNet)
networkID := c.config.GetUint64(optionNameNetworkID)
networkID, err = parseNetworks(mainnet, networkID)
if err != nil {
return err
}
bootnodes := c.config.GetStringSlice(optionNameBootnodes)
bootnodes = parseBootnodes(logger, mainnet, networkID, bootnodes)
b, err := node.NewBee(c.config.GetString(optionNameP2PAddr), signerConfig.publicKey, signerConfig.signer, networkID, logger, signerConfig.libp2pPrivateKey, signerConfig.pssPrivateKey, &node.Options{
DataDir: c.config.GetString(optionNameDataDir), DataDir: c.config.GetString(optionNameDataDir),
CacheCapacity: c.config.GetUint64(optionNameCacheCapacity), CacheCapacity: c.config.GetUint64(optionNameCacheCapacity),
DBOpenFilesLimit: c.config.GetUint64(optionNameDBOpenFilesLimit), DBOpenFilesLimit: c.config.GetUint64(optionNameDBOpenFilesLimit),
...@@ -141,7 +152,7 @@ inability to use, or your interaction with other nodes or the software.`) ...@@ -141,7 +152,7 @@ inability to use, or your interaction with other nodes or the software.`)
EnableWS: c.config.GetBool(optionNameP2PWSEnable), EnableWS: c.config.GetBool(optionNameP2PWSEnable),
EnableQUIC: c.config.GetBool(optionNameP2PQUICEnable), EnableQUIC: c.config.GetBool(optionNameP2PQUICEnable),
WelcomeMessage: c.config.GetString(optionWelcomeMessage), WelcomeMessage: c.config.GetString(optionWelcomeMessage),
Bootnodes: c.config.GetStringSlice(optionNameBootnodes), Bootnodes: bootnodes,
CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins), CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins),
Standalone: c.config.GetBool(optionNameStandalone), Standalone: c.config.GetBool(optionNameStandalone),
TracingEnabled: c.config.GetBool(optionNameTracingEnabled), TracingEnabled: c.config.GetBool(optionNameTracingEnabled),
...@@ -405,3 +416,29 @@ func (c *command) configureSigner(cmd *cobra.Command, logger logging.Logger) (co ...@@ -405,3 +416,29 @@ func (c *command) configureSigner(cmd *cobra.Command, logger logging.Logger) (co
pssPrivateKey: pssPrivateKey, pssPrivateKey: pssPrivateKey,
}, nil }, nil
} }
func parseNetworks(main bool, networkID uint64) (uint64, error) {
if main && networkID != 1 {
return 0, errors.New("provided network ID does not match mainnet")
}
return networkID, nil
}
func parseBootnodes(log logging.Logger, main bool, networkID uint64, bootnodes []string) []string {
if len(bootnodes) > 0 {
return bootnodes // use provided values
}
if main {
return []string{"/dnsaddr/mainnet.ethswarm.org"}
}
if networkID == 10 {
return []string{"/dnsaddr/testnet.ethswarm.org"}
}
log.Warning("no bootnodes defined for network ID", networkID)
return bootnodes
}
...@@ -88,3 +88,5 @@ password-file: /var/lib/bee/password ...@@ -88,3 +88,5 @@ password-file: /var/lib/bee/password
# verbosity: info # verbosity: info
## send a welcome message string during handshakes ## send a welcome message string during handshakes
# welcome-message: "" # welcome-message: ""
## triggers connection to main network
# bee-mainnet: false
...@@ -58,6 +58,7 @@ services: ...@@ -58,6 +58,7 @@ services:
- BEE_TRANSACTION - BEE_TRANSACTION
- BEE_VERBOSITY - BEE_VERBOSITY
- BEE_WELCOME_MESSAGE - BEE_WELCOME_MESSAGE
- BEE_MAINNET
ports: ports:
- "${API_ADDR:-1633}${BEE_API_ADDR:-:1633}" - "${API_ADDR:-1633}${BEE_API_ADDR:-:1633}"
- "${P2P_ADDR:-1634}${BEE_P2P_ADDR:-:1634}" - "${P2P_ADDR:-1634}${BEE_P2P_ADDR:-:1634}"
......
...@@ -95,3 +95,5 @@ BEE_CLEF_SIGNER_ENABLE=true ...@@ -95,3 +95,5 @@ BEE_CLEF_SIGNER_ENABLE=true
# BEE_VERBOSITY=info # BEE_VERBOSITY=info
## send a welcome message string during handshakes ## send a welcome message string during handshakes
# BEE_WELCOME_MESSAGE= # BEE_WELCOME_MESSAGE=
## triggers connection to main network
# BEE_MAINNET=
...@@ -88,3 +88,5 @@ password-file: /usr/local/var/lib/swarm-bee/password ...@@ -88,3 +88,5 @@ password-file: /usr/local/var/lib/swarm-bee/password
# verbosity: info # verbosity: info
## send a welcome message string during handshakes ## send a welcome message string during handshakes
# welcome-message: "" # welcome-message: ""
## triggers connection to main network
# bee-mainnet: false
...@@ -78,3 +78,5 @@ password-file: ./password ...@@ -78,3 +78,5 @@ password-file: ./password
# verbosity: info # verbosity: info
## send a welcome message string during handshakes ## send a welcome message string during handshakes
# welcome-message: "" # welcome-message: ""
## triggers connection to main network
# bee-mainnet: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment