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 112 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
19 changes: 14 additions & 5 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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)
}

for i := 0; txIt.Next(); i++ {
Expand Down Expand Up @@ -236,13 +236,19 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
)
evm := vm.NewEVM(vmContext, txContext, statedb, chainConfig, vmConfig)

if tracer != nil {
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)
if tracer != nil {
tracer.CaptureTxEnd(nil, err)
}
continue
}
includedTxs = append(includedTxs, tx)
Expand Down Expand Up @@ -285,6 +291,9 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
//receipt.BlockNumber
receipt.TransactionIndex = uint(txIndex)
receipts = append(receipts, receipt)
if tracer != nil {
tracer.CaptureTxEnd(receipt, nil)
}
}

txIndex++
Expand All @@ -310,15 +319,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, uint256.MustFromBig(reward))
statedb.AddBalance(ommer.Address, uint256.MustFromBig(reward), state.BalanceIncreaseRewardMineUncle)
}
statedb.AddBalance(pre.Env.Coinbase, uint256.MustFromBig(minerReward))
statedb.AddBalance(pre.Env.Coinbase, uint256.MustFromBig(minerReward), state.BalanceIncreaseRewardMineBlock)
}
// 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, uint256.MustFromBig(amount))
statedb.AddBalance(w.Address, uint256.MustFromBig(amount), state.BalanceIncreaseWithdrawal)
}
// Commit block
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
Expand Down Expand Up @@ -361,7 +370,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, uint256.MustFromBig(a.Balance))
statedb.SetBalance(addr, uint256.MustFromBig(a.Balance), state.BalanceIncreaseGenesisBalance)
for k, v := range a.Storage {
statedb.SetState(addr, k, v)
}
Expand Down
33 changes: 22 additions & 11 deletions cmd/evm/internal/t8ntool/tracewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"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/eth/tracers/directory"
"github.com/ethereum/go-ethereum/log"
)

