Skip to content

Commit 304396a

Browse files
committed
consensus/satoshi,core,core/state/pruner,core/state,core,core/tracing,core/txpool/legacypool,eth,eth/tracers,internal/ethapi: add missing bits for previous commit
1 parent 446859d commit 304396a

File tree

13 files changed

+45
-31
lines changed

13 files changed

+45
-31
lines changed

consensus/satoshi/satoshi.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/core/forkid"
3232
"github.com/ethereum/go-ethereum/core/state"
3333
"github.com/ethereum/go-ethereum/core/systemcontracts"
34+
"github.com/ethereum/go-ethereum/core/tracing"
3435
"github.com/ethereum/go-ethereum/core/types"
3536
"github.com/ethereum/go-ethereum/core/vm"
3637
"github.com/ethereum/go-ethereum/crypto"
@@ -1240,8 +1241,8 @@ func (p *Satoshi) distributeIncoming(val common.Address, state *state.StateDB, h
12401241
txs *[]*types.Transaction, receipts *[]*types.Receipt, receivedTxs *[]*types.Transaction, usedGas *uint64, mining bool) error {
12411242
coinbase := header.Coinbase
12421243
balance := state.GetBalance(consensus.SystemAddress)
1243-
state.SetBalance(consensus.SystemAddress, common.U2560)
1244-
state.AddBalance(coinbase, balance)
1244+
state.SetBalance(consensus.SystemAddress, common.U2560, tracing.BalanceDecreaseCoreDistributeReward)
1245+
state.AddBalance(coinbase, balance, tracing.BalanceIncreaseCoreDistributeReward)
12451246
log.Trace("distribute to validator contract", "block hash", header.Hash(), "amount", balance)
12461247
return p.distributeToValidator(balance.ToBig(), val, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
12471248
}

core/genesis.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc types.Gene
208208
switch blockhash {
209209
case params.MainnetGenesisHash:
210210
genesis = DefaultGenesisBlock()
211-
case params.GoerliGenesisHash:
212-
genesis = DefaultGoerliGenesisBlock()
213-
case params.SepoliaGenesisHash:
214-
genesis = DefaultSepoliaGenesisBlock()
215-
case params.HoleskyGenesisHash:
216-
genesis = DefaultHoleskyGenesisBlock()
211+
case params.CoreGenesisHash:
212+
genesis = DefaultCOREGenesisBlock()
213+
case params.BuffaloGenesisHash:
214+
genesis = DefaultBuffaloGenesisBlock()
215+
case params.PigeonGenesisHash:
216+
genesis = DefaultPigeonGenesisBlock()
217217
}
218218
if genesis != nil {
219219
return genesis.Alloc, nil

core/state/pruner/pruner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/core/rawdb"
3737
"github.com/ethereum/go-ethereum/core/state"
3838
"github.com/ethereum/go-ethereum/core/state/snapshot"
39+
"github.com/ethereum/go-ethereum/core/tracing"
3940
"github.com/ethereum/go-ethereum/core/types"
4041
"github.com/ethereum/go-ethereum/ethdb"
4142
"github.com/ethereum/go-ethereum/log"
@@ -234,7 +235,7 @@ func pruneAll(maindb ethdb.Database, g *core.Genesis) error {
234235
}
235236
statedb, _ := state.New(common.Hash{}, state.NewDatabase(maindb), nil)
236237
for addr, account := range g.Alloc {
237-
statedb.AddBalance(addr, uint256.MustFromBig(account.Balance))
238+
statedb.AddBalance(addr, uint256.MustFromBig(account.Balance), tracing.BalanceChangeUnspecified)
238239
statedb.SetCode(addr, account.Code)
239240
statedb.SetNonce(addr, account.Nonce)
240241
for key, value := range account.Storage {

core/state/statedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type StateDB struct {
9696
// It will be updated when the Commit is called.
9797
originalRoot common.Hash
9898
expectedRoot common.Hash // The state root in the block header
99-
stateRoot common.Hash // The calculation result of IntermediateRoot
99+
// stateRoot common.Hash // The calculation result of IntermediateRoot
100100

101101
fullProcessed bool
102102

core/state/statedb_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func TestCopyWithDirtyJournal(t *testing.T) {
234234
// Fill up the initial states
235235
for i := byte(0); i < 255; i++ {
236236
obj := orig.getOrNewStateObject(common.BytesToAddress([]byte{i}))
237-
obj.AddBalance(uint256.NewInt(uint64(i)))
237+
obj.AddBalance(uint256.NewInt(uint64(i)), tracing.BalanceChangeUnspecified)
238238
obj.data.Root = common.HexToHash("0xdeadbeef")
239239
orig.updateStateObject(obj)
240240
}
@@ -244,7 +244,7 @@ func TestCopyWithDirtyJournal(t *testing.T) {
244244
// modify all in memory without finalizing
245245
for i := byte(0); i < 255; i++ {
246246
obj := orig.getOrNewStateObject(common.BytesToAddress([]byte{i}))
247-
obj.SubBalance(uint256.NewInt(uint64(i)))
247+
obj.SubBalance(uint256.NewInt(uint64(i)), tracing.BalanceChangeUnspecified)
248248
orig.updateStateObject(obj)
249249
}
250250
cpy := orig.Copy()
@@ -278,7 +278,7 @@ func TestCopyObjectState(t *testing.T) {
278278
// Fill up the initial states
279279
for i := byte(0); i < 5; i++ {
280280
obj := orig.getOrNewStateObject(common.BytesToAddress([]byte{i}))
281-
obj.AddBalance(uint256.NewInt(uint64(i)))
281+
obj.AddBalance(uint256.NewInt(uint64(i)), tracing.BalanceChangeUnspecified)
282282
obj.data.Root = common.HexToHash("0xdeadbeef")
283283
orig.updateStateObject(obj)
284284
}

core/state/trie_prefetcher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr comm
216216
}
217217

218218
select {
219+
case <-p.term:
220+
return errTerminated
219221
case p.prefetchChan <- &prefetchMsg{owner, root, addr, keys}:
220222
}
221223
return nil

core/state_transition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,13 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
454454
fee.Mul(fee, effectiveTipU256)
455455
// consensus engine is satoshi
456456
if st.evm.ChainConfig().Satoshi != nil {
457-
st.state.AddBalance(consensus.SystemAddress, fee)
457+
st.state.AddBalance(consensus.SystemAddress, fee, tracing.BalanceIncreaseRewardTransactionFee)
458458
// add extra blob fee reward
459459
if rules.IsCancun {
460460
blobFee := new(big.Int).SetUint64(st.blobGasUsed())
461461
blobFee.Mul(blobFee, st.evm.Context.BlobBaseFee)
462462
blobFeeU256, _ := uint256.FromBig(blobFee)
463-
st.state.AddBalance(consensus.SystemAddress, blobFeeU256)
463+
st.state.AddBalance(consensus.SystemAddress, blobFeeU256, tracing.BalanceIncreaseRewardTransactionFee)
464464
}
465465
} else {
466466
fee := new(uint256.Int).SetUint64(st.gasUsed())

core/tracing/hooks.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ const (
212212
// account within the same tx (captured at end of tx).
213213
// Note it doesn't account for a self-destruct which appoints itself as recipient.
214214
BalanceDecreaseSelfdestructBurn BalanceChangeReason = 14
215+
216+
// Core specific balance changes
217+
218+
// BalanceDecreaseCoreDistributeReward is a balance change that decreases system address' balance and happens
219+
// when Core is distributing rewards to validator.
220+
BalanceDecreaseCoreDistributeReward BalanceChangeReason = 180
221+
// BalanceIncreaseCoreDistributeReward is a balance change that increases the block validator's balance and
222+
// happens when Core is distributing rewards to validator.
223+
BalanceIncreaseCoreDistributeReward BalanceChangeReason = 181
215224
)
216225

217226
// GasChangeReason is used to indicate the reason for a gas change, useful

core/txpool/legacypool/legacypool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ func TestTransactionPendingReannouce(t *testing.T) {
25522552

25532553
key, _ := crypto.GenerateKey()
25542554
account := crypto.PubkeyToAddress(key.PublicKey)
2555-
pool.currentState.AddBalance(account, uint256.NewInt(1000000))
2555+
pool.currentState.AddBalance(account, uint256.NewInt(1000000), tracing.BalanceChangeUnspecified)
25562556

25572557
events := make(chan core.ReannoTxsEvent, testTxPoolConfig.AccountQueue)
25582558
sub := pool.reannoTxFeed.Subscribe(events)

eth/backend.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
298298
}
299299
vmConfig.Tracer = t
300300
}
301-
302301
if stack.Config().EnableDoubleSignMonitor {
303302
bcOps = append(bcOps, core.EnableDoubleSignChecker)
304303
}

eth/state_accessor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ethereum/go-ethereum/core"
2828
"github.com/ethereum/go-ethereum/core/rawdb"
2929
"github.com/ethereum/go-ethereum/core/state"
30+
"github.com/ethereum/go-ethereum/core/tracing"
3031
"github.com/ethereum/go-ethereum/core/types"
3132
"github.com/ethereum/go-ethereum/core/vm"
3233
"github.com/ethereum/go-ethereum/eth/tracers"
@@ -252,8 +253,8 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block,
252253
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
253254
balance := statedb.GetBalance(consensus.SystemAddress)
254255
if balance.Cmp(common.U2560) > 0 {
255-
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
256-
statedb.AddBalance(block.Header().Coinbase, balance)
256+
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
257+
statedb.AddBalance(block.Header().Coinbase, balance, tracing.BalanceChangeUnspecified)
257258
}
258259

259260
beforeSystemTx = false

eth/tracers/api.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/ethereum/go-ethereum/core"
3636
"github.com/ethereum/go-ethereum/core/rawdb"
3737
"github.com/ethereum/go-ethereum/core/state"
38+
"github.com/ethereum/go-ethereum/core/tracing"
3839
"github.com/ethereum/go-ethereum/core/types"
3940
"github.com/ethereum/go-ethereum/core/vm"
4041
"github.com/ethereum/go-ethereum/eth/tracers/logger"
@@ -282,8 +283,8 @@ func (api *API) traceChain(start, end *types.Block, config *TraceConfig, closed
282283
if isSystem, _ := posa.IsSystemTransaction(tx, task.block.Header()); isSystem {
283284
balance := task.statedb.GetBalance(consensus.SystemAddress)
284285
if balance.Cmp(common.U2560) > 0 {
285-
task.statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
286-
task.statedb.AddBalance(blockCtx.Coinbase, balance)
286+
task.statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
287+
task.statedb.AddBalance(blockCtx.Coinbase, balance, tracing.BalanceChangeUnspecified)
287288
}
288289
beforeSystemTx = false
289290
}
@@ -559,8 +560,8 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config
559560
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
560561
balance := statedb.GetBalance(consensus.SystemAddress)
561562
if balance.Cmp(common.U2560) > 0 {
562-
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
563-
statedb.AddBalance(vmctx.Coinbase, balance)
563+
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
564+
statedb.AddBalance(vmctx.Coinbase, balance, tracing.BalanceChangeUnspecified)
564565
}
565566
}
566567
}
@@ -643,8 +644,8 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
643644
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
644645
balance := statedb.GetBalance(consensus.SystemAddress)
645646
if balance.Cmp(common.U2560) > 0 {
646-
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
647-
statedb.AddBalance(blockCtx.Coinbase, balance)
647+
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
648+
statedb.AddBalance(blockCtx.Coinbase, balance, tracing.BalanceChangeUnspecified)
648649
}
649650

650651
beforeSystemTx = false
@@ -728,8 +729,8 @@ txloop:
728729
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
729730
balance := statedb.GetBalance(consensus.SystemAddress)
730731
if balance.Cmp(common.U2560) > 0 {
731-
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
732-
statedb.AddBalance(block.Header().Coinbase, balance)
732+
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
733+
statedb.AddBalance(block.Header().Coinbase, balance, tracing.BalanceChangeUnspecified)
733734
}
734735

735736
beforeSystemTx = false
@@ -833,8 +834,8 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
833834
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
834835
balance := statedb.GetBalance(consensus.SystemAddress)
835836
if balance.Cmp(common.U2560) > 0 {
836-
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
837-
statedb.AddBalance(vmctx.Coinbase, balance)
837+
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
838+
statedb.AddBalance(vmctx.Coinbase, balance, tracing.BalanceChangeUnspecified)
838839
}
839840

840841
beforeSystemTx = false

internal/ethapi/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,8 +1446,8 @@ func (s *BlockChainAPI) replay(ctx context.Context, block *types.Block, accounts
14461446
if isSystem, _ := posa.IsSystemTransaction(tx, block.Header()); isSystem {
14471447
balance := statedb.GetBalance(consensus.SystemAddress)
14481448
if balance.Cmp(common.U2560) > 0 {
1449-
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0))
1450-
statedb.AddBalance(block.Header().Coinbase, balance)
1449+
statedb.SetBalance(consensus.SystemAddress, uint256.NewInt(0), tracing.BalanceChangeUnspecified)
1450+
statedb.AddBalance(block.Header().Coinbase, balance, tracing.BalanceChangeUnspecified)
14511451
}
14521452
}
14531453
}

0 commit comments

Comments
 (0)