Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[ETCM-247] Fix Fetcher updates #760

Conversation

mirkoAlic
Copy link
Contributor

@mirkoAlic mirkoAlic commented Oct 26, 2020

Description

According to https://jira.iohk.io/browse/ETCM-247, the desyncronization between importer and fetcher could cause several issues.

The goal of this PR is to provide an easy fix in order to keep fetcher state updated in case a node is only importing throw new mined blocks, or new checkpoint blocks.

Also, notice that previous to this PR, if a node(node2) wants to sync with other(node1), requires that its peer(node 1) is continuously generating blocks, if is not the case is going to catch up with only the first n number of blocks (according to block-headers-per-request). By subscribing to new block headers, now fetcher can update its vision about know top and react to this.
^ issue: Block downloading doesn't start without any new block received from the network

Proposed Solution

  • Fetcher is updating last block and know top(if is the case) if a mined or checkpointed block is imported
  • Fetch is subscribed to new block headers

Testing

  • Regular sync IT tests should passed.
  • Previous tests should work too.
  • Try to reproduce the manual scenario described over ETCM-247

TODO

Add tests for fetcher once ETCM-211 got merged (use code: ETCM-248)

@mirkoAlic mirkoAlic added the bug Something isn't working label Oct 26, 2020
@mirkoAlic mirkoAlic force-pushed the etcm-247-Fetcher-is-not-receiving-mined-or-checkpointed-blocks branch from eb62350 to 525365d Compare October 27, 2020 12:33
- Fetcher will update last block and know top(only if is needed) if a mined or checkpointed block was imported
- Fetcher will update know top if detect a block header with better top
@mirkoAlic mirkoAlic force-pushed the etcm-247-Fetcher-is-not-receiving-mined-or-checkpointed-blocks branch from 525365d to 5fda427 Compare October 27, 2020 13:03
@mirkoAlic mirkoAlic requested a review from biandratti October 27, 2020 15:26
@mirkoAlic mirkoAlic marked this pull request as ready for review October 27, 2020 15:26
@mirkoAlic mirkoAlic requested review from ntallar and kapke October 27, 2020 15:27

"given a previously mined blockchain" in customTestCaseResourceM(FakePeer.start2FakePeersRes()) {
case (peer1, peer2) =>
val blockHeadersPerRequest = 200
Copy link

Choose a reason for hiding this comment

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

Should we use here peer2.syncConfig.blockHeadersPerRequest?

//keep fetcher state updated in case new checkpoint block or mined block was imported
case LastBlockChanged(blockNr) => {
log.debug(s"New last block $blockNr imported from the inside")
val newState = state.withLastBlock(blockNr).withPossibleNewTopAt(blockNr)
Copy link

Choose a reason for hiding this comment

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

Last block seems to also involve the last headers fetched, what if we are already in progress of fetching blocks from the network with block number higher than the one imported (as it's likely the case for checkpoint blocks)? Doesn't this break the consistency of the fetcher?

Maybe the new last block should be blockNr.max(state.lastBlock) or sth like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

@@ -232,6 +255,9 @@ class BlockImporter(
case ChainReorganised(oldBranch, newBranch, totalDifficulties) =>
updateTxPool(newBranch, oldBranch)
broadcastBlocks(newBranch, totalDifficulties)
if (informFetcherOnLastBlockChanged) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor - after changes introduced in ETCM-175 (on develop already), it should be enough to call fetcher from RegularSync actor after receiving update about imported block.

Copy link

@ntallar ntallar left a comment

Choose a reason for hiding this comment

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

LGTM!

 .\\            //.
. \ \          / /.
.\  ,\     /` /,.-
 -.   \  /'/ /  .
 ` -   `-'  \  -
   '.       /.\`
      -    .-
      :`//.'
      .`.'
      .' BP 

@mirkoAlic mirkoAlic merged commit 4f043d9 into develop Oct 29, 2020
@mirkoAlic mirkoAlic deleted the etcm-247-Fetcher-is-not-receiving-mined-or-checkpointed-blocks branch October 29, 2020 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants