Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent access to blockCtx in debug_traceBlock #284

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion ethapi/api.go
Expand Up @@ -2179,12 +2179,14 @@ func (api *PublicDebugAPI) traceBlock(ctx context.Context, block *evmcore.EvmBlo
threads = len(txs)
}

blockCtx := api.b.GetBlockContext(block.Header())
blockHeader := block.Header()
blockHash := block.Hash
for th := 0; th < threads; th++ {
pend.Add(1)
go func() {
defer pend.Done()
blockCtx := api.b.GetBlockContext(blockHeader)

// Fetch and execute the next transaction trace tasks
for task := range jobs {
msg, _ := txs[task.index].AsMessage(signer, block.BaseFee)
Expand All @@ -2203,6 +2205,7 @@ func (api *PublicDebugAPI) traceBlock(ctx context.Context, block *evmcore.EvmBlo
}()
}
// Feed the transactions into the tracers and return
blockCtx := api.b.GetBlockContext(blockHeader)
var failed error
for i, tx := range txs {
// Send the trace task over for execution
Expand Down
4 changes: 2 additions & 2 deletions evmcore/evm.go
Expand Up @@ -48,7 +48,7 @@ func NewEVMBlockContext(header *EvmHeader, chain DummyChain, author *common.Addr
return vm.BlockContext{
CanTransfer: CanTransfer,
Transfer: Transfer,
GetHash: GetHashFn(*header, chain),
GetHash: GetHashFn(header, chain),
Coinbase: beneficiary,
BlockNumber: new(big.Int).Set(header.Number),
Time: new(big.Int).SetUint64(uint64(header.Time.Unix())),
Expand All @@ -67,7 +67,7 @@ func NewEVMTxContext(msg Message) vm.TxContext {
}

// GetHashFn returns a GetHashFunc which retrieves header hashes by number
func GetHashFn(ref EvmHeader, chain DummyChain) func(n uint64) common.Hash {
func GetHashFn(ref *EvmHeader, chain DummyChain) func(n uint64) common.Hash {
// Cache will initially contain [refHash.parent],
// Then fill up with [refHash.p, refHash.pp, refHash.ppp, ...]
var cache []common.Hash
Expand Down