fix(chain_manager): fix some synchronization issues #2519
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains two distinct patches that solve some synchronization issues.
Pretty self-explanatory. Don't use the current epoch for validating block transactions when synchronizing blocks that may be older than the current protocol version.
Somewhat more involved. When I restart a node that is already in V1.8, I noticed it failed to synchronize. It received new blocks, but did not want to add them properly. I added some debug info and found that the block hashes it receives are non-versioned block hashes while it expects versioned ones.
I logged the
InventoryAnnouncement
message it receives here (for a block starting at epoch 1010):witnet-rust/node/src/actors/session/handlers.rs
Line 770 in da223fe
And the expected hashes when it receives block messages for epoch 1010:
Note the different hashes. The reason for this is because the second hash for block 1010 is a versioned hash with protocol version V1.8 while the former is not.
This results in the following line not evaluating to true:
witnet-rust/node/src/actors/session/handlers.rs
Line 679 in da223fe
After which we call
AddCandidates
which drops the block because of this condition:witnet-rust/node/src/actors/chain_manager/mod.rs
Line 750 in da223fe
However, if we use the versioned hash as proposed in the patch, you can see that the
block_chain
structure will insert the correctly versioned hash here:witnet-rust/node/src/actors/chain_manager/mod.rs
Line 1322 in da223fe
After which the
InventoryAnnouncement
which usesGetBlocksEpochRange
which reads theblock_chain
structure should return the correct, expected versioned hash.Just to confirm, I printed out the non-versioned and versioned hash for epoch 1010:
As you can see, the old hash matches the hash we receive in the
InventoryAnnouncement
message block hash array while the new hash matches the expected versioned hash in the received block message which will eventually be processed.I cannot fully test this works because we'd need a testnet reset since we are essentially forking the chain, but it looks reasonable.