koinos / koinos-p2p

The p2p microservice orchestrates the distribution of blocks and transactions between peers.
MIT License
6 stars 4 forks source link

BlockDownloadManager needs to be sure blocks don't get stuck in WaitingToApply state #155

Closed theoreticalbts closed 3 years ago

theoreticalbts commented 3 years ago

PR #152 has some commented-out code related to the fate of WaitingToApply / Applying blocks from kicked peers.

It's clear that Downloading blocks need to be scrubbed, since they'll never finish downloading. Applying blocks likewise we can't do much about -- we've already sent them off to the koinos-chain microservice to do what it will.

So let's instead explore the WaitingToApply state and look for interesting failure modes.

For example it's possible Eve will report a bogus fork with blocks A, B, C in that order. We ask Eve for A, B and C. Eve gives us B and C, but times out on A (or gives a bogus block that fails to apply). We kick Eve and delete A if we got it, but now B and C are stuck in the WaitingToApply state. They'll never leave that state because they'll only be applied once we apply bogus block A, which we're never going to be able to do.

I think the most graceful way to handle this is to simply track when each block entered the WaitingToApply state, then periodically (once every ~5 minutes) walk the list of blocks and expire blocks that have gotten too old.

mvandeberg commented 3 years ago

This is irrelevant after #166 is merged