2022-10-14 08:50:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-05-17 14:29:58 +00:00
|
|
|
"context"
|
2022-10-14 08:50:36 +00:00
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
stdlog "log"
|
|
|
|
"os"
|
2024-05-17 14:29:58 +00:00
|
|
|
"os/signal"
|
2022-10-14 08:50:36 +00:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2024-05-17 14:29:58 +00:00
|
|
|
gethmetrics "github.com/ethereum/go-ethereum/metrics"
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/account/generator"
|
|
|
|
"github.com/status-im/status-go/api"
|
2023-10-02 09:28:42 +00:00
|
|
|
"github.com/status-im/status-go/common/dbsetup"
|
2022-10-14 08:50:36 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/logutils"
|
2024-05-17 14:29:58 +00:00
|
|
|
"github.com/status-im/status-go/metrics"
|
|
|
|
nodemetrics "github.com/status-im/status-go/metrics/node"
|
2022-10-14 08:50:36 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2024-05-17 14:29:58 +00:00
|
|
|
"github.com/status-im/status-go/node"
|
2022-10-14 08:50:36 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2023-05-05 14:00:54 +00:00
|
|
|
"github.com/status-im/status-go/profiling"
|
2022-10-14 08:50:36 +00:00
|
|
|
"github.com/status-im/status-go/protocol"
|
|
|
|
"github.com/status-im/status-go/protocol/identity/alias"
|
|
|
|
waku2extn "github.com/status-im/status-go/services/wakuv2ext"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
serverClientName = "Statusd"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
configFiles configFlags
|
|
|
|
logLevel = flag.String("log", "INFO", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`)
|
|
|
|
logWithoutColors = flag.Bool("log-without-color", false, "Disables log colors")
|
|
|
|
seedPhrase = flag.String("seed-phrase", "", "Seed phrase")
|
|
|
|
version = flag.Bool("version", false, "Print version and dump configuration")
|
2023-04-26 16:22:09 +00:00
|
|
|
apiModules = flag.String("api-modules", "wakuext,ext,waku,ens", "API modules to enable in the HTTP server")
|
2023-05-05 14:00:54 +00:00
|
|
|
pprofEnabled = flag.Bool("pprof", false, "Enable runtime profiling via pprof")
|
|
|
|
pprofPort = flag.Int("pprof-port", 52525, "Port for runtime profiling via pprof")
|
2024-05-17 14:29:58 +00:00
|
|
|
metricsEnabled = flag.Bool("metrics", false, "Expose ethereum metrics with debug_metrics jsonrpc call")
|
|
|
|
metricsPort = flag.Int("metrics-port", 9305, "Port for the Prometheus /metrics endpoint")
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
dataDir = flag.String("dir", getDefaultDataDir(), "Directory used by node to store data")
|
|
|
|
networkID = flag.Int(
|
|
|
|
"network-id",
|
2024-10-15 07:29:21 +00:00
|
|
|
params.SepoliaNetworkID,
|
2022-10-14 08:50:36 +00:00
|
|
|
fmt.Sprintf(
|
2024-10-15 07:29:21 +00:00
|
|
|
"A network ID: %d (Mainnet), %d (Sepolia)",
|
|
|
|
params.MainNetworkID, params.SepoliaNetworkID,
|
2022-10-14 08:50:36 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
listenAddr = flag.String("addr", "", "address to bind listener to")
|
|
|
|
)
|
|
|
|
|
|
|
|
// All general log messages in this package should be routed through this logger.
|
|
|
|
var logger = log.New("package", "status-go/cmd/statusd")
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.Var(&configFiles, "c", "JSON configuration file(s). Multiple configuration files can be specified, and will be merged in occurrence order")
|
|
|
|
}
|
|
|
|
|
|
|
|
// nolint:gocyclo
|
|
|
|
func main() {
|
|
|
|
colors := terminal.IsTerminal(int(os.Stdin.Fd()))
|
|
|
|
if err := logutils.OverrideRootLog(true, "ERROR", logutils.FileOptions{}, colors); err != nil {
|
|
|
|
stdlog.Fatalf("Error initializing logger: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
flag.Usage = printUsage
|
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() > 0 {
|
|
|
|
printUsage()
|
|
|
|
logger.Error("Extra args in command line: %v", flag.Args())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
opts := []params.Option{}
|
|
|
|
|
|
|
|
config, err := params.NewNodeConfigWithDefaultsAndFiles(
|
|
|
|
*dataDir,
|
|
|
|
uint64(*networkID),
|
|
|
|
opts,
|
|
|
|
configFiles,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
printUsage()
|
|
|
|
logger.Error(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use listenAddr if and only if explicitly provided in the arguments.
|
|
|
|
// The default value is set in params.NewNodeConfigWithDefaultsAndFiles().
|
|
|
|
if *listenAddr != "" {
|
|
|
|
config.ListenAddr = *listenAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
if *logLevel != "" {
|
|
|
|
config.LogLevel = *logLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up logging options
|
|
|
|
setupLogging(config)
|
|
|
|
|
|
|
|
// We want statusd to be distinct from StatusIM client.
|
|
|
|
config.Name = serverClientName
|
|
|
|
|
|
|
|
if *version {
|
|
|
|
printVersion(config)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:00:54 +00:00
|
|
|
// Check if profiling shall be enabled.
|
|
|
|
if *pprofEnabled {
|
|
|
|
profiling.NewProfiler(*pprofPort).Go()
|
|
|
|
}
|
|
|
|
|
test_: Code Migration from status-cli-tests
author shashankshampi <shashank.sanket1995@gmail.com> 1729780155 +0530
committer shashankshampi <shashank.sanket1995@gmail.com> 1730274350 +0530
test: Code Migration from status-cli-tests
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
fix(ci)_: remove workspace and tmp dir
This ensures we do not encounter weird errors like:
```
+ ln -s /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907 /home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go
ln: failed to create symbolic link '/home/jenkins/workspace/go_prs_linux_x86_64_main_PR-5907@tmp/go/src/github.com/status-im/status-go': File exists
script returned exit code 1
```
Signed-off-by: Jakub Sokołowski <jakub@status.im>
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
cleanup
added logger and cleanup
review comments changes
fix_: functional tests (#5979)
* fix_: generate on test-functional
* chore(test)_: fix functional test assertion
---------
Co-authored-by: Siddarth Kumar <siddarthkay@gmail.com>
feat(accounts)_: cherry-pick Persist acceptance of Terms of Use & Privacy policy (#5766) (#5977)
* feat(accounts)_: Persist acceptance of Terms of Use & Privacy policy (#5766)
The original GH issue https://github.com/status-im/status-mobile/issues/21113
came from a request from the Legal team. We must show to Status v1 users the new
terms (Terms of Use & Privacy Policy) right after they upgrade to Status v2
from the stores.
The solution we use is to create a flag in the accounts table, named
hasAcceptedTerms. The flag will be set to true on the first account ever
created in v2 and we provide a native call in mobile/status.go#AcceptTerms,
which allows the client to persist the user's choice in case they are upgrading
(from v1 -> v2, or from a v2 older than this PR).
This solution is not the best because we should store the setting in a separate
table, not in the accounts table.
Related Mobile PR https://github.com/status-im/status-mobile/pull/21124
* fix(test)_: Compare addresses using uppercased strings
---------
Co-authored-by: Icaro Motta <icaro.ldm@gmail.com>
test_: restore account (#5960)
feat_: `LogOnPanic` linter (#5969)
* feat_: LogOnPanic linter
* fix_: add missing defer LogOnPanic
* chore_: make vendor
* fix_: tests, address pr comments
* fix_: address pr comments
chore_: enable windows and macos CI build (#5840)
- Added support for Windows and macOS in CI pipelines
- Added missing dependencies for Windows and x86-64-darwin
- Resolved macOS SDK version compatibility for darwin-x86_64
The `mkShell` override was necessary to ensure compatibility with the newer
macOS SDK (version 11.0) for x86_64. The default SDK (10.12) was causing build failures
because of the missing libs and frameworks. OverrideSDK creates a mapping from
the default SDK in all package categories to the requested SDK (11.0).
fix(contacts)_: fix trust status not being saved to cache when changed (#5965)
Fixes https://github.com/status-im/status-desktop/issues/16392
test_: remove port bind
chore(wallet)_: move route execution code to separate module
chore_: replace geth logger with zap logger (#5962)
closes: #6002
feat(telemetry)_: add metrics for message reliability (#5899)
* feat(telemetry)_: track message reliability
Add metrics for dial errors, missed messages,
missed relevant messages, and confirmed delivery.
* fix_: handle error from json marshal
chore_: use zap logger as request logger
iterates: status-im/status-desktop#16536
test_: unique project per run
test_: use docker compose v2, more concrete project name
fix(codecov)_: ignore folders without tests
Otherwise Codecov reports incorrect numbers when making changes.
https://docs.codecov.com/docs/ignoring-paths
Signed-off-by: Jakub Sokołowski <jakub@status.im>
test_: verify schema of signals during init; fix schema verification warnings (#5947)
fix_: update defaultGorushURL (#6011)
fix(tests)_: use non-standard port to avoid conflicts
We have observed `nimbus-eth2` build failures reporting this port:
```json
{
"lvl": "NTC",
"ts": "2024-10-28 13:51:32.308+00:00",
"msg": "REST HTTP server could not be started",
"topics": "beacnde",
"address": "127.0.0.1:5432",
"reason": "(98) Address already in use"
}
```
https://ci.status.im/job/nimbus-eth2/job/platforms/job/linux/job/x86_64/job/main/job/PR-6683/3/
Signed-off-by: Jakub Sokołowski <jakub@status.im>
fix_: create request logger ad-hoc in tests
Fixes `TestCall` failing when run concurrently.
chore_: configure codecov (#6005)
* chore_: configure codecov
* fix_: after_n_builds
2024-10-24 14:29:15 +00:00
|
|
|
backend := api.NewGethStatusBackend(logutils.ZapLogger())
|
2022-10-14 08:50:36 +00:00
|
|
|
err = ImportAccount(*seedPhrase, backend)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("failed import account", "err", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-17 14:29:58 +00:00
|
|
|
// handle interrupt signals
|
|
|
|
interruptCh := exitOnInterruptSignal(backend.StatusNode())
|
|
|
|
|
|
|
|
// Start collecting metrics. Metrics can be enabled by providing `-metrics` flag
|
|
|
|
// or setting `gethmetrics.Enabled` to true during compilation time:
|
|
|
|
// https://github.com/status-im/go-ethereum/pull/76.
|
|
|
|
if *metricsEnabled || gethmetrics.Enabled {
|
|
|
|
go startNodeMetrics(interruptCh, backend.StatusNode())
|
|
|
|
go gethmetrics.CollectProcessMetrics(3 * time.Second)
|
|
|
|
go metrics.NewMetricsServer(*metricsPort, gethmetrics.DefaultRegistry).Listen()
|
|
|
|
}
|
|
|
|
|
2022-10-14 08:50:36 +00:00
|
|
|
wakuextservice := backend.StatusNode().WakuV2ExtService()
|
|
|
|
if wakuextservice == nil {
|
|
|
|
logger.Error("wakuext not available")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
wakuext := waku2extn.NewPublicAPI(wakuextservice)
|
|
|
|
|
2024-05-24 11:45:58 +00:00
|
|
|
messenger := wakuext.Messenger()
|
|
|
|
messenger.DisableStoreNodes()
|
2022-10-14 08:50:36 +00:00
|
|
|
// This will start the push notification server as well as
|
|
|
|
// the config is set to Enabled
|
|
|
|
_, err = wakuext.StartMessenger()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("failed to start messenger", "error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-24 11:45:58 +00:00
|
|
|
retrieveMessagesLoop(messenger, 300*time.Millisecond)
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func getDefaultDataDir() string {
|
|
|
|
if home := os.Getenv("HOME"); home != "" {
|
|
|
|
return filepath.Join(home, ".statusd")
|
|
|
|
}
|
|
|
|
return "./statusd-data"
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupLogging(config *params.NodeConfig) {
|
|
|
|
logSettings := logutils.LogSettings{
|
|
|
|
Enabled: config.LogEnabled,
|
|
|
|
MobileSystem: config.LogMobileSystem,
|
|
|
|
Level: config.LogLevel,
|
|
|
|
File: config.LogFile,
|
|
|
|
MaxSize: config.LogMaxSize,
|
|
|
|
MaxBackups: config.LogMaxBackups,
|
|
|
|
CompressRotated: config.LogCompressRotated,
|
|
|
|
}
|
|
|
|
colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd()))
|
|
|
|
if err := logutils.OverrideRootLogWithConfig(logSettings, colors); err != nil {
|
|
|
|
stdlog.Fatalf("Error initializing logger: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// printVersion prints verbose output about version and config.
|
|
|
|
func printVersion(config *params.NodeConfig) {
|
|
|
|
fmt.Println(strings.Title(config.Name))
|
|
|
|
fmt.Println("Version:", config.Version)
|
|
|
|
fmt.Println("Network ID:", config.NetworkID)
|
|
|
|
fmt.Println("Go Version:", runtime.Version())
|
|
|
|
fmt.Println("OS:", runtime.GOOS)
|
|
|
|
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
|
|
|
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
|
|
|
|
|
|
|
|
fmt.Println("Loaded Config: ", config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printUsage() {
|
|
|
|
usage := `
|
|
|
|
Usage: statusd [options]
|
|
|
|
Examples:
|
|
|
|
statusd # run regular Whisper node that joins Status network
|
|
|
|
statusd -c ./default.json # run node with configuration specified in ./default.json file
|
|
|
|
statusd -c ./default.json -c ./standalone.json # run node with configuration specified in ./default.json file, after merging ./standalone.json file
|
|
|
|
statusd -c ./default.json -metrics # run node with configuration specified in ./default.json file, and expose ethereum metrics with debug_metrics jsonrpc call
|
|
|
|
|
|
|
|
Options:
|
|
|
|
`
|
|
|
|
fmt.Fprint(os.Stderr, usage)
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathWalletRoot = "m/44'/60'/0'/0"
|
|
|
|
const pathEIP1581 = "m/43'/60'/1581'"
|
|
|
|
const pathDefaultChat = pathEIP1581 + "/0'/0"
|
|
|
|
const pathDefaultWallet = pathWalletRoot + "/0"
|
|
|
|
|
|
|
|
var paths = []string{pathWalletRoot, pathEIP1581, pathDefaultChat, pathDefaultWallet}
|
|
|
|
|
|
|
|
func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derivedAddresses map[string]generator.AccountInfo, mnemonic *string) (*settings.Settings, error) {
|
|
|
|
chatKeyString := derivedAddresses[pathDefaultChat].PublicKey
|
|
|
|
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings := &settings.Settings{}
|
|
|
|
defaultSettings.KeyUID = generatedAccountInfo.KeyUID
|
|
|
|
defaultSettings.Address = types.HexToAddress(generatedAccountInfo.Address)
|
|
|
|
defaultSettings.WalletRootAddress = types.HexToAddress(derivedAddresses[pathWalletRoot].Address)
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
// Set chat key & name
|
|
|
|
name, err := alias.GenerateFromPublicKeyString(chatKeyString)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.Name = name
|
|
|
|
defaultSettings.PublicKey = chatKeyString
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.DappsAddress = types.HexToAddress(derivedAddresses[pathDefaultWallet].Address)
|
|
|
|
defaultSettings.EIP1581Address = types.HexToAddress(derivedAddresses[pathEIP1581].Address)
|
|
|
|
defaultSettings.Mnemonic = mnemonic
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
signingPhrase, err := buildSigningPhrase()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.SigningPhrase = signingPhrase
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.SendPushNotifications = true
|
|
|
|
defaultSettings.InstallationID = uuid.New().String()
|
|
|
|
defaultSettings.UseMailservers = true
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.PreviewPrivacy = true
|
2024-03-05 10:44:09 +00:00
|
|
|
defaultSettings.PeerSyncingEnabled = false
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.Currency = "usd"
|
|
|
|
defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone
|
|
|
|
defaultSettings.LinkPreviewRequestEnabled = true
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2024-03-26 11:38:16 +00:00
|
|
|
defaultSettings.TestNetworksEnabled = false
|
|
|
|
|
2022-10-14 08:50:36 +00:00
|
|
|
visibleTokens := make(map[string][]string)
|
|
|
|
visibleTokens["mainnet"] = []string{"SNT"}
|
|
|
|
visibleTokensJSON, err := json.Marshal(visibleTokens)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
visibleTokenJSONRaw := json.RawMessage(visibleTokensJSON)
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.WalletVisibleTokens = &visibleTokenJSONRaw
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
// TODO: fix this
|
|
|
|
networks := make([]map[string]string, 0)
|
|
|
|
networksJSON, err := json.Marshal(networks)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
networkRawMessage := json.RawMessage(networksJSON)
|
2023-06-19 16:55:04 +00:00
|
|
|
defaultSettings.Networks = &networkRawMessage
|
|
|
|
defaultSettings.CurrentNetwork = "mainnet_rpc"
|
2022-10-14 08:50:36 +00:00
|
|
|
|
2023-06-19 16:55:04 +00:00
|
|
|
return defaultSettings, nil
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
|
|
|
|
// Set mainnet
|
|
|
|
nodeConfig := ¶ms.NodeConfig{}
|
|
|
|
nodeConfig.NetworkID = 1
|
|
|
|
nodeConfig.LogLevel = "DEBUG"
|
2024-04-22 12:33:23 +00:00
|
|
|
nodeConfig.DataDir = api.DefaultDataDir
|
2022-10-14 08:50:36 +00:00
|
|
|
nodeConfig.HTTPEnabled = true
|
|
|
|
nodeConfig.HTTPPort = 8545
|
|
|
|
// FIXME: This should be taken from CLI flags.
|
|
|
|
nodeConfig.HTTPHost = "0.0.0.0"
|
|
|
|
// FIXME: This should be taken from CLI flags.
|
|
|
|
nodeConfig.HTTPVirtualHosts = []string{"localhost", "wakunode"}
|
2023-04-26 16:22:09 +00:00
|
|
|
nodeConfig.APIModules = *apiModules
|
2024-05-17 14:13:00 +00:00
|
|
|
// Disable to avoid errors about empty ClusterConfig.BootNodes.
|
|
|
|
nodeConfig.NoDiscovery = true
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
nodeConfig.Name = "StatusIM"
|
2024-07-29 21:19:48 +00:00
|
|
|
clusterConfig, err := params.LoadClusterConfigFromFleet("status.prod")
|
2022-10-14 08:50:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
nodeConfig.ClusterConfig = *clusterConfig
|
|
|
|
|
|
|
|
nodeConfig.WalletConfig = params.WalletConfig{Enabled: true}
|
|
|
|
nodeConfig.LocalNotificationsConfig = params.LocalNotificationsConfig{Enabled: true}
|
|
|
|
nodeConfig.BrowsersConfig = params.BrowsersConfig{Enabled: true}
|
|
|
|
nodeConfig.PermissionsConfig = params.PermissionsConfig{Enabled: true}
|
|
|
|
nodeConfig.MailserversConfig = params.MailserversConfig{Enabled: true}
|
2023-09-27 17:26:10 +00:00
|
|
|
err = api.SetDefaultFleet(nodeConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-10-14 08:50:36 +00:00
|
|
|
|
|
|
|
nodeConfig.WakuV2Config = params.WakuV2Config{
|
|
|
|
Enabled: true,
|
|
|
|
EnableDiscV5: true,
|
|
|
|
DiscoveryLimit: 20,
|
|
|
|
UDPPort: 9002,
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeConfig.ShhextConfig = params.ShhextConfig{
|
|
|
|
InstallationID: installationID,
|
2024-04-26 14:11:49 +00:00
|
|
|
MaxMessageDeliveryAttempts: api.DefaultMaxMessageDeliveryAttempts,
|
2022-10-14 08:50:36 +00:00
|
|
|
MailServerConfirmations: true,
|
|
|
|
VerifyTransactionURL: "",
|
|
|
|
VerifyENSURL: "",
|
|
|
|
VerifyENSContractAddress: "",
|
2024-04-26 14:11:49 +00:00
|
|
|
VerifyTransactionChainID: api.DefaultVerifyTransactionChainID,
|
2022-10-14 08:50:36 +00:00
|
|
|
DataSyncEnabled: true,
|
|
|
|
PFSEnabled: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: check topics
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ImportAccount(seedPhrase string, backend *api.GethStatusBackend) error {
|
2023-05-29 15:51:23 +00:00
|
|
|
backend.UpdateRootDataDir(*dataDir)
|
2022-10-14 08:50:36 +00:00
|
|
|
manager := backend.AccountManager()
|
2023-05-29 15:51:23 +00:00
|
|
|
if err := manager.InitKeystore(*dataDir); err != nil {
|
2022-10-14 08:50:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
err := backend.OpenAccounts()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("failed open accounts", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
generator := manager.AccountsGenerator()
|
|
|
|
generatedAccountInfo, err := generator.ImportMnemonic(seedPhrase, "")
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("failed import mnemonic", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
derivedAddresses, err := generator.DeriveAddresses(generatedAccountInfo.ID, paths)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("failed derive", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var exist bool
|
|
|
|
_, err = generator.StoreDerivedAccounts(generatedAccountInfo.ID, "", paths)
|
|
|
|
if err != nil && err.Error() == "account already exists" {
|
|
|
|
exist = true
|
|
|
|
} else if err != nil {
|
|
|
|
logger.Error("failed store derive", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
account := multiaccounts.Account{
|
|
|
|
KeyUID: generatedAccountInfo.KeyUID,
|
2023-10-02 09:28:42 +00:00
|
|
|
KDFIterations: dbsetup.ReducedKDFIterationsNumber,
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|
|
|
|
settings, err := defaultSettings(generatedAccountInfo, derivedAddresses, &seedPhrase)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeConfig, err := defaultNodeConfig(settings.InstallationID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
walletDerivedAccount := derivedAddresses[pathDefaultWallet]
|
|
|
|
walletAccount := &accounts.Account{
|
|
|
|
PublicKey: types.Hex2Bytes(walletDerivedAccount.PublicKey),
|
|
|
|
KeyUID: generatedAccountInfo.KeyUID,
|
|
|
|
Address: types.HexToAddress(walletDerivedAccount.Address),
|
2023-06-02 15:06:51 +00:00
|
|
|
ColorID: "",
|
2022-10-14 08:50:36 +00:00
|
|
|
Wallet: true,
|
|
|
|
Path: pathDefaultWallet,
|
|
|
|
Name: "Ethereum account",
|
|
|
|
}
|
|
|
|
|
|
|
|
chatDerivedAccount := derivedAddresses[pathDefaultChat]
|
|
|
|
chatAccount := &accounts.Account{
|
|
|
|
PublicKey: types.Hex2Bytes(chatDerivedAccount.PublicKey),
|
|
|
|
KeyUID: generatedAccountInfo.KeyUID,
|
|
|
|
Address: types.HexToAddress(chatDerivedAccount.Address),
|
|
|
|
Name: settings.Name,
|
|
|
|
Chat: true,
|
|
|
|
Path: pathDefaultChat,
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(nodeConfig)
|
|
|
|
accounts := []*accounts.Account{walletAccount, chatAccount}
|
|
|
|
if !exist {
|
2024-06-26 11:14:27 +00:00
|
|
|
return backend.StartNodeWithAccountAndInitialConfig(account, "", *settings, nodeConfig, accounts, nil)
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|
2024-06-26 11:14:27 +00:00
|
|
|
return backend.StartNodeWithAccount(account, "", nodeConfig, nil)
|
2022-10-14 08:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func retrieveMessagesLoop(messenger *protocol.Messenger, tick time.Duration) {
|
|
|
|
ticker := time.NewTicker(tick)
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for { //nolint: gosimple
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
_, err := messenger.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("failed to retrieve raw messages", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-17 14:29:58 +00:00
|
|
|
|
|
|
|
// exitOnInterruptSignal catches interrupt signal (SIGINT) and
|
|
|
|
// stops the node. It times out after 5 seconds
|
|
|
|
// if the node can not be stopped.
|
|
|
|
func exitOnInterruptSignal(statusNode *node.StatusNode) <-chan struct{} {
|
|
|
|
interruptCh := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
sigChan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigChan, os.Interrupt)
|
|
|
|
defer signal.Stop(sigChan)
|
|
|
|
<-sigChan
|
|
|
|
close(interruptCh)
|
|
|
|
logger.Info("Got interrupt, shutting down...")
|
|
|
|
if err := statusNode.Stop(); err != nil {
|
|
|
|
logger.Error("Failed to stop node", "error", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return interruptCh
|
|
|
|
}
|
|
|
|
|
|
|
|
// startCollectingStats collects various stats about the node and other protocols like Whisper.
|
|
|
|
func startNodeMetrics(interruptCh <-chan struct{}, statusNode *node.StatusNode) {
|
|
|
|
logger.Info("Starting collecting node metrics")
|
|
|
|
|
|
|
|
gNode := statusNode.GethNode()
|
|
|
|
if gNode == nil {
|
|
|
|
logger.Error("Failed to run metrics because it could not get the node")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
go func() {
|
|
|
|
// Try to subscribe and collect metrics. In case of an error, retry.
|
|
|
|
for {
|
|
|
|
if err := nodemetrics.SubscribeServerEvents(ctx, gNode); err != nil {
|
|
|
|
logger.Error("Failed to subscribe server events", "error", err)
|
|
|
|
} else {
|
|
|
|
// no error means that the subscription was terminated by purpose
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
<-interruptCh
|
|
|
|
}
|