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 Mar 29, 2024
2 parents d58d3ff + a382917 commit 766d2d8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 46 deletions.
11 changes: 0 additions & 11 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,17 +1552,6 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
return nil
}

// WriteBlockAndSetHead writes the given block and all associated state to the database,
// and applies the block as the new chain head.
func (bc *BlockChain) WriteBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
if !bc.chainmu.TryLock() {
return NonStatTy, errChainStopped
}
defer bc.chainmu.Unlock()

return bc.writeBlockAndSetHead(block, receipts, logs, state, emitHeadEvent)
}

// writeBlockAndSetHead is the internal implementation of WriteBlockAndSetHead.
// This function expects the chain mutex to be held.
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
Expand Down
5 changes: 2 additions & 3 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package state
import (
"fmt"
"math/big"
"slices"
"sort"
"time"

Expand Down Expand Up @@ -243,9 +244,7 @@ func (s *StateDB) Logs() []*types.Log {
func (s *StateDB) AddPreimage(hash common.Hash, preimage []byte) {
if _, ok := s.preimages[hash]; !ok {
s.journal.append(addPreimageChange{hash: hash})
pi := make([]byte, len(preimage))
copy(pi, preimage)
s.preimages[hash] = pi
s.preimages[hash] = slices.Clone(preimage)
}
}

Expand Down
22 changes: 11 additions & 11 deletions eth/tracers/js/goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,11 @@ func (mo *memoryObj) Length() int {
return len(mo.memory)
}

func (m *memoryObj) setupObject() *goja.Object {
o := m.vm.NewObject()
o.Set("slice", m.vm.ToValue(m.Slice))
o.Set("getUint", m.vm.ToValue(m.GetUint))
o.Set("length", m.vm.ToValue(m.Length))
func (mo *memoryObj) setupObject() *goja.Object {
o := mo.vm.NewObject()
o.Set("slice", mo.vm.ToValue(mo.Slice))
o.Set("getUint", mo.vm.ToValue(mo.GetUint))
o.Set("length", mo.vm.ToValue(mo.Length))
return o
}

Expand Down Expand Up @@ -863,12 +863,12 @@ func (co *contractObj) GetInput() goja.Value {
return res
}

func (c *contractObj) setupObject() *goja.Object {
o := c.vm.NewObject()
o.Set("getCaller", c.vm.ToValue(c.GetCaller))
o.Set("getAddress", c.vm.ToValue(c.GetAddress))
o.Set("getValue", c.vm.ToValue(c.GetValue))
o.Set("getInput", c.vm.ToValue(c.GetInput))
func (co *contractObj) setupObject() *goja.Object {
o := co.vm.NewObject()
o.Set("getCaller", co.vm.ToValue(co.GetCaller))
o.Set("getAddress", co.vm.ToValue(co.GetAddress))
o.Set("getValue", co.vm.ToValue(co.GetValue))
o.Set("getInput", co.vm.ToValue(co.GetInput))
return o
}

Expand Down
12 changes: 3 additions & 9 deletions eth/tracers/logger/access_list_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package logger

import (
"maps"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -71,17 +73,9 @@ func (al accessList) equal(other accessList) bool {
// Accounts match, cross reference the storage slots too
for addr, slots := range al {
otherslots := other[addr]

if len(slots) != len(otherslots) {
if !maps.Equal(slots, otherslots) {
return false
}
// Given that len(slots) == len(otherslots), we only need to check that
// all the items from slots are in otherslots.
for hash := range slots {
if _, ok := otherslots[hash]; !ok {
return false
}
}
}
return true
}
Expand Down
17 changes: 8 additions & 9 deletions ethdb/dbtest/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package dbtest
import (
"bytes"
"crypto/rand"
"reflect"
"slices"
"sort"
"testing"
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
if err := it.Error(); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Errorf("Iterator: got: %s; want: %s", got, want)
}
}
Expand All @@ -160,7 +159,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
if err := it.Error(); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Errorf("IteratorWith(1,nil): got: %s; want: %s", got, want)
}
}
Expand All @@ -171,7 +170,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
if err := it.Error(); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Errorf("IteratorWith(5,nil): got: %s; want: %s", got, want)
}
}
Expand All @@ -182,7 +181,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
if err := it.Error(); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Errorf("IteratorWith(nil,2): got: %s; want: %s", got, want)
}
}
Expand All @@ -193,7 +192,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
if err := it.Error(); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Errorf("IteratorWith(nil,5): got: %s; want: %s", got, want)
}
}
Expand Down Expand Up @@ -262,7 +261,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {

{
it := db.NewIterator(nil, nil)
if got, want := iterateKeys(it), []string{"1", "2", "3", "4"}; !reflect.DeepEqual(got, want) {
if got, want := iterateKeys(it), []string{"1", "2", "3", "4"}; !slices.Equal(got, want) {
t.Errorf("got: %s; want: %s", got, want)
}
}
Expand All @@ -286,7 +285,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {

{
it := db.NewIterator(nil, nil)
if got, want := iterateKeys(it), []string{"2", "3", "4", "5", "6"}; !reflect.DeepEqual(got, want) {
if got, want := iterateKeys(it), []string{"2", "3", "4", "5", "6"}; !slices.Equal(got, want) {
t.Errorf("got: %s; want: %s", got, want)
}
}
Expand Down Expand Up @@ -314,7 +313,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
}

it := db.NewIterator(nil, nil)
if got := iterateKeys(it); !reflect.DeepEqual(got, want) {
if got := iterateKeys(it); !slices.Equal(got, want) {
t.Errorf("got: %s; want: %s", got, want)
}
})
Expand Down
5 changes: 2 additions & 3 deletions p2p/dnsdisc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/ecdsa"
"errors"
"maps"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -453,9 +454,7 @@ func (mr mapResolver) clear() {
}

func (mr mapResolver) add(m map[string]string) {
for k, v := range m {
mr[k] = v
}
maps.Copy(mr, m)
}

func (mr mapResolver) LookupTXT(ctx context.Context, name string) ([]string, error) {
Expand Down

0 comments on commit 766d2d8

Please sign in to comment.