mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
* Adding in Mumbai/Mainnet precursor deb packaging for tests to use during upgrade(iterations to come) * Added changes per discussion in PR, more changes may be necessary * Adding prerelease true * Disabling goreleaser * Removing README swap file * change bor_dir and add bor user for v0.3.0 release * rollback bor user and use root * metrics: handle equal to separated config flag (#596) * metrics: handle based config path * internal/cli/server: add more context to logs * use space separated flag and value in bor.service * fixed static-nodes related buf (os independent) (#598) * fixed static-nodes related buf (os independent) * taking static-nodes as input if default not present * Update default flags (#600) * internal/cli/server: use geth's default for txpool.pricelimit and add comments * builder/files: update config.toml for mainnet * packaging/templates: update defaults for mainnet and mumbai * internal/cli/server: skip overriding cache * packaging/templates: update cache value for mainnet * packaging/templates: update gcmode for archive mumbai node * metrics: handle nil telemetry config (#601) * resolve merge conflicts * update go version in release.yml * update goversion in makefile * update Docker login for goreleaser-cross v1.19 * Cleanup for the packager to use git tag in the package profile naming. Added conditional check for directory structure, this is in prep for v0.3.1, as this will create a failure on upgrade path in package due to file exist * added a toml configuration file with comments describing each flag (#607) * added a toml configuration file with comments describing each flag * internal/cli/server: update flag description * docs/cli: update example config and description of flags * docs: update new-cli docs Co-authored-by: Manav Darji <manavdarji.india@gmail.com> * Adding of 0.3.0 package changes, control file updates, postinst changes, and packager update * added ancient datadir flag and toml field, need to decide on default value and update the conversion script * updated toml files with ancient field * Add support for new flags in new config.toml, which were present in old config.toml (#612) * added HTTPTimeouts, and TrieTimeout flag in new tol, from old toml * added RAW fields for these time.Duration flags * updated the conversion script to support these extra 4 flags * removed hcl and json config tests as we are only supporting toml config files * updated toml files with cache.timeout field * updated toml files with jsonrpc.timeouts field * tests/bor: expect a call for latest checkpoint * tests/bor: expect a call for latest checkpoint * packaging/templates: update cache values for archive nodes Co-authored-by: Manav Darji <manavdarji.india@gmail.com> * remove unwanted code * Fix docker publish authentication issue In gorelease-cross 1.19+, dockerhub authentication will require docker logion action followed by mounting docker config file. See https://github.com/goreleaser/goreleaser-cross#github-actions. * Revert "update Docker login for goreleaser-cross v1.19" This reverts commit4d19cf5342. * Bump version to stable * Revert "Merge pull request #435 from maticnetwork/POS-553" This reverts commit657d262def, reversing changes made to88dbfa1c13. * revert change for release for go1.19 * Add default values to CLI helper and docs This commit adds default values to CLI helper and docs. When the default value of a string flag, slice string flag, or map string flag is empty, its helper message won't show any default value. * Add a summary of new CLI in docs * Updating packager as binutils changed version so that apt-get installs current versions * Add state pruning to new CLI * Minor wording fix in prune state description * Bumping control file versions * Mainnet Delhi fork * Set version to stable * change delhi hardfork block number * handle future chain import and skip peer drop (#650) * handle future chain import and skip peer drop * add block import metric * params: bump version to v0.3.3-stable * Bump bor version in control files for v0.3.3 mainnet release Co-authored-by: Daniel Jones <djones@polygon.technology> Co-authored-by: Will Button <wbutton@polygon.technology> Co-authored-by: Will Button <will@willbutton.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Daniel Jones <105369507+djpolygon@users.noreply.github.com> Co-authored-by: Pratik Patil <pratikspatil024@gmail.com> Co-authored-by: Arpit Temani <temaniarpit27@gmail.com> Co-authored-by: Jerry <jerrycgh@gmail.com>
303 lines
6.3 KiB
Go
303 lines
6.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
"github.com/ethereum/go-ethereum/internal/cli/flagset"
|
|
"github.com/ethereum/go-ethereum/internal/cli/server"
|
|
"github.com/ethereum/go-ethereum/internal/cli/server/proto"
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/mitchellh/cli"
|
|
"github.com/ryanuber/columnize"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
const (
|
|
emptyPlaceHolder = "<none>"
|
|
)
|
|
|
|
type MarkDownCommand interface {
|
|
MarkDown
|
|
cli.Command
|
|
}
|
|
|
|
type MarkDownCommandFactory func() (MarkDownCommand, error)
|
|
|
|
func Run(args []string) int {
|
|
commands := Commands()
|
|
|
|
mappedCommands := make(map[string]cli.CommandFactory)
|
|
|
|
for k, v := range commands {
|
|
// Declare a new v to limit the scope of v to inside the block, so the anonymous function below
|
|
// can get the "current" value of v, instead of the value of last v in the loop.
|
|
// See this post: https://stackoverflow.com/questions/10116507/go-transfer-var-into-anonymous-function for more explanation
|
|
v := v
|
|
mappedCommands[k] = func() (cli.Command, error) {
|
|
cmd, err := v()
|
|
return cmd.(cli.Command), err
|
|
}
|
|
}
|
|
|
|
cli := &cli.CLI{
|
|
Name: "bor",
|
|
Args: args,
|
|
Commands: mappedCommands,
|
|
}
|
|
|
|
exitCode, err := cli.Run()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
|
|
return 1
|
|
}
|
|
|
|
return exitCode
|
|
}
|
|
|
|
func Commands() map[string]MarkDownCommandFactory {
|
|
ui := &cli.BasicUi{
|
|
Reader: os.Stdin,
|
|
Writer: os.Stdout,
|
|
ErrorWriter: os.Stderr,
|
|
}
|
|
|
|
meta2 := &Meta2{
|
|
UI: ui,
|
|
}
|
|
meta := &Meta{
|
|
UI: ui,
|
|
}
|
|
|
|
return map[string]MarkDownCommandFactory{
|
|
"server": func() (MarkDownCommand, error) {
|
|
return &server.Command{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"version": func() (MarkDownCommand, error) {
|
|
return &VersionCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"dumpconfig": func() (MarkDownCommand, error) {
|
|
return &DumpconfigCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"debug": func() (MarkDownCommand, error) {
|
|
return &DebugCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"debug pprof": func() (MarkDownCommand, error) {
|
|
return &DebugPprofCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"debug block": func() (MarkDownCommand, error) {
|
|
return &DebugBlockCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"chain": func() (MarkDownCommand, error) {
|
|
return &ChainCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"chain watch": func() (MarkDownCommand, error) {
|
|
return &ChainWatchCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"chain sethead": func() (MarkDownCommand, error) {
|
|
return &ChainSetHeadCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"account": func() (MarkDownCommand, error) {
|
|
return &Account{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"account new": func() (MarkDownCommand, error) {
|
|
return &AccountNewCommand{
|
|
Meta: meta,
|
|
}, nil
|
|
},
|
|
"account import": func() (MarkDownCommand, error) {
|
|
return &AccountImportCommand{
|
|
Meta: meta,
|
|
}, nil
|
|
},
|
|
"account list": func() (MarkDownCommand, error) {
|
|
return &AccountListCommand{
|
|
Meta: meta,
|
|
}, nil
|
|
},
|
|
"peers": func() (MarkDownCommand, error) {
|
|
return &PeersCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"peers add": func() (MarkDownCommand, error) {
|
|
return &PeersAddCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"peers remove": func() (MarkDownCommand, error) {
|
|
return &PeersRemoveCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"peers list": func() (MarkDownCommand, error) {
|
|
return &PeersListCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"peers status": func() (MarkDownCommand, error) {
|
|
return &PeersStatusCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"status": func() (MarkDownCommand, error) {
|
|
return &StatusCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"fingerprint": func() (MarkDownCommand, error) {
|
|
return &FingerprintCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"attach": func() (MarkDownCommand, error) {
|
|
return &AttachCommand{
|
|
UI: ui,
|
|
Meta: meta,
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"bootnode": func() (MarkDownCommand, error) {
|
|
return &BootnodeCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"removedb": func() (MarkDownCommand, error) {
|
|
return &RemoveDBCommand{
|
|
Meta2: meta2,
|
|
}, nil
|
|
},
|
|
"snapshot": func() (MarkDownCommand, error) {
|
|
return &SnapshotCommand{
|
|
UI: ui,
|
|
}, nil
|
|
},
|
|
"snapshot prune-state": func() (MarkDownCommand, error) {
|
|
return &PruneStateCommand{
|
|
Meta: meta,
|
|
}, nil
|
|
},
|
|
}
|
|
}
|
|
|
|
type Meta2 struct {
|
|
UI cli.Ui
|
|
|
|
addr string
|
|
}
|
|
|
|
func (m *Meta2) NewFlagSet(n string) *flagset.Flagset {
|
|
f := flagset.NewFlagSet(n)
|
|
|
|
f.StringFlag(&flagset.StringFlag{
|
|
Name: "address",
|
|
Value: &m.addr,
|
|
Usage: "Address of the grpc endpoint",
|
|
Default: "127.0.0.1:3131",
|
|
})
|
|
|
|
return f
|
|
}
|
|
|
|
func (m *Meta2) Conn() (*grpc.ClientConn, error) {
|
|
conn, err := grpc.Dial(m.addr, grpc.WithInsecure())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to connect to server: %v", err)
|
|
}
|
|
|
|
return conn, nil
|
|
}
|
|
|
|
func (m *Meta2) BorConn() (proto.BorClient, error) {
|
|
conn, err := m.Conn()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return proto.NewBorClient(conn), nil
|
|
}
|
|
|
|
// Meta is a helper utility for the commands
|
|
type Meta struct {
|
|
UI cli.Ui
|
|
|
|
dataDir string
|
|
keyStoreDir string
|
|
}
|
|
|
|
func (m *Meta) NewFlagSet(n string) *flagset.Flagset {
|
|
f := flagset.NewFlagSet(n)
|
|
|
|
f.StringFlag(&flagset.StringFlag{
|
|
Name: "datadir",
|
|
Value: &m.dataDir,
|
|
Usage: "Path of the data directory to store information",
|
|
})
|
|
f.StringFlag(&flagset.StringFlag{
|
|
Name: "keystore",
|
|
Value: &m.keyStoreDir,
|
|
Usage: "Path of the data directory to store keys",
|
|
})
|
|
|
|
return f
|
|
}
|
|
|
|
func (m *Meta) AskPassword() (string, error) {
|
|
return m.UI.AskSecret("Your new account is locked with a password. Please give a password. Do not forget this password")
|
|
}
|
|
|
|
func (m *Meta) GetKeystore() (*keystore.KeyStore, error) {
|
|
cfg := node.DefaultConfig
|
|
cfg.DataDir = m.dataDir
|
|
cfg.KeyStoreDir = m.keyStoreDir
|
|
|
|
stack, err := node.New(&cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
keydir := stack.KeyStoreDir()
|
|
scryptN := keystore.StandardScryptN
|
|
scryptP := keystore.StandardScryptP
|
|
|
|
keys := keystore.NewKeyStore(keydir, scryptN, scryptP)
|
|
|
|
return keys, nil
|
|
}
|
|
|
|
func formatList(in []string) string {
|
|
columnConf := columnize.DefaultConfig()
|
|
columnConf.Empty = emptyPlaceHolder
|
|
|
|
return columnize.Format(in, columnConf)
|
|
}
|
|
|
|
func formatKV(in []string) string {
|
|
columnConf := columnize.DefaultConfig()
|
|
columnConf.Empty = emptyPlaceHolder
|
|
columnConf.Glue = " = "
|
|
|
|
return columnize.Format(in, columnConf)
|
|
}
|