Skip to content

Commit a9b73b4

Browse files
committed
Merge branch 'master' into astria
* master: docs: update outdated DeriveSha docs comment (ethereum#26968) internal/debug: add log.logfmt flag to set logging to use logfmt (ethereum#26970) eth/tracers/native: prevent panic for LOG edge-cases (ethereum#26848) graphql: fix data races (ethereum#26965) core/state: use atomic.Bool (ethereum#26992) core/bloombits: use atomic type (ethereum#26993) core/vm: use atomic.Bool (ethereum#26951) metrics/librato: ensure resp.body closed (ethereum#26969) core/state, trie: remove Try prefix in Trie accessors (ethereum#26975) ethclient: ensure returned subscription is nil on error (ethereum#26976)
2 parents 97a0ee2 + 7ca4f60 commit a9b73b4

File tree

33 files changed

+522
-347
lines changed

33 files changed

+522
-347
lines changed

core/bloombits/matcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type Matcher struct {
8383
retrievals chan chan *Retrieval // Retriever processes waiting for task allocations
8484
deliveries chan *Retrieval // Retriever processes waiting for task response deliveries
8585

86-
running uint32 // Atomic flag whether a session is live or not
86+
running atomic.Bool // Atomic flag whether a session is live or not
8787
}
8888

8989
// NewMatcher creates a new pipeline for retrieving bloom bit streams and doing
@@ -146,10 +146,10 @@ func (m *Matcher) addScheduler(idx uint) {
146146
// channel is closed.
147147
func (m *Matcher) Start(ctx context.Context, begin, end uint64, results chan uint64) (*MatcherSession, error) {
148148
// Make sure we're not creating concurrent sessions
149-
if atomic.SwapUint32(&m.running, 1) == 1 {
149+
if m.running.Swap(true) {
150150
return nil, errors.New("matcher already running")
151151
}
152-
defer atomic.StoreUint32(&m.running, 0)
152+
defer m.running.Store(false)
153153

154154
// Initiate a new matching round
155155
session := &MatcherSession{

core/bloombits/matcher_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func testMatcher(t *testing.T, filter [][]bloomIndexes, start, blocks uint64, in
160160
}
161161
}
162162
// Track the number of retrieval requests made
163-
var requested uint32
163+
var requested atomic.Uint32
164164

165165
// Start the matching session for the filter and the retriever goroutines
166166
quit := make(chan struct{})
@@ -208,15 +208,15 @@ func testMatcher(t *testing.T, filter [][]bloomIndexes, start, blocks uint64, in
208208
session.Close()
209209
close(quit)
210210

211-
if retrievals != 0 && requested != retrievals {
212-
t.Errorf("filter = %v blocks = %v intermittent = %v: request count mismatch, have #%v, want #%v", filter, blocks, intermittent, requested, retrievals)
211+
if retrievals != 0 && requested.Load() != retrievals {
212+
t.Errorf("filter = %v blocks = %v intermittent = %v: request count mismatch, have #%v, want #%v", filter, blocks, intermittent, requested.Load(), retrievals)
213213
}
214-
return requested
214+
return requested.Load()
215215
}
216216

217217
// startRetrievers starts a batch of goroutines listening for section requests
218218
// and serving them.
219-
func startRetrievers(session *MatcherSession, quit chan struct{}, retrievals *uint32, batch int) {
219+
func startRetrievers(session *MatcherSession, quit chan struct{}, retrievals *atomic.Uint32, batch int) {
220220
requests := make(chan chan *Retrieval)
221221

222222
for i := 0; i < 10; i++ {
@@ -238,7 +238,7 @@ func startRetrievers(session *MatcherSession, quit chan struct{}, retrievals *ui
238238
for i, section := range task.Sections {
239239
if rand.Int()%4 != 0 { // Handle occasional missing deliveries
240240
task.Bitsets[i] = generateBitset(task.Bit, section)
241-
atomic.AddUint32(retrievals, 1)
241+
retrievals.Add(1)
242242
}
243243
}
244244
request <- task

core/bloombits/scheduler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func testScheduler(t *testing.T, clients int, fetchers int, requests int) {
4545
fetch := make(chan *request, 16)
4646
defer close(fetch)
4747

48-
var delivered uint32
48+
var delivered atomic.Uint32
4949
for i := 0; i < fetchers; i++ {
5050
go func() {
5151
defer fetchPend.Done()
5252

5353
for req := range fetch {
54-
atomic.AddUint32(&delivered, 1)
54+
delivered.Add(1)
5555

5656
f.deliver([]uint64{
5757
req.section + uint64(requests), // Non-requested data (ensure it doesn't go out of bounds)
@@ -97,7 +97,7 @@ func testScheduler(t *testing.T, clients int, fetchers int, requests int) {
9797
}
9898
pend.Wait()
9999

100-
if have := atomic.LoadUint32(&delivered); int(have) != requests {
100+
if have := delivered.Load(); int(have) != requests {
101101
t.Errorf("request count mismatch: have %v, want %v", have, requests)
102102
}
103103
}

core/state/database.go

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

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

76-
// TryGetAccount abstracts an account read from the trie. It retrieves the
76+
// GetAccount abstracts an account read from the trie. It retrieves the
7777
// account blob from the trie with provided account address and decodes it
7878
// with associated decoding algorithm. If the specified account is not in
7979
// the trie, nil will be returned. If the trie is corrupted(e.g. some nodes
8080
// are missing or the account blob is incorrect for decoding), an error will
8181
// be returned.
82-
TryGetAccount(address common.Address) (*types.StateAccount, error)
82+
GetAccount(address common.Address) (*types.StateAccount, error)
8383

84-
// TryUpdateStorage associates key with value in the trie. If value has length zero,
84+
// UpdateStorage associates key with value in the trie. If value has length zero,
8585
// 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-
TryUpdateStorage(addr common.Address, key, value []byte) error
88+
UpdateStorage(addr common.Address, key, value []byte) error
8989

90-
// TryUpdateAccount abstracts an account write to the trie. It encodes the
90+
// UpdateAccount 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.
93-
TryUpdateAccount(address common.Address, account *types.StateAccount) error
93+
UpdateAccount(address common.Address, account *types.StateAccount) error
9494

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

99-
// TryDeleteAccount abstracts an account deletion from the trie.
100-
TryDeleteAccount(address common.Address) error
99+
// DeleteAccount abstracts an account deletion from the trie.
100+
DeleteAccount(address common.Address) error
101101

102102
// Hash returns the root hash of the trie. It does not write to the database and
103103
// can be used even if the trie doesn't have one.

core/state/snapshot/difflayer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type diffLayer struct {
103103
memory uint64 // Approximate guess as to how much memory we use
104104

105105
root common.Hash // Root hash to which this snapshot diff belongs to
106-
stale uint32 // Signals that the layer became stale (state progressed)
106+
stale atomic.Bool // Signals that the layer became stale (state progressed)
107107

108108
// destructSet is a very special helper marker. If an account is marked as
109109
// deleted, then it's recorded in this set. However it's allowed that an account
@@ -267,7 +267,7 @@ func (dl *diffLayer) Parent() snapshot {
267267
// Stale return whether this layer has become stale (was flattened across) or if
268268
// it's still live.
269269
func (dl *diffLayer) Stale() bool {
270-
return atomic.LoadUint32(&dl.stale) != 0
270+
return dl.stale.Load()
271271
}
272272

273273
// Account directly retrieves the account associated with a particular hash in
@@ -449,7 +449,7 @@ func (dl *diffLayer) flatten() snapshot {
449449

450450
// Before actually writing all our data to the parent, first ensure that the
451451
// parent hasn't been 'corrupted' by someone else already flattening into it
452-
if atomic.SwapUint32(&parent.stale, 1) != 0 {
452+
if parent.stale.Swap(true) {
453453
panic("parent diff layer is stale") // we've flattened into the same parent from two children, boo
454454
}
455455
// Overwrite all the updated accounts blindly, merge the sorted list

core/state/snapshot/snapshot.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"sync"
25-
"sync/atomic"
2625

2726
"github.com/ethereum/go-ethereum/common"
2827
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -272,7 +271,7 @@ func (t *Tree) Disable() {
272271
case *diffLayer:
273272
// If the layer is a simple diff, simply mark as stale
274273
layer.lock.Lock()
275-
atomic.StoreUint32(&layer.stale, 1)
274+
layer.stale.Store(true)
276275
layer.lock.Unlock()
277276

278277
default:
@@ -726,7 +725,7 @@ func (t *Tree) Rebuild(root common.Hash) {
726725
case *diffLayer:
727726
// If the layer is a simple diff, simply mark as stale
728727
layer.lock.Lock()
729-
atomic.StoreUint32(&layer.stale, 1)
728+
layer.stale.Store(true)
730729
layer.lock.Unlock()
731730

732731
default:

core/state/state_object.go

Lines changed: 3 additions & 3 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.TryGetStorage(s.address, key.Bytes())
204+
enc, err = tr.GetStorage(s.address, key.Bytes())
205205
if metrics.EnabledExpensive {
206206
s.db.StorageReads += time.Since(start)
207207
}
@@ -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.TryDeleteStorage(s.address, key[:]); err != nil {
297+
if err := tr.DeleteStorage(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.TryUpdateStorage(s.address, key[:], v); err != nil {
305+
if err := tr.UpdateStorage(s.address, key[:], v); err != nil {
306306
s.db.setError(err)
307307
return nil, err
308308
}

core/state/statedb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
512512
}
513513
// Encode the account and update the account trie
514514
addr := obj.Address()
515-
if err := s.trie.TryUpdateAccount(addr, &obj.data); err != nil {
515+
if err := s.trie.UpdateAccount(addr, &obj.data); err != nil {
516516
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err))
517517
}
518518

@@ -533,7 +533,7 @@ func (s *StateDB) deleteStateObject(obj *stateObject) {
533533
}
534534
// Delete the account from the trie
535535
addr := obj.Address()
536-
if err := s.trie.TryDeleteAccount(addr); err != nil {
536+
if err := s.trie.DeleteAccount(addr); err != nil {
537537
s.setError(fmt.Errorf("deleteStateObject (%x) error: %v", addr[:], err))
538538
}
539539
}
@@ -587,7 +587,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
587587
if data == nil {
588588
start := time.Now()
589589
var err error
590-
data, err = s.trie.TryGetAccount(addr)
590+
data, err = s.trie.GetAccount(addr)
591591
if metrics.EnabledExpensive {
592592
s.AccountReads += time.Since(start)
593593
}

core/state/trie_prefetcher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ func (sf *subfetcher) loop() {
339339
sf.dups++
340340
} else {
341341
if len(task) == common.AddressLength {
342-
sf.trie.TryGetAccount(common.BytesToAddress(task))
342+
sf.trie.GetAccount(common.BytesToAddress(task))
343343
} else {
344-
sf.trie.TryGetStorage(sf.addr, task)
344+
sf.trie.GetStorage(sf.addr, task)
345345
}
346346
sf.seen[string(task)] = struct{}{}
347347
}

core/types/hashing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func encodeForDerive(list DerivableList, i int, buf *bytes.Buffer) []byte {
8383
return common.CopyBytes(buf.Bytes())
8484
}
8585

86-
// DeriveSha creates the tree hashes of transactions and receipts in a block header.
86+
// DeriveSha creates the tree hashes of transactions, receipts, and withdrawals in a block header.
8787
func DeriveSha(list DerivableList, hasher TrieHasher) common.Hash {
8888
hasher.Reset()
8989

0 commit comments

Comments
 (0)