feat: extract node config from settings to individual tables (#2470)
This commit is contained in:
parent
98784b752a
commit
ee41e30881
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/node"
|
||||
"github.com/status-im/status-go/nodecfg"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/services/personal"
|
||||
|
@ -338,19 +339,18 @@ func (b *GethStatusBackend) StartNodeWithKey(acc multiaccounts.Account, password
|
|||
return err
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) mergeConfig(nodecfg *params.NodeConfig) (*params.NodeConfig, error) {
|
||||
var conf params.NodeConfig
|
||||
accountDB := accounts.NewDB(b.appDB)
|
||||
if err := accountDB.GetNodeConfig(&conf); err != nil {
|
||||
func (b *GethStatusBackend) mergeConfig(n *params.NodeConfig) (*params.NodeConfig, error) {
|
||||
conf, err := nodecfg.GetNodeConfig(b.appDB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Overwrite db configuration
|
||||
if err := mergo.Merge(&conf, nodecfg, mergo.WithOverride); err != nil {
|
||||
// Overwrite db configuration (only adds new values)
|
||||
if err := mergo.Merge(conf, n); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := b.saveNodeConfig(&conf); err != nil {
|
||||
if err := b.saveNodeConfig(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -660,9 +660,7 @@ func (b *GethStatusBackend) saveAccountsAndSettings(settings accounts.Settings,
|
|||
func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
var conf params.NodeConfig
|
||||
accountDB := accounts.NewDB(b.appDB)
|
||||
err := accountDB.GetNodeConfig(&conf)
|
||||
conf, err := nodecfg.GetNodeConfig(b.appDB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -683,14 +681,13 @@ func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
|
|||
}
|
||||
conf.KeyStoreDir = filepath.Join(b.rootDataDir, conf.KeyStoreDir)
|
||||
|
||||
return &conf, nil
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) saveNodeConfig(nodeCfg *params.NodeConfig) error {
|
||||
func (b *GethStatusBackend) saveNodeConfig(n *params.NodeConfig) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
accountDB := accounts.NewDB(b.appDB)
|
||||
err := accountDB.SaveSetting("node-config", nodeCfg)
|
||||
err := nodecfg.SaveNodeConfig(b.appDB, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"database/sql"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase/migrations"
|
||||
migrationsprevnodecfg "github.com/status-im/status-go/appdatabase/migrationsprevnodecfg"
|
||||
"github.com/status-im/status-go/nodecfg"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
||||
|
@ -13,6 +15,18 @@ func InitializeDB(path, password string) (*sql.DB, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = migrationsprevnodecfg.Migrate(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// NodeConfig migration cannot be done with SQL
|
||||
err = nodecfg.MigrateNodeConfig(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = migrations.Migrate(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,6 @@
|
|||
-- DO NOT REMOVE
|
||||
-- -----------------------------
|
||||
-- This file does nothing
|
||||
-- It's created so the migration knows from which sql file to continue since
|
||||
-- the migration has been splitted in two (before, and after nodecfg extraction)
|
||||
-- Do not add code here
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,19 @@
|
|||
package migrationsprevnodecfg
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
bindata "github.com/status-im/migrate/v4/source/go_bindata"
|
||||
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
||||
// Migrate applies migrations.
|
||||
func Migrate(db *sql.DB) error {
|
||||
return sqlite.Migrate(db, bindata.Resource(
|
||||
AssetNames(),
|
||||
func(name string) ([]byte, error) {
|
||||
return Asset(name)
|
||||
},
|
||||
))
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
CREATE TABLE node_config (
|
||||
network_id UNSIGNED INT NOT NULL,
|
||||
data_dir VARCHAR NOT NULL,
|
||||
keystore_dir VARCHAR NOT NULL,
|
||||
node_key VARCHAR NOT NULL DEFAULT "",
|
||||
no_discovery BOOLEAN DEFAULT false,
|
||||
rendezvous BOOLEAN DEFAULT false,
|
||||
listen_addr VARCHAR NOT NULL DEFAULT "",
|
||||
advertise_addr VARCHAR NOT NULL DEFAULT "",
|
||||
name VARCHAR NOT NULL DEFAULT "",
|
||||
version VARCHAR NOT NULL DEFAULT "",
|
||||
api_modules VARCHAR NOT NULL DEFAULT "",
|
||||
tls_enabled BOOLEAN DEFAULT false,
|
||||
max_peers UNSIGNED INT,
|
||||
max_pending_peers UNSIGNED INT,
|
||||
enable_status_service BOOLEAN DEFAULT false,
|
||||
enable_ntp_sync BOOLEAN DEFAULT false,
|
||||
waku_enabled BOOLEAN DEFAULT false,
|
||||
waku2_enabled BOOOLEAN DEFAULT false,
|
||||
bridge_enabled BOOLEAN DEFAULT false,
|
||||
wallet_enabled BOOLEAN DEFAULT false,
|
||||
local_notifications_enabled BOOLEAN DEFAULT false,
|
||||
browser_enabled BOOLEAN DEFAULT false,
|
||||
permissions_enabled BOOLEAN DEFAULT false,
|
||||
mailservers_enabled BOOLEAN DEFAULT false,
|
||||
swarm_enabled BOOLEAN DEFAULT false,
|
||||
mailserver_registry_address VARCHAR NOT NULL DEFAULT "",
|
||||
web3provider_enabled BOOLEAN DEFAULT false,
|
||||
ens_enabled BOOLEAN DEFAULT false,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE http_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
host VARCHAR NOT NULL DEFAULT "",
|
||||
port UNSIGNED INT,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE http_virtual_hosts (
|
||||
host VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY(host, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE http_cors (
|
||||
cors VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY(cors, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE ipc_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
file VARCHAR NOT NULL DEFAULT "",
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE log_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
mobile_system BOOLEAN DEFAULT false,
|
||||
log_dir VARCHAR NOT NULL DEFAULT "",
|
||||
file VARCHAR NOT NULL DEFAULT "",
|
||||
log_level VARCHAR NOT NULL DEFAULT "INFO",
|
||||
max_backups UNSIGNED INT,
|
||||
max_size UNSIGNED INT,
|
||||
compress_rotated BOOLEAN DEFAULT false,
|
||||
log_to_stderr BOOLEAN DEFAULT false,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE upstream_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
url VARCHAR NOT NULL DEFAULT "",
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE network_config (
|
||||
chain_id UNSIGNED INT,
|
||||
chain_name VARCHAR NOT NULL DEFAULT "",
|
||||
rpc_url VARCHAR NOT NULL DEFAULT "",
|
||||
block_explorer_url VARCHAR NOT NULL DEFAULT "",
|
||||
icon_url VARCHAR NOT NULL DEFAULT "",
|
||||
native_currency_name VARCHAR NOT NULL DEFAULT "",
|
||||
native_currency_symbol VARCHAR NOT NULL DEFAULT "",
|
||||
native_currency_decimals UNSIGNED INT,
|
||||
is_test BOOLEAN DEFAULT false,
|
||||
layer UNSIGNED INT,
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (chain_id, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE cluster_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
fleet VARCHAR NOT NULL DEFAULT "",
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE cluster_nodes (
|
||||
node VARCHAR NOT NULL,
|
||||
type VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (node, type, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE light_eth_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
database_cache UNSIGNED INT,
|
||||
min_trusted_fraction UNSIGNED INT,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE light_eth_trusted_nodes (
|
||||
node VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (node, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE register_topics (
|
||||
topic VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (topic, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE require_topics (
|
||||
topic VARCHAR NOT NULL,
|
||||
min UNSIGNED INT NOT NULL DEFAULT 0,
|
||||
max UNSIGNED INT NOT NULL DEFAULT 0,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (topic, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE push_notifications_server_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
identity VARCHAR NOT NULL DEFAULT "",
|
||||
gorush_url VARCHAR NOT NULL DEFAULT "",
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE waku_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
light_client BOOLEAN DEFAULT false,
|
||||
full_node BOOLEAN DEFAULT false,
|
||||
enable_mailserver BOOLEAN DEFAULT false,
|
||||
data_dir VARCHAR NOT NULL DEFAULT "",
|
||||
minimum_pow REAL,
|
||||
mailserver_password VARCHAR NOT NULL DEFAULT "",
|
||||
mailserver_rate_limit UNSIGNED INT,
|
||||
mailserver_data_retention UNSIGNED INT,
|
||||
ttl UNSIGNED INT,
|
||||
max_message_size UNSIGNED INT,
|
||||
enable_rate_limiter BOOLEAN DEFAULT false,
|
||||
packet_rate_limit_ip UNSIGNED INT,
|
||||
packet_rate_limit_peer_id UNSIGNED INT,
|
||||
bytes_rate_limit_ip UNSIGNED INT,
|
||||
bytes_rate_limit_peer_id UNSIGNED INT,
|
||||
rate_limit_tolerance UNSIGNED INT,
|
||||
bloom_filter_mode BOOLEAN DEFAULT false,
|
||||
enable_confirmations BOOLEAN DEFAULT false,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE waku_config_db_pg (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
uri VARCHAR NOT NULL DEFAULT "",
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE waku_softblacklisted_peers (
|
||||
peer_id VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (peer_id, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE wakuv2_config (
|
||||
enabled BOOLEAN DEFAULT false,
|
||||
host VARCHAR NOT NULL DEFAULT "",
|
||||
port UNSIGNED INT,
|
||||
keep_alive_interval UNSIGNED INT,
|
||||
light_client BOOLEAN DEFAULT false,
|
||||
full_node BOOLEAN DEFAULT false,
|
||||
discovery_limit UNSIGNED INT,
|
||||
persist_peers BOOLEAN DEFAULT false,
|
||||
data_dir VARCHAR NOT NULL DEFAULT "",
|
||||
max_message_size UNSIGNED INT,
|
||||
enable_confirmations BOOLEAN DEFAULT false,
|
||||
peer_exchange BOOLEAN DEFAULT true,
|
||||
enable_discv5 BOOLEAN DEFAULT false,
|
||||
udp_port UNSIGNED INT,
|
||||
auto_update BOOLEAN default false,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE wakuv2_custom_nodes (
|
||||
name VARCHAR NOT NULL,
|
||||
multiaddress VARCHAR NOT NULL,
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY(name, synthetic_id)
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE shhext_config (
|
||||
pfs_enabled BOOLEAN DEFAULT false,
|
||||
backup_disabled_data_dir VARCHAR NOT NULL DEFAULT "",
|
||||
installation_id VARCHAR NOT NULL DEFAULT "",
|
||||
mailserver_confirmations BOOLEAN DEFAULT false,
|
||||
enable_connection_manager BOOLEAN DEFAULT false,
|
||||
enable_last_used_monitor BOOLEAN DEFAULT false,
|
||||
connection_target UNSIGNED INT,
|
||||
request_delay UNSIGNED BIGINT,
|
||||
max_server_failures UNSIGNED INT,
|
||||
max_message_delivery_attempts UNSIGNED INT,
|
||||
whisper_cache_dir VARCHAR NOT NULL DEFAULT "",
|
||||
disable_generic_discovery_topic BOOLEAN DEFAULT false,
|
||||
send_v1_messages BOOLEAN DEFAULT false,
|
||||
data_sync_enabled BOOLEAN DEFAULT false,
|
||||
verify_transaction_url VARCHAR NOT NULL DEFAULT "",
|
||||
verify_ens_url VARCHAR NOT NULL DEFAULT "",
|
||||
verify_ens_contract_address VARCHAR NOT NULL DEFAULT "",
|
||||
verify_transaction_chain_id UNSIGNED INT,
|
||||
anon_metrics_server_enabled BOOLEAN DEFAULT false,
|
||||
anon_metrics_send_id VARCHAR NOT NULL DEFAULT "",
|
||||
anon_metrics_server_postgres_uri VARCHAR NOT NULL DEFAULT "",
|
||||
bandwidth_stats_enabled BOOLEAN DEFAULT false,
|
||||
enable_mailserver_cycle BOOLEAN DEFAULT false,
|
||||
synthetic_id VARCHAR DEFAULT 'id' PRIMARY KEY
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TABLE shhext_default_push_notification_servers (
|
||||
public_key VARCHAR NOT NULL DEFAULT "",
|
||||
synthetic_id VARCHAR DEFAULT 'id',
|
||||
PRIMARY KEY (public_key, synthetic_id)
|
||||
) WITHOUT ROWID;
|
|
@ -0,0 +1,3 @@
|
|||
package sql
|
||||
|
||||
//go:generate go-bindata -pkg migrationsprevnodecfg -o ../bindata.go ./
|
|
@ -0,0 +1,323 @@
|
|||
package appdatabase
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/nodecfg"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
||||
func setupTestDB(t *testing.T) (*sql.DB, func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "settings-tests-")
|
||||
require.NoError(t, err)
|
||||
db, err := InitializeDB(tmpfile.Name(), "settings-tests")
|
||||
require.NoError(t, err)
|
||||
return db, func() {
|
||||
require.NoError(t, db.Close())
|
||||
require.NoError(t, os.Remove(tmpfile.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNodeConfig(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
|
||||
nodeConfig := randomNodeConfig()
|
||||
require.NoError(t, nodecfg.SaveNodeConfig(db, nodeConfig))
|
||||
|
||||
dbNodeConfig, err := nodecfg.GetNodeConfig(db)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nodeConfig, dbNodeConfig)
|
||||
}
|
||||
|
||||
func TestSaveNodeConfig(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
|
||||
require.NoError(t, nodecfg.SaveNodeConfig(db, randomNodeConfig()))
|
||||
|
||||
newNodeConfig := randomNodeConfig()
|
||||
require.NoError(t, nodecfg.SaveNodeConfig(db, newNodeConfig))
|
||||
|
||||
dbNodeConfig, err := nodecfg.GetNodeConfig(db)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, *newNodeConfig, *dbNodeConfig)
|
||||
}
|
||||
|
||||
func TestMigrateNodeConfig(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
|
||||
nodeConfig := ¶ms.NodeConfig{
|
||||
NetworkID: uint64(randomInt(10)),
|
||||
DataDir: randomString(),
|
||||
ListenAddr: randomString(),
|
||||
Rendezvous: true,
|
||||
ShhextConfig: params.ShhextConfig{
|
||||
PFSEnabled: true,
|
||||
},
|
||||
WakuV2Config: params.WakuV2Config{
|
||||
CustomNodes: make(map[string]string),
|
||||
},
|
||||
RequireTopics: make(map[discv5.Topic]params.Limits),
|
||||
}
|
||||
value := &sqlite.JSONBlob{Data: nodeConfig}
|
||||
|
||||
fmt.Println(value)
|
||||
update, err := db.Prepare("INSERT INTO settings(node_config, address, current_network, dapps_address, installation_id, key_uid, name, networks, photo_path, public_key, signing_phrase, wallet_root_address, synthetic_id) VALUES(?, '', 0, '', '', '', '', '', '', '', '', '', 'id')")
|
||||
require.NoError(t, err)
|
||||
b, err := update.Exec(value)
|
||||
require.NoError(t, err)
|
||||
fmt.Println(b.RowsAffected())
|
||||
// Forcing deletion of node_config data to be able to run migration
|
||||
_, err = db.Exec("DELETE FROM node_config WHERE synthetic_id = 'id'")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = nodecfg.MigrateNodeConfig(db)
|
||||
require.NoError(t, err)
|
||||
|
||||
dbNodeConfig, err := nodecfg.GetNodeConfig(db)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nodeConfig, dbNodeConfig)
|
||||
|
||||
// node_config column should be empty
|
||||
var result string
|
||||
err = db.QueryRow("SELECT COALESCE(NULL, 'empty')").Scan(&result)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "empty", result)
|
||||
}
|
||||
|
||||
func randomString() string {
|
||||
b := make([]byte, 10)
|
||||
_, _ = rand.Read(b)
|
||||
return fmt.Sprintf("%x", b)[:10]
|
||||
}
|
||||
|
||||
func randomBool() bool {
|
||||
return randomInt(2) == 1
|
||||
}
|
||||
|
||||
func randomInt(max int64) int {
|
||||
r, _ := rand.Int(rand.Reader, big.NewInt(max))
|
||||
return int(r.Int64())
|
||||
}
|
||||
|
||||
func randomFloat(max int64) float64 {
|
||||
r, _ := rand.Int(rand.Reader, big.NewInt(max))
|
||||
return float64(r.Int64()) / (1 << 63)
|
||||
}
|
||||
|
||||
func randomStringSlice() []string {
|
||||
m := randomInt(7)
|
||||
var result []string
|
||||
for i := 0; i < m; i++ {
|
||||
result = append(result, randomString())
|
||||
}
|
||||
sort.Strings(result)
|
||||
return result
|
||||
}
|
||||
|
||||
func randomTopicSlice() []discv5.Topic {
|
||||
randomValues := randomStringSlice()
|
||||
var result []discv5.Topic
|
||||
for _, v := range randomValues {
|
||||
result = append(result, discv5.Topic(v))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func randomTopicLimits() map[discv5.Topic]params.Limits {
|
||||
result := make(map[discv5.Topic]params.Limits)
|
||||
m := randomInt(7) + 1
|
||||
for i := 0; i < m; i++ {
|
||||
result[discv5.Topic(fmt.Sprint(i))] = params.Limits{Min: randomInt(2), Max: randomInt(10)}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func randomCustomNodes() map[string]string {
|
||||
result := make(map[string]string)
|
||||
m := randomInt(7)
|
||||
for i := 0; i < m; i++ {
|
||||
result[randomString()] = randomString()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func randomNetworkSlice() []params.Network {
|
||||
m := randomInt(7) + 1
|
||||
var result []params.Network
|
||||
for i := 0; i < m; i++ {
|
||||
n := params.Network{
|
||||
ChainID: uint64(i),
|
||||
ChainName: randomString(),
|
||||
RPCURL: randomString(),
|
||||
BlockExplorerURL: randomString(),
|
||||
IconURL: randomString(),
|
||||
NativeCurrencyName: randomString(),
|
||||
NativeCurrencySymbol: randomString(),
|
||||
NativeCurrencyDecimals: uint64(int64(randomInt(math.MaxInt64))),
|
||||
IsTest: randomBool(),
|
||||
Layer: uint64(int64(randomInt(math.MaxInt64))),
|
||||
Enabled: randomBool(),
|
||||
}
|
||||
result = append(result, n)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func randomNodeConfig() *params.NodeConfig {
|
||||
privK, _ := crypto.GenerateKey()
|
||||
|
||||
return ¶ms.NodeConfig{
|
||||
NetworkID: uint64(int64(randomInt(math.MaxInt64))),
|
||||
DataDir: randomString(),
|
||||
KeyStoreDir: randomString(),
|
||||
NodeKey: randomString(),
|
||||
NoDiscovery: randomBool(),
|
||||
Rendezvous: randomBool(),
|
||||
ListenAddr: randomString(),
|
||||
AdvertiseAddr: randomString(),
|
||||
Name: randomString(),
|
||||
Version: randomString(),
|
||||
APIModules: randomString(),
|
||||
TLSEnabled: randomBool(),
|
||||
MaxPeers: randomInt(math.MaxInt64),
|
||||
MaxPendingPeers: randomInt(math.MaxInt64),
|
||||
EnableStatusService: randomBool(),
|
||||
EnableNTPSync: randomBool(),
|
||||
BridgeConfig: params.BridgeConfig{Enabled: randomBool()},
|
||||
WalletConfig: params.WalletConfig{Enabled: randomBool()},
|
||||
LocalNotificationsConfig: params.LocalNotificationsConfig{Enabled: randomBool()},
|
||||
BrowsersConfig: params.BrowsersConfig{Enabled: randomBool()},
|
||||
ENSConfig: params.ENSConfig{Enabled: randomBool()},
|
||||
PermissionsConfig: params.PermissionsConfig{Enabled: randomBool()},
|
||||
MailserversConfig: params.MailserversConfig{Enabled: randomBool()},
|
||||
Web3ProviderConfig: params.Web3ProviderConfig{Enabled: randomBool()},
|
||||
SwarmConfig: params.SwarmConfig{Enabled: randomBool()},
|
||||
MailServerRegistryAddress: randomString(),
|
||||
HTTPEnabled: randomBool(),
|
||||
HTTPHost: randomString(),
|
||||
HTTPPort: randomInt(math.MaxInt64),
|
||||
HTTPVirtualHosts: randomStringSlice(),
|
||||
HTTPCors: randomStringSlice(),
|
||||
IPCEnabled: randomBool(),
|
||||
IPCFile: randomString(),
|
||||
LogEnabled: randomBool(),
|
||||
LogMobileSystem: randomBool(),
|
||||
LogDir: randomString(),
|
||||
LogFile: randomString(),
|
||||
LogLevel: randomString(),
|
||||
LogMaxBackups: randomInt(math.MaxInt64),
|
||||
LogMaxSize: randomInt(math.MaxInt64),
|
||||
LogCompressRotated: randomBool(),
|
||||
LogToStderr: randomBool(),
|
||||
UpstreamConfig: params.UpstreamRPCConfig{Enabled: randomBool(), URL: randomString()},
|
||||
Networks: randomNetworkSlice(),
|
||||
ClusterConfig: params.ClusterConfig{
|
||||
Enabled: randomBool(),
|
||||
Fleet: randomString(),
|
||||
StaticNodes: randomStringSlice(),
|
||||
BootNodes: randomStringSlice(),
|
||||
},
|
||||
LightEthConfig: params.LightEthConfig{
|
||||
Enabled: randomBool(),
|
||||
DatabaseCache: randomInt(math.MaxInt64),
|
||||
TrustedNodes: randomStringSlice(),
|
||||
MinTrustedFraction: randomInt(math.MaxInt64),
|
||||
},
|
||||
RegisterTopics: randomTopicSlice(),
|
||||
RequireTopics: randomTopicLimits(),
|
||||
PushNotificationServerConfig: pushnotificationserver.Config{
|
||||
Enabled: randomBool(),
|
||||
GorushURL: randomString(),
|
||||
Identity: privK,
|
||||
},
|
||||
ShhextConfig: params.ShhextConfig{
|
||||
PFSEnabled: randomBool(),
|
||||
BackupDisabledDataDir: randomString(),
|
||||
InstallationID: randomString(),
|
||||
MailServerConfirmations: randomBool(),
|
||||
EnableConnectionManager: randomBool(),
|
||||
EnableLastUsedMonitor: randomBool(),
|
||||
ConnectionTarget: randomInt(math.MaxInt64),
|
||||
RequestsDelay: time.Duration(randomInt(math.MaxInt64)),
|
||||
MaxServerFailures: randomInt(math.MaxInt64),
|
||||
MaxMessageDeliveryAttempts: randomInt(math.MaxInt64),
|
||||
WhisperCacheDir: randomString(),
|
||||
DisableGenericDiscoveryTopic: randomBool(),
|
||||
SendV1Messages: randomBool(),
|
||||
DataSyncEnabled: randomBool(),
|
||||
VerifyTransactionURL: randomString(),
|
||||
VerifyENSURL: randomString(),
|
||||
VerifyENSContractAddress: randomString(),
|
||||
VerifyTransactionChainID: int64(randomInt(math.MaxInt64)),
|
||||
AnonMetricsSendID: randomString(),
|
||||
AnonMetricsServerEnabled: randomBool(),
|
||||
AnonMetricsServerPostgresURI: randomString(),
|
||||
BandwidthStatsEnabled: randomBool(),
|
||||
},
|
||||
WakuV2Config: params.WakuV2Config{
|
||||
Enabled: randomBool(),
|
||||
Host: randomString(),
|
||||
Port: randomInt(math.MaxInt64),
|
||||
KeepAliveInterval: randomInt(math.MaxInt64),
|
||||
LightClient: randomBool(),
|
||||
FullNode: randomBool(),
|
||||
DiscoveryLimit: randomInt(math.MaxInt64),
|
||||
PersistPeers: randomBool(),
|
||||
DataDir: randomString(),
|
||||
MaxMessageSize: uint32(randomInt(math.MaxInt64)),
|
||||
EnableConfirmations: randomBool(),
|
||||
CustomNodes: randomCustomNodes(),
|
||||
PeerExchange: randomBool(),
|
||||
EnableDiscV5: randomBool(),
|
||||
UDPPort: randomInt(math.MaxInt64),
|
||||
AutoUpdate: randomBool(),
|
||||
},
|
||||
WakuConfig: params.WakuConfig{
|
||||
Enabled: randomBool(),
|
||||
LightClient: randomBool(),
|
||||
FullNode: randomBool(),
|
||||
EnableMailServer: randomBool(),
|
||||
DataDir: randomString(),
|
||||
MinimumPoW: randomFloat(math.MaxInt64),
|
||||
MailServerPassword: randomString(),
|
||||
MailServerRateLimit: randomInt(math.MaxInt64),
|
||||
MailServerDataRetention: randomInt(math.MaxInt64),
|
||||
TTL: randomInt(math.MaxInt64),
|
||||
MaxMessageSize: uint32(randomInt(math.MaxInt64)),
|
||||
DatabaseConfig: params.DatabaseConfig{
|
||||
PGConfig: params.PGConfig{
|
||||
Enabled: randomBool(),
|
||||
URI: randomString(),
|
||||
},
|
||||
},
|
||||
EnableRateLimiter: randomBool(),
|
||||
PacketRateLimitIP: int64(randomInt(math.MaxInt64)),
|
||||
PacketRateLimitPeerID: int64(randomInt(math.MaxInt64)),
|
||||
BytesRateLimitIP: int64(randomInt(math.MaxInt64)),
|
||||
BytesRateLimitPeerID: int64(randomInt(math.MaxInt64)),
|
||||
RateLimitTolerance: int64(randomInt(math.MaxInt64)),
|
||||
BloomFilterMode: randomBool(),
|
||||
SoftBlacklistedPeerIDs: randomStringSlice(),
|
||||
EnableConfirmations: randomBool(),
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/nodecfg"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
@ -151,14 +153,33 @@ type Database struct {
|
|||
db *sql.DB
|
||||
}
|
||||
|
||||
// Get database
|
||||
func (db Database) DB() *sql.DB {
|
||||
return db.db
|
||||
}
|
||||
|
||||
// Close closes database.
|
||||
func (db Database) Close() error {
|
||||
return db.db.Close()
|
||||
}
|
||||
|
||||
// TODO remove photoPath from settings
|
||||
func (db *Database) CreateSettings(s Settings, nodecfg params.NodeConfig) error {
|
||||
_, err := db.db.Exec(`
|
||||
func (db *Database) CreateSettings(s Settings, n params.NodeConfig) error {
|
||||
tx, err := db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
return
|
||||
}
|
||||
// don't shadow original error
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
_, err = tx.Exec(`
|
||||
INSERT INTO settings (
|
||||
address,
|
||||
currency,
|
||||
|
@ -174,7 +195,6 @@ INSERT INTO settings (
|
|||
mnemonic,
|
||||
name,
|
||||
networks,
|
||||
node_config,
|
||||
photo_path,
|
||||
preview_privacy,
|
||||
public_key,
|
||||
|
@ -183,8 +203,7 @@ INSERT INTO settings (
|
|||
synthetic_id
|
||||
) VALUES (
|
||||
?,?,?,?,?,?,?,?,?,?,
|
||||
?,?,?,?,?,?,?,?,?,?,
|
||||
'id')`,
|
||||
?,?,?,?,?,?,?,?,?,'id')`,
|
||||
s.Address,
|
||||
s.Currency,
|
||||
s.CurrentNetwork,
|
||||
|
@ -199,15 +218,17 @@ INSERT INTO settings (
|
|||
s.Mnemonic,
|
||||
s.Name,
|
||||
s.Networks,
|
||||
&sqlite.JSONBlob{Data: nodecfg},
|
||||
s.PhotoPath,
|
||||
s.PreviewPrivacy,
|
||||
s.PublicKey,
|
||||
s.SigningPhrase,
|
||||
s.WalletRootAddress,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
return nodecfg.SaveConfigWithTx(tx, &n)
|
||||
}
|
||||
|
||||
func (db *Database) SaveSetting(setting string, value interface{}) error {
|
||||
|
@ -292,7 +313,11 @@ func (db *Database) SaveSetting(setting string, value interface{}) error {
|
|||
value = &sqlite.JSONBlob{Data: value}
|
||||
update, err = db.db.Prepare("UPDATE settings SET networks = ? WHERE synthetic_id = 'id'")
|
||||
case "node-config":
|
||||
value = &sqlite.JSONBlob{Data: value}
|
||||
nodeConfig := value.(params.NodeConfig)
|
||||
if err = nodecfg.SaveNodeConfig(db.db, &nodeConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
value = nil
|
||||
update, err = db.db.Prepare("UPDATE settings SET node_config = ? WHERE synthetic_id = 'id'")
|
||||
case "notifications-enabled?":
|
||||
_, ok := value.(bool)
|
||||
|
@ -458,10 +483,6 @@ func (db *Database) SaveSetting(setting string, value interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (db *Database) GetNodeConfig(nodecfg interface{}) error {
|
||||
return db.db.QueryRow("SELECT node_config FROM settings WHERE synthetic_id = 'id'").Scan(&sqlite.JSONBlob{Data: nodecfg})
|
||||
}
|
||||
|
||||
func (db *Database) GetSettings() (Settings, error) {
|
||||
var s Settings
|
||||
err := db.db.QueryRow("SELECT address, anon_metrics_should_send, chaos_mode, currency, current_network, custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, last_updated, latest_derived_path, link_preview_request_enabled, link_previews_enabled_sites, log_level, mnemonic, name, networks, notifications_enabled, push_notifications_server_enabled, push_notifications_from_contacts_only, remote_push_notifications_enabled, send_push_notifications, push_notifications_block_mentions, photo_path, pinned_mailservers, preferred_name, preview_privacy, public_key, remember_syncing_choice, signing_phrase, stickers_packs_installed, stickers_packs_pending, stickers_recent_stickers, syncing_on_mobile_network, default_sync_period, use_mailservers, messages_from_contacts_only, usernames, appearance, profile_pictures_show_to, profile_pictures_visibility, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens, waku_bloom_filter_mode, webview_allow_permission_requests, current_user_status, send_status_updates, gif_recents, gif_favorites, opensea_enabled, last_backup, backup_enabled, telemetry_server_url, auto_message_enabled FROM settings WHERE synthetic_id = 'id'").Scan(
|
||||
|
|
|
@ -80,16 +80,6 @@ func TestSaveSetting(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGetNodeConfig(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
|
||||
require.NoError(t, db.CreateSettings(settings, config))
|
||||
|
||||
_, err := db.GetSettings()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSaveAccounts(t *testing.T) {
|
||||
type testCase struct {
|
||||
description string
|
||||
|
|
|
@ -249,23 +249,22 @@ func (b *StatusNode) wakuService(wakuCfg *params.WakuConfig, clusterCfg *params.
|
|||
func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku, error) {
|
||||
if b.wakuV2Srvc == nil {
|
||||
cfg := &wakuv2.Config{
|
||||
MaxMessageSize: wakucommon.DefaultMaxMessageSize,
|
||||
SoftBlacklistedPeerIDs: nodeConfig.WakuV2Config.SoftBlacklistedPeerIDs,
|
||||
Host: nodeConfig.WakuV2Config.Host,
|
||||
Port: nodeConfig.WakuV2Config.Port,
|
||||
LightClient: nodeConfig.WakuV2Config.LightClient,
|
||||
KeepAliveInterval: nodeConfig.WakuV2Config.KeepAliveInterval,
|
||||
RelayNodes: nodeConfig.ClusterConfig.RelayNodes,
|
||||
StoreNodes: nodeConfig.ClusterConfig.StoreNodes,
|
||||
FilterNodes: nodeConfig.ClusterConfig.FilterNodes,
|
||||
LightpushNodes: nodeConfig.ClusterConfig.LightpushNodes,
|
||||
Rendezvous: nodeConfig.Rendezvous,
|
||||
WakuRendezvousNodes: nodeConfig.ClusterConfig.WakuRendezvousNodes,
|
||||
PeerExchange: nodeConfig.WakuV2Config.PeerExchange,
|
||||
DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit,
|
||||
PersistPeers: nodeConfig.WakuV2Config.PersistPeers,
|
||||
DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes,
|
||||
EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5,
|
||||
MaxMessageSize: wakucommon.DefaultMaxMessageSize,
|
||||
Host: nodeConfig.WakuV2Config.Host,
|
||||
Port: nodeConfig.WakuV2Config.Port,
|
||||
LightClient: nodeConfig.WakuV2Config.LightClient,
|
||||
KeepAliveInterval: nodeConfig.WakuV2Config.KeepAliveInterval,
|
||||
RelayNodes: nodeConfig.ClusterConfig.RelayNodes,
|
||||
StoreNodes: nodeConfig.ClusterConfig.StoreNodes,
|
||||
FilterNodes: nodeConfig.ClusterConfig.FilterNodes,
|
||||
LightpushNodes: nodeConfig.ClusterConfig.LightpushNodes,
|
||||
Rendezvous: nodeConfig.Rendezvous,
|
||||
WakuRendezvousNodes: nodeConfig.ClusterConfig.WakuRendezvousNodes,
|
||||
PeerExchange: nodeConfig.WakuV2Config.PeerExchange,
|
||||
DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit,
|
||||
PersistPeers: nodeConfig.WakuV2Config.PersistPeers,
|
||||
DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes,
|
||||
EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5,
|
||||
}
|
||||
|
||||
if nodeConfig.WakuV2Config.MaxMessageSize > 0 {
|
||||
|
|
|
@ -0,0 +1,732 @@
|
|||
package nodecfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
||||
const StaticNodes = "static"
|
||||
const BootNodes = "boot"
|
||||
const TrustedMailServers = "trusted_mailserver"
|
||||
const PushNotificationsServers = "pushnotification"
|
||||
const RendezvousNodes = "rendezvous"
|
||||
const RelayNodes = "relay"
|
||||
const StoreNodes = "store"
|
||||
const FilterNodes = "filter"
|
||||
const LightpushNodes = "lightpush"
|
||||
const WakuRendezvousNodes = "waku_rendezvous"
|
||||
const DiscV5BootstrapNodes = "discV5boot"
|
||||
|
||||
func nodeConfigWasMigrated(tx *sql.Tx) (migrated bool, err error) {
|
||||
row := tx.QueryRow("SELECT exists(SELECT 1 FROM node_config)")
|
||||
switch err := row.Scan(&migrated); err {
|
||||
case sql.ErrNoRows, nil:
|
||||
return migrated, nil
|
||||
default:
|
||||
return migrated, err
|
||||
}
|
||||
}
|
||||
|
||||
type insertFn func(tx *sql.Tx, c *params.NodeConfig) error
|
||||
|
||||
func insertNodeConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`
|
||||
INSERT OR REPLACE INTO node_config (
|
||||
network_id, data_dir, keystore_dir, node_key, no_discovery, rendezvous,
|
||||
listen_addr, advertise_addr, name, version, api_modules, tls_enabled,
|
||||
max_peers, max_pending_peers, enable_status_service, enable_ntp_sync,
|
||||
bridge_enabled, wallet_enabled, local_notifications_enabled,
|
||||
browser_enabled, permissions_enabled, mailservers_enabled,
|
||||
swarm_enabled, mailserver_registry_address, web3provider_enabled,
|
||||
ens_enabled, synthetic_id
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, 'id'
|
||||
)`,
|
||||
c.NetworkID, c.DataDir, c.KeyStoreDir, c.NodeKey, c.NoDiscovery, c.Rendezvous,
|
||||
c.ListenAddr, c.AdvertiseAddr, c.Name, c.Version, c.APIModules,
|
||||
c.TLSEnabled, c.MaxPeers, c.MaxPendingPeers,
|
||||
c.EnableStatusService, c.EnableNTPSync,
|
||||
c.BridgeConfig.Enabled, c.WalletConfig.Enabled, c.LocalNotificationsConfig.Enabled,
|
||||
c.BrowsersConfig.Enabled, c.PermissionsConfig.Enabled, c.MailserversConfig.Enabled,
|
||||
c.SwarmConfig.Enabled, c.MailServerRegistryAddress, c.Web3ProviderConfig.Enabled,
|
||||
c.ENSConfig.Enabled,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertHTTPConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
if _, err := tx.Exec(`INSERT OR REPLACE INTO http_config (enabled, host, port, synthetic_id) VALUES (?, ?, ?, 'id')`, c.HTTPEnabled, c.HTTPHost, c.HTTPPort); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(`DELETE FROM http_virtual_hosts WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, httpVirtualHost := range c.HTTPVirtualHosts {
|
||||
if _, err := tx.Exec(`INSERT OR REPLACE INTO http_virtual_hosts (host, synthetic_id) VALUES (?, 'id')`, httpVirtualHost); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(`DELETE FROM http_cors WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, httpCors := range c.HTTPCors {
|
||||
if _, err := tx.Exec(`INSERT OR REPLACE INTO http_cors (cors, synthetic_id) VALUES (?, 'id')`, httpCors); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertLogConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`
|
||||
INSERT OR REPLACE INTO log_config (
|
||||
enabled, mobile_system, log_dir, log_level, max_backups, max_size,
|
||||
file, compress_rotated, log_to_stderr, synthetic_id
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'id' )`,
|
||||
c.LogEnabled, c.LogMobileSystem, c.LogDir, c.LogLevel, c.LogMaxBackups, c.LogMaxSize,
|
||||
c.LogFile, c.LogCompressRotated, c.LogToStderr,
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func insertNetworkConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
if _, err := tx.Exec(`DELETE FROM network_config WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, network := range c.Networks {
|
||||
_, err := tx.Exec(`
|
||||
INSERT OR REPLACE INTO network_config (
|
||||
chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name,
|
||||
native_currency_symbol, native_currency_decimals, is_test, layer, enabled,
|
||||
synthetic_id
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'id' )`,
|
||||
network.ChainID, network.ChainName, network.RPCURL, network.BlockExplorerURL, network.IconURL, network.NativeCurrencyName,
|
||||
network.NativeCurrencySymbol, network.NativeCurrencyDecimals, network.IsTest, network.Layer, network.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertLightETHConfigTrustedNodes(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
if _, err := tx.Exec(`DELETE FROM light_eth_trusted_nodes WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, node := range c.LightEthConfig.TrustedNodes {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO light_eth_trusted_nodes (node, synthetic_id) VALUES (?, 'id')`, node)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertRegisterTopics(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
if _, err := tx.Exec(`DELETE FROM register_topics WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, topic := range c.RegisterTopics {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO register_topics (topic, synthetic_id) VALUES (?, 'id')`, topic)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertRequireTopics(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
if _, err := tx.Exec(`DELETE FROM require_topics WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for topic, limits := range c.RequireTopics {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO require_topics (topic, min, max, synthetic_id) VALUES (?, ?, ?, 'id')`, topic, limits.Min, limits.Max)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertIPCConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO ipc_config (enabled, file, synthetic_id) VALUES (?, ?, 'id')`, c.IPCEnabled, c.IPCFile)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertClusterConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO cluster_config (enabled, fleet, synthetic_id) VALUES (?, ?, 'id')`, c.ClusterConfig.Enabled, c.ClusterConfig.Fleet)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertUpstreamConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO upstream_config (enabled, url, synthetic_id) VALUES (?, ?, 'id')`, c.UpstreamConfig.Enabled, c.UpstreamConfig.URL)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertLightETHConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO light_eth_config (enabled, database_cache, min_trusted_fraction, synthetic_id) VALUES (?, ?, ?, 'id')`, c.LightEthConfig.Enabled, c.LightEthConfig.DatabaseCache, c.LightEthConfig.MinTrustedFraction)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertShhExtConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`
|
||||
INSERT OR REPLACE INTO shhext_config (
|
||||
pfs_enabled, backup_disabled_data_dir, installation_id, mailserver_confirmations, enable_connection_manager,
|
||||
enable_last_used_monitor, connection_target, request_delay, max_server_failures, max_message_delivery_attempts,
|
||||
whisper_cache_dir, disable_generic_discovery_topic, send_v1_messages, data_sync_enabled, verify_transaction_url,
|
||||
verify_ens_url, verify_ens_contract_address, verify_transaction_chain_id, anon_metrics_server_enabled,
|
||||
anon_metrics_send_id, anon_metrics_server_postgres_uri, bandwidth_stats_enabled, enable_mailserver_cycle, synthetic_id
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'id')`,
|
||||
c.ShhextConfig.PFSEnabled, c.ShhextConfig.BackupDisabledDataDir, c.ShhextConfig.InstallationID, c.ShhextConfig.MailServerConfirmations, c.ShhextConfig.EnableConnectionManager,
|
||||
c.ShhextConfig.EnableLastUsedMonitor, c.ShhextConfig.ConnectionTarget, c.ShhextConfig.RequestsDelay, c.ShhextConfig.MaxServerFailures, c.ShhextConfig.MaxMessageDeliveryAttempts,
|
||||
c.ShhextConfig.WhisperCacheDir, c.ShhextConfig.DisableGenericDiscoveryTopic, c.ShhextConfig.SendV1Messages, c.ShhextConfig.DataSyncEnabled, c.ShhextConfig.VerifyTransactionURL,
|
||||
c.ShhextConfig.VerifyENSURL, c.ShhextConfig.VerifyENSContractAddress, c.ShhextConfig.VerifyTransactionChainID, c.ShhextConfig.AnonMetricsServerEnabled,
|
||||
c.ShhextConfig.AnonMetricsSendID, c.ShhextConfig.AnonMetricsServerPostgresURI, c.ShhextConfig.BandwidthStatsEnabled, c.ShhextConfig.EnableMailserverCycle,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(`DELETE FROM shhext_default_push_notification_servers WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, pubKey := range c.ShhextConfig.DefaultPushNotificationsServers {
|
||||
hexpubk := hexutil.Encode(crypto.FromECDSAPub(pubKey))
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO shhext_default_push_notification_servers (public_key, synthetic_id) VALUES (?, 'id')`, hexpubk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertWakuV2Config(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`
|
||||
INSERT OR REPLACE INTO wakuv2_config (
|
||||
enabled, host, port, keep_alive_interval, light_client, full_node, discovery_limit, persist_peers, data_dir,
|
||||
max_message_size, enable_confirmations, peer_exchange, enable_discv5, udp_port, auto_update, synthetic_id
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'id')`,
|
||||
c.WakuV2Config.Enabled, c.WakuV2Config.Host, c.WakuV2Config.Port, c.WakuV2Config.KeepAliveInterval, c.WakuV2Config.LightClient, c.WakuV2Config.FullNode, c.WakuV2Config.DiscoveryLimit, c.WakuV2Config.PersistPeers, c.WakuV2Config.DataDir,
|
||||
c.WakuV2Config.MaxMessageSize, c.WakuV2Config.EnableConfirmations, c.WakuV2Config.PeerExchange, c.WakuV2Config.EnableDiscV5, c.WakuV2Config.UDPPort, c.WakuV2Config.AutoUpdate,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(`DELETE FROM wakuv2_custom_nodes WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for name, multiaddress := range c.WakuV2Config.CustomNodes {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO wakuv2_custom_nodes (name, multiaddress, synthetic_id) VALUES (?, ?, 'id')`, name, multiaddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertWakuConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
_, err := tx.Exec(`
|
||||
INSERT OR REPLACE INTO waku_config (
|
||||
enabled, light_client, full_node, enable_mailserver, data_dir, minimum_pow, mailserver_password, mailserver_rate_limit, mailserver_data_retention,
|
||||
ttl, max_message_size, enable_rate_limiter, packet_rate_limit_ip, packet_rate_limit_peer_id, bytes_rate_limit_ip, bytes_rate_limit_peer_id,
|
||||
rate_limit_tolerance, bloom_filter_mode, enable_confirmations, synthetic_id
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'id')`,
|
||||
c.WakuConfig.Enabled, c.WakuConfig.LightClient, c.WakuConfig.FullNode, c.WakuConfig.EnableMailServer, c.WakuConfig.DataDir, c.WakuConfig.MinimumPoW,
|
||||
c.WakuConfig.MailServerPassword, c.WakuConfig.MailServerRateLimit, c.WakuConfig.MailServerDataRetention, c.WakuConfig.TTL, c.WakuConfig.MaxMessageSize,
|
||||
c.WakuConfig.EnableRateLimiter, c.WakuConfig.PacketRateLimitIP, c.WakuConfig.PacketRateLimitPeerID, c.WakuConfig.BytesRateLimitIP, c.WakuConfig.BytesRateLimitPeerID,
|
||||
c.WakuConfig.RateLimitTolerance, c.WakuConfig.BloomFilterMode, c.WakuConfig.EnableConfirmations,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(`INSERT OR REPLACE INTO waku_config_db_pg (enabled, uri, synthetic_id) VALUES (?, ?, 'id')`, c.WakuConfig.DatabaseConfig.PGConfig.Enabled, c.WakuConfig.DatabaseConfig.PGConfig.URI); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(`DELETE FROM waku_softblacklisted_peers WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, peerID := range c.WakuConfig.SoftBlacklistedPeerIDs {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO waku_softblacklisted_peers (peer_id, synthetic_id) VALUES (?, 'id')`, peerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertPushNotificationsServerConfig(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
hexPrivKey := ""
|
||||
if c.PushNotificationServerConfig.Identity != nil {
|
||||
hexPrivKey = hexutil.Encode(crypto.FromECDSA(c.PushNotificationServerConfig.Identity))
|
||||
}
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO push_notifications_server_config (enabled, identity, gorush_url, synthetic_id) VALUES (?, ?, ?, 'id')`, c.PushNotificationServerConfig.Enabled, hexPrivKey, c.PushNotificationServerConfig.GorushURL)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertClusterConfigNodes(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
if _, err := tx.Exec(`DELETE FROM cluster_nodes WHERE synthetic_id = 'id'`); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nodeMap := make(map[string][]string)
|
||||
nodeMap[StaticNodes] = c.ClusterConfig.StaticNodes
|
||||
nodeMap[BootNodes] = c.ClusterConfig.BootNodes
|
||||
nodeMap[TrustedMailServers] = c.ClusterConfig.TrustedMailServers
|
||||
nodeMap[PushNotificationsServers] = c.ClusterConfig.PushNotificationsServers
|
||||
nodeMap[RendezvousNodes] = c.ClusterConfig.RendezvousNodes
|
||||
nodeMap[RelayNodes] = c.ClusterConfig.RelayNodes
|
||||
nodeMap[StoreNodes] = c.ClusterConfig.StoreNodes
|
||||
nodeMap[FilterNodes] = c.ClusterConfig.FilterNodes
|
||||
nodeMap[LightpushNodes] = c.ClusterConfig.LightpushNodes
|
||||
nodeMap[WakuRendezvousNodes] = c.ClusterConfig.WakuRendezvousNodes
|
||||
nodeMap[DiscV5BootstrapNodes] = c.ClusterConfig.DiscV5BootstrapNodes
|
||||
|
||||
for nodeType, nodes := range nodeMap {
|
||||
for _, node := range nodes {
|
||||
_, err := tx.Exec(`INSERT OR REPLACE INTO cluster_nodes (node, type, synthetic_id) VALUES (?, ?, 'id')`, node, nodeType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveConfigWithTx(tx *sql.Tx, c *params.NodeConfig) error {
|
||||
insertFNs := []insertFn{
|
||||
insertNodeConfig,
|
||||
insertHTTPConfig,
|
||||
insertIPCConfig,
|
||||
insertLogConfig,
|
||||
insertUpstreamConfig,
|
||||
insertNetworkConfig,
|
||||
insertClusterConfig,
|
||||
insertClusterConfigNodes,
|
||||
insertLightETHConfig,
|
||||
insertLightETHConfigTrustedNodes,
|
||||
insertRegisterTopics,
|
||||
insertRequireTopics,
|
||||
insertPushNotificationsServerConfig,
|
||||
insertShhExtConfig,
|
||||
insertWakuConfig,
|
||||
insertWakuV2Config,
|
||||
}
|
||||
|
||||
for _, fn := range insertFNs {
|
||||
err := fn(tx, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveNodeConfig(db *sql.DB, c *params.NodeConfig) error {
|
||||
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
return
|
||||
}
|
||||
// don't shadow original error
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
return SaveConfigWithTx(tx, c)
|
||||
}
|
||||
|
||||
func migrateNodeConfig(tx *sql.Tx) error {
|
||||
nodecfg := ¶ms.NodeConfig{}
|
||||
err := tx.QueryRow("SELECT node_config FROM settings WHERE synthetic_id = 'id'").Scan(&sqlite.JSONBlob{Data: nodecfg})
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return err
|
||||
}
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
// Can't migrate because there's no data
|
||||
return nil
|
||||
}
|
||||
|
||||
err = SaveConfigWithTx(tx, nodecfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadNodeConfig(tx *sql.Tx) (*params.NodeConfig, error) {
|
||||
nodecfg := ¶ms.NodeConfig{}
|
||||
|
||||
err := tx.QueryRow(`
|
||||
SELECT
|
||||
network_id, data_dir, keystore_dir, node_key, no_discovery, rendezvous,
|
||||
listen_addr, advertise_addr, name, version, api_modules, tls_enabled, max_peers, max_pending_peers,
|
||||
enable_status_service, enable_ntp_sync, bridge_enabled, wallet_enabled, local_notifications_enabled,
|
||||
browser_enabled, permissions_enabled, mailservers_enabled, swarm_enabled,
|
||||
mailserver_registry_address, web3provider_enabled, ens_enabled FROM node_config
|
||||
WHERE synthetic_id = 'id'
|
||||
`).Scan(
|
||||
&nodecfg.NetworkID, &nodecfg.DataDir, &nodecfg.KeyStoreDir, &nodecfg.NodeKey, &nodecfg.NoDiscovery, &nodecfg.Rendezvous,
|
||||
&nodecfg.ListenAddr, &nodecfg.AdvertiseAddr, &nodecfg.Name, &nodecfg.Version, &nodecfg.APIModules, &nodecfg.TLSEnabled, &nodecfg.MaxPeers, &nodecfg.MaxPendingPeers,
|
||||
&nodecfg.EnableStatusService, &nodecfg.EnableNTPSync, &nodecfg.BridgeConfig.Enabled, &nodecfg.WalletConfig.Enabled, &nodecfg.LocalNotificationsConfig.Enabled,
|
||||
&nodecfg.BrowsersConfig.Enabled, &nodecfg.PermissionsConfig.Enabled, &nodecfg.MailserversConfig.Enabled, &nodecfg.SwarmConfig.Enabled,
|
||||
&nodecfg.MailServerRegistryAddress, &nodecfg.Web3ProviderConfig.Enabled, &nodecfg.ENSConfig.Enabled,
|
||||
)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = tx.QueryRow(`SELECT enabled, host, port FROM http_config WHERE synthetic_id = 'id'`).Scan(&nodecfg.HTTPEnabled, &nodecfg.HTTPHost, &nodecfg.HTTPPort)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err := tx.Query("SELECT host FROM http_virtual_hosts WHERE synthetic_id = 'id' ORDER BY host ASC")
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var host string
|
||||
err = rows.Scan(&host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.HTTPVirtualHosts = append(nodecfg.HTTPVirtualHosts, host)
|
||||
}
|
||||
|
||||
rows, err = tx.Query("SELECT cors FROM http_cors WHERE synthetic_id = 'id' ORDER BY cors ASC")
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var cors string
|
||||
err = rows.Scan(&cors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.HTTPCors = append(nodecfg.HTTPCors, cors)
|
||||
}
|
||||
|
||||
err = tx.QueryRow("SELECT enabled, file FROM ipc_config WHERE synthetic_id = 'id'").Scan(&nodecfg.IPCEnabled, &nodecfg.IPCFile)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = tx.QueryRow("SELECT enabled, mobile_system, log_dir, log_level, file, max_backups, max_size, compress_rotated, log_to_stderr FROM log_config WHERE synthetic_id = 'id'").Scan(
|
||||
&nodecfg.LogEnabled, &nodecfg.LogMobileSystem, &nodecfg.LogDir, &nodecfg.LogLevel, &nodecfg.LogFile, &nodecfg.LogMaxBackups, &nodecfg.LogMaxSize, &nodecfg.LogCompressRotated, &nodecfg.LogToStderr)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = tx.QueryRow("SELECT enabled, url FROM upstream_config WHERE synthetic_id = 'id'").Scan(&nodecfg.UpstreamConfig.Enabled, &nodecfg.UpstreamConfig.URL)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT
|
||||
chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name,
|
||||
native_currency_symbol, native_currency_decimals, is_test, layer, enabled
|
||||
FROM network_config WHERE synthetic_id = 'id' ORDER BY chain_id ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var n params.Network
|
||||
err = rows.Scan(&n.ChainID, &n.ChainName, &n.RPCURL, &n.BlockExplorerURL, &n.IconURL,
|
||||
&n.NativeCurrencyName, &n.NativeCurrencySymbol, &n.NativeCurrencyDecimals, &n.IsTest,
|
||||
&n.Layer, &n.Enabled,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.Networks = append(nodecfg.Networks, n)
|
||||
}
|
||||
|
||||
err = tx.QueryRow("SELECT enabled, fleet FROM cluster_config WHERE synthetic_id = 'id'").Scan(&nodecfg.ClusterConfig.Enabled, &nodecfg.ClusterConfig.Fleet)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeMap := make(map[string]*[]string)
|
||||
nodeMap[StaticNodes] = &nodecfg.ClusterConfig.StaticNodes
|
||||
nodeMap[BootNodes] = &nodecfg.ClusterConfig.BootNodes
|
||||
nodeMap[TrustedMailServers] = &nodecfg.ClusterConfig.TrustedMailServers
|
||||
nodeMap[PushNotificationsServers] = &nodecfg.ClusterConfig.PushNotificationsServers
|
||||
nodeMap[RendezvousNodes] = &nodecfg.ClusterConfig.RendezvousNodes
|
||||
nodeMap[RelayNodes] = &nodecfg.ClusterConfig.RelayNodes
|
||||
nodeMap[StoreNodes] = &nodecfg.ClusterConfig.StoreNodes
|
||||
nodeMap[FilterNodes] = &nodecfg.ClusterConfig.FilterNodes
|
||||
nodeMap[LightpushNodes] = &nodecfg.ClusterConfig.LightpushNodes
|
||||
nodeMap[WakuRendezvousNodes] = &nodecfg.ClusterConfig.WakuRendezvousNodes
|
||||
nodeMap[DiscV5BootstrapNodes] = &nodecfg.ClusterConfig.DiscV5BootstrapNodes
|
||||
rows, err = tx.Query(`SELECT node, type FROM cluster_nodes WHERE synthetic_id = 'id' ORDER BY node ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var node string
|
||||
var nodeType string
|
||||
err = rows.Scan(&node, &nodeType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if nodeList, ok := nodeMap[nodeType]; ok {
|
||||
*nodeList = append(*nodeList, node)
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.QueryRow("SELECT enabled, database_cache, min_trusted_fraction FROM light_eth_config WHERE synthetic_id = 'id'").Scan(&nodecfg.LightEthConfig.Enabled, &nodecfg.LightEthConfig.DatabaseCache, &nodecfg.LightEthConfig.MinTrustedFraction)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT node FROM light_eth_trusted_nodes WHERE synthetic_id = 'id' ORDER BY node ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var node string
|
||||
err = rows.Scan(&node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.LightEthConfig.TrustedNodes = append(nodecfg.LightEthConfig.TrustedNodes, node)
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT topic FROM register_topics WHERE synthetic_id = 'id' ORDER BY topic ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var topic discv5.Topic
|
||||
err = rows.Scan(&topic)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.RegisterTopics = append(nodecfg.RegisterTopics, topic)
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT topic, min, max FROM require_topics WHERE synthetic_id = 'id' ORDER BY topic ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
nodecfg.RequireTopics = make(map[discv5.Topic]params.Limits)
|
||||
for rows.Next() {
|
||||
var topic discv5.Topic
|
||||
var limit params.Limits
|
||||
err = rows.Scan(&topic, &limit.Min, &limit.Max)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.RequireTopics[topic] = limit
|
||||
}
|
||||
|
||||
var pushNotifHexIdentity string
|
||||
err = tx.QueryRow("SELECT enabled, identity, gorush_url FROM push_notifications_server_config WHERE synthetic_id = 'id'").Scan(&nodecfg.PushNotificationServerConfig.Enabled, &pushNotifHexIdentity, &nodecfg.PushNotificationServerConfig.GorushURL)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
if pushNotifHexIdentity != "" {
|
||||
b, err := hexutil.Decode(pushNotifHexIdentity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.PushNotificationServerConfig.Identity, err = crypto.ToECDSA(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.QueryRow(`
|
||||
SELECT pfs_enabled, backup_disabled_data_dir, installation_id, mailserver_confirmations, enable_connection_manager,
|
||||
enable_last_used_monitor, connection_target, request_delay, max_server_failures, max_message_delivery_attempts,
|
||||
whisper_cache_dir, disable_generic_discovery_topic, send_v1_messages, data_sync_enabled, verify_transaction_url,
|
||||
verify_ens_url, verify_ens_contract_address, verify_transaction_chain_id, anon_metrics_server_enabled,
|
||||
anon_metrics_send_id, anon_metrics_server_postgres_uri, bandwidth_stats_enabled, enable_mailserver_cycle FROM shhext_config WHERE synthetic_id = 'id'
|
||||
`).Scan(
|
||||
&nodecfg.ShhextConfig.PFSEnabled, &nodecfg.ShhextConfig.BackupDisabledDataDir, &nodecfg.ShhextConfig.InstallationID, &nodecfg.ShhextConfig.MailServerConfirmations, &nodecfg.ShhextConfig.EnableConnectionManager,
|
||||
&nodecfg.ShhextConfig.EnableLastUsedMonitor, &nodecfg.ShhextConfig.ConnectionTarget, &nodecfg.ShhextConfig.RequestsDelay, &nodecfg.ShhextConfig.MaxServerFailures, &nodecfg.ShhextConfig.MaxMessageDeliveryAttempts,
|
||||
&nodecfg.ShhextConfig.WhisperCacheDir, &nodecfg.ShhextConfig.DisableGenericDiscoveryTopic, &nodecfg.ShhextConfig.SendV1Messages, &nodecfg.ShhextConfig.DataSyncEnabled, &nodecfg.ShhextConfig.VerifyTransactionURL,
|
||||
&nodecfg.ShhextConfig.VerifyENSURL, &nodecfg.ShhextConfig.VerifyENSContractAddress, &nodecfg.ShhextConfig.VerifyTransactionChainID, &nodecfg.ShhextConfig.AnonMetricsServerEnabled,
|
||||
&nodecfg.ShhextConfig.AnonMetricsSendID, &nodecfg.ShhextConfig.AnonMetricsServerPostgresURI, &nodecfg.ShhextConfig.BandwidthStatsEnabled, &nodecfg.ShhextConfig.EnableMailserverCycle,
|
||||
)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT public_key FROM shhext_default_push_notification_servers WHERE synthetic_id = 'id' ORDER BY public_key ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var pubKeyStr string
|
||||
err = rows.Scan(&pubKeyStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pubKeyStr != "" {
|
||||
b, err := hexutil.Decode(pubKeyStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pubKey, err := crypto.UnmarshalPubkey(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.ShhextConfig.DefaultPushNotificationsServers = append(nodecfg.ShhextConfig.DefaultPushNotificationsServers, pubKey)
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.QueryRow(`
|
||||
SELECT enabled, host, port, keep_alive_interval, light_client, full_node, discovery_limit, persist_peers, data_dir,
|
||||
max_message_size, enable_confirmations, peer_exchange, enable_discv5, udp_port, auto_update
|
||||
FROM wakuv2_config WHERE synthetic_id = 'id'
|
||||
`).Scan(
|
||||
&nodecfg.WakuV2Config.Enabled, &nodecfg.WakuV2Config.Host, &nodecfg.WakuV2Config.Port, &nodecfg.WakuV2Config.KeepAliveInterval, &nodecfg.WakuV2Config.LightClient, &nodecfg.WakuV2Config.FullNode,
|
||||
&nodecfg.WakuV2Config.DiscoveryLimit, &nodecfg.WakuV2Config.PersistPeers, &nodecfg.WakuV2Config.DataDir, &nodecfg.WakuV2Config.MaxMessageSize, &nodecfg.WakuV2Config.EnableConfirmations,
|
||||
&nodecfg.WakuV2Config.PeerExchange, &nodecfg.WakuV2Config.EnableDiscV5, &nodecfg.WakuV2Config.UDPPort, &nodecfg.WakuV2Config.AutoUpdate,
|
||||
)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT name, multiaddress FROM wakuv2_custom_nodes WHERE synthetic_id = 'id' ORDER BY name ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
nodecfg.WakuV2Config.CustomNodes = make(map[string]string)
|
||||
for rows.Next() {
|
||||
var name string
|
||||
var multiaddress string
|
||||
err = rows.Scan(&name, &multiaddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.WakuV2Config.CustomNodes[name] = multiaddress
|
||||
}
|
||||
|
||||
err = tx.QueryRow(`
|
||||
SELECT enabled, light_client, full_node, enable_mailserver, data_dir, minimum_pow, mailserver_password, mailserver_rate_limit, mailserver_data_retention,
|
||||
ttl, max_message_size, enable_rate_limiter, packet_rate_limit_ip, packet_rate_limit_peer_id, bytes_rate_limit_ip, bytes_rate_limit_peer_id,
|
||||
rate_limit_tolerance, bloom_filter_mode, enable_confirmations
|
||||
FROM waku_config WHERE synthetic_id = 'id'
|
||||
`).Scan(
|
||||
&nodecfg.WakuConfig.Enabled, &nodecfg.WakuConfig.LightClient, &nodecfg.WakuConfig.FullNode, &nodecfg.WakuConfig.EnableMailServer, &nodecfg.WakuConfig.DataDir, &nodecfg.WakuConfig.MinimumPoW,
|
||||
&nodecfg.WakuConfig.MailServerPassword, &nodecfg.WakuConfig.MailServerRateLimit, &nodecfg.WakuConfig.MailServerDataRetention, &nodecfg.WakuConfig.TTL, &nodecfg.WakuConfig.MaxMessageSize,
|
||||
&nodecfg.WakuConfig.EnableRateLimiter, &nodecfg.WakuConfig.PacketRateLimitIP, &nodecfg.WakuConfig.PacketRateLimitPeerID, &nodecfg.WakuConfig.BytesRateLimitIP, &nodecfg.WakuConfig.BytesRateLimitPeerID,
|
||||
&nodecfg.WakuConfig.RateLimitTolerance, &nodecfg.WakuConfig.BloomFilterMode, &nodecfg.WakuConfig.EnableConfirmations,
|
||||
)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = tx.QueryRow("SELECT enabled, uri FROM waku_config_db_pg WHERE synthetic_id = 'id'").Scan(&nodecfg.WakuConfig.DatabaseConfig.PGConfig.Enabled, &nodecfg.WakuConfig.DatabaseConfig.PGConfig.URI)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rows, err = tx.Query(`SELECT peer_id FROM waku_softblacklisted_peers WHERE synthetic_id = 'id' ORDER BY peer_id ASC`)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var peerID string
|
||||
err = rows.Scan(&peerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodecfg.WakuConfig.SoftBlacklistedPeerIDs = append(nodecfg.WakuConfig.SoftBlacklistedPeerIDs, peerID)
|
||||
}
|
||||
|
||||
return nodecfg, nil
|
||||
}
|
||||
|
||||
func MigrateNodeConfig(db *sql.DB) error {
|
||||
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
return
|
||||
}
|
||||
// don't shadow original error
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
migrated, err := nodeConfigWasMigrated(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !migrated {
|
||||
return migrateNodeConfig(tx)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetNodeConfig(db *sql.DB) (*params.NodeConfig, error) {
|
||||
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
err = tx.Commit()
|
||||
return
|
||||
}
|
||||
// don't shadow original error
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
return loadNodeConfig(tx)
|
||||
}
|
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||
"github.com/status-im/status-go/rpc/network"
|
||||
"github.com/status-im/status-go/static"
|
||||
wakucommon "github.com/status-im/status-go/waku/common"
|
||||
wakuv2common "github.com/status-im/status-go/wakuv2/common"
|
||||
|
@ -179,57 +178,14 @@ type WakuV2Config struct {
|
|||
//it attempts to reconnect to these peers
|
||||
PersistPeers bool
|
||||
|
||||
// EnableMailServer is mode when node is capable of delivering expired messages on demand
|
||||
EnableMailServer bool
|
||||
|
||||
// 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
|
||||
|
||||
// MailServerPassword for symmetric encryption of waku message history requests.
|
||||
// (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
|
||||
|
||||
// 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
|
||||
|
||||
// DatabaseConfig is configuration for which data store we use.
|
||||
DatabaseConfig DatabaseConfig
|
||||
|
||||
// EnableRateLimiter set to true enables IP and peer ID rate limiting.
|
||||
EnableRateLimiter bool
|
||||
|
||||
// PacketRateLimitIP sets the limit on the number of packets per second
|
||||
// from a given IP.
|
||||
PacketRateLimitIP int64
|
||||
|
||||
// PacketRateLimitPeerID sets the limit on the number of packets per second
|
||||
// from a given peer ID.
|
||||
PacketRateLimitPeerID int64
|
||||
|
||||
// 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
|
||||
|
||||
// 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
|
||||
|
||||
// SoftBlacklistedPeerIDs is a list of peer ids that should be soft-blacklisted (messages should be dropped but connection kept)
|
||||
SoftBlacklistedPeerIDs []string
|
||||
|
||||
// EnableConfirmations when true, instructs that confirmation should be sent for received messages
|
||||
EnableConfirmations bool
|
||||
|
||||
|
@ -473,7 +429,7 @@ type NodeConfig struct {
|
|||
UpstreamConfig UpstreamRPCConfig `json:"UpstreamConfig"`
|
||||
|
||||
// Initial networks to load
|
||||
Networks []network.Network
|
||||
Networks []Network
|
||||
|
||||
// ClusterConfig extra configuration for supporting cluster peers.
|
||||
ClusterConfig ClusterConfig `json:"ClusterConfig," validate:"structonly"`
|
||||
|
@ -534,6 +490,20 @@ type NodeConfig struct {
|
|||
PushNotificationServerConfig pushnotificationserver.Config `json:"PushNotificationServerConfig"`
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
ChainID uint64 `json:"chainId"`
|
||||
ChainName string `json:"chainName"`
|
||||
RPCURL string `json:"rpcUrl"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// WalletConfig extra configuration for wallet.Service.
|
||||
type WalletConfig struct {
|
||||
Enabled bool
|
||||
|
@ -965,14 +935,6 @@ func (c *NodeConfig) Validate() error {
|
|||
}
|
||||
}
|
||||
|
||||
// WakuV2's data directory must be relative to the main data directory
|
||||
// if EnableMailServer is true.
|
||||
if c.WakuV2Config.Enabled && c.WakuV2Config.EnableMailServer {
|
||||
if !strings.HasPrefix(c.WakuV2Config.DataDir, c.DataDir) {
|
||||
return fmt.Errorf("WakuV2Config.DataDir must start with DataDir fragment")
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
|
|
@ -59,7 +59,7 @@ type Client struct {
|
|||
//
|
||||
// Client is safe for concurrent use and will automatically
|
||||
// reconnect to the server if connection is lost.
|
||||
func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.UpstreamRPCConfig, networks []network.Network, db *sql.DB) (*Client, error) {
|
||||
func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.UpstreamRPCConfig, networks []params.Network, db *sql.DB) (*Client, error) {
|
||||
var err error
|
||||
|
||||
log := log.New("package", "status-go/rpc.Client")
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/rpc/network"
|
||||
|
||||
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
@ -46,7 +45,7 @@ func TestBlockedRoutesCall(t *testing.T) {
|
|||
gethRPCClient, err := gethrpc.Dial(ts.URL)
|
||||
require.NoError(t, err)
|
||||
|
||||
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []network.Network{}, db)
|
||||
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, m := range blockedMethods {
|
||||
|
@ -85,7 +84,7 @@ func TestBlockedRoutesRawCall(t *testing.T) {
|
|||
gethRPCClient, err := gethrpc.Dial(ts.URL)
|
||||
require.NoError(t, err)
|
||||
|
||||
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []network.Network{}, db)
|
||||
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, m := range blockedMethods {
|
||||
|
@ -112,7 +111,7 @@ func TestUpdateUpstreamURL(t *testing.T) {
|
|||
gethRPCClient, err := gethrpc.Dial(ts.URL)
|
||||
require.NoError(t, err)
|
||||
|
||||
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: true, URL: ts.URL}, []network.Network{}, db)
|
||||
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: true, URL: ts.URL}, []params.Network{}, db)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ts.URL, c.upstreamURL)
|
||||
|
||||
|
|
|
@ -3,21 +3,9 @@ package network
|
|||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Network struct {
|
||||
ChainID uint64 `json:"chainId"`
|
||||
ChainName string `json:"chainName"`
|
||||
RPCURL string `json:"rpcUrl"`
|
||||
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"`
|
||||
}
|
||||
"github.com/status-im/status-go/params"
|
||||
)
|
||||
|
||||
const baseQuery = "SELECT chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name, native_currency_symbol, native_currency_decimals, is_test, layer, enabled FROM networks"
|
||||
|
||||
|
@ -57,15 +45,15 @@ func (nq *networksQuery) filterChainID(chainID uint64) *networksQuery {
|
|||
return nq
|
||||
}
|
||||
|
||||
func (nq *networksQuery) exec(db *sql.DB) ([]*Network, error) {
|
||||
func (nq *networksQuery) exec(db *sql.DB) ([]*params.Network, error) {
|
||||
rows, err := db.Query(nq.buf.String(), nq.args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res []*Network
|
||||
var res []*params.Network
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
network := Network{}
|
||||
network := params.Network{}
|
||||
err := rows.Scan(
|
||||
&network.ChainID, &network.ChainName, &network.RPCURL, &network.BlockExplorerURL, &network.IconURL,
|
||||
&network.NativeCurrencyName, &network.NativeCurrencySymbol, &network.NativeCurrencyDecimals,
|
||||
|
@ -90,7 +78,7 @@ func NewManager(db *sql.DB) *Manager {
|
|||
}
|
||||
}
|
||||
|
||||
func (nm *Manager) Init(networks []Network) error {
|
||||
func (nm *Manager) Init(networks []params.Network) error {
|
||||
if networks == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -110,7 +98,7 @@ func (nm *Manager) Init(networks []Network) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (nm *Manager) Upsert(network *Network) error {
|
||||
func (nm *Manager) Upsert(network *params.Network) error {
|
||||
_, err := nm.db.Exec(
|
||||
"INSERT OR REPLACE INTO networks (chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name, native_currency_symbol, native_currency_decimals, is_test, layer, enabled) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
network.ChainID, network.ChainName, network.RPCURL, network.BlockExplorerURL, network.IconURL,
|
||||
|
@ -125,7 +113,7 @@ func (nm *Manager) Delete(chainID uint64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (nm *Manager) Find(chainID uint64) *Network {
|
||||
func (nm *Manager) Find(chainID uint64) *params.Network {
|
||||
networks, err := newNetworksQuery().filterChainID(chainID).exec(nm.db)
|
||||
if len(networks) != 1 || err != nil {
|
||||
return nil
|
||||
|
@ -133,7 +121,7 @@ func (nm *Manager) Find(chainID uint64) *Network {
|
|||
return networks[0]
|
||||
}
|
||||
|
||||
func (nm *Manager) Get(onlyEnabled bool) ([]*Network, error) {
|
||||
func (nm *Manager) Get(onlyEnabled bool) ([]*params.Network, error) {
|
||||
query := newNetworksQuery()
|
||||
if onlyEnabled {
|
||||
query.filterEnabled(true)
|
||||
|
|
|
@ -9,9 +9,10 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/params"
|
||||
)
|
||||
|
||||
var initNetworks = []Network{
|
||||
var initNetworks = []params.Network{
|
||||
{
|
||||
ChainID: 1,
|
||||
ChainName: "Ethereum Mainnet",
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/nodecfg"
|
||||
"github.com/status-im/status-go/params"
|
||||
)
|
||||
|
||||
func NewSettingsAPI(db *accounts.Database) *SettingsAPI {
|
||||
|
@ -27,3 +29,11 @@ func (api *SettingsAPI) SaveSetting(ctx context.Context, typ string, val interfa
|
|||
func (api *SettingsAPI) GetSettings(ctx context.Context) (accounts.Settings, error) {
|
||||
return api.db.GetSettings()
|
||||
}
|
||||
|
||||
func (api *SettingsAPI) NodeConfig(ctx context.Context) (*params.NodeConfig, error) {
|
||||
return nodecfg.GetNodeConfig(api.db.DB())
|
||||
}
|
||||
|
||||
func (api *SettingsAPI) SaveNodeConfig(ctx context.Context, n *params.NodeConfig) error {
|
||||
return nodecfg.SaveNodeConfig(api.db.DB(), n)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/status-im/status-go/rpc/network"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/wallet/chain"
|
||||
"github.com/status-im/status-go/services/wallet/transfer"
|
||||
)
|
||||
|
@ -240,7 +240,7 @@ func (api *API) GetOpenseaAssetsByOwnerAndCollection(ctx context.Context, chainI
|
|||
return client.fetchAllAssetsByOwnerAndCollection(owner, collectionSlug, limit)
|
||||
}
|
||||
|
||||
func (api *API) AddEthereumChain(ctx context.Context, network network.Network) error {
|
||||
func (api *API) AddEthereumChain(ctx context.Context, network params.Network) error {
|
||||
log.Debug("call to AddEthereumChain")
|
||||
return api.s.rpcClient.NetworkManager.Upsert(&network)
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ func (api *API) DeleteEthereumChain(ctx context.Context, chainID uint64) error {
|
|||
return api.s.rpcClient.NetworkManager.Delete(chainID)
|
||||
}
|
||||
|
||||
func (api *API) GetEthereumChains(ctx context.Context, onlyEnabled bool) ([]*network.Network, error) {
|
||||
func (api *API) GetEthereumChains(ctx context.Context, onlyEnabled bool) ([]*params.Network, error) {
|
||||
log.Debug("call to GetEthereumChains")
|
||||
return api.s.rpcClient.NetworkManager.Get(onlyEnabled)
|
||||
}
|
||||
|
|
|
@ -24,26 +24,25 @@ import (
|
|||
|
||||
// Config represents the configuration state of a waku node.
|
||||
type Config struct {
|
||||
MaxMessageSize uint32 `toml:",omitempty"`
|
||||
SoftBlacklistedPeerIDs []string `toml:",omitempty"`
|
||||
Host string `toml:",omitempty"`
|
||||
Port int `toml:",omitempty"`
|
||||
PersistPeers bool `toml:",omitempty"`
|
||||
PeerExchange bool `toml:",omitempty"`
|
||||
KeepAliveInterval int `toml:",omitempty"`
|
||||
MinPeersForRelay int `toml:",omitempty"`
|
||||
LightClient bool `toml:",omitempty"`
|
||||
RelayNodes []string `toml:",omitempty"`
|
||||
StoreNodes []string `toml:",omitempty"`
|
||||
FilterNodes []string `toml:",omitempty"`
|
||||
LightpushNodes []string `toml:",omitempty"`
|
||||
Rendezvous bool `toml:",omitempty"`
|
||||
WakuRendezvousNodes []string `toml:",omitempty"`
|
||||
DiscV5BootstrapNodes []string `toml:",omitempty"`
|
||||
EnableDiscV5 bool `toml:",omitempty"`
|
||||
DiscoveryLimit int `toml:",omitempty"`
|
||||
AutoUpdate bool `toml:",omitempty"`
|
||||
UDPPort int `toml:",omitempty"`
|
||||
MaxMessageSize uint32 `toml:",omitempty"`
|
||||
Host string `toml:",omitempty"`
|
||||
Port int `toml:",omitempty"`
|
||||
PersistPeers bool `toml:",omitempty"`
|
||||
PeerExchange bool `toml:",omitempty"`
|
||||
KeepAliveInterval int `toml:",omitempty"`
|
||||
MinPeersForRelay int `toml:",omitempty"`
|
||||
LightClient bool `toml:",omitempty"`
|
||||
RelayNodes []string `toml:",omitempty"`
|
||||
StoreNodes []string `toml:",omitempty"`
|
||||
FilterNodes []string `toml:",omitempty"`
|
||||
LightpushNodes []string `toml:",omitempty"`
|
||||
Rendezvous bool `toml:",omitempty"`
|
||||
WakuRendezvousNodes []string `toml:",omitempty"`
|
||||
DiscV5BootstrapNodes []string `toml:",omitempty"`
|
||||
EnableDiscV5 bool `toml:",omitempty"`
|
||||
DiscoveryLimit int `toml:",omitempty"`
|
||||
AutoUpdate bool `toml:",omitempty"`
|
||||
UDPPort int `toml:",omitempty"`
|
||||
}
|
||||
|
||||
var DefaultConfig = Config{
|
||||
|
|
|
@ -80,11 +80,10 @@ const messageQueueLimit = 1024
|
|||
const requestTimeout = 5 * time.Second
|
||||
|
||||
type settings struct {
|
||||
LightClient bool // Indicates if the node is a light client
|
||||
MinPeersForRelay int // Indicates the minimum number of peers required for using Relay Protocol instead of Lightpush
|
||||
MaxMsgSize uint32 // Maximal message length allowed by the waku node
|
||||
EnableConfirmations bool // Enable sending message confirmations
|
||||
SoftBlacklistedPeerIDs map[string]bool // SoftBlacklistedPeerIDs is a list of peer ids that we want to keep connected but silently drop any envelope from
|
||||
LightClient bool // Indicates if the node is a light client
|
||||
MinPeersForRelay int // Indicates the minimum number of peers required for using Relay Protocol instead of Lightpush
|
||||
MaxMsgSize uint32 // Maximal message length allowed by the waku node
|
||||
EnableConfirmations bool // Enable sending message confirmations
|
||||
}
|
||||
|
||||
// Waku represents a dark communication interface through the Ethereum
|
||||
|
@ -156,10 +155,9 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger, appdb *sql.DB) (*Waku,
|
|||
}
|
||||
|
||||
waku.settings = settings{
|
||||
MaxMsgSize: cfg.MaxMessageSize,
|
||||
SoftBlacklistedPeerIDs: make(map[string]bool),
|
||||
LightClient: cfg.LightClient,
|
||||
MinPeersForRelay: cfg.MinPeersForRelay,
|
||||
MaxMsgSize: cfg.MaxMessageSize,
|
||||
LightClient: cfg.LightClient,
|
||||
MinPeersForRelay: cfg.MinPeersForRelay,
|
||||
}
|
||||
|
||||
waku.filters = common.NewFilters()
|
||||
|
|
Loading…
Reference in New Issue