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

[PAN-2312] Validate DAO block #939

Merged
merged 13 commits into from
Feb 22, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Feb 21, 2019

PR description

This PR adds a DaoForkPeerValidator that will run for every connected eth peer when pantheon is run against mainnet. The validator checks if the peer is ready to be validated by looking at the peer's estimated chain height. If the height is past the DAO block, it will request and check the block from the peer at the DAO fork. If this block is on the wrong side of the fork, the peer will be disconnected.

Some secondary changes in this PR include:

  • Updating BlockHeadersMessage.getHeaders to return a list
  • Updating AbstractGetHeadersFromPeerTask to perform stricter matching on responses: if a response contains more headers than were requested, we don't consider this response a match to our request
  • Making the timeout in PeerRequestTask configurable
  • Updating some test utilities to provide more control over the execution of executor tasks within tests

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.

Generally looks good. Couple of nits and just need to make sure we stop checking peers if they disconnect before getting to the fork block.

In terms of helping fast sync to pick the right block, ideally this check would be performed before the peer is considered available (at least in the case of them being ahead of the Dao block on initial connection). Otherwise there's a (quite small) risk that we'd connect to 5 ETC peers at about the same time and fast sync would pick one of their blocks before this check has a chance to run. In any case that's almost certainly a separate PR.

I do like that the PeerValidator sets things up so we can make this a more generic test in the future (e.g. to detect the many varied forks around Ropsten Constantinople) and potentially even dynamically based on bad blocks we detect.

disconnectPeer(ethPeer);
}
});
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this to be } else if (!peer.isDisconnected()) {?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - good catch. we need to handle disconnects so we don't repeatedly check disconnected peers.

@@ -116,6 +123,9 @@ public MainnetPantheonController(
metricsSystem);
final SyncState syncState =
new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers());
final LabelledMetric<OperationTimer> ethTasksTimer =
metricsSystem.createLabelledTimer(
MetricCategory.SYNCHRONIZER, "task", "Internal processing tasks", "taskName");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for pushing this up to here? Seems odd to have only done it for MainnetPantheonController and not clique & IBFT, plus we're generally trying to push common construction code out of the controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need it to construct any EthTask's and DaoForkPeerValidator uses an EthTask. I think the real fix is to keep working on MetricsSystem to allow metrics to be created idempotently so we can then push this timer creation into AbstractEthTask where it's used. I have some in-progress work on that which I can come back to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh, yeah that's very unfortunate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remembered, I added some caching for metrics back when I did the EVM metrics but had to revert it, so 525aa19#diff-b95472676d731050caa643c3ebe592b1 may be useful.

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.

@ajsutton ajsutton merged commit b85c6a2 into PegaSysEng:master Feb 22, 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.

2 participants