Skip to content

Commit

Permalink
Merge pull request #284 from hkalina/debug-api-fix
Browse files Browse the repository at this point in the history
Fix concurrent access to blockCtx in debug_traceBlock
  • Loading branch information
uprendis committed Apr 11, 2022
2 parents 91623cf + 14064f0 commit a8e1398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit a8e1398

Please sign in to comment.