Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
23ac8df
cmd. core: save preimages on genesis creation (#25538)
gballet Aug 18, 2022
cce7f08
rlp/rlpgen: fix error handling when target type not found (#25547)
jtraglia Aug 18, 2022
a1b8892
trie: improve node rlp decoding performance (#25357)
rjl493456442 Aug 18, 2022
2c5648d
all: fix some typos (#25551)
jtraglia Aug 19, 2022
fa1305f
internal/ethapi: fix comment typo (#25548)
ucwong Aug 19, 2022
32e8490
accounts/abi/bind/backends: typo fix (#25549)
ucwong Aug 19, 2022
656dc8c
eth, les: unlock downloader peerSet if there's an error (#25546)
jtraglia Aug 19, 2022
9762ddf
cmd/geth: parse uint64 value with ParseUint instead of Atoi (#25545)
jtraglia Aug 19, 2022
77308cd
consensus/beacon: check ttd reached on pos blocks (#25552)
MariusVanDerWijden Aug 19, 2022
36874b6
eth/filters: add global block logs cache (#25459)
s1na Aug 19, 2022
0865880
accounts/abi: fix set function (#25477)
zhiqiangxu Aug 19, 2022
ac7ad81
internal/ethapi: fix build regression (#25555)
fjl Aug 19, 2022
0ce494b
eth/fetcher: don't spend too much time on transaction inclusion (#25524)
holiman Aug 19, 2022
02418c2
Revert "eth/fetcher: don't spend too much time on transaction inclusi…
karalabe Aug 22, 2022
395f3d4
eth/catalyst: warn less frequently if no beacon client is available (…
karalabe Aug 22, 2022
2de49b0
params: release go-ethereum v1.10.22
fjl Aug 22, 2022
6d711f0
params: begin v1.10.23 release cycle
fjl Aug 22, 2022
81bd998
core, eth/downloader: handle spurious junk bodies from racey rollback…
karalabe Aug 23, 2022
5758d1f
core/state, trie: fix trie flush order for proper pruning
karalabe Aug 23, 2022
45a660a
consensus/beacon: don't ignore errors
holiman Aug 23, 2022
9ed10b9
Merge pull request #25581 from karalabe/triedb-fix-flush-order
karalabe Aug 23, 2022
4c114af
Merge pull request #25582 from holiman/err_handling
karalabe Aug 23, 2022
d901d85
params: release Geth v1.10.23
karalabe Aug 24, 2022
57896d6
params: begin v1.10.24 release cycle
karalabe Aug 24, 2022
6c40aed
params: begin go-ethereum v1.11 release cycle
fjl Aug 25, 2022
70e1e65
internal/ethapi: rename debug getters to match spec (#25176)
lightclient Aug 25, 2022
f03c37b
accounts/abi/bind: add const for tx fee elasticity multiplier (#25504)
xinbenlv Aug 25, 2022
c394c30
all: remove duplicate word in comments (#25618)
Abirdcfly Aug 29, 2022
6e6b508
cmd/geth: fix legacy receipt detection for empty db (#25609)
s1na Aug 30, 2022
6d882a5
build: fix ignored errors (#25591)
uji Aug 30, 2022
44b36a0
docs: specify execution client (#25566)
sandakersmann Aug 30, 2022
8df8eb4
ethclient: add 'finalized' and 'safe' block number support (#25580)
rachel-bousfield Aug 30, 2022
7813b67
node: change JWT error status to 401 Unauthorized (#25629)
dbadoy Aug 30, 2022
2b6df28
node: fix regression in TestJWT (#25635)
fjl Aug 30, 2022
d10c280
all: move genesis initialization to blockchain (#25523)
rjl493456442 Aug 30, 2022
362256e
eth/catalyst: adjust eta for themerge (#25601)
holiman Aug 31, 2022
279afd7
mobile: close node on error (#25643)
jakub-freebit Aug 31, 2022
8cfcb41
graphql: return correct logs for tx (#25612)
s1na Aug 31, 2022
3d68bb0
trie: fix grammar in comment (#25648)
aaronbuchwald Aug 31, 2022
dafa40e
eth/protocols/snap: fix problems due to idle-but-busy peers
holiman Aug 31, 2022
3f79afb
trie: cleanup stateTrie (#25640)
rjl493456442 Aug 31, 2022
95a2c22
eth/catalyst: prevent division by zero (#25654)
MariusVanDerWijden Aug 31, 2022
d79bd2f
trie: better error reporting (#25645)
holiman Sep 1, 2022
d46184c
core/state: filter out nil trie for copy (#25575)
rjl493456442 Sep 1, 2022
511bf8f
Merge pull request #25651 from holiman/fix_snapqueue
karalabe Sep 1, 2022
d2027ac
mobile: register filter APIs (#25642)
jakub-freebit Sep 2, 2022
198fa95
README.md: improve grammar (#25646)
xternet Sep 2, 2022
d6a12bc
eth/tracers/js: fill in log.refund field (#25661)
s1na Sep 2, 2022
7f2890a
eth/fetcher: throttle peers which deliver many invalid transactions (…
holiman Sep 2, 2022
90711ef
node, rpc: add JWT auth support in client (#24911)
protolambda Sep 2, 2022
38e002f
rpc: check that "version" is "2.0" in request objects (#25570)
dbadoy Sep 2, 2022
0d68b6b
trie: fix typo in comment (#25667)
dbadoy Sep 2, 2022
4b9c307
trie: fix unhandled error in test (#25628)
Kamandlou Sep 2, 2022
7318858
eth/tracers/js: improve integer types in log object (#25668)
fjl Sep 5, 2022
a9ec2ab
trie: check childrens' existence concurrently for snap heal
karalabe Sep 6, 2022
d408cb6
Merge pull request #25694 from karalabe/concurrent-heal-check
karalabe Sep 6, 2022
5ddedd2
core, light, trie: remove DiskDB function from trie database (#25690)
rjl493456442 Sep 7, 2022
a32a02f
params: update chts (#25707)
rjl493456442 Sep 7, 2022
d30e39b
core/vm: rename RANDOM to PREVRANDAO (#25691)
MariusVanDerWijden Sep 7, 2022
dea1fb3
all: cleanup tests (#25641)
rjl493456442 Sep 7, 2022
b1f6dcc
eth, les: rework chain tracer (#25143)
rjl493456442 Sep 7, 2022
6a575ed
eth/tracer: fix broken test (#25715)
rjl493456442 Sep 8, 2022
8363f79
trie: update comments + err check for preimages (#25672)
Sep 8, 2022
de8d5fa
eth/protocols/snap: throttle trie heal requests when peers DoS us (#2…
karalabe Sep 9, 2022
06151eb
p2p/msgrate: be more lenient when calculating 'mean' (#25653)
holiman Sep 9, 2022
610cf02
rpc: improve error codes for internal server errors (#25678)
niczy Sep 9, 2022
389021a
core: place a cap on reorglogs (#25711)
holiman Sep 9, 2022
b628d72
build: upgrade to go 1.19 (#25726)
fjl Sep 10, 2022
0c1888a
p2p/discover/v5wire: reject packets smaller than 63 bytes (#25740)
dbadoy Sep 12, 2022
3a4cef5
core: preallocate maps in TxPool helper methods (#25737)
dbadoy Sep 12, 2022
9a3bd11
accounts/abi: fix typo in error message (#25742)
bprosnitz Sep 13, 2022
818ff32
graphql: fixes missing tx logs (#25745)
s1na Sep 13, 2022
9d71716
cmd/geth: add a verkle subcommand (#25718)
gballet Sep 14, 2022
25b35c9
node: fix HTTP server always force closing (#25755)
ngotchac Sep 14, 2022
0ee8b27
core: fix log order in "Imported new chain segment" (#25768)
fjl Sep 15, 2022
3db4a13
node: fix lint issue in rpcstack.go (#25774)
fjl Sep 15, 2022
1d2f5cf
les/catalyst/api: add support for ExchangeTransitionConfigurationV1 (…
pinkiebell Sep 15, 2022
a89b7ad
params: set TerminalTotalDifficultyPassed to true (#25769)
MariusVanDerWijden Sep 15, 2022
57a65f0
trie: handle more batch commit errors in Database (#25674)
Kamandlou Sep 15, 2022
83989a1
core/rawdb: fix leak of backoff timer (#25776)
ucwong Sep 16, 2022
d213cb0
crypto/bls12381: docfix of g1 Affine (#25729)
georgercarder Sep 16, 2022
8ade5e6
internal/ethapi: return error when requesting invalid trie key (#25762)
lightclient Sep 16, 2022
ada603f
core: don't cache zero nonce in txNoncer (#25603)
dbadoy Sep 16, 2022
8e52015
core: more compact bad block report (#25714)
lightclient Sep 17, 2022
468d184
core: move build version reading to its own package (#25806)
fjl Sep 19, 2022
d728ba9
eth: fix a rare datarace on CHT challenge reply / shutdown
karalabe Sep 20, 2022
18a001f
Merge pull request #25831 from karalabe/fix-challenge-stop-hang
karalabe Sep 20, 2022
d8ada03
core/vm: return copy of input slice in identity precompile, avoid ret…
jwasinger Sep 20, 2022
338bb2e
core/blockchain: downgrade tx indexing and unindexing logs (#25832)
lightclient Sep 21, 2022
5d11d38
eth/tracers: fix trace config for `TraceCall` (#25821)
makcandrov Sep 21, 2022
6eb8f32
eth/catalyst: add locking around newpayload (#25816)
holiman Sep 21, 2022
400ab0d
eth/catalyst: make tests run faster (#25818)
holiman Sep 21, 2022
6215b92
cmd/utils: make --authrpc.jwtsecret a DirectoryFlag (#25849)
jsvisa Sep 22, 2022
fb500d1
eth/protocols/snap: make log messages more clear that sync is ongoing…
holiman Sep 23, 2022
220bdd3
.github: add CL client to issue template (#25814)
s1na Sep 23, 2022
e6d4aed
p2p: add channel buffers to avoid goroutine leaks in tests (#24929)
Chain-Fox Sep 23, 2022
65f3c1b
internal/version: use gitCommit injection in version handling code (#…
fjl Sep 23, 2022
e878067
cmd/abigen: change --exc to exclude by type name (#22620)
sebastianst Sep 23, 2022
9b35f3f
tests, les, eth: remove mentions of deprecated Morden testnet (#23570)
Sep 23, 2022
3da42f8
all: clean up the configs for pruner and snapshotter (#22396)
rjl493456442 Sep 23, 2022
15b4a4b
cmd/puppeth, cmd/utils: finalize removal of gasTarget flag (#24370)
Sep 23, 2022
367e605
core/types: improve accuracy of header.Size() (#25859)
zhiqiangxu Sep 26, 2022
4dc212d
eth/tracers: pad memory slice on OOB case (#25213)
s1na Sep 26, 2022
a3c6d1d
cmd/faucet: fix readme typos (#25867)
omahs Sep 26, 2022
e004e7d
core: fix datarace in txpool, fixes #25870 and #25869 (#25872)
holiman Sep 26, 2022
b32d203
eth/downloader, les/downloader: fix subtle flaw in queue delivery (#2…
zhiqiangxu Sep 26, 2022
c55c56c
core/vm: better handle error on eip activation check (#25131)
qinglin89 Sep 26, 2022
7227c9e
cmd/geth: make dumpgenesis load genesis datadir if it exists (#25135)
jwasinger Sep 26, 2022
3ec6fe6
tests: fix state test error checking (#25702)
meowsbits Sep 26, 2022
fc3e6d0
eth/tracers: use gencodec for native tracers (#25637)
s1na Sep 26, 2022
bff84a9
cmd, core, eth, les, light: track deleted nodes (#25757)
rjl493456442 Sep 27, 2022
13e6985
eth: return state error via GetEVM (#25876)
zhiqiangxu Sep 27, 2022
80cc34a
eth/downloader: make flakey test less flakey (#25879)
holiman Sep 27, 2022
1a63a76
ethclient/gethclient: fix bugs in override object encoding (#25616)
simonovic86 Sep 27, 2022
456b187
trie, eth/protocols/snap: less tiny db-writes during trie-healing (#2…
holiman Sep 28, 2022
1743e61
accounts/abi/bind/backends: fix AdjustTime to respect Fork (#25225)
lightclient Sep 28, 2022
53d68fe
tests: report mgas/s metric in evm benchmarks (#25700)
shekhirin Sep 28, 2022
2b1299b
core/vm: minor trivial clean up (#25880)
lmittmann Sep 28, 2022
85aafcf
eth/tracers: fix a bug in prestateTracer (#25884)
jsvisa Sep 28, 2022
88132af
internal/ethapi: handle odd length hex in decodeHash (#25883)
f01c5700 Sep 28, 2022
052c634
core: rework tx indexer (#25723)
rjl493456442 Sep 29, 2022
c2918c2
accounts/abi: return toGoType error immediately (#25565)
ceyonur Sep 29, 2022
ff1f492
eth/tracers: remove revertReasonTracer, add revert reason to callTrac…
s1na Sep 29, 2022
f651d6d
accounts/abi/bind: parse ABI only once on bind (#25574)
mikhailv Sep 29, 2022
07e0704
internal/flags: fix issue with stringslice migration (#25830)
holiman Sep 29, 2022
ea26fc8
cmd/geth, cmd/utils: geth attach with custom headers (#25829)
holiman Sep 30, 2022
a724163
core/types: add a testcase to TestLegacyReceiptDecoding (#25909)
zhiqiangxu Oct 3, 2022
f61b50b
eth/protocols/snap: serve snap requests when possible (#25644)
holiman Oct 3, 2022
1913b50
eth, miner: add timeout for building sealing block (#25407)
rjl493456442 Oct 3, 2022
ee301c7
all: fix docstrings
holiman Oct 4, 2022
4f7a425
Merge pull request #25924 from holiman/comments_fix
karalabe Oct 4, 2022
e14164d
core: fix linter complaint (#25927)
holiman Oct 4, 2022
5d52a35
eth/tracers: add diffMode to prestateTracer (#25422)
jsvisa Oct 6, 2022
e50aeac
eth/traces: add state limit (#25812)
rjl493456442 Oct 6, 2022
deead99
core/bloombits: speed up windows-test (#25844)
holiman Oct 6, 2022
067bac3
core, ethclient/gethclient: improve flaky tests (#25918)
holiman Oct 6, 2022
9cddfe9
node: prevent exposing engine API on unauthenticated endpoint (#25939)
fjl Oct 6, 2022
df2b3cd
eth/filters: fix for eth_getLogs failing with finalized- and safe tag…
ryanschneider Oct 6, 2022
5647516
cmd/geth: fix help output issues (#25941)
fjl Oct 6, 2022
7eafbec
accounts/usbwallet: support Ledger Nano S Plus and FTS (#25933)
lochjin Oct 11, 2022
5a02b2d
all: fix spelling mistakes (#25961)
holiman Oct 11, 2022
1c737e8
cmd/geth, core: fix typo in comment (#25954)
molecula451 Oct 11, 2022
28d076d
core/rawdb: provide more info on 'gap in the chain' error (#25938)
holiman Oct 12, 2022
a007ab7
core/types: add more context around ErrInvalidChainID (#25367)
MariusVanDerWijden Oct 12, 2022
bed3b10
common/math: optimized modexp (+ fuzzer) (#25525)
holiman Oct 12, 2022
e257b3a
tests/fuzzers/modexp: gofmt (#25972)
fjl Oct 12, 2022
3630caf
node: drop support for static & trusted node list files (#25610)
s1na Oct 12, 2022
eaf095c
accounts/keystore: faster tests (#25827)
holiman Oct 12, 2022
010f47f
eth/protocols/eth: fix typo in log message (#25969)
DragonDev1906 Oct 12, 2022
5b1a04b
eth/filters, ethclient/gethclient: add fullTx option to pending tx fi…
lmittmann Oct 12, 2022
9207e34
go.mod: upgrade github.com/dop251/goja (#25955)
ucwong Oct 12, 2022
c776a98
eth/tracers: fix the issue of panic in prestate with diffmode (#25957)
jsvisa Oct 12, 2022
fb75f11
Revert "go.mod: upgrade github.com/dop251/goja" (#25975)
holiman Oct 12, 2022
15b7e0b
common/math, tests/fuzzers: use big.Int clone (#26006)
holiman Oct 18, 2022
6069d82
cmd/utils: enable snapshot generation in import-mode (#25990)
holiman Oct 19, 2022
d86fe26
core/rawdb: refactor db key prefix (#26000)
s7v7nislands Oct 19, 2022
b9ba6f6
core/rawdb: open meta file in read only mode (#26009)
rjl493456442 Oct 19, 2022
9b9a1b6
internal/ethapi, accounts/abi/backends: use error defined in core (#2…
s7v7nislands Oct 20, 2022
a404195
eth/tracers: fix the issue prestate missing existing contract state (…
jsvisa Oct 21, 2022
5f70f9f
eth/tracers: simplify test framework (#25973)
holiman Oct 21, 2022
a6dda03
all: refactor txpool into it's own package in prep for 4844
karalabe Oct 24, 2022
a2b7481
Merge pull request #26038 from karalabe/split-txpool
karalabe Oct 24, 2022
68ba845
core/types: rename tx files to group them better together
karalabe Oct 26, 2022
5bed24d
Merge pull request #26044 from karalabe/rename-typed-tx-files
karalabe Oct 26, 2022
c4a6621
core, eth: for types with accurate size calcs, return uint64, not flo…
karalabe Oct 26, 2022
1d0c4e2
build: upgrade -dlgo version to Go 1.19.2
sandakersmann Oct 26, 2022
7496ad8
Merge pull request #26049 from sandakersmann/master
karalabe Oct 27, 2022
0c66d97
accounts/scwallet: fix keycard data signing error (#25331)
gballet Oct 27, 2022
4984c4e
build: make ios work again (#26052)
jakub-freebit Oct 27, 2022
9d795d0
core/vm: use optimized bigint (#26021)
holiman Oct 27, 2022
a1fc0d8
eth/filters: change filter block to be by-ref (#26054)
holiman Oct 27, 2022
60e30a9
core/rawdb: refactor db inspector for extending multiple ancient stor…
rjl493456442 Oct 28, 2022
fbdeff9
cmd/evm: calc base fee if parent data is present (#26051)
lightclient Oct 28, 2022
0f49422
eth/tracers: fix gasUsed for native and JS tracers (#26048)
s1na Oct 28, 2022
2c1af8b
cmd, eth: implement full-sync tester (#26035)
rjl493456442 Oct 28, 2022
fb4a97f
rpc: update docstring (#26072)
s7v7nislands Oct 31, 2022
5329aa3
Fix trace call for inner reverts (#25971)
ngotchac Oct 31, 2022
b0d4433
eth: implement eth/68 (#25980)
vdwijden Oct 31, 2022
8e69622
eth/tracers: add withLog to callTracer (#25991)
jsvisa Nov 1, 2022
0c40df5
eth/tracers: prestateTracer - exclude unchanged storage slots in diff…
s1na Nov 1, 2022
8578eb2
accounts/abi: return error on fixed bytes with size larger than 32 by…
zhiqiangxu Nov 1, 2022
2b65219
consensus/ethash: fix typo (#26016)
zhiqiangxu Nov 1, 2022
2415911
docs/postmortems: remove wrong parentheses (#26066)
SebastianSupreme Nov 1, 2022
a2a144c
miner, eth: implement recommit mechanism for payload building (#25836)
rjl493456442 Nov 2, 2022
24f08ec
miner: fail early if core.NewBlockChain fails (#26079)
roberto-bayardo Nov 2, 2022
621b423
p2p/discover: fix handling of distance 256 in lookupDistances (#26087)
jtraglia Nov 2, 2022
4a81e5a
rlp: add more tests for nil pointer / optional field encoding (#26077)
roberto-bayardo Nov 2, 2022
05037ea
rpc: handle wrong HTTP batch response length (#26064)
jmank88 Nov 2, 2022
f3a005f
cmd/clef: add `list-accounts` and `list-wallets` to CLI (#26080)
jmcook1186 Nov 2, 2022
19bf99f
merge devnet-v3 with latest master, part 1
roberto-bayardo Nov 3, 2022
c77e39b
next ~50 commits from master to merge into devnet-v3
roberto-bayardo Nov 3, 2022
9a4e8e2
crypto/bls12381: docs - fix broken links to references (#26095)
jwasinger Nov 3, 2022
8f94acc
final commits from master merged into devnet-v3
roberto-bayardo Nov 3, 2022
a0731a0
Merge branch 'master' into merge-master
roberto-bayardo Nov 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
eth, les: rework chain tracer (ethereum#25143)
This PR simplifies the logic of chain tracer and also adds the unit tests.

The most important change has been made in this PR is the state management. Whenever a tracing state is acquired there is a corresponding release function be returned as well. It must be called once the state is used up, otherwise resource leaking can happen.

And also the logic of state management has been simplified a lot. Specifically, the state provider(eth backend, les backend) should ensure the state is available and referenced. State customers can use the state according to their own needs, or build other states based on the given state. But once the release function is called, there is no guarantee of the availability of the state.


Co-authored-by: Sina Mahmoodi <[email protected]>
Co-authored-by: Péter Szilágyi <[email protected]>
  • Loading branch information
3 people authored Sep 7, 2022
commit b1f6dccfbaa5712adafabd374b89d8d12e4ad3ad
4 changes: 3 additions & 1 deletion eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ func (api *DebugAPI) StorageRangeAt(blockHash common.Hash, txIndex int, contract
if block == nil {
return StorageRangeResult{}, fmt.Errorf("block %#x not found", blockHash)
}
_, _, statedb, err := api.eth.stateAtTransaction(block, txIndex, 0)
_, _, statedb, release, err := api.eth.stateAtTransaction(block, txIndex, 0)
if err != nil {
return StorageRangeResult{}, err
}
defer release()

st := statedb.StorageTrie(contractAddress)
if st == nil {
return StorageRangeResult{}, fmt.Errorf("account %x doesn't exist", contractAddress)
Expand Down
7 changes: 4 additions & 3 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/miner"
Expand Down Expand Up @@ -363,10 +364,10 @@ func (b *EthAPIBackend) StartMining(threads int) error {
return b.eth.StartMining(threads)
}

func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, checkLive, preferDisk bool) (*state.StateDB, error) {
return b.eth.StateAtBlock(block, reexec, base, checkLive, preferDisk)
func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (*state.StateDB, tracers.StateReleaseFunc, error) {
return b.eth.StateAtBlock(block, reexec, base, readOnly, preferDisk)
}

func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, error) {
func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
return b.eth.stateAtTransaction(block, txIndex, reexec)
}
107 changes: 65 additions & 42 deletions eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,97 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
)

// noopReleaser is returned in case there is no operation expected
// for releasing state.
var noopReleaser = tracers.StateReleaseFunc(func() {})

// StateAtBlock retrieves the state database associated with a certain block.
// If no state is locally available for the given block, a number of blocks
// are attempted to be reexecuted to generate the desired state. The optional
// base layer statedb can be passed then it's regarded as the statedb of the
// base layer statedb can be provided which is regarded as the statedb of the
// parent block.
//
// An additional release function will be returned if the requested state is
// available. Release is expected to be invoked when the returned state is no longer needed.
// Its purpose is to prevent resource leaking. Though it can be noop in some cases.
//
// Parameters:
// - block: The block for which we want the state (== state at the stateRoot of the parent)
// - reexec: The maximum number of blocks to reprocess trying to obtain the desired state
// - base: If the caller is tracing multiple blocks, the caller can provide the parent state
// continuously from the callsite.
// - checklive: if true, then the live 'blockchain' state database is used. If the caller want to
// perform Commit or other 'save-to-disk' changes, this should be set to false to avoid
// storing trash persistently
// - preferDisk: this arg can be used by the caller to signal that even though the 'base' is provided,
// it would be preferable to start from a fresh state, if we have it on disk.
func (eth *Ethereum) StateAtBlock(block *types.Block, reexec uint64, base *state.StateDB, checkLive bool, preferDisk bool) (statedb *state.StateDB, err error) {
// - block: The block for which we want the state(state = block.Root)
// - reexec: The maximum number of blocks to reprocess trying to obtain the desired state
// - base: If the caller is tracing multiple blocks, the caller can provide the parent
// state continuously from the callsite.
// - readOnly: If true, then the live 'blockchain' state database is used. No mutation should
// be made from caller, e.g. perform Commit or other 'save-to-disk' changes.
// Otherwise, the trash generated by caller may be persisted permanently.
// - preferDisk: this arg can be used by the caller to signal that even though the 'base' is
// provided, it would be preferable to start from a fresh state, if we have it
// on disk.
func (eth *Ethereum) StateAtBlock(block *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (statedb *state.StateDB, release tracers.StateReleaseFunc, err error) {
var (
current *types.Block
database state.Database
report = true
origin = block.NumberU64()
)
// Check the live database first if we have the state fully available, use that.
if checkLive {
statedb, err = eth.blockchain.StateAt(block.Root())
if err == nil {
return statedb, nil
// The state is only for reading purposes, check the state presence in
// live database.
if readOnly {
// The state is available in live database, create a reference
// on top to prevent garbage collection and return a release
// function to deref it.
if statedb, err = eth.blockchain.StateAt(block.Root()); err == nil {
statedb.Database().TrieDB().Reference(block.Root(), common.Hash{})
return statedb, func() {
statedb.Database().TrieDB().Dereference(block.Root())
}, nil
}
}
// The state is both for reading and writing, or it's unavailable in disk,
// try to construct/recover the state over an ephemeral trie.Database for
// isolating the live one.
if base != nil {
if preferDisk {
// Create an ephemeral trie.Database for isolating the live one. Otherwise
// the internal junks created by tracing will be persisted into the disk.
database = state.NewDatabaseWithConfig(eth.chainDb, &trie.Config{Cache: 16})
if statedb, err = state.New(block.Root(), database, nil); err == nil {
log.Info("Found disk backend for state trie", "root", block.Root(), "number", block.Number())
return statedb, nil
return statedb, noopReleaser, nil
}
}
// The optional base statedb is given, mark the start point as parent block
statedb, database, report = base, base.Database(), false
current = eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
} else {
// Otherwise try to reexec blocks until we find a state or reach our limit
// Otherwise, try to reexec blocks until we find a state or reach our limit
current = block

// Create an ephemeral trie.Database for isolating the live one. Otherwise
// the internal junks created by tracing will be persisted into the disk.
database = state.NewDatabaseWithConfig(eth.chainDb, &trie.Config{Cache: 16})

// If we didn't check the dirty database, do check the clean one, otherwise
// we would rewind past a persisted block (specific corner case is chain
// tracing from the genesis).
if !checkLive {
// If we didn't check the live database, do check state over ephemeral database,
// otherwise we would rewind past a persisted block (specific corner case is
// chain tracing from the genesis).
if !readOnly {
statedb, err = state.New(current.Root(), database, nil)
if err == nil {
return statedb, nil
return statedb, noopReleaser, nil
}
}
// Database does not have the state for the given block, try to regenerate
for i := uint64(0); i < reexec; i++ {
if current.NumberU64() == 0 {
return nil, errors.New("genesis state is missing")
return nil, nil, errors.New("genesis state is missing")
}
parent := eth.blockchain.GetBlock(current.ParentHash(), current.NumberU64()-1)
if parent == nil {
return nil, fmt.Errorf("missing block %v %d", current.ParentHash(), current.NumberU64()-1)
return nil, nil, fmt.Errorf("missing block %v %d", current.ParentHash(), current.NumberU64()-1)
}
current = parent

Expand All @@ -108,13 +128,14 @@ func (eth *Ethereum) StateAtBlock(block *types.Block, reexec uint64, base *state
if err != nil {
switch err.(type) {
case *trie.MissingNodeError:
return nil, fmt.Errorf("required historical state unavailable (reexec=%d)", reexec)
return nil, nil, fmt.Errorf("required historical state unavailable (reexec=%d)", reexec)
default:
return nil, err
return nil, nil, err
}
}
}
// State was available at historical point, regenerate
// State is available at historical point, re-execute the blocks on top for
// the desired state.
var (
start = time.Now()
logged time.Time
Expand All @@ -129,22 +150,24 @@ func (eth *Ethereum) StateAtBlock(block *types.Block, reexec uint64, base *state
// Retrieve the next block to regenerate and process it
next := current.NumberU64() + 1
if current = eth.blockchain.GetBlockByNumber(next); current == nil {
return nil, fmt.Errorf("block #%d not found", next)
return nil, nil, fmt.Errorf("block #%d not found", next)
}
_, _, _, err := eth.blockchain.Processor().Process(current, statedb, vm.Config{})
if err != nil {
return nil, fmt.Errorf("processing block %d failed: %v", current.NumberU64(), err)
return nil, nil, fmt.Errorf("processing block %d failed: %v", current.NumberU64(), err)
}
// Finalize the state so any modifications are written to the trie
root, err := statedb.Commit(eth.blockchain.Config().IsEIP158(current.Number()))
if err != nil {
return nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w",
return nil, nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w",
current.NumberU64(), current.Root().Hex(), err)
}
statedb, err = state.New(root, database, nil)
if err != nil {
return nil, fmt.Errorf("state reset after block %d failed: %v", current.NumberU64(), err)
return nil, nil, fmt.Errorf("state reset after block %d failed: %v", current.NumberU64(), err)
}
// Hold the state reference and also drop the parent state
// to prevent accumulating too many nodes in memory.
database.TrieDB().Reference(root, common.Hash{})
if parent != (common.Hash{}) {
database.TrieDB().Dereference(parent)
Expand All @@ -155,28 +178,28 @@ func (eth *Ethereum) StateAtBlock(block *types.Block, reexec uint64, base *state
nodes, imgs := database.TrieDB().Size()
log.Info("Historical state regenerated", "block", current.NumberU64(), "elapsed", time.Since(start), "nodes", nodes, "preimages", imgs)
}
return statedb, nil
return statedb, func() { database.TrieDB().Dereference(block.Root()) }, nil
}

// stateAtTransaction returns the execution environment of a certain transaction.
func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, error) {
func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.StateDB, tracers.StateReleaseFunc, error) {
// Short circuit if it's genesis block.
if block.NumberU64() == 0 {
return nil, vm.BlockContext{}, nil, errors.New("no transaction in genesis")
return nil, vm.BlockContext{}, nil, nil, errors.New("no transaction in genesis")
}
// Create the parent state database
parent := eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if parent == nil {
return nil, vm.BlockContext{}, nil, fmt.Errorf("parent %#x not found", block.ParentHash())
return nil, vm.BlockContext{}, nil, nil, fmt.Errorf("parent %#x not found", block.ParentHash())
}
// Lookup the statedb of parent block from the live database,
// otherwise regenerate it on the flight.
statedb, err := eth.StateAtBlock(parent, reexec, nil, true, false)
statedb, release, err := eth.StateAtBlock(parent, reexec, nil, true, false)
if err != nil {
return nil, vm.BlockContext{}, nil, err
return nil, vm.BlockContext{}, nil, nil, err
}
if txIndex == 0 && len(block.Transactions()) == 0 {
return nil, vm.BlockContext{}, statedb, nil
return nil, vm.BlockContext{}, statedb, release, nil
}
// Recompute transactions up to the target index.
signer := types.MakeSigner(eth.blockchain.Config(), block.Number())
Expand All @@ -186,17 +209,17 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(block.Header(), eth.blockchain, nil)
if idx == txIndex {
return msg, context, statedb, nil
return msg, context, statedb, release, nil
}
// Not yet the searched for transaction, execute on top of the current state
vmenv := vm.NewEVM(context, txContext, statedb, eth.blockchain.Config(), vm.Config{})
statedb.Prepare(tx.Hash(), idx)
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
return nil, vm.BlockContext{}, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
return nil, vm.BlockContext{}, nil, nil, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
}
// Ensure any modifications are committed to the state
// Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect
statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number()))
}
return nil, vm.BlockContext{}, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, block.Hash())
return nil, vm.BlockContext{}, nil, nil, fmt.Errorf("transaction index %d out of range for block %#x", txIndex, block.Hash())
}
Loading