mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
fix lint
This commit is contained in:
parent
c763560f88
commit
08b4937cb6
33 changed files with 846 additions and 1277 deletions
193
.golangci.yml
193
.golangci.yml
|
|
@ -1,7 +1,6 @@
|
||||||
# This file configures github.com/golangci/golangci-lint.
|
# This file configures github.com/golangci/golangci-lint.
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go: '1.20'
|
|
||||||
timeout: 20m
|
timeout: 20m
|
||||||
tests: true
|
tests: true
|
||||||
# default is true. Enables skipping of directories:
|
# default is true. Enables skipping of directories:
|
||||||
|
|
@ -9,180 +8,60 @@ run:
|
||||||
skip-dirs-use-default: true
|
skip-dirs-use-default: true
|
||||||
skip-files:
|
skip-files:
|
||||||
- core/genesis_alloc.go
|
- core/genesis_alloc.go
|
||||||
- gen_.*.go
|
|
||||||
- .*_gen.go
|
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
- goconst
|
- goconst
|
||||||
- goimports
|
- goimports
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
- misspell
|
- misspell
|
||||||
- unconvert
|
- unconvert
|
||||||
- bodyclose
|
- typecheck
|
||||||
- containedctx
|
- unused
|
||||||
- contextcheck
|
- staticcheck
|
||||||
- decorder
|
- bidichk
|
||||||
- durationcheck
|
- durationcheck
|
||||||
- errchkjson
|
|
||||||
- errname
|
|
||||||
- exhaustive
|
|
||||||
- exportloopref
|
- exportloopref
|
||||||
- gocognit
|
- whitespace
|
||||||
- gofmt
|
|
||||||
# - gomnd
|
# - structcheck # lots of false positives
|
||||||
# - gomoddirectives
|
# - errcheck #lot of false positives
|
||||||
- gosec
|
# - contextcheck
|
||||||
- makezero
|
# - errchkjson # lots of false positives
|
||||||
- nestif
|
# - errorlint # this check crashes
|
||||||
- nilerr
|
# - exhaustive # silly check
|
||||||
- nilnil
|
# - makezero # false positives
|
||||||
- noctx
|
# - nilerr # several intentional
|
||||||
#- nosprintfhostport # TODO: do we use IPv6?
|
|
||||||
- paralleltest
|
|
||||||
- prealloc
|
|
||||||
- predeclared
|
|
||||||
#- promlinter
|
|
||||||
#- revive
|
|
||||||
# - tagliatelle
|
|
||||||
- tenv
|
|
||||||
- thelper
|
|
||||||
- tparallel
|
|
||||||
- unconvert
|
|
||||||
- unparam
|
|
||||||
# - wsl
|
|
||||||
- asasalint
|
|
||||||
#- errorlint causes stack overflow. TODO: recheck after each golangci update
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
gofmt:
|
gofmt:
|
||||||
simplify: true
|
simplify: true
|
||||||
auto-fix: false
|
|
||||||
|
|
||||||
goconst:
|
goconst:
|
||||||
min-len: 3 # minimum length of string constant
|
min-len: 3 # minimum length of string constant
|
||||||
min-occurrences: 2 # minimum number of occurrences
|
min-occurrences: 6 # minimum number of occurrences
|
||||||
numbers: true
|
|
||||||
|
|
||||||
goimports:
|
|
||||||
local-prefixes: github.com/ethereum/go-ethereum
|
|
||||||
|
|
||||||
nestif:
|
|
||||||
min-complexity: 5
|
|
||||||
|
|
||||||
prealloc:
|
|
||||||
for-loops: true
|
|
||||||
|
|
||||||
gocritic:
|
|
||||||
# Which checks should be enabled; can't be combined with 'disabled-checks';
|
|
||||||
# See https://go-critic.github.io/overview#checks-overview
|
|
||||||
# To check which checks are enabled run `GL_DEBUG=gocritic ./build/bin/golangci-lint run`
|
|
||||||
# By default list of stable checks is used.
|
|
||||||
enabled-checks:
|
|
||||||
- badLock
|
|
||||||
- filepathJoin
|
|
||||||
- sortSlice
|
|
||||||
- sprintfQuotedString
|
|
||||||
- syncMapLoadAndDelete
|
|
||||||
- weakCond
|
|
||||||
- boolExprSimplify
|
|
||||||
- httpNoBody
|
|
||||||
- ioutilDeprecated
|
|
||||||
- nestingReduce
|
|
||||||
- preferFilepathJoin
|
|
||||||
- redundantSprint
|
|
||||||
- stringConcatSimplify
|
|
||||||
- timeExprSimplify
|
|
||||||
- typeAssertChain
|
|
||||||
- yodaStyleExpr
|
|
||||||
- truncateCmp
|
|
||||||
- equalFold
|
|
||||||
- preferDecodeRune
|
|
||||||
- preferFprint
|
|
||||||
- preferStringWriter
|
|
||||||
- preferWriteByte
|
|
||||||
- sliceClear
|
|
||||||
#- ruleguard
|
|
||||||
|
|
||||||
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
|
|
||||||
disabled-checks:
|
|
||||||
- regexpMust
|
|
||||||
- exitAfterDefer
|
|
||||||
- dupBranchBody
|
|
||||||
- singleCaseSwitch
|
|
||||||
- unlambda
|
|
||||||
- captLocal
|
|
||||||
- commentFormatting
|
|
||||||
- ifElseChain
|
|
||||||
- importShadow
|
|
||||||
- builtinShadow
|
|
||||||
|
|
||||||
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
|
|
||||||
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
|
|
||||||
enabled-tags:
|
|
||||||
- performance
|
|
||||||
- diagnostic
|
|
||||||
- opinionated
|
|
||||||
- style
|
|
||||||
disabled-tags:
|
|
||||||
- experimental
|
|
||||||
govet:
|
|
||||||
disable:
|
|
||||||
- deepequalerrors
|
|
||||||
- fieldalignment
|
|
||||||
- shadow
|
|
||||||
- unsafeptr
|
|
||||||
check-shadowing: true
|
|
||||||
enable-all: true
|
|
||||||
settings:
|
|
||||||
printf:
|
|
||||||
# Run `go tool vet help printf` to see available settings for `printf` analyzer.
|
|
||||||
funcs:
|
|
||||||
- (github.com/ethereum/go-ethereum/log.Logger).Trace
|
|
||||||
- (github.com/ethereum/go-ethereum/log.Logger).Debug
|
|
||||||
- (github.com/ethereum/go-ethereum/log.Logger).Info
|
|
||||||
- (github.com/ethereum/go-ethereum/log.Logger).Warn
|
|
||||||
- (github.com/ethereum/go-ethereum/log.Logger).Error
|
|
||||||
- (github.com/ethereum/go-ethereum/log.Logger).Crit
|
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- path: crypto/bn256/cloudflare/optate.go
|
- path: crypto/bn256/cloudflare/optate.go
|
||||||
linters:
|
linters:
|
||||||
- deadcode
|
- deadcode
|
||||||
- path: crypto/bn256/cloudflare
|
- staticcheck
|
||||||
linters:
|
- path: internal/build/pgp.go
|
||||||
- deadcode
|
text: 'SA1019: "golang.org/x/crypto/openpgp" is deprecated: this package is unmaintained except for security fixes.'
|
||||||
- path: p2p/discv5/
|
- path: core/vm/contracts.go
|
||||||
linters:
|
text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.'
|
||||||
- deadcode
|
- path: accounts/usbwallet/trezor.go
|
||||||
- path: core/vm/instructions_test.go
|
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
|
||||||
linters:
|
- path: accounts/usbwallet/trezor/
|
||||||
- goconst
|
text: 'SA1019: "github.com/golang/protobuf/proto" is deprecated: Use the "google.golang.org/protobuf/proto" package instead.'
|
||||||
- path: cmd/faucet/
|
exclude:
|
||||||
linters:
|
- 'SA1019: event.TypeMux is deprecated: use Feed'
|
||||||
- deadcode
|
- 'SA1019: strings.Title is deprecated'
|
||||||
# Exclude some linters from running on tests files.
|
- 'SA1019: strings.Title has been deprecated since Go 1.18 and an alternative has been available since Go 1.0: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead.'
|
||||||
- path: test\.go
|
- 'SA1029: should not use built-in type string as key for value'
|
||||||
linters:
|
- 'SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details'
|
||||||
- gosec
|
- 'SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x'
|
||||||
- unused
|
- "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate"
|
||||||
- deadcode
|
|
||||||
- gocritic
|
|
||||||
- path: cmd/devp2p
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- unused
|
|
||||||
- deadcode
|
|
||||||
- gocritic
|
|
||||||
- path: metrics/sample\.go
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- gocritic
|
|
||||||
- path: p2p/simulations
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- gocritic
|
|
||||||
max-issues-per-linter: 0
|
|
||||||
max-same-issues: 0
|
|
||||||
#new: true
|
|
||||||
new-from-rev: origin/master
|
|
||||||
|
|
|
||||||
|
|
@ -205,11 +205,9 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
|
||||||
// dumpConfig is the dumpconfig command.
|
// dumpConfig is the dumpconfig command.
|
||||||
func dumpConfig(ctx *cli.Context) error {
|
func dumpConfig(ctx *cli.Context) error {
|
||||||
_, cfg := makeConfigNode(ctx)
|
_, cfg := makeConfigNode(ctx)
|
||||||
comment := ""
|
|
||||||
|
|
||||||
if cfg.Eth.Genesis != nil {
|
if cfg.Eth.Genesis != nil {
|
||||||
cfg.Eth.Genesis = nil
|
cfg.Eth.Genesis = nil
|
||||||
comment += "# Note: this config doesn't contain the genesis block.\n\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := toml.NewEncoder(os.Stdout).Encode(&cfg); err != nil {
|
if err := toml.NewEncoder(os.Stdout).Encode(&cfg); err != nil {
|
||||||
|
|
@ -277,21 +275,6 @@ func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func deprecated(field string) bool {
|
|
||||||
switch field {
|
|
||||||
case "ethconfig.Config.EVMInterpreter":
|
|
||||||
return true
|
|
||||||
case "ethconfig.Config.EWASMInterpreter":
|
|
||||||
return true
|
|
||||||
case "ethconfig.Config.TrieCleanCacheJournal":
|
|
||||||
return true
|
|
||||||
case "ethconfig.Config.TrieCleanCacheRejournal":
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setAccountManagerBackends(conf *node.Config, am *accounts.Manager, keydir string) error {
|
func setAccountManagerBackends(conf *node.Config, am *accounts.Manager, keydir string) error {
|
||||||
scryptN := keystore.StandardScryptN
|
scryptN := keystore.StandardScryptN
|
||||||
scryptP := keystore.StandardScryptP
|
scryptP := keystore.StandardScryptP
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,6 @@ func main() {
|
||||||
// prepare manipulates memory cache allowance and setups metric system.
|
// prepare manipulates memory cache allowance and setups metric system.
|
||||||
// This function should be called before launching devp2p stack.
|
// This function should be called before launching devp2p stack.
|
||||||
func prepare(ctx *cli.Context) {
|
func prepare(ctx *cli.Context) {
|
||||||
|
|
||||||
const light = "light"
|
const light = "light"
|
||||||
|
|
||||||
// If we're running a known preset, log it for convenience.
|
// If we're running a known preset, log it for convenience.
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -67,24 +64,6 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func getGenesis(genesisPath string) (*core.Genesis, error) {
|
|
||||||
log.Info("Reading genesis at ", "file", genesisPath)
|
|
||||||
|
|
||||||
file, err := os.Open(genesisPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
genesis := new(core.Genesis)
|
|
||||||
if err := json.NewDecoder(file).Decode(genesis); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return genesis, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBorConfig sets bor config
|
// SetBorConfig sets bor config
|
||||||
func SetBorConfig(ctx *cli.Context, cfg *eth.Config) {
|
func SetBorConfig(ctx *cli.Context, cfg *eth.Config) {
|
||||||
cfg.HeimdallURL = ctx.String(HeimdallURLFlag.Name)
|
cfg.HeimdallURL = ctx.String(HeimdallURLFlag.Name)
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ func ApplyMessage(
|
||||||
return gasUsed, nil
|
return gasUsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ApplyBorMessage(vmenv vm.EVM, msg Callmsg) (*core.ExecutionResult, error) {
|
func ApplyBorMessage(vmenv *vm.EVM, msg Callmsg) (*core.ExecutionResult, error) {
|
||||||
initialGas := msg.Gas()
|
initialGas := msg.Gas()
|
||||||
|
|
||||||
// Apply the transaction to the current state (included in the env)
|
// Apply the transaction to the current state (included in the env)
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ func TestChain2HeadEvent(t *testing.T) {
|
||||||
}})
|
}})
|
||||||
|
|
||||||
// reorg event
|
// reorg event
|
||||||
//In this event the channel recieves an array of Blocks in NewChain and OldChain
|
//In this event the channel receives an array of Blocks in NewChain and OldChain
|
||||||
readEvent(&eventTest{
|
readEvent(&eventTest{
|
||||||
Type: Chain2HeadReorgEvent,
|
Type: Chain2HeadReorgEvent,
|
||||||
Added: []common.Hash{
|
Added: []common.Hash{
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ func runParallelGetMetadata(t *testing.T, tasks []ExecTask, validation PropertyC
|
||||||
|
|
||||||
func TestLessConflicts(t *testing.T) {
|
func TestLessConflicts(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{10, 50, 100, 200, 300}
|
totalTxs := []int{10, 50, 100, 200, 300}
|
||||||
numReads := []int{20, 100, 200}
|
numReads := []int{20, 100, 200}
|
||||||
|
|
@ -495,7 +495,7 @@ func TestLessConflicts(t *testing.T) {
|
||||||
|
|
||||||
func TestLessConflictsWithMetadata(t *testing.T) {
|
func TestLessConflictsWithMetadata(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{300}
|
totalTxs := []int{300}
|
||||||
numReads := []int{100, 200}
|
numReads := []int{100, 200}
|
||||||
|
|
@ -541,7 +541,7 @@ func TestLessConflictsWithMetadata(t *testing.T) {
|
||||||
|
|
||||||
func TestZeroTx(t *testing.T) {
|
func TestZeroTx(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{0}
|
totalTxs := []int{0}
|
||||||
numReads := []int{20}
|
numReads := []int{20}
|
||||||
|
|
@ -562,7 +562,7 @@ func TestZeroTx(t *testing.T) {
|
||||||
|
|
||||||
func TestAlternatingTx(t *testing.T) {
|
func TestAlternatingTx(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{200}
|
totalTxs := []int{200}
|
||||||
numReads := []int{20}
|
numReads := []int{20}
|
||||||
|
|
@ -583,7 +583,7 @@ func TestAlternatingTx(t *testing.T) {
|
||||||
|
|
||||||
func TestAlternatingTxWithMetadata(t *testing.T) {
|
func TestAlternatingTxWithMetadata(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{200}
|
totalTxs := []int{200}
|
||||||
numReads := []int{20}
|
numReads := []int{20}
|
||||||
|
|
@ -626,7 +626,7 @@ func TestAlternatingTxWithMetadata(t *testing.T) {
|
||||||
|
|
||||||
func TestMoreConflicts(t *testing.T) {
|
func TestMoreConflicts(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{10, 50, 100, 200, 300}
|
totalTxs := []int{10, 50, 100, 200, 300}
|
||||||
numReads := []int{20, 100, 200}
|
numReads := []int{20, 100, 200}
|
||||||
|
|
@ -650,7 +650,7 @@ func TestMoreConflicts(t *testing.T) {
|
||||||
|
|
||||||
func TestMoreConflictsWithMetadata(t *testing.T) {
|
func TestMoreConflictsWithMetadata(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{300}
|
totalTxs := []int{300}
|
||||||
numReads := []int{100, 200}
|
numReads := []int{100, 200}
|
||||||
|
|
@ -696,7 +696,7 @@ func TestMoreConflictsWithMetadata(t *testing.T) {
|
||||||
|
|
||||||
func TestRandomTx(t *testing.T) {
|
func TestRandomTx(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{10, 50, 100, 200, 300}
|
totalTxs := []int{10, 50, 100, 200, 300}
|
||||||
numReads := []int{20, 100, 200}
|
numReads := []int{20, 100, 200}
|
||||||
|
|
@ -718,7 +718,7 @@ func TestRandomTx(t *testing.T) {
|
||||||
|
|
||||||
func TestRandomTxWithMetadata(t *testing.T) {
|
func TestRandomTxWithMetadata(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{300}
|
totalTxs := []int{300}
|
||||||
numReads := []int{100, 200}
|
numReads := []int{100, 200}
|
||||||
|
|
@ -762,7 +762,7 @@ func TestRandomTxWithMetadata(t *testing.T) {
|
||||||
|
|
||||||
func TestTxWithLongTailRead(t *testing.T) {
|
func TestTxWithLongTailRead(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{10, 50, 100, 200, 300}
|
totalTxs := []int{10, 50, 100, 200, 300}
|
||||||
numReads := []int{20, 100, 200}
|
numReads := []int{20, 100, 200}
|
||||||
|
|
@ -789,7 +789,7 @@ func TestTxWithLongTailRead(t *testing.T) {
|
||||||
|
|
||||||
func TestTxWithLongTailReadWithMetadata(t *testing.T) {
|
func TestTxWithLongTailReadWithMetadata(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{300}
|
totalTxs := []int{300}
|
||||||
numReads := []int{100, 200}
|
numReads := []int{100, 200}
|
||||||
|
|
@ -838,7 +838,7 @@ func TestTxWithLongTailReadWithMetadata(t *testing.T) {
|
||||||
|
|
||||||
func TestDexScenario(t *testing.T) {
|
func TestDexScenario(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{10, 50, 100, 200, 300}
|
totalTxs := []int{10, 50, 100, 200, 300}
|
||||||
numReads := []int{20, 100, 200}
|
numReads := []int{20, 100, 200}
|
||||||
|
|
@ -873,7 +873,7 @@ func TestDexScenario(t *testing.T) {
|
||||||
|
|
||||||
func TestDexScenarioWithMetadata(t *testing.T) {
|
func TestDexScenarioWithMetadata(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
totalTxs := []int{300}
|
totalTxs := []int{300}
|
||||||
numReads := []int{100, 200}
|
numReads := []int{100, 200}
|
||||||
|
|
@ -930,7 +930,7 @@ func TestDexScenarioWithMetadata(t *testing.T) {
|
||||||
|
|
||||||
func TestBreakFromCircularDependency(t *testing.T) {
|
func TestBreakFromCircularDependency(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
tasks := make([]ExecTask, 5)
|
tasks := make([]ExecTask, 5)
|
||||||
|
|
||||||
|
|
@ -956,7 +956,7 @@ func TestBreakFromCircularDependency(t *testing.T) {
|
||||||
|
|
||||||
func TestBreakFromPartialCircularDependency(t *testing.T) {
|
func TestBreakFromPartialCircularDependency(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
rand.Seed(0)
|
rand.New(rand.NewSource(0))
|
||||||
|
|
||||||
tasks := make([]ExecTask, 5)
|
tasks := make([]ExecTask, 5)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,6 @@ func (mv *MVHashMap) Write(k Key, v Version, data interface{}) {
|
||||||
rw: sync.RWMutex{},
|
rw: sync.RWMutex{},
|
||||||
tm: treemap.NewWithIntComparator(),
|
tm: treemap.NewWithIntComparator(),
|
||||||
}
|
}
|
||||||
cells = n
|
|
||||||
val, _ := mv.m.LoadOrStore(kenc, n)
|
val, _ := mv.m.LoadOrStore(kenc, n)
|
||||||
cells = val.(*TxnIndexCells)
|
cells = val.(*TxnIndexCells)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (bc *BlockChain) GetBorReceiptByHash(hash common.Hash) *types.Receipt {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// read bor reciept by hash and number
|
// read bor receipt by hash and number
|
||||||
receipt := rawdb.ReadBorReceipt(bc.db, hash, *number, bc.chainConfig)
|
receipt := rawdb.ReadBorReceipt(bc.db, hash, *number, bc.chainConfig)
|
||||||
if receipt == nil {
|
if receipt == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ func ReadBorReceiptRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.Raw
|
||||||
func ReadRawBorReceipt(db ethdb.Reader, hash common.Hash, number uint64) *types.Receipt {
|
func ReadRawBorReceipt(db ethdb.Reader, hash common.Hash, number uint64) *types.Receipt {
|
||||||
// Retrieve the flattened receipt slice
|
// Retrieve the flattened receipt slice
|
||||||
data := ReadBorReceiptRLP(db, hash, number)
|
data := ReadBorReceiptRLP(db, hash, number)
|
||||||
if data == nil || len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -424,11 +424,6 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
|
||||||
log.Info("Defaulting to leveldb as the backing database")
|
log.Info("Defaulting to leveldb as the backing database")
|
||||||
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.ExtraDBConfig)
|
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.ExtraDBConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use leveldb, either as default (no explicit choice), or pre-existing, or chosen explicitly
|
|
||||||
log.Info("Using leveldb as the backing database")
|
|
||||||
|
|
||||||
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.ExtraDBConfig)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens both a disk-based key-value database such as leveldb or pebble, but also
|
// Open opens both a disk-based key-value database such as leveldb or pebble, but also
|
||||||
|
|
|
||||||
|
|
@ -1039,15 +1039,15 @@ func (t *freezerTable) dumpIndex(w io.Writer, start, stop int64) {
|
||||||
// Bor related changes
|
// Bor related changes
|
||||||
//
|
//
|
||||||
|
|
||||||
// Fill adds empty data till given number (convenience method for backward compatibilty)
|
// Fill adds empty data till given number (convenience method for backward compatibility)
|
||||||
func (t *freezerTable) Fill(number uint64) error {
|
func (t *freezerTable) Fill(number uint64) error {
|
||||||
if t.items.Load() < number {
|
if t.items.Load() < number {
|
||||||
b := t.newBatch()
|
b := t.newBatch()
|
||||||
log.Info("Filling all data into freezer for backward compatablity", "name", t.name, "items", t.items, "number", number)
|
log.Info("Filling all data into freezer for backward compatibility", "name", t.name, "items", &t.items, "number", number)
|
||||||
|
|
||||||
for t.items.Load() < number {
|
for t.items.Load() < number {
|
||||||
if err := b.Append(t.items.Load(), nil); err != nil {
|
if err := b.Append(t.items.Load(), nil); err != nil {
|
||||||
log.Error("Failed to fill data into freezer", "name", t.name, "items", t.items, "number", number, "err", err)
|
log.Error("Failed to fill data into freezer", "name", t.name, "items", &t.items, "number", number, "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -32,12 +31,8 @@ import (
|
||||||
|
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
"github.com/maticnetwork/crand"
|
"github.com/maticnetwork/crand"
|
||||||
"gonum.org/v1/gonum/floats"
|
|
||||||
"gonum.org/v1/gonum/stat"
|
|
||||||
"pgregory.net/rapid"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/debug"
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
|
@ -59,7 +54,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
txPoolGasLimit = 10_000_000
|
// txPoolGasLimit = 10_000_000
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -3274,131 +3269,131 @@ func newTxs(pool *LegacyPool) *types.Transaction {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
type acc struct {
|
// type acc struct {
|
||||||
nonce uint64
|
// nonce uint64
|
||||||
key *ecdsa.PrivateKey
|
// key *ecdsa.PrivateKey
|
||||||
account common.Address
|
// account common.Address
|
||||||
}
|
// }
|
||||||
|
|
||||||
type testTx struct {
|
// type testTx struct {
|
||||||
tx *types.Transaction
|
// tx *types.Transaction
|
||||||
idx int
|
// idx int
|
||||||
isLocal bool
|
// isLocal bool
|
||||||
}
|
// }
|
||||||
|
|
||||||
const localIdx = 0
|
// const localIdx = 0
|
||||||
|
|
||||||
func getTransactionGen(t *rapid.T, keys []*acc, nonces []uint64, localKey *acc, gasPriceMin, gasPriceMax, gasLimitMin, gasLimitMax uint64) *testTx {
|
// func getTransactionGen(t *rapid.T, keys []*acc, nonces []uint64, localKey *acc, gasPriceMin, gasPriceMax, gasLimitMin, gasLimitMax uint64) *testTx {
|
||||||
idx := rapid.IntRange(0, len(keys)-1).Draw(t, "accIdx").(int)
|
// idx := rapid.IntRange(0, len(keys)-1).Draw(t, "accIdx").(int)
|
||||||
|
|
||||||
var (
|
// var (
|
||||||
isLocal bool
|
// isLocal bool
|
||||||
key *ecdsa.PrivateKey
|
// key *ecdsa.PrivateKey
|
||||||
)
|
// )
|
||||||
|
|
||||||
if idx == localIdx {
|
// if idx == localIdx {
|
||||||
isLocal = true
|
// isLocal = true
|
||||||
key = localKey.key
|
// key = localKey.key
|
||||||
} else {
|
// } else {
|
||||||
key = keys[idx].key
|
// key = keys[idx].key
|
||||||
}
|
// }
|
||||||
|
|
||||||
nonces[idx]++
|
// nonces[idx]++
|
||||||
|
|
||||||
gasPriceUint := rapid.Uint64Range(gasPriceMin, gasPriceMax).Draw(t, "gasPrice").(uint64)
|
// gasPriceUint := rapid.Uint64Range(gasPriceMin, gasPriceMax).Draw(t, "gasPrice").(uint64)
|
||||||
gasPrice := big.NewInt(0).SetUint64(gasPriceUint)
|
// gasPrice := big.NewInt(0).SetUint64(gasPriceUint)
|
||||||
gasLimit := rapid.Uint64Range(gasLimitMin, gasLimitMax).Draw(t, "gasLimit").(uint64)
|
// gasLimit := rapid.Uint64Range(gasLimitMin, gasLimitMax).Draw(t, "gasLimit").(uint64)
|
||||||
|
|
||||||
return &testTx{
|
// return &testTx{
|
||||||
tx: pricedTransaction(nonces[idx]-1, gasLimit, gasPrice, key),
|
// tx: pricedTransaction(nonces[idx]-1, gasLimit, gasPrice, key),
|
||||||
idx: idx,
|
// idx: idx,
|
||||||
isLocal: isLocal,
|
// isLocal: isLocal,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
type transactionBatches struct {
|
// type transactionBatches struct {
|
||||||
txs []*testTx
|
// txs []*testTx
|
||||||
totalTxs int
|
// totalTxs int
|
||||||
}
|
// }
|
||||||
|
|
||||||
func transactionsGen(keys []*acc, nonces []uint64, localKey *acc, minTxs int, maxTxs int, gasPriceMin, gasPriceMax, gasLimitMin, gasLimitMax uint64, caseParams *strings.Builder) func(t *rapid.T) *transactionBatches {
|
// func transactionsGen(keys []*acc, nonces []uint64, localKey *acc, minTxs int, maxTxs int, gasPriceMin, gasPriceMax, gasLimitMin, gasLimitMax uint64, caseParams *strings.Builder) func(t *rapid.T) *transactionBatches {
|
||||||
return func(t *rapid.T) *transactionBatches {
|
// return func(t *rapid.T) *transactionBatches {
|
||||||
totalTxs := rapid.IntRange(minTxs, maxTxs).Draw(t, "totalTxs").(int)
|
// totalTxs := rapid.IntRange(minTxs, maxTxs).Draw(t, "totalTxs").(int)
|
||||||
txs := make([]*testTx, totalTxs)
|
// txs := make([]*testTx, totalTxs)
|
||||||
|
|
||||||
gasValues := make([]float64, totalTxs)
|
// gasValues := make([]float64, totalTxs)
|
||||||
|
|
||||||
fmt.Fprintf(caseParams, " totalTxs = %d;", totalTxs)
|
// fmt.Fprintf(caseParams, " totalTxs = %d;", totalTxs)
|
||||||
|
|
||||||
keys = keys[:len(nonces)]
|
// keys = keys[:len(nonces)]
|
||||||
|
|
||||||
for i := 0; i < totalTxs; i++ {
|
// for i := 0; i < totalTxs; i++ {
|
||||||
txs[i] = getTransactionGen(t, keys, nonces, localKey, gasPriceMin, gasPriceMax, gasLimitMin, gasLimitMax)
|
// txs[i] = getTransactionGen(t, keys, nonces, localKey, gasPriceMin, gasPriceMax, gasLimitMin, gasLimitMax)
|
||||||
|
|
||||||
gasValues[i] = float64(txs[i].tx.Gas())
|
// gasValues[i] = float64(txs[i].tx.Gas())
|
||||||
}
|
// }
|
||||||
|
|
||||||
mean, stddev := stat.MeanStdDev(gasValues, nil)
|
// mean, stddev := stat.MeanStdDev(gasValues, nil)
|
||||||
fmt.Fprintf(caseParams, " gasValues mean %d, stdev %d, %d-%d);", int64(mean), int64(stddev), int64(floats.Min(gasValues)), int64(floats.Max(gasValues)))
|
// fmt.Fprintf(caseParams, " gasValues mean %d, stdev %d, %d-%d);", int64(mean), int64(stddev), int64(floats.Min(gasValues)), int64(floats.Max(gasValues)))
|
||||||
|
|
||||||
return &transactionBatches{txs, totalTxs}
|
// return &transactionBatches{txs, totalTxs}
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
type txPoolRapidConfig struct {
|
// type txPoolRapidConfig struct {
|
||||||
gasLimit uint64
|
// gasLimit uint64
|
||||||
avgBlockTxs uint64
|
// avgBlockTxs uint64
|
||||||
|
|
||||||
minTxs int
|
// minTxs int
|
||||||
maxTxs int
|
// maxTxs int
|
||||||
|
|
||||||
minAccs int
|
// minAccs int
|
||||||
maxAccs int
|
// maxAccs int
|
||||||
|
|
||||||
// less tweakable, more like constants
|
// // less tweakable, more like constants
|
||||||
gasPriceMin uint64
|
// gasPriceMin uint64
|
||||||
gasPriceMax uint64
|
// gasPriceMax uint64
|
||||||
|
|
||||||
gasLimitMin uint64
|
// gasLimitMin uint64
|
||||||
gasLimitMax uint64
|
// gasLimitMax uint64
|
||||||
|
|
||||||
balance int64
|
// balance int64
|
||||||
|
|
||||||
blockTime time.Duration
|
// blockTime time.Duration
|
||||||
maxEmptyBlocks int
|
// maxEmptyBlocks int
|
||||||
maxStuckBlocks int
|
// maxStuckBlocks int
|
||||||
}
|
// }
|
||||||
|
|
||||||
func defaultTxPoolRapidConfig() txPoolRapidConfig {
|
// func defaultTxPoolRapidConfig() txPoolRapidConfig {
|
||||||
gasLimit := uint64(30_000_000)
|
// gasLimit := uint64(30_000_000)
|
||||||
avgBlockTxs := gasLimit/params.TxGas + 1
|
// avgBlockTxs := gasLimit/params.TxGas + 1
|
||||||
maxTxs := int(25 * avgBlockTxs)
|
// maxTxs := int(25 * avgBlockTxs)
|
||||||
|
|
||||||
return txPoolRapidConfig{
|
// return txPoolRapidConfig{
|
||||||
gasLimit: gasLimit,
|
// gasLimit: gasLimit,
|
||||||
|
|
||||||
avgBlockTxs: avgBlockTxs,
|
// avgBlockTxs: avgBlockTxs,
|
||||||
|
|
||||||
minTxs: 1,
|
// minTxs: 1,
|
||||||
maxTxs: maxTxs,
|
// maxTxs: maxTxs,
|
||||||
|
|
||||||
minAccs: 1,
|
// minAccs: 1,
|
||||||
maxAccs: maxTxs,
|
// maxAccs: maxTxs,
|
||||||
|
|
||||||
// less tweakable, more like constants
|
// // less tweakable, more like constants
|
||||||
gasPriceMin: 1,
|
// gasPriceMin: 1,
|
||||||
gasPriceMax: 1_000,
|
// gasPriceMax: 1_000,
|
||||||
|
|
||||||
gasLimitMin: params.TxGas,
|
// gasLimitMin: params.TxGas,
|
||||||
gasLimitMax: gasLimit / 2,
|
// gasLimitMax: gasLimit / 2,
|
||||||
|
|
||||||
balance: 0xffffffffffffff,
|
// balance: 0xffffffffffffff,
|
||||||
|
|
||||||
blockTime: 2 * time.Second,
|
// blockTime: 2 * time.Second,
|
||||||
maxEmptyBlocks: 10,
|
// maxEmptyBlocks: 10,
|
||||||
maxStuckBlocks: 10,
|
// maxStuckBlocks: 10,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// TODO - Fix Later
|
// TODO - Fix Later
|
||||||
// TestSmallTxPool is not something to run in parallel as far it uses all CPUs
|
// TestSmallTxPool is not something to run in parallel as far it uses all CPUs
|
||||||
|
|
@ -4558,163 +4553,163 @@ func BenchmarkBigs(b *testing.B) {
|
||||||
// common.NowMilliseconds(), time.Duration(mean), time.Duration(stddev), time.Duration(floats.Min(pendingDurationsFloat)), time.Duration(floats.Max(pendingDurationsFloat)))
|
// common.NowMilliseconds(), time.Duration(mean), time.Duration(stddev), time.Duration(floats.Min(pendingDurationsFloat)), time.Duration(floats.Max(pendingDurationsFloat)))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func addTransactionsBatches(tb testing.TB, batches []types.Transactions, fn func(types.Transactions) error, done chan struct{}, timeoutDuration time.Duration, tickerDuration time.Duration, name string, thread int) {
|
// func addTransactionsBatches(tb testing.TB, batches []types.Transactions, fn func(types.Transactions) error, done chan struct{}, timeoutDuration time.Duration, tickerDuration time.Duration, name string, thread int) {
|
||||||
tb.Helper()
|
// tb.Helper()
|
||||||
|
|
||||||
tb.Logf("[%s] starting %s", common.NowMilliseconds(), name)
|
// tb.Logf("[%s] starting %s", common.NowMilliseconds(), name)
|
||||||
|
|
||||||
defer func() {
|
// defer func() {
|
||||||
tb.Logf("[%s] stop %s", common.NowMilliseconds(), name)
|
// tb.Logf("[%s] stop %s", common.NowMilliseconds(), name)
|
||||||
}()
|
// }()
|
||||||
|
|
||||||
for _, batch := range batches {
|
// for _, batch := range batches {
|
||||||
batch := batch
|
// batch := batch
|
||||||
|
|
||||||
select {
|
// select {
|
||||||
case <-done:
|
// case <-done:
|
||||||
return
|
// return
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
|
|
||||||
runWithTimeout(tb, func(_ chan struct{}) {
|
// runWithTimeout(tb, func(_ chan struct{}) {
|
||||||
err := fn(batch)
|
// err := fn(batch)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
tb.Logf("[%s] %s error: %s", common.NowMilliseconds(), name, err)
|
// tb.Logf("[%s] %s error: %s", common.NowMilliseconds(), name, err)
|
||||||
}
|
// }
|
||||||
}, done, name, timeoutDuration, 0, thread)
|
// }, done, name, timeoutDuration, 0, thread)
|
||||||
|
|
||||||
time.Sleep(tickerDuration)
|
// time.Sleep(tickerDuration)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func addTransactions(tb testing.TB, batches []types.Transactions, fn func(*types.Transaction) error, done chan struct{}, timeoutDuration time.Duration, tickerDuration time.Duration, name string, thread int) {
|
// func addTransactions(tb testing.TB, batches []types.Transactions, fn func(*types.Transaction) error, done chan struct{}, timeoutDuration time.Duration, tickerDuration time.Duration, name string, thread int) {
|
||||||
tb.Helper()
|
// tb.Helper()
|
||||||
|
|
||||||
tb.Logf("[%s] starting %s", common.NowMilliseconds(), name)
|
// tb.Logf("[%s] starting %s", common.NowMilliseconds(), name)
|
||||||
|
|
||||||
defer func() {
|
// defer func() {
|
||||||
tb.Logf("[%s] stop %s", common.NowMilliseconds(), name)
|
// tb.Logf("[%s] stop %s", common.NowMilliseconds(), name)
|
||||||
}()
|
// }()
|
||||||
|
|
||||||
for _, batch := range batches {
|
// for _, batch := range batches {
|
||||||
for _, tx := range batch {
|
// for _, tx := range batch {
|
||||||
tx := tx
|
// tx := tx
|
||||||
|
|
||||||
select {
|
// select {
|
||||||
case <-done:
|
// case <-done:
|
||||||
return
|
// return
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
|
|
||||||
runWithTimeout(tb, func(_ chan struct{}) {
|
// runWithTimeout(tb, func(_ chan struct{}) {
|
||||||
err := fn(tx)
|
// err := fn(tx)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
tb.Logf("%s error: %s", name, err)
|
// tb.Logf("%s error: %s", name, err)
|
||||||
}
|
// }
|
||||||
}, done, name, timeoutDuration, 0, thread)
|
// }, done, name, timeoutDuration, 0, thread)
|
||||||
|
|
||||||
time.Sleep(tickerDuration)
|
// time.Sleep(tickerDuration)
|
||||||
}
|
// }
|
||||||
|
|
||||||
time.Sleep(tickerDuration)
|
// time.Sleep(tickerDuration)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func getFnForBatches(fn func([]*types.Transaction) []error) func(types.Transactions) error {
|
// func getFnForBatches(fn func([]*types.Transaction) []error) func(types.Transactions) error {
|
||||||
return func(batch types.Transactions) error {
|
// return func(batch types.Transactions) error {
|
||||||
errs := fn(batch)
|
// errs := fn(batch)
|
||||||
if len(errs) != 0 {
|
// if len(errs) != 0 {
|
||||||
return errs[0]
|
// return errs[0]
|
||||||
}
|
// }
|
||||||
|
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//nolint:unparam
|
//nolint:unparam
|
||||||
func runWithTicker(tb testing.TB, fn func(c chan struct{}), done chan struct{}, name string, tickerDuration, timeoutDuration time.Duration, thread int) {
|
// func runWithTicker(tb testing.TB, fn func(c chan struct{}), done chan struct{}, name string, tickerDuration, timeoutDuration time.Duration, thread int) {
|
||||||
tb.Helper()
|
// tb.Helper()
|
||||||
|
|
||||||
select {
|
// select {
|
||||||
case <-done:
|
// case <-done:
|
||||||
tb.Logf("[%s] Short path. finishing outer runWithTicker for %q, thread %d", common.NowMilliseconds(), name, thread)
|
// tb.Logf("[%s] Short path. finishing outer runWithTicker for %q, thread %d", common.NowMilliseconds(), name, thread)
|
||||||
|
|
||||||
return
|
// return
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
|
|
||||||
defer func() {
|
// defer func() {
|
||||||
tb.Logf("[%s] finishing outer runWithTicker for %q, thread %d", common.NowMilliseconds(), name, thread)
|
// tb.Logf("[%s] finishing outer runWithTicker for %q, thread %d", common.NowMilliseconds(), name, thread)
|
||||||
}()
|
// }()
|
||||||
|
|
||||||
localTicker := time.NewTicker(tickerDuration)
|
// localTicker := time.NewTicker(tickerDuration)
|
||||||
defer localTicker.Stop()
|
// defer localTicker.Stop()
|
||||||
|
|
||||||
n := 0
|
// n := 0
|
||||||
|
|
||||||
for range localTicker.C {
|
// for range localTicker.C {
|
||||||
select {
|
// select {
|
||||||
case <-done:
|
// case <-done:
|
||||||
return
|
// return
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
|
|
||||||
runWithTimeout(tb, fn, done, name, timeoutDuration, n, thread)
|
// runWithTimeout(tb, fn, done, name, timeoutDuration, n, thread)
|
||||||
|
|
||||||
n++
|
// n++
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func runWithTimeout(tb testing.TB, fn func(chan struct{}), outerDone chan struct{}, name string, timeoutDuration time.Duration, n, thread int) {
|
// func runWithTimeout(tb testing.TB, fn func(chan struct{}), outerDone chan struct{}, name string, timeoutDuration time.Duration, n, thread int) {
|
||||||
tb.Helper()
|
// tb.Helper()
|
||||||
|
|
||||||
select {
|
// select {
|
||||||
case <-outerDone:
|
// case <-outerDone:
|
||||||
tb.Logf("[%s] Short path. exiting inner runWithTimeout by outer exit event for %q, thread %d, iteration %d", common.NowMilliseconds(), name, thread, n)
|
// tb.Logf("[%s] Short path. exiting inner runWithTimeout by outer exit event for %q, thread %d, iteration %d", common.NowMilliseconds(), name, thread, n)
|
||||||
|
|
||||||
return
|
// return
|
||||||
default:
|
// default:
|
||||||
}
|
// }
|
||||||
|
|
||||||
timeout := time.NewTimer(timeoutDuration)
|
// timeout := time.NewTimer(timeoutDuration)
|
||||||
defer timeout.Stop()
|
// defer timeout.Stop()
|
||||||
|
|
||||||
doneCh := make(chan struct{})
|
// doneCh := make(chan struct{})
|
||||||
|
|
||||||
isError := new(int32)
|
// isError := new(int32)
|
||||||
*isError = 0
|
// *isError = 0
|
||||||
|
|
||||||
go func() {
|
// go func() {
|
||||||
defer close(doneCh)
|
// defer close(doneCh)
|
||||||
|
|
||||||
select {
|
// select {
|
||||||
case <-outerDone:
|
// case <-outerDone:
|
||||||
return
|
// return
|
||||||
default:
|
// default:
|
||||||
fn(doneCh)
|
// fn(doneCh)
|
||||||
}
|
// }
|
||||||
}()
|
// }()
|
||||||
|
|
||||||
const isDebug = false
|
// const isDebug = false
|
||||||
|
|
||||||
var stack string
|
// var stack string
|
||||||
|
|
||||||
select {
|
// select {
|
||||||
case <-outerDone:
|
// case <-outerDone:
|
||||||
tb.Logf("[%s] exiting inner runWithTimeout by outer exit event for %q, thread %d, iteration %d", common.NowMilliseconds(), name, thread, n)
|
// tb.Logf("[%s] exiting inner runWithTimeout by outer exit event for %q, thread %d, iteration %d", common.NowMilliseconds(), name, thread, n)
|
||||||
case <-doneCh:
|
// case <-doneCh:
|
||||||
// only for debug
|
// // only for debug
|
||||||
//tb.Logf("[%s] exiting inner runWithTimeout by successful call for %q, thread %d, iteration %d", common.NowMilliseconds(), name, thread, n)
|
// //tb.Logf("[%s] exiting inner runWithTimeout by successful call for %q, thread %d, iteration %d", common.NowMilliseconds(), name, thread, n)
|
||||||
case <-timeout.C:
|
// case <-timeout.C:
|
||||||
atomic.StoreInt32(isError, 1)
|
// atomic.StoreInt32(isError, 1)
|
||||||
|
|
||||||
if isDebug {
|
// if isDebug {
|
||||||
stack = string(debug.Stack(true))
|
// stack = string(debug.Stack(true))
|
||||||
}
|
// }
|
||||||
|
|
||||||
tb.Errorf("[%s] %s timeouted, thread %d, iteration %d. Stack %s", common.NowMilliseconds(), name, thread, n, stack)
|
// tb.Errorf("[%s] %s timeouted, thread %d, iteration %d. Stack %s", common.NowMilliseconds(), name, thread, n, stack)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Benchmarks the speed of batch transaction insertion in case of multiple accounts.
|
// Benchmarks the speed of batch transaction insertion in case of multiple accounts.
|
||||||
func BenchmarkMultiAccountBatchInsert(b *testing.B) {
|
func BenchmarkMultiAccountBatchInsert(b *testing.B) {
|
||||||
|
|
|
||||||
|
|
@ -588,116 +588,3 @@ func (s *TxByPriceAndTime) Pop() interface{} {
|
||||||
|
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransactionsByPriceAndNonce represents a set of transactions that can return
|
|
||||||
// transactions in a profit-maximizing sorted order, while supporting removing
|
|
||||||
// entire batches of transactions for non-executable accounts.
|
|
||||||
type TransactionsByPriceAndNonce struct {
|
|
||||||
txs map[common.Address]Transactions // Per account nonce-sorted list of transactions
|
|
||||||
heads TxByPriceAndTime // Next transaction for each unique account (price heap)
|
|
||||||
signer Signer // Signer for the set of transactions
|
|
||||||
baseFee *uint256.Int // Current base fee
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTransactionsByPriceAndNonce creates a transaction set that can retrieve
|
|
||||||
// price sorted transactions in a nonce-honouring way.
|
|
||||||
//
|
|
||||||
// Note, the input map is reowned so the caller should not interact any more with
|
|
||||||
// if after providing it to the constructor.
|
|
||||||
/*
|
|
||||||
func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions, baseFee *big.Int) *TransactionsByPriceAndNonce {
|
|
||||||
// Initialize a price and received time based heap with the head transactions
|
|
||||||
heads := make(TxByPriceAndTime, 0, len(txs))
|
|
||||||
for from, accTxs := range txs {
|
|
||||||
if len(accTxs) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
acc, _ := Sender(signer, accTxs[0])
|
|
||||||
wrapped, err := NewTxWithMinerFee(accTxs[0], baseFee)
|
|
||||||
// Remove transaction if sender doesn't match from, or if wrapping fails.
|
|
||||||
if acc != from || err != nil {
|
|
||||||
delete(txs, from)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
heads = append(heads, wrapped)
|
|
||||||
txs[from] = accTxs[1:]
|
|
||||||
}
|
|
||||||
heap.Init(&heads)
|
|
||||||
|
|
||||||
// Assemble and return the transaction set
|
|
||||||
return &TransactionsByPriceAndNonce{
|
|
||||||
txs: txs,
|
|
||||||
heads: heads,
|
|
||||||
signer: signer,
|
|
||||||
baseFee: baseFee,
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions, baseFee *uint256.Int) *TransactionsByPriceAndNonce {
|
|
||||||
// // Initialize a price and received time based heap with the head transactions
|
|
||||||
// heads := make(TxByPriceAndTime, 0, len(txs))
|
|
||||||
|
|
||||||
// for from, accTxs := range txs {
|
|
||||||
// if len(accTxs) == 0 {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// acc, _ := Sender(signer, accTxs[0])
|
|
||||||
// wrapped, err := NewTxWithMinerFee(accTxs[0], baseFee)
|
|
||||||
|
|
||||||
// // Remove transaction if sender doesn't match from, or if wrapping fails.
|
|
||||||
// if acc != from || err != nil {
|
|
||||||
// delete(txs, from)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// heads = append(heads, wrapped)
|
|
||||||
// txs[from] = accTxs[1:]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// heap.Init(&heads)
|
|
||||||
|
|
||||||
// // Assemble and return the transaction set
|
|
||||||
// return &TransactionsByPriceAndNonce{
|
|
||||||
// txs: txs,
|
|
||||||
// heads: heads,
|
|
||||||
// signer: signer,
|
|
||||||
// baseFee: baseFee,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Peek returns the next transaction by price.
|
|
||||||
// func (t *TransactionsByPriceAndNonce) Peek() *Transaction {
|
|
||||||
// if len(t.heads) == 0 {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return t.heads[0].tx
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Shift replaces the current best head with the next one from the same account.
|
|
||||||
// func (t *TransactionsByPriceAndNonce) Shift() {
|
|
||||||
// acc, _ := Sender(t.signer, t.heads[0].tx)
|
|
||||||
// if txs, ok := t.txs[acc]; ok && len(txs) > 0 {
|
|
||||||
// if wrapped, err := NewTxWithMinerFee(txs[0], t.baseFee); err == nil {
|
|
||||||
// t.heads[0], t.txs[acc] = wrapped, txs[1:]
|
|
||||||
// heap.Fix(&t.heads, 0)
|
|
||||||
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// heap.Pop(&t.heads)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (t *TransactionsByPriceAndNonce) GetTxs() int {
|
|
||||||
// return len(t.txs)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Pop removes the best transaction, *not* replacing it with the next one from
|
|
||||||
// // the same account. This should be used when a transaction cannot be executed
|
|
||||||
// // and hence all subsequent ones should be discarded from the same account.
|
|
||||||
// func (t *TransactionsByPriceAndNonce) Pop() {
|
|
||||||
// heap.Pop(&t.heads)
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
|
|
@ -146,11 +146,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||||
if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb); err != nil {
|
if err := pruner.RecoverPruning(stack.ResolvePath(""), chainDb); err != nil {
|
||||||
log.Error("Failed to recover state", "error", err)
|
log.Error("Failed to recover state", "error", err)
|
||||||
}
|
}
|
||||||
// Transfer mining-related config to the ethash config.
|
|
||||||
chainConfig, err := core.LoadChainConfig(chainDb, config.Genesis)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// START: Bor changes
|
// START: Bor changes
|
||||||
eth := &Ethereum{
|
eth := &Ethereum{
|
||||||
|
|
|
||||||
|
|
@ -894,7 +894,6 @@ func (d *Downloader) getFetchHeadersByNumber(p *peerConnection) func(number uint
|
||||||
// In the rare scenario when we ended up on a long reorganisation (i.e. none of
|
// In the rare scenario when we ended up on a long reorganisation (i.e. none of
|
||||||
// the head links match), we do a binary search to find the common ancestor.
|
// the head links match), we do a binary search to find the common ancestor.
|
||||||
func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) (uint64, error) {
|
func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) (uint64, error) {
|
||||||
|
|
||||||
// Check the validity of peer from which the chain is to be downloaded
|
// Check the validity of peer from which the chain is to be downloaded
|
||||||
if d.ChainValidator != nil {
|
if d.ChainValidator != nil {
|
||||||
if _, err := d.IsValidPeer(d.getFetchHeadersByNumber(p)); err != nil {
|
if _, err := d.IsValidPeer(d.getFetchHeadersByNumber(p)); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,6 @@ func newTesterWithNotification(t *testing.T, success func()) *downloadTester {
|
||||||
return tester
|
return tester
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl *downloadTester) setWhitelist(w ethereum.ChainValidator) {
|
|
||||||
dl.downloader.ChainValidator = w
|
|
||||||
}
|
|
||||||
|
|
||||||
// terminate aborts any operations on the embedded downloader and releases all
|
// terminate aborts any operations on the embedded downloader and releases all
|
||||||
// held resources.
|
// held resources.
|
||||||
func (dl *downloadTester) terminate() {
|
func (dl *downloadTester) terminate() {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,6 @@ func (b *TestBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *TestBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
func (b *TestBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||||
|
|
||||||
if number := rawdb.ReadHeaderNumber(b.DB, hash); number != nil {
|
if number := rawdb.ReadHeaderNumber(b.DB, hash); number != nil {
|
||||||
block := rawdb.ReadBlock(b.DB, hash, *number)
|
block := rawdb.ReadBlock(b.DB, hash, *number)
|
||||||
return rawdb.ReadReceipts(b.DB, hash, *number, block.Time(), params.TestChainConfig), nil
|
return rawdb.ReadReceipts(b.DB, hash, *number, block.Time(), params.TestChainConfig), nil
|
||||||
|
|
|
||||||
|
|
@ -146,12 +146,6 @@ func fetchMilestoneTest(t *testing.T, heimdall *mockHeimdall, bor *bor.Bor, hand
|
||||||
require.Equal(t, milestones[len(milestones)-1].Hash, hash)
|
require.Equal(t, milestones[len(milestones)-1].Hash, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMockFetchCheckpointFn(number int64, err error) func(ctx context.Context) (int64, error) {
|
|
||||||
return func(_ context.Context) (int64, error) {
|
|
||||||
return number, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createMockCheckpoints(count int) []*checkpoint.Checkpoint {
|
func createMockCheckpoints(count int) []*checkpoint.Checkpoint {
|
||||||
var (
|
var (
|
||||||
checkpoints []*checkpoint.Checkpoint = make([]*checkpoint.Checkpoint, count)
|
checkpoints []*checkpoint.Checkpoint = make([]*checkpoint.Checkpoint, count)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -888,7 +887,7 @@ txloop:
|
||||||
if *config.BorTraceEnabled {
|
if *config.BorTraceEnabled {
|
||||||
callmsg := prepareCallMessage(*msg)
|
callmsg := prepareCallMessage(*msg)
|
||||||
// nolint : contextcheck
|
// nolint : contextcheck
|
||||||
if _, err := statefull.ApplyBorMessage(*vmenv, callmsg); err != nil {
|
if _, err := statefull.ApplyBorMessage(vmenv, callmsg); err != nil {
|
||||||
failed = err
|
failed = err
|
||||||
break txloop
|
break txloop
|
||||||
}
|
}
|
||||||
|
|
@ -957,7 +956,7 @@ txloop:
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that the file exists and write IOdump
|
// make sure that the file exists and write IOdump
|
||||||
err = ioutil.WriteFile(filepath.Join(path, "data.csv"), []byte(fmt.Sprint(IOdump)), 0600)
|
err = os.WriteFile(filepath.Join(path, "data.csv"), []byte(fmt.Sprint(IOdump)), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1095,7 +1094,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
|
||||||
if stateSyncPresent && i == len(txs)-1 {
|
if stateSyncPresent && i == len(txs)-1 {
|
||||||
if *config.BorTraceEnabled {
|
if *config.BorTraceEnabled {
|
||||||
callmsg := prepareCallMessage(*msg)
|
callmsg := prepareCallMessage(*msg)
|
||||||
_, err = statefull.ApplyBorMessage(*vmenv, callmsg)
|
_, err = statefull.ApplyBorMessage(vmenv, callmsg)
|
||||||
|
|
||||||
if writer != nil {
|
if writer != nil {
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
|
|
@ -1340,7 +1339,7 @@ func (api *API) traceTx(ctx context.Context, message *core.Message, txctx *Conte
|
||||||
if *config.BorTx {
|
if *config.BorTx {
|
||||||
callmsg := prepareCallMessage(*message)
|
callmsg := prepareCallMessage(*message)
|
||||||
// nolint : contextcheck
|
// nolint : contextcheck
|
||||||
if _, err := statefull.ApplyBorMessage(*vmenv, callmsg); err != nil {
|
if _, err := statefull.ApplyBorMessage(vmenv, callmsg); err != nil {
|
||||||
return nil, fmt.Errorf("tracing failed: %w", err)
|
return nil, fmt.Errorf("tracing failed: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T
|
||||||
|
|
||||||
if borTx {
|
if borTx {
|
||||||
callmsg := prepareCallMessage(*message)
|
callmsg := prepareCallMessage(*message)
|
||||||
execRes, err = statefull.ApplyBorMessage(*vmenv, callmsg)
|
execRes, err = statefull.ApplyBorMessage(vmenv, callmsg)
|
||||||
} else {
|
} else {
|
||||||
execRes, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.GasLimit), nil)
|
execRes, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.GasLimit), nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -180,6 +180,7 @@ type AncientStore interface {
|
||||||
|
|
||||||
// Database contains all the methods required by the high level database to not
|
// Database contains all the methods required by the high level database to not
|
||||||
// only access the key-value data store but also the chain freezer.
|
// only access the key-value data store but also the chain freezer.
|
||||||
|
//
|
||||||
//go:generate mockgen -destination=../eth/filters/IDatabase.go -package=filters . Database
|
//go:generate mockgen -destination=../eth/filters/IDatabase.go -package=filters . Database
|
||||||
type Database interface {
|
type Database interface {
|
||||||
Reader
|
Reader
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/ryanuber/columnize"
|
"github.com/ryanuber/columnize"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -222,7 +223,7 @@ func (m *Meta2) NewFlagSet(n string) *flagset.Flagset {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Meta2) Conn() (*grpc.ClientConn, error) {
|
func (m *Meta2) Conn() (*grpc.ClientConn, error) {
|
||||||
conn, err := grpc.Dial(m.addr, grpc.WithInsecure())
|
conn, err := grpc.Dial(m.addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to connect to server: %v", err)
|
return nil, fmt.Errorf("failed to connect to server: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -107,7 +106,7 @@ func (d *debugEnv) init() error {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Generate temp directory
|
// Generate temp directory
|
||||||
tmp, err = ioutil.TempDir(os.TempDir(), d.name)
|
tmp, err = os.MkdirTemp(os.TempDir(), d.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating tmp directory: %s", err.Error())
|
return fmt.Errorf("error creating tmp directory: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +187,7 @@ func (d *debugEnv) writeJSON(name string, msg protoreflect.ProtoMessage) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filepath.Join(d.dst, name), data, 0600); err != nil {
|
if err := os.WriteFile(filepath.Join(d.dst, name), data, 0600); err != nil {
|
||||||
return fmt.Errorf("failed to write status: %v", err)
|
return fmt.Errorf("failed to write status: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -1093,7 +1092,7 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
|
||||||
mem.Total = 2 * 1024 * 1024 * 1024
|
mem.Total = 2 * 1024 * 1024 * 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
allowance := uint64(mem.Total / 1024 / 1024 / 3)
|
allowance := mem.Total / 1024 / 1024 / 3
|
||||||
if cache > allowance {
|
if cache > allowance {
|
||||||
log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
|
log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
|
||||||
cache = allowance
|
cache = allowance
|
||||||
|
|
@ -1525,7 +1524,7 @@ func Hostname() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakePasswordListFromFile(path string) ([]string, error) {
|
func MakePasswordListFromFile(path string) ([]string, error) {
|
||||||
text, err := ioutil.ReadFile(path)
|
text, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read password file: %v", err)
|
return nil, fmt.Errorf("failed to read password file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,12 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"sync/atomic"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var initialPort uint64 = 61000
|
|
||||||
|
|
||||||
// nextPort gives the next available port starting from 60000
|
|
||||||
func nextPort() uint64 {
|
|
||||||
log.Info("Checking for new port", "current", initialPort)
|
|
||||||
port := atomic.AddUint64(&initialPort, 1)
|
|
||||||
addr := fmt.Sprintf("localhost:%d", port)
|
|
||||||
|
|
||||||
lis, err := net.Listen("tcp", addr)
|
|
||||||
if err == nil {
|
|
||||||
lis.Close()
|
|
||||||
|
|
||||||
return port
|
|
||||||
} else {
|
|
||||||
return nextPort()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestServer_DeveloperMode(t *testing.T) {
|
func TestServer_DeveloperMode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
@ -49,7 +26,7 @@ func TestServer_DeveloperMode(t *testing.T) {
|
||||||
// record the initial block number
|
// record the initial block number
|
||||||
blockNumber := server.backend.BlockChain().CurrentBlock().Number.Int64()
|
blockNumber := server.backend.BlockChain().CurrentBlock().Number.Int64()
|
||||||
|
|
||||||
var i int64 = 0
|
var i int64
|
||||||
for i = 0; i < 3; i++ {
|
for i = 0; i < 3; i++ {
|
||||||
// We expect the node to mine blocks every `config.Developer.Period` time period
|
// We expect the node to mine blocks every `config.Developer.Period` time period
|
||||||
time.Sleep(time.Duration(config.Developer.Period) * time.Second)
|
time.Sleep(time.Duration(config.Developer.Period) * time.Second)
|
||||||
|
|
|
||||||
|
|
@ -1811,17 +1811,6 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By
|
||||||
return blob
|
return blob
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
|
|
||||||
func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig, db ethdb.Database) *RPCTransaction {
|
|
||||||
for idx, tx := range b.Transactions() {
|
|
||||||
if tx.Hash() == hash {
|
|
||||||
return newRPCTransactionFromBlockIndex(b, uint64(idx), config, db)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// accessListResult returns an optional accesslist
|
// accessListResult returns an optional accesslist
|
||||||
// It's the result of the `debug_createAccessList` RPC call.
|
// It's the result of the `debug_createAccessList` RPC call.
|
||||||
// It contains an error if the transaction itself failed.
|
// It contains an error if the transaction itself failed.
|
||||||
|
|
|
||||||
|
|
@ -19,24 +19,15 @@ package miner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/clique"
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool"
|
"github.com/ethereum/go-ethereum/core/txpool"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type mockBackend struct {
|
type mockBackend struct {
|
||||||
|
|
@ -68,36 +59,6 @@ func (m *mockBackend) StateAtBlock(block *types.Block, reexec uint64, base *stat
|
||||||
return nil, errors.New("not supported")
|
return nil, errors.New("not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
type testBlockChain struct {
|
|
||||||
config *params.ChainConfig
|
|
||||||
statedb *state.StateDB
|
|
||||||
gasLimit uint64
|
|
||||||
chainHeadFeed *event.Feed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *testBlockChain) Config() *params.ChainConfig {
|
|
||||||
return bc.config
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *testBlockChain) CurrentBlock() *types.Header {
|
|
||||||
return &types.Header{
|
|
||||||
Number: new(big.Int),
|
|
||||||
GasLimit: bc.gasLimit,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *testBlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
|
|
||||||
return types.NewBlock(bc.CurrentBlock(), nil, nil, nil, trie.NewStackTrie(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *testBlockChain) StateAt(common.Hash) (*state.StateDB, error) {
|
|
||||||
return bc.statedb, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription {
|
|
||||||
return bc.chainHeadFeed.Subscribe(ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMiner(t *testing.T) {
|
func TestMiner(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
@ -338,76 +299,76 @@ func waitForMiningState(t *testing.T, m *Miner, mining bool) {
|
||||||
t.Fatalf("Mining() == %t, want %t", state, mining)
|
t.Fatalf("Mining() == %t, want %t", state, mining)
|
||||||
}
|
}
|
||||||
|
|
||||||
func minerTestGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *core.Genesis {
|
// func minerTestGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *core.Genesis {
|
||||||
config := *params.AllCliqueProtocolChanges
|
// config := *params.AllCliqueProtocolChanges
|
||||||
config.Clique = ¶ms.CliqueConfig{
|
// config.Clique = ¶ms.CliqueConfig{
|
||||||
Period: period,
|
// Period: period,
|
||||||
Epoch: config.Clique.Epoch,
|
// Epoch: config.Clique.Epoch,
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Assemble and return the genesis with the precompiles and faucet pre-funded
|
// // Assemble and return the genesis with the precompiles and faucet pre-funded
|
||||||
return &core.Genesis{
|
// return &core.Genesis{
|
||||||
Config: &config,
|
// Config: &config,
|
||||||
ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...),
|
// ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...),
|
||||||
GasLimit: gasLimit,
|
// GasLimit: gasLimit,
|
||||||
BaseFee: big.NewInt(params.InitialBaseFee),
|
// BaseFee: big.NewInt(params.InitialBaseFee),
|
||||||
Difficulty: big.NewInt(1),
|
// Difficulty: big.NewInt(1),
|
||||||
Alloc: map[common.Address]core.GenesisAccount{
|
// Alloc: map[common.Address]core.GenesisAccount{
|
||||||
common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
|
// common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
|
||||||
common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256
|
// common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256
|
||||||
common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD
|
// common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD
|
||||||
common.BytesToAddress([]byte{4}): {Balance: big.NewInt(1)}, // Identity
|
// common.BytesToAddress([]byte{4}): {Balance: big.NewInt(1)}, // Identity
|
||||||
common.BytesToAddress([]byte{5}): {Balance: big.NewInt(1)}, // ModExp
|
// common.BytesToAddress([]byte{5}): {Balance: big.NewInt(1)}, // ModExp
|
||||||
common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
|
// common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
|
||||||
common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
|
// common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
|
||||||
common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
|
// common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
|
||||||
common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b
|
// common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b
|
||||||
faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
|
// faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
|
// func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
|
||||||
t.Helper()
|
// t.Helper()
|
||||||
|
|
||||||
// Create Ethash config
|
// // Create Ethash config
|
||||||
config := Config{
|
// config := Config{
|
||||||
Etherbase: common.HexToAddress("123456789"),
|
// Etherbase: common.HexToAddress("123456789"),
|
||||||
}
|
// }
|
||||||
// Create chainConfig
|
// // Create chainConfig
|
||||||
chainDB := rawdb.NewMemoryDatabase()
|
// chainDB := rawdb.NewMemoryDatabase()
|
||||||
genesis := minerTestGenesisBlock(15, 11_500_000, common.HexToAddress("12345"))
|
// genesis := minerTestGenesisBlock(15, 11_500_000, common.HexToAddress("12345"))
|
||||||
chainConfig, _, err := core.SetupGenesisBlock(chainDB, trie.NewDatabase(chainDB), genesis)
|
// chainConfig, _, err := core.SetupGenesisBlock(chainDB, trie.NewDatabase(chainDB), genesis)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
t.Fatalf("can't create new chain config: %v", err)
|
// t.Fatalf("can't create new chain config: %v", err)
|
||||||
}
|
// }
|
||||||
// Create consensus engine
|
// // Create consensus engine
|
||||||
engine := clique.New(chainConfig.Clique, chainDB)
|
// engine := clique.New(chainConfig.Clique, chainDB)
|
||||||
// Create Ethereum backend
|
// // Create Ethereum backend
|
||||||
bc, err := core.NewBlockChain(chainDB, nil, genesis, nil, engine, vm.Config{}, nil, nil, nil)
|
// bc, err := core.NewBlockChain(chainDB, nil, genesis, nil, engine, vm.Config{}, nil, nil, nil)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
t.Fatalf("can't create new chain %v", err)
|
// t.Fatalf("can't create new chain %v", err)
|
||||||
}
|
// }
|
||||||
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(chainDB), nil)
|
// statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(chainDB), nil)
|
||||||
blockchain := &testBlockChain{chainConfig, statedb, 10000000, new(event.Feed)}
|
// blockchain := &testBlockChain{chainConfig, statedb, 10000000, new(event.Feed)}
|
||||||
|
|
||||||
pool := legacypool.New(testTxPoolConfig, blockchain)
|
// pool := legacypool.New(testTxPoolConfig, blockchain)
|
||||||
txpool, _ := txpool.New(new(big.Int).SetUint64(testTxPoolConfig.PriceLimit), blockchain, []txpool.SubPool{pool})
|
// txpool, _ := txpool.New(new(big.Int).SetUint64(testTxPoolConfig.PriceLimit), blockchain, []txpool.SubPool{pool})
|
||||||
|
|
||||||
backend := NewMockBackend(bc, txpool)
|
// backend := NewMockBackend(bc, txpool)
|
||||||
// Create event Mux
|
// // Create event Mux
|
||||||
// nolint:staticcheck
|
// // nolint:staticcheck
|
||||||
mux := new(event.TypeMux)
|
// mux := new(event.TypeMux)
|
||||||
// Create Miner
|
// // Create Miner
|
||||||
miner := New(backend, &config, chainConfig, mux, engine, nil)
|
// miner := New(backend, &config, chainConfig, mux, engine, nil)
|
||||||
cleanup := func(skipMiner bool) {
|
// cleanup := func(skipMiner bool) {
|
||||||
bc.Stop()
|
// bc.Stop()
|
||||||
engine.Close()
|
// engine.Close()
|
||||||
txpool.Close()
|
// txpool.Close()
|
||||||
if !skipMiner {
|
// if !skipMiner {
|
||||||
miner.Close()
|
// miner.Close()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return miner, mux, cleanup
|
// return miner, mux, cleanup
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,6 @@ const (
|
||||||
// any newly arrived transactions.
|
// any newly arrived transactions.
|
||||||
minRecommitInterval = 1 * time.Second
|
minRecommitInterval = 1 * time.Second
|
||||||
|
|
||||||
// maxRecommitInterval is the maximum time interval to recreate the sealing block with
|
|
||||||
// any newly arrived transactions.
|
|
||||||
maxRecommitInterval = 15 * time.Second
|
|
||||||
|
|
||||||
// intervalAdjustRatio is the impact a single interval adjustment has on sealing work
|
// intervalAdjustRatio is the impact a single interval adjustment has on sealing work
|
||||||
// resubmitting interval.
|
// resubmitting interval.
|
||||||
intervalAdjustRatio = 0.1
|
intervalAdjustRatio = 0.1
|
||||||
|
|
@ -364,16 +360,6 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
|
||||||
return worker
|
return worker
|
||||||
}
|
}
|
||||||
|
|
||||||
// disablePreseal disables pre-sealing feature
|
|
||||||
func (w *worker) disablePreseal() {
|
|
||||||
w.noempty.Store(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// enablePreseal enables pre-sealing feature
|
|
||||||
func (w *worker) enablePreseal() {
|
|
||||||
w.noempty.Store(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// setEtherbase sets the etherbase used to initialize the block coinbase field.
|
// setEtherbase sets the etherbase used to initialize the block coinbase field.
|
||||||
func (w *worker) setEtherbase(addr common.Address) {
|
func (w *worker) setEtherbase(addr common.Address) {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
|
|
@ -1175,7 +1161,6 @@ mainloop:
|
||||||
env.header.Extra = append(tempVanity, blockExtraDataBytes...)
|
env.header.Extra = append(tempVanity, blockExtraDataBytes...)
|
||||||
|
|
||||||
env.header.Extra = append(env.header.Extra, tempSeal...)
|
env.header.Extra = append(env.header.Extra, tempSeal...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !w.IsRunning() && len(coalescedLogs) > 0 {
|
if !w.IsRunning() && len(coalescedLogs) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -814,14 +814,11 @@ func TestClientHTTP(t *testing.T) {
|
||||||
func TestClientReconnect(t *testing.T) {
|
func TestClientReconnect(t *testing.T) {
|
||||||
startServer := func(addr string) (*Server, net.Listener) {
|
startServer := func(addr string) (*Server, net.Listener) {
|
||||||
srv := newTestServer()
|
srv := newTestServer()
|
||||||
|
|
||||||
l, err := net.Listen("tcp", addr)
|
l, err := net.Listen("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("can't listen:", err)
|
t.Fatal("can't listen:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go http.Serve(l, srv.WebsocketHandler([]string{"*"}))
|
go http.Serve(l, srv.WebsocketHandler([]string{"*"}))
|
||||||
|
|
||||||
return srv, l
|
return srv, l
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -830,14 +827,10 @@ func TestClientReconnect(t *testing.T) {
|
||||||
|
|
||||||
// Start a server and corresponding client.
|
// Start a server and corresponding client.
|
||||||
s1, l1 := startServer("127.0.0.1:0")
|
s1, l1 := startServer("127.0.0.1:0")
|
||||||
|
|
||||||
client, err := DialContext(ctx, "ws://"+l1.Addr().String())
|
client, err := DialContext(ctx, "ws://"+l1.Addr().String())
|
||||||
defer client.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("can't dial", err)
|
t.Fatal("can't dial", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
// Perform a call. This should work because the server is up.
|
// Perform a call. This should work because the server is up.
|
||||||
|
|
@ -865,27 +858,22 @@ func TestClientReconnect(t *testing.T) {
|
||||||
defer s2.Stop()
|
defer s2.Stop()
|
||||||
|
|
||||||
start := make(chan struct{})
|
start := make(chan struct{})
|
||||||
|
|
||||||
errors := make(chan error, 20)
|
errors := make(chan error, 20)
|
||||||
for i := 0; i < cap(errors); i++ {
|
for i := 0; i < cap(errors); i++ {
|
||||||
go func() {
|
go func() {
|
||||||
<-start
|
<-start
|
||||||
|
|
||||||
var resp echoResult
|
var resp echoResult
|
||||||
errors <- client.CallContext(ctx, &resp, "test_echo", "", 3, nil)
|
errors <- client.CallContext(ctx, &resp, "test_echo", "", 3, nil)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
close(start)
|
close(start)
|
||||||
|
|
||||||
errcount := 0
|
errcount := 0
|
||||||
|
|
||||||
for i := 0; i < cap(errors); i++ {
|
for i := 0; i < cap(errors); i++ {
|
||||||
if err = <-errors; err != nil {
|
if err = <-errors; err != nil {
|
||||||
errcount++
|
errcount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Logf("%d errors, last error: %v", errcount, err)
|
t.Logf("%d errors, last error: %v", errcount, err)
|
||||||
|
|
||||||
if errcount > 1 {
|
if errcount > 1 {
|
||||||
t.Errorf("expected one error after disconnect, got %d", errcount)
|
t.Errorf("expected one error after disconnect, got %d", errcount)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -309,6 +309,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
||||||
return snaps, statedb, root, err
|
return snaps, statedb, root, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:unused
|
||||||
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
||||||
return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas]
|
return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ func NewSecure(stateRoot common.Hash, owner common.Hash, root common.Hash, db *D
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Root: root,
|
Root: root,
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewStateTrie(id, db)
|
return NewStateTrie(id, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,12 +65,11 @@ func NewStateTrie(id *ID, db *Database) (*StateTrie, error) {
|
||||||
if db == nil {
|
if db == nil {
|
||||||
panic("trie.NewStateTrie called without a database")
|
panic("trie.NewStateTrie called without a database")
|
||||||
}
|
}
|
||||||
|
|
||||||
trie, err := New(id, db)
|
trie, err := New(id, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// nolint
|
||||||
return &StateTrie{trie: *trie, preimages: db.preimages}, nil
|
return &StateTrie{trie: *trie, preimages: db.preimages}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,10 +103,8 @@ func (t *StateTrie) GetAccount(address common.Address) (*types.StateAccount, err
|
||||||
if res == nil || err != nil {
|
if res == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := new(types.StateAccount)
|
ret := new(types.StateAccount)
|
||||||
err = rlp.DecodeBytes(res, ret)
|
err = rlp.DecodeBytes(res, ret)
|
||||||
|
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,10 +116,8 @@ func (t *StateTrie) GetAccountByHash(addrHash common.Hash) (*types.StateAccount,
|
||||||
if res == nil || err != nil {
|
if res == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := new(types.StateAccount)
|
ret := new(types.StateAccount)
|
||||||
err = rlp.DecodeBytes(res, ret)
|
err = rlp.DecodeBytes(res, ret)
|
||||||
|
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,7 +141,6 @@ func (t *StateTrie) GetNode(path []byte) ([]byte, int, error) {
|
||||||
func (t *StateTrie) MustUpdate(key, value []byte) {
|
func (t *StateTrie) MustUpdate(key, value []byte) {
|
||||||
hk := t.hashKey(key)
|
hk := t.hashKey(key)
|
||||||
t.trie.MustUpdate(hk, value)
|
t.trie.MustUpdate(hk, value)
|
||||||
|
|
||||||
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
|
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,9 +159,7 @@ func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
|
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,17 +167,13 @@ func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
||||||
func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccount) error {
|
func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccount) error {
|
||||||
hk := t.hashKey(address.Bytes())
|
hk := t.hashKey(address.Bytes())
|
||||||
data, err := rlp.EncodeToBytes(acc)
|
data, err := rlp.EncodeToBytes(acc)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := t.trie.Update(hk, data); err != nil {
|
if err := t.trie.Update(hk, data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.getSecKeyCache()[string(hk)] = address.Bytes()
|
t.getSecKeyCache()[string(hk)] = address.Bytes()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,7 +195,6 @@ func (t *StateTrie) MustDelete(key []byte) {
|
||||||
func (t *StateTrie) DeleteStorage(_ common.Address, key []byte) error {
|
func (t *StateTrie) DeleteStorage(_ common.Address, key []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := t.hashKey(key)
|
||||||
delete(t.getSecKeyCache(), string(hk))
|
delete(t.getSecKeyCache(), string(hk))
|
||||||
|
|
||||||
return t.trie.Delete(hk)
|
return t.trie.Delete(hk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +202,6 @@ func (t *StateTrie) DeleteStorage(_ common.Address, key []byte) error {
|
||||||
func (t *StateTrie) DeleteAccount(address common.Address) error {
|
func (t *StateTrie) DeleteAccount(address common.Address) error {
|
||||||
hk := t.hashKey(address.Bytes())
|
hk := t.hashKey(address.Bytes())
|
||||||
delete(t.getSecKeyCache(), string(hk))
|
delete(t.getSecKeyCache(), string(hk))
|
||||||
|
|
||||||
return t.trie.Delete(hk)
|
return t.trie.Delete(hk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,11 +211,9 @@ func (t *StateTrie) GetKey(shaKey []byte) []byte {
|
||||||
if key, ok := t.getSecKeyCache()[string(shaKey)]; ok {
|
if key, ok := t.getSecKeyCache()[string(shaKey)]; ok {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.preimages == nil {
|
if t.preimages == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.preimages.preimage(common.BytesToHash(shaKey))
|
return t.preimages.preimage(common.BytesToHash(shaKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,10 +232,8 @@ func (t *StateTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, er
|
||||||
for hk, key := range t.secKeyCache {
|
for hk, key := range t.secKeyCache {
|
||||||
preimages[common.BytesToHash([]byte(hk))] = key
|
preimages[common.BytesToHash([]byte(hk))] = key
|
||||||
}
|
}
|
||||||
|
|
||||||
t.preimages.insertPreimage(preimages)
|
t.preimages.insertPreimage(preimages)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.secKeyCache = make(map[string][]byte)
|
t.secKeyCache = make(map[string][]byte)
|
||||||
}
|
}
|
||||||
// Commit the trie and return its modified nodeset.
|
// Commit the trie and return its modified nodeset.
|
||||||
|
|
@ -295,7 +276,6 @@ func (t *StateTrie) hashKey(key []byte) []byte {
|
||||||
h.sha.Write(key)
|
h.sha.Write(key)
|
||||||
h.sha.Read(t.hashKeyBuf[:])
|
h.sha.Read(t.hashKeyBuf[:])
|
||||||
returnHasherToPool(h)
|
returnHasherToPool(h)
|
||||||
|
|
||||||
return t.hashKeyBuf[:]
|
return t.hashKeyBuf[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -307,6 +287,5 @@ func (t *StateTrie) getSecKeyCache() map[string][]byte {
|
||||||
t.secKeyCacheOwner = t
|
t.secKeyCacheOwner = t
|
||||||
t.secKeyCache = make(map[string][]byte)
|
t.secKeyCache = make(map[string][]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.secKeyCache
|
return t.secKeyCache
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue