mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
eth: fix some review comments
This commit is contained in:
parent
09f99176d3
commit
1a4a187675
4 changed files with 27 additions and 22 deletions
|
|
@ -62,7 +62,7 @@ type TraceConfig struct {
|
|||
|
||||
// txTraceResult is the result of a single transaction trace.
|
||||
type txTraceResult struct {
|
||||
Result interface{} `json:"result,omitempty"` // Trace results procuded by the tracer
|
||||
Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer
|
||||
Error string `json:"error,omitempty"` // Trace failure produced by the tracer
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ type blockTraceTask struct {
|
|||
type blockTraceResult struct {
|
||||
Block hexutil.Uint64 `json:"block"` // Block number corresponding to this trace
|
||||
Hash common.Hash `json:"hash"` // Block hash corresponding to this trace
|
||||
Traces []*txTraceResult `json:"traces"` // Trace results procuded by the task
|
||||
Traces []*txTraceResult `json:"traces"` // Trace results produced by the task
|
||||
}
|
||||
|
||||
// txTraceTask represents a single transaction trace task when an entire block
|
||||
|
|
@ -118,6 +118,8 @@ func (db *ephemeralDatabase) Get(key []byte) ([]byte, error) {
|
|||
}
|
||||
|
||||
// Prune does a state sync into a new memory write layer and replaces the old one.
|
||||
// This allows us to discard entries that are no longer referenced from the current
|
||||
// state.
|
||||
func (db *ephemeralDatabase) Prune(root common.Hash) {
|
||||
// Pull the still relevant state data into memory
|
||||
sync := state.NewStateSync(root, db.diskdb)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@
|
|||
result: function(ctx) {
|
||||
// Save the outer calldata also
|
||||
if (ctx.input.length > 4) {
|
||||
this.store(ctx.input.slice(0, 4), ctx.input.length-4)
|
||||
this.store(slice(ctx.input, 0, 4), ctx.input.length-4)
|
||||
}
|
||||
return this.ids;
|
||||
},
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -370,6 +370,23 @@ func New(code string) (*Tracer, error) {
|
|||
ctx.PushBoolean(ok)
|
||||
return 1
|
||||
})
|
||||
tracer.vm.PushGlobalGoFunction("slice", func(ctx *duktape.Context) int {
|
||||
start, end := ctx.GetInt(-2), ctx.GetInt(-1)
|
||||
ctx.Pop2()
|
||||
|
||||
blob := popSlice(ctx)
|
||||
size := end - start
|
||||
|
||||
if start < 0 || start > end || end > len(blob) {
|
||||
// TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
|
||||
// runtime goes belly up https://github.com/golang/go/issues/15639.
|
||||
log.Warn("Tracer accessed out of bound memory", "available", len(blob), "offset", start, "size", size)
|
||||
ctx.PushFixedBuffer(0)
|
||||
return 1
|
||||
}
|
||||
copy(makeSlice(ctx.PushFixedBuffer(size), uint(size)), blob[start:end])
|
||||
return 1
|
||||
})
|
||||
// Push the JavaScript tracer as object #0 onto the JSVM stack and validate it
|
||||
if err := tracer.vm.PevalString("(" + code + ")"); err != nil {
|
||||
log.Warn("Failed to compile tracer", "err", err)
|
||||
|
|
@ -559,25 +576,11 @@ func (jst *Tracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, er
|
|||
|
||||
// GetResult calls the Javascript 'result' function and returns its value, or any accumulated error
|
||||
func (jst *Tracer) GetResult() (json.RawMessage, error) {
|
||||
// Push all the data buffers into the stack first
|
||||
keys := make([]string, 0, len(jst.ctx))
|
||||
for key := range jst.ctx {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
buffers := 0
|
||||
for _, key := range keys {
|
||||
switch val := jst.ctx[key].(type) {
|
||||
case []byte:
|
||||
ptr := jst.vm.PushFixedBuffer(len(val))
|
||||
copy(makeSlice(ptr, uint(len(val))), val[:])
|
||||
buffers++
|
||||
}
|
||||
}
|
||||
// Transform the context into a JavaScript object and inject into the state
|
||||
obj := jst.vm.PushObject()
|
||||
|
||||
for _, key := range keys {
|
||||
switch val := jst.ctx[key].(type) {
|
||||
for key, val := range jst.ctx {
|
||||
switch val := val.(type) {
|
||||
case uint64:
|
||||
jst.vm.PushUint(uint(val))
|
||||
|
||||
|
|
@ -585,8 +588,8 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {
|
|||
jst.vm.PushString(val)
|
||||
|
||||
case []byte:
|
||||
jst.vm.PushBufferObject(-(buffers + 1), len(val), len(val), duktape.BufobjArraybuffer)
|
||||
buffers--
|
||||
ptr := jst.vm.PushFixedBuffer(len(val))
|
||||
copy(makeSlice(ptr, uint(len(val))), val[:])
|
||||
|
||||
case common.Address:
|
||||
ptr := jst.vm.PushFixedBuffer(20)
|
||||
|
|
|
|||
Loading…
Reference in a new issue