From 3ed0f5c83d951d04ed770c578a067774bf677b97 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sat, 31 Jul 2021 12:24:20 +0700 Subject: [PATCH] better prune error message (#2475) --- cmd/erigon/main.go | 9 ++++++-- eth/backend.go | 2 +- ethdb/prune/storage_mode.go | 41 ++++++++++++++++++++++--------------- turbo/node/node.go | 17 ++++++++------- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/cmd/erigon/main.go b/cmd/erigon/main.go index b50937fef..e189a2521 100644 --- a/cmd/erigon/main.go +++ b/cmd/erigon/main.go @@ -51,8 +51,13 @@ func runErigon(cliCtx *cli.Context) { chaindb.Close() } - err := node.New(nodeCfg, ethCfg, logger).Serve() + ethNode, err := node.New(nodeCfg, ethCfg, logger) if err != nil { - log.Error("error while serving a Erigon node", "err", err) + log.Error("Erigon startup", "err", err) + return + } + err = ethNode.Serve() + if err != nil { + log.Error("error while serving an Erigon node", "err", err) } } diff --git a/eth/backend.go b/eth/backend.go index 86f55864a..67a51c061 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -231,7 +231,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere if config.Prune.Initialised { // If storage mode is not explicitly specified, we take whatever is in the database if !reflect.DeepEqual(pm, config.Prune) { - return errors.New("prune is " + config.Prune.String() + " original prune is " + pm.String()) + return errors.New("not allowed change of --prune flag, last time you used: " + pm.String()) } } else { config.Prune = pm diff --git a/ethdb/prune/storage_mode.go b/ethdb/prune/storage_mode.go index e251be644..2ab2930c6 100644 --- a/ethdb/prune/storage_mode.go +++ b/ethdb/prune/storage_mode.go @@ -152,33 +152,40 @@ func (m Mode) String() string { if !m.Initialised { return "default" } - modeString := "" + long := "" + short := "--prune=" if m.History.Enabled() { - modeString += fmt.Sprintf("history=%d,", m.History) - } else { - modeString += "history=no," + if m.History == params.FullImmutabilityThreshold { + short += "h" + } else { + long += fmt.Sprintf(" --prune.h.older=%d", m.History) + } } if m.Receipts.Enabled() { - modeString += fmt.Sprintf("receipt=%d,", m.Receipts) - } else { - modeString += "receipt=no," + if m.Receipts == params.FullImmutabilityThreshold { + short += "r" + } else { + long += fmt.Sprintf(" --prune.r.older=%d", m.Receipts) + } } if m.TxIndex.Enabled() { - modeString += fmt.Sprintf("txindex=%d,", m.TxIndex) - } else { - modeString += "txindex=no," + if m.TxIndex == params.FullImmutabilityThreshold { + short += "t" + } else { + long += fmt.Sprintf(" --prune.t.older=%d", m.TxIndex) + } } if m.CallTraces.Enabled() { - modeString += fmt.Sprintf("calltrace=%d,", m.CallTraces) - } else { - modeString += "calltrace=no," + if m.CallTraces == params.FullImmutabilityThreshold { + short += "c" + } else { + long += fmt.Sprintf(" --prune.c.older=%d", m.CallTraces) + } } if m.Experiments.TEVM { - modeString += "experiments.tevm=enabled" - } else { - modeString += "experiments.tevm=disabled" + long += " --experiments.tevm=enabled" } - return modeString + return short + long } func Override(db kv.RwTx, sm Mode) error { diff --git a/turbo/node/node.go b/turbo/node/node.go index 933e30f1c..ecc33886b 100644 --- a/turbo/node/node.go +++ b/turbo/node/node.go @@ -92,20 +92,19 @@ func New( nodeConfig *node.Config, ethConfig *ethconfig.Config, logger log.Logger, -) *ErigonNode { +) (*ErigonNode, error) { //prepareBuckets(optionalParams.CustomBuckets) node := makeConfigNode(nodeConfig) - ethereum := RegisterEthService(node, ethConfig, logger) - return &ErigonNode{stack: node, backend: ethereum} + ethereum, err := RegisterEthService(node, ethConfig, logger) + if err != nil { + return nil, err + } + return &ErigonNode{stack: node, backend: ethereum}, nil } // RegisterEthService adds an Ethereum client to the stack. -func RegisterEthService(stack *node.Node, cfg *ethconfig.Config, logger log.Logger) *eth.Ethereum { - backend, err := eth.New(stack, cfg, logger) - if err != nil { - panic(err) - } - return backend +func RegisterEthService(stack *node.Node, cfg *ethconfig.Config, logger log.Logger) (*eth.Ethereum, error) { + return eth.New(stack, cfg, logger) } func NewNodeConfig() *node.Config {