Compare commits
10 Commits
87adf35072
...
ff0762a5e7
Author | SHA1 | Date |
---|---|---|
Martin HS | ff0762a5e7 | |
Martin Holst Swende | fc0705f566 | |
Martin Holst Swende | b34643f914 | |
Martin Holst Swende | d9785071dc | |
Martin Holst Swende | 97c174725f | |
Martin Holst Swende | d5c2af7088 | |
Martin Holst Swende | 5d3e3e30ca | |
Martin Holst Swende | c1f12cd77e | |
Martin Holst Swende | b30b331bb8 | |
Martin Holst Swende | cc0c78866e |
|
@ -42,7 +42,7 @@ func MakeTopics(query ...[]interface{}) ([][]common.Hash, error) {
|
|||
case common.Address:
|
||||
copy(topic[common.HashLength-common.AddressLength:], rule[:])
|
||||
case *big.Int:
|
||||
copy(topic[:], math.U256Bytes(new(big.Int).Set(rule)))
|
||||
copy(topic[:], math.U256Bytes(rule))
|
||||
case bool:
|
||||
if rule {
|
||||
topic[common.HashLength-1] = 1
|
||||
|
|
|
@ -149,23 +149,6 @@ func TestMakeTopics(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("does not mutate big.Int", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
want := [][]common.Hash{{common.HexToHash("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")}}
|
||||
|
||||
in := big.NewInt(-1)
|
||||
got, err := MakeTopics([]interface{}{in})
|
||||
if err != nil {
|
||||
t.Fatalf("makeTopics() error = %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("makeTopics() = %v, want %v", got, want)
|
||||
}
|
||||
if orig := big.NewInt(-1); in.Cmp(orig) != 0 {
|
||||
t.Fatalf("makeTopics() mutated an input parameter from %v to %v", orig, in)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
type args struct {
|
||||
|
|
|
@ -206,24 +206,47 @@ func New(config Config, diskdb ethdb.KeyValueStore, triedb *triedb.Database, roo
|
|||
log.Warn("Snapshot maintenance disabled (syncing)")
|
||||
return snap, nil
|
||||
}
|
||||
// Create the building waiter iff the background generation is allowed
|
||||
if !config.NoBuild && !config.AsyncBuild {
|
||||
defer snap.waitBuild()
|
||||
}
|
||||
if err != nil {
|
||||
log.Warn("Failed to load snapshot", "err", err)
|
||||
if config.NoBuild {
|
||||
return nil, err
|
||||
if !config.NoBuild {
|
||||
snap.Rebuild(root)
|
||||
return snap, nil
|
||||
}
|
||||
wait := snap.Rebuild(root)
|
||||
if !config.AsyncBuild {
|
||||
wait()
|
||||
}
|
||||
return snap, nil
|
||||
return nil, err // Bail out the error, don't rebuild automatically.
|
||||
}
|
||||
// Existing snapshot loaded, seed all the layers
|
||||
for ; head != nil; head = head.Parent() {
|
||||
for head != nil {
|
||||
snap.layers[head.Root()] = head
|
||||
head = head.Parent()
|
||||
}
|
||||
return snap, nil
|
||||
}
|
||||
|
||||
// waitBuild blocks until the snapshot finishes rebuilding. This method is meant
|
||||
// to be used by tests to ensure we're testing what we believe we are.
|
||||
func (t *Tree) waitBuild() {
|
||||
// Find the rebuild termination channel
|
||||
var done chan struct{}
|
||||
|
||||
t.lock.RLock()
|
||||
for _, layer := range t.layers {
|
||||
if layer, ok := layer.(*diskLayer); ok {
|
||||
done = layer.genPending
|
||||
break
|
||||
}
|
||||
}
|
||||
t.lock.RUnlock()
|
||||
|
||||
// Wait until the snapshot is generated
|
||||
if done != nil {
|
||||
<-done
|
||||
}
|
||||
}
|
||||
|
||||
// Disable interrupts any pending snapshot generator, deletes all the snapshot
|
||||
// layers in memory and marks snapshots disabled globally. In order to resume
|
||||
// the snapshot functionality, the caller must invoke Rebuild.
|
||||
|
@ -665,9 +688,8 @@ func (t *Tree) Journal(root common.Hash) (common.Hash, error) {
|
|||
|
||||
// Rebuild wipes all available snapshot data from the persistent database and
|
||||
// discard all caches and diff layers. Afterwards, it starts a new snapshot
|
||||
// generator with the given root hash. The returned function blocks until
|
||||
// regeneration is complete.
|
||||
func (t *Tree) Rebuild(root common.Hash) (wait func()) {
|
||||
// generator with the given root hash.
|
||||
func (t *Tree) Rebuild(root common.Hash) {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
|
@ -699,11 +721,9 @@ func (t *Tree) Rebuild(root common.Hash) (wait func()) {
|
|||
// Start generating a new snapshot from scratch on a background thread. The
|
||||
// generator will run a wiper first if there's not one running right now.
|
||||
log.Info("Rebuilding state snapshot")
|
||||
disk := generateSnapshot(t.diskdb, t.triedb, t.config.CacheSize, root)
|
||||
t.layers = map[common.Hash]snapshot{
|
||||
root: disk,
|
||||
root: generateSnapshot(t.diskdb, t.triedb, t.config.CacheSize, root),
|
||||
}
|
||||
return func() { <-disk.genPending }
|
||||
}
|
||||
|
||||
// AccountIterator creates a new account iterator for the specified root hash and
|
||||
|
|
|
@ -363,35 +363,26 @@ func (t *mdLogger) OnEnter(depth int, typ byte, from common.Address, to common.A
|
|||
if depth != 0 {
|
||||
return
|
||||
}
|
||||
if create := vm.OpCode(typ) == vm.CREATE; !create {
|
||||
fmt.Fprintf(t.out, "Pre-execution info:\n"+
|
||||
" - from: `%v`\n"+
|
||||
" - to: `%v`\n"+
|
||||
" - data: `%#x`\n"+
|
||||
" - gas: `%d`\n"+
|
||||
" - value: `%v` wei\n",
|
||||
from.String(), to.String(), input, gas, value)
|
||||
create := vm.OpCode(typ) == vm.CREATE
|
||||
if !create {
|
||||
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
|
||||
from.String(), to.String(),
|
||||
input, gas, value)
|
||||
} else {
|
||||
fmt.Fprintf(t.out, "Pre-execution info:\n"+
|
||||
" - from: `%v`\n"+
|
||||
" - create: `%v`\n"+
|
||||
" - data: `%#x`\n"+
|
||||
" - gas: `%d`\n"+
|
||||
" - value: `%v` wei\n",
|
||||
from.String(), to.String(), input, gas, value)
|
||||
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
|
||||
from.String(), to.String(),
|
||||
input, gas, value)
|
||||
}
|
||||
|
||||
fmt.Fprintf(t.out, `
|
||||
| Pc | Op | Cost | Refund | Stack |
|
||||
|-------|-------------|------|-----------|-----------|
|
||||
| Pc | Op | Cost | Stack | RStack | Refund |
|
||||
|-------|-------------|------|-----------|-----------|---------|
|
||||
`)
|
||||
}
|
||||
|
||||
func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
if depth == 0 {
|
||||
fmt.Fprintf(t.out, "\nPost-execution info:\n"+
|
||||
" - output: `%#x`\n"+
|
||||
" - consumed gas: `%d`\n"+
|
||||
" - error: `%v`\n",
|
||||
fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
|
||||
output, gasUsed, err)
|
||||
}
|
||||
}
|
||||
|
@ -399,8 +390,7 @@ func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, r
|
|||
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
|
||||
func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||
stack := scope.StackData()
|
||||
fmt.Fprintf(t.out, "| %4d | %10v | %3d |%10v |", pc, vm.OpCode(op).String(),
|
||||
cost, t.env.StateDB.GetRefund())
|
||||
fmt.Fprintf(t.out, "| %4d | %10v | %3d |", pc, vm.OpCode(op).String(), cost)
|
||||
|
||||
if !t.cfg.DisableStack {
|
||||
// format stack
|
||||
|
@ -411,6 +401,7 @@ func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.
|
|||
b := fmt.Sprintf("[%v]", strings.Join(a, ","))
|
||||
fmt.Fprintf(t.out, "%10v |", b)
|
||||
}
|
||||
fmt.Fprintf(t.out, "%10v |", t.env.StateDB.GetRefund())
|
||||
fmt.Fprintln(t.out, "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(t.out, "Error: %v\n", err)
|
||||
|
|
|
@ -71,7 +71,7 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *tracing.Hooks {
|
|||
l.hooks = &tracing.Hooks{
|
||||
OnTxStart: l.OnTxStart,
|
||||
OnSystemCallStart: l.onSystemCallStart,
|
||||
OnExit: l.OnExit,
|
||||
OnExit: l.OnEnd,
|
||||
OnOpcode: l.OnOpcode,
|
||||
OnFault: l.OnFault,
|
||||
}
|
||||
|
@ -152,6 +152,13 @@ func (l *jsonLogger) OnEnter(depth int, typ byte, from common.Address, to common
|
|||
l.encoder.Encode(frame)
|
||||
}
|
||||
|
||||
func (l *jsonLogger) OnEnd(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
if depth > 0 {
|
||||
return
|
||||
}
|
||||
l.OnExit(depth, output, gasUsed, err, false)
|
||||
}
|
||||
|
||||
func (l *jsonLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
type endLog struct {
|
||||
Output string `json:"output"`
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
|
@ -185,7 +186,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
Tracer: tracer.Hooks(),
|
||||
}
|
||||
)
|
||||
tracingStateDB := vm.StateDB(sim.state)
|
||||
var tracingStateDB = vm.StateDB(sim.state)
|
||||
if hooks := tracer.Hooks(); hooks != nil {
|
||||
tracingStateDB = state.NewHookedState(sim.state, hooks)
|
||||
}
|
||||
|
@ -288,7 +289,7 @@ func (sim *simulator) activePrecompiles(base *types.Header) vm.PrecompiledContra
|
|||
isMerge = (base.Difficulty.Sign() == 0)
|
||||
rules = sim.chainConfig.Rules(base.Number, isMerge, base.Time)
|
||||
)
|
||||
return vm.ActivePrecompiledContracts(rules)
|
||||
return maps.Clone(vm.ActivePrecompiledContracts(rules))
|
||||
}
|
||||
|
||||
// sanitizeChain checks the chain integrity. Specifically it checks that
|
||||
|
|
|
@ -676,7 +676,7 @@ func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interf
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return math.U256Bytes(new(big.Int).Set(b)), nil
|
||||
return math.U256Bytes(b), nil
|
||||
}
|
||||
return nil, fmt.Errorf("unrecognized type '%s'", encType)
|
||||
}
|
||||
|
|
|
@ -51,14 +51,16 @@ type (
|
|||
// intense than using the fullNode type.
|
||||
fullnodeEncoder struct {
|
||||
Children [17][]byte
|
||||
flags nodeFlag
|
||||
}
|
||||
|
||||
//shortNodeEncoder is a type used exclusively for encoding. Briefly instantiating
|
||||
// a shortNodeEncoder and initializing with existing slices is less memory
|
||||
// intense than using the shortNode type.
|
||||
shortNodeEncoder struct {
|
||||
Key []byte
|
||||
Val []byte
|
||||
Key []byte
|
||||
Val []byte
|
||||
flags nodeFlag
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue