refactor(tracing): refactor wrappedProof (#536)

This commit is contained in:
HAOYUatHZ 2023-10-18 00:31:29 +08:00 committed by GitHub
parent 9a0a87f4ca
commit fcb3e1768d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -138,11 +138,7 @@ func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext ChainContext,
log.Error("Proof for coinbase not available", "coinbase", coinbase, "error", err) log.Error("Proof for coinbase not available", "coinbase", coinbase, "error", err)
// but we still mark the proofs map with nil array // but we still mark the proofs map with nil array
} }
wrappedProof := make([]hexutil.Bytes, len(proof)) env.Proofs[key] = types.WrapProof(proof)
for i, bt := range proof {
wrappedProof[i] = bt
}
env.Proofs[key] = wrappedProof
} }
return env, nil return env, nil
@ -347,10 +343,7 @@ func (env *TraceEnv) getTxResult(state *state.StateDB, index int, block *types.B
log.Error("Proof not available", "address", addrStr, "error", err) log.Error("Proof not available", "address", addrStr, "error", err)
// but we still mark the proofs map with nil array // but we still mark the proofs map with nil array
} }
wrappedProof := make([]hexutil.Bytes, len(proof)) wrappedProof := types.WrapProof(proof)
for i, bt := range proof {
wrappedProof[i] = bt
}
env.pMu.Lock() env.pMu.Lock()
env.Proofs[addrStr] = wrappedProof env.Proofs[addrStr] = wrappedProof
txStorageTrace.Proofs[addrStr] = wrappedProof txStorageTrace.Proofs[addrStr] = wrappedProof
@ -412,10 +405,7 @@ func (env *TraceEnv) getTxResult(state *state.StateDB, index int, block *types.B
log.Error("Storage proof not available", "error", err, "address", addrStr, "key", keyStr) log.Error("Storage proof not available", "error", err, "address", addrStr, "key", keyStr)
// but we still mark the proofs map with nil array // but we still mark the proofs map with nil array
} }
wrappedProof := make([]hexutil.Bytes, len(proof)) wrappedProof := types.WrapProof(proof)
for i, bt := range proof {
wrappedProof[i] = bt
}
env.sMu.Lock() env.sMu.Lock()
txm[keyStr] = wrappedProof txm[keyStr] = wrappedProof
m[keyStr] = wrappedProof m[keyStr] = wrappedProof
@ -468,11 +458,7 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro
if proof, err := statedb.GetProof(addr); err != nil { if proof, err := statedb.GetProof(addr); err != nil {
log.Error("Proof for intrinstic address not available", "error", err, "address", addr) log.Error("Proof for intrinstic address not available", "error", err, "address", addr)
} else { } else {
wrappedProof := make([]hexutil.Bytes, len(proof)) env.Proofs[addr.String()] = types.WrapProof(proof)
for i, bt := range proof {
wrappedProof[i] = bt
}
env.Proofs[addr.String()] = wrappedProof
} }
} }
@ -487,11 +473,7 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro
} else if proof, _ := statedb.GetSecureTrieProof(trie, slot); err != nil { } else if proof, _ := statedb.GetSecureTrieProof(trie, slot); err != nil {
log.Error("Get storage proof for intrinstic address failed", "error", err, "address", addr, "slot", slot) log.Error("Get storage proof for intrinstic address failed", "error", err, "address", addr, "slot", slot)
} else { } else {
wrappedProof := make([]hexutil.Bytes, len(proof)) env.StorageProofs[addr.String()][slot.String()] = types.WrapProof(proof)
for i, bt := range proof {
wrappedProof[i] = bt
}
env.StorageProofs[addr.String()][slot.String()] = wrappedProof
} }
} }
} }