mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
commit
06f29851a3
22 changed files with 647 additions and 184 deletions
2
.github/ISSUE_TEMPLATE/bug.md
vendored
2
.github/ISSUE_TEMPLATE/bug.md
vendored
|
|
@ -6,7 +6,7 @@ labels: 'type:bug'
|
||||||
assignees: ''
|
assignees: ''
|
||||||
---
|
---
|
||||||
|
|
||||||
Our support team has aggregated some common issues and their solutions from past which are faced while running or interacting with a bor client. In order to prevent redundant efforts, we would encourage you to have a look at the [FAQ's section](https://wiki.polygon.technology/docs/faq/technical-faqs/) of our documentation mentioning the same, before filing an issue here. In case of additional support, you can also join our [discord](https://discord.com/invite/zdwkdvMNY2) server
|
Our support team has aggregated some common issues and their solutions from past which are faced while running or interacting with a bor client. In order to prevent redundant efforts, we would encourage you to have a look at the [FAQ's section](https://wiki.polygon.technology/docs/faq/technical-faqs/) of our documentation mentioning the same, before filing an issue here. In case of additional support, you can also join our [discord](https://discord.com/invite/0xPolygonDevs) server
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
NOTE: Please make sure to check of any addresses / private keys / rpc url's / IP's before sharing the logs or anything from the additional information section (start.sh or heimdall config).
|
NOTE: Please make sure to check of any addresses / private keys / rpc url's / IP's before sharing the logs or anything from the additional information section (start.sh or heimdall config).
|
||||||
|
|
|
||||||
2
.github/ISSUE_TEMPLATE/question.md
vendored
2
.github/ISSUE_TEMPLATE/question.md
vendored
|
|
@ -8,4 +8,4 @@ assignees: ''
|
||||||
|
|
||||||
This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation.
|
This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation.
|
||||||
|
|
||||||
For general questions please join our [discord](https://discord.com/invite/zdwkdvMNY2) server.
|
For general questions please join our [discord](https://discord.com/invite/0xPolygonDevs) server.
|
||||||
|
|
|
||||||
19
.github/workflows/ci.yml
vendored
19
.github/workflows/ci.yml
vendored
|
|
@ -107,6 +107,11 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test
|
run: make test
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: unitTest-coverage
|
||||||
|
path: cover.out
|
||||||
|
|
||||||
#- name: Data race tests
|
#- name: Data race tests
|
||||||
# run: make test-race
|
# run: make test-race
|
||||||
|
|
||||||
|
|
@ -153,17 +158,25 @@ jobs:
|
||||||
- name: test-integration
|
- name: test-integration
|
||||||
run: make test-integration
|
run: make test-integration
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: integrationTest-coverage
|
||||||
|
path: cover.out
|
||||||
|
|
||||||
codecov:
|
codecov:
|
||||||
if: (github.event.action != 'closed' || github.event.pull_request.merged == true)
|
if: (github.event.action != 'closed' || github.event.pull_request.merged == true)
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-20.04 ] # list of os: https://github.com/actions/virtual-environments
|
os: [ ubuntu-20.04 ] # list of os: https://github.com/actions/virtual-environments
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
needs: [unit-tests, integration-tests]
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Download artifacts
|
||||||
|
uses: actions/download-artifact@v2
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v3
|
||||||
with:
|
|
||||||
file: ./cover.out
|
|
||||||
|
|
||||||
e2e-tests:
|
e2e-tests:
|
||||||
if: (github.event.action != 'closed' || github.event.pull_request.merged == true)
|
if: (github.event.action != 'closed' || github.event.pull_request.merged == true)
|
||||||
|
|
|
||||||
41
.github/workflows/codeql.yml
vendored
Normal file
41
.github/workflows/codeql.yml
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master", "develop" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master", "develop" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
|
||||||
|
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'go' ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
|
with:
|
||||||
|
category: "/language:${{matrix.language}}"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: Security CI
|
name: Govuln
|
||||||
on: [ push, pull_request ]
|
on: [ push, pull_request ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -8,12 +8,12 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Running govulncheck
|
- name: Running govulncheck
|
||||||
uses: Templum/govulncheck-action@v0.10.1
|
uses: Templum/govulncheck-action@v1.0.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
DEBUG: "true"
|
DEBUG: "true"
|
||||||
with:
|
with:
|
||||||
go-version: 1.20.5
|
go-version: 1.21
|
||||||
package: ./...
|
package: ./...
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
fail-on-vuln: true
|
fail-on-vuln: true
|
||||||
41
.snyk
41
.snyk
|
|
@ -1,41 +0,0 @@
|
||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.25.0
|
|
||||||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
|
||||||
ignore:
|
|
||||||
'snyk:lic:golang:github.com:karalabe:usb:LGPL-3.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:06:37.028Z
|
|
||||||
'snyk:lic:golang:github.com:mitchellh:cli:MPL-2.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:07:42.661Z
|
|
||||||
'snyk:lic:golang:github.com:hashicorp:hcl:v2:MPL-2.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:09:08.112Z
|
|
||||||
'snyk:lic:golang:github.com:hashicorp:go-multierror:MPL-2.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:09:14.673Z
|
|
||||||
'snyk:lic:golang:github.com:hashicorp:go-bexpr:MPL-2.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:09:21.843Z
|
|
||||||
'snyk:lic:golang:github.com:hashicorp:errwrap:MPL-2.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:09:28.257Z
|
|
||||||
'snyk:lic:golang:github.com:ethereum:go-ethereum:LGPL-3.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:09:35.273Z
|
|
||||||
'snyk:lic:golang:github.com:maticnetwork:polyproto:GPL-3.0':
|
|
||||||
- '*':
|
|
||||||
reason: 'As open source org, we have no issues with licenses'
|
|
||||||
created: 2022-11-11T08:09:41.635Z
|
|
||||||
'SNYK-GOLANG-GOLANGORGXNETHTTP2-3160322':
|
|
||||||
- '*':
|
|
||||||
reason: 'grpc working on a release to fix the issue'
|
|
||||||
created: 2022-12-12T06:50:00.000Z
|
|
||||||
patch: {}
|
|
||||||
5
Makefile
5
Makefile
|
|
@ -66,8 +66,11 @@ test-txpool-race:
|
||||||
test-race:
|
test-race:
|
||||||
$(GOTEST) --timeout 15m -race -shuffle=on $(TESTALL)
|
$(GOTEST) --timeout 15m -race -shuffle=on $(TESTALL)
|
||||||
|
|
||||||
|
gocovmerge-deps:
|
||||||
|
$(GOBUILD) -o $(GOBIN)/gocovmerge github.com/wadey/gocovmerge
|
||||||
|
|
||||||
test-integration:
|
test-integration:
|
||||||
$(GOTEST) --timeout 60m -tags integration $(TESTE2E)
|
$(GOTEST) --timeout 60m -cover -coverprofile=cover.out -covermode=atomic -tags integration $(TESTE2E)
|
||||||
|
|
||||||
escape:
|
escape:
|
||||||
cd $(path) && go test -gcflags "-m -m" -run none -bench=BenchmarkJumpdest* -benchmem -memprofile mem.out
|
cd $(path) && go test -gcflags "-m -m" -run none -bench=BenchmarkJumpdest* -benchmem -memprofile mem.out
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/6874
|
||||||
)](https://pkg.go.dev/github.com/maticnetwork/bor)
|
)](https://pkg.go.dev/github.com/maticnetwork/bor)
|
||||||
[](https://goreportcard.com/report/github.com/maticnetwork/bor)
|
[](https://goreportcard.com/report/github.com/maticnetwork/bor)
|
||||||

|

|
||||||
[](https://discord.gg/zdwkdvMNY2)
|
[](https://discord.com/invite/0xPolygonDevs)
|
||||||
[](https://twitter.com/0xPolygon)
|
[](https://twitter.com/0xPolygon)
|
||||||
|
|
||||||
### Installing bor using packaging
|
### Installing bor using packaging
|
||||||
|
|
@ -79,4 +79,4 @@ included in our repository in the `COPYING` file.
|
||||||
|
|
||||||
## Join our Discord server
|
## Join our Discord server
|
||||||
|
|
||||||
Join Polygon community – share your ideas or just say hi over [on Discord](https://discord.gg/zdwkdvMNY2).
|
Join Polygon community – share your ideas or just say hi over [on Discord](https://discord.com/invite/0xPolygonDevs).
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,14 @@ func (w *trezorDriver) trezorExchange(req proto.Message, results ...proto.Messag
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := make([]byte, 8+len(data))
|
var payload []byte
|
||||||
|
|
||||||
|
if len(data) < 64*1024*1024 {
|
||||||
|
payload = make([]byte, 8+len(data))
|
||||||
|
} else {
|
||||||
|
return 0, errors.New("data too large")
|
||||||
|
}
|
||||||
|
|
||||||
copy(payload, []byte{0x23, 0x23})
|
copy(payload, []byte{0x23, 0x23})
|
||||||
binary.BigEndian.PutUint16(payload[2:], trezor.Type(req))
|
binary.BigEndian.PutUint16(payload[2:], trezor.Type(req))
|
||||||
binary.BigEndian.PutUint32(payload[4:], uint32(len(data)))
|
binary.BigEndian.PutUint32(payload[4:], uint32(len(data)))
|
||||||
|
|
|
||||||
8
go.mod
8
go.mod
|
|
@ -77,11 +77,11 @@ require (
|
||||||
github.com/tendermint/tendermint v0.34.21
|
github.com/tendermint/tendermint v0.34.21
|
||||||
github.com/tyler-smith/go-bip39 v1.1.0
|
github.com/tyler-smith/go-bip39 v1.1.0
|
||||||
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
|
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
|
||||||
golang.org/x/crypto v0.11.0
|
golang.org/x/crypto v0.14.0
|
||||||
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
|
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
|
||||||
golang.org/x/sync v0.3.0
|
golang.org/x/sync v0.3.0
|
||||||
golang.org/x/sys v0.12.0
|
golang.org/x/sys v0.13.0
|
||||||
golang.org/x/text v0.11.0
|
golang.org/x/text v0.13.0
|
||||||
golang.org/x/time v0.3.0
|
golang.org/x/time v0.3.0
|
||||||
golang.org/x/tools v0.10.0
|
golang.org/x/tools v0.10.0
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
||||||
|
|
@ -159,7 +159,7 @@ require (
|
||||||
go.opentelemetry.io/otel/sdk v1.19.0
|
go.opentelemetry.io/otel/sdk v1.19.0
|
||||||
go.uber.org/goleak v1.2.1
|
go.uber.org/goleak v1.2.1
|
||||||
golang.org/x/mod v0.11.0 // indirect
|
golang.org/x/mod v0.11.0 // indirect
|
||||||
golang.org/x/net v0.12.0 // indirect
|
golang.org/x/net v0.17.0 // indirect
|
||||||
gonum.org/v1/gonum v0.11.0
|
gonum.org/v1/gonum v0.11.0
|
||||||
google.golang.org/grpc v1.58.2
|
google.golang.org/grpc v1.58.2
|
||||||
google.golang.org/protobuf v1.31.0
|
google.golang.org/protobuf v1.31.0
|
||||||
|
|
|
||||||
13
go.sum
13
go.sum
|
|
@ -2239,8 +2239,9 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw
|
||||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||||
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
|
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
|
||||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
|
||||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||||
|
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||||
|
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||||
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
|
@ -2400,8 +2401,9 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
|
||||||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||||
|
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||||
|
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
|
@ -2596,8 +2598,8 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
|
@ -2628,8 +2630,9 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
|
||||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func (c *DumpconfigCommand) Synopsis() string {
|
||||||
func (c *DumpconfigCommand) Run(args []string) int {
|
func (c *DumpconfigCommand) Run(args []string) int {
|
||||||
// Initialize an empty command instance to get flags
|
// Initialize an empty command instance to get flags
|
||||||
command := server.Command{}
|
command := server.Command{}
|
||||||
flags := command.Flags()
|
flags := command.Flags(nil)
|
||||||
|
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
|
|
|
||||||
|
|
@ -5,33 +5,42 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Flagset struct {
|
type Flagset struct {
|
||||||
flags []*FlagVar
|
flags map[string]*FlagVar
|
||||||
set *flag.FlagSet
|
set *flag.FlagSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFlagSet(name string) *Flagset {
|
func NewFlagSet(name string) *Flagset {
|
||||||
f := &Flagset{
|
f := &Flagset{
|
||||||
flags: []*FlagVar{},
|
flags: make(map[string]*FlagVar, 0),
|
||||||
set: flag.NewFlagSet(name, flag.ContinueOnError),
|
set: flag.NewFlagSet(name, flag.ContinueOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updatable is a minimalistic representation of a flag which has
|
||||||
|
// the method `UpdateValue` implemented which can be called while
|
||||||
|
// overwriting flags.
|
||||||
|
type Updatable interface {
|
||||||
|
UpdateValue(string)
|
||||||
|
}
|
||||||
|
|
||||||
type FlagVar struct {
|
type FlagVar struct {
|
||||||
Name string
|
Name string
|
||||||
Usage string
|
Usage string
|
||||||
Group string
|
Group string
|
||||||
Default any
|
Default any
|
||||||
|
Value Updatable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Flagset) addFlag(fl *FlagVar) {
|
func (f *Flagset) addFlag(fl *FlagVar) {
|
||||||
f.flags = append(f.flags, fl)
|
f.flags[fl.Name] = fl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Flagset) Help() string {
|
func (f *Flagset) Help() string {
|
||||||
|
|
@ -51,9 +60,12 @@ func (f *Flagset) Help() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Flagset) GetAllFlags() []string {
|
func (f *Flagset) GetAllFlags() []string {
|
||||||
flags := []string{}
|
i := 0
|
||||||
for _, flag := range f.flags {
|
flags := make([]string, 0, len(f.flags))
|
||||||
flags = append(flags, flag.Name)
|
|
||||||
|
for name := range f.flags {
|
||||||
|
flags[i] = name
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
|
|
@ -110,6 +122,33 @@ func (f *Flagset) Args() []string {
|
||||||
return f.set.Args()
|
return f.set.Args()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateValue updates the underlying value of a flag
|
||||||
|
// given the flag name and value to update using pointer.
|
||||||
|
func (f *Flagset) UpdateValue(names []string, values []string) {
|
||||||
|
for i, name := range names {
|
||||||
|
if flag, ok := f.flags[name]; ok {
|
||||||
|
value := values[i]
|
||||||
|
|
||||||
|
// Call the underlying flag's `UpdateValue` method
|
||||||
|
flag.Value.UpdateValue(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Visit visits all the set flags and returns the name and value
|
||||||
|
// in string to set later.
|
||||||
|
func (f *Flagset) Visit() ([]string, []string) {
|
||||||
|
names := make([]string, 0, len(f.flags))
|
||||||
|
values := make([]string, 0, len(f.flags))
|
||||||
|
|
||||||
|
f.set.Visit(func(flag *flag.Flag) {
|
||||||
|
names = append(names, flag.Name)
|
||||||
|
values = append(values, flag.Value.String())
|
||||||
|
})
|
||||||
|
|
||||||
|
return names, values
|
||||||
|
}
|
||||||
|
|
||||||
type BoolFlag struct {
|
type BoolFlag struct {
|
||||||
Name string
|
Name string
|
||||||
Usage string
|
Usage string
|
||||||
|
|
@ -118,12 +157,19 @@ type BoolFlag struct {
|
||||||
Group string
|
Group string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BoolFlag) UpdateValue(value string) {
|
||||||
|
v, _ := strconv.ParseBool(value)
|
||||||
|
|
||||||
|
*b.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) BoolFlag(b *BoolFlag) {
|
func (f *Flagset) BoolFlag(b *BoolFlag) {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
Name: b.Name,
|
Name: b.Name,
|
||||||
Usage: b.Usage,
|
Usage: b.Usage,
|
||||||
Group: b.Group,
|
Group: b.Group,
|
||||||
Default: b.Default,
|
Default: b.Default,
|
||||||
|
Value: b,
|
||||||
})
|
})
|
||||||
f.set.BoolVar(b.Value, b.Name, b.Default, b.Usage)
|
f.set.BoolVar(b.Value, b.Name, b.Default, b.Usage)
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +183,10 @@ type StringFlag struct {
|
||||||
HideDefaultFromDoc bool
|
HideDefaultFromDoc bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *StringFlag) UpdateValue(value string) {
|
||||||
|
*b.Value = value
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) StringFlag(b *StringFlag) {
|
func (f *Flagset) StringFlag(b *StringFlag) {
|
||||||
if b.Default == "" || b.HideDefaultFromDoc {
|
if b.Default == "" || b.HideDefaultFromDoc {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
|
|
@ -144,6 +194,7 @@ func (f *Flagset) StringFlag(b *StringFlag) {
|
||||||
Usage: b.Usage,
|
Usage: b.Usage,
|
||||||
Group: b.Group,
|
Group: b.Group,
|
||||||
Default: nil,
|
Default: nil,
|
||||||
|
Value: b,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
|
|
@ -151,6 +202,7 @@ func (f *Flagset) StringFlag(b *StringFlag) {
|
||||||
Usage: b.Usage,
|
Usage: b.Usage,
|
||||||
Group: b.Group,
|
Group: b.Group,
|
||||||
Default: b.Default,
|
Default: b.Default,
|
||||||
|
Value: b,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,12 +217,19 @@ type IntFlag struct {
|
||||||
Group string
|
Group string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *IntFlag) UpdateValue(value string) {
|
||||||
|
v, _ := strconv.ParseInt(value, 10, 64)
|
||||||
|
|
||||||
|
*b.Value = int(v)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) IntFlag(i *IntFlag) {
|
func (f *Flagset) IntFlag(i *IntFlag) {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
Name: i.Name,
|
Name: i.Name,
|
||||||
Usage: i.Usage,
|
Usage: i.Usage,
|
||||||
Group: i.Group,
|
Group: i.Group,
|
||||||
Default: i.Default,
|
Default: i.Default,
|
||||||
|
Value: i,
|
||||||
})
|
})
|
||||||
f.set.IntVar(i.Value, i.Name, i.Default, i.Usage)
|
f.set.IntVar(i.Value, i.Name, i.Default, i.Usage)
|
||||||
}
|
}
|
||||||
|
|
@ -183,12 +242,19 @@ type Uint64Flag struct {
|
||||||
Group string
|
Group string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Uint64Flag) UpdateValue(value string) {
|
||||||
|
v, _ := strconv.ParseUint(value, 10, 64)
|
||||||
|
|
||||||
|
*b.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) Uint64Flag(i *Uint64Flag) {
|
func (f *Flagset) Uint64Flag(i *Uint64Flag) {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
Name: i.Name,
|
Name: i.Name,
|
||||||
Usage: i.Usage,
|
Usage: i.Usage,
|
||||||
Group: i.Group,
|
Group: i.Group,
|
||||||
Default: fmt.Sprintf("%d", i.Default),
|
Default: fmt.Sprintf("%d", i.Default),
|
||||||
|
Value: i,
|
||||||
})
|
})
|
||||||
f.set.Uint64Var(i.Value, i.Name, i.Default, i.Usage)
|
f.set.Uint64Var(i.Value, i.Name, i.Default, i.Usage)
|
||||||
}
|
}
|
||||||
|
|
@ -209,31 +275,47 @@ func (b *BigIntFlag) String() string {
|
||||||
return b.Value.String()
|
return b.Value.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BigIntFlag) Set(value string) error {
|
func parseBigInt(value string) *big.Int {
|
||||||
num := new(big.Int)
|
num := new(big.Int)
|
||||||
|
|
||||||
var ok bool
|
|
||||||
if strings.HasPrefix(value, "0x") {
|
if strings.HasPrefix(value, "0x") {
|
||||||
num, ok = num.SetString(value[2:], 16)
|
num, _ = num.SetString(value[2:], 16)
|
||||||
*b.Value = *num
|
|
||||||
} else {
|
} else {
|
||||||
num, ok = num.SetString(value, 10)
|
num, _ = num.SetString(value, 10)
|
||||||
*b.Value = *num
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
return num
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BigIntFlag) Set(value string) error {
|
||||||
|
num := parseBigInt(value)
|
||||||
|
|
||||||
|
if num == nil {
|
||||||
return fmt.Errorf("failed to set big int")
|
return fmt.Errorf("failed to set big int")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*b.Value = *num
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BigIntFlag) UpdateValue(value string) {
|
||||||
|
num := parseBigInt(value)
|
||||||
|
|
||||||
|
if num == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
*b.Value = *num
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) BigIntFlag(b *BigIntFlag) {
|
func (f *Flagset) BigIntFlag(b *BigIntFlag) {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
Name: b.Name,
|
Name: b.Name,
|
||||||
Usage: b.Usage,
|
Usage: b.Usage,
|
||||||
Group: b.Group,
|
Group: b.Group,
|
||||||
Default: b.Default,
|
Default: b.Default,
|
||||||
|
Value: b,
|
||||||
})
|
})
|
||||||
f.set.Var(b, b.Name, b.Usage)
|
f.set.Var(b, b.Name, b.Usage)
|
||||||
}
|
}
|
||||||
|
|
@ -273,6 +355,10 @@ func (i *SliceStringFlag) Set(value string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *SliceStringFlag) UpdateValue(value string) {
|
||||||
|
*i.Value = SplitAndTrim(value)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) SliceStringFlag(s *SliceStringFlag) {
|
func (f *Flagset) SliceStringFlag(s *SliceStringFlag) {
|
||||||
if s.Default == nil || len(s.Default) == 0 {
|
if s.Default == nil || len(s.Default) == 0 {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
|
|
@ -280,6 +366,7 @@ func (f *Flagset) SliceStringFlag(s *SliceStringFlag) {
|
||||||
Usage: s.Usage,
|
Usage: s.Usage,
|
||||||
Group: s.Group,
|
Group: s.Group,
|
||||||
Default: nil,
|
Default: nil,
|
||||||
|
Value: s,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
|
|
@ -287,6 +374,7 @@ func (f *Flagset) SliceStringFlag(s *SliceStringFlag) {
|
||||||
Usage: s.Usage,
|
Usage: s.Usage,
|
||||||
Group: s.Group,
|
Group: s.Group,
|
||||||
Default: strings.Join(s.Default, ","),
|
Default: strings.Join(s.Default, ","),
|
||||||
|
Value: s,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,12 +389,19 @@ type DurationFlag struct {
|
||||||
Group string
|
Group string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DurationFlag) UpdateValue(value string) {
|
||||||
|
v, _ := time.ParseDuration(value)
|
||||||
|
|
||||||
|
*d.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) DurationFlag(d *DurationFlag) {
|
func (f *Flagset) DurationFlag(d *DurationFlag) {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
Name: d.Name,
|
Name: d.Name,
|
||||||
Usage: d.Usage,
|
Usage: d.Usage,
|
||||||
Group: d.Group,
|
Group: d.Group,
|
||||||
Default: d.Default,
|
Default: d.Default,
|
||||||
|
Value: d,
|
||||||
})
|
})
|
||||||
f.set.DurationVar(d.Value, d.Name, d.Default, "")
|
f.set.DurationVar(d.Value, d.Name, d.Default, "")
|
||||||
}
|
}
|
||||||
|
|
@ -336,24 +431,38 @@ func (m *MapStringFlag) String() string {
|
||||||
return formatMapString(*m.Value)
|
return formatMapString(*m.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MapStringFlag) Set(value string) error {
|
func parseMap(value string) map[string]string {
|
||||||
if m.Value == nil {
|
m := make(map[string]string)
|
||||||
m.Value = &map[string]string{}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, t := range strings.Split(value, ",") {
|
for _, t := range strings.Split(value, ",") {
|
||||||
if t != "" {
|
if t != "" {
|
||||||
kv := strings.Split(t, "=")
|
kv := strings.Split(t, "=")
|
||||||
|
|
||||||
if len(kv) == 2 {
|
if len(kv) == 2 {
|
||||||
(*m.Value)[kv[0]] = kv[1]
|
m[kv[0]] = kv[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MapStringFlag) Set(value string) error {
|
||||||
|
if m.Value == nil {
|
||||||
|
m.Value = &map[string]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
m2 := parseMap(value)
|
||||||
|
*m.Value = m2
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MapStringFlag) UpdateValue(value string) {
|
||||||
|
m2 := parseMap(value)
|
||||||
|
*m.Value = m2
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) MapStringFlag(m *MapStringFlag) {
|
func (f *Flagset) MapStringFlag(m *MapStringFlag) {
|
||||||
if m.Default == nil || len(m.Default) == 0 {
|
if m.Default == nil || len(m.Default) == 0 {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
|
|
@ -361,6 +470,7 @@ func (f *Flagset) MapStringFlag(m *MapStringFlag) {
|
||||||
Usage: m.Usage,
|
Usage: m.Usage,
|
||||||
Group: m.Group,
|
Group: m.Group,
|
||||||
Default: nil,
|
Default: nil,
|
||||||
|
Value: m,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
|
|
@ -368,6 +478,7 @@ func (f *Flagset) MapStringFlag(m *MapStringFlag) {
|
||||||
Usage: m.Usage,
|
Usage: m.Usage,
|
||||||
Group: m.Group,
|
Group: m.Group,
|
||||||
Default: formatMapString(m.Default),
|
Default: formatMapString(m.Default),
|
||||||
|
Value: m,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -382,12 +493,19 @@ type Float64Flag struct {
|
||||||
Group string
|
Group string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Float64Flag) UpdateValue(value string) {
|
||||||
|
v, _ := strconv.ParseFloat(value, 64)
|
||||||
|
|
||||||
|
*f.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Flagset) Float64Flag(i *Float64Flag) {
|
func (f *Flagset) Float64Flag(i *Float64Flag) {
|
||||||
f.addFlag(&FlagVar{
|
f.addFlag(&FlagVar{
|
||||||
Name: i.Name,
|
Name: i.Name,
|
||||||
Usage: i.Usage,
|
Usage: i.Usage,
|
||||||
Group: i.Group,
|
Group: i.Group,
|
||||||
Default: i.Default,
|
Default: i.Default,
|
||||||
|
Value: i,
|
||||||
})
|
})
|
||||||
f.set.Float64Var(i.Value, i.Name, i.Default, "")
|
f.set.Float64Var(i.Value, i.Name, i.Default, "")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,176 @@
|
||||||
package flagset
|
package flagset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFlagsetBool(t *testing.T) {
|
func TestFlagsetBool(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
f := NewFlagSet("")
|
f := NewFlagSet("")
|
||||||
|
|
||||||
value := false
|
value := true
|
||||||
f.BoolFlag(&BoolFlag{
|
f.BoolFlag(&BoolFlag{
|
||||||
Name: "flag",
|
Name: "flag",
|
||||||
Value: &value,
|
Value: &value,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, f.Parse([]string{"--flag", "true"}))
|
// Parse no value, should have default (of datatype)
|
||||||
assert.Equal(t, value, true)
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, false, value)
|
||||||
|
|
||||||
|
// Parse --flag true
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "true"}))
|
||||||
|
require.Equal(t, true, value)
|
||||||
|
|
||||||
|
// Parse --flag=true
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=true"}))
|
||||||
|
require.Equal(t, true, value)
|
||||||
|
|
||||||
|
// Parse --flag false: won't parse false
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "false"}))
|
||||||
|
require.Equal(t, true, value)
|
||||||
|
|
||||||
|
// Parse --flag=false
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=false"}))
|
||||||
|
require.Equal(t, false, value)
|
||||||
|
|
||||||
|
// Parse --flag
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag"}))
|
||||||
|
require.Equal(t, true, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFlagsetString(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := NewFlagSet("")
|
||||||
|
|
||||||
|
value := "hello"
|
||||||
|
f.StringFlag(&StringFlag{
|
||||||
|
Name: "flag",
|
||||||
|
Value: &value,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Parse no value, should have default
|
||||||
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, "", value)
|
||||||
|
|
||||||
|
// Parse --flag value
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "value"}))
|
||||||
|
require.Equal(t, "value", value)
|
||||||
|
|
||||||
|
// Parse --flag ""
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", ""}))
|
||||||
|
require.Equal(t, "", value)
|
||||||
|
|
||||||
|
// Parse --flag=newvalue
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=newvalue"}))
|
||||||
|
require.Equal(t, "newvalue", value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFlagsetInt(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := NewFlagSet("")
|
||||||
|
|
||||||
|
value := 10
|
||||||
|
f.IntFlag(&IntFlag{
|
||||||
|
Name: "flag",
|
||||||
|
Value: &value,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Parse no value, should have default
|
||||||
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, 0, value)
|
||||||
|
|
||||||
|
// Parse --flag 20
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "20"}))
|
||||||
|
require.Equal(t, 20, value)
|
||||||
|
|
||||||
|
// Parse --flag 0
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "0"}))
|
||||||
|
require.Equal(t, 0, value)
|
||||||
|
|
||||||
|
// Parse --flag=30
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=30"}))
|
||||||
|
require.Equal(t, 30, value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFlagsetFloat64(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := NewFlagSet("")
|
||||||
|
|
||||||
|
value := 10.0
|
||||||
|
f.Float64Flag(&Float64Flag{
|
||||||
|
Name: "flag",
|
||||||
|
Value: &value,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Parse no value, should have default
|
||||||
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, 0.0, value)
|
||||||
|
|
||||||
|
// Parse --flag 20
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "20.1"}))
|
||||||
|
require.Equal(t, 20.1, value)
|
||||||
|
|
||||||
|
// Parse --flag 0
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "0"}))
|
||||||
|
require.Equal(t, 0.0, value)
|
||||||
|
|
||||||
|
// Parse --flag 0.0
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "0.0"}))
|
||||||
|
require.Equal(t, 0.0, value)
|
||||||
|
|
||||||
|
// Parse --flag=30.1
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=30.1"}))
|
||||||
|
require.Equal(t, 30.1, value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFlagsetBigInt(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := NewFlagSet("")
|
||||||
|
|
||||||
|
value := big.NewInt(0)
|
||||||
|
f.BigIntFlag(&BigIntFlag{
|
||||||
|
Name: "flag",
|
||||||
|
Value: value,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Parse no value, should have initial value (0 here)
|
||||||
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, big.NewInt(0), value)
|
||||||
|
|
||||||
|
// Parse --flag 20
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "20"}))
|
||||||
|
require.Equal(t, big.NewInt(20), value)
|
||||||
|
|
||||||
|
// Parse --flag=30
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=30"}))
|
||||||
|
require.Equal(t, big.NewInt(30), value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlagsetSliceString(t *testing.T) {
|
func TestFlagsetSliceString(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
f := NewFlagSet("")
|
f := NewFlagSet("")
|
||||||
|
|
||||||
value := []string{"a", "b", "c"}
|
value := []string{"a", "b", "c"}
|
||||||
|
|
@ -30,13 +180,25 @@ func TestFlagsetSliceString(t *testing.T) {
|
||||||
Default: value,
|
Default: value,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, f.Parse([]string{}))
|
// Parse no value, should have initial value
|
||||||
assert.Equal(t, value, []string{"a", "b", "c"})
|
require.NoError(t, f.Parse([]string{}))
|
||||||
assert.NoError(t, f.Parse([]string{"--flag", "a,b"}))
|
require.Equal(t, []string{"a", "b", "c"}, value)
|
||||||
assert.Equal(t, value, []string{"a", "b"})
|
|
||||||
|
// Parse --flag a,b
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "a,b"}))
|
||||||
|
require.Equal(t, []string{"a", "b"}, value)
|
||||||
|
|
||||||
|
// Parse --flag ""
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", ""}))
|
||||||
|
require.Equal(t, []string(nil), value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlagsetDuration(t *testing.T) {
|
func TestFlagsetDuration(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
f := NewFlagSet("")
|
f := NewFlagSet("")
|
||||||
|
|
||||||
value := time.Duration(0)
|
value := time.Duration(0)
|
||||||
|
|
@ -45,11 +207,25 @@ func TestFlagsetDuration(t *testing.T) {
|
||||||
Value: &value,
|
Value: &value,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, f.Parse([]string{"--flag", "1m"}))
|
// Parse no value, should have initial value
|
||||||
assert.Equal(t, value, 1*time.Minute)
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, time.Duration(0), value)
|
||||||
|
|
||||||
|
// Parse --flag 1m
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "1m"}))
|
||||||
|
require.Equal(t, time.Minute, value)
|
||||||
|
|
||||||
|
// Parse --flag=1h
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=1h"}))
|
||||||
|
require.Equal(t, time.Hour, value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlagsetMapString(t *testing.T) {
|
func TestFlagsetMapString(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
f := NewFlagSet("")
|
f := NewFlagSet("")
|
||||||
|
|
||||||
value := map[string]string{}
|
value := map[string]string{}
|
||||||
|
|
@ -58,6 +234,18 @@ func TestFlagsetMapString(t *testing.T) {
|
||||||
Value: &value,
|
Value: &value,
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.NoError(t, f.Parse([]string{"--flag", "a=b,c=d"}))
|
// Parse no value, should have initial value
|
||||||
assert.Equal(t, value, map[string]string{"a": "b", "c": "d"})
|
require.NoError(t, f.Parse([]string{}))
|
||||||
|
require.Equal(t, map[string]string{}, value)
|
||||||
|
|
||||||
|
// Parse --flag a=b,c=d
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag", "a=b,c=d"}))
|
||||||
|
require.Equal(t, map[string]string{"a": "b", "c": "d"}, value)
|
||||||
|
|
||||||
|
// Parse --flag=x=y
|
||||||
|
require.NoError(t, f.Parse([]string{"--flag=x=y"}))
|
||||||
|
require.Equal(t, map[string]string{"x": "y"}, value)
|
||||||
|
|
||||||
|
// Parse --flag: should fail due to no args
|
||||||
|
require.Error(t, f.Parse([]string{"--flag"}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func (c *Command) MarkDown() string {
|
||||||
items := []string{
|
items := []string{
|
||||||
"# Server",
|
"# Server",
|
||||||
"The ```bor server``` command runs the Bor client.",
|
"The ```bor server``` command runs the Bor client.",
|
||||||
c.Flags().MarkDown(),
|
c.Flags(nil).MarkDown(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(items, "\n\n")
|
return strings.Join(items, "\n\n")
|
||||||
|
|
@ -46,7 +46,7 @@ func (c *Command) Help() string {
|
||||||
return `Usage: bor [options]
|
return `Usage: bor [options]
|
||||||
|
|
||||||
Run the Bor server.
|
Run the Bor server.
|
||||||
` + c.Flags().Help()
|
` + c.Flags(nil).Help()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synopsis implements the cli.Command interface
|
// Synopsis implements the cli.Command interface
|
||||||
|
|
@ -54,40 +54,69 @@ func (c *Command) Synopsis() string {
|
||||||
return "Run the Bor server"
|
return "Run the Bor server"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkConfigFlag checks if the config flag is set or not. If set,
|
||||||
|
// it returns the value else an empty string.
|
||||||
|
func checkConfigFlag(args []string) string {
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
arg := args[i]
|
||||||
|
|
||||||
|
// Check for single or double dashes
|
||||||
|
if strings.HasPrefix(arg, "-config") || strings.HasPrefix(arg, "--config") {
|
||||||
|
parts := strings.SplitN(arg, "=", 2)
|
||||||
|
if len(parts) == 2 {
|
||||||
|
return parts[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no equal sign, check the next argument
|
||||||
|
if i+1 < len(args) {
|
||||||
|
return args[i+1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Command) extractFlags(args []string) error {
|
func (c *Command) extractFlags(args []string) error {
|
||||||
config := *DefaultConfig()
|
// Check if config file is provided or not
|
||||||
|
configFilePath := checkConfigFlag(args)
|
||||||
|
|
||||||
flags := c.Flags()
|
if configFilePath != "" {
|
||||||
if err := flags.Parse(args); err != nil {
|
log.Info("Reading config file", "path", configFilePath)
|
||||||
c.UI.Error(err.Error())
|
|
||||||
c.config = &config
|
|
||||||
|
|
||||||
return err
|
// Parse the config file
|
||||||
}
|
cfg, err := readConfigFile(configFilePath)
|
||||||
|
|
||||||
// TODO: Check if this can be removed or not
|
|
||||||
// read cli flags
|
|
||||||
if err := config.Merge(c.cliConfig); err != nil {
|
|
||||||
c.UI.Error(err.Error())
|
|
||||||
c.config = &config
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// read if config file is provided, this will overwrite the cli flags, if provided
|
|
||||||
if c.configFile != "" {
|
|
||||||
log.Warn("Config File provided, this will overwrite the cli flags", "path", c.configFile)
|
|
||||||
|
|
||||||
cfg, err := readConfigFile(c.configFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
c.config = &config
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.Merge(cfg); err != nil {
|
log.Warn("Config set via config file will be overridden by cli flags")
|
||||||
|
|
||||||
|
// Initialse a flagset based on the config created above
|
||||||
|
flags := c.Flags(cfg)
|
||||||
|
|
||||||
|
// Check for explicit cli args
|
||||||
|
cmd := Command{} // use a new variable to keep the original config intact
|
||||||
|
|
||||||
|
cliFlags := cmd.Flags(nil)
|
||||||
|
if err := cliFlags.Parse(args); err != nil {
|
||||||
|
c.UI.Error(err.Error())
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the list of flags set explicitly
|
||||||
|
names, values := cliFlags.Visit()
|
||||||
|
|
||||||
|
// Set these flags using the flagset created earlier
|
||||||
|
flags.UpdateValue(names, values)
|
||||||
|
} else {
|
||||||
|
flags := c.Flags(nil)
|
||||||
|
|
||||||
|
if err := flags.Parse(args); err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
c.config = &config
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -95,33 +124,33 @@ func (c *Command) extractFlags(args []string) error {
|
||||||
|
|
||||||
// nolint: nestif
|
// nolint: nestif
|
||||||
// check for log-level and verbosity here
|
// check for log-level and verbosity here
|
||||||
if c.configFile != "" {
|
if configFilePath != "" {
|
||||||
data, _ := toml.LoadFile(c.configFile)
|
data, _ := toml.LoadFile(configFilePath)
|
||||||
if data.Has("verbosity") && data.Has("log-level") {
|
if data.Has("verbosity") && data.Has("log-level") {
|
||||||
log.Warn("Config contains both, verbosity and log-level, log-level will be deprecated soon. Use verbosity only.", "using", data.Get("verbosity"))
|
log.Warn("Config contains both, verbosity and log-level, log-level will be deprecated soon. Use verbosity only.", "using", data.Get("verbosity"))
|
||||||
} else if !data.Has("verbosity") && data.Has("log-level") {
|
} else if !data.Has("verbosity") && data.Has("log-level") {
|
||||||
log.Warn("Config contains log-level only, note that log-level will be deprecated soon. Use verbosity instead.", "using", data.Get("log-level"))
|
log.Warn("Config contains log-level only, note that log-level will be deprecated soon. Use verbosity instead.", "using", data.Get("log-level"))
|
||||||
config.Verbosity = VerbosityStringToInt(strings.ToLower(data.Get("log-level").(string)))
|
c.cliConfig.Verbosity = VerbosityStringToInt(strings.ToLower(data.Get("log-level").(string)))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tempFlag := 0
|
tempFlag := 0
|
||||||
|
|
||||||
for _, val := range args {
|
for _, val := range args {
|
||||||
if (strings.HasPrefix(val, "-verbosity") || strings.HasPrefix(val, "--verbosity")) && config.LogLevel != "" {
|
if (strings.HasPrefix(val, "-verbosity") || strings.HasPrefix(val, "--verbosity")) && c.cliConfig.LogLevel != "" {
|
||||||
tempFlag = 1
|
tempFlag = 1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tempFlag == 1 {
|
if tempFlag == 1 {
|
||||||
log.Warn("Both, verbosity and log-level flags are provided, log-level will be deprecated soon. Use verbosity only.", "using", config.Verbosity)
|
log.Warn("Both, verbosity and log-level flags are provided, log-level will be deprecated soon. Use verbosity only.", "using", c.cliConfig.Verbosity)
|
||||||
} else if tempFlag == 0 && config.LogLevel != "" {
|
} else if tempFlag == 0 && c.cliConfig.LogLevel != "" {
|
||||||
log.Warn("Only log-level flag is provided, note that log-level will be deprecated soon. Use verbosity instead.", "using", config.LogLevel)
|
log.Warn("Only log-level flag is provided, note that log-level will be deprecated soon. Use verbosity instead.", "using", c.cliConfig.LogLevel)
|
||||||
config.Verbosity = VerbosityStringToInt(strings.ToLower(config.LogLevel))
|
c.cliConfig.Verbosity = VerbosityStringToInt(strings.ToLower(c.cliConfig.LogLevel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.config = &config
|
c.config = c.cliConfig
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,43 +8,135 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFlags(t *testing.T) {
|
// TestFlagsWithoutConfig tests all types of flags passed only
|
||||||
|
// via cli args.
|
||||||
|
func TestFlagsWithoutConfig(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var c Command
|
var c Command
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--txpool.rejournal", "30m0s",
|
"--identity", "",
|
||||||
"--txpool.lifetime", "30m0s",
|
|
||||||
"--miner.gasprice", "20000000000",
|
|
||||||
"--gpo.maxprice", "70000000000",
|
|
||||||
"--gpo.ignoreprice", "1",
|
|
||||||
"--cache.trie.rejournal", "40m0s",
|
|
||||||
"--dev",
|
|
||||||
"--dev.period", "2",
|
|
||||||
"--datadir", "./data",
|
"--datadir", "./data",
|
||||||
"--maxpeers", "30",
|
"--verbosity", "3",
|
||||||
|
"--rpc.batchlimit", "0",
|
||||||
|
"--snapshot",
|
||||||
|
"--bor.logs=false",
|
||||||
"--eth.requiredblocks", "a=b",
|
"--eth.requiredblocks", "a=b",
|
||||||
"--http.api", "eth,web3,bor",
|
"--miner.gasprice", "30000000000",
|
||||||
|
"--miner.recommit", "20s",
|
||||||
|
"--rpc.evmtimeout", "5s",
|
||||||
|
"--rpc.txfeecap", "6.0",
|
||||||
|
"--http.api", "eth,bor",
|
||||||
|
"--ws.api", "",
|
||||||
|
"--gpo.maxprice", "5000000000000",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.extractFlags(args)
|
err := c.extractFlags(args)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
txRe, _ := time.ParseDuration("30m0s")
|
recommit, _ := time.ParseDuration("20s")
|
||||||
txLt, _ := time.ParseDuration("30m0s")
|
evmTimeout, _ := time.ParseDuration("5s")
|
||||||
caRe, _ := time.ParseDuration("40m0s")
|
|
||||||
|
|
||||||
|
require.Equal(t, c.config.Identity, "")
|
||||||
require.Equal(t, c.config.DataDir, "./data")
|
require.Equal(t, c.config.DataDir, "./data")
|
||||||
require.Equal(t, c.config.Developer.Enabled, true)
|
require.Equal(t, c.config.Verbosity, 3)
|
||||||
require.Equal(t, c.config.Developer.Period, uint64(2))
|
require.Equal(t, c.config.RPCBatchLimit, uint64(0))
|
||||||
require.Equal(t, c.config.TxPool.Rejournal, txRe)
|
require.Equal(t, c.config.Snapshot, true)
|
||||||
require.Equal(t, c.config.TxPool.LifeTime, txLt)
|
require.Equal(t, c.config.BorLogs, false)
|
||||||
require.Equal(t, c.config.Sealer.GasPrice, big.NewInt(20000000000))
|
|
||||||
require.Equal(t, c.config.Gpo.MaxPrice, big.NewInt(70000000000))
|
|
||||||
require.Equal(t, c.config.Gpo.IgnorePrice, big.NewInt(1))
|
|
||||||
require.Equal(t, c.config.Cache.Rejournal, caRe)
|
|
||||||
require.Equal(t, c.config.P2P.MaxPeers, uint64(30))
|
|
||||||
require.Equal(t, c.config.RequiredBlocks, map[string]string{"a": "b"})
|
require.Equal(t, c.config.RequiredBlocks, map[string]string{"a": "b"})
|
||||||
require.Equal(t, c.config.JsonRPC.Http.API, []string{"eth", "web3", "bor"})
|
require.Equal(t, c.config.Sealer.GasPrice, big.NewInt(30000000000))
|
||||||
|
require.Equal(t, c.config.Sealer.Recommit, recommit)
|
||||||
|
require.Equal(t, c.config.JsonRPC.RPCEVMTimeout, evmTimeout)
|
||||||
|
require.Equal(t, c.config.JsonRPC.Http.API, []string{"eth", "bor"})
|
||||||
|
require.Equal(t, c.config.JsonRPC.Ws.API, []string(nil))
|
||||||
|
require.Equal(t, c.config.Gpo.MaxPrice, big.NewInt(5000000000000))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestFlagsWithoutConfig tests all types of flags passed only
|
||||||
|
// via config file.
|
||||||
|
func TestFlagsWithConfig(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
var c Command
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"--config", "./testdata/test.toml",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := c.extractFlags(args)
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recommit, _ := time.ParseDuration("20s")
|
||||||
|
evmTimeout, _ := time.ParseDuration("5s")
|
||||||
|
|
||||||
|
require.Equal(t, c.config.Identity, "")
|
||||||
|
require.Equal(t, c.config.DataDir, "./data")
|
||||||
|
require.Equal(t, c.config.Verbosity, 3)
|
||||||
|
require.Equal(t, c.config.RPCBatchLimit, uint64(0))
|
||||||
|
require.Equal(t, c.config.Snapshot, true)
|
||||||
|
require.Equal(t, c.config.BorLogs, false)
|
||||||
|
require.Equal(t, c.config.RequiredBlocks,
|
||||||
|
map[string]string{
|
||||||
|
"31000000": "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e",
|
||||||
|
"32000000": "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
require.Equal(t, c.config.Sealer.GasPrice, big.NewInt(30000000000))
|
||||||
|
require.Equal(t, c.config.Sealer.Recommit, recommit)
|
||||||
|
require.Equal(t, c.config.JsonRPC.RPCEVMTimeout, evmTimeout)
|
||||||
|
require.Equal(t, c.config.JsonRPC.Http.API, []string{"eth", "bor"})
|
||||||
|
require.Equal(t, c.config.JsonRPC.Ws.API, []string{""})
|
||||||
|
require.Equal(t, c.config.Gpo.MaxPrice, big.NewInt(5000000000000))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestFlagsWithConfig tests all types of flags passed via both
|
||||||
|
// config file and cli args. The cli args should overwrite the
|
||||||
|
// value of flag.
|
||||||
|
func TestFlagsWithConfigAndFlags(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
var c Command
|
||||||
|
|
||||||
|
// Set the config and also override
|
||||||
|
args := []string{
|
||||||
|
"--config", "./testdata/test.toml",
|
||||||
|
"--identity", "Anon",
|
||||||
|
"--datadir", "",
|
||||||
|
"--verbosity", "0",
|
||||||
|
"--rpc.batchlimit", "5",
|
||||||
|
"--snapshot=false",
|
||||||
|
"--bor.logs=true",
|
||||||
|
"--eth.requiredblocks", "x=y",
|
||||||
|
"--miner.gasprice", "60000000000",
|
||||||
|
"--miner.recommit", "30s",
|
||||||
|
"--rpc.evmtimeout", "0s",
|
||||||
|
"--rpc.txfeecap", "0",
|
||||||
|
"--http.api", "",
|
||||||
|
"--ws.api", "eth,bor,web3",
|
||||||
|
"--gpo.maxprice", "0",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := c.extractFlags(args)
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
recommit, _ := time.ParseDuration("30s")
|
||||||
|
evmTimeout, _ := time.ParseDuration("0s")
|
||||||
|
|
||||||
|
require.Equal(t, c.config.Identity, "Anon")
|
||||||
|
require.Equal(t, c.config.DataDir, "")
|
||||||
|
require.Equal(t, c.config.Verbosity, 0)
|
||||||
|
require.Equal(t, c.config.RPCBatchLimit, uint64(5))
|
||||||
|
require.Equal(t, c.config.Snapshot, false)
|
||||||
|
require.Equal(t, c.config.BorLogs, true)
|
||||||
|
require.Equal(t, c.config.RequiredBlocks, map[string]string{"x": "y"})
|
||||||
|
require.Equal(t, c.config.Sealer.GasPrice, big.NewInt(60000000000))
|
||||||
|
require.Equal(t, c.config.Sealer.Recommit, recommit)
|
||||||
|
require.Equal(t, c.config.JsonRPC.RPCEVMTimeout, evmTimeout)
|
||||||
|
require.Equal(t, c.config.JsonRPC.Http.API, []string(nil))
|
||||||
|
require.Equal(t, c.config.JsonRPC.Ws.API, []string{"eth", "bor", "web3"})
|
||||||
|
require.Equal(t, c.config.Gpo.MaxPrice, big.NewInt(0))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,21 +15,23 @@ func TestConfigLegacy(t *testing.T) {
|
||||||
|
|
||||||
testConfig := DefaultConfig()
|
testConfig := DefaultConfig()
|
||||||
|
|
||||||
|
testConfig.Identity = ""
|
||||||
testConfig.DataDir = "./data"
|
testConfig.DataDir = "./data"
|
||||||
testConfig.Snapshot = false
|
testConfig.Verbosity = 3
|
||||||
|
testConfig.RPCBatchLimit = 0
|
||||||
|
testConfig.Snapshot = true
|
||||||
|
testConfig.BorLogs = false
|
||||||
testConfig.RequiredBlocks = map[string]string{
|
testConfig.RequiredBlocks = map[string]string{
|
||||||
"31000000": "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e",
|
"31000000": "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e",
|
||||||
"32000000": "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68",
|
"32000000": "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68",
|
||||||
}
|
}
|
||||||
testConfig.P2P.MaxPeers = 30
|
testConfig.Sealer.GasPrice = big.NewInt(30000000000)
|
||||||
testConfig.TxPool.Locals = []string{}
|
testConfig.Sealer.Recommit = 20 * time.Second
|
||||||
testConfig.TxPool.LifeTime = time.Second
|
testConfig.JsonRPC.RPCEVMTimeout = 5 * time.Second
|
||||||
testConfig.Sealer.Enabled = true
|
testConfig.JsonRPC.TxFeeCap = 6.0
|
||||||
testConfig.Sealer.GasCeil = 30000000
|
testConfig.JsonRPC.Http.API = []string{"eth", "bor"}
|
||||||
testConfig.Sealer.GasPrice = big.NewInt(1000000000)
|
testConfig.JsonRPC.Ws.API = []string{""}
|
||||||
testConfig.Gpo.IgnorePrice = big.NewInt(4)
|
testConfig.Gpo.MaxPrice = big.NewInt(5000000000000)
|
||||||
testConfig.Cache.Cache = 1024
|
|
||||||
testConfig.Cache.Rejournal = time.Second
|
|
||||||
|
|
||||||
assert.Equal(t, expectedConfig, testConfig)
|
assert.Equal(t, expectedConfig, testConfig)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,12 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/internal/cli/flagset"
|
"github.com/ethereum/go-ethereum/internal/cli/flagset"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Command) Flags() *flagset.Flagset {
|
func (c *Command) Flags(config *Config) *flagset.Flagset {
|
||||||
c.cliConfig = DefaultConfig()
|
if config != nil {
|
||||||
|
c.cliConfig = config
|
||||||
|
} else {
|
||||||
|
c.cliConfig = DefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
f := flagset.NewFlagSet("server")
|
f := flagset.NewFlagSet("server")
|
||||||
|
|
||||||
|
|
|
||||||
32
internal/cli/server/testdata/test.toml
vendored
32
internal/cli/server/testdata/test.toml
vendored
|
|
@ -1,25 +1,25 @@
|
||||||
|
identity = ""
|
||||||
datadir = "./data"
|
datadir = "./data"
|
||||||
snapshot = false
|
verbosity = 3
|
||||||
|
"rpc.batchlimit" = 0
|
||||||
|
snapshot = true
|
||||||
|
"bor.logs" = false
|
||||||
|
|
||||||
["eth.requiredblocks"]
|
["eth.requiredblocks"]
|
||||||
"31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e"
|
"31000000" = "0x2087b9e2b353209c2c21e370c82daa12278efd0fe5f0febe6c29035352cf050e"
|
||||||
"32000000" = "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68"
|
"32000000" = "0x875500011e5eecc0c554f95d07b31cf59df4ca2505f4dbbfffa7d4e4da917c68"
|
||||||
|
|
||||||
[p2p]
|
|
||||||
maxpeers = 30
|
|
||||||
|
|
||||||
[txpool]
|
|
||||||
locals = []
|
|
||||||
lifetime = "1s"
|
|
||||||
|
|
||||||
[miner]
|
[miner]
|
||||||
mine = true
|
gasprice = "30000000000"
|
||||||
gaslimit = 30000000
|
recommit = "20s"
|
||||||
gasprice = "1000000000"
|
|
||||||
|
[jsonrpc]
|
||||||
|
evmtimeout = "5s"
|
||||||
|
txfeecap = 6.0
|
||||||
|
[jsonrpc.http]
|
||||||
|
api = ["eth", "bor"]
|
||||||
|
[jsonrpc.ws]
|
||||||
|
api = [""]
|
||||||
|
|
||||||
[gpo]
|
[gpo]
|
||||||
ignoreprice = "4"
|
maxprice = "5000000000000"
|
||||||
|
|
||||||
[cache]
|
|
||||||
cache = 1024
|
|
||||||
rejournal = "1s"
|
|
||||||
|
|
|
||||||
|
|
@ -1070,7 +1070,7 @@ func (w *worker) commitTransactions(env *environment, txs *types.TransactionsByP
|
||||||
|
|
||||||
var depsWg sync.WaitGroup
|
var depsWg sync.WaitGroup
|
||||||
|
|
||||||
EnableMVHashMap := false
|
EnableMVHashMap := w.chainConfig.Bor.IsParallelUniverse(env.header.Number)
|
||||||
|
|
||||||
// create and add empty mvHashMap in statedb
|
// create and add empty mvHashMap in statedb
|
||||||
if EnableMVHashMap {
|
if EnableMVHashMap {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ package enode
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -211,8 +212,11 @@ func (ln *LocalNode) SetFallbackUDP(port int) {
|
||||||
ln.mu.Lock()
|
ln.mu.Lock()
|
||||||
defer ln.mu.Unlock()
|
defer ln.mu.Unlock()
|
||||||
|
|
||||||
ln.endpoint4.fallbackUDP = uint16(port)
|
if port > 0 && port <= math.MaxUint16 {
|
||||||
ln.endpoint6.fallbackUDP = uint16(port)
|
ln.endpoint4.fallbackUDP = uint16(port)
|
||||||
|
ln.endpoint6.fallbackUDP = uint16(port)
|
||||||
|
}
|
||||||
|
|
||||||
ln.updateEndpoints()
|
ln.updateEndpoints()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -699,7 +699,7 @@ func main() {
|
||||||
args, ignoreForNow := beautifyArgs(args)
|
args, ignoreForNow := beautifyArgs(args)
|
||||||
|
|
||||||
c := server.Command{}
|
c := server.Command{}
|
||||||
flags := c.Flags()
|
flags := c.Flags(nil)
|
||||||
allFlags := flags.GetAllFlags()
|
allFlags := flags.GetAllFlags()
|
||||||
flagsToCheck := getFlagsToCheck(args)
|
flagsToCheck := getFlagsToCheck(args)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue