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

[Staking] Don't assert if we were beaten to the block #916

Merged
merged 2 commits into from
Jun 16, 2019

Conversation

CaveSpectre11
Copy link

A timing window exists where a wallet could be creating a new block from within the miner thread when a new block is received to the wallet. This window will create a situation where TestBlockValidity() fails because the chain tip has changed between the time it created the new block and the time it tested the validity of the block.

This situation would result in the wallet being asserted; however this is a little overkill. rather than asserting if the tip has changed, it is better to throw the block away.

This problem was revealed during a testnet test of an altcoin, and very prevalent when multiple wallet existed with the exact same number of staking coins received in the same transaction; or when multiple wallets were staking the same coins via import private key. The problem happens significantly less in more normal circumstances, but was still observed in a testing environment with fast blocks.

It is likely that this scenario has been encountered but never determined to be root cause, as a crashed wallet could be restarted, re-indexed and never investigated further.

A timing window exists where a wallet could be creating a new block from within the miner thread when a new block is received to the wallet.  This window will create a situation where TestBlockValidity() fails because the chain tip has changed between the time it created the new block and the time it tested the validity of the block.  

This situation would result in the wallet being asserted; however this is a little overkill.  rather than asserting if the tip has changed, it is better to throw the block away.

This problem was revealed during a testnet test of an altcoin, and very prevalent when multiple wallet existed with the exact same number of staking coins received in the same transaction; or when multiple wallets were staking the same coins via import private key.  The problem happens significantly less in more normal circumstances, but was still observed in a testing environment with fast blocks.

It is likely that this scenario has been encountered but never determined to be root cause, as a crashed wallet could be restarted, re-indexed and never investigated further.
@Warrows Warrows self-assigned this Jun 10, 2019
@Warrows Warrows self-requested a review June 12, 2019 14:25
@Warrows Warrows removed their assignment Jun 12, 2019
Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

utACK with a minor and non-blocking change to the LogPrintf() format

src/main.cpp Outdated
assert(pindexPrev && pindexPrev == chainActive.Tip());
assert(pindexPrev);
if (pindexPrev != chainActive.Tip()) {
LogPrintf("TestBlockValidity(): No longer working on chain tip\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

could change this to

LogPrintf("%s : No longer working on chain tip\n", __func__);

@Fuzzbawls Fuzzbawls added the Block Generation Mining/Staking related issues label Jun 14, 2019
@furszy furszy self-requested a review June 15, 2019 12:48
Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Looks good , pretty straightforward change.
utACK 👍.

@Fuzzbawls Fuzzbawls added this to the 3.3.0 milestone Jun 15, 2019
@Fuzzbawls Fuzzbawls changed the title Don't assert if we were beaten to the block [Staking] Don't assert if we were beaten to the block Jun 16, 2019
@Fuzzbawls Fuzzbawls merged commit 24d72d0 into PIVX-Project:master Jun 16, 2019
Fuzzbawls added a commit that referenced this pull request Jun 16, 2019
24d72d0 [code review] LogPrintf nit change (CaveSpectre11)
019d26a Don't assert if we were beaten to the block (CaveSpectre11)

Tree-SHA512: 9818319df999ba21fb6f89dadf254f76ad02d14b4f35fcae5b8d9a6251a0be5212650f3834a61a90fad2a9e8ce242751a9c09f7325c9cccc60223a59a6b3f22c
@Fuzzbawls
Copy link
Collaborator

Paid 150 PIV for this contribution, thanks :)

@random-zebra random-zebra modified the milestones: 3.3.0, Future Jul 1, 2019
@Fuzzbawls Fuzzbawls modified the milestones: Future, 4.0.0 Jul 11, 2019
@CaveSpectre11 CaveSpectre11 deleted the patch-3 branch July 22, 2019 00:27
@Fuzzbawls Fuzzbawls added the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Aug 16, 2019
@random-zebra random-zebra modified the milestones: 4.0.0, 3.4.0 Aug 25, 2019
@Fuzzbawls Fuzzbawls modified the milestones: 3.4.0, 3.3.0 Aug 26, 2019
@Fuzzbawls Fuzzbawls removed the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Block Generation Mining/Staking related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants