Merge branch 'ethereum:master' into portal

This commit is contained in:
Chen Kai 2024-03-29 10:09:47 +08:00 committed by GitHub
commit 766d2d8ece
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 26 additions and 46 deletions

View file

@ -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) {

View file

@ -20,6 +20,7 @@ package state
import (
"fmt"
"math/big"
"slices"
"sort"
"time"
@ -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)
}
}

View file

@ -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
}
@ -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
}

View file

@ -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"
@ -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
}

View file

@ -19,7 +19,6 @@ package dbtest
import (
"bytes"
"crypto/rand"
"reflect"
"slices"
"sort"
"testing"
@ -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)
}
}
@ -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)
}
}
@ -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)
}
}
@ -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)
}
}
@ -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)
}
}
@ -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)
}
}
@ -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)
}
}
@ -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)
}
})

View file

@ -20,6 +20,7 @@ import (
"context"
"crypto/ecdsa"
"errors"
"maps"
"reflect"
"testing"
"time"
@ -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) {