2018-02-14 06:49:11 -06:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-22 11:48:40 -05:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-06 19:54:22 -05:00
|
|
|
//
|
2015-07-23 11:35:11 -05:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-06 19:54:22 -05:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 11:48:40 -05:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-06 19:54:22 -05:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 11:48:40 -05:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-06 19:54:22 -05:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 11:48:40 -05:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-06 19:54:22 -05:00
|
|
|
|
2015-06-10 13:38:39 -05:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2017-07-11 06:49:14 -05:00
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
2023-05-25 01:54:28 -05:00
|
|
|
"errors"
|
2015-06-10 13:38:39 -05:00
|
|
|
"fmt"
|
2017-07-11 06:49:14 -05:00
|
|
|
"math/big"
|
2019-08-08 04:07:23 -05:00
|
|
|
"strconv"
|
2016-10-05 16:55:47 -05:00
|
|
|
"strings"
|
2015-06-10 13:38:39 -05:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-07-11 06:49:14 -05:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 15:21:51 -06:00
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
2023-12-28 04:39:28 -06:00
|
|
|
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
|
2015-06-10 13:38:39 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2018-09-24 07:57:49 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2015-06-10 13:38:39 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
2021-02-25 01:10:30 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
2024-03-22 12:53:53 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/tracing"
|
2017-01-05 07:03:50 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2017-07-11 06:49:14 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2015-06-10 13:38:39 -05:00
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
2016-10-20 06:36:29 -05:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2017-08-24 04:26:06 -05:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2024-02-13 07:49:53 -06:00
|
|
|
"github.com/ethereum/go-ethereum/triedb"
|
|
|
|
"github.com/ethereum/go-ethereum/triedb/hashdb"
|
|
|
|
"github.com/ethereum/go-ethereum/triedb/pathdb"
|
2024-01-23 07:51:58 -06:00
|
|
|
"github.com/holiman/uint256"
|
2019-01-03 16:15:26 -06:00
|
|
|
"golang.org/x/crypto/sha3"
|
2015-06-10 13:38:39 -05:00
|
|
|
)
|
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
// StateTest checks transaction processing without block context.
|
|
|
|
// See https://github.com/ethereum/EIPs/issues/176 for the test format specification.
|
|
|
|
type StateTest struct {
|
|
|
|
json stJSON
|
|
|
|
}
|
2015-06-14 16:55:03 -05:00
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
// StateSubtest selects a specific configuration of a General State Test.
|
|
|
|
type StateSubtest struct {
|
|
|
|
Fork string
|
|
|
|
Index int
|
2015-06-14 16:55:03 -05:00
|
|
|
}
|
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
func (t *StateTest) UnmarshalJSON(in []byte) error {
|
|
|
|
return json.Unmarshal(in, &t.json)
|
|
|
|
}
|
2015-06-14 16:55:03 -05:00
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
type stJSON struct {
|
|
|
|
Env stEnv `json:"env"`
|
2024-02-16 12:05:33 -06:00
|
|
|
Pre types.GenesisAlloc `json:"pre"`
|
2017-07-11 06:49:14 -05:00
|
|
|
Tx stTransaction `json:"transaction"`
|
|
|
|
Out hexutil.Bytes `json:"out"`
|
|
|
|
Post map[string][]stPostState `json:"post"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type stPostState struct {
|
2021-07-29 07:05:22 -05:00
|
|
|
Root common.UnprefixedHash `json:"hash"`
|
|
|
|
Logs common.UnprefixedHash `json:"logs"`
|
|
|
|
TxBytes hexutil.Bytes `json:"txbytes"`
|
|
|
|
ExpectException string `json:"expectException"`
|
|
|
|
Indexes struct {
|
2017-07-11 06:49:14 -05:00
|
|
|
Data int `json:"data"`
|
|
|
|
Gas int `json:"gas"`
|
|
|
|
Value int `json:"value"`
|
2015-06-14 16:55:03 -05:00
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
2015-06-14 16:55:03 -05:00
|
|
|
|
2022-04-12 13:24:02 -05:00
|
|
|
//go:generate go run github.com/fjl/gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
|
2015-06-14 16:55:03 -05:00
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
type stEnv struct {
|
2023-12-28 04:39:28 -06:00
|
|
|
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
|
|
|
|
Difficulty *big.Int `json:"currentDifficulty" gencodec:"optional"`
|
|
|
|
Random *big.Int `json:"currentRandom" gencodec:"optional"`
|
|
|
|
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
|
|
|
|
Number uint64 `json:"currentNumber" gencodec:"required"`
|
|
|
|
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
|
|
|
|
BaseFee *big.Int `json:"currentBaseFee" gencodec:"optional"`
|
|
|
|
ExcessBlobGas *uint64 `json:"currentExcessBlobGas" gencodec:"optional"`
|
2015-06-14 16:55:03 -05:00
|
|
|
}
|
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
type stEnvMarshaling struct {
|
2023-12-28 04:39:28 -06:00
|
|
|
Coinbase common.UnprefixedAddress
|
|
|
|
Difficulty *math.HexOrDecimal256
|
|
|
|
Random *math.HexOrDecimal256
|
|
|
|
GasLimit math.HexOrDecimal64
|
|
|
|
Number math.HexOrDecimal64
|
|
|
|
Timestamp math.HexOrDecimal64
|
|
|
|
BaseFee *math.HexOrDecimal256
|
|
|
|
ExcessBlobGas *math.HexOrDecimal64
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
|
|
|
|
2022-04-12 13:24:02 -05:00
|
|
|
//go:generate go run github.com/fjl/gencodec -type stTransaction -field-override stTransactionMarshaling -out gen_sttransaction.go
|
2017-07-11 06:49:14 -05:00
|
|
|
|
|
|
|
type stTransaction struct {
|
2021-06-07 07:37:56 -05:00
|
|
|
GasPrice *big.Int `json:"gasPrice"`
|
|
|
|
MaxFeePerGas *big.Int `json:"maxFeePerGas"`
|
|
|
|
MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"`
|
|
|
|
Nonce uint64 `json:"nonce"`
|
|
|
|
To string `json:"to"`
|
|
|
|
Data []string `json:"data"`
|
|
|
|
AccessLists []*types.AccessList `json:"accessLists,omitempty"`
|
|
|
|
GasLimit []uint64 `json:"gasLimit"`
|
|
|
|
Value []string `json:"value"`
|
|
|
|
PrivateKey []byte `json:"secretKey"`
|
2023-08-28 21:36:10 -05:00
|
|
|
Sender *common.Address `json:"sender"`
|
2023-07-15 16:27:36 -05:00
|
|
|
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
|
2023-07-27 08:53:28 -05:00
|
|
|
BlobGasFeeCap *big.Int `json:"maxFeePerBlobGas,omitempty"`
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type stTransactionMarshaling struct {
|
2021-06-07 07:37:56 -05:00
|
|
|
GasPrice *math.HexOrDecimal256
|
|
|
|
MaxFeePerGas *math.HexOrDecimal256
|
|
|
|
MaxPriorityFeePerGas *math.HexOrDecimal256
|
|
|
|
Nonce math.HexOrDecimal64
|
|
|
|
GasLimit []math.HexOrDecimal64
|
|
|
|
PrivateKey hexutil.Bytes
|
2023-07-15 16:27:36 -05:00
|
|
|
BlobGasFeeCap *math.HexOrDecimal256
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
|
|
|
|
2020-06-30 03:12:51 -05:00
|
|
|
// GetChainConfig takes a fork definition and returns a chain config.
|
2019-08-08 04:07:23 -05:00
|
|
|
// The fork definition can be
|
|
|
|
// - a plain forkname, e.g. `Byzantium`,
|
|
|
|
// - a fork basename, and a list of EIPs to enable; e.g. `Byzantium+1884+1283`.
|
2020-06-30 03:12:51 -05:00
|
|
|
func GetChainConfig(forkString string) (baseConfig *params.ChainConfig, eips []int, err error) {
|
2019-08-08 04:07:23 -05:00
|
|
|
var (
|
|
|
|
splitForks = strings.Split(forkString, "+")
|
|
|
|
ok bool
|
|
|
|
baseName, eipsStrings = splitForks[0], splitForks[1:]
|
|
|
|
)
|
|
|
|
if baseConfig, ok = Forks[baseName]; !ok {
|
|
|
|
return nil, nil, UnsupportedForkError{baseName}
|
|
|
|
}
|
|
|
|
for _, eip := range eipsStrings {
|
|
|
|
if eipNum, err := strconv.Atoi(eip); err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("syntax error, invalid eip number %v", eipNum)
|
|
|
|
} else {
|
2020-06-30 03:12:51 -05:00
|
|
|
if !vm.ValidEip(eipNum) {
|
|
|
|
return nil, nil, fmt.Errorf("syntax error, invalid eip number %v", eipNum)
|
|
|
|
}
|
2019-08-08 04:07:23 -05:00
|
|
|
eips = append(eips, eipNum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return baseConfig, eips, nil
|
|
|
|
}
|
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
// Subtests returns all valid subtests of the test.
|
|
|
|
func (t *StateTest) Subtests() []StateSubtest {
|
|
|
|
var sub []StateSubtest
|
|
|
|
for fork, pss := range t.json.Post {
|
2017-11-08 04:45:52 -06:00
|
|
|
for i := range pss {
|
2017-07-11 06:49:14 -05:00
|
|
|
sub = append(sub, StateSubtest{fork, i})
|
|
|
|
}
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
return sub
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:00:56 -05:00
|
|
|
// checkError checks if the error returned by the state transition matches any expected error.
|
|
|
|
// A failing expectation returns a wrapped version of the original error, if any,
|
|
|
|
// or a new error detailing the failing expectation.
|
|
|
|
// This function does not return or modify the original error, it only evaluates and returns expectations for the error.
|
|
|
|
func (t *StateTest) checkError(subtest StateSubtest, err error) error {
|
|
|
|
expectedError := t.json.Post[subtest.Fork][subtest.Index].ExpectException
|
|
|
|
if err == nil && expectedError == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err == nil && expectedError != "" {
|
|
|
|
return fmt.Errorf("expected error %q, got no error", expectedError)
|
|
|
|
}
|
|
|
|
if err != nil && expectedError == "" {
|
|
|
|
return fmt.Errorf("unexpected error: %w", err)
|
|
|
|
}
|
|
|
|
if err != nil && expectedError != "" {
|
|
|
|
// Ignore expected errors (TODO MariusVanDerWijden check error string)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-11 06:46:14 -05:00
|
|
|
// Run executes a specific subtest and verifies the post-state and logs
|
2024-02-14 10:02:56 -06:00
|
|
|
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bool, scheme string, postCheck func(err error, st *StateTestState)) (result error) {
|
|
|
|
st, root, err := t.RunNoVerify(subtest, vmconfig, snapshotter, scheme)
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
// Invoke the callback at the end of function for further analysis.
|
|
|
|
defer func() {
|
2024-02-14 10:02:56 -06:00
|
|
|
postCheck(result, &st)
|
|
|
|
st.Close()
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
}()
|
2024-02-14 10:02:56 -06:00
|
|
|
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
checkedErr := t.checkError(subtest, err)
|
|
|
|
if checkedErr != nil {
|
|
|
|
return checkedErr
|
2022-09-26 09:00:56 -05:00
|
|
|
}
|
|
|
|
// The error has been checked; if it was unexpected, it's already returned.
|
2019-09-11 06:46:14 -05:00
|
|
|
if err != nil {
|
2022-09-26 09:00:56 -05:00
|
|
|
// Here, an error exists but it was expected.
|
|
|
|
// We do not check the post state or logs.
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
return nil
|
2019-09-11 06:46:14 -05:00
|
|
|
}
|
|
|
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
|
|
|
// N.B: We need to do this in a two-step process, because the first Commit takes care
|
2023-07-15 09:35:30 -05:00
|
|
|
// of self-destructs, and we need to touch the coinbase _after_ it has potentially self-destructed.
|
2019-09-11 06:46:14 -05:00
|
|
|
if root != common.Hash(post.Root) {
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
return fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
|
2019-09-11 06:46:14 -05:00
|
|
|
}
|
2024-02-14 10:02:56 -06:00
|
|
|
if logs := rlpHash(st.StateDB.Logs()); logs != common.Hash(post.Logs) {
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
return fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
|
cmd, core/state, eth, tests, trie: improve state reader (#27428)
The state availability is checked during the creation of a state reader.
- In hash-based database, if the specified root node does not exist on disk disk, then
the state reader won't be created and an error will be returned.
- In path-based database, if the specified state layer is not available, then the
state reader won't be created and an error will be returned.
This change also contains a stricter semantics regarding the `Commit` operation: once it has been performed, the trie is no longer usable, and certain operations will return an error.
2023-06-20 14:31:45 -05:00
|
|
|
}
|
2024-09-05 05:10:47 -05:00
|
|
|
st.StateDB, _ = state.New(root, st.StateDB.Database())
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
return nil
|
2019-09-11 06:46:14 -05:00
|
|
|
}
|
|
|
|
|
2024-02-14 10:02:56 -06:00
|
|
|
// RunNoVerify runs a specific subtest and returns the statedb and post-state root.
|
|
|
|
// Remember to call state.Close after verifying the test result!
|
2024-03-22 12:53:53 -05:00
|
|
|
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapshotter bool, scheme string) (st StateTestState, root common.Hash, err error) {
|
2020-06-30 03:12:51 -05:00
|
|
|
config, eips, err := GetChainConfig(subtest.Fork)
|
2019-08-08 04:07:23 -05:00
|
|
|
if err != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
return st, common.Hash{}, UnsupportedForkError{subtest.Fork}
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2019-08-08 04:07:23 -05:00
|
|
|
vmconfig.ExtraEips = eips
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
|
2022-08-09 04:44:39 -05:00
|
|
|
block := t.genesis(config).ToBlock()
|
2024-03-22 12:53:53 -05:00
|
|
|
st = MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, snapshotter, scheme)
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2021-06-07 07:37:56 -05:00
|
|
|
var baseFee *big.Int
|
|
|
|
if config.IsLondon(new(big.Int)) {
|
|
|
|
baseFee = t.json.Env.BaseFee
|
|
|
|
if baseFee == nil {
|
|
|
|
// Retesteth uses `0x10` for genesis baseFee. Therefore, it defaults to
|
|
|
|
// parent - 2 : 0xa as the basefee for 'this' context.
|
|
|
|
baseFee = big.NewInt(0x0a)
|
|
|
|
}
|
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
2021-06-07 07:37:56 -05:00
|
|
|
msg, err := t.json.Tx.toMessage(post, baseFee)
|
2017-07-11 06:49:14 -05:00
|
|
|
if err != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
return st, common.Hash{}, err
|
2024-02-14 10:02:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // Blob transactions may be present after the Cancun fork.
|
|
|
|
// In production,
|
|
|
|
// - the header is verified against the max in eip4844.go:VerifyEIP4844Header
|
|
|
|
// - the block body is verified against the header in block_validator.go:ValidateBody
|
|
|
|
// Here, we just do this shortcut smaller fix, since state tests do not
|
|
|
|
// utilize those codepaths
|
|
|
|
if len(msg.BlobHashes)*params.BlobTxBlobGasPerBlob > params.MaxBlobGasPerBlock {
|
2024-03-22 12:53:53 -05:00
|
|
|
return st, common.Hash{}, errors.New("blob gas exceeds maximum")
|
2024-02-14 10:02:56 -06:00
|
|
|
}
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2021-02-25 08:26:57 -06:00
|
|
|
|
2021-07-29 07:05:22 -05:00
|
|
|
// Try to recover tx with current signer
|
|
|
|
if len(post.TxBytes) != 0 {
|
|
|
|
var ttx types.Transaction
|
|
|
|
err := ttx.UnmarshalBinary(post.TxBytes)
|
|
|
|
if err != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
return st, common.Hash{}, err
|
2021-07-29 07:05:22 -05:00
|
|
|
}
|
|
|
|
if _, err := types.Sender(types.LatestSigner(config), &ttx); err != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
return st, common.Hash{}, err
|
2021-07-29 07:05:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-25 08:26:57 -06:00
|
|
|
// Prepare the EVM.
|
2020-11-13 06:42:19 -06:00
|
|
|
txContext := core.NewEVMTxContext(msg)
|
|
|
|
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
|
2017-07-11 06:49:14 -05:00
|
|
|
context.GetHash = vmTestBlockHash
|
2021-06-07 07:37:56 -05:00
|
|
|
context.BaseFee = baseFee
|
2022-07-15 07:01:07 -05:00
|
|
|
context.Random = nil
|
2023-01-10 07:22:43 -06:00
|
|
|
if t.json.Env.Difficulty != nil {
|
|
|
|
context.Difficulty = new(big.Int).Set(t.json.Env.Difficulty)
|
|
|
|
}
|
|
|
|
if config.IsLondon(new(big.Int)) && t.json.Env.Random != nil {
|
|
|
|
rnd := common.BigToHash(t.json.Env.Random)
|
|
|
|
context.Random = &rnd
|
2022-01-10 01:44:21 -06:00
|
|
|
context.Difficulty = big.NewInt(0)
|
|
|
|
}
|
2023-12-28 04:39:28 -06:00
|
|
|
if config.IsCancun(new(big.Int), block.Time()) && t.json.Env.ExcessBlobGas != nil {
|
|
|
|
context.BlobBaseFee = eip4844.CalcBlobFee(*t.json.Env.ExcessBlobGas)
|
|
|
|
}
|
2024-03-22 12:53:53 -05:00
|
|
|
evm := vm.NewEVM(context, txContext, st.StateDB, config, vmconfig)
|
2024-01-15 02:15:40 -06:00
|
|
|
|
2024-03-26 09:04:15 -05:00
|
|
|
if tracer := vmconfig.Tracer; tracer != nil && tracer.OnTxStart != nil {
|
|
|
|
tracer.OnTxStart(evm.GetVMContext(), nil, msg.From)
|
|
|
|
}
|
2021-02-25 08:26:57 -06:00
|
|
|
// Execute the message.
|
2024-03-22 12:53:53 -05:00
|
|
|
snapshot := st.StateDB.Snapshot()
|
2017-07-11 06:49:14 -05:00
|
|
|
gaspool := new(core.GasPool)
|
|
|
|
gaspool.AddGas(block.GasLimit())
|
2024-08-21 08:16:08 -05:00
|
|
|
vmRet, err := core.ApplyMessage(evm, msg, gaspool)
|
2022-09-26 09:00:56 -05:00
|
|
|
if err != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
st.StateDB.RevertToSnapshot(snapshot)
|
2024-08-21 08:16:08 -05:00
|
|
|
if tracer := evm.Config.Tracer; tracer != nil && tracer.OnTxEnd != nil {
|
|
|
|
evm.Config.Tracer.OnTxEnd(nil, err)
|
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
2018-09-04 03:49:18 -05:00
|
|
|
// Add 0-value mining reward. This only makes a difference in the cases
|
|
|
|
// where
|
2023-07-15 09:35:30 -05:00
|
|
|
// - the coinbase self-destructed, or
|
2018-09-04 03:49:18 -05:00
|
|
|
// - there are only 'bad' transactions, which aren't executed. In those cases,
|
|
|
|
// the coinbase gets no txfee, so isn't created, and thus needs to be touched
|
2024-03-22 12:53:53 -05:00
|
|
|
st.StateDB.AddBalance(block.Coinbase(), new(uint256.Int), tracing.BalanceChangeUnspecified)
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
|
|
|
|
// Commit state mutations into database.
|
2024-03-22 12:53:53 -05:00
|
|
|
root, _ = st.StateDB.Commit(block.NumberU64(), config.IsEIP158(block.Number()))
|
2024-08-21 08:16:08 -05:00
|
|
|
if tracer := evm.Config.Tracer; tracer != nil && tracer.OnTxEnd != nil {
|
|
|
|
receipt := &types.Receipt{GasUsed: vmRet.UsedGas}
|
|
|
|
tracer.OnTxEnd(receipt, nil)
|
|
|
|
}
|
2024-03-22 12:53:53 -05:00
|
|
|
return st, root, err
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
|
|
|
return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas]
|
|
|
|
}
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
func (t *StateTest) genesis(config *params.ChainConfig) *core.Genesis {
|
2022-01-10 01:44:21 -06:00
|
|
|
genesis := &core.Genesis{
|
2017-07-11 06:49:14 -05:00
|
|
|
Config: config,
|
|
|
|
Coinbase: t.json.Env.Coinbase,
|
|
|
|
Difficulty: t.json.Env.Difficulty,
|
2017-11-13 05:47:27 -06:00
|
|
|
GasLimit: t.json.Env.GasLimit,
|
2017-07-11 06:49:14 -05:00
|
|
|
Number: t.json.Env.Number,
|
|
|
|
Timestamp: t.json.Env.Timestamp,
|
|
|
|
Alloc: t.json.Pre,
|
2015-06-14 16:55:03 -05:00
|
|
|
}
|
2022-01-10 01:44:21 -06:00
|
|
|
if t.json.Env.Random != nil {
|
|
|
|
// Post-Merge
|
|
|
|
genesis.Mixhash = common.BigToHash(t.json.Env.Random)
|
|
|
|
genesis.Difficulty = big.NewInt(0)
|
|
|
|
}
|
|
|
|
return genesis
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
2015-06-10 13:38:39 -05:00
|
|
|
|
core, core/types: plain Message struct (#25977)
Here, the core.Message interface turns into a plain struct and
types.Message gets removed.
This is a breaking change to packages core and core/types. While we do
not promise API stability for package core, we do for core/types. An
exception can be made for types.Message, since it doesn't have any
purpose apart from invoking the state transition in package core.
types.Message was also marked deprecated by the same commit it
got added in, 4dca5d4db7 (November 2016).
The core.Message interface was added in December 2014, in commit
db494170dc, for the purpose of 'testing' state transitions. It's the
same change that made transaction struct fields private. Before that,
the state transition used *types.Transaction directly.
Over time, multiple implementations of the interface accrued across
different packages, since constructing a Message is required whenever
one wants to invoke the state transition. These implementations all
looked very similar, a struct with private fields exposing the fields
as accessor methods.
By changing Message into a struct with public fields we can remove all
these useless interface implementations. It will also hopefully
simplify future changes to the type with less updates to apply across
all of go-ethereum when a field is added to Message.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
2023-03-09 07:19:12 -06:00
|
|
|
func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Message, error) {
|
2017-07-11 06:49:14 -05:00
|
|
|
var from common.Address
|
2023-08-28 21:36:10 -05:00
|
|
|
// If 'sender' field is present, use that
|
|
|
|
if tx.Sender != nil {
|
|
|
|
from = *tx.Sender
|
|
|
|
} else if len(tx.PrivateKey) > 0 {
|
|
|
|
// Derive sender from private key if needed.
|
2017-07-11 06:49:14 -05:00
|
|
|
key, err := crypto.ToECDSA(tx.PrivateKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid private key: %v", err)
|
2015-06-10 16:04:06 -05:00
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
from = crypto.PubkeyToAddress(key.PublicKey)
|
|
|
|
}
|
|
|
|
// Parse recipient if present.
|
|
|
|
var to *common.Address
|
|
|
|
if tx.To != "" {
|
|
|
|
to = new(common.Address)
|
|
|
|
if err := to.UnmarshalText([]byte(tx.To)); err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid to address: %v", err)
|
2015-06-10 13:38:39 -05:00
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
}
|
2015-06-10 13:38:39 -05:00
|
|
|
|
2017-07-11 06:49:14 -05:00
|
|
|
// Get values specific to this post state.
|
|
|
|
if ps.Indexes.Data > len(tx.Data) {
|
|
|
|
return nil, fmt.Errorf("tx data index %d out of bounds", ps.Indexes.Data)
|
|
|
|
}
|
|
|
|
if ps.Indexes.Value > len(tx.Value) {
|
|
|
|
return nil, fmt.Errorf("tx value index %d out of bounds", ps.Indexes.Value)
|
|
|
|
}
|
|
|
|
if ps.Indexes.Gas > len(tx.GasLimit) {
|
|
|
|
return nil, fmt.Errorf("tx gas limit index %d out of bounds", ps.Indexes.Gas)
|
|
|
|
}
|
|
|
|
dataHex := tx.Data[ps.Indexes.Data]
|
|
|
|
valueHex := tx.Value[ps.Indexes.Value]
|
|
|
|
gasLimit := tx.GasLimit[ps.Indexes.Gas]
|
|
|
|
// Value, Data hex encoding is messy: https://github.com/ethereum/tests/issues/203
|
|
|
|
value := new(big.Int)
|
|
|
|
if valueHex != "0x" {
|
|
|
|
v, ok := math.ParseBig256(valueHex)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid tx value %q", valueHex)
|
|
|
|
}
|
|
|
|
value = v
|
|
|
|
}
|
|
|
|
data, err := hex.DecodeString(strings.TrimPrefix(dataHex, "0x"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid tx data %q", dataHex)
|
2015-06-14 16:55:03 -05:00
|
|
|
}
|
2021-03-03 08:50:07 -06:00
|
|
|
var accessList types.AccessList
|
|
|
|
if tx.AccessLists != nil && tx.AccessLists[ps.Indexes.Data] != nil {
|
|
|
|
accessList = *tx.AccessLists[ps.Indexes.Data]
|
|
|
|
}
|
2021-06-07 07:37:56 -05:00
|
|
|
// If baseFee provided, set gasPrice to effectiveGasPrice.
|
|
|
|
gasPrice := tx.GasPrice
|
|
|
|
if baseFee != nil {
|
|
|
|
if tx.MaxFeePerGas == nil {
|
|
|
|
tx.MaxFeePerGas = gasPrice
|
|
|
|
}
|
|
|
|
if tx.MaxFeePerGas == nil {
|
|
|
|
tx.MaxFeePerGas = new(big.Int)
|
|
|
|
}
|
|
|
|
if tx.MaxPriorityFeePerGas == nil {
|
|
|
|
tx.MaxPriorityFeePerGas = tx.MaxFeePerGas
|
|
|
|
}
|
|
|
|
gasPrice = math.BigMin(new(big.Int).Add(tx.MaxPriorityFeePerGas, baseFee),
|
|
|
|
tx.MaxFeePerGas)
|
|
|
|
}
|
2021-06-18 05:34:31 -05:00
|
|
|
if gasPrice == nil {
|
2023-05-25 01:54:28 -05:00
|
|
|
return nil, errors.New("no gas price provided")
|
2021-06-18 05:34:31 -05:00
|
|
|
}
|
2021-06-07 07:37:56 -05:00
|
|
|
|
core, core/types: plain Message struct (#25977)
Here, the core.Message interface turns into a plain struct and
types.Message gets removed.
This is a breaking change to packages core and core/types. While we do
not promise API stability for package core, we do for core/types. An
exception can be made for types.Message, since it doesn't have any
purpose apart from invoking the state transition in package core.
types.Message was also marked deprecated by the same commit it
got added in, 4dca5d4db7 (November 2016).
The core.Message interface was added in December 2014, in commit
db494170dc, for the purpose of 'testing' state transitions. It's the
same change that made transaction struct fields private. Before that,
the state transition used *types.Transaction directly.
Over time, multiple implementations of the interface accrued across
different packages, since constructing a Message is required whenever
one wants to invoke the state transition. These implementations all
looked very similar, a struct with private fields exposing the fields
as accessor methods.
By changing Message into a struct with public fields we can remove all
these useless interface implementations. It will also hopefully
simplify future changes to the type with less updates to apply across
all of go-ethereum when a field is added to Message.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
2023-03-09 07:19:12 -06:00
|
|
|
msg := &core.Message{
|
2023-07-15 16:27:36 -05:00
|
|
|
From: from,
|
|
|
|
To: to,
|
|
|
|
Nonce: tx.Nonce,
|
|
|
|
Value: value,
|
|
|
|
GasLimit: gasLimit,
|
|
|
|
GasPrice: gasPrice,
|
|
|
|
GasFeeCap: tx.MaxFeePerGas,
|
|
|
|
GasTipCap: tx.MaxPriorityFeePerGas,
|
|
|
|
Data: data,
|
|
|
|
AccessList: accessList,
|
|
|
|
BlobHashes: tx.BlobVersionedHashes,
|
|
|
|
BlobGasFeeCap: tx.BlobGasFeeCap,
|
core, core/types: plain Message struct (#25977)
Here, the core.Message interface turns into a plain struct and
types.Message gets removed.
This is a breaking change to packages core and core/types. While we do
not promise API stability for package core, we do for core/types. An
exception can be made for types.Message, since it doesn't have any
purpose apart from invoking the state transition in package core.
types.Message was also marked deprecated by the same commit it
got added in, 4dca5d4db7 (November 2016).
The core.Message interface was added in December 2014, in commit
db494170dc, for the purpose of 'testing' state transitions. It's the
same change that made transaction struct fields private. Before that,
the state transition used *types.Transaction directly.
Over time, multiple implementations of the interface accrued across
different packages, since constructing a Message is required whenever
one wants to invoke the state transition. These implementations all
looked very similar, a struct with private fields exposing the fields
as accessor methods.
By changing Message into a struct with public fields we can remove all
these useless interface implementations. It will also hopefully
simplify future changes to the type with less updates to apply across
all of go-ethereum when a field is added to Message.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
2023-03-09 07:19:12 -06:00
|
|
|
}
|
2017-07-11 06:49:14 -05:00
|
|
|
return msg, nil
|
2015-06-14 16:55:03 -05:00
|
|
|
}
|
2015-06-10 13:38:39 -05:00
|
|
|
|
2017-08-24 04:26:06 -05:00
|
|
|
func rlpHash(x interface{}) (h common.Hash) {
|
2019-01-03 16:15:26 -06:00
|
|
|
hw := sha3.NewLegacyKeccak256()
|
2017-08-24 04:26:06 -05:00
|
|
|
rlp.Encode(hw, x)
|
|
|
|
hw.Sum(h[:0])
|
|
|
|
return h
|
2015-06-10 13:38:39 -05:00
|
|
|
}
|
2021-08-17 10:30:21 -05:00
|
|
|
|
|
|
|
func vmTestBlockHash(n uint64) common.Hash {
|
|
|
|
return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
|
|
|
|
}
|
2024-02-14 10:02:56 -06:00
|
|
|
|
|
|
|
// StateTestState groups all the state database objects together for use in tests.
|
|
|
|
type StateTestState struct {
|
|
|
|
StateDB *state.StateDB
|
|
|
|
TrieDB *triedb.Database
|
|
|
|
Snapshots *snapshot.Tree
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakePreState creates a state containing the given allocation.
|
2024-02-16 12:05:33 -06:00
|
|
|
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, snapshotter bool, scheme string) StateTestState {
|
2024-02-14 10:02:56 -06:00
|
|
|
tconf := &triedb.Config{Preimages: true}
|
|
|
|
if scheme == rawdb.HashScheme {
|
|
|
|
tconf.HashDB = hashdb.Defaults
|
|
|
|
} else {
|
|
|
|
tconf.PathDB = pathdb.Defaults
|
|
|
|
}
|
|
|
|
triedb := triedb.NewDatabase(db, tconf)
|
2024-09-05 05:10:47 -05:00
|
|
|
sdb := state.NewDatabase(triedb, nil)
|
|
|
|
statedb, _ := state.New(types.EmptyRootHash, sdb)
|
2024-02-14 10:02:56 -06:00
|
|
|
for addr, a := range accounts {
|
|
|
|
statedb.SetCode(addr, a.Code)
|
|
|
|
statedb.SetNonce(addr, a.Nonce)
|
2024-03-22 12:53:53 -05:00
|
|
|
statedb.SetBalance(addr, uint256.MustFromBig(a.Balance), tracing.BalanceChangeUnspecified)
|
2024-02-14 10:02:56 -06:00
|
|
|
for k, v := range a.Storage {
|
|
|
|
statedb.SetState(addr, k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Commit and re-open to start with a clean state.
|
|
|
|
root, _ := statedb.Commit(0, false)
|
|
|
|
|
|
|
|
// If snapshot is requested, initialize the snapshotter and use it in state.
|
|
|
|
var snaps *snapshot.Tree
|
|
|
|
if snapshotter {
|
|
|
|
snapconfig := snapshot.Config{
|
|
|
|
CacheSize: 1,
|
|
|
|
Recovery: false,
|
|
|
|
NoBuild: false,
|
|
|
|
AsyncBuild: false,
|
|
|
|
}
|
|
|
|
snaps, _ = snapshot.New(snapconfig, db, triedb, root)
|
|
|
|
}
|
2024-09-05 05:10:47 -05:00
|
|
|
sdb = state.NewDatabase(triedb, snaps)
|
|
|
|
statedb, _ = state.New(root, sdb)
|
2024-02-14 10:02:56 -06:00
|
|
|
return StateTestState{statedb, triedb, snaps}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close should be called when the state is no longer needed, ie. after running the test.
|
|
|
|
func (st *StateTestState) Close() {
|
|
|
|
if st.TrieDB != nil {
|
|
|
|
st.TrieDB.Close()
|
|
|
|
st.TrieDB = nil
|
|
|
|
}
|
|
|
|
if st.Snapshots != nil {
|
|
|
|
// Need to call Disable here to quit the snapshot generator goroutine.
|
|
|
|
st.Snapshots.Disable()
|
|
|
|
st.Snapshots.Release()
|
|
|
|
st.Snapshots = nil
|
|
|
|
}
|
|
|
|
}
|