Skip to content

Commit

Permalink
Merge branch 'ethereum:master' into portal
Browse files Browse the repository at this point in the history
  • Loading branch information
GrapeBaBa authored Apr 3, 2024
2 parents a66e1aa + dfb3d46 commit bc7987b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 42 deletions.
13 changes: 11 additions & 2 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,17 @@ func runCmd(ctx *cli.Context) error {
output, leftOverGas, stats, err := timedExec(bench, execFunc)

if ctx.Bool(DumpFlag.Name) {
statedb.Commit(genesisConfig.Number, true)
fmt.Println(string(statedb.Dump(nil)))
root, err := statedb.Commit(genesisConfig.Number, true)
if err != nil {
fmt.Printf("Failed to commit changes %v\n", err)
return err
}
dumpdb, err := state.New(root, sdb, nil)
if err != nil {
fmt.Printf("Failed to open statedb %v\n", err)
return err
}
fmt.Println(string(dumpdb.Dump(nil)))
}

if ctx.Bool(DebugFlag.Name) {
Expand Down
4 changes: 1 addition & 3 deletions common/lru/basiclru.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ func (c *BasicLRU[K, V]) Peek(key K) (value V, ok bool) {
// Purge empties the cache.
func (c *BasicLRU[K, V]) Purge() {
c.list.init()
for k := range c.items {
delete(c.items, k)
}
clear(c.items)
}

// Remove drops an item from the cache. Returns true if the key was present in cache.
Expand Down
12 changes: 4 additions & 8 deletions core/state/access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package state

import (
"maps"

"github.com/ethereum/go-ethereum/common"
)

Expand Down Expand Up @@ -57,16 +59,10 @@ func newAccessList() *accessList {
// Copy creates an independent copy of an accessList.
func (a *accessList) Copy() *accessList {
cp := newAccessList()
for k, v := range a.addresses {
cp.addresses[k] = v
}
cp.addresses = maps.Clone(a.addresses)
cp.slots = make([]map[common.Hash]struct{}, len(a.slots))
for i, slotMap := range a.slots {
newSlotmap := make(map[common.Hash]struct{}, len(slotMap))
for k := range slotMap {
newSlotmap[k] = struct{}{}
}
cp.slots[i] = newSlotmap
cp.slots[i] = maps.Clone(slotMap)
}
return cp
}
Expand Down
7 changes: 2 additions & 5 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io"
"maps"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -47,11 +48,7 @@ func (s Storage) String() (str string) {
}

func (s Storage) Copy() Storage {
cpy := make(Storage, len(s))
for key, value := range s {
cpy[key] = value
}
return cpy
return maps.Clone(s)
}

// stateObject represents an Ethereum account which is being modified.
Expand Down
10 changes: 4 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package state

import (
"fmt"
"maps"
"math/big"
"slices"
"sort"
Expand Down Expand Up @@ -750,9 +751,8 @@ func (s *StateDB) Copy() *StateDB {
state.stateObjectsDirty[addr] = struct{}{}
}
// Deep copy the destruction markers.
for addr, value := range s.stateObjectsDestruct {
state.stateObjectsDestruct[addr] = value
}
state.stateObjectsDestruct = maps.Clone(s.stateObjectsDestruct)

// Deep copy the state changes made in the scope of block
// along with their original values.
state.accounts = copySet(s.accounts)
Expand All @@ -770,9 +770,7 @@ func (s *StateDB) Copy() *StateDB {
state.logs[hash] = cpy
}
// Deep copy the preimages occurred in the scope of block
for hash, preimage := range s.preimages {
state.preimages[hash] = preimage
}
state.preimages = maps.Clone(s.preimages)
// Do we need to copy the access list and transient storage?
// In practice: No. At the start of a transaction, these two lists are empty.
// In practice, we only ever copy state _between_ transactions/blocks, never
Expand Down
25 changes: 8 additions & 17 deletions eth/fetcher/tx_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"math/big"
"math/rand"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -1823,12 +1824,12 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
continue
}
for _, hash := range hashes {
if !containsHash(request.hashes, hash) {
if !slices.Contains(request.hashes, hash) {
t.Errorf("step %d, peer %s: hash %x missing from requests", i, peer, hash)
}
}
for _, hash := range request.hashes {
if !containsHash(hashes, hash) {
if !slices.Contains(hashes, hash) {
t.Errorf("step %d, peer %s: hash %x extra in requests", i, peer, hash)
}
}
Expand All @@ -1850,7 +1851,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
for hash := range fetcher.fetching {
var found bool
for _, req := range fetcher.requests {
if containsHash(req.hashes, hash) {
if slices.Contains(req.hashes, hash) {
found = true
break
}
Expand Down Expand Up @@ -1891,12 +1892,12 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
continue
}
for _, hash := range hashes {
if !containsHash(request.hashes, hash) {
if !slices.Contains(request.hashes, hash) {
t.Errorf("step %d, peer %s: hash %x missing from requests", i, peer, hash)
}
}
for _, hash := range request.hashes {
if !containsHash(hashes, hash) {
if !slices.Contains(hashes, hash) {
t.Errorf("step %d, peer %s: hash %x extra in requests", i, peer, hash)
}
}
Expand All @@ -1909,7 +1910,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
for _, ann := range announces {
var found bool
for _, hs := range step.fetching {
if containsHash(hs, ann.hash) {
if slices.Contains(hs, ann.hash) {
found = true
break
}
Expand All @@ -1925,7 +1926,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
}
}
for hash := range fetcher.announced {
if !containsHash(queued, hash) {
if !slices.Contains(queued, hash) {
t.Errorf("step %d: hash %x extra in announced", i, hash)
}
}
Expand Down Expand Up @@ -1984,16 +1985,6 @@ func containsHashInAnnounces(slice []announce, hash common.Hash) bool {
return false
}

// containsHash returns whether a hash is contained within a hash slice.
func containsHash(slice []common.Hash, hash common.Hash) bool {
for _, have := range slice {
if have == hash {
return true
}
}
return false
}

// Tests that a transaction is forgotten after the timeout.
func TestTransactionForgotten(t *testing.T) {
fetcher := NewTxFetcher(
Expand Down
6 changes: 5 additions & 1 deletion p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const (
)

var (
activePeerGauge metrics.Gauge = metrics.NilGauge{}
activePeerGauge metrics.Gauge = metrics.NilGauge{}
activeInboundPeerGauge metrics.Gauge = metrics.NilGauge{}
activeOutboundPeerGauge metrics.Gauge = metrics.NilGauge{}

ingressTrafficMeter = metrics.NewRegisteredMeter("p2p/ingress", nil)
egressTrafficMeter = metrics.NewRegisteredMeter("p2p/egress", nil)
Expand Down Expand Up @@ -65,6 +67,8 @@ func init() {
}

activePeerGauge = metrics.NewRegisteredGauge("p2p/peers", nil)
activeInboundPeerGauge = metrics.NewRegisteredGauge("p2p/peers/inbound", nil)
activeOutboundPeerGauge = metrics.NewRegisteredGauge("p2p/peers/outbound", nil)
serveMeter = metrics.NewRegisteredMeter("p2p/serves", nil)
serveSuccessMeter = metrics.NewRegisteredMeter("p2p/serves/success", nil)
dialMeter = metrics.NewRegisteredMeter("p2p/dials", nil)
Expand Down
5 changes: 5 additions & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,10 @@ running:
if p.Inbound() {
inboundCount++
serveSuccessMeter.Mark(1)
activeInboundPeerGauge.Inc(1)
} else {
dialSuccessMeter.Mark(1)
activeOutboundPeerGauge.Inc(1)
}
activePeerGauge.Inc(1)
}
Expand All @@ -786,6 +788,9 @@ running:
srv.dialsched.peerRemoved(pd.rw)
if pd.Inbound() {
inboundCount--
activeInboundPeerGauge.Dec(1)
} else {
activeOutboundPeerGauge.Dec(1)
}
activePeerGauge.Dec(1)
}
Expand Down

0 comments on commit bc7987b

Please sign in to comment.