From 31da9729fb6cffa4404a88d208ba1b582e0ce4f8 Mon Sep 17 00:00:00 2001 From: Jerry Date: Mon, 5 Dec 2022 22:35:27 -0800 Subject: [PATCH 1/8] Revert "update Docker login for goreleaser-cross v1.19" This reverts commit 4d19cf5342a439d98cca21b03c63a0bc075769cf. --- .github/workflows/release.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0d45f0bc98..b615cf639e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,12 +29,6 @@ jobs: TAG=${GITHUB_REF#refs/tags/} echo ::set-output name=tag_name::${TAG} - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB }} - password: ${{ secrets.DOCKERHUB_KEY }} - - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -45,3 +39,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ steps.prepare.outputs.tag_name }} SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + DOCKER_USERNAME: ${{ secrets.DOCKERHUB }} + DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_KEY }} From 43d894c44e1e5a544e915f4c950ce6981cd57536 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 6 Dec 2022 11:01:22 -0800 Subject: [PATCH 2/8] Bump version to stable --- params/version.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/params/version.go b/params/version.go index 83e04a66f8..d2746b37ee 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 0 // Major version component of the current release - VersionMinor = 3 // Minor version component of the current release - VersionPatch = 0 // Patch version component of the current release - VersionMeta = "beta" // Version metadata to append to the version string + VersionMajor = 0 // Major version component of the current release + VersionMinor = 3 // Minor version component of the current release + VersionPatch = 0 // Patch version component of the current release + VersionMeta = "stable" // Version metadata to append to the version string ) // Version holds the textual version string. @@ -43,7 +43,8 @@ var VersionWithMeta = func() string { // ArchiveVersion holds the textual version string used for Geth archives. // e.g. "1.8.11-dea1ce05" for stable releases, or -// "1.8.13-unstable-21c059b6" for unstable releases +// +// "1.8.13-unstable-21c059b6" for unstable releases func ArchiveVersion(gitCommit string) string { vsn := Version if VersionMeta != "stable" { From 6d11117edc687716549e69cb64147c182e116a3f Mon Sep 17 00:00:00 2001 From: Manav Darji Date: Wed, 14 Dec 2022 00:44:01 +0530 Subject: [PATCH 3/8] Revert "Merge pull request #435 from maticnetwork/POS-553" This reverts commit 657d262defc9c94e9513b3d45230492d8b20eac7, reversing changes made to 88dbfa1c13c15464d3c1a3085a9f12d0ffb9b218. --- internal/ethapi/api.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 082dfea66f..2fd148c7c6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -819,20 +819,6 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H return nil } -// getAuthor: returns the author of the Block -func (s *PublicBlockChainAPI) getAuthor(head *types.Header) *common.Address { - // get author using Author() function from: /consensus/clique/clique.go - // In Production: get author using Author() function from: /consensus/bor/bor.go - author, err := s.b.Engine().Author(head) - // make sure we don't send error to the user, return 0x0 instead - if err != nil { - add := common.HexToAddress("0x0000000000000000000000000000000000000000") - return &add - } - // change the coinbase (0x0) with the miner address - return &author -} - // GetBlockByNumber returns the requested canonical block. // - When blockNr is -1 the chain head is returned. // - When blockNr is -2 the pending chain head is returned. @@ -841,7 +827,6 @@ func (s *PublicBlockChainAPI) getAuthor(head *types.Header) *common.Address { func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { block, err := s.b.BlockByNumber(ctx, number) if block != nil && err == nil { - response, err := s.rpcMarshalBlock(ctx, block, true, fullTx) if err == nil && number == rpc.PendingBlockNumber { // Pending blocks need to nil out a few fields @@ -850,12 +835,6 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.B } } - if err == nil && number != rpc.PendingBlockNumber { - author := s.getAuthor(block.Header()) - - response["miner"] = author - } - // append marshalled bor transaction if err == nil && response != nil { response = s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx) @@ -874,10 +853,6 @@ func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Ha response, err := s.rpcMarshalBlock(ctx, block, true, fullTx) // append marshalled bor transaction if err == nil && response != nil { - author := s.getAuthor(block.Header()) - - response["miner"] = author - return s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx), err } return response, err From 7364f940ba418e32507f7095fb583f641d06e710 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 14 Dec 2022 00:59:54 +0530 Subject: [PATCH 4/8] revert change for release for go1.19 --- .github/workflows/release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 92b960f5cd..2ceda3d2ee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,12 @@ jobs: TAG=${GITHUB_REF#refs/tags/} echo ::set-output name=tag_name::${TAG} + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB }} + password: ${{ secrets.DOCKERHUB_KEY }} + - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -39,5 +45,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ steps.prepare.outputs.tag_name }} SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - DOCKER_USERNAME: ${{ secrets.DOCKERHUB }} - DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_KEY }} From a37af35c361eb7b61be6962402460909010f409e Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 13 Dec 2022 15:17:29 -0800 Subject: [PATCH 5/8] 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. --- docs/README.md | 2 + docs/cli/bootnode.md | 10 +- docs/cli/chain_sethead.md | 4 +- docs/cli/debug_block.md | 2 +- docs/cli/debug_pprof.md | 4 +- docs/cli/peers_add.md | 4 +- docs/cli/peers_list.md | 2 +- docs/cli/peers_remove.md | 4 +- docs/cli/peers_status.md | 2 +- docs/cli/removedb.md | 2 +- docs/cli/server.md | 144 ++++++++++++++-------------- internal/cli/flagset/flagset.go | 160 +++++++++++++++++++++----------- internal/cli/server/flags.go | 71 +++++++------- 13 files changed, 237 insertions(+), 174 deletions(-) diff --git a/docs/README.md b/docs/README.md index 45021e8c7f..4622bb8f00 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,6 +11,8 @@ $ bor server ``` + See [here](./cli/server.md) for more flag details. + - The `bor dumpconfig` sub-command prints the default configurations, in the TOML format, on the terminal. One can `pipe (>)` this to a file (say `config.toml`) and use it to start bor. - A toml file now can be used instead of flags and can contain all configuration for the node to run. To simply run bor with a configuration file, the following command can be used. diff --git a/docs/cli/bootnode.md b/docs/cli/bootnode.md index 48e933a934..064de39014 100644 --- a/docs/cli/bootnode.md +++ b/docs/cli/bootnode.md @@ -2,16 +2,16 @@ ## Options -- ```listen-addr```: listening address of bootnode (:) +- ```listen-addr```: listening address of bootnode (:) (default: 0.0.0.0:30303) -- ```v5```: Enable UDP v5 +- ```v5```: Enable UDP v5 (default: false) -- ```log-level```: Log level (trace|debug|info|warn|error|crit) +- ```log-level```: Log level (trace|debug|info|warn|error|crit) (default: info) -- ```nat```: port mapping mechanism (any|none|upnp|pmp|extip:) +- ```nat```: port mapping mechanism (any|none|upnp|pmp|extip:) (default: none) - ```node-key```: file or hex node key - ```save-key```: path to save the ecdsa private key -- ```dry-run```: validates parameters and prints bootnode configurations, but does not start bootnode \ No newline at end of file +- ```dry-run```: validates parameters and prints bootnode configurations, but does not start bootnode (default: false) \ No newline at end of file diff --git a/docs/cli/chain_sethead.md b/docs/cli/chain_sethead.md index bf97990e62..09cd37baa1 100644 --- a/docs/cli/chain_sethead.md +++ b/docs/cli/chain_sethead.md @@ -8,6 +8,6 @@ The ```chain sethead ``` command sets the current chain to a certain blo ## Options -- ```address```: Address of the grpc endpoint +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) -- ```yes```: Force set head \ No newline at end of file +- ```yes```: Force set head (default: false) \ No newline at end of file diff --git a/docs/cli/debug_block.md b/docs/cli/debug_block.md index ced7e482ee..efcead2626 100644 --- a/docs/cli/debug_block.md +++ b/docs/cli/debug_block.md @@ -4,6 +4,6 @@ The ```bor debug block ``` command will create an archive containing tra ## Options -- ```address```: Address of the grpc endpoint +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) - ```output```: Output directory \ No newline at end of file diff --git a/docs/cli/debug_pprof.md b/docs/cli/debug_pprof.md index 86a84b6065..2e7e40b677 100644 --- a/docs/cli/debug_pprof.md +++ b/docs/cli/debug_pprof.md @@ -4,8 +4,8 @@ The ```debug pprof ``` command will create an archive containing bor ppro ## Options -- ```address```: Address of the grpc endpoint +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) -- ```seconds```: seconds to trace +- ```seconds```: seconds to trace (default: 2) - ```output```: Output directory \ No newline at end of file diff --git a/docs/cli/peers_add.md b/docs/cli/peers_add.md index 5bc4ed1448..7b879cdf0d 100644 --- a/docs/cli/peers_add.md +++ b/docs/cli/peers_add.md @@ -4,6 +4,6 @@ The ```peers add ``` command joins the local client to another remote pee ## Options -- ```address```: Address of the grpc endpoint +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) -- ```trusted```: Add the peer as a trusted \ No newline at end of file +- ```trusted```: Add the peer as a trusted (default: false) \ No newline at end of file diff --git a/docs/cli/peers_list.md b/docs/cli/peers_list.md index 41f398b764..5d30d1d32e 100644 --- a/docs/cli/peers_list.md +++ b/docs/cli/peers_list.md @@ -4,4 +4,4 @@ The ```peers list``` command lists the connected peers. ## Options -- ```address```: Address of the grpc endpoint \ No newline at end of file +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) \ No newline at end of file diff --git a/docs/cli/peers_remove.md b/docs/cli/peers_remove.md index 2cac1e7656..f731f12f6f 100644 --- a/docs/cli/peers_remove.md +++ b/docs/cli/peers_remove.md @@ -4,6 +4,6 @@ The ```peers remove ``` command disconnects the local client from a conne ## Options -- ```address```: Address of the grpc endpoint +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) -- ```trusted```: Add the peer as a trusted \ No newline at end of file +- ```trusted```: Add the peer as a trusted (default: false) \ No newline at end of file diff --git a/docs/cli/peers_status.md b/docs/cli/peers_status.md index 65a0fe9d8f..9806bfb638 100644 --- a/docs/cli/peers_status.md +++ b/docs/cli/peers_status.md @@ -4,4 +4,4 @@ The ```peers status ``` command displays the status of a peer by its id ## Options -- ```address```: Address of the grpc endpoint \ No newline at end of file +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) \ No newline at end of file diff --git a/docs/cli/removedb.md b/docs/cli/removedb.md index 473d47ecef..7ee09568b9 100644 --- a/docs/cli/removedb.md +++ b/docs/cli/removedb.md @@ -4,6 +4,6 @@ The ```bor removedb``` command will remove the blockchain and state databases at ## Options -- ```address```: Address of the grpc endpoint +- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131) - ```datadir```: Path of the data directory to store information \ No newline at end of file diff --git a/docs/cli/server.md b/docs/cli/server.md index 4c291a74b9..777856de34 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -4,49 +4,51 @@ The ```bor server``` command runs the Bor client. ## Options -- ```chain```: Name of the chain to sync ('mumbai', 'mainnet') or path to a genesis file +- ```chain```: Name of the chain to sync ('mumbai', 'mainnet') or path to a genesis file (default: mainnet) - ```identity```: Name/Identity of the node -- ```log-level```: Set log level for the server +- ```log-level```: Set log level for the server (default: INFO) - ```datadir```: Path of the data directory to store information +- ```datadir.ancient```: Data directory for ancient chain segments (default = inside chaindata) + - ```keystore```: Path of the directory where keystores are located - ```config```: File for the config file -- ```syncmode```: Blockchain sync mode (only "full" sync supported) +- ```syncmode```: Blockchain sync mode (only "full" sync supported) (default: full) -- ```gcmode```: Blockchain garbage collection mode ("full", "archive") +- ```gcmode```: Blockchain garbage collection mode ("full", "archive") (default: full) - ```eth.requiredblocks```: Comma separated block number-to-hash mappings to require for peering (=) -- ```snapshot```: Enables the snapshot-database mode (default = true) +- ```snapshot```: Enables the snapshot-database mode (default: true) -- ```bor.logs```: Enables bor log retrieval (default = false) +- ```bor.logs```: Enables bor log retrieval (default: false) -- ```bor.heimdall```: URL of Heimdall service +- ```bor.heimdall```: URL of Heimdall service (default: http://localhost:1317) -- ```bor.withoutheimdall```: Run without Heimdall service (for testing purpose) +- ```bor.withoutheimdall```: Run without Heimdall service (for testing purpose) (default: false) - ```ethstats```: Reporting URL of a ethstats service (nodename:secret@host:port) -- ```gpo.blocks```: Number of recent blocks to check for gas prices +- ```gpo.blocks```: Number of recent blocks to check for gas prices (default: 20) -- ```gpo.percentile```: Suggested gas price is the given percentile of a set of recent transaction gas prices +- ```gpo.percentile```: Suggested gas price is the given percentile of a set of recent transaction gas prices (default: 60) -- ```gpo.maxprice```: Maximum gas price will be recommended by gpo +- ```gpo.maxprice```: Maximum gas price will be recommended by gpo (default: 5000000000000) -- ```gpo.ignoreprice```: Gas price below which gpo will ignore transactions +- ```gpo.ignoreprice```: Gas price below which gpo will ignore transactions (default: 2) -- ```disable-bor-wallet```: Disable the personal wallet endpoints +- ```disable-bor-wallet```: Disable the personal wallet endpoints (default: true) -- ```grpc.addr```: Address and port to bind the GRPC server +- ```grpc.addr```: Address and port to bind the GRPC server (default: :3131) -- ```dev```: Enable developer mode with ephemeral proof-of-authority network and a pre-funded developer account, mining enabled +- ```dev```: Enable developer mode with ephemeral proof-of-authority network and a pre-funded developer account, mining enabled (default: false) -- ```dev.period```: Block period to use in developer mode (0 = mine only if transaction pending) +- ```dev.period```: Block period to use in developer mode (0 = mine only if transaction pending) (default: 0) ### Account Management Options @@ -54,111 +56,111 @@ The ```bor server``` command runs the Bor client. - ```password```: Password file to use for non-interactive password input -- ```allow-insecure-unlock```: Allow insecure account unlocking when account-related RPCs are exposed by http +- ```allow-insecure-unlock```: Allow insecure account unlocking when account-related RPCs are exposed by http (default: false) -- ```lightkdf```: Reduce key-derivation RAM & CPU usage at some expense of KDF strength +- ```lightkdf```: Reduce key-derivation RAM & CPU usage at some expense of KDF strength (default: false) ### Cache Options -- ```cache```: Megabytes of memory allocated to internal caching (default = 4096 mainnet full node) +- ```cache```: Megabytes of memory allocated to internal caching (default: 1024) -- ```cache.database```: Percentage of cache memory allowance to use for database io +- ```cache.database```: Percentage of cache memory allowance to use for database io (default: 50) -- ```cache.trie```: Percentage of cache memory allowance to use for trie caching (default = 15% full mode, 30% archive mode) +- ```cache.trie```: Percentage of cache memory allowance to use for trie caching (default: 15) -- ```cache.trie.journal```: Disk journal directory for trie cache to survive node restarts +- ```cache.trie.journal```: Disk journal directory for trie cache to survive node restarts (default: triecache) -- ```cache.trie.rejournal```: Time interval to regenerate the trie cache journal +- ```cache.trie.rejournal```: Time interval to regenerate the trie cache journal (default: 1h0m0s) -- ```cache.gc```: Percentage of cache memory allowance to use for trie pruning (default = 25% full mode, 0% archive mode) +- ```cache.gc```: Percentage of cache memory allowance to use for trie pruning (default: 25) -- ```cache.snapshot```: Percentage of cache memory allowance to use for snapshot caching (default = 10% full mode, 20% archive mode) +- ```cache.snapshot```: Percentage of cache memory allowance to use for snapshot caching (default: 10) -- ```cache.noprefetch```: Disable heuristic state prefetch during block import (less CPU and disk IO, more time waiting for data) +- ```cache.noprefetch```: Disable heuristic state prefetch during block import (less CPU and disk IO, more time waiting for data) (default: false) -- ```cache.preimages```: Enable recording the SHA3/keccak preimages of trie keys +- ```cache.preimages```: Enable recording the SHA3/keccak preimages of trie keys (default: false) -- ```txlookuplimit```: Number of recent blocks to maintain transactions index for (default = about 56 days, 0 = entire chain) +- ```txlookuplimit```: Number of recent blocks to maintain transactions index for (default: 2350000) ### JsonRPC Options -- ```rpc.gascap```: Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite) +- ```rpc.gascap```: Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite) (default: 50000000) -- ```rpc.txfeecap```: Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) +- ```rpc.txfeecap```: Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap) (default: 5) -- ```ipcdisable```: Disable the IPC-RPC server +- ```ipcdisable```: Disable the IPC-RPC server (default: false) - ```ipcpath```: Filename for IPC socket/pipe within the datadir (explicit paths escape it) -- ```http.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) +- ```http.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) (default: localhost) -- ```http.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. +- ```http.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: localhost) -- ```ws.origins```: Origins from which to accept websockets requests +- ```ws.origins```: Origins from which to accept websockets requests (default: localhost) -- ```graphql.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) +- ```graphql.corsdomain```: Comma separated list of domains from which to accept cross origin requests (browser enforced) (default: localhost) -- ```graphql.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. +- ```graphql.vhosts```: Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: localhost) -- ```http```: Enable the HTTP-RPC server +- ```http```: Enable the HTTP-RPC server (default: false) -- ```http.addr```: HTTP-RPC server listening interface +- ```http.addr```: HTTP-RPC server listening interface (default: localhost) -- ```http.port```: HTTP-RPC server listening port +- ```http.port```: HTTP-RPC server listening port (default: 8545) - ```http.rpcprefix```: HTTP path path prefix on which JSON-RPC is served. Use '/' to serve on all paths. -- ```http.api```: API's offered over the HTTP-RPC interface +- ```http.api```: API's offered over the HTTP-RPC interface (default: eth,net,web3,txpool,bor) -- ```ws```: Enable the WS-RPC server +- ```ws```: Enable the WS-RPC server (default: false) -- ```ws.addr```: WS-RPC server listening interface +- ```ws.addr```: WS-RPC server listening interface (default: localhost) -- ```ws.port```: WS-RPC server listening port +- ```ws.port```: WS-RPC server listening port (default: 8546) - ```ws.rpcprefix```: HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths. -- ```ws.api```: API's offered over the WS-RPC interface +- ```ws.api```: API's offered over the WS-RPC interface (default: net,web3) -- ```graphql```: Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well. +- ```graphql```: Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well. (default: false) ### P2P Options -- ```bind```: Network binding address +- ```bind```: Network binding address (default: 0.0.0.0) -- ```port```: Network listening port +- ```port```: Network listening port (default: 30303) - ```bootnodes```: Comma separated enode URLs for P2P discovery bootstrap -- ```maxpeers```: Maximum number of network peers (network disabled if set to 0) +- ```maxpeers```: Maximum number of network peers (network disabled if set to 0) (default: 50) -- ```maxpendpeers```: Maximum number of pending connection attempts +- ```maxpendpeers```: Maximum number of pending connection attempts (default: 50) -- ```nat```: NAT port mapping mechanism (any|none|upnp|pmp|extip:) +- ```nat```: NAT port mapping mechanism (any|none|upnp|pmp|extip:) (default: any) -- ```nodiscover```: Disables the peer discovery mechanism (manual peer addition) +- ```nodiscover```: Disables the peer discovery mechanism (manual peer addition) (default: false) -- ```v5disc```: Enables the experimental RLPx V5 (Topic Discovery) mechanism +- ```v5disc```: Enables the experimental RLPx V5 (Topic Discovery) mechanism (default: false) ### Sealer Options -- ```mine```: Enable mining +- ```mine```: Enable mining (default: false) - ```miner.etherbase```: Public address for block mining rewards - ```miner.extradata```: Block extra data set by the miner (default = client version) -- ```miner.gaslimit```: Target gas ceiling (gas limit) for mined blocks +- ```miner.gaslimit```: Target gas ceiling (gas limit) for mined blocks (default: 30000000) -- ```miner.gasprice```: Minimum gas price for mining a transaction +- ```miner.gasprice```: Minimum gas price for mining a transaction (default: 1000000000) ### Telemetry Options -- ```metrics```: Enable metrics collection and reporting +- ```metrics```: Enable metrics collection and reporting (default: false) -- ```metrics.expensive```: Enable expensive metrics collection and reporting +- ```metrics.expensive```: Enable expensive metrics collection and reporting (default: false) -- ```metrics.influxdb```: Enable metrics export/push to an external InfluxDB database (v1) +- ```metrics.influxdb```: Enable metrics export/push to an external InfluxDB database (v1) (default: false) - ```metrics.influxdb.endpoint```: InfluxDB API endpoint to report metrics to @@ -170,11 +172,11 @@ The ```bor server``` command runs the Bor client. - ```metrics.influxdb.tags```: Comma-separated InfluxDB tags (key/values) attached to all measurements -- ```metrics.prometheus-addr```: Address for Prometheus Server +- ```metrics.prometheus-addr```: Address for Prometheus Server (default: 127.0.0.1:7071) -- ```metrics.opencollector-endpoint```: OpenCollector Endpoint (host:port) +- ```metrics.opencollector-endpoint```: OpenCollector Endpoint (host:port) (default: 127.0.0.1:4317) -- ```metrics.influxdbv2```: Enable metrics export/push to an external InfluxDB v2 database +- ```metrics.influxdbv2```: Enable metrics export/push to an external InfluxDB v2 database (default: false) - ```metrics.influxdb.token```: Token to authorize access to the database (v2 only) @@ -186,22 +188,22 @@ The ```bor server``` command runs the Bor client. - ```txpool.locals```: Comma separated accounts to treat as locals (no flush, priority inclusion) -- ```txpool.nolocals```: Disables price exemptions for locally submitted transactions +- ```txpool.nolocals```: Disables price exemptions for locally submitted transactions (default: false) -- ```txpool.journal```: Disk journal for local transaction to survive node restarts +- ```txpool.journal```: Disk journal for local transaction to survive node restarts (default: transactions.rlp) -- ```txpool.rejournal```: Time interval to regenerate the local transaction journal +- ```txpool.rejournal```: Time interval to regenerate the local transaction journal (default: 1h0m0s) -- ```txpool.pricelimit```: Minimum gas price limit to enforce for acceptance into the pool +- ```txpool.pricelimit```: Minimum gas price limit to enforce for acceptance into the pool (default: 1) -- ```txpool.pricebump```: Price bump percentage to replace an already existing transaction +- ```txpool.pricebump```: Price bump percentage to replace an already existing transaction (default: 10) -- ```txpool.accountslots```: Minimum number of executable transaction slots guaranteed per account +- ```txpool.accountslots```: Minimum number of executable transaction slots guaranteed per account (default: 16) -- ```txpool.globalslots```: Maximum number of executable transaction slots for all accounts +- ```txpool.globalslots```: Maximum number of executable transaction slots for all accounts (default: 32768) -- ```txpool.accountqueue```: Maximum number of non-executable transaction slots permitted per account +- ```txpool.accountqueue```: Maximum number of non-executable transaction slots permitted per account (default: 16) -- ```txpool.globalqueue```: Maximum number of non-executable transaction slots for all accounts +- ```txpool.globalqueue```: Maximum number of non-executable transaction slots for all accounts (default: 32768) -- ```txpool.lifetime```: Maximum amount of time non-executable transaction are queued \ No newline at end of file +- ```txpool.lifetime```: Maximum amount of time non-executable transaction are queued (default: 3h0m0s) \ No newline at end of file diff --git a/internal/cli/flagset/flagset.go b/internal/cli/flagset/flagset.go index 933fe59060..74249df395 100644 --- a/internal/cli/flagset/flagset.go +++ b/internal/cli/flagset/flagset.go @@ -24,9 +24,10 @@ func NewFlagSet(name string) *Flagset { } type FlagVar struct { - Name string - Usage string - Group string + Name string + Usage string + Group string + Default any } func (f *Flagset) addFlag(fl *FlagVar) { @@ -38,7 +39,11 @@ func (f *Flagset) Help() string { items := []string{} for _, item := range f.flags { - items = append(items, fmt.Sprintf(" -%s\n %s", item.Name, item.Usage)) + if item.Default != nil { + items = append(items, fmt.Sprintf(" -%s\n %s (default: %v)", item.Name, item.Usage, item.Default)) + } else { + items = append(items, fmt.Sprintf(" -%s\n %s", item.Name, item.Usage)) + } } return str + strings.Join(items, "\n\n") @@ -85,7 +90,11 @@ func (f *Flagset) MarkDown() string { } for _, item := range groups[k] { - items = append(items, fmt.Sprintf("- ```%s```: %s", item.Name, item.Usage)) + if item.Default != nil { + items = append(items, fmt.Sprintf("- ```%s```: %s (default: %v)", item.Name, item.Usage, item.Default)) + } else { + items = append(items, fmt.Sprintf("- ```%s```: %s", item.Name, item.Usage)) + } } } @@ -110,27 +119,39 @@ type BoolFlag struct { func (f *Flagset) BoolFlag(b *BoolFlag) { f.addFlag(&FlagVar{ - Name: b.Name, - Usage: b.Usage, - Group: b.Group, + Name: b.Name, + Usage: b.Usage, + Group: b.Group, + Default: b.Default, }) f.set.BoolVar(b.Value, b.Name, b.Default, b.Usage) } type StringFlag struct { - Name string - Usage string - Default string - Value *string - Group string + Name string + Usage string + Default string + Value *string + Group string + HideDefaultFromDoc bool } func (f *Flagset) StringFlag(b *StringFlag) { - f.addFlag(&FlagVar{ - Name: b.Name, - Usage: b.Usage, - Group: b.Group, - }) + if b.Default == "" || b.HideDefaultFromDoc { + f.addFlag(&FlagVar{ + Name: b.Name, + Usage: b.Usage, + Group: b.Group, + Default: nil, + }) + } else { + f.addFlag(&FlagVar{ + Name: b.Name, + Usage: b.Usage, + Group: b.Group, + Default: b.Default, + }) + } f.set.StringVar(b.Value, b.Name, b.Default, b.Usage) } @@ -144,9 +165,10 @@ type IntFlag struct { func (f *Flagset) IntFlag(i *IntFlag) { f.addFlag(&FlagVar{ - Name: i.Name, - Usage: i.Usage, - Group: i.Group, + Name: i.Name, + Usage: i.Usage, + Group: i.Group, + Default: i.Default, }) f.set.IntVar(i.Value, i.Name, i.Default, i.Usage) } @@ -161,18 +183,20 @@ type Uint64Flag struct { func (f *Flagset) Uint64Flag(i *Uint64Flag) { f.addFlag(&FlagVar{ - Name: i.Name, - Usage: i.Usage, - Group: i.Group, + Name: i.Name, + Usage: i.Usage, + Group: i.Group, + Default: fmt.Sprintf("%d", i.Default), }) f.set.Uint64Var(i.Value, i.Name, i.Default, i.Usage) } type BigIntFlag struct { - Name string - Usage string - Value *big.Int - Group string + Name string + Usage string + Value *big.Int + Group string + Default *big.Int } func (b *BigIntFlag) String() string { @@ -204,9 +228,10 @@ func (b *BigIntFlag) Set(value string) error { func (f *Flagset) BigIntFlag(b *BigIntFlag) { f.addFlag(&FlagVar{ - Name: b.Name, - Usage: b.Usage, - Group: b.Group, + Name: b.Name, + Usage: b.Usage, + Group: b.Group, + Default: b.Default, }) f.set.Var(b, b.Name, b.Usage) } @@ -247,11 +272,21 @@ func (i *SliceStringFlag) Set(value string) error { } func (f *Flagset) SliceStringFlag(s *SliceStringFlag) { - f.addFlag(&FlagVar{ - Name: s.Name, - Usage: s.Usage, - Group: s.Group, - }) + if s.Default == nil || len(s.Default) == 0 { + f.addFlag(&FlagVar{ + Name: s.Name, + Usage: s.Usage, + Group: s.Group, + Default: nil, + }) + } else { + f.addFlag(&FlagVar{ + Name: s.Name, + Usage: s.Usage, + Group: s.Group, + Default: strings.Join(s.Default, ","), + }) + } f.set.Var(s, s.Name, s.Usage) } @@ -265,33 +300,39 @@ type DurationFlag struct { func (f *Flagset) DurationFlag(d *DurationFlag) { f.addFlag(&FlagVar{ - Name: d.Name, - Usage: d.Usage, - Group: d.Group, + Name: d.Name, + Usage: d.Usage, + Group: d.Group, + Default: d.Default, }) f.set.DurationVar(d.Value, d.Name, d.Default, "") } type MapStringFlag struct { - Name string - Usage string - Value *map[string]string - Group string + Name string + Usage string + Value *map[string]string + Group string + Default map[string]string } -func (m *MapStringFlag) String() string { - if m.Value == nil { +func formatMapString(m map[string]string) string { + if len(m) == 0 { return "" } ls := []string{} - for k, v := range *m.Value { + for k, v := range m { ls = append(ls, k+"="+v) } return strings.Join(ls, ",") } +func (m *MapStringFlag) String() string { + return formatMapString(*m.Value) +} + func (m *MapStringFlag) Set(value string) error { if m.Value == nil { m.Value = &map[string]string{} @@ -311,11 +352,21 @@ func (m *MapStringFlag) Set(value string) error { } func (f *Flagset) MapStringFlag(m *MapStringFlag) { - f.addFlag(&FlagVar{ - Name: m.Name, - Usage: m.Usage, - Group: m.Group, - }) + if m.Default == nil || len(m.Default) == 0 { + f.addFlag(&FlagVar{ + Name: m.Name, + Usage: m.Usage, + Group: m.Group, + Default: nil, + }) + } else { + f.addFlag(&FlagVar{ + Name: m.Name, + Usage: m.Usage, + Group: m.Group, + Default: formatMapString(m.Default), + }) + } f.set.Var(m, m.Name, m.Usage) } @@ -329,9 +380,10 @@ type Float64Flag struct { func (f *Flagset) Float64Flag(i *Float64Flag) { f.addFlag(&FlagVar{ - Name: i.Name, - Usage: i.Usage, - Group: i.Group, + Name: i.Name, + Usage: i.Usage, + Group: i.Group, + Default: i.Default, }) f.set.Float64Var(i.Value, i.Name, i.Default, "") } diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index a53e1c3e46..c1560d9347 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -16,10 +16,11 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.Chain, }) f.StringFlag(&flagset.StringFlag{ - Name: "identity", - Usage: "Name/Identity of the node", - Value: &c.cliConfig.Identity, - Default: c.cliConfig.Identity, + Name: "identity", + Usage: "Name/Identity of the node", + Value: &c.cliConfig.Identity, + Default: c.cliConfig.Identity, + HideDefaultFromDoc: true, }) f.StringFlag(&flagset.StringFlag{ Name: "log-level", @@ -28,10 +29,11 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.LogLevel, }) f.StringFlag(&flagset.StringFlag{ - Name: "datadir", - Usage: "Path of the data directory to store information", - Value: &c.cliConfig.DataDir, - Default: c.cliConfig.DataDir, + Name: "datadir", + Usage: "Path of the data directory to store information", + Value: &c.cliConfig.DataDir, + Default: c.cliConfig.DataDir, + HideDefaultFromDoc: true, }) f.StringFlag(&flagset.StringFlag{ Name: "datadir.ancient", @@ -62,19 +64,20 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.GcMode, }) f.MapStringFlag(&flagset.MapStringFlag{ - Name: "eth.requiredblocks", - Usage: "Comma separated block number-to-hash mappings to require for peering (=)", - Value: &c.cliConfig.RequiredBlocks, + Name: "eth.requiredblocks", + Usage: "Comma separated block number-to-hash mappings to require for peering (=)", + Value: &c.cliConfig.RequiredBlocks, + Default: c.cliConfig.RequiredBlocks, }) f.BoolFlag(&flagset.BoolFlag{ Name: "snapshot", - Usage: `Enables the snapshot-database mode (default = true)`, + Usage: `Enables the snapshot-database mode`, Value: &c.cliConfig.Snapshot, Default: c.cliConfig.Snapshot, }) f.BoolFlag(&flagset.BoolFlag{ Name: "bor.logs", - Usage: `Enables bor log retrieval (default = false)`, + Usage: `Enables bor log retrieval`, Value: &c.cliConfig.BorLogs, Default: c.cliConfig.BorLogs, }) @@ -202,10 +205,11 @@ func (c *Command) Flags() *flagset.Flagset { Group: "Sealer", }) f.BigIntFlag(&flagset.BigIntFlag{ - Name: "miner.gasprice", - Usage: "Minimum gas price for mining a transaction", - Value: c.cliConfig.Sealer.GasPrice, - Group: "Sealer", + Name: "miner.gasprice", + Usage: "Minimum gas price for mining a transaction", + Value: c.cliConfig.Sealer.GasPrice, + Group: "Sealer", + Default: c.cliConfig.Sealer.GasPrice, }) // ethstats @@ -230,20 +234,22 @@ func (c *Command) Flags() *flagset.Flagset { Default: c.cliConfig.Gpo.Percentile, }) f.BigIntFlag(&flagset.BigIntFlag{ - Name: "gpo.maxprice", - Usage: "Maximum gas price will be recommended by gpo", - Value: c.cliConfig.Gpo.MaxPrice, + Name: "gpo.maxprice", + Usage: "Maximum gas price will be recommended by gpo", + Value: c.cliConfig.Gpo.MaxPrice, + Default: c.cliConfig.Gpo.MaxPrice, }) f.BigIntFlag(&flagset.BigIntFlag{ - Name: "gpo.ignoreprice", - Usage: "Gas price below which gpo will ignore transactions", - Value: c.cliConfig.Gpo.IgnorePrice, + Name: "gpo.ignoreprice", + Usage: "Gas price below which gpo will ignore transactions", + Value: c.cliConfig.Gpo.IgnorePrice, + Default: c.cliConfig.Gpo.IgnorePrice, }) // cache options f.Uint64Flag(&flagset.Uint64Flag{ Name: "cache", - Usage: "Megabytes of memory allocated to internal caching (default = 4096 mainnet full node)", + Usage: "Megabytes of memory allocated to internal caching", Value: &c.cliConfig.Cache.Cache, Default: c.cliConfig.Cache.Cache, Group: "Cache", @@ -257,7 +263,7 @@ func (c *Command) Flags() *flagset.Flagset { }) f.Uint64Flag(&flagset.Uint64Flag{ Name: "cache.trie", - Usage: "Percentage of cache memory allowance to use for trie caching (default = 15% full mode, 30% archive mode)", + Usage: "Percentage of cache memory allowance to use for trie caching", Value: &c.cliConfig.Cache.PercTrie, Default: c.cliConfig.Cache.PercTrie, Group: "Cache", @@ -278,14 +284,14 @@ func (c *Command) Flags() *flagset.Flagset { }) f.Uint64Flag(&flagset.Uint64Flag{ Name: "cache.gc", - Usage: "Percentage of cache memory allowance to use for trie pruning (default = 25% full mode, 0% archive mode)", + Usage: "Percentage of cache memory allowance to use for trie pruning", Value: &c.cliConfig.Cache.PercGc, Default: c.cliConfig.Cache.PercGc, Group: "Cache", }) f.Uint64Flag(&flagset.Uint64Flag{ Name: "cache.snapshot", - Usage: "Percentage of cache memory allowance to use for snapshot caching (default = 10% full mode, 20% archive mode)", + Usage: "Percentage of cache memory allowance to use for snapshot caching", Value: &c.cliConfig.Cache.PercSnapshot, Default: c.cliConfig.Cache.PercSnapshot, Group: "Cache", @@ -306,7 +312,7 @@ func (c *Command) Flags() *flagset.Flagset { }) f.Uint64Flag(&flagset.Uint64Flag{ Name: "txlookuplimit", - Usage: "Number of recent blocks to maintain transactions index for (default = about 56 days, 0 = entire chain)", + Usage: "Number of recent blocks to maintain transactions index for", Value: &c.cliConfig.Cache.TxLookupLimit, Default: c.cliConfig.Cache.TxLookupLimit, Group: "Cache", @@ -569,10 +575,11 @@ func (c *Command) Flags() *flagset.Flagset { Group: "Telemetry", }) f.MapStringFlag(&flagset.MapStringFlag{ - Name: "metrics.influxdb.tags", - Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements", - Value: &c.cliConfig.Telemetry.InfluxDB.Tags, - Group: "Telemetry", + Name: "metrics.influxdb.tags", + Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements", + Value: &c.cliConfig.Telemetry.InfluxDB.Tags, + Group: "Telemetry", + Default: c.cliConfig.Telemetry.InfluxDB.Tags, }) f.StringFlag(&flagset.StringFlag{ Name: "metrics.prometheus-addr", From ddf1a4db8ca805705ecc4b20dc063b3ec5e9e875 Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 13 Dec 2022 23:46:43 -0800 Subject: [PATCH 6/8] Add a summary of new CLI in docs --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 4622bb8f00..2f75b218e4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ # Documentation -- [The new command line interface](./cli) +[The new command line interface (CLI)](./cli) in this version of Bor aims to give users more control over the codebase when interacting with and starting a node. We have made every effort to keep most of the flags similar to the old CLI, except for a few notable changes. One major change is the use of the --config flag, which previously represented fields without available flags. It now represents all flags available to the user, and will overwrite any other flags if provided. As a node operator, you still have the flexibility to modify flags as needed. Please note that this change does not affect the internal functionality of the node, and it remains compatible with Geth and the Ethereum Virtual Machine (EVM). ## Additional notes From b7ed9de45b4339e09ce50fb8990623059766bb6f Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 14 Dec 2022 14:18:56 -0800 Subject: [PATCH 7/8] Add state pruning to new CLI --- docs/cli/README.md | 4 + docs/cli/account_import.md | 2 +- docs/cli/account_list.md | 2 +- docs/cli/account_new.md | 2 +- docs/cli/server.md | 4 + docs/cli/snapshot.md | 5 + docs/cli/snapshot_prune-state.md | 21 ++++ internal/cli/command.go | 12 +- internal/cli/removedb.go | 7 +- internal/cli/server/config.go | 4 +- internal/cli/snapshot.go | 183 +++++++++++++++++++++++++++++++ 11 files changed, 237 insertions(+), 9 deletions(-) create mode 100644 docs/cli/snapshot.md create mode 100644 docs/cli/snapshot_prune-state.md create mode 100644 internal/cli/snapshot.go diff --git a/docs/cli/README.md b/docs/cli/README.md index bf37d6ef56..d52a4fd836 100644 --- a/docs/cli/README.md +++ b/docs/cli/README.md @@ -44,6 +44,10 @@ - [```server```](./server.md) +- [```snapshot```](./snapshot.md) + +- [```snapshot prune-state```](./snapshot_prune-state.md) + - [```status```](./status.md) - [```version```](./version.md) \ No newline at end of file diff --git a/docs/cli/account_import.md b/docs/cli/account_import.md index d7b02195bc..697d951fd3 100644 --- a/docs/cli/account_import.md +++ b/docs/cli/account_import.md @@ -6,4 +6,4 @@ The ```account import``` command imports an account in Json format to the Bor da - ```datadir```: Path of the data directory to store information -- ```keystore```: Path of the data directory to store information \ No newline at end of file +- ```keystore```: Path of the data directory to store keys \ No newline at end of file diff --git a/docs/cli/account_list.md b/docs/cli/account_list.md index 61ebf9e776..a11b4a05e7 100644 --- a/docs/cli/account_list.md +++ b/docs/cli/account_list.md @@ -6,4 +6,4 @@ The `account list` command lists all the accounts in the Bor data directory. - ```datadir```: Path of the data directory to store information -- ```keystore```: Path of the data directory to store information \ No newline at end of file +- ```keystore```: Path of the data directory to store keys \ No newline at end of file diff --git a/docs/cli/account_new.md b/docs/cli/account_new.md index dd62061ba0..bd47ecb371 100644 --- a/docs/cli/account_new.md +++ b/docs/cli/account_new.md @@ -6,4 +6,4 @@ The `account new` command creates a new local account file on the Bor data direc - ```datadir```: Path of the data directory to store information -- ```keystore```: Path of the data directory to store information \ No newline at end of file +- ```keystore```: Path of the data directory to store keys \ No newline at end of file diff --git a/docs/cli/server.md b/docs/cli/server.md index 777856de34..5bc0ff1024 100644 --- a/docs/cli/server.md +++ b/docs/cli/server.md @@ -32,6 +32,8 @@ The ```bor server``` command runs the Bor client. - ```bor.withoutheimdall```: Run without Heimdall service (for testing purpose) (default: false) +- ```bor.heimdallgRPC```: Address of Heimdall gRPC service + - ```ethstats```: Reporting URL of a ethstats service (nodename:secret@host:port) - ```gpo.blocks```: Number of recent blocks to check for gas prices (default: 20) @@ -80,6 +82,8 @@ The ```bor server``` command runs the Bor client. - ```cache.preimages```: Enable recording the SHA3/keccak preimages of trie keys (default: false) +- ```cache.triesinmemory```: Number of block states (tries) to keep in memory (default = 128) (default: 128) + - ```txlookuplimit```: Number of recent blocks to maintain transactions index for (default: 2350000) ### JsonRPC Options diff --git a/docs/cli/snapshot.md b/docs/cli/snapshot.md new file mode 100644 index 0000000000..8a7a6b96e5 --- /dev/null +++ b/docs/cli/snapshot.md @@ -0,0 +1,5 @@ +# snapshot + +The ```snapshot``` command groups snapshot related actions: + +- [```snapshot prune-state```](./snapshot_prune-state.md): Joins the local client to another remote peer. \ No newline at end of file diff --git a/docs/cli/snapshot_prune-state.md b/docs/cli/snapshot_prune-state.md new file mode 100644 index 0000000000..73742faeac --- /dev/null +++ b/docs/cli/snapshot_prune-state.md @@ -0,0 +1,21 @@ +# Prune state + +The ```bor snapshot prune-state``` command will prune historical state data with the help of the state snapshot. All trie nodes and contract codes that do not belong to the specified version state will be deleted from the database. After pruning, only two version states are available: genesis and the specific one. + +## Options + +- ```datadir```: Path of the data directory to store information + +- ```keystore```: Path of the data directory to store keys + +- ```datadir.ancient```: Path of the ancient data directory to store information + +- ```bloomfilter.size```: Size of the bloom filter (default: 2048) + +### Cache Options + +- ```cache```: Megabytes of memory allocated to internal caching (default: 1024) + +- ```cache.trie```: Percentage of cache memory allowance to use for trie caching (default: 25) + +- ```cache.trie.journal```: Path of the trie journal directory to store information (default: triecache) \ No newline at end of file diff --git a/internal/cli/command.go b/internal/cli/command.go index 93dca4cb3e..95f7776df6 100644 --- a/internal/cli/command.go +++ b/internal/cli/command.go @@ -189,6 +189,16 @@ func Commands() map[string]MarkDownCommandFactory { Meta2: meta2, }, nil }, + "snapshot": func() (MarkDownCommand, error) { + return &SnapshotCommand{ + UI: ui, + }, nil + }, + "snapshot prune-state": func() (MarkDownCommand, error) { + return &PruneStateCommand{ + Meta: meta, + }, nil + }, } } @@ -248,7 +258,7 @@ func (m *Meta) NewFlagSet(n string) *flagset.Flagset { f.StringFlag(&flagset.StringFlag{ Name: "keystore", Value: &m.keyStoreDir, - Usage: "Path of the data directory to store information", + Usage: "Path of the data directory to store keys", }) return f diff --git a/internal/cli/removedb.go b/internal/cli/removedb.go index 4a604086ed..224dae95d5 100644 --- a/internal/cli/removedb.go +++ b/internal/cli/removedb.go @@ -24,9 +24,10 @@ type RemoveDBCommand struct { } const ( - chaindataPath string = "chaindata" - ancientPath string = "ancient" - lightchaindataPath string = "lightchaindata" + chaindataPath string = "chaindata" + ancientPath string = "ancient" + trieCacheJournalPath string = "triecache" + lightchaindataPath string = "lightchaindata" ) // MarkDown implements cli.MarkDown interface diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 1ab0a83712..35d7e19359 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -686,7 +686,7 @@ func (c *Config) loadChain() error { //nolint:gocognit func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*ethconfig.Config, error) { - dbHandles, err := makeDatabaseHandles() + dbHandles, err := MakeDatabaseHandles() if err != nil { return nil, err } @@ -1075,7 +1075,7 @@ func (c *Config) Merge(cc ...*Config) error { return nil } -func makeDatabaseHandles() (int, error) { +func MakeDatabaseHandles() (int, error) { limit, err := fdlimit.Maximum() if err != nil { return -1, err diff --git a/internal/cli/snapshot.go b/internal/cli/snapshot.go new file mode 100644 index 0000000000..b48712d35f --- /dev/null +++ b/internal/cli/snapshot.go @@ -0,0 +1,183 @@ +// Snapshot related commands + +package cli + +import ( + "strings" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state/pruner" + "github.com/ethereum/go-ethereum/internal/cli/flagset" + "github.com/ethereum/go-ethereum/internal/cli/server" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/node" + + "github.com/mitchellh/cli" +) + +// SnapshotCommand is the command to group the snapshot commands +type SnapshotCommand struct { + UI cli.Ui +} + +// MarkDown implements cli.MarkDown interface +func (a *SnapshotCommand) MarkDown() string { + items := []string{ + "# snapshot", + "The ```snapshot``` command groups snapshot related actions:", + "- [```snapshot prune-state```](./snapshot_prune-state.md): Joins the local client to another remote peer.", + } + + return strings.Join(items, "\n\n") +} + +// Help implements the cli.Command interface +func (c *SnapshotCommand) Help() string { + return `Usage: bor snapshot + + This command groups snapshot related actions. + + Prune the state trie: + + $ bor snapshot prune-state` +} + +// Synopsis implements the cli.Command interface +func (c *SnapshotCommand) Synopsis() string { + return "Snapshot related commands" +} + +// Run implements the cli.Command interface +func (c *SnapshotCommand) Run(args []string) int { + return cli.RunResultHelp +} + +type PruneStateCommand struct { + *Meta + + datadirAncient string + cache uint64 + cacheTrie uint64 + cacheTrieJournal string + bloomfilterSize uint64 +} + +// MarkDown implements cli.MarkDown interface +func (c *PruneStateCommand) MarkDown() string { + items := []string{ + "# Prune state", + "The ```bor snapshot prune-state``` command will prune historical state data with the help of the state snapshot. All trie nodes and contract codes that do not belong to the specified version state will be deleted from the database. After pruning, only two version states are available: genesis and the specific one.", + c.Flags().MarkDown(), + } + + return strings.Join(items, "\n\n") +} + +// Help implements the cli.Command interface +func (c *PruneStateCommand) Help() string { + return `Usage: bor snapshot prune-state + + This command will prune state databases at the given datadir location` + c.Flags().Help() +} + +// Synopsis implements the cli.Command interface +func (c *PruneStateCommand) Synopsis() string { + return "Prune state databases" +} + +// Flags: datadir, datadir.ancient, cache.trie.journal, bloomfilter.size +func (c *PruneStateCommand) Flags() *flagset.Flagset { + flags := c.NewFlagSet("prune-state") + + flags.StringFlag(&flagset.StringFlag{ + Name: "datadir.ancient", + Value: &c.datadirAncient, + Usage: "Path of the ancient data directory to store information", + Default: "", + }) + + flags.Uint64Flag(&flagset.Uint64Flag{ + Name: "cache", + Usage: "Megabytes of memory allocated to internal caching", + Value: &c.cache, + Default: 1024.0, + Group: "Cache", + }) + + flags.Uint64Flag(&flagset.Uint64Flag{ + Name: "cache.trie", + Usage: "Percentage of cache memory allowance to use for trie caching", + Value: &c.cacheTrie, + Default: 25, + Group: "Cache", + }) + + flags.StringFlag(&flagset.StringFlag{ + Name: "cache.trie.journal", + Value: &c.cacheTrieJournal, + Usage: "Path of the trie journal directory to store information", + Default: trieCacheJournalPath, + Group: "Cache", + }) + + flags.Uint64Flag(&flagset.Uint64Flag{ + Name: "bloomfilter.size", + Value: &c.bloomfilterSize, + Usage: "Size of the bloom filter", + Default: 2048, + }) + + return flags +} + +// Run implements the cli.Command interface +func (c *PruneStateCommand) Run(args []string) int { + flags := c.Flags() + + if err := flags.Parse(args); err != nil { + c.UI.Error(err.Error()) + return 1 + } + + datadir := c.dataDir + if datadir == "" { + c.UI.Error("datadir is required") + return 1 + } + + // Create the node + node, err := node.New(&node.Config{ + DataDir: datadir, + }) + + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + dbHandles, err := server.MakeDatabaseHandles() + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + chaindb, err := node.OpenDatabaseWithFreezer(chaindataPath, int(c.cache), dbHandles, c.datadirAncient, "", false) + + if err != nil { + c.UI.Error(err.Error()) + return 1 + } + + pruner, err := pruner.NewPruner(chaindb, node.ResolvePath(""), node.ResolvePath(c.cacheTrieJournal), c.bloomfilterSize) + if err != nil { + log.Error("Failed to open snapshot tree", "err", err) + return 1 + } + + if err = pruner.Prune(common.Hash{}); err != nil { + log.Error("Failed to prune state", "err", err) + return 1 + } + + return 0 +} From 9b2407a58f8b94f9101869f850171731144b014f Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 14 Dec 2022 21:48:54 -0800 Subject: [PATCH 8/8] Minor wording fix in prune state description --- docs/cli/snapshot.md | 2 +- internal/cli/snapshot.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cli/snapshot.md b/docs/cli/snapshot.md index 8a7a6b96e5..376220749b 100644 --- a/docs/cli/snapshot.md +++ b/docs/cli/snapshot.md @@ -2,4 +2,4 @@ The ```snapshot``` command groups snapshot related actions: -- [```snapshot prune-state```](./snapshot_prune-state.md): Joins the local client to another remote peer. \ No newline at end of file +- [```snapshot prune-state```](./snapshot_prune-state.md): Prune state databases at the given datadir location. \ No newline at end of file diff --git a/internal/cli/snapshot.go b/internal/cli/snapshot.go index b48712d35f..3c8e4ec97d 100644 --- a/internal/cli/snapshot.go +++ b/internal/cli/snapshot.go @@ -25,7 +25,7 @@ func (a *SnapshotCommand) MarkDown() string { items := []string{ "# snapshot", "The ```snapshot``` command groups snapshot related actions:", - "- [```snapshot prune-state```](./snapshot_prune-state.md): Joins the local client to another remote peer.", + "- [```snapshot prune-state```](./snapshot_prune-state.md): Prune state databases at the given datadir location.", } return strings.Join(items, "\n\n")