Skip to content

Commit fcb3e17

Browse files
refactor(tracing): refactor wrappedProof (#536)
1 parent 9a0a87f commit fcb3e17

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

core/trace.go

+5-23
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext ChainContext,
138138
log.Error("Proof for coinbase not available", "coinbase", coinbase, "error", err)
139139
// but we still mark the proofs map with nil array
140140
}
141-
wrappedProof := make([]hexutil.Bytes, len(proof))
142-
for i, bt := range proof {
143-
wrappedProof[i] = bt
144-
}
145-
env.Proofs[key] = wrappedProof
141+
env.Proofs[key] = types.WrapProof(proof)
146142
}
147143

148144
return env, nil
@@ -347,10 +343,7 @@ func (env *TraceEnv) getTxResult(state *state.StateDB, index int, block *types.B
347343
log.Error("Proof not available", "address", addrStr, "error", err)
348344
// but we still mark the proofs map with nil array
349345
}
350-
wrappedProof := make([]hexutil.Bytes, len(proof))
351-
for i, bt := range proof {
352-
wrappedProof[i] = bt
353-
}
346+
wrappedProof := types.WrapProof(proof)
354347
env.pMu.Lock()
355348
env.Proofs[addrStr] = wrappedProof
356349
txStorageTrace.Proofs[addrStr] = wrappedProof
@@ -412,10 +405,7 @@ func (env *TraceEnv) getTxResult(state *state.StateDB, index int, block *types.B
412405
log.Error("Storage proof not available", "error", err, "address", addrStr, "key", keyStr)
413406
// but we still mark the proofs map with nil array
414407
}
415-
wrappedProof := make([]hexutil.Bytes, len(proof))
416-
for i, bt := range proof {
417-
wrappedProof[i] = bt
418-
}
408+
wrappedProof := types.WrapProof(proof)
419409
env.sMu.Lock()
420410
txm[keyStr] = wrappedProof
421411
m[keyStr] = wrappedProof
@@ -468,11 +458,7 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro
468458
if proof, err := statedb.GetProof(addr); err != nil {
469459
log.Error("Proof for intrinstic address not available", "error", err, "address", addr)
470460
} else {
471-
wrappedProof := make([]hexutil.Bytes, len(proof))
472-
for i, bt := range proof {
473-
wrappedProof[i] = bt
474-
}
475-
env.Proofs[addr.String()] = wrappedProof
461+
env.Proofs[addr.String()] = types.WrapProof(proof)
476462
}
477463
}
478464

@@ -487,11 +473,7 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro
487473
} else if proof, _ := statedb.GetSecureTrieProof(trie, slot); err != nil {
488474
log.Error("Get storage proof for intrinstic address failed", "error", err, "address", addr, "slot", slot)
489475
} else {
490-
wrappedProof := make([]hexutil.Bytes, len(proof))
491-
for i, bt := range proof {
492-
wrappedProof[i] = bt
493-
}
494-
env.StorageProofs[addr.String()][slot.String()] = wrappedProof
476+
env.StorageProofs[addr.String()][slot.String()] = types.WrapProof(proof)
495477
}
496478
}
497479
}

0 commit comments

Comments
 (0)