Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[MINOR] Eliminate redundant header validation #943

Conversation

smatthewenglish
Copy link
Contributor

@smatthewenglish smatthewenglish commented Feb 22, 2019

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)

@smatthewenglish smatthewenglish added the work in progress Work on this pull request is ongoing label Feb 22, 2019
@smatthewenglish smatthewenglish force-pushed the eliminate-redundant-header-validation branch from 75bf8a5 to 84553d9 Compare February 25, 2019 18:04
@smatthewenglish smatthewenglish removed the work in progress Work on this pull request is ongoing label Feb 25, 2019
@smatthewenglish smatthewenglish force-pushed the eliminate-redundant-header-validation branch from 6f4d2ea to e269709 Compare February 25, 2019 21:42
@smatthewenglish smatthewenglish force-pushed the eliminate-redundant-header-validation branch from e269709 to d6ed372 Compare February 25, 2019 21:44
Copy link
Contributor

@ajsutton ajsutton left a 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);
Copy link
Contributor

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(
() -> {
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor

@ajsutton ajsutton left a 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));
Copy link
Contributor

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.

Suggested change
return ethContext.getScheduler().scheduleSyncWorkerTask(() -> runImportTask(block));
return runImportTask(block);

.whenComplete(
(r, t) -> {
(result, throwable) -> {
Copy link
Contributor

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. :)

@smatthewenglish smatthewenglish merged commit 4e8b387 into PegaSysEng:master Feb 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants