-
Notifications
You must be signed in to change notification settings - Fork 130
[MINOR] Eliminate redundant header validation #943
[MINOR] Eliminate redundant header validation #943
Conversation
75bf8a5
to
84553d9
Compare
6f4d2ea
to
e269709
Compare
e269709
to
d6ed372
Compare
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.
Looks pretty good - this would work, just a few suggestions for clean up to make it a bit easier to read things.
|
||
// Import block | ||
final PersistBlockTask<C> importTask = | ||
PersistBlockTask.create( | ||
protocolSchedule, protocolContext, block, HeaderValidationMode.FULL, metricsSystem); | ||
protocolSchedule, protocolContext, block, HeaderValidationMode.NONE, metricsSystem); |
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.
Can we create this inside the if(validate) block so it's only created if it will actually be used? Mostly just so that the first thing you come across isn't HeaderValidationMode.NODE
which is a bit scary. :)
importingBlocks.remove(block.getHash()); | ||
if (t != null) { | ||
.scheduleSyncWorkerTask( | ||
() -> { |
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.
There's probably a few methods that should be extracted here to make it easier to read. I'd probably have the whole of this worker task as a private method (maybe validateAndProcessPendingBlock
?)
ethContext | ||
.getScheduler() | ||
.scheduleSyncWorkerTask(() -> broadcastBlock(block, parent)); | ||
return ethContext |
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.
I'd be tempted to extract this blob that does the actual import into a separate method as well.
.scheduleSyncWorkerTask(() -> broadcastBlock(block, parent)); | ||
return ethContext | ||
.getScheduler() | ||
.scheduleSyncWorkerTask(importTask::run) |
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.
We're already in a worker thread so can remove scheduleSyncWorkerTask
and just call run
directly. It still returns a CompletableFuture<Block>
so we'd still chain the whenComplete
in the same way.
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.
LGTM. Just the one suggestion to simplify things a little.
if (blockHeaderValidator.validateHeader( | ||
block.getHeader(), parent, protocolContext, HeaderValidationMode.FULL)) { | ||
ethContext.getScheduler().scheduleSyncWorkerTask(() -> broadcastBlock(block, parent)); | ||
return ethContext.getScheduler().scheduleSyncWorkerTask(() -> runImportTask(block)); |
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.
You don't need to defer this to a separate worker task since you're already in a worker thread.
return ethContext.getScheduler().scheduleSyncWorkerTask(() -> runImportTask(block)); | |
return runImportTask(block); |
.whenComplete( | ||
(r, t) -> { | ||
(result, throwable) -> { |
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.
+1 to the better naming here. :)
…nt-header-validation
PR description
wrt block propagation -- currently we're validating headers twice: once to decide if we should propagate and once when we actually import.
changes here enforce that we validate just once, then propagate and import in parallel.
Fixed Issue(s)