Expand All @@ -38,11 +39,11 @@ type traceWriter struct {
// Compile-time interface check
var _ = vm.EVMLogger((*traceWriter)(nil))

func (t *traceWriter) CaptureTxEnd(restGas uint64) {
t.inner.CaptureTxEnd(restGas)
func (t *traceWriter) CaptureTxEnd(receipt *types.Receipt, err error) {
t.inner.CaptureTxEnd(receipt, err)
defer t.f.Close()

if tracer, ok := t.inner.(tracers.Tracer); ok {
if tracer, ok := t.inner.(directory.Tracer); ok {
result, err := tracer.GetResult()
if err != nil {
log.Warn("Error in tracer", "err", err)
Expand All @@ -56,21 +57,23 @@ func (t *traceWriter) CaptureTxEnd(restGas uint64) {
}
}

func (t *traceWriter) CaptureTxStart(gasLimit uint64) { t.inner.CaptureTxStart(gasLimit) }
func (t *traceWriter) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
t.inner.CaptureStart(env, from, to, create, input, gas, value)
func (t *traceWriter) CaptureTxStart(env *vm.EVM, tx *types.Transaction, from common.Address) {
t.inner.CaptureTxStart(env, tx, from)
}
func (t *traceWriter) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
t.inner.CaptureStart(from, to, create, input, gas, value)
}

func (t *traceWriter) CaptureEnd(output []byte, gasUsed uint64, err error) {
t.inner.CaptureEnd(output, gasUsed, err)
func (t *traceWriter) CaptureEnd(output []byte, gasUsed uint64, err error, reverted bool) {
t.inner.CaptureEnd(output, gasUsed, err, reverted)
}

func (t *traceWriter) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
t.inner.CaptureEnter(typ, from, to, input, gas, value)
}

func (t *traceWriter) CaptureExit(output []byte, gasUsed uint64, err error) {
t.inner.CaptureExit(output, gasUsed, err)
func (t *traceWriter) CaptureExit(output []byte, gasUsed uint64, err error, reverted bool) {
t.inner.CaptureExit(output, gasUsed, err, reverted)
}

func (t *traceWriter) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
Expand All @@ -79,3 +82,11 @@ func (t *traceWriter) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, sc
func (t *traceWriter) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
t.inner.CaptureFault(pc, op, gas, cost, scope, depth, err)
}

func (t *traceWriter) CaptureKeccakPreimage(hash common.Hash, data []byte) {
t.inner.CaptureKeccakPreimage(hash, data)
}

func (t *traceWriter) OnGasChange(old, new uint64, reason vm.GasChangeReason) {
t.inner.OnGasChange(old, new, reason)
}
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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/eth/tracers/directory"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -113,7 +113,7 @@ func Transition(ctx *cli.Context) error {
if err != nil {
return nil, NewError(ErrorIO, fmt.Errorf("failed creating trace-file: %v", err))
}
tracer, err := tracers.DefaultDirectory.New(ctx.String(TraceTracerFlag.Name), nil, config)
tracer, err := directory.DefaultDirectory.New(ctx.String(TraceTracerFlag.Name), nil, config)
if err != nil {
return nil, NewError(ErrorConfig, fmt.Errorf("failed instantiating tracer: %w", err))
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
utils.TxLookupLimitFlag,
utils.VMTraceFlag,
utils.VMTraceConfigFlag,
utils.TransactionHistoryFlag,
utils.StateHistoryFlag,
}, utils.DatabaseFlags),
Expand Down
18 changes: 18 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -36,6 +37,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/live"
"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 +179,22 @@ 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 != "" {
var config string
if ctx.IsSet(utils.VMTraceConfigFlag.Name) {
config = ctx.String(utils.VMTraceConfigFlag.Name)
}
t, err := live.Directory.New(name, json.RawMessage(config))
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
3 changes: 3 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,8 @@ var (
utils.DeveloperGasLimitFlag,
utils.DeveloperPeriodFlag,
utils.VMEnableDebugFlag,
utils.VMTraceFlag,
utils.VMTraceConfigFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
utils.NoCompactionFlag,
Expand Down
28 changes: 26 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -51,6 +52,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/live"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/remotedb"
"github.com/ethereum/go-ethereum/ethstats"
Expand Down Expand Up @@ -496,7 +498,16 @@ 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,
}
VMTraceConfigFlag = &cli.StringFlag{
Name: "vmtrace.config",
Usage: "Tracer configuration (JSON)",
Category: flags.VMCategory,
}
// API options.
RPCGlobalGasCapFlag = &cli.Uint64Flag{
Name: "rpc.gascap",
Expand Down Expand Up @@ -2120,12 +2131,25 @@ 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 != "" {
var config string
if ctx.IsSet(VMTraceConfigFlag.Name) {
config = ctx.String(VMTraceConfigFlag.Name)
}
t, err := live.Directory.New(name, json.RawMessage(config))
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 @@ -348,17 +348,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(uint256.Int).SetUint64(w.Amount)
amount = amount.Mul(amount, uint256.NewInt(params.GWei))
state.AddBalance(w.Address, amount)
stateDB.AddBalance(w.Address, amount, state.BalanceIncreaseWithdrawal)
}
// 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 @@ -570,7 +570,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 @@ -589,10 +589,10 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
r.Sub(r, hNum)
r.Mul(r, blockReward)
r.Div(r, u256_8)
state.AddBalance(uncle.Coinbase, r)
stateDB.AddBalance(uncle.Coinbase, r, state.BalanceIncreaseRewardMineUncle)

r.Div(blockReward, u256_32)
reward.Add(reward, r)
}
state.AddBalance(header.Coinbase, reward)
stateDB.AddBalance(header.Coinbase, reward, state.BalanceIncreaseRewardMineBlock)
}
4 changes: 2 additions & 2 deletions consensus/misc/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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(uint256.Int))
statedb.AddBalance(params.DAORefundContract, statedb.GetBalance(addr), state.BalanceIncreaseDaoContract)
statedb.SetBalance(addr, new(uint256.Int), state.BalanceDecreaseDaoAccount)
}
}
Loading
Loading