erigon-pulse/turbo/cli/flags.go

296 lines
9.9 KiB
Go
Raw Normal View History

2020-10-27 15:53:49 +00:00
package cli
import (
"fmt"
"strings"
"time"
2020-10-27 15:53:49 +00:00
"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common/etl"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/prune"
"github.com/ledgerwatch/erigon/log"
"github.com/ledgerwatch/erigon/node"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
2021-03-23 09:00:07 +00:00
"github.com/spf13/pflag"
2020-10-27 15:53:49 +00:00
"github.com/urfave/cli"
)
var (
DatabaseVerbosityFlag = cli.IntFlag{
Name: "database.verbosity",
Usage: "Enabling internal db logs. Very high verbosity levels may require recompile db. Default: 2, means warning.",
Value: 2,
}
2020-10-27 15:53:49 +00:00
BatchSizeFlag = cli.StringFlag{
Name: "batchSize",
Usage: "Batch size for the execution stage",
Value: "512M",
}
EtlBufferSizeFlag = cli.StringFlag{
Name: "etl.bufferSize",
Usage: "Buffer size for ETL operations.",
Value: etl.BufferOptimalSize.String(),
}
BlockDownloaderWindowFlag = cli.IntFlag{
Name: "blockDownloaderWindow",
Usage: "Outstanding limit of block bodies being downloaded",
Value: 65536,
}
2020-10-27 15:53:49 +00:00
PrivateApiAddr = cli.StringFlag{
Name: "private.api.addr",
Usage: "private api network address, for example: 127.0.0.1:9090, empty string means not to start the listener. do not expose to public network. serves remote database interface",
Value: "127.0.0.1:9090",
2020-10-27 15:53:49 +00:00
}
PrivateApiRateLimit = cli.IntFlag{
Name: "private.api.ratelimit",
Usage: "Amount of requests server handle simultaneously - requests over this limit will wait. Increase it - if clients see 'request timeout' while server load is low - it means your 'hot data' is small or have much RAM. ",
Value: 500,
}
MaxPeersFlag = cli.IntFlag{
Name: "maxpeers",
Usage: "Maximum number of network peers (network disabled if set to 0)",
Value: node.DefaultConfig.P2P.MaxPeers,
}
PruneFlag = cli.StringFlag{
Name: "prune",
Usage: `Choose which ancient data delete from DB:
h - prune history (ChangeSets, HistoryIndices - used by historical state access)
r - prune receipts (Receipts, Logs, LogTopicIndex, LogAddressIndex - used by eth_getLogs and similar RPC methods)
t - prune transaction by it's hash index
c - prune call traces (used by trace_* methods)
Does delete data older than 90K block (can set another value by '--prune.*.older' flags).
If item is NOT in the list - means NO pruning for this data.s
Example: --prune=hrtc`,
Value: "disabled",
}
PruneHistoryFlag = cli.Uint64Flag{
Name: "prune.history.older",
Usage: `Prune data after this amount of blocks (if --prune flag has 'h', then default is 90K)`,
}
PruneReceiptFlag = cli.Uint64Flag{
Name: "prune.receipt.older",
Usage: `Prune data after this amount of blocks (if --prune flag has 'r', then default is 90K)`,
}
PruneTxIndexFlag = cli.Uint64Flag{
Name: "prune.txindex.older",
Usage: `Prune data after this amount of blocks (if --prune flag has 't', then default is 90K)`,
}
PruneCallTracesFlag = cli.Uint64Flag{
Name: "prune.calltrace.older",
Usage: `Prune data after this amount of blocks (if --prune flag has 'c', then default is 90K)`,
}
ExperimentsFlag = cli.StringFlag{
Name: "experiments",
Usage: `Enable some experimental stages:
* tevm - write TEVM translated code to the DB`,
Value: "default",
2020-10-27 15:53:49 +00:00
}
2020-10-27 15:53:49 +00:00
SnapshotModeFlag = cli.StringFlag{
Name: "snapshot.mode",
2021-02-09 15:48:55 +00:00
Usage: `Configures the snapshot mode of the app:
2020-10-27 15:53:49 +00:00
* h - download headers snapshot
* b - download bodies snapshot
* s - download state snapshot
* r - download receipts snapshot
`,
Value: snapshotsync.DefaultSnapshotMode.ToString(),
2020-10-27 15:53:49 +00:00
}
SeedSnapshotsFlag = cli.BoolTFlag{
Name: "snapshot.seed",
Usage: `Seed snapshot seeding(default: true)`,
}
//todo replace to BoolT
SnapshotDatabaseLayoutFlag = cli.BoolFlag{
Name: "snapshot.layout",
Usage: `Enable snapshot db layout(default: false)`,
}
ExternalSnapshotDownloaderAddrFlag = cli.StringFlag{
Name: "snapshot.downloader.addr",
Usage: `enable external snapshot downloader`,
2020-10-27 15:53:49 +00:00
}
// mTLS flags
TLSFlag = cli.BoolFlag{
Name: "tls",
Usage: "Enable TLS handshake",
}
TLSCertFlag = cli.StringFlag{
Name: "tls.cert",
Usage: "Specify certificate",
Value: "",
}
TLSKeyFlag = cli.StringFlag{
Name: "tls.key",
Usage: "Specify key file",
Value: "",
}
TLSCACertFlag = cli.StringFlag{
Name: "tls.cacert",
Usage: "Specify certificate authority",
Value: "",
}
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
StateStreamFlag = cli.BoolFlag{
Name: "state.stream",
Usage: "Enable streaming of state changes from core to RPC daemon",
}
// Throttling Flags
SyncLoopThrottleFlag = cli.StringFlag{
Name: "sync.loop.throttle",
Usage: "Sets the minimum time between sync loop starts (e.g. 1h30m, default is none)",
Value: "",
}
2020-10-27 15:53:49 +00:00
)
2021-03-23 09:00:07 +00:00
func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) {
mode, err := prune.FromCli(
ctx.GlobalString(PruneFlag.Name),
ctx.GlobalUint64(PruneHistoryFlag.Name),
ctx.GlobalUint64(PruneReceiptFlag.Name),
ctx.GlobalUint64(PruneTxIndexFlag.Name),
ctx.GlobalUint64(PruneCallTracesFlag.Name),
strings.Split(ctx.GlobalString(ExperimentsFlag.Name), ","),
)
2020-10-27 15:53:49 +00:00
if err != nil {
utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err))
}
cfg.Prune = mode
snMode, err := snapshotsync.SnapshotModeFromString(ctx.GlobalString(SnapshotModeFlag.Name))
2020-10-27 15:53:49 +00:00
if err != nil {
utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err))
}
2021-07-08 13:52:22 +00:00
cfg.Snapshot.Mode = snMode
cfg.Snapshot.Seeding = ctx.GlobalBool(SeedSnapshotsFlag.Name)
cfg.Snapshot.Enabled = ctx.GlobalBool(SnapshotDatabaseLayoutFlag.Name)
2020-10-27 15:53:49 +00:00
if ctx.GlobalString(BatchSizeFlag.Name) != "" {
err := cfg.BatchSize.UnmarshalText([]byte(ctx.GlobalString(BatchSizeFlag.Name)))
if err != nil {
utils.Fatalf("Invalid batchSize provided: %v", err)
}
}
if ctx.GlobalString(EtlBufferSizeFlag.Name) != "" {
sizeVal := datasize.ByteSize(0)
size := &sizeVal
err := size.UnmarshalText([]byte(ctx.GlobalString(EtlBufferSizeFlag.Name)))
if err != nil {
utils.Fatalf("Invalid batchSize provided: %v", err)
}
etl.BufferOptimalSize = *size
}
cfg.ExternalSnapshotDownloaderAddr = ctx.GlobalString(ExternalSnapshotDownloaderAddrFlag.Name)
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
cfg.StateStream = ctx.GlobalBool(StateStreamFlag.Name)
cfg.BlockDownloaderWindow = ctx.GlobalInt(BlockDownloaderWindowFlag.Name)
if ctx.GlobalString(SyncLoopThrottleFlag.Name) != "" {
syncLoopThrottle, err := time.ParseDuration(ctx.GlobalString(SyncLoopThrottleFlag.Name))
if err != nil {
utils.Fatalf("Invalid time duration provided in %s: %v", SyncLoopThrottleFlag.Name, err)
}
cfg.SyncLoopThrottle = syncLoopThrottle
}
2020-10-27 15:53:49 +00:00
}
2021-03-23 09:00:07 +00:00
func ApplyFlagsForEthConfigCobra(f *pflag.FlagSet, cfg *ethconfig.Config) {
if v := f.String(PruneFlag.Name, PruneFlag.Value, PruneFlag.Usage); v != nil {
var experiments []string
if exp := f.StringSlice(ExperimentsFlag.Name, nil, ExperimentsFlag.Usage); exp != nil {
experiments = *exp
}
var exactH, exactR, exactT, exactC uint64
if v := f.Uint64(PruneHistoryFlag.Name, PruneHistoryFlag.Value, PruneHistoryFlag.Usage); v != nil {
exactH = *v
}
if v := f.Uint64(PruneReceiptFlag.Name, PruneReceiptFlag.Value, PruneReceiptFlag.Usage); v != nil {
exactR = *v
}
if v := f.Uint64(PruneTxIndexFlag.Name, PruneTxIndexFlag.Value, PruneTxIndexFlag.Usage); v != nil {
exactT = *v
}
if v := f.Uint64(PruneCallTracesFlag.Name, PruneCallTracesFlag.Value, PruneCallTracesFlag.Usage); v != nil {
exactC = *v
}
mode, err := prune.FromCli(*v, exactH, exactR, exactT, exactC, experiments)
2021-03-23 09:00:07 +00:00
if err != nil {
utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err))
}
cfg.Prune = mode
2021-03-23 09:00:07 +00:00
}
if v := f.String(SnapshotModeFlag.Name, SnapshotModeFlag.Value, SnapshotModeFlag.Usage); v != nil {
snMode, err := snapshotsync.SnapshotModeFromString(*v)
if err != nil {
utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err))
}
2021-07-08 13:52:22 +00:00
cfg.Snapshot.Mode = snMode
2021-03-23 09:00:07 +00:00
}
if v := f.Bool(SeedSnapshotsFlag.Name, false, SeedSnapshotsFlag.Usage); v != nil {
2021-07-08 13:52:22 +00:00
cfg.Snapshot.Seeding = *v
2021-03-23 09:00:07 +00:00
}
if v := f.String(BatchSizeFlag.Name, BatchSizeFlag.Value, BatchSizeFlag.Usage); v != nil {
err := cfg.BatchSize.UnmarshalText([]byte(*v))
if err != nil {
utils.Fatalf("Invalid batchSize provided: %v", err)
}
}
if v := f.String(EtlBufferSizeFlag.Name, EtlBufferSizeFlag.Value, EtlBufferSizeFlag.Usage); v != nil {
sizeVal := datasize.ByteSize(0)
size := &sizeVal
err := size.UnmarshalText([]byte(*v))
if err != nil {
utils.Fatalf("Invalid batchSize provided: %v", err)
}
etl.BufferOptimalSize = *size
}
if v := f.String(ExternalSnapshotDownloaderAddrFlag.Name, ExternalSnapshotDownloaderAddrFlag.Value, ExternalSnapshotDownloaderAddrFlag.Usage); v != nil {
cfg.ExternalSnapshotDownloaderAddr = *v
}
State stream to RPC daemon (#1986) * Remove interfaces * Squashed 'interfaces/' content from commit e06631eb4 git-subtree-dir: interfaces git-subtree-split: e06631eb4d0926c2d6a4f552497b920b4ed8d1bd * Update KV interface * Squashed 'interfaces/' changes from e06631eb4..014677ffe 014677ffe Merge remote-tracking branch 'origin/master' into stream 08c32a09e add version method to txPool and ethbackend 5b6bf70b9 Update README.md 7712cb267 Update README.md f895ece4c save (#37) git-subtree-dir: interfaces git-subtree-split: 014677ffe5bff0dee1a333f06c92e6110d791468 * Fix old interfaces * Squashed 'interfaces/' changes from 014677ffe..df31e1146 df31e1146 remove action from storage change git-subtree-dir: interfaces git-subtree-split: df31e1146c368eda2e2b15ab252b78fba7a0a6f3 * add Accumulator * add location * Squashed 'interfaces/' changes from df31e1146..472584639 472584639 Merge remote-tracking branch 'origin/master' into stream dd6a42724 Refactor of consensus interface (#28) git-subtree-dir: interfaces git-subtree-split: 472584639f637189dfb906ef1ed03665f98d55d2 * Fix compilation in cons * Pass accumulator to Execution stage * Fix test * Pass accumulator to unwind and plain writer * Add accumulator use to plain writer * Squashed 'interfaces/' changes from 472584639f..5c36f038b8 5c36f038b8 State change stream to KV (#38) REVERT: 472584639f Merge remote-tracking branch 'origin/master' into stream REVERT: df31e1146c remove action from storage change REVERT: 014677ffe5 Merge remote-tracking branch 'origin/master' into stream REVERT: e06631eb4d Fix REVERT: 9c10d79d2d Fix REVERT: 61ae9307de Fix REVERT: 4fcf34ecc5 State change stream to KV git-subtree-dir: interfaces git-subtree-split: 5c36f038b87096ffb6b07e90c6762c21b864cd3b * Add state.stream flag Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2021-05-23 14:53:18 +00:00
if v := f.Bool(StateStreamFlag.Name, false, StateStreamFlag.Usage); v != nil {
cfg.StateStream = *v
}
2021-03-23 09:00:07 +00:00
}
2020-10-27 15:53:49 +00:00
func ApplyFlagsForNodeConfig(ctx *cli.Context, cfg *node.Config) {
setPrivateApi(ctx, cfg)
cfg.DatabaseVerbosity = ethdb.DBVerbosityLvl(ctx.GlobalInt(DatabaseVerbosityFlag.Name))
2020-10-27 15:53:49 +00:00
}
// setPrivateApi populates configuration fields related to the remote
// read-only interface to the databae
func setPrivateApi(ctx *cli.Context, cfg *node.Config) {
cfg.PrivateApiAddr = ctx.GlobalString(PrivateApiAddr.Name)
cfg.PrivateApiRateLimit = uint32(ctx.GlobalUint64(PrivateApiRateLimit.Name))
maxRateLimit := uint32(ethdb.ReadersLimit - 128) // leave some readers for P2P
if cfg.PrivateApiRateLimit > maxRateLimit {
log.Warn("private.api.ratelimit is too big", "force", maxRateLimit)
cfg.PrivateApiRateLimit = maxRateLimit
}
2020-10-27 15:53:49 +00:00
if ctx.GlobalBool(TLSFlag.Name) {
certFile := ctx.GlobalString(TLSCertFlag.Name)
keyFile := ctx.GlobalString(TLSKeyFlag.Name)
if certFile == "" {
log.Warn("Could not establish TLS grpc: missing certificate")
return
} else if keyFile == "" {
log.Warn("Could not establish TLS grpc: missing key file")
return
}
cfg.TLSConnection = true
cfg.TLSCertFile = certFile
cfg.TLSKeyFile = keyFile
cfg.TLSCACert = ctx.GlobalString(TLSCACertFlag.Name)
}
}