Skip to content

fix(chain): reindex on startup when headers outlive the saved height - #1486

Open
Micah-Shallom wants to merge 1 commit into
getfloresta:masterfrom
Micah-Shallom:fix/reindex-headers-on-startup
Open

Micah-Shallom wants to merge 1 commit into
getfloresta:masterfrom
Micah-Shallom:fix/reindex-headers-on-startup

Conversation

@Micah-Shallom

Copy link
Copy Markdown
Contributor

If florestad is killed during header sync, the headers it already downloaded are on disk but the best height isn't, since that's only saved on flush. On restart the node thinks it's back at the old height and only finds the stored headers once a peer sends one it already has. With presync (#1249) that means a full presync pass first.

Now ChainState::open checks for a stored header one past the saved height and runs reindex_chain before any peer is involved.

Tested on signet by killing florestad with kill -9 at around 44k headers and restarting:

20:41:57  WARN chain: Found headers past our saved best height 0. Reindexing.
20:42:08  INFO wire: New peer id=5 ...
20:42:52  INFO wire: Downloading headers from peer=40 at height=44001 ...

A clean Ctrl+C restart loads the saved height and doesn't reindex. There's also a unit test that reopens the store after headers were accepted without a flush, both before and after a first flush.

Closes #1479

The best height is only written on flush, so if florestad is killed during header sync, the stored headers are ahead of the saved height and the node restarts thinking it's at that older height. Today it only notices when a peer sends a header we already have, which with presync means after a full presync pass. Now `open` checks for a header one past the saved height and reindexes right away.

Closes getfloresta#1479
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Best header height isn't persisted during header sync; recovery waits for a peer's headers

1 participant