-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
eth/filters, eth/tracers: add request cancellation checks #26320
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eacf53d
eth/filters, eth/tracers: add request cancellation checks
fjl 455f2f4
Update api.go
fjl 2b87faa
eth/tracers: reduce block tracing channel buffer
fjl 125954d
fix jobs chan length
s1na 54a5986
eth: add cancel checks to StateAt* methods
s1na File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -547,6 +547,9 @@ func (api *API) IntermediateRoots(ctx context.Context, hash common.Hash, config | |
deleteEmptyObjects = chainConfig.IsEIP158(block.Number()) | ||
) | ||
for i, tx := range block.Transactions() { | ||
if err := ctx.Err(); err != nil { | ||
return nil, err | ||
} | ||
var ( | ||
msg, _ = tx.AsMessage(signer, block.BaseFee()) | ||
txContext = core.NewEVMTxContext(msg) | ||
|
@@ -638,12 +641,19 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac | |
} | ||
}() | ||
} | ||
|
||
// Feed the transactions into the tracers and return | ||
var failed error | ||
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) | ||
for i, tx := range txs { | ||
// Send the trace task over for execution | ||
jobs <- &txTraceTask{statedb: statedb.Copy(), index: i} | ||
task := &txTraceTask{statedb: statedb.Copy(), index: i} | ||
select { | ||
case jobs <- task: | ||
case <-ctx.Done(): | ||
failed = ctx.Err() | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Classic mistake here, |
||
} | ||
|
||
// Generate the next state snapshot fast without tracing | ||
msg, _ := tx.AsMessage(signer, block.BaseFee()) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this more efficient than simply checking
ctx.Err()
at the beginning of the loop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not more efficient, I just did it because the send could theoretically block at this point. Canceling the context would unblock it. However, it seems the
jobs
channel is actually buffered, and so the send will always succeed.