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

Fix reorg handling #5819

Merged
merged 4 commits into from
Nov 12, 2021
Merged

Conversation

chimp1984
Copy link
Contributor

@chimp1984 chimp1984 commented Nov 10, 2021

Fixes #5809

How to reproduce:

  • Start a new regtest setup with a seed, a full node (Alice) and a lite node (Bob)
  • Make a backup of that start setup version. Assume block height is 113 here.
  • Create 1 block
  • Create 1 tx
  • Create 1 block. Block height is 115.
  • Stop BTC core replace the blocks and regtest folders in btc core data dir with the folders from the start setup backup. This is used for simulating a reorg.
  • Create 2 blocks. Still no reorg as fork chain has same height 115 as existing chain.
  • Create 1 more block triggering the reorg at 116.

In master the Alice nad Bob nodes get caught in an endless loop requesting new blocks. The seed node is shut down automatically. Bob will start the endless loop only after the seed has restarted and the next block is propagated.

With the PR version there is just the shutdown at seed node and the shutdown popup at desktop apps but no loops.
The litenode will not recognize the new block as the full nodes are shut down or inactive. Only after restarting the seed and creating a new block the lite node will detect the reorg. The block propagation is delayed with a random delay so it can take a bit...

To avoid that all seed nodes shut down at the same time when a reorg happens we add a detereministic delay derived from the index of the seed in the seed node list. So shut down is delayed by 30 sec * index, distributing the shutdown of 12 seeds over 6 minutes.

and FullNode

The custom implementations triggered to repeat requests
but we shut down the seed node in case of a reorg and
for desktops we request the user to shutdown.
…tion

We trigger a resync from resources if there is a reorg and don't want to
continue to request blocks
persistance is below the chain height of btc core.
With the new handling of dao state hashblocks it can be the
we have persisted the latest block up to the chain height.
Before that change we only had the last snapshot which was at least
20 blocks back persisted.
We want to avoid to get caught in a retry loop at parseBlocksOnHeadHeight
so we filter out that case just at the caller.

At parseBlocksOnHeadHeight we inline the requestChainHeadHeightAndParseBlocks
method as it is not used by other callers anymore.
This case  that we request a block but our local btc core chain hight is below
that might be some edge case when we had a synced dao blocks but we btc core is
resyncing...
We shut down with a deterministic delay per seed to avoid that all seeds shut down at the
same time in case of a reorg. We use 30 sec. as distance delay between the seeds to be on the
safe side. We have 12 seeds so that's 6 minutes.
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Contributor

@ripcurlx ripcurlx left a comment

Choose a reason for hiding this comment

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

ACK - Tested the process on Regtest and was able to simulate the behavior as described.

  • Seednode shut down
  • Full node got notified to shut down
    Bildschirmfoto 2021-11-12 um 09 40 13
  • Light node didn't recognize the reorg yet
  • Seednode and Alice (fullnode) were restarted
  • After creating new blocks, Bob (light node) recognized the reorg
    Bildschirmfoto 2021-11-12 um 10 43 51

After restart of Light node everything went back to normal.

@ripcurlx ripcurlx added this to the v1.8.0 milestone Nov 12, 2021
@ripcurlx ripcurlx merged commit 3e6bb3b into bisq-network:master Nov 12, 2021
@chimp1984 chimp1984 deleted the fix-reorg-handling branch November 17, 2021 18:57
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.

Bug at reorgs
2 participants