Skip to content

[FIX] blacklist for longer in case of header validation failure #840

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

KonradStaniec
Copy link
Contributor

@KonradStaniec KonradStaniec commented Dec 8, 2020

Description

Increases duration for critical offences in fast sync.

Imagine scenario with 3 remote peers - two of them are on wrong fork for us, and only one of them is on correct for, and those two on wrong fork are slightly beter than this on good fork.

Such scenario is possible:

  1. we sync up with the first peer on wrong fork, ultimately blacklisting him due to validation error. We rollback N blocks and start from behind
    2.we sync up with the second peer on wrong fork, ultimately blacklisting him due to validation error. We rollback N blocks and start from behind
  2. during the time we have been syncing with second peer, first peer has been unblacklisted, so we start syncing from him. And the same situation happens.

By increasing blacklist time for validation errors we make sure we will have time to try other peers.

btw. I did not introduce it to regular sync as it not easy to grab header validation error there and i would like to avoid big code changes before release

@KonradStaniec KonradStaniec requested a review from mmrozek December 8, 2020 13:07
Copy link
Contributor

@mmrozek mmrozek left a comment

Choose a reason for hiding this comment

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

One doubt only. Apart from that code LGTM

handleRewind(
header,
peerToBlackList,
syncConfig.fastSyncBlockValidationN,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we shouldn't rewind more blocks in case of critical failure. Some times ago I stuck in the wrong fork and only the increasing number of blocks helped me. WDYT?

Copy link
Contributor Author

@KonradStaniec KonradStaniec Dec 8, 2020

Choose a reason for hiding this comment

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

to be honest all those number were derived from old geth pr which also proided some security analysis so i am not eager the change those just before release, also until we will have proper branch resolving during fast sync all we do here i a little hacky either way. So i would leave it as it is.

@jmendiola222 jmendiola222 requested a review from aakoshh December 8, 2020 13:41
@jmendiola222 jmendiola222 added the high priority This PRs should be reviewed and merged ASAP label Dec 8, 2020
@aakoshh
Copy link
Contributor

aakoshh commented Dec 8, 2020

Imagine scenario with 3 remote peers - two of them are on wrong fork for us, and only one of them is on correct for, and those two on wrong fork are slightly beter than this on good fork.

What does it mean that 2 are on wrong fork "for us"? Which criteria tells that it's wrong? Is it a hard fork we don't want to follow? Or rather if we do we get validation error because of the implementation differences?

@KonradStaniec
Copy link
Contributor Author

Is it a hard fork we don't want to follow. i.e take Thanos, hard fork, it changes how proof of work validation work and we do not want to follow nodes which do not activated it.

@@ -431,14 +431,20 @@ class FastSync(
// we blacklist peer just in case we got malicious peer which would send us bad blocks, forcing us to rollback
// to genesis
log.warning("Parent chain weight not found for block {}, not processing rest of headers", header.idTag)
handleRewind(header, peer, syncConfig.fastSyncBlockValidationN)
handleRewind(header, peer, syncConfig.fastSyncBlockValidationN, syncConfig.blacklistDuration)
case HeadersProcessingFinished =>
processSyncing()
case ImportedPivotBlock =>
updatePivotBlock(ImportedLastBlock)
case ValidationFailed(header, peerToBlackList) =>
log.warning(s"validation fo header ${header.idTag} failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.warning(s"validation fo header ${header.idTag} failed")
log.warning(s"validation of header ${header.idTag} failed")

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

Looks reasonable. I don't fully understand what the default case is, the "missing parent weight".

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@KonradStaniec KonradStaniec force-pushed the fix/longer-blacklist-for-critical branch from 46694ea to e9006ef Compare December 8, 2020 14:11
@KonradStaniec
Copy link
Contributor Author

this can happen when lets say there is minor fork in the chain. Let say we are on block 10 with hash x, and we ask peer for block from block 11. Then we receive chain starting from block 11 which states that its parent is block 10 with hash y, it may happen that we may not validate this block as we do not validate every header pow, but we need is parent total diffiuctly to update it in db, she then when we try to reach for this block parent we will have header parent not found error.

In this case we also rewind blockchain a little bit, and hope fork will be resolved the next time we will get to this place.

@KonradStaniec KonradStaniec merged commit e9006ef into develop Dec 8, 2020
@KonradStaniec KonradStaniec deleted the fix/longer-blacklist-for-critical branch December 8, 2020 14:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
high priority This PRs should be reviewed and merged ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants