Skip to content

Commit a316abf

Browse files
committed
Merge branch 'master' into feature/grpc-execution-api
* master: rlp/rlpgen: print want/expect output string if mismatch (ethereum#26932) go.mod: update golang.org/x/tools (ethereum#26960) eth/gasprice: change feehistory input type from int to uint64 (ethereum#26922) metrics/influxdb: use smaller dependency and reuse code between v1 and v2 reporters (ethereum#26963) metrics: add cpu counters (ethereum#26796) core/state: add account address to Trie slot accessors (ethereum#26934) cmd/evm, tests: record preimages if dump is expected (ethereum#26955) core/rawdb: update freezertable read meter (ethereum#26946)
2 parents d0892fa + 792d893 commit a316abf

39 files changed

+636
-711
lines changed

cmd/evm/runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/internal/flags"
4141
"github.com/ethereum/go-ethereum/log"
4242
"github.com/ethereum/go-ethereum/params"
43+
"github.com/ethereum/go-ethereum/trie"
4344
"github.com/urfave/cli/v2"
4445
)
4546

@@ -125,6 +126,7 @@ func runCmd(ctx *cli.Context) error {
125126
sender = common.BytesToAddress([]byte("sender"))
126127
receiver = common.BytesToAddress([]byte("receiver"))
127128
genesisConfig *core.Genesis
129+
preimages = ctx.Bool(DumpFlag.Name)
128130
)
129131
if ctx.Bool(MachineFlag.Name) {
130132
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
@@ -139,10 +141,12 @@ func runCmd(ctx *cli.Context) error {
139141
genesisConfig = gen
140142
db := rawdb.NewMemoryDatabase()
141143
genesis := gen.MustCommit(db)
142-
statedb, _ = state.New(genesis.Root(), state.NewDatabase(db), nil)
144+
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: preimages})
145+
statedb, _ = state.New(genesis.Root(), sdb, nil)
143146
chainConfig = gen.Config
144147
} else {
145-
statedb, _ = state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
148+
sdb := state.NewDatabaseWithConfig(rawdb.NewMemoryDatabase(), &trie.Config{Preimages: preimages})
149+
statedb, _ = state.New(common.Hash{}, sdb, nil)
146150
genesisConfig = new(core.Genesis)
147151
}
148152
if ctx.String(SenderFlag.Name) != "" {

core/rawdb/freezer_table.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,9 @@ func (t *freezerTable) retrieveItems(start, count, maxBytes uint64) ([]byte, []i
823823
break
824824
}
825825
}
826+
827+
// Update metrics.
828+
t.readMeter.Mark(int64(totalSize))
826829
return output[:outputSize], sizes, nil
827830
}
828831

