2016-04-14 19:18:24 +03:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-11-06 00:57:57 +03:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2016-02-05 13:45:36 +02:00
|
|
|
"fmt"
|
2023-07-02 14:21:16 +03:00
|
|
|
"net"
|
2015-11-06 00:57:57 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-02-02 19:06:43 +02:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2015-11-06 00:57:57 +03:00
|
|
|
|
2016-02-02 19:06:43 +02:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2015-11-06 00:57:57 +03:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2017-02-22 15:10:07 +03:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2017-04-12 17:27:23 +03:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2018-07-31 12:16:14 +03:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2015-11-06 00:57:57 +03:00
|
|
|
)
|
|
|
|
|
2017-08-06 19:43:43 +03:00
|
|
|
const (
|
2016-08-15 19:38:32 +03:00
|
|
|
datadirPrivateKey = "nodekey" // Path within the datadir to the node's private key
|
2022-03-07 10:30:27 +03:00
|
|
|
datadirJWTKey = "jwtsecret" // Path within the datadir to the node's jwt secret
|
2016-08-15 19:38:32 +03:00
|
|
|
datadirDefaultKeyStore = "keystore" // Path within the datadir to the keystore
|
|
|
|
datadirStaticNodes = "static-nodes.json" // Path within the datadir to the static node list
|
|
|
|
datadirTrustedNodes = "trusted-nodes.json" // Path within the datadir to the trusted node list
|
|
|
|
datadirNodeDatabase = "nodes" // Path within the datadir to store the node infos
|
2015-11-06 00:57:57 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents a small collection of configuration values to fine tune the
|
|
|
|
// P2P network layer of a protocol stack. These values can be further extended by
|
|
|
|
// all registered services.
|
|
|
|
type Config struct {
|
2016-08-18 14:28:17 +03:00
|
|
|
// Name sets the instance name of the node. It must not contain the / character and is
|
|
|
|
// used in the devp2p node identifier. The instance name of geth is "geth". If no
|
|
|
|
// value is specified, the basename of the current executable is used.
|
2017-04-12 17:27:23 +03:00
|
|
|
Name string `toml:"-"`
|
2016-08-18 14:28:17 +03:00
|
|
|
|
|
|
|
// UserIdent, if set, is used as an additional component in the devp2p node identifier.
|
2017-04-12 17:27:23 +03:00
|
|
|
UserIdent string `toml:",omitempty"`
|
2016-08-18 14:28:17 +03:00
|
|
|
|
|
|
|
// Version should be set to the version number of the program. It is used
|
|
|
|
// in the devp2p node identifier.
|
2017-04-12 17:27:23 +03:00
|
|
|
Version string `toml:"-"`
|
2016-08-18 14:28:17 +03:00
|
|
|
|
2015-11-06 00:57:57 +03:00
|
|
|
// DataDir is the file system folder the node should use for any data storage
|
|
|
|
// requirements. The configured data directory will not be directly shared with
|
|
|
|
// registered services, instead those can use utility methods to create/access
|
|
|
|
// databases or flat files. This enables ephemeral nodes which can fully reside
|
|
|
|
// in memory.
|
|
|
|
DataDir string
|
|
|
|
|
2017-04-12 17:27:23 +03:00
|
|
|
// Configuration of peer-to-peer networking.
|
|
|
|
P2P p2p.Config
|
|
|
|
|
2016-08-15 19:38:32 +03:00
|
|
|
// KeyStoreDir is the file system folder that contains private keys. The directory can
|
|
|
|
// be specified as a relative path, in which case it is resolved relative to the
|
|
|
|
// current directory.
|
|
|
|
//
|
|
|
|
// If KeyStoreDir is empty, the default location is the "keystore" subdirectory of
|
|
|
|
// DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory
|
|
|
|
// is created by New and destroyed when the node is stopped.
|
2017-04-12 17:27:23 +03:00
|
|
|
KeyStoreDir string `toml:",omitempty"`
|
2016-08-15 19:38:32 +03:00
|
|
|
|
2023-05-10 11:42:55 +03:00
|
|
|
// ExternalSigner specifies an external URI for a clef-type signer.
|
2020-06-08 10:52:18 +03:00
|
|
|
ExternalSigner string `toml:",omitempty"`
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 13:23:57 +03:00
|
|
|
|
2016-08-15 19:38:32 +03:00
|
|
|
// UseLightweightKDF lowers the memory and CPU requirements of the key store
|
|
|
|
// scrypt KDF at the expense of security.
|
2017-04-12 17:27:23 +03:00
|
|
|
UseLightweightKDF bool `toml:",omitempty"`
|
2016-08-15 19:38:32 +03:00
|
|
|
|
2019-04-04 14:03:10 +03:00
|
|
|
// InsecureUnlockAllowed allows user to unlock accounts in unsafe http environment.
|
|
|
|
InsecureUnlockAllowed bool `toml:",omitempty"`
|
|
|
|
|
2017-04-20 14:01:51 +03:00
|
|
|
// NoUSB disables hardware wallet monitoring and connectivity.
|
2021-08-24 15:10:52 +03:00
|
|
|
// Deprecated: USB monitoring is disabled by default and must be enabled explicitly.
|
2017-04-20 14:01:51 +03:00
|
|
|
NoUSB bool `toml:",omitempty"`
|
|
|
|
|
2021-03-03 12:50:30 +03:00
|
|
|
// DirectBroadcast enable directly broadcast mined block to all peers
|
|
|
|
DirectBroadcast bool `toml:",omitempty"`
|
|
|
|
|
2022-07-05 06:14:21 +03:00
|
|
|
// DisableSnapProtocol disable the snap protocol
|
|
|
|
DisableSnapProtocol bool `toml:",omitempty"`
|
|
|
|
|
2021-02-23 10:12:41 +03:00
|
|
|
// RangeLimit enable 5000 blocks limit when handle range query
|
|
|
|
RangeLimit bool `toml:",omitempty"`
|
|
|
|
|
2021-01-13 13:14:36 +03:00
|
|
|
// USB enables hardware wallet monitoring and connectivity.
|
|
|
|
USB bool `toml:",omitempty"`
|
|
|
|
|
2023-05-10 11:42:55 +03:00
|
|
|
// SmartCardDaemonPath is the path to the smartcard daemon's socket.
|
2019-05-31 12:30:28 +03:00
|
|
|
SmartCardDaemonPath string `toml:",omitempty"`
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// IPCPath is the requested location to place the IPC endpoint. If the path is
|
2016-02-02 19:06:43 +02:00
|
|
|
// a simple file name, it is placed inside the data directory (or on the root
|
|
|
|
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
|
|
|
|
// relative), then that specific path is enforced. An empty path disables IPC.
|
2020-07-06 23:09:30 +03:00
|
|
|
IPCPath string
|
2016-02-05 13:45:36 +02:00
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// HTTPHost is the host interface on which to start the HTTP RPC server. If this
|
2016-02-05 13:45:36 +02:00
|
|
|
// field is empty, no HTTP API endpoint will be started.
|
2020-07-06 23:09:30 +03:00
|
|
|
HTTPHost string
|
2016-02-05 13:45:36 +02:00
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// HTTPPort is the TCP port number on which to start the HTTP RPC server. The
|
2016-02-05 13:45:36 +02:00
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful
|
|
|
|
// for ephemeral nodes).
|
2017-04-12 17:27:23 +03:00
|
|
|
HTTPPort int `toml:",omitempty"`
|
2016-02-05 13:45:36 +02:00
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
|
2016-02-05 13:45:36 +02:00
|
|
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
|
|
|
// useless for custom HTTP clients.
|
2017-04-13 00:04:14 +03:00
|
|
|
HTTPCors []string `toml:",omitempty"`
|
2016-02-05 13:45:36 +02:00
|
|
|
|
2018-02-12 15:52:07 +03:00
|
|
|
// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
|
|
|
|
// This is by default {'localhost'}. Using this prevents attacks like
|
|
|
|
// DNS rebinding, which bypasses SOP by simply masquerading as being within the same
|
|
|
|
// origin. These attacks do not utilize CORS, since they are not cross-domain.
|
|
|
|
// By explicitly checking the Host-header, the server will not allow requests
|
|
|
|
// made against the server with a malicious host domain.
|
|
|
|
// Requests using ip address directly are not affected
|
|
|
|
HTTPVirtualHosts []string `toml:",omitempty"`
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// HTTPModules is a list of API modules to expose via the HTTP RPC interface.
|
2016-02-05 13:45:36 +02:00
|
|
|
// If the module list is empty, all RPC API endpoints designated public will be
|
|
|
|
// exposed.
|
2020-07-06 23:09:30 +03:00
|
|
|
HTTPModules []string
|
2016-02-05 15:08:48 +02:00
|
|
|
|
2018-07-31 12:16:14 +03:00
|
|
|
// HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC
|
|
|
|
// interface.
|
|
|
|
HTTPTimeouts rpc.HTTPTimeouts
|
|
|
|
|
2021-02-02 12:05:46 +03:00
|
|
|
// HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
|
|
|
|
HTTPPathPrefix string `toml:",omitempty"`
|
|
|
|
|
2022-03-17 18:20:03 +03:00
|
|
|
// AuthAddr is the listening address on which authenticated APIs are provided.
|
|
|
|
AuthAddr string `toml:",omitempty"`
|
2022-03-09 16:45:39 +03:00
|
|
|
|
|
|
|
// AuthPort is the port number on which authenticated APIs are provided.
|
|
|
|
AuthPort int `toml:",omitempty"`
|
|
|
|
|
2022-03-17 18:20:03 +03:00
|
|
|
// AuthVirtualHosts is the list of virtual hostnames which are allowed on incoming requests
|
|
|
|
// for the authenticated api. This is by default {'localhost'}.
|
|
|
|
AuthVirtualHosts []string `toml:",omitempty"`
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// WSHost is the host interface on which to start the websocket RPC server. If
|
2016-02-05 15:08:48 +02:00
|
|
|
// this field is empty, no websocket API endpoint will be started.
|
2020-07-06 23:09:30 +03:00
|
|
|
WSHost string
|
2016-02-05 15:08:48 +02:00
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// WSPort is the TCP port number on which to start the websocket RPC server. The
|
2016-02-05 15:08:48 +02:00
|
|
|
// default zero value is/ valid and will pick a port number randomly (useful for
|
|
|
|
// ephemeral nodes).
|
2017-04-12 17:27:23 +03:00
|
|
|
WSPort int `toml:",omitempty"`
|
2016-02-05 15:08:48 +02:00
|
|
|
|
2021-02-02 12:05:46 +03:00
|
|
|
// WSPathPrefix specifies a path prefix on which ws-rpc is to be served.
|
|
|
|
WSPathPrefix string `toml:",omitempty"`
|
|
|
|
|
2016-03-14 10:38:54 +02:00
|
|
|
// WSOrigins is the list of domain to accept websocket requests from. Please be
|
2016-02-09 13:24:42 +02:00
|
|
|
// aware that the server can only act upon the HTTP request the client sends and
|
|
|
|
// cannot verify the validity of the request header.
|
2017-04-13 00:04:14 +03:00
|
|
|
WSOrigins []string `toml:",omitempty"`
|
2016-02-05 15:08:48 +02:00
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// WSModules is a list of API modules to expose via the websocket RPC interface.
|
2016-02-05 15:08:48 +02:00
|
|
|
// If the module list is empty, all RPC API endpoints designated public will be
|
|
|
|
// exposed.
|
2020-07-06 23:09:30 +03:00
|
|
|
WSModules []string
|
2017-09-25 11:08:07 +03:00
|
|
|
|
|
|
|
// WSExposeAll exposes all API modules via the WebSocket RPC interface rather
|
|
|
|
// than just the public ones.
|
|
|
|
//
|
|
|
|
// *WARNING* Only set this if the node is running in a trusted network, exposing
|
|
|
|
// private APIs to untrusted users is a major security risk.
|
|
|
|
WSExposeAll bool `toml:",omitempty"`
|
2017-12-01 14:49:04 +03:00
|
|
|
|
2019-04-04 14:03:10 +03:00
|
|
|
// GraphQLCors is the Cross-Origin Resource Sharing header to send to requesting
|
|
|
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
|
|
|
// useless for custom HTTP clients.
|
|
|
|
GraphQLCors []string `toml:",omitempty"`
|
|
|
|
|
|
|
|
// GraphQLVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
|
|
|
|
// This is by default {'localhost'}. Using this prevents attacks like
|
|
|
|
// DNS rebinding, which bypasses SOP by simply masquerading as being within the same
|
|
|
|
// origin. These attacks do not utilize CORS, since they are not cross-domain.
|
|
|
|
// By explicitly checking the Host-header, the server will not allow requests
|
|
|
|
// made against the server with a malicious host domain.
|
|
|
|
// Requests using ip address directly are not affected
|
|
|
|
GraphQLVirtualHosts []string `toml:",omitempty"`
|
|
|
|
|
2017-12-01 14:49:04 +03:00
|
|
|
// Logger is a custom logger to use with the p2p.Server.
|
2018-02-12 15:52:07 +03:00
|
|
|
Logger log.Logger `toml:",omitempty"`
|
2018-12-07 16:43:27 +03:00
|
|
|
|
2020-05-20 06:46:45 +03:00
|
|
|
LogConfig *LogConfig `toml:",omitempty"`
|
|
|
|
|
2018-12-07 16:43:27 +03:00
|
|
|
oldGethResourceWarning bool
|
2021-02-23 15:09:19 +03:00
|
|
|
|
|
|
|
// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
|
|
|
|
AllowUnprotectedTxs bool `toml:",omitempty"`
|
2023-02-03 10:53:36 +03:00
|
|
|
|
|
|
|
// EnableDoubleSignMonitor is a flag that whether to enable the double signature checker
|
|
|
|
EnableDoubleSignMonitor bool `toml:",omitempty"`
|
2023-04-10 13:36:45 +03:00
|
|
|
|
2023-05-11 09:45:15 +03:00
|
|
|
// EnableMaliciousVoteMonitor is a flag that whether to enable the malicious vote checker
|
|
|
|
EnableMaliciousVoteMonitor bool `toml:",omitempty"`
|
|
|
|
|
2023-04-10 13:36:45 +03:00
|
|
|
// BLSPasswordFile is the file that contains BLS wallet password.
|
|
|
|
BLSPasswordFile string `toml:",omitempty"`
|
|
|
|
|
|
|
|
// BLSWalletDir is the file system folder of BLS wallet. The directory can
|
|
|
|
// be specified as a relative path, in which case it is resolved relative to the
|
|
|
|
// current directory.
|
|
|
|
BLSWalletDir string `toml:",omitempty"`
|
|
|
|
|
|
|
|
// VoteJournalDir is the directory to store votes in the fast finality feature.
|
|
|
|
VoteJournalDir string `toml:",omitempty"`
|
2023-08-23 12:46:08 +03:00
|
|
|
|
rpc: add limit for batch request items and response size (#26681)
This PR adds server-side limits for JSON-RPC batch requests. Before this change, batches
were limited only by processing time. The server would pick calls from the batch and
answer them until the response timeout occurred, then stop processing the remaining batch
items.
Here, we are adding two additional limits which can be configured:
- the 'item limit': batches can have at most N items
- the 'response size limit': batches can contain at most X response bytes
These limits are optional in package rpc. In Geth, we set a default limit of 1000 items
and 25MB response size.
When a batch goes over the limit, an error response is returned to the client. However,
doing this correctly isn't always possible. In JSON-RPC, only method calls with a valid
`id` can be responded to. Since batches may also contain non-call messages or
notifications, the best effort thing we can do to report an error with the batch itself is
reporting the limit violation as an error for the first method call in the batch. If a batch is
too large, but contains only notifications and responses, the error will be reported with
a null `id`.
The RPC client was also changed so it can deal with errors resulting from too large
batches. An older client connected to the server code in this PR could get stuck
until the request timeout occurred when the batch is too large. **Upgrading to a version
of the RPC client containing this change is strongly recommended to avoid timeout issues.**
For some weird reason, when writing the original client implementation, @fjl worked off of
the assumption that responses could be distributed across batches arbitrarily. So for a
batch request containing requests `[A B C]`, the server could respond with `[A B C]` but
also with `[A B] [C]` or even `[A] [B] [C]` and it wouldn't make a difference to the
client.
So in the implementation of BatchCallContext, the client waited for all requests in the
batch individually. If the server didn't respond to some of the requests in the batch, the
client would eventually just time out (if a context was used).
With the addition of batch limits into the server, we anticipate that people will hit this
kind of error way more often. To handle this properly, the client now waits for a single
response batch and expects it to contain all responses to the requests.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2023-06-13 14:38:58 +03:00
|
|
|
// BatchRequestLimit is the maximum number of requests in a batch.
|
|
|
|
BatchRequestLimit int `toml:",omitempty"`
|
|
|
|
|
|
|
|
// BatchResponseMaxSize is the maximum number of bytes returned from a batched rpc call.
|
|
|
|
BatchResponseMaxSize int `toml:",omitempty"`
|
|
|
|
|
2022-09-02 18:40:41 +03:00
|
|
|
// JWTSecret is the path to the hex-encoded jwt secret.
|
2022-03-07 10:30:27 +03:00
|
|
|
JWTSecret string `toml:",omitempty"`
|
2023-02-02 14:52:19 +03:00
|
|
|
|
|
|
|
// EnablePersonal enables the deprecated personal namespace.
|
|
|
|
EnablePersonal bool `toml:"-"`
|
2023-02-09 11:48:34 +03:00
|
|
|
|
|
|
|
DBEngine string `toml:",omitempty"`
|
2024-03-21 08:06:48 +03:00
|
|
|
|
|
|
|
Instance int `toml:",omitempty"`
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
2016-02-02 19:06:43 +02:00
|
|
|
// account the set data folders as well as the designated platform we're currently
|
|
|
|
// running on.
|
2016-02-09 13:24:42 +02:00
|
|
|
func (c *Config) IPCEndpoint() string {
|
2016-02-02 19:06:43 +02:00
|
|
|
// Short circuit if IPC has not been enabled
|
2016-02-09 13:24:42 +02:00
|
|
|
if c.IPCPath == "" {
|
2016-02-02 19:06:43 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// On windows we can only use plain top-level pipes
|
|
|
|
if runtime.GOOS == "windows" {
|
2016-02-09 13:24:42 +02:00
|
|
|
if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) {
|
|
|
|
return c.IPCPath
|
2016-02-02 19:06:43 +02:00
|
|
|
}
|
2016-02-09 13:24:42 +02:00
|
|
|
return `\\.\pipe\` + c.IPCPath
|
2016-02-02 19:06:43 +02:00
|
|
|
}
|
|
|
|
// Resolve names into the data directory full paths otherwise
|
2016-02-09 13:24:42 +02:00
|
|
|
if filepath.Base(c.IPCPath) == c.IPCPath {
|
2016-02-02 19:06:43 +02:00
|
|
|
if c.DataDir == "" {
|
2016-02-09 13:24:42 +02:00
|
|
|
return filepath.Join(os.TempDir(), c.IPCPath)
|
2016-02-02 19:06:43 +02:00
|
|
|
}
|
2016-02-09 13:24:42 +02:00
|
|
|
return filepath.Join(c.DataDir, c.IPCPath)
|
2016-02-02 19:06:43 +02:00
|
|
|
}
|
2016-02-09 13:24:42 +02:00
|
|
|
return c.IPCPath
|
2016-02-02 19:06:43 +02:00
|
|
|
}
|
|
|
|
|
2016-08-18 14:28:17 +03:00
|
|
|
// NodeDB returns the path to the discovery node database.
|
|
|
|
func (c *Config) NodeDB() string {
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return "" // ephemeral
|
|
|
|
}
|
cmd, dashboard, log: log collection and exploration (#17097)
* cmd, dashboard, internal, log, node: logging feature
* cmd, dashboard, internal, log: requested changes
* dashboard, vendor: gofmt, govendor, use vendored file watcher
* dashboard, log: gofmt -s -w, goimports
* dashboard, log: gosimple
2018-07-11 10:59:04 +03:00
|
|
|
return c.ResolvePath(datadirNodeDatabase)
|
2016-08-18 14:28:17 +03:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// DefaultIPCEndpoint returns the IPC path used by default.
|
2016-08-18 14:28:17 +03:00
|
|
|
func DefaultIPCEndpoint(clientIdentifier string) string {
|
|
|
|
if clientIdentifier == "" {
|
|
|
|
clientIdentifier = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
|
|
|
|
if clientIdentifier == "" {
|
|
|
|
panic("empty executable name")
|
|
|
|
}
|
|
|
|
}
|
2016-09-16 12:53:50 +03:00
|
|
|
config := &Config{DataDir: DefaultDataDir(), IPCPath: clientIdentifier + ".ipc"}
|
2016-02-09 13:24:42 +02:00
|
|
|
return config.IPCEndpoint()
|
2016-02-02 19:06:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// HTTPEndpoint resolves an HTTP endpoint based on the configured host interface
|
2016-02-05 13:45:36 +02:00
|
|
|
// and port parameters.
|
2016-02-09 13:24:42 +02:00
|
|
|
func (c *Config) HTTPEndpoint() string {
|
|
|
|
if c.HTTPHost == "" {
|
2016-02-05 13:45:36 +02:00
|
|
|
return ""
|
|
|
|
}
|
2023-07-02 14:21:16 +03:00
|
|
|
return net.JoinHostPort(c.HTTPHost, fmt.Sprintf("%d", c.HTTPPort))
|
2016-02-05 13:45:36 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
|
|
|
|
func DefaultHTTPEndpoint() string {
|
2022-03-07 10:30:27 +03:00
|
|
|
config := &Config{HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort, AuthPort: DefaultAuthPort}
|
2016-02-09 13:24:42 +02:00
|
|
|
return config.HTTPEndpoint()
|
2016-02-05 13:45:36 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 16:32:02 +03:00
|
|
|
// WSEndpoint resolves a websocket endpoint based on the configured host interface
|
2016-02-05 15:08:48 +02:00
|
|
|
// and port parameters.
|
2016-02-09 13:24:42 +02:00
|
|
|
func (c *Config) WSEndpoint() string {
|
|
|
|
if c.WSHost == "" {
|
2016-02-05 15:08:48 +02:00
|
|
|
return ""
|
|
|
|
}
|
2023-07-02 14:21:16 +03:00
|
|
|
return net.JoinHostPort(c.WSHost, fmt.Sprintf("%d", c.WSPort))
|
2016-02-05 15:08:48 +02:00
|
|
|
}
|
|
|
|
|
2016-02-09 13:24:42 +02:00
|
|
|
// DefaultWSEndpoint returns the websocket endpoint used by default.
|
|
|
|
func DefaultWSEndpoint() string {
|
2016-09-16 12:53:50 +03:00
|
|
|
config := &Config{WSHost: DefaultWSHost, WSPort: DefaultWSPort}
|
2016-02-09 13:24:42 +02:00
|
|
|
return config.WSEndpoint()
|
2016-02-05 15:08:48 +02:00
|
|
|
}
|
|
|
|
|
2019-04-04 14:03:10 +03:00
|
|
|
// ExtRPCEnabled returns the indicator whether node enables the external
|
|
|
|
// RPC(http, ws or graphql).
|
|
|
|
func (c *Config) ExtRPCEnabled() bool {
|
2020-08-03 20:40:46 +03:00
|
|
|
return c.HTTPHost != "" || c.WSHost != ""
|
2019-04-04 14:03:10 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 14:28:17 +03:00
|
|
|
// NodeName returns the devp2p node identifier.
|
|
|
|
func (c *Config) NodeName() string {
|
|
|
|
name := c.name()
|
|
|
|
// Backwards compatibility: previous versions used title-cased "Geth", keep that.
|
|
|
|
if name == "geth" || name == "geth-testnet" {
|
|
|
|
name = "Geth"
|
|
|
|
}
|
|
|
|
if c.UserIdent != "" {
|
|
|
|
name += "/" + c.UserIdent
|
|
|
|
}
|
|
|
|
if c.Version != "" {
|
|
|
|
name += "/v" + c.Version
|
|
|
|
}
|
2017-04-05 22:51:01 +03:00
|
|
|
name += "/" + runtime.GOOS + "-" + runtime.GOARCH
|
2016-08-18 14:28:17 +03:00
|
|
|
name += "/" + runtime.Version()
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) name() string {
|
|
|
|
if c.Name == "" {
|
|
|
|
progname := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
|
|
|
|
if progname == "" {
|
|
|
|
panic("empty executable name, set Config.Name")
|
|
|
|
}
|
|
|
|
return progname
|
|
|
|
}
|
|
|
|
return c.Name
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:03:24 +03:00
|
|
|
// These resources are resolved differently for "geth" instances.
|
2016-08-18 14:28:17 +03:00
|
|
|
var isOldGethResource = map[string]bool{
|
|
|
|
"chaindata": true,
|
|
|
|
"nodes": true,
|
|
|
|
"nodekey": true,
|
2018-12-07 16:43:27 +03:00
|
|
|
"static-nodes.json": false, // no warning for these because they have their
|
|
|
|
"trusted-nodes.json": false, // own separate warning.
|
2016-08-18 14:28:17 +03:00
|
|
|
}
|
|
|
|
|
cmd, dashboard, log: log collection and exploration (#17097)
* cmd, dashboard, internal, log, node: logging feature
* cmd, dashboard, internal, log: requested changes
* dashboard, vendor: gofmt, govendor, use vendored file watcher
* dashboard, log: gofmt -s -w, goimports
* dashboard, log: gosimple
2018-07-11 10:59:04 +03:00
|
|
|
// ResolvePath resolves path in the instance directory.
|
|
|
|
func (c *Config) ResolvePath(path string) string {
|
2016-08-18 14:28:17 +03:00
|
|
|
if filepath.IsAbs(path) {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
// Backwards-compatibility: ensure that data directory files created
|
|
|
|
// by geth 1.4 are used if they exist.
|
2018-12-07 16:43:27 +03:00
|
|
|
if warn, isOld := isOldGethResource[path]; isOld {
|
2016-08-18 14:28:17 +03:00
|
|
|
oldpath := ""
|
2018-12-07 16:43:27 +03:00
|
|
|
if c.name() == "geth" {
|
2016-08-18 14:28:17 +03:00
|
|
|
oldpath = filepath.Join(c.DataDir, path)
|
|
|
|
}
|
|
|
|
if oldpath != "" && common.FileExist(oldpath) {
|
2022-10-12 11:50:12 +03:00
|
|
|
if warn && !c.oldGethResourceWarning {
|
|
|
|
c.oldGethResourceWarning = true
|
|
|
|
log.Warn("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir.", "file", oldpath)
|
2018-12-07 16:43:27 +03:00
|
|
|
}
|
2016-08-18 14:28:17 +03:00
|
|
|
return oldpath
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 19:03:24 +03:00
|
|
|
return filepath.Join(c.instanceDir(), path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) instanceDir() string {
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return filepath.Join(c.DataDir, c.name())
|
2016-08-18 14:28:17 +03:00
|
|
|
}
|
|
|
|
|
2015-11-06 00:57:57 +03:00
|
|
|
// NodeKey retrieves the currently configured private key of the node, checking
|
|
|
|
// first any manually set key, falling back to the one found in the configured
|
|
|
|
// data folder. If no key can be found, a new one is generated.
|
|
|
|
func (c *Config) NodeKey() *ecdsa.PrivateKey {
|
2016-08-18 14:28:17 +03:00
|
|
|
// Use any specifically configured key.
|
2017-04-12 17:27:23 +03:00
|
|
|
if c.P2P.PrivateKey != nil {
|
|
|
|
return c.P2P.PrivateKey
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
2016-08-18 14:28:17 +03:00
|
|
|
// Generate ephemeral key if no datadir is being used.
|
2015-11-06 00:57:57 +03:00
|
|
|
if c.DataDir == "" {
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
2017-02-22 15:10:07 +03:00
|
|
|
log.Crit(fmt.Sprintf("Failed to generate ephemeral node key: %v", err))
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
|
|
|
return key
|
|
|
|
}
|
2016-08-18 14:28:17 +03:00
|
|
|
|
cmd, dashboard, log: log collection and exploration (#17097)
* cmd, dashboard, internal, log, node: logging feature
* cmd, dashboard, internal, log: requested changes
* dashboard, vendor: gofmt, govendor, use vendored file watcher
* dashboard, log: gofmt -s -w, goimports
* dashboard, log: gosimple
2018-07-11 10:59:04 +03:00
|
|
|
keyfile := c.ResolvePath(datadirPrivateKey)
|
2015-11-06 00:57:57 +03:00
|
|
|
if key, err := crypto.LoadECDSA(keyfile); err == nil {
|
|
|
|
return key
|
|
|
|
}
|
2016-08-18 14:28:17 +03:00
|
|
|
// No persistent key found, generate and store a new one.
|
2015-11-06 00:57:57 +03:00
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
2017-02-22 15:10:07 +03:00
|
|
|
log.Crit(fmt.Sprintf("Failed to generate node key: %v", err))
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
2016-08-18 14:28:17 +03:00
|
|
|
instanceDir := filepath.Join(c.DataDir, c.name())
|
|
|
|
if err := os.MkdirAll(instanceDir, 0700); err != nil {
|
2017-02-22 15:10:07 +03:00
|
|
|
log.Error(fmt.Sprintf("Failed to persist node key: %v", err))
|
2016-08-18 14:28:17 +03:00
|
|
|
return key
|
|
|
|
}
|
|
|
|
keyfile = filepath.Join(instanceDir, datadirPrivateKey)
|
2015-11-06 00:57:57 +03:00
|
|
|
if err := crypto.SaveECDSA(keyfile, key); err != nil {
|
2017-02-22 15:10:07 +03:00
|
|
|
log.Error(fmt.Sprintf("Failed to persist node key: %v", err))
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
|
2023-05-10 11:42:55 +03:00
|
|
|
// checkLegacyFiles inspects the datadir for signs of legacy static-nodes
|
2022-10-12 11:50:12 +03:00
|
|
|
// and trusted-nodes files. If they exist it raises an error.
|
|
|
|
func (c *Config) checkLegacyFiles() {
|
|
|
|
c.checkLegacyFile(c.ResolvePath(datadirStaticNodes))
|
|
|
|
c.checkLegacyFile(c.ResolvePath(datadirTrustedNodes))
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
|
|
|
|
2022-10-12 11:50:12 +03:00
|
|
|
// checkLegacyFile will only raise an error if a file at the given path exists.
|
|
|
|
func (c *Config) checkLegacyFile(path string) {
|
2015-11-06 00:57:57 +03:00
|
|
|
// Short circuit if no node config is present
|
|
|
|
if c.DataDir == "" {
|
2022-10-12 11:50:12 +03:00
|
|
|
return
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
2022-10-12 11:50:12 +03:00
|
|
|
return
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
2022-10-12 11:50:12 +03:00
|
|
|
logger := c.Logger
|
|
|
|
if logger == nil {
|
|
|
|
logger = log.Root()
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
2022-10-12 11:50:12 +03:00
|
|
|
switch fname := filepath.Base(path); fname {
|
|
|
|
case "static-nodes.json":
|
|
|
|
logger.Error("The static-nodes.json file is deprecated and ignored. Use P2P.StaticNodes in config.toml instead.")
|
|
|
|
case "trusted-nodes.json":
|
|
|
|
logger.Error("The trusted-nodes.json file is deprecated and ignored. Use P2P.TrustedNodes in config.toml instead.")
|
|
|
|
default:
|
|
|
|
// We shouldn't wind up here, but better print something just in case.
|
|
|
|
logger.Error("Ignoring deprecated file.", "file", path)
|
2015-11-06 00:57:57 +03:00
|
|
|
}
|
|
|
|
}
|
2016-08-15 19:38:32 +03:00
|
|
|
|
2021-08-25 23:34:22 +03:00
|
|
|
// KeyDirConfig determines the settings for keydirectory
|
|
|
|
func (c *Config) KeyDirConfig() (string, error) {
|
2017-02-07 13:47:34 +03:00
|
|
|
var (
|
2017-11-20 19:39:53 +03:00
|
|
|
keydir string
|
|
|
|
err error
|
2017-02-07 13:47:34 +03:00
|
|
|
)
|
2016-08-15 19:38:32 +03:00
|
|
|
switch {
|
2017-11-20 19:39:53 +03:00
|
|
|
case filepath.IsAbs(c.KeyStoreDir):
|
|
|
|
keydir = c.KeyStoreDir
|
|
|
|
case c.DataDir != "":
|
|
|
|
if c.KeyStoreDir == "" {
|
|
|
|
keydir = filepath.Join(c.DataDir, datadirDefaultKeyStore)
|
2016-08-15 19:38:32 +03:00
|
|
|
} else {
|
2017-11-20 19:39:53 +03:00
|
|
|
keydir, err = filepath.Abs(c.KeyStoreDir)
|
2016-08-15 19:38:32 +03:00
|
|
|
}
|
2017-11-20 19:39:53 +03:00
|
|
|
case c.KeyStoreDir != "":
|
|
|
|
keydir, err = filepath.Abs(c.KeyStoreDir)
|
|
|
|
}
|
2021-08-25 23:34:22 +03:00
|
|
|
return keydir, err
|
2017-11-20 19:39:53 +03:00
|
|
|
}
|
|
|
|
|
2023-04-27 13:57:29 +03:00
|
|
|
// GetKeyStoreDir retrieves the key directory and will create
|
2021-08-25 23:34:22 +03:00
|
|
|
// and ephemeral one if necessary.
|
2023-04-27 13:57:29 +03:00
|
|
|
func (c *Config) GetKeyStoreDir() (string, bool, error) {
|
|
|
|
keydir, err := c.KeyDirConfig()
|
2021-08-25 23:34:22 +03:00
|
|
|
if err != nil {
|
|
|
|
return "", false, err
|
|
|
|
}
|
|
|
|
isEphemeral := false
|
2017-11-20 19:39:53 +03:00
|
|
|
if keydir == "" {
|
2016-08-15 19:38:32 +03:00
|
|
|
// There is no datadir.
|
2022-05-16 12:59:35 +03:00
|
|
|
keydir, err = os.MkdirTemp("", "go-ethereum-keystore")
|
2021-08-25 23:34:22 +03:00
|
|
|
isEphemeral = true
|
2016-08-15 19:38:32 +03:00
|
|
|
}
|
2017-11-20 19:39:53 +03:00
|
|
|
|
2016-08-15 19:38:32 +03:00
|
|
|
if err != nil {
|
2021-08-25 23:34:22 +03:00
|
|
|
return "", false, err
|
2016-08-15 19:38:32 +03:00
|
|
|
}
|
|
|
|
if err := os.MkdirAll(keydir, 0700); err != nil {
|
2021-08-25 23:34:22 +03:00
|
|
|
return "", false, err
|
2017-01-23 10:58:05 +03:00
|
|
|
}
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 13:23:57 +03:00
|
|
|
|
2021-08-25 23:34:22 +03:00
|
|
|
return keydir, isEphemeral, nil
|
2016-08-15 19:38:32 +03:00
|
|
|
}
|
2018-12-07 16:43:27 +03:00
|
|
|
|
2020-05-20 06:46:45 +03:00
|
|
|
type LogConfig struct {
|
2023-04-06 07:24:04 +03:00
|
|
|
FileRoot *string `toml:",omitempty"`
|
|
|
|
FilePath *string `toml:",omitempty"`
|
|
|
|
MaxBytesSize *uint `toml:",omitempty"`
|
|
|
|
Level *string `toml:",omitempty"`
|
2023-12-14 05:02:26 +03:00
|
|
|
RotateHours *uint `toml:",omitempty"`
|
2024-01-30 14:16:01 +03:00
|
|
|
MaxBackups *uint `toml:",omitempty"`
|
2023-04-03 05:22:49 +03:00
|
|
|
|
|
|
|
// TermTimeFormat is the time format used for console logging.
|
2023-04-06 07:24:04 +03:00
|
|
|
TermTimeFormat *string `toml:",omitempty"`
|
2023-04-03 05:22:49 +03:00
|
|
|
// TimeFormat is the time format used for file logging.
|
2023-04-06 07:24:04 +03:00
|
|
|
TimeFormat *string `toml:",omitempty"`
|
2020-05-20 06:46:45 +03:00
|
|
|
}
|