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 26 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 @@ -647,7 +647,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, 0x0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from.SetBalance(math.MaxBig256, 0x0)
from.SetBalance(math.MaxBig256, state.BalanceChangeUnspecified)

On the whole, I don't find it super elegant. Would it make sense to have two methods, e.g.

	from.SetBalanceWithReason(math.MaxBig256,  state.BalanceChangeUnspecified)
	from.SetBalance(math.MaxBig256) // defaults to Unspecified

Alternatively, have the default be with reason:

	from.SetBalance(math.MaxBig256,  state.BalanceChangeGenesisBalance)
	from.SetBalanceLegacy(math.MaxBig256) // defaults to Unspecified

I don't know really. But quite a lot of locations where you invoke SetBalance (Add..,Sub..) uses 0x0 here, and it's a bit clunky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear I had responded on this 😮 since my response has vanished:

I don't know. I feel like it will be too easy to "forget" adding a reason if there's a method for it, specially if it's the default. But I agree the 0x0 were not so appealing so changed all of them to Unspecified. They were mostly in tests. The only production code was in eth_call state override and simulated backend.


// Execute the call.
msg := &core.Message{
Expand Down
11 changes: 7 additions & 4 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
)
evm := vm.NewEVM(vmContext, txContext, statedb, chainConfig, vmConfig)

tracer.CaptureTxStart(evm, tx)
// (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 @@ -230,6 +232,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 @@ -255,15 +258,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 @@ -301,7 +304,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
1 change: 1 addition & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
utils.TxLookupLimitFlag,
utils.VMTraceFlag,
}, utils.DatabasePathFlags),
Description: `
The import command imports blocks from an RLP-encoded form. The form can be one file
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ var (
utils.DeveloperGasLimitFlag,
utils.DeveloperPeriodFlag,
utils.VMEnableDebugFlag,
utils.VMTraceFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
utils.NoCompactionFlag,
Expand Down
13 changes: 12 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ var (
Usage: "Record information useful for VM and contract debugging",
Category: flags.VMCategory,
}
VMTraceFlag = &cli.BoolFlag{
Name: "vmtrace",
Usage: "Record internal VM operations (costly)",
Category: flags.VMCategory,
}

// API options.
RPCGlobalGasCapFlag = &cli.Uint64Flag{
Expand Down Expand Up @@ -1718,6 +1723,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// TODO(fjl): force-enable this in --dev mode
cfg.EnablePreimageRecording = ctx.Bool(VMEnableDebugFlag.Name)
}
if ctx.IsSet(VMTraceFlag.Name) {
cfg.LiveTrace = ctx.Bool(VMTraceFlag.Name)
}

if ctx.IsSet(RPCGlobalGasCapFlag.Name) {
cfg.RPCGasCap = ctx.Uint64(RPCGlobalGasCapFlag.Name)
Expand Down Expand Up @@ -2134,12 +2142,15 @@ 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) {
vmcfg.Tracer = tracers.NewPrinter()
s1na marked this conversation as resolved.
Show resolved Hide resolved
}
// 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 @@ -341,17 +341,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 @@ -546,7 +546,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 @@ -563,10 +563,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)
}
}
48 changes: 46 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ var defaultCacheConfig = &CacheConfig{
SnapshotWait: true,
}

// BlockchainLogger is used to collect traces during chain processing.
// Please make a copy of the referenced types if you intend to retain them.
type BlockchainLogger interface {
vm.EVMLogger
state.StateLogger
// OnBlockStart is called before executing `block`.
// `td` is the total difficulty prior to `block`.
OnBlockStart(block *types.Block, td *big.Int, finalized *types.Header, safe *types.Header)
OnBlockEnd(err error)
OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc)
}

// BlockChain represents the canonical chain given a database with a genesis
// block. The Blockchain manages chain imports, reverts, chain reorganisations.
//
Expand Down Expand Up @@ -225,6 +237,7 @@ type BlockChain struct {
processor Processor // Block transaction processor interface
forker *ForkChoice
vmConfig vm.Config
logger BlockchainLogger
}

// NewBlockChain returns a fully initialised block chain using information
Expand All @@ -239,10 +252,19 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
Cache: cacheConfig.TrieCleanLimit,
Preimages: cacheConfig.Preimages,
})
var logger BlockchainLogger
if vmConfig.Tracer != nil {
l, ok := vmConfig.Tracer.(BlockchainLogger)
if !ok {
return nil, fmt.Errorf("only extended tracers are supported for live mode")
s1na marked this conversation as resolved.
Show resolved Hide resolved
}
logger = l
}
// Setup the genesis block, commit the provided genesis specification
// to database if the genesis block is not present yet, or load the
// stored one from database.
chainConfig, genesisHash, genesisErr := SetupGenesisBlockWithOverride(db, triedb, genesis, overrides)
// TODO: pass in blockchainLogger here to catch genesis block and allocs
chainConfig, genesisHash, genesisErr := SetupGenesisBlockWithOverride(db, triedb, genesis, overrides, logger)
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
return nil, genesisErr
}
Expand Down Expand Up @@ -270,6 +292,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
engine: engine,
vmConfig: vmConfig,
logger: logger,
}
bc.flushInterval.Store(int64(cacheConfig.TrieTimeLimit))
bc.forker = NewForkChoice(bc, shouldPreserve)
Expand Down Expand Up @@ -1707,6 +1730,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
if err != nil {
return it.index, err
}
statedb.SetLogger(bc.logger)
s1na marked this conversation as resolved.
Show resolved Hide resolved

// Enable prefetching to pull in trie node paths while processing transactions
statedb.StartPrefetcher("chain")
s1na marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1720,7 +1744,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
throwaway, _ := state.New(parent.Root, bc.stateCache, bc.snaps)

go func(start time.Time, followup *types.Block, throwaway *state.StateDB) {
bc.prefetcher.Prefetch(followup, throwaway, bc.vmConfig, &followupInterrupt)
vmCfg := bc.vmConfig
vmCfg.Tracer = nil
bc.prefetcher.Prefetch(followup, throwaway, vmCfg, &followupInterrupt)

blockPrefetchExecuteTimer.Update(time.Since(start))
if followupInterrupt.Load() {
Expand All @@ -1732,10 +1758,18 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)

// Process block using the parent state as reference point
pstart := time.Now()

if bc.logger != nil {
td := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
bc.logger.OnBlockStart(block, td, bc.CurrentFinalBlock(), bc.CurrentSafeBlock())
}
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig)
if err != nil {
bc.reportBlock(block, receipts, err)
followupInterrupt.Store(true)
if bc.logger != nil {
bc.logger.OnBlockEnd(err)
}
return it.index, err
}
ptime := time.Since(pstart)
Expand All @@ -1744,6 +1778,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
if err := bc.validator.ValidateState(block, statedb, receipts, usedGas); err != nil {
bc.reportBlock(block, receipts, err)
followupInterrupt.Store(true)
if bc.logger != nil {
bc.logger.OnBlockEnd(err)
}
return it.index, err
}
vtime := time.Since(vstart)
Expand Down Expand Up @@ -1778,6 +1815,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}
followupInterrupt.Store(true)
if err != nil {
if bc.logger != nil {
bc.logger.OnBlockEnd(err)
}
return it.index, err
}
// Update the metrics touched during block commit
Expand All @@ -1796,6 +1836,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
dirty, _ := bc.triedb.Size()
stats.report(chain, it.index, dirty, setHead)

if bc.logger != nil {
bc.logger.OnBlockEnd(nil)
s1na marked this conversation as resolved.
Show resolved Hide resolved
}

if !setHead {
// After merge we expect few side chains. Simply count
// all blocks the CL gives us for GC processing time
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
// then generate chain on top.
func GenerateChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (ethdb.Database, []*types.Block, []types.Receipts) {
db := rawdb.NewMemoryDatabase()
_, err := genesis.Commit(db, trie.NewDatabase(db))
_, err := genesis.Commit(db, trie.NewDatabase(db), nil)
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)
Expand Down Expand Up @@ -126,6 +127,6 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool {

// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {
db.SubBalance(sender, amount)
db.AddBalance(recipient, amount)
db.SubBalance(sender, amount, state.BalanceChangeTransfer)
db.AddBalance(recipient, amount, state.BalanceChangeTransfer)
}
Loading