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 future time limit exception in cpuminer #18

Merged
merged 1 commit into from
Nov 4, 2019

Conversation

dgenr8
Copy link
Collaborator

@dgenr8 dgenr8 commented Nov 3, 2019

Running the cpuminer to find a block in the same second the tip was found would cause the default time increment (1 second in non-regtest) to kick in and violate the future time limit. The solution is to wait until that second has passed. This logic already exists in the GBT code path.

This wait already exists in GBT, need it in the cpuminer also
@dgenr8
Copy link
Collaborator Author

dgenr8 commented Nov 3, 2019

@cryptozeny Would you mind re-trying your test case with this?

Previously I could reliably generate the error with 'generate 2 420000000', but I think you had a different scenario.

@cryptozeny
Copy link
Contributor

At minimum testnet (=mainnet) difficulty you need about 7,000,000 * 600 = about 4,200,000,000 tries. You can enter # of tries in the next parameter.

but 4,200,000,000 is not possible. out of range. so i tried 420,000,000 this is bit confused.

// Not regtest: Wait until tip is 1 second in the past.
if (!Params().GetConsensus().fPowNoRetargeting) {
while (GetTime() - tip->GetBlockTime() < 1)
MilliSleep(50);
Copy link
Contributor

@cryptozeny cryptozeny Nov 4, 2019

Choose a reason for hiding this comment

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

i just curious, why 50ms sleep?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question.

First (in case anyone else is wondering), why wait at all? The reason is that in this reference code we don't want to do anything that could possibly create a block that an honest peer with an accurate clock would reject. If we generate a block with a time 1 second in the future, it may be received and rejected by such a peer before it is valid.

Why 50ms? Just to avoid a pegged loop. On average, this will require 10 checks before passing. Another option would be to wait on an event we schedule for the exact 1s mark in another thread.

What if I just recently moved my clock by setting it back by minutes or hours? Won't this potentially be a long wait? Answer: yes, if the network has been taken over by cheating miners making future blocks. You will be part of the solution by not building on the chain until it is valid, but there's more I'd like to see done in this area. When the local clock is adjusted by you or your automated agent, we should (possibly with your manual approval) roll the chain back to the last non-future block.

Will all this waiting cause the block production rate to fall? Answer: imperceptibly. Mining a block at 1 second is 11 trillion times harder than current difficulty.

11 trillion times harder than current difficulty? Won't that cause miners to disappear and mine something else until a few minutes later when this chain is more profitable? Answer: that's up to them. Simulation has shown the presence of this kind of hashrate makes blocktimes MORE stable. The reason is that it reduces lucky short blocks which would otherwise cause a big difficulty response, and encourages maximum hashrate after the block is late, reducing long blocks.

Ok but won't that cause more orphans if everybody is mining only around the same time? Answer: probably, it depends on the hashrate distribution. We need to keep an eye on this. The worst case is if there are 2 miners with a 50/50 split. I simulated this and found an average of 7 collisions within 1 second per 10,000 blocks. So far, in 2986 blocks on chain2, there has been 1 orphan.

@cryptozeny
Copy link
Contributor

1st try is ok

2019-11-04 00:05:23 CreateNewBlock(): total size 1000 txs: 0 fees: 0 sigops 100
2019-11-04 00:05:24 UpdateTip: new best=0000000385d56d218885131d804dbe8fd2d7a358bfcee62b485195184573e990  height=1159  log2_work=67.294289  tx=1160  date=2019-11-04 00:05:23 progress=1.000000  cache=0.0MiB(1txo)
2019-11-04 00:05:24 AddToWallet 887980cea48361e2665511d67103efa9ffb36ec58c70b8f7edc82ba31ba38547  new
2019-11-04 00:05:24 keypool keep 10

image

@cryptozeny
Copy link
Contributor

2nd ok

2019-11-04 00:21:31 UpdateTip: new best=00000046f06e694c5afed0855c9f3abe3844cd8616b9b156e576af1718ade181  height=1160  log2_work=67.294289  tx=1161  date=2019-11-04 00:21:30 progress=1.000000  cache=0.0MiB(2txo)
2019-11-04 00:21:31 AddToWallet 555c0ea92111a5437edff533a52732641fdf2ebebed4bb24336542897a39ab28  new
2019-11-04 00:21:31 keypool keep 12

image

@cryptozeny
Copy link
Contributor

3rd ok

2019-11-04 00:37:36 UpdateTip: new best=0000000c41c8de15c11f24108d61df282933f275dbb1835391a205b34aeb32a1  height=1161  log2_work=67.294289  tx=1162  date=2019-11-04 00:37:36 progress=1.000000  cache=0.0MiB(3txo)
2019-11-04 00:37:36 AddToWallet c751d0c22a59ba376fd19117ea839106338bdabdbc3e7df7864b59de59ac2477  new
2019-11-04 00:37:36 keypool keep 14

image

Copy link
Contributor

@cryptozeny cryptozeny left a comment

Choose a reason for hiding this comment

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

f6c5cc9 seems OK

@dgenr8 dgenr8 merged commit 468f9ac into chain2:master Nov 4, 2019
@dgenr8 dgenr8 deleted the fix_cpuminer_ftl branch May 10, 2020 19:44
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.

None yet

2 participants