core/state/database.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ type Trie interface {
6868
// TODO(fjl): remove this when StateTrie is removed
6969
GetKey([]byte) []byte
7070

71-
// TryGet returns the value for key stored in the trie. The value bytes must
72-
// not be modified by the caller. If a node was not found in the database, a
73-
// trie.MissingNodeError is returned.
74-
TryGet(key []byte) ([]byte, error)
71+
// TryGetStorage returns the value for key stored in the trie. The value bytes
72+
// must not be modified by the caller. If a node was not found in the database,
73+
// a trie.MissingNodeError is returned.
74+
TryGetStorage(addr common.Address, key []byte) ([]byte, error)
7575

7676
// TryGetAccount abstracts an account read from the trie. It retrieves the
7777
// account blob from the trie with provided account address and decodes it
@@ -81,20 +81,20 @@ type Trie interface {
8181
// be returned.
8282
TryGetAccount(address common.Address) (*types.StateAccount, error)
8383

84-
// TryUpdate associates key with value in the trie. If value has length zero, any
85-
// existing value is deleted from the trie. The value bytes must not be modified
84+
// TryUpdateStorage associates key with value in the trie. If value has length zero,
85+
// any existing value is deleted from the trie. The value bytes must not be modified
8686
// by the caller while they are stored in the trie. If a node was not found in the
8787
// database, a trie.MissingNodeError is returned.
88-
TryUpdate(key, value []byte) error
88+
TryUpdateStorage(addr common.Address, key, value []byte) error
8989

9090
// TryUpdateAccount abstracts an account write to the trie. It encodes the
9191
// provided account object with associated algorithm and then updates it
9292
// in the trie with provided address.
9393
TryUpdateAccount(address common.Address, account *types.StateAccount) error
9494

95-
// TryDelete removes any existing value for key from the trie. If a node was not
96-
// found in the database, a trie.MissingNodeError is returned.
97-
TryDelete(key []byte) error
95+
// TryDeleteStorage removes any existing value for key from the trie. If a node
96+
// was not found in the database, a trie.MissingNodeError is returned.
97+
TryDeleteStorage(addr common.Address, key []byte) error
9898

9999
// TryDeleteAccount abstracts an account deletion from the trie.
100100
TryDeleteAccount(address common.Address) error

core/state/state_object.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
201201
s.db.setError(err)
202202
return common.Hash{}
203203
}
204-
enc, err = tr.TryGet(key.Bytes())
204+
enc, err = tr.TryGetStorage(s.address, key.Bytes())
205205
if metrics.EnabledExpensive {
206206
s.db.StorageReads += time.Since(start)
207207
}
@@ -253,7 +253,7 @@ func (s *stateObject) finalise(prefetch bool) {
253253
}
254254
}
255255
if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash {
256-
s.db.prefetcher.prefetch(s.addrHash, s.data.Root, slotsToPrefetch)
256+
s.db.prefetcher.prefetch(s.addrHash, s.data.Root, s.address, slotsToPrefetch)
257257
}
258258
if len(s.dirtyStorage) > 0 {
259259
s.dirtyStorage = make(Storage)
@@ -294,15 +294,15 @@ func (s *stateObject) updateTrie(db Database) (Trie, error) {
294294

295295
var v []byte
296296
if (value == common.Hash{}) {
297-
if err := tr.TryDelete(key[:]); err != nil {
297+
if err := tr.TryDeleteStorage(s.address, key[:]); err != nil {
298298
s.db.setError(err)
299299
return nil, err
300300
}
301301
s.db.StorageDeleted += 1
302302
} else {
303303
// Encoding []byte cannot fail, ok to ignore the error.
304304
v, _ = rlp.EncodeToBytes(common.TrimLeftZeroes(value[:]))
305-
if err := tr.TryUpdate(key[:], v); err != nil {
305+
if err := tr.TryUpdateStorage(s.address, key[:], v); err != nil {
306306
s.db.setError(err)
307307
return nil, err
308308
}

core/state/statedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
871871
addressesToPrefetch = append(addressesToPrefetch, common.CopyBytes(addr[:])) // Copy needed for closure
872872
}
873873
if s.prefetcher != nil && len(addressesToPrefetch) > 0 {
874-
s.prefetcher.prefetch(common.Hash{}, s.originalRoot, addressesToPrefetch)
874+
s.prefetcher.prefetch(common.Hash{}, s.originalRoot, common.Address{}, addressesToPrefetch)
875875
}
876876
// Invalidate journal because reverting across transactions is not allowed.
877877
s.clearJournalAndRefund()

core/state/trie_prefetcher.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (p *triePrefetcher) copy() *triePrefetcher {
141141
}
142142

143143
// prefetch schedules a batch of trie items to prefetch.
144-
func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, keys [][]byte) {
144+
func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr common.Address, keys [][]byte) {
145145
// If the prefetcher is an inactive one, bail out
146146
if p.fetches != nil {
147147
return
@@ -150,7 +150,7 @@ func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, keys [][]
150150
id := p.trieID(owner, root)
151151
fetcher := p.fetchers[id]
152152
if fetcher == nil {
153-
fetcher = newSubfetcher(p.db, p.root, owner, root)
153+
fetcher = newSubfetcher(p.db, p.root, owner, root, addr)
154154
p.fetchers[id] = fetcher
155155
}
156156
fetcher.schedule(keys)
@@ -205,11 +205,12 @@ func (p *triePrefetcher) trieID(owner common.Hash, root common.Hash) string {
205205
// main prefetcher is paused and either all requested items are processed or if
206206
// the trie being worked on is retrieved from the prefetcher.
207207
type subfetcher struct {
208-
db Database // Database to load trie nodes through
209-
state common.Hash // Root hash of the state to prefetch
210-
owner common.Hash // Owner of the trie, usually account hash
211-
root common.Hash // Root hash of the trie to prefetch
212-
trie Trie // Trie being populated with nodes
208+
db Database // Database to load trie nodes through
209+
state common.Hash // Root hash of the state to prefetch
210+
owner common.Hash // Owner of the trie, usually account hash
211+
root common.Hash // Root hash of the trie to prefetch
212+
addr common.Address // Address of the account that the trie belongs to
213+
trie Trie // Trie being populated with nodes
213214

214215
tasks [][]byte // Items queued up for retrieval
215216
lock sync.Mutex // Lock protecting the task queue
@@ -226,12 +227,13 @@ type subfetcher struct {
226227

227228
// newSubfetcher creates a goroutine to prefetch state items belonging to a
228229
// particular root hash.
229-
func newSubfetcher(db Database, state common.Hash, owner common.Hash, root common.Hash) *subfetcher {
230+
func newSubfetcher(db Database, state common.Hash, owner common.Hash, root common.Hash, addr common.Address) *subfetcher {
230231
sf := &subfetcher{
231232
db: db,
232233
state: state,
233234
owner: owner,
234235
root: root,
236+
addr: addr,
235237
wake: make(chan struct{}, 1),
236238
stop: make(chan struct{}),
237239
term: make(chan struct{}),
@@ -336,7 +338,11 @@ func (sf *subfetcher) loop() {
336338
if _, ok := sf.seen[string(task)]; ok {
337339
sf.dups++
338340
} else {
339-
sf.trie.TryGet(task)
341+
if len(task) == common.AddressLength {
342+
sf.trie.TryGetAccount(common.BytesToAddress(task))
343+
} else {
344+
sf.trie.TryGetStorage(sf.addr, task)
345+
}
340346
sf.seen[string(task)] = struct{}{}
341347
}
342348
}

core/state/trie_prefetcher_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ func TestCopyAndClose(t *testing.T) {
4747
db := filledStateDB()
4848
prefetcher := newTriePrefetcher(db.db, db.originalRoot, "")
4949
skey := common.HexToHash("aaa")
50-
prefetcher.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
51-
prefetcher.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
50+
prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
51+
prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
5252
time.Sleep(1 * time.Second)
5353
a := prefetcher.trie(common.Hash{}, db.originalRoot)
54-
prefetcher.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
54+
prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
5555
b := prefetcher.trie(common.Hash{}, db.originalRoot)
5656
cpy := prefetcher.copy()
57-
cpy.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
58-
cpy.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
57+
cpy.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
58+
cpy.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
5959
c := cpy.trie(common.Hash{}, db.originalRoot)
6060
prefetcher.close()
6161
cpy2 := cpy.copy()
62-
cpy2.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
62+
cpy2.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
6363
d := cpy2.trie(common.Hash{}, db.originalRoot)
6464
cpy.close()
6565
cpy2.close()
@@ -72,7 +72,7 @@ func TestUseAfterClose(t *testing.T) {
7272
db := filledStateDB()
7373
prefetcher := newTriePrefetcher(db.db, db.originalRoot, "")
7474
skey := common.HexToHash("aaa")
75-
prefetcher.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
75+
prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
7676
a := prefetcher.trie(common.Hash{}, db.originalRoot)
7777
prefetcher.close()
7878
b := prefetcher.trie(common.Hash{}, db.originalRoot)
@@ -88,7 +88,7 @@ func TestCopyClose(t *testing.T) {
8888
db := filledStateDB()
8989
prefetcher := newTriePrefetcher(db.db, db.originalRoot, "")
9090
skey := common.HexToHash("aaa")
91-
prefetcher.prefetch(common.Hash{}, db.originalRoot, [][]byte{skey.Bytes()})
91+
prefetcher.prefetch(common.Hash{}, db.originalRoot, common.Address{}, [][]byte{skey.Bytes()})
9292
cpy := prefetcher.copy()
9393
a := prefetcher.trie(common.Hash{}, db.originalRoot)
9494
b := cpy.trie(common.Hash{}, db.originalRoot)

eth/api_backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (b *EthAPIBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
327327
return b.gpo.SuggestTipCap(ctx)
328328
}
329329

330-
func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
330+
func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
331331
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
332332
}
333333

eth/gasprice/feehistory.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (oracle *Oracle) processBlock(bf *blockFees, percentiles []float64) {
142142
// also returned if requested and available.
143143
// Note: an error is only returned if retrieving the head header has failed. If there are no
144144
// retrievable blocks in the specified range then zero block count is returned with no error.
145-
func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNumber, blocks int) (*types.Block, []*types.Receipt, uint64, int, error) {
145+
func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNumber, blocks uint64) (*types.Block, []*types.Receipt, uint64, uint64, error) {
146146
var (
147147
headBlock *types.Header
148148
pendingBlock *types.Block
@@ -200,8 +200,8 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNum
200200
return nil, nil, 0, 0, nil
201201
}
202202
// Ensure not trying to retrieve before genesis.
203-
if int(reqEnd+1) < blocks {
204-
blocks = int(reqEnd + 1)
203+
if uint64(reqEnd+1) < blocks {
204+
blocks = uint64(reqEnd + 1)
205205
}
206206
return pendingBlock, pendingReceipts, uint64(reqEnd), blocks, nil
207207
}
@@ -220,7 +220,7 @@ func (oracle *Oracle) resolveBlockRange(ctx context.Context, reqEnd rpc.BlockNum
220220
//
221221
// Note: baseFee includes the next block after the newest of the returned range, because this
222222
// value can be derived from the newest block.
223-
func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
223+
func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
224224
if blocks < 1 {
225225
return common.Big0, nil, nil, nil, nil // returning with no data and no error means there are no retrievable blocks
226226
}
@@ -249,7 +249,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
249249
if err != nil || blocks == 0 {
250250
return common.Big0, nil, nil, nil, err
251251
}
252-
oldestBlock := lastBlock + 1 - uint64(blocks)
252+
oldestBlock := lastBlock + 1 - blocks
253253

254254
var (
255255
next = oldestBlock
@@ -259,7 +259,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
259259
for i, p := range rewardPercentiles {
260260
binary.LittleEndian.PutUint64(percentileKey[i*8:(i+1)*8], math.Float64bits(p))
261261
}
262-
for i := 0; i < maxBlockFetchers && i < blocks; i++ {
262+
for i := 0; i < maxBlockFetchers && i < int(blocks); i++ {
263263
go func() {
264264
for {
265265
// Retrieve the next block number to fetch with this goroutine
@@ -314,7 +314,7 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks int, unresolvedLast
314314
if fees.err != nil {
315315
return common.Big0, nil, nil, nil, fees.err
316316
}
317-
i := int(fees.blockNumber - oldestBlock)
317+
i := fees.blockNumber - oldestBlock
318318
if fees.results.baseFee != nil {
319319
reward[i], baseFee[i], baseFee[i+1], gasUsedRatio[i] = fees.results.reward, fees.results.baseFee, fees.results.nextBaseFee, fees.results.gasUsedRatio
320320
} else {

eth/gasprice/feehistory_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
func TestFeeHistory(t *testing.T) {
2929
var cases = []struct {
3030
pending bool
31-
maxHeader, maxBlock int
32-
count int
31+
maxHeader, maxBlock uint64
32+
count uint64
3333
last rpc.BlockNumber
3434
percent []float64
3535
expFirst uint64

0 commit comments

Comments
 (0)