2017-03-15 21:03:01 +00:00
package params
import (
2020-08-20 09:05:39 +00:00
"crypto/ecdsa"
"encoding/hex"
2017-03-15 21:03:01 +00:00
"encoding/json"
2017-05-02 14:30:11 +00:00
"fmt"
2017-03-15 21:03:01 +00:00
"io/ioutil"
"os"
"path/filepath"
"strings"
2019-01-15 09:21:33 +00:00
"time"
2017-03-15 21:03:01 +00:00
2024-10-28 20:54:17 +00:00
"go.uber.org/zap"
2020-01-02 09:10:19 +00:00
validator "gopkg.in/go-playground/validator.v9"
2022-09-13 09:30:52 +00:00
"github.com/ethereum/go-ethereum/common"
2018-04-10 06:44:09 +00:00
"github.com/ethereum/go-ethereum/p2p/discv5"
2021-06-30 11:40:54 +00:00
"github.com/ethereum/go-ethereum/params"
2020-01-02 09:10:19 +00:00
2019-12-19 16:03:00 +00:00
"github.com/status-im/status-go/eth-node/crypto"
2021-06-30 11:40:54 +00:00
"github.com/status-im/status-go/eth-node/types"
2024-11-06 17:36:49 +00:00
"github.com/status-im/status-go/internal/version"
2024-10-28 20:54:17 +00:00
"github.com/status-im/status-go/logutils"
2018-09-13 16:31:29 +00:00
"github.com/status-im/status-go/static"
2020-08-19 12:06:41 +00:00
wakucommon "github.com/status-im/status-go/waku/common"
2021-06-16 20:19:45 +00:00
wakuv2common "github.com/status-im/status-go/wakuv2/common"
2017-03-15 21:03:01 +00:00
)
2021-06-30 11:40:54 +00:00
// ----------
// LightEthConfig
// ----------
// LightEthConfig holds LES-related configuration
// Status nodes are always lightweight clients (due to mobile platform constraints)
type LightEthConfig struct {
// Enabled flag specifies whether protocol is enabled
Enabled bool
// DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced)
DatabaseCache int
// TrustedNodes is a list of trusted servers
TrustedNodes [ ] string
//MinTrustedFraction is minimum percentage of connected trusted servers to validate header(1-100)
MinTrustedFraction int
}
2020-01-08 11:12:23 +00:00
// ----------
// DatabaseConfig
// ----------
type DatabaseConfig struct {
PGConfig PGConfig
}
// ----------
// PGConfig
// ----------
type PGConfig struct {
// Enabled whether we should use a Postgres instance
Enabled bool
// The URI of the server
URI string
}
// ----------
// WakuConfig
// ----------
// WakuConfig provides a configuration for Waku service.
type WakuConfig struct {
// Enabled set to true enables Waku subprotocol.
Enabled bool
// LightClient should be true if the node should start with an empty bloom filter and not forward messages from other nodes
LightClient bool
2020-08-20 09:05:39 +00:00
// FullNode should be true if waku should always acta as a full node
FullNode bool
2020-01-08 11:12:23 +00:00
// EnableMailServer is mode when node is capable of delivering expired messages on demand
EnableMailServer bool
2020-05-14 05:40:40 +00:00
// DataDir is the file system folder Waku should use for any data storage needs.
2020-01-08 11:12:23 +00:00
// For instance, MailServer will use this directory to store its data.
DataDir string
2020-05-14 05:40:40 +00:00
// MinimumPoW minimum PoW for Waku messages
// We enforce a minimum as a bland spam prevention mechanism.
2020-01-08 11:12:23 +00:00
MinimumPoW float64
2020-05-14 05:40:40 +00:00
// MailServerPassword for symmetric encryption of waku message history requests.
2020-01-08 11:12:23 +00:00
// (if no account file selected, then this password is used for symmetric encryption).
MailServerPassword string
// MailServerRateLimit minimum time between queries to mail server per peer.
MailServerRateLimit int
// MailServerDataRetention is a number of days data should be stored by MailServer.
MailServerDataRetention int
// TTL time to live for messages, in seconds
TTL int
2020-05-14 05:40:40 +00:00
// MaxMessageSize is a maximum size of a devp2p packet handled by the Waku protocol,
2020-01-08 11:12:23 +00:00
// not only the size of envelopes sent in that packet.
MaxMessageSize uint32
// DatabaseConfig is configuration for which data store we use.
DatabaseConfig DatabaseConfig
// EnableRateLimiter set to true enables IP and peer ID rate limiting.
EnableRateLimiter bool
2020-06-08 11:15:19 +00:00
// PacketRateLimitIP sets the limit on the number of packets per second
2020-01-08 11:12:23 +00:00
// from a given IP.
2020-06-08 09:43:56 +00:00
PacketRateLimitIP int64
2020-01-08 11:12:23 +00:00
2020-06-08 11:15:19 +00:00
// PacketRateLimitPeerID sets the limit on the number of packets per second
2020-01-08 11:12:23 +00:00
// from a given peer ID.
2020-06-08 09:43:56 +00:00
PacketRateLimitPeerID int64
2020-01-08 11:12:23 +00:00
2020-06-08 11:15:19 +00:00
// BytesRateLimitIP sets the limit on the number of bytes per second
// from a given IP.
BytesRateLimitIP int64
// BytesRateLimitPeerID sets the limit on the number of bytes per second
// from a given peer ID.
BytesRateLimitPeerID int64
2020-01-08 11:12:23 +00:00
// RateLimitTolerance is a number of how many a limit must be exceeded
// in order to drop a peer.
// If equal to 0, the peers are never dropped.
RateLimitTolerance int64
2020-02-21 14:48:53 +00:00
// BloomFilterMode tells us whether we should be sending a bloom
// filter rather than TopicInterest
BloomFilterMode bool
2020-09-09 08:10:01 +00:00
// SoftBlacklistedPeerIDs is a list of peer ids that should be soft-blacklisted (messages should be dropped but connection kept)
SoftBlacklistedPeerIDs [ ] string
2021-01-26 11:32:52 +00:00
// EnableConfirmations when true, instructs that confirmation should be sent for received messages
EnableConfirmations bool
2020-01-08 11:12:23 +00:00
}
2021-06-16 20:19:45 +00:00
// ----------
// WakuV2Config
// ----------
// WakuConfig provides a configuration for Waku service.
type WakuV2Config struct {
// Enabled set to true enables Waku subprotocol.
Enabled bool
// Host interface in which to start libp2p protocol
Host string
// Port number in which to start libp2p protocol (0 for random)
Port int
2021-09-23 16:17:57 +00:00
// LightClient should be true if the node will not relay messages and only rely on lightpush/filter nodes
2021-06-16 20:19:45 +00:00
LightClient bool
// FullNode should be true if waku should always acta as a full node
FullNode bool
2021-10-06 16:08:54 +00:00
// DiscoveryLimit indicates the maximum number of peers to discover
DiscoveryLimit int
2021-06-16 20:19:45 +00:00
// DataDir is the file system folder Waku should use for any data storage needs.
// For instance, MailServer will use this directory to store its data.
DataDir string
// MaxMessageSize is a maximum size of a devp2p packet handled by the Waku protocol,
// not only the size of envelopes sent in that packet.
MaxMessageSize uint32
// EnableConfirmations when true, instructs that confirmation should be sent for received messages
EnableConfirmations bool
2021-07-21 10:08:08 +00:00
// A name->libp2p_addr map for Wakuv2 custom nodes
CustomNodes map [ string ] string
2021-10-06 16:08:54 +00:00
2022-11-29 12:43:11 +00:00
// PeerExchange determines whether WakuV2 Peer Exchange is enabled or not
2024-02-27 09:24:34 +00:00
// Deprecated: will be calculated based on LightClient
2021-10-06 16:08:54 +00:00
PeerExchange bool
2021-11-22 13:40:14 +00:00
2023-01-03 14:14:59 +00:00
// Nameserver determines which nameserver will be used for dns discovery
Nameserver string
2021-11-22 13:40:14 +00:00
// EnableDiscV5 indicates if DiscoveryV5 is enabled or not
2024-03-01 05:43:07 +00:00
// Deprecated: will be calculated based on LightClient
2021-11-22 13:40:14 +00:00
EnableDiscV5 bool
// UDPPort number to start discovery v5
UDPPort int
// AutoUpdate instructs the node to update their own ip address and port with the values seen by other nodes
AutoUpdate bool
2022-08-19 16:34:07 +00:00
// EnableStore indicates if WakuStore protocol should be enabled or not
EnableStore bool
// StoreCapacity indicates the max number of messages to store
StoreCapacity int
// StoreSeconds indicates the maximum number of seconds before a message is removed from the store
StoreSeconds int
2023-09-27 20:06:53 +00:00
2024-05-22 22:01:54 +00:00
TelemetryServerURL string
2024-07-09 13:42:34 +00:00
// EnableMissingMessageVerification indicates whether the storenodes must be queried periodically to retrieve any missing message
EnableMissingMessageVerification bool
2024-07-10 10:39:37 +00:00
// EnableMissingMessageVerification indicates whether storenodes must be queried periodically to confirm if messages sent are actually propagated in the network
EnableStoreConfirmationForMessagesSent bool
2021-06-16 20:19:45 +00:00
}
2018-03-19 16:22:09 +00:00
// ----------
// SwarmConfig
// ----------
2017-03-15 21:03:01 +00:00
// SwarmConfig holds Swarm-related configuration
2017-03-28 09:04:52 +00:00
type SwarmConfig struct {
2017-05-11 13:20:27 +00:00
// Enabled flag specifies whether protocol is enabled
2017-03-28 09:04:52 +00:00
Enabled bool
}
2017-03-15 21:03:01 +00:00
2017-07-13 06:54:10 +00:00
// String dumps config object as nicely indented JSON
func ( c * SwarmConfig ) String ( ) string {
2018-01-17 16:46:21 +00:00
data , _ := json . MarshalIndent ( c , "" , " " ) // nolint: gas
2017-07-13 06:54:10 +00:00
return string ( data )
}
2018-03-19 16:22:09 +00:00
// ----------
2018-03-20 14:05:21 +00:00
// ClusterConfig
2018-03-19 16:22:09 +00:00
// ----------
2018-03-20 14:05:21 +00:00
// ClusterConfig holds configuration for supporting cluster peers, which is a temporary
2017-05-11 13:20:27 +00:00
// means for mobile devices to get connected to Ethereum network (UDP-based discovery
// may not be available, so we need means to discover the network manually).
2018-03-20 14:05:21 +00:00
type ClusterConfig struct {
2018-10-04 10:40:26 +00:00
// Enabled flag specifies that nodes in this configuration are taken into account.
2017-05-11 13:20:27 +00:00
Enabled bool
2018-10-04 10:40:26 +00:00
// Fleet is a name of a selected fleet. If it has a value, nodes are loaded
// from a file, namely `fleet-*.{{ .Fleet }}.json`. Nodes can be added to any list
// in `ClusterConfig`.
2018-07-25 14:03:35 +00:00
Fleet string
2018-10-04 10:40:26 +00:00
// StaticNodes is a list of static nodes.
2018-03-20 14:05:21 +00:00
StaticNodes [ ] string
2018-10-04 10:40:26 +00:00
// BootNodes is a list of bootnodes.
2024-05-22 13:49:41 +00:00
// Deprecated: won't be used at all in wakuv2
2017-08-04 16:14:17 +00:00
BootNodes [ ] string
2018-07-04 10:51:47 +00:00
2018-10-04 10:40:26 +00:00
// TrustedMailServers is a list of verified and trusted Mail Server nodes.
2018-07-25 14:48:02 +00:00
TrustedMailServers [ ] string
2020-08-20 09:05:39 +00:00
// PushNotificationsServers is a list of default push notification servers.
PushNotificationsServers [ ] string
2021-11-22 15:27:05 +00:00
// WakuNodes is a list of waku2 multiaddresses
WakuNodes [ ] string
2021-11-22 13:40:14 +00:00
// DiscV5Nodes is a list of enr to be used for ambient discovery
DiscV5BootstrapNodes [ ] string
2023-11-23 08:41:05 +00:00
//Waku network identifier
ClusterID uint16
2017-05-11 13:20:27 +00:00
}
2017-07-13 06:54:10 +00:00
// String dumps config object as nicely indented JSON
2018-03-20 14:05:21 +00:00
func ( c * ClusterConfig ) String ( ) string {
2018-01-17 16:46:21 +00:00
data , _ := json . MarshalIndent ( c , "" , " " ) // nolint: gas
2017-07-13 06:54:10 +00:00
return string ( data )
}
2018-04-10 06:44:09 +00:00
// Limits represent min and max amount of peers
2018-04-20 07:39:31 +00:00
type Limits struct {
Min , Max int
}
// NewLimits creates new Limits config with given min and max values.
func NewLimits ( min , max int ) Limits {
return Limits {
Min : min ,
Max : max ,
}
}
2018-04-10 06:44:09 +00:00
2024-07-31 06:21:11 +00:00
type ProviderConfig struct {
// Enabled flag specifies whether feature is enabled
Enabled bool ` validate:"required" `
// To identify provider
Name string ` validate:"required" `
// URL sets the rpc upstream host address for communication with
// a non-local infura endpoint.
User string ` json:",omitempty" `
Password string ` json:",omitempty" `
APIKey string ` json:"APIKey,omitempty" `
APIKeySecret string ` json:"APIKeySecret,omitempty" `
}
2018-03-19 16:22:09 +00:00
// ----------
// NodeConfig
// ----------
2017-08-15 10:27:12 +00:00
2017-03-15 21:03:01 +00:00
// NodeConfig stores configuration options for a node
type NodeConfig struct {
2017-05-03 14:24:48 +00:00
// NetworkID sets network to use for selecting peers to connect to
2017-08-10 15:31:29 +00:00
NetworkID uint64 ` json:"NetworkId" validate:"required" `
2017-03-15 21:03:01 +00:00
2023-03-23 11:44:15 +00:00
RootDataDir string ` json:",omitempty" `
2022-05-09 13:07:57 +00:00
2017-03-15 21:03:01 +00:00
// DataDir is the file system folder the node should use for any data storage needs.
2017-08-10 15:31:29 +00:00
DataDir string ` validate:"required" `
2017-03-15 21:03:01 +00:00
2017-04-28 08:49:15 +00:00
// KeyStoreDir is the file system folder that contains private keys.
2018-09-13 16:31:29 +00:00
KeyStoreDir string ` validate:"required" `
2017-04-28 08:49:15 +00:00
2023-09-12 12:45:32 +00:00
// KeycardPairingDataFile is the file where we keep keycard pairings data.
2024-06-26 11:14:27 +00:00
// It's specified by clients (and not in status-go) when creating a new account,
// because this file is initialized by status-keycard-go and we need to use it before initializing the node.
// I guess proper way would be to ask status-go for the file path, or just duplicate the file path in both backend and client.
2023-09-16 01:20:23 +00:00
// note: this field won't be saved into db, it's local to the device.
2024-05-17 13:54:35 +00:00
KeycardPairingDataFile string
2023-09-12 12:45:32 +00:00
2018-09-13 16:31:29 +00:00
// NodeKey is the hex-encoded node ID (private key). Should be a valid secp256k1 private key that will be used for both
2017-04-09 22:16:05 +00:00
// remote peer identification as well as network traffic encryption.
2018-09-13 16:31:29 +00:00
NodeKey string
2017-04-09 22:16:05 +00:00
2018-05-10 11:45:51 +00:00
// NoDiscovery set to true will disable discovery protocol.
2024-05-22 13:49:41 +00:00
// Deprecated: won't be used at all in wakuv2
2018-05-10 11:45:51 +00:00
NoDiscovery bool
2018-01-23 05:16:13 +00:00
2017-12-04 16:11:14 +00:00
// ListenAddr is an IP address and port of this node (e.g. 127.0.0.1:30303).
ListenAddr string
2018-08-17 06:25:55 +00:00
// AdvertiseAddr is a public IP address the node wants to be found with.
// It is especially useful when using floating IPs attached to a server.
2021-09-06 13:46:35 +00:00
// This configuration value is used by rendezvous protocol, and it's optional
// If no value is specified, it will attempt to determine the node's external
// IP address. A value can be specified in case the returned address is incorrect
2018-08-17 06:25:55 +00:00
AdvertiseAddr string
2017-03-15 21:03:01 +00:00
// Name sets the instance name of the node. It must not contain the / character.
2017-08-10 15:31:29 +00:00
Name string ` validate:"excludes=/" `
2017-03-15 21:03:01 +00:00
// Version exposes program's version. It is used in the devp2p node identifier.
Version string
// APIModules is a comma-separated list of API modules exposed via *any* (HTTP/WS/IPC) RPC interface.
2020-02-26 19:35:47 +00:00
APIModules string ` validate:"required" `
2017-03-15 21:03:01 +00:00
2018-09-21 14:09:31 +00:00
// HTTPEnabled specifies whether the http RPC server is to be enabled by default.
HTTPEnabled bool
2017-03-15 21:03:01 +00:00
// HTTPHost is the host interface on which to start the HTTP RPC server.
// Pass empty string if no HTTP RPC interface needs to be started.
HTTPHost string
// HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server.
HTTPPort int
2024-06-26 14:33:22 +00:00
// WSEnabled specifies whether the Websocket RPC server is to be enabled by default.
WSEnabled bool
// WSHost is the host interface on which to start Geth's Websocket RPC server.
WSHost string
// WSPort is the TCP port number on which to start the Geth's Websocket RPC server.
WSPort int
2018-10-12 12:58:32 +00:00
// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
// This is by default {'localhost'}. Using this prevents attacks like
// DNS rebinding, which bypasses SOP by simply masquerading as being within the same
// origin. These attacks do not utilize CORS, since they are not cross-domain.
// By explicitly checking the Host-header, the server will not allow requests
// made against the server with a malicious host domain.
// Requests using an IP address directly are not affected.
HTTPVirtualHosts [ ] string
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
// clients. Please be aware that CORS is a browser enforced security, it's fully
// useless for custom HTTP clients.
HTTPCors [ ] string
2017-03-15 21:03:01 +00:00
// IPCEnabled specifies whether IPC-RPC Server is enabled or not
IPCEnabled bool
2018-09-21 14:09:31 +00:00
// IPCFile is filename of exposed IPC RPC Server
IPCFile string
2017-03-15 21:03:01 +00:00
// TLSEnabled specifies whether TLS support should be enabled on node or not
// TLS support is only planned in go-ethereum, so we are using our own patch.
TLSEnabled bool
// MaxPeers is the maximum number of (global) peers that can be connected.
// Set to zero, if only static or trusted peers are allowed to connect.
MaxPeers int
// MaxPendingPeers is the maximum number of peers that can be pending in the
// handshake phase, counted separately for inbound and outbound connections.
MaxPendingPeers int
2018-04-26 16:28:42 +00:00
// LogEnabled enables the logger
LogEnabled bool ` json:"LogEnabled" `
2019-03-05 09:03:06 +00:00
// LogMobileSystem enables log redirection to android/ios system logger.
LogMobileSystem bool
2020-02-03 09:20:04 +00:00
// LogFile is a folder which contains LogFile
LogDir string
2017-03-18 19:00:40 +00:00
// LogFile is filename where exposed logs get written to
LogFile string
2024-02-02 21:08:48 +00:00
// RuntimeLoglevel defines minimum log level for this session only, not affecting the db-stored node configuration
RuntimeLogLevel string ` validate:"omitempty,eq=ERROR|eq=WARN|eq=INFO|eq=DEBUG|eq=TRACE" `
2018-01-03 14:11:21 +00:00
// LogLevel defines minimum log level. Valid names are "ERROR", "WARN", "INFO", "DEBUG", and "TRACE".
LogLevel string ` validate:"eq=ERROR|eq=WARN|eq=INFO|eq=DEBUG|eq=TRACE" `
2017-03-18 19:00:40 +00:00
2019-03-01 13:37:13 +00:00
// LogMaxBackups defines number of rotated log files that will be stored.
LogMaxBackups int
2019-04-24 10:24:21 +00:00
// LogMaxSize in megabytes after current size is reached log file will be rotated.
2019-03-01 13:37:13 +00:00
LogMaxSize int
// LogCompressRotated if true all rotated files will be gzipped.
LogCompressRotated bool
2017-05-02 14:30:11 +00:00
// LogToStderr defines whether logged info should also be output to os.Stderr
LogToStderr bool
2017-03-15 21:03:01 +00:00
2019-01-17 12:56:22 +00:00
// EnableStatusService should be true to enable methods under status namespace.
EnableStatusService bool
2021-09-09 14:28:54 +00:00
// Initial networks to load
2022-01-12 20:04:43 +00:00
Networks [ ] Network
2021-09-09 14:28:54 +00:00
2018-03-20 14:05:21 +00:00
// ClusterConfig extra configuration for supporting cluster peers.
2018-09-13 16:31:29 +00:00
ClusterConfig ClusterConfig ` json:"ClusterConfig," validate:"structonly" `
2017-05-11 13:20:27 +00:00
2021-06-30 11:40:54 +00:00
// LightEthConfig extra configuration for LES
LightEthConfig LightEthConfig ` json:"LightEthConfig," validate:"structonly" `
2020-01-08 11:12:23 +00:00
// WakuConfig provides a configuration for Waku subprotocol.
WakuConfig WakuConfig ` json:"WakuConfig" validate:"structonly" `
2021-06-16 20:19:45 +00:00
// WakuV2Config provides a configuration for WakuV2 protocol.
WakuV2Config WakuV2Config ` json:"WakuV2Config" validate:"structonly" `
2020-02-18 11:21:01 +00:00
// BridgeConfig provides a configuration for Whisper-Waku bridge.
BridgeConfig BridgeConfig ` json:"BridgeConfig" validate:"structonly" `
2019-06-14 10:16:30 +00:00
// ShhextConfig extra configuration for service running under shhext namespace.
2019-01-22 07:08:29 +00:00
ShhextConfig ShhextConfig ` json:"ShhextConfig," validate:"structonly" `
2019-01-17 12:56:22 +00:00
2019-06-14 10:16:30 +00:00
// WalletConfig extra configuration for wallet.Service.
WalletConfig WalletConfig
2020-10-28 07:56:14 +00:00
// WalleLocalNotificationsConfig extra configuration for localnotifications.Service.
LocalNotificationsConfig LocalNotificationsConfig
2019-07-17 05:28:37 +00:00
// BrowsersConfig extra configuration for browsers.Service.
BrowsersConfig BrowsersConfig
2019-07-21 05:41:30 +00:00
// PermissionsConfig extra configuration for permissions.Service.
PermissionsConfig PermissionsConfig
2019-09-04 06:25:33 +00:00
// MailserversConfig extra configuration for mailservers.Service
// (persistent storage of user's mailserver records).
MailserversConfig MailserversConfig
2021-12-21 15:44:37 +00:00
// Web3ProviderConfig extra configuration for provider.Service
// (desktop provider API)
Web3ProviderConfig Web3ProviderConfig
2024-06-24 14:29:40 +00:00
// ConnectorConfig extra configuration for connector.Service
ConnectorConfig ConnectorConfig
2017-03-15 21:03:01 +00:00
// SwarmConfig extra configuration for Swarm and ENS
2018-09-13 16:31:29 +00:00
SwarmConfig SwarmConfig ` json:"SwarmConfig," validate:"structonly" `
2018-04-10 06:44:09 +00:00
2022-03-08 13:17:26 +00:00
TorrentConfig TorrentConfig
2018-07-16 07:40:40 +00:00
// RegisterTopics a list of specific topics where the peer wants to be
// discoverable.
RegisterTopics [ ] discv5 . Topic ` json:"RegisterTopics" `
// RequiredTopics list of topics where a client wants to search for
// discoverable peers with the discovery limits.
RequireTopics map [ discv5 . Topic ] Limits ` json:"RequireTopics" `
2018-05-03 10:36:56 +00:00
2018-08-20 13:55:43 +00:00
// MailServerRegistryAddress is the MailServerRegistry contract address
MailServerRegistryAddress string
2020-08-20 07:26:00 +00:00
// PushNotificationServerConfig is the config for the push notification server
2023-10-02 09:28:42 +00:00
PushNotificationServerConfig PushNotificationServerConfig ` json:"PushNotificationServerConfig" `
2022-08-24 12:06:48 +00:00
OutputMessageCSVEnabled bool
2023-07-20 10:08:57 +00:00
// ProcessBackedupMessages should be set to true when user follows recovery (using seed phrase or keycard) onboarding flow
ProcessBackedupMessages bool
2019-01-17 12:56:22 +00:00
}
2018-12-06 09:30:57 +00:00
2022-09-13 09:30:52 +00:00
type TokenOverride struct {
Symbol string ` json:"symbol" `
Address common . Address ` json:"address" `
}
2022-01-12 20:04:43 +00:00
type Network struct {
2022-09-13 09:30:52 +00:00
ChainID uint64 ` json:"chainId" `
ChainName string ` json:"chainName" `
2024-10-02 08:20:03 +00:00
DefaultRPCURL string ` json:"defaultRpcUrl" ` // proxy rpc url
DefaultFallbackURL string ` json:"defaultFallbackURL" ` // proxy fallback url
DefaultFallbackURL2 string ` json:"defaultFallbackURL2" ` // second proxy fallback url
2022-09-13 09:30:52 +00:00
RPCURL string ` json:"rpcUrl" `
2023-08-08 09:05:17 +00:00
OriginalRPCURL string ` json:"originalRpcUrl" `
2023-02-20 09:32:45 +00:00
FallbackURL string ` json:"fallbackURL" `
2023-08-08 09:05:17 +00:00
OriginalFallbackURL string ` json:"originalFallbackURL" `
2022-09-13 09:30:52 +00:00
BlockExplorerURL string ` json:"blockExplorerUrl,omitempty" `
IconURL string ` json:"iconUrl,omitempty" `
NativeCurrencyName string ` json:"nativeCurrencyName,omitempty" `
NativeCurrencySymbol string ` json:"nativeCurrencySymbol,omitempty" `
NativeCurrencyDecimals uint64 ` json:"nativeCurrencyDecimals" `
IsTest bool ` json:"isTest" `
Layer uint64 ` json:"layer" `
Enabled bool ` json:"enabled" `
ChainColor string ` json:"chainColor" `
ShortName string ` json:"shortName" `
TokenOverrides [ ] TokenOverride ` json:"tokenOverrides" `
2023-07-13 14:03:49 +00:00
RelatedChainID uint64 ` json:"relatedChainId" `
2022-01-12 20:04:43 +00:00
}
2019-06-14 10:16:30 +00:00
// WalletConfig extra configuration for wallet.Service.
type WalletConfig struct {
2024-07-31 06:21:11 +00:00
Enabled bool
OpenseaAPIKey string ` json:"OpenseaAPIKey" `
RaribleMainnetAPIKey string ` json:"RaribleMainnetAPIKey" `
RaribleTestnetAPIKey string ` json:"RaribleTestnetAPIKey" `
AlchemyAPIKeys map [ uint64 ] string ` json:"AlchemyAPIKeys" `
InfuraAPIKey string ` json:"InfuraAPIKey" `
InfuraAPIKeySecret string ` json:"InfuraAPIKeySecret" `
StatusProxyMarketUser string ` json:"StatusProxyMarketUser" `
StatusProxyMarketPassword string ` json:"StatusProxyMarketPassword" `
StatusProxyBlockchainUser string ` json:"StatusProxyBlockchainUser" `
StatusProxyBlockchainPassword string ` json:"StatusProxyBlockchainPassword" `
StatusProxyEnabled bool ` json:"StatusProxyEnabled" `
2024-08-14 15:35:48 +00:00
StatusProxyStageName string ` json:"StatusProxyStageName" `
2024-07-31 06:21:11 +00:00
EnableCelerBridge bool ` json:"EnableCelerBridge" `
2019-06-14 10:16:30 +00:00
}
2024-08-08 08:35:11 +00:00
// MarshalJSON custom marshalling to avoid exposing sensitive data in log,
// there's a function called `startNode` will log NodeConfig which include WalletConfig
func ( wc WalletConfig ) MarshalJSON ( ) ( [ ] byte , error ) {
return json . Marshal ( struct {
Enabled bool ` json:"Enabled" `
StatusProxyEnabled bool ` json:"StatusProxyEnabled" `
EnableCelerBridge bool ` json:"EnableCelerBridge" `
} {
Enabled : wc . Enabled ,
StatusProxyEnabled : wc . StatusProxyEnabled ,
EnableCelerBridge : wc . EnableCelerBridge ,
} )
}
2020-10-28 07:56:14 +00:00
// LocalNotificationsConfig extra configuration for localnotifications.Service.
type LocalNotificationsConfig struct {
Enabled bool
}
2019-07-17 05:28:37 +00:00
// BrowsersConfig extra configuration for browsers.Service.
type BrowsersConfig struct {
Enabled bool
}
2019-07-21 05:41:30 +00:00
// PermissionsConfig extra configuration for permissions.Service.
type PermissionsConfig struct {
Enabled bool
}
2019-09-04 06:25:33 +00:00
// MailserversConfig extra configuration for mailservers.Service.
type MailserversConfig struct {
Enabled bool
}
2021-12-21 15:44:37 +00:00
// ProviderConfig extra configuration for provider.Service
type Web3ProviderConfig struct {
Enabled bool
}
2024-06-24 14:29:40 +00:00
// ConnectorConfig extra configuration for provider.Service
type ConnectorConfig struct {
Enabled bool
}
2020-02-18 11:21:01 +00:00
// BridgeConfig provides configuration for Whisper-Waku bridge.
type BridgeConfig struct {
Enabled bool
}
2022-04-25 11:27:40 +00:00
type PushNotificationServer struct {
* ecdsa . PublicKey
}
func ( p * PushNotificationServer ) MarshalText ( ) ( [ ] byte , error ) {
return [ ] byte ( hex . EncodeToString ( crypto . FromECDSAPub ( p . PublicKey ) ) ) , nil
}
func ( p * PushNotificationServer ) UnmarshalText ( data [ ] byte ) error {
2022-04-25 13:39:52 +00:00
pubKeyBytes , err := hex . DecodeString ( string ( data ) )
if err != nil {
return err
}
pk , err := crypto . UnmarshalPubkey ( pubKeyBytes )
2022-04-25 11:27:40 +00:00
if err != nil {
return err
}
p . PublicKey = pk
return nil
}
2023-10-02 09:28:42 +00:00
type PushNotificationServerConfig struct {
Enabled bool
Identity * ecdsa . PrivateKey
GorushURL string
}
2019-01-17 12:56:22 +00:00
// ShhextConfig defines options used by shhext service.
type ShhextConfig struct {
2019-01-22 07:08:29 +00:00
PFSEnabled bool
2019-01-17 12:56:22 +00:00
// InstallationId id of the current installation
2019-03-01 13:36:21 +00:00
InstallationID string
2018-12-06 09:30:57 +00:00
// MailServerConfirmations should be true if client wants to receive confirmatons only from a selected mail servers.
MailServerConfirmations bool
2019-01-17 12:56:22 +00:00
// EnableConnectionManager turns on management of the mail server connections if true.
EnableConnectionManager bool
// EnableLastUsedMonitor guarantees that last used mail server will be tracked and persisted into the storage.
EnableLastUsedMonitor bool
// ConnectionTarget will be used by connection manager. It will ensure that we connected with configured number of servers.
ConnectionTarget int
2019-01-15 09:21:33 +00:00
// RequestsDelay used to ensure that no similar requests are sent within short periods of time.
RequestsDelay time . Duration
2019-01-21 14:00:10 +00:00
// MaxServerFailures defines maximum allowed expired requests before server will be swapped to another one.
MaxServerFailures int
2019-03-01 13:36:21 +00:00
// MaxMessageDeliveryAttempts defines how many times we will try to deliver not-acknowledged envelopes.
MaxMessageDeliveryAttempts int
2019-04-30 06:46:12 +00:00
// WhisperCacheDir is a folder where whisper filters may persist messages before delivering them
// to a client.
WhisperCacheDir string
2019-07-26 07:17:29 +00:00
// DisableGenericDiscoveryTopic indicates whether we should be listening on the old discovery
DisableGenericDiscoveryTopic bool
// SendV1Messages indicates whether we should be sending v1-compatible only messages
SendV1Messages bool
// DatasyncEnabled indicates whether we should enable dataasync
DataSyncEnabled bool
2020-01-10 18:59:01 +00:00
// VerifyTransactionURL is the URL for verifying transactions.
// IMPORTANT: It should always be mainnet unless used for testing
2020-01-17 12:39:09 +00:00
VerifyTransactionURL string
// VerifyENSURL is the URL for verifying ens names.
// IMPORTANT: It should always be mainnet unless used for testing
VerifyENSURL string
2020-02-05 10:09:33 +00:00
// VerifyENSContractAddress is the address of the contract used to verify ENS
// No default is provided and if not set ENS resolution is disabled
VerifyENSContractAddress string
2020-01-10 18:59:01 +00:00
VerifyTransactionChainID int64
2020-08-20 09:05:39 +00:00
// DefaultPushNotificationsServers is the default-status run push notification servers
2022-04-25 11:27:40 +00:00
DefaultPushNotificationsServers [ ] * PushNotificationServer
2021-09-01 12:02:18 +00:00
// AnonMetricsSendID is the public key used by a metrics node to decrypt metrics protobufs
AnonMetricsSendID string
// AnonMetricsServerEnabled indicates whether or not the
AnonMetricsServerEnabled bool
// AnonMetricsServerPostgresURI is the uri used to connect to a postgres db
AnonMetricsServerPostgresURI string
2021-09-29 14:52:45 +00:00
// BandwidthStatsEnabled indicates if a signal is going to be emitted to indicate the upload and download rate
BandwidthStatsEnabled bool
2019-01-17 12:56:22 +00:00
}
2022-03-08 13:17:26 +00:00
// TorrentConfig provides configuration for the BitTorrent client used for message history archives.
type TorrentConfig struct {
// Enabled set to true enables Community History Archive protocol
Enabled bool
// Port number which the BitTorrent client will listen to for conntections
Port int
// DataDir is the file system folder Status should use for message archive torrent data.
DataDir string
// TorrentDir is the file system folder Status should use for storing torrent metadata files.
TorrentDir string
}
2019-01-17 12:56:22 +00:00
// Validate validates the ShhextConfig struct and returns an error if inconsistent values are found
func ( c * ShhextConfig ) Validate ( validate * validator . Validate ) error {
2019-01-22 07:08:29 +00:00
if err := validate . Struct ( c ) ; err != nil {
return err
}
return nil
2017-03-15 21:03:01 +00:00
}
2018-09-21 14:09:31 +00:00
// Option is an additional setting when creating a NodeConfig
// using NewNodeConfigWithDefaults.
type Option func ( * NodeConfig ) error
// WithFleet loads one of the preconfigured Status fleets.
func WithFleet ( fleet string ) Option {
return func ( c * NodeConfig ) error {
if fleet == FleetUndefined {
return nil
}
2018-10-27 13:20:17 +00:00
c . NoDiscovery = false
2018-10-04 10:40:26 +00:00
c . ClusterConfig . Enabled = true
2018-09-21 14:09:31 +00:00
return loadConfigFromAsset ( fmt . Sprintf ( "../config/cli/fleet-%s.json" , fleet ) , c )
}
}
// WithLES enabled LES protocol.
func WithLES ( ) Option {
return func ( c * NodeConfig ) error {
return loadConfigFromAsset ( "../config/cli/les-enabled.json" , c )
}
}
// WithMailserver enables MailServer.
func WithMailserver ( ) Option {
return func ( c * NodeConfig ) error {
return loadConfigFromAsset ( "../config/cli/mailserver-enabled.json" , c )
}
}
2024-03-22 10:55:09 +00:00
func WithDiscV5BootstrapNodes ( nodes [ ] string ) Option {
return func ( c * NodeConfig ) error {
c . ClusterConfig . DiscV5BootstrapNodes = nodes
return nil
}
}
func WithWakuNodes ( nodes [ ] string ) Option {
return func ( c * NodeConfig ) error {
c . ClusterConfig . WakuNodes = nodes
return nil
}
}
2018-09-19 18:29:42 +00:00
// NewNodeConfigWithDefaults creates new node configuration object
// with some defaults suitable for adhoc use.
2018-09-21 14:09:31 +00:00
func NewNodeConfigWithDefaults ( dataDir string , networkID uint64 , opts ... Option ) ( * NodeConfig , error ) {
c , err := NewNodeConfig ( dataDir , networkID )
2018-09-13 16:31:29 +00:00
if err != nil {
return nil , err
}
2018-10-27 13:20:17 +00:00
c . NoDiscovery = true
2018-09-21 14:09:31 +00:00
c . HTTPHost = ""
c . ListenAddr = ":30303"
c . LogEnabled = true
c . LogLevel = "INFO"
2019-03-01 13:37:13 +00:00
c . LogMaxSize = 100
c . LogCompressRotated = true
c . LogMaxBackups = 3
2018-09-21 14:09:31 +00:00
c . LogToStderr = true
2020-08-19 12:06:41 +00:00
c . WakuConfig . Enabled = true
2018-09-13 16:31:29 +00:00
2018-09-21 14:09:31 +00:00
for _ , opt := range opts {
if err := opt ( c ) ; err != nil {
return nil , err
2018-09-13 16:31:29 +00:00
}
}
2018-09-21 14:09:31 +00:00
c . updatePeerLimits ( )
2018-09-13 16:31:29 +00:00
2018-09-21 14:09:31 +00:00
if err := c . Validate ( ) ; err != nil {
return nil , err
}
2018-09-14 10:25:52 +00:00
2018-09-21 14:09:31 +00:00
return c , nil
2018-09-13 16:31:29 +00:00
}
2020-08-20 09:05:39 +00:00
func ( c * NodeConfig ) setDefaultPushNotificationsServers ( ) error {
2020-08-25 09:46:01 +00:00
if c . ClusterConfig . Fleet == FleetUndefined {
return nil
}
2020-08-20 09:05:39 +00:00
// If empty load defaults from the fleet
if len ( c . ClusterConfig . PushNotificationsServers ) == 0 {
2024-10-28 20:54:17 +00:00
logutils . ZapLogger ( ) . Debug ( "empty push notification servers, setting" , zap . String ( "fleet" , c . ClusterConfig . Fleet ) )
2020-08-20 09:05:39 +00:00
defaultConfig := & NodeConfig { }
err := loadConfigFromAsset ( fmt . Sprintf ( "../config/cli/fleet-%s.json" , c . ClusterConfig . Fleet ) , defaultConfig )
if err != nil {
return err
}
c . ClusterConfig . PushNotificationsServers = defaultConfig . ClusterConfig . PushNotificationsServers
}
// If empty set the default servers
if len ( c . ShhextConfig . DefaultPushNotificationsServers ) == 0 {
2024-10-28 20:54:17 +00:00
logutils . ZapLogger ( ) . Debug ( "setting default push notification servers" , zap . Strings ( "cluster servers" , c . ClusterConfig . PushNotificationsServers ) )
2020-08-20 09:05:39 +00:00
for _ , pk := range c . ClusterConfig . PushNotificationsServers {
2023-05-15 10:09:14 +00:00
keyBytes , err := hex . DecodeString ( "04" + pk )
2020-08-20 09:05:39 +00:00
if err != nil {
return err
}
key , err := crypto . UnmarshalPubkey ( keyBytes )
if err != nil {
return err
}
2022-04-25 11:27:40 +00:00
c . ShhextConfig . DefaultPushNotificationsServers = append ( c . ShhextConfig . DefaultPushNotificationsServers , & PushNotificationServer { PublicKey : key } )
2020-08-20 09:05:39 +00:00
}
}
return nil
}
// UpdateWithDefaults updates config with missing default values, as
// the config is only generated once and is thereafter pulled from the database.
// The way it is stored in the database makes this step necessary as it's stored as a blob and can't be easily migrated.
func ( c * NodeConfig ) UpdateWithDefaults ( ) error {
2020-02-26 19:35:47 +00:00
// Empty APIModules will fallback to services' APIs definition.
// If any API is defined as public, it will be exposed.
// We disallow empty APIModules to avoid confusion
// when some APIs suddenly become available for Dapps.
// More: https://github.com/status-im/status-go/issues/1870.
if c . APIModules == "" {
2020-02-28 16:19:32 +00:00
c . APIModules = "net,web3,eth"
2020-02-26 19:35:47 +00:00
}
2020-05-13 13:10:04 +00:00
2020-05-14 05:40:40 +00:00
// Override defaultMinPoW passed by the client
2020-05-13 13:10:04 +00:00
if c . WakuConfig . Enabled {
c . WakuConfig . MinimumPoW = WakuMinimumPoW
}
2024-06-06 14:08:17 +00:00
// Ensure TorrentConfig is valid
if c . TorrentConfig . Enabled {
if c . TorrentConfig . DataDir == "" {
c . TorrentConfig . DataDir = filepath . Join ( c . RootDataDir , ArchivesRelativePath )
}
if c . TorrentConfig . TorrentDir == "" {
c . TorrentConfig . TorrentDir = filepath . Join ( c . RootDataDir , TorrentTorrentsRelativePath )
}
}
2020-08-20 09:05:39 +00:00
return c . setDefaultPushNotificationsServers ( )
2020-02-26 19:35:47 +00:00
}
2018-09-19 18:29:42 +00:00
// NewNodeConfigWithDefaultsAndFiles creates new node configuration object
// with some defaults suitable for adhoc use and applies config files on top.
func NewNodeConfigWithDefaultsAndFiles (
2018-09-21 14:09:31 +00:00
dataDir string , networkID uint64 , opts [ ] Option , files [ ] string ,
2018-09-19 18:29:42 +00:00
) ( * NodeConfig , error ) {
2018-09-21 14:09:31 +00:00
c , err := NewNodeConfigWithDefaults ( dataDir , networkID , opts ... )
2018-09-19 18:29:42 +00:00
if err != nil {
return nil , err
}
for _ , file := range files {
if err := loadConfigConfigFromFile ( file , c ) ; err != nil {
return nil , err
}
}
c . updatePeerLimits ( )
2018-09-21 14:09:31 +00:00
if err := c . Validate ( ) ; err != nil {
return nil , err
}
2018-09-19 18:29:42 +00:00
return c , nil
}
2018-09-14 10:25:52 +00:00
// updatePeerLimits will set default peer limits expectations based on enabled services.
func ( c * NodeConfig ) updatePeerLimits ( ) {
2024-08-22 17:12:37 +00:00
if c . NoDiscovery {
2018-09-14 10:25:52 +00:00
return
}
2021-06-30 11:40:54 +00:00
if c . LightEthConfig . Enabled {
c . RequireTopics [ discv5 . Topic ( LesTopic ( int ( c . NetworkID ) ) ) ] = LesDiscoveryLimits
}
2018-09-14 10:25:52 +00:00
}
2019-01-04 11:44:01 +00:00
// NewNodeConfig creates new node configuration object with bare-minimum defaults.
// Important: the returned config is not validated.
2018-09-21 14:09:31 +00:00
func NewNodeConfig ( dataDir string , networkID uint64 ) ( * NodeConfig , error ) {
2023-09-12 12:45:32 +00:00
var keyStoreDir , keycardPairingDataFile , wakuDir , wakuV2Dir string
2018-09-21 14:09:31 +00:00
if dataDir != "" {
keyStoreDir = filepath . Join ( dataDir , "keystore" )
2023-09-12 12:45:32 +00:00
keycardPairingDataFile = filepath . Join ( dataDir , "keycard" , "pairings.json" )
2020-08-19 12:06:41 +00:00
wakuDir = filepath . Join ( dataDir , "waku" )
2021-06-16 20:19:45 +00:00
wakuV2Dir = filepath . Join ( dataDir , "wakuv2" )
2018-09-21 14:09:31 +00:00
}
config := & NodeConfig {
2023-09-12 12:45:32 +00:00
NetworkID : networkID ,
2024-06-05 13:03:34 +00:00
RootDataDir : dataDir ,
2023-09-12 12:45:32 +00:00
DataDir : dataDir ,
KeyStoreDir : keyStoreDir ,
KeycardPairingDataFile : keycardPairingDataFile ,
2024-11-06 17:36:49 +00:00
Version : version . Version ( ) ,
2023-09-12 12:45:32 +00:00
HTTPHost : "localhost" ,
HTTPPort : 8545 ,
HTTPVirtualHosts : [ ] string { "localhost" } ,
ListenAddr : ":0" ,
APIModules : "eth,net,web3,peer,wallet" ,
MaxPeers : 25 ,
MaxPendingPeers : 0 ,
IPCFile : "geth.ipc" ,
LogFile : "" ,
LogLevel : "ERROR" ,
NoDiscovery : true ,
2021-06-30 11:40:54 +00:00
LightEthConfig : LightEthConfig {
DatabaseCache : 16 ,
} ,
2020-08-19 12:06:41 +00:00
WakuConfig : WakuConfig {
DataDir : wakuDir ,
MinimumPoW : WakuMinimumPoW ,
TTL : WakuTTL ,
MaxMessageSize : wakucommon . DefaultMaxMessageSize ,
} ,
2021-06-16 20:19:45 +00:00
WakuV2Config : WakuV2Config {
Host : "0.0.0.0" ,
2023-02-23 11:19:23 +00:00
Port : 0 ,
2021-06-16 20:19:45 +00:00
DataDir : wakuV2Dir ,
MaxMessageSize : wakuv2common . DefaultMaxMessageSize ,
} ,
2024-06-05 13:03:34 +00:00
ShhextConfig : ShhextConfig { } ,
SwarmConfig : SwarmConfig { } ,
2022-03-08 13:17:26 +00:00
TorrentConfig : TorrentConfig {
Enabled : false ,
Port : 9025 ,
DataDir : dataDir + "/archivedata" ,
TorrentDir : dataDir + "/torrents" ,
} ,
2018-04-20 12:23:18 +00:00
RegisterTopics : [ ] discv5 . Topic { } ,
RequireTopics : map [ discv5 . Topic ] Limits { } ,
2017-03-15 21:03:01 +00:00
}
2018-09-21 14:09:31 +00:00
return config , nil
2017-03-15 21:03:01 +00:00
}
2018-09-13 16:31:29 +00:00
// NewConfigFromJSON parses incoming JSON and returned it as Config
func NewConfigFromJSON ( configJSON string ) ( * NodeConfig , error ) {
2018-09-21 14:09:31 +00:00
config , err := NewNodeConfig ( "" , 0 )
2017-08-10 15:31:29 +00:00
if err != nil {
return nil , err
}
2018-09-21 14:09:31 +00:00
if err := loadConfigFromJSON ( configJSON , config ) ; err != nil {
2017-08-10 15:31:29 +00:00
return nil , err
}
2018-09-21 14:09:31 +00:00
if err := config . Validate ( ) ; err != nil {
return nil , err
2018-09-13 16:31:29 +00:00
}
2018-09-21 14:09:31 +00:00
return config , nil
2018-09-13 16:31:29 +00:00
}
2021-03-25 15:15:22 +00:00
func LoadClusterConfigFromFleet ( fleet string ) ( * ClusterConfig , error ) {
nodeConfig := & NodeConfig { }
err := loadConfigFromAsset ( fmt . Sprintf ( "../config/cli/fleet-%s.json" , fleet ) , nodeConfig )
if err != nil {
return nil , err
}
return & nodeConfig . ClusterConfig , nil
}
2018-09-21 14:09:31 +00:00
func loadConfigFromJSON ( configJSON string , nodeConfig * NodeConfig ) error {
2017-03-15 21:03:01 +00:00
decoder := json . NewDecoder ( strings . NewReader ( configJSON ) )
// override default configuration with values by JSON input
2018-09-21 14:09:31 +00:00
return decoder . Decode ( & nodeConfig )
2018-09-13 16:31:29 +00:00
}
func loadConfigConfigFromFile ( path string , config * NodeConfig ) error {
jsonConfig , err := ioutil . ReadFile ( path )
if err != nil {
return err
2017-05-02 14:30:11 +00:00
}
2018-09-21 14:09:31 +00:00
return loadConfigFromJSON ( string ( jsonConfig ) , config )
2018-09-13 16:31:29 +00:00
}
2018-09-21 14:09:31 +00:00
func loadConfigFromAsset ( name string , config * NodeConfig ) error {
data , err := static . Asset ( name )
if err != nil {
return err
2018-09-13 16:31:29 +00:00
}
2018-09-21 14:09:31 +00:00
return loadConfigFromJSON ( string ( data ) , config )
2017-08-10 15:31:29 +00:00
}
// Validate checks if NodeConfig fields have valid values.
//
// It returns nil if there are no errors, otherwise one or more errors
// can be returned. Multiple errors are joined with a new line.
//
// A single error for a struct:
//
2022-11-04 13:56:45 +00:00
// type TestStruct struct {
// TestField string `validate:"required"`
// }
2017-08-10 15:31:29 +00:00
//
// has the following format:
//
2022-11-04 13:56:45 +00:00
// Key: 'TestStruct.TestField' Error:Field validation for 'TestField' failed on the 'required' tag
2017-08-10 15:31:29 +00:00
func ( c * NodeConfig ) Validate ( ) error {
validate := NewValidator ( )
if err := validate . Struct ( c ) ; err != nil {
return err
2017-03-15 21:03:01 +00:00
}
2018-09-13 16:31:29 +00:00
if c . NodeKey != "" {
if _ , err := crypto . HexToECDSA ( c . NodeKey ) ; err != nil {
return fmt . Errorf ( "NodeKey is invalid (%s): %v" , c . NodeKey , err )
2017-08-10 15:31:29 +00:00
}
2017-03-15 21:03:01 +00:00
}
2018-09-13 16:31:29 +00:00
if err := c . validateChildStructs ( validate ) ; err != nil {
return err
2017-08-10 15:31:29 +00:00
}
2021-06-16 20:19:45 +00:00
if c . WakuConfig . Enabled && c . WakuV2Config . Enabled && c . WakuConfig . DataDir == c . WakuV2Config . DataDir {
return fmt . Errorf ( "both Waku and WakuV2 are enabled and use the same data dir" )
}
2020-08-19 12:06:41 +00:00
// Waku's data directory must be relative to the main data directory
// if EnableMailServer is true.
if c . WakuConfig . Enabled && c . WakuConfig . EnableMailServer {
if ! strings . HasPrefix ( c . WakuConfig . DataDir , c . DataDir ) {
return fmt . Errorf ( "WakuConfig.DataDir must start with DataDir fragment" )
2019-01-04 11:44:01 +00:00
}
}
2018-09-13 16:31:29 +00:00
if ! c . NoDiscovery && len ( c . ClusterConfig . BootNodes ) == 0 {
// No point in running discovery if we don't have bootnodes.
// In case we do have bootnodes, NoDiscovery should be true.
return fmt . Errorf ( "NoDiscovery is false, but ClusterConfig.BootNodes is empty" )
}
2019-01-17 12:56:22 +00:00
if c . ShhextConfig . PFSEnabled && len ( c . ShhextConfig . InstallationID ) == 0 {
2018-09-24 18:07:34 +00:00
return fmt . Errorf ( "PFSEnabled is true, but InstallationID is empty" )
}
2017-08-10 15:31:29 +00:00
return nil
2017-03-15 21:03:01 +00:00
}
2018-09-13 16:31:29 +00:00
func ( c * NodeConfig ) validateChildStructs ( validate * validator . Validate ) error {
// Validate child structs
if err := c . ClusterConfig . Validate ( validate ) ; err != nil {
2017-03-15 21:03:01 +00:00
return err
}
2021-06-30 11:40:54 +00:00
if err := c . LightEthConfig . Validate ( validate ) ; err != nil {
return err
}
2018-09-13 16:31:29 +00:00
if err := c . SwarmConfig . Validate ( validate ) ; err != nil {
2017-03-15 21:03:01 +00:00
return err
}
2019-01-17 12:56:22 +00:00
if err := c . ShhextConfig . Validate ( validate ) ; err != nil {
return err
}
2022-03-08 13:17:26 +00:00
if err := c . TorrentConfig . Validate ( validate ) ; err != nil {
return err
}
2017-03-15 21:03:01 +00:00
return nil
}
2018-09-13 16:31:29 +00:00
// Validate validates the ClusterConfig struct and returns an error if inconsistent values are found
func ( c * ClusterConfig ) Validate ( validate * validator . Validate ) error {
if ! c . Enabled {
2017-05-16 03:24:56 +00:00
return nil
}
2018-09-13 16:31:29 +00:00
if err := validate . Struct ( c ) ; err != nil {
2017-05-16 03:24:56 +00:00
return err
}
2018-09-13 16:31:29 +00:00
return nil
2017-10-16 21:54:56 +00:00
}
2021-06-30 11:40:54 +00:00
// Validate validates the LightEthConfig struct and returns an error if inconsistent values are found
func ( c * LightEthConfig ) Validate ( validate * validator . Validate ) error {
if ! c . Enabled {
return nil
}
if err := validate . Struct ( c ) ; err != nil {
return err
}
return nil
}
2018-09-13 16:31:29 +00:00
// Validate validates the SwarmConfig struct and returns an error if inconsistent values are found
func ( c * SwarmConfig ) Validate ( validate * validator . Validate ) error {
if ! c . Enabled {
return nil
2017-05-16 03:24:56 +00:00
}
2018-09-13 16:31:29 +00:00
if err := validate . Struct ( c ) ; err != nil {
return err
2017-05-16 03:24:56 +00:00
}
return nil
}
2022-03-08 13:17:26 +00:00
func ( c * TorrentConfig ) Validate ( validate * validator . Validate ) error {
if ! c . Enabled {
return nil
}
if err := validate . Struct ( c ) ; err != nil {
return err
}
2024-06-06 14:08:17 +00:00
if c . Enabled && ( c . DataDir == "" || c . TorrentDir == "" ) {
2022-03-08 13:17:26 +00:00
return fmt . Errorf ( "TorrentConfig.DataDir and TorrentConfig.TorrentDir cannot be \"\"" )
}
return nil
}
2018-09-13 16:31:29 +00:00
// Save dumps configuration to the disk
func ( c * NodeConfig ) Save ( ) error {
data , err := json . MarshalIndent ( c , "" , " " )
if err != nil {
return err
2018-04-20 12:23:18 +00:00
}
2018-09-13 16:31:29 +00:00
if err := os . MkdirAll ( c . DataDir , os . ModePerm ) ; err != nil {
return err
2018-04-20 12:23:18 +00:00
}
2018-09-13 16:31:29 +00:00
configFilePath := filepath . Join ( c . DataDir , "config.json" )
if err := ioutil . WriteFile ( configFilePath , data , os . ModePerm ) ; err != nil {
return err
2018-08-24 11:20:50 +00:00
}
2018-09-13 16:31:29 +00:00
return nil
2018-04-20 12:23:18 +00:00
}
2017-03-15 21:03:01 +00:00
// String dumps config object as nicely indented JSON
func ( c * NodeConfig ) String ( ) string {
data , _ := json . MarshalIndent ( c , "" , " " )
return string ( data )
}
2018-04-12 16:17:10 +00:00
// FormatAPIModules returns a slice of APIModules.
func ( c * NodeConfig ) FormatAPIModules ( ) [ ] string {
if len ( c . APIModules ) == 0 {
return nil
}
return strings . Split ( c . APIModules , "," )
}
2018-05-08 21:57:29 +00:00
// AddAPIModule adds a mobule to APIModules
func ( c * NodeConfig ) AddAPIModule ( m string ) {
c . APIModules = fmt . Sprintf ( "%s,%s" , c . APIModules , m )
}
2021-06-30 11:40:54 +00:00
// LesTopic returns discovery v5 topic derived from genesis of the provided network.
2024-10-15 07:29:21 +00:00
// 1 - mainnet
2021-06-30 11:40:54 +00:00
func LesTopic ( netid int ) string {
switch netid {
case 1 :
return LESDiscoveryIdentifier + types . Bytes2Hex ( params . MainnetGenesisHash . Bytes ( ) [ : 8 ] )
default :
return ""
}
}