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

BIP94: Change timewarp delta to 7200 seconds #1658

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

fjahr
Copy link
Contributor

@fjahr fjahr commented Aug 5, 2024

This aligns the BIP with the Bitcoin Core pull request and sets the allowed delta between the first block of the new difficulty period and the previous block to 7200 seconds (2 hours) instead of 600 seconds.

See also the discussion in the PR: bitcoin/bitcoin#29775 (comment)

@achow101
Copy link
Member

achow101 commented Aug 5, 2024

2 hours is 7200, not 720.

@fjahr fjahr force-pushed the bip94-timewarp-delta branch 2 times, most recently from 92e792e to bce34f6 Compare August 5, 2024 21:20
@fjahr
Copy link
Contributor Author

fjahr commented Aug 5, 2024

2 hours is 7200, not 720.

Fixed, also slightly changed the wording and added some additional explanation.

@fjahr fjahr changed the title BIP94: Change timewarp delta to 720 seconds BIP94: Change timewarp delta to 7200 seconds Aug 5, 2024
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

LGTM

@murchandamus murchandamus merged commit 7655088 into bitcoin:master Aug 7, 2024
3 checks passed
@Sjors
Copy link
Member

Sjors commented Aug 8, 2024

I'm curious about the original author's take on this, @TheBlueMatt.

Although we can always change the number later if this is proposed for mainnet, that would either complicate the consensus code with another if branch, or require us to drop / fork testnet4 (or hope we never hit an edge case).

There's two additional reasons that make the number 600 nice:

  1. When maximally exploited, it neatly offsets the off-by-one error in Satoshi's code so that blocks actually happen every 10 minutes. See footnote [1] in the original BIP.

  2. "we limit the attack scenario to about a 0.1% inflation rate, much smaller than the historical inflation rate due to rapid hashrate growth" - what happens to that rate with this new value?

Looking around a bit more, there's a mailinglist post from 2018 Johnson Lau who called this number t:

0 <= t <= infinity. With a bigger t, the fix is less effective but also less likely to cause intentional/unintentional split.

He then considered that even "t=86400 (one day)" would probably be safe enough, so the choice of 7200 should be fine here.

All that said, I think it makes sense to make it safe for honest miners to just use their system time when producing a block. Though even with this change I'm not sure if that's really safe behavior.

Our own code does the following (miner.cpp):

pblock->nTime = TicksSinceEpoch<std::chrono::seconds>(NodeClock::now());
...
UpdateTime(pblock, ...)


int64_t UpdateTime(CBlockHeader* pblock, ...)
{
    int64_t nOldTime = pblock->nTime;
    int64_t nNewTime{std::max<int64_t>(pindexPrev->GetMedianTimePast() + 1, TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()))};

    if (nOldTime < nNewTime) {
        pblock->nTime = nNewTime;
    }

In other words, we pick the system time, and if needed bump it to MTP + 1.

I think this would indeed get us in trouble under the timewarp rule if t=600, when the previous block is > 600 seconds in the future.

@TheBlueMatt
Copy link
Contributor

I don't think there's much reason to care about miners being able to mine at their system time. Mining devices generally don't have clocks that are robust anyway, they just roll nTime from where the mining work producer told them to start. And, indeed, like @Sjors points out, its nice to maximally restrict here.

@fjahr
Copy link
Contributor Author

fjahr commented Aug 8, 2024

I don't think there's much reason to care about miners being able to mine at their system time. Mining devices generally don't have clocks that are robust anyway, they just roll nTime from where the mining work producer told them to start.

This seemed like a good idea to me at the time but I can't really judge this since I don't know the mining landscape enough. What time do the honest pools usually use then? I would have assumed they just use the easiest thing.

We could still make the switch to 600 if there is a preference for it. There don't seem to be any shenanigans on the network so far, I could sync fine with the 600 delta.

@Sjors
Copy link
Member

Sjors commented Aug 9, 2024

Maybe we should hash this out (haha) in a Delving or mailinglist post.

@TheBlueMatt
Copy link
Contributor

If we even maybe want to use 600 on mainnet we should use testnet to test whether anyone's stuff breaks :)

@murchandamus
Copy link
Contributor

I find @TheBlueMatt’s points convincing, and must admit, that I have little insight into miners’ setups. My concern regarding the timestamp being limited 2h in the future and therefore honest miners potentially running out of a 10 minute range was a shot from the hip, and it would be better for miners to run into this concern on testnet than eventually on mainnet.

@murchandamus
Copy link
Contributor

Nevermind, I just realized that #1660 was already opened ahead of my comment.

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.

5 participants