Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: live chain-aware tracing #27629

Closed
wants to merge 113 commits into from
Closed
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
642a374
Initial support for extended tracer
s1na Jun 15, 2023
e25065b
capture keccak preimage
s1na Jun 15, 2023
f67ac09
add hooks to state object & genesis
s1na Jun 20, 2023
84d6432
add log and newAccount hooks
s1na Jun 22, 2023
ee791b2
add gas consumption hook
s1na Jun 23, 2023
0d25fbc
pass logger to BC through vmConfig
s1na Jun 26, 2023
8db1078
fix genesis logging
s1na Jun 26, 2023
788851b
disable tracing for miner processed txes
s1na Jun 26, 2023
057bbda
add comments
s1na Jun 26, 2023
a7de17e
only emit event for new accounts
s1na Jun 26, 2023
3787816
Upgrade TxStart and TxEnd hooks
s1na Jun 28, 2023
3975c7c
minor
s1na Jun 28, 2023
619ac29
provide StateLogger for short-lived tracers
s1na Jun 28, 2023
54171ee
pass env in TxStart
s1na Jun 28, 2023
3cabef4
capture block end errors
s1na Jun 30, 2023
f1bd415
rm extra CaptureTxEnd
s1na Jul 10, 2023
d799c68
nicer printer output
s1na Jul 10, 2023
add825e
fix BlockEnd in case of err
s1na Jul 10, 2023
0aeec7f
mv td to OnBlockStart
s1na Jul 12, 2023
b692a68
add final & safe headers to BlockStart
s1na Jul 12, 2023
2a59d24
add genesis alloc to hook
s1na Jul 12, 2023
4370527
fix prefetcher double emit
s1na Jul 24, 2023
5466fa3
Capture balance reason (#12)
maoueh Jul 26, 2023
2faf3db
emit err on tx validation failure
s1na Jul 26, 2023
b2b32e6
fix merge conflict
s1na Jul 27, 2023
09ee197
fix merge conflict
s1na Jul 27, 2023
f9f377d
capture call validation errors
s1na Jul 27, 2023
b7ff573
minor refactor
s1na Jul 28, 2023
00a19d3
Fixed tests compilation (#13)
maoueh Aug 2, 2023
216a4b0
Added writing of `genesis.Alloc` on bootstrap (#15)
maoueh Aug 30, 2023
659043a
pass tracer name via cli
s1na Aug 30, 2023
9c999c3
Use noopTracer as base for loggers
s1na Aug 31, 2023
0be6e22
add comment to statedb logger
s1na Aug 31, 2023
abd8807
use defer for OnBlockEnd
s1na Aug 31, 2023
f7ca31e
fix import cycle in blockchain test
s1na Sep 4, 2023
651c438
fix runtime tests
s1na Sep 4, 2023
74c1f30
Fixed `BlockchainLogger` tracer not being correctly set up up to `Blo…
maoueh Sep 12, 2023
ff3c15f
Full OnGasConsumed loop and added `GasChangeReason` (#16)
maoueh Sep 12, 2023
6ee4fb8
resolve merge conflicts
s1na Sep 13, 2023
1914bc6
error code for VM failures (#18)
maoueh Oct 27, 2023
429dcc9
fix merge conflict
s1na Nov 2, 2023
e65f14a
update state processor
s1na Nov 2, 2023
e4399a6
Use applyTransaction in tracer instead of applyMessage
s1na Nov 3, 2023
14d603b
add comment re newAccount precompile
s1na Nov 3, 2023
023ade6
instrument when inserting known block
s1na Nov 3, 2023
ee58cc7
statedb: precompile check before onNewAccount
s1na Nov 7, 2023
dc1175e
rm unnecessary line
s1na Nov 7, 2023
da8b362
minor
s1na Nov 7, 2023
0d268b7
fix TxStart for traceCall
s1na Nov 8, 2023
cc6b68e
Fix prestate create issue, add test
s1na Nov 11, 2023
6b8d216
fix setBalance reasons
s1na Nov 13, 2023
b80aa1e
fix double-allocation
s1na Nov 24, 2023
1d13645
move balance reason to metadata file
s1na Nov 24, 2023
856c079
move traced block processing to own func
s1na Nov 24, 2023
9c00b12
fix merge conflict
s1na Nov 24, 2023
379b8d3
fix atomic followupInterrupt
s1na Nov 24, 2023
56600e9
fix VMError.Unwrap
s1na Nov 24, 2023
8a1f67c
forgot prestate testcase
s1na Nov 24, 2023
5bc3f62
move makeTest to own file
s1na Nov 24, 2023
cd8c4c5
force load live tracer set
s1na Nov 24, 2023
8610f8f
add hooks for beacon block root processing
s1na Nov 24, 2023
00ee953
rm comment
s1na Nov 28, 2023
72410c3
Fixed `BlockchainLogger.OnBlockEnd` called too much times (#19)
maoueh Nov 30, 2023
c341c79
Merge remote-tracking branch 's1na/extended-tracer' into extended-tracer
s1na Dec 4, 2023
5190cfc
rm extra galloc capturing
s1na Dec 5, 2023
9e5c96f
add chainConfig to block events
s1na Dec 5, 2023
f862531
rm chainConfig from OnGenesisBlock
s1na Dec 5, 2023
c5e407b
resolve merge conflicts
s1na Dec 5, 2023
9360cab
assign values for balance reasons
s1na Dec 7, 2023
0967291
Track burnt and selfdestruct withdraw bal changes
s1na Dec 7, 2023
ddd1b0a
fix gas purchase
s1na Dec 11, 2023
0484068
fix lint issues
s1na Dec 11, 2023
5e82cbe
nil check
s1na Dec 11, 2023
0d254e4
fix test
s1na Dec 11, 2023
a52c80d
Fix test case
s1na Dec 12, 2023
89d79d6
fix t8n tracer nil check
s1na Dec 12, 2023
54f4bc7
fix balance check
s1na Dec 13, 2023
64e35e9
revert buyGas refactor
s1na Dec 13, 2023
8b3180d
revert gas refund
s1na Dec 13, 2023
2d14bb5
rename and document balance change reasons
s1na Dec 13, 2023
68bd6c6
Removed the `OnGenesisBlock` in `genesis.Commit` (#20)
maoueh Jan 11, 2024
f241a76
fix comment'
s1na Jan 12, 2024
580f025
has call reverted to snapshot
s1na Jan 12, 2024
aa0db68
resolve merge conflict
s1na Jan 12, 2024
f21efbc
fix traceWriter
s1na Jan 12, 2024
c331930
add test case for frontier create out of storage
s1na Jan 15, 2024
626fee4
fix withdraw balance change name
s1na Jan 15, 2024
d07264a
no balance change reason on 0 balance selfdestruct
s1na Jan 16, 2024
4c1d675
resolve merge conflict
s1na Jan 29, 2024
9a6b9a2
re-add simulated backend removed accidentally
s1na Jan 30, 2024
ae522d6
rm empty line
s1na Jan 30, 2024
56862cf
emit onNewAccount when reseting account
s1na Jan 30, 2024
68342ef
improve processBlock
s1na Jan 31, 2024
3078dfe
minor fix
s1na Jan 31, 2024
6c44a59
fix self destruct burn condition
s1na Feb 5, 2024
188cd41
remove precompile check for newAccount
s1na Feb 5, 2024
f3c0a89
add OnBlockchainInit for chainConfig
s1na Feb 6, 2024
95b5029
replace printer with noop live tracer
s1na Feb 6, 2024
2cc0954
rename
s1na Feb 6, 2024
57cd0c3
rm OnNewAccount
s1na Feb 8, 2024
056f229
indicate known block
s1na Feb 8, 2024
27f662d
fix merge conflict
s1na Feb 8, 2024
706c869
fix remaining conflict
s1na Feb 9, 2024
03206be
fix blockchain -> logger circular import
s1na Feb 9, 2024
08cb623
live tracer err -> warn
s1na Feb 9, 2024
cf6a315
fix mdLogger
s1na Feb 9, 2024
4cd7cb3
resolve merge conflict
s1na Feb 14, 2024
674a38e
add config for tracers
s1na Feb 14, 2024
0db7a19
minor fix
s1na Feb 14, 2024
35291e6
resolve merge conflict
s1na Feb 15, 2024
3ba6b92
remove onBeaconBlockRoot events
s1na Feb 15, 2024
5f0a543
refactor onBlockStart params, new skip method
s1na Feb 15, 2024
490efc5
resolve merge conflict
s1na Feb 16, 2024
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
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM

// Set infinite balance to the fake caller account.
from := stateDB.GetOrNewStateObject(call.From)
from.SetBalance(math.MaxBig256)
from.SetBalance(math.MaxBig256, state.BalanceChangeUnspecified)

// Execute the call.
msg := &core.Message{
Expand Down
13 changes: 8 additions & 5 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
}
if beaconRoot := pre.Env.ParentBeaconBlockRoot; beaconRoot != nil {
evm := vm.NewEVM(vmContext, vm.TxContext{}, statedb, chainConfig, vmConfig)
core.ProcessBeaconBlockRoot(*beaconRoot, evm, statedb)
core.ProcessBeaconBlockRoot(*beaconRoot, evm, statedb, nil)
}
var blobGasUsed uint64

Expand Down Expand Up @@ -234,13 +234,15 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
)
evm := vm.NewEVM(vmContext, txContext, statedb, chainConfig, vmConfig)

tracer.CaptureTxStart(evm, tx, msg.From)
// (ret []byte, usedGas uint64, failed bool, err error)
msgResult, err := core.ApplyMessage(evm, msg, gaspool)
if err != nil {
statedb.RevertToSnapshot(snapshot)
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From, "error", err)
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
gaspool.SetGas(prevGas)
tracer.CaptureTxEnd(nil, err)
continue
}
includedTxs = append(includedTxs, tx)
Expand Down Expand Up @@ -282,6 +284,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
//receipt.BlockNumber
receipt.TransactionIndex = uint(txIndex)
receipts = append(receipts, receipt)
tracer.CaptureTxEnd(receipt, nil)
}

txIndex++
Expand All @@ -307,15 +310,15 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
reward.Sub(reward, new(big.Int).SetUint64(ommer.Delta))
reward.Mul(reward, blockReward)
reward.Div(reward, big.NewInt(8))
statedb.AddBalance(ommer.Address, reward)
statedb.AddBalance(ommer.Address, reward, state.BalanceChangeRewardMineUncle)
}
statedb.AddBalance(pre.Env.Coinbase, minerReward)
statedb.AddBalance(pre.Env.Coinbase, minerReward, state.BalanceChangeRewardMineBlock)
}
// Apply withdrawals
for _, w := range pre.Env.Withdrawals {
// Amount is in gwei, turn into wei
amount := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), big.NewInt(params.GWei))
statedb.AddBalance(w.Address, amount)
statedb.AddBalance(w.Address, amount, state.BalanceChangeWithdrawal)
}
// Commit block
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
Expand Down Expand Up @@ -358,7 +361,7 @@ func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB
for addr, a := range accounts {
statedb.SetCode(addr, a.Code)
statedb.SetNonce(addr, a.Nonce)
statedb.SetBalance(addr, a.Balance)
statedb.SetBalance(addr, a.Balance, state.BalanceChangeGenesisBalance)
for k, v := range a.Storage {
statedb.SetState(addr, k, v)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
utils.TxLookupLimitFlag,
utils.VMTraceFlag,
utils.TransactionHistoryFlag,
utils.StateHistoryFlag,
}, utils.DatabaseFlags),
Expand Down Expand Up @@ -201,7 +202,7 @@ func initGenesis(ctx *cli.Context) error {
triedb := utils.MakeTrieDatabase(ctx, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsVerkle())
defer triedb.Close()

_, hash, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides)
_, hash, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides, nil)
if err != nil {
utils.Fatalf("Failed to write genesis block: %v", err)
}
Expand Down
13 changes: 13 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/tracers/directory"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/internal/version"
Expand Down Expand Up @@ -177,6 +178,18 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
v := ctx.Uint64(utils.OverrideVerkle.Name)
cfg.Eth.OverrideVerkle = &v
}

if ctx.IsSet(utils.VMTraceFlag.Name) {
if name := ctx.String(utils.VMTraceFlag.Name); name != "" {
t, err := directory.LiveDirectory.New(name)
if err != nil {
utils.Fatalf("Failed to create tracer %q: %v", name, err)
}

cfg.Eth.VMTracer = t
}
}

backend, eth := utils.RegisterEthService(stack, &cfg.Eth)

// Create gauge with geth system and build information
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

// Force-load the tracer engines to trigger registration
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/live"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -136,6 +137,7 @@ var (
utils.DeveloperGasLimitFlag,
utils.DeveloperPeriodFlag,
utils.VMEnableDebugFlag,
utils.VMTraceFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
utils.NoCompactionFlag,
Expand Down
17 changes: 16 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/eth/tracers/directory"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/remotedb"
"github.com/ethereum/go-ethereum/ethstats"
Expand Down Expand Up @@ -496,6 +497,11 @@ var (
Usage: "Record information useful for VM and contract debugging",
Category: flags.VMCategory,
}
VMTraceFlag = &cli.StringFlag{
Name: "vmtrace",
Usage: "Name of tracer which should record internal VM operations (costly)",
Category: flags.VMCategory,
}

// API options.
RPCGlobalGasCapFlag = &cli.Uint64Flag{
Expand Down Expand Up @@ -2110,12 +2116,21 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
cache.TrieDirtyLimit = ctx.Int(CacheFlag.Name) * ctx.Int(CacheGCFlag.Name) / 100
}
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}

if ctx.IsSet(VMTraceFlag.Name) {
if name := ctx.String(VMTraceFlag.Name); name != "" {
t, err := directory.LiveDirectory.New(name)
if err != nil {
Fatalf("Failed to create tracer %q: %v", name, err)
}
vmcfg.Tracer = t
}
}
// Disable transaction indexing/unindexing by default.
chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil)
if err != nil {
Fatalf("Can't create BlockChain: %v", err)
}

return chain, chainDb
}

Expand Down
6 changes: 3 additions & 3 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,17 @@ func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.H
}

// Finalize implements consensus.Engine and processes withdrawals on top.
func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.Header, stateDB *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
if !beacon.IsPoSHeader(header) {
beacon.ethone.Finalize(chain, header, state, txs, uncles, nil)
beacon.ethone.Finalize(chain, header, stateDB, txs, uncles, nil)
return
}
// Withdrawals processing.
for _, w := range withdrawals {
// Convert amount from gwei to wei.
amount := new(big.Int).SetUint64(w.Amount)
amount = amount.Mul(amount, big.NewInt(params.GWei))
state.AddBalance(w.Address, amount)
stateDB.AddBalance(w.Address, amount, state.BalanceChangeWithdrawal)
}
// No block reward which is issued by consensus layer instead.
}
Expand Down
6 changes: 3 additions & 3 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ var (
// AccumulateRewards credits the coinbase of the given block with the mining
// reward. The total reward consists of the static block reward and rewards for
// included uncles. The coinbase of each uncle block is also rewarded.
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
func accumulateRewards(config *params.ChainConfig, stateDB *state.StateDB, header *types.Header, uncles []*types.Header) {
// Select the correct block reward based on chain progression
blockReward := FrontierBlockReward
if config.IsByzantium(header.Number) {
Expand All @@ -586,10 +586,10 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
r.Sub(r, header.Number)
r.Mul(r, blockReward)
r.Div(r, big8)
state.AddBalance(uncle.Coinbase, r)
stateDB.AddBalance(uncle.Coinbase, r, state.BalanceChangeRewardMineUncle)

r.Div(blockReward, big32)
reward.Add(reward, r)
}
state.AddBalance(header.Coinbase, reward)
stateDB.AddBalance(header.Coinbase, reward, state.BalanceChangeRewardMineBlock)
}
4 changes: 2 additions & 2 deletions consensus/misc/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func ApplyDAOHardFork(statedb *state.StateDB) {

// Move every DAO account and extra-balance account funds into the refund contract
for _, addr := range params.DAODrainList() {
statedb.AddBalance(params.DAORefundContract, statedb.GetBalance(addr))
statedb.SetBalance(addr, new(big.Int))
statedb.AddBalance(params.DAORefundContract, statedb.GetBalance(addr), state.BalanceChangeDaoRefundContract)
statedb.SetBalance(addr, new(big.Int), state.BalanceChangeDaoAdjustBalance)
}
}
Loading
Loading