public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
* [bitcoindev] Unbreaking testnet4
@ 2025-03-18 14:29 'Antoine Poinsot' via Bitcoin Development Mailing List
  2025-03-19  7:01 ` [bitcoindev] " Garlo Nicon
  2025-03-19  8:32 ` Sjors Provoost
  0 siblings, 2 replies; 5+ messages in thread
From: 'Antoine Poinsot' via Bitcoin Development Mailing List @ 2025-03-18 14:29 UTC (permalink / raw)
  To: Bitcoin Development Mailing List

[-- Attachment #1: Type: text/plain, Size: 2087 bytes --]

Hi,

Testnet4 was rolled out a year ago to address the shortcomings of testnet3. One of those shortcomings was the difficulty reset creating havoc. [0] In spite of this a similar rule was adopted for testnet4. [1] As a result, testnet4 is similarly creating havoc. [2]

The goal of testnet is to mimic the Bitcoin mainnet. This is why it is useful to have in addition to a more control testing environment such as Signet.

The given rationale for a difficulty reset was to let developers occasionally mine blocks on their laptop. But you cannot have your cake and eat it too: either the network is permissionless (PoW) or you assign identities and privileges to some (Signet). By trying to do both at the same time testnet4 created a loophole for abuse. As a result it failed on both count: it neither mimics mainnet nor allows developers to mine active blocks on their laptop.

I propose to fix this by removing the difficulty reset rule from testnet4 through a flag day hard fork on 2026-01-01. I picked a date well in the future to minimize disruption. This leaves enough time for a patch to be reviewed, merged, included in the next major Bitcoin Core release, backported to previous releases and adopted by the infrastructure running on testnet4. That should be enough for a test network.

Let me know what you think,
Antoine

[0] https://gnusha.org/pi/bitcoindev/CADL_X_eXjbRFROuJU0b336vPVy5Q2RJvhcx64NSNPH-3fDCUfw@mail.gmail.com
[1] https://github.com/bitcoin/bips/blob/master/bip-0094.mediawiki#rule-specification
[2] [https://fork.observer](https://fork.observer/) - pick the network on the top right corner

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/hU75DurC5XToqizyA-vOKmVtmzd3uZGDKOyXuE_ogE6eQ8tPCrvX__S08fG_nrW5CjH6IUx7EPrq8KwM5KFy9ltbFBJZQCHR2ThoimRbMqU%3D%40protonmail.com.

[-- Attachment #2: Type: text/html, Size: 3441 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bitcoindev] Re: Unbreaking testnet4
  2025-03-18 14:29 [bitcoindev] Unbreaking testnet4 'Antoine Poinsot' via Bitcoin Development Mailing List
@ 2025-03-19  7:01 ` Garlo Nicon
  2025-03-19  7:56   ` [bitcoindev] " Sjors Provoost
  2025-03-19  8:32 ` Sjors Provoost
  1 sibling, 1 reply; 5+ messages in thread
From: Garlo Nicon @ 2025-03-19  7:01 UTC (permalink / raw)
  To: Bitcoin Development Mailing List


[-- Attachment #1.1: Type: text/plain, Size: 3522 bytes --]

> I propose to fix this by removing the difficulty reset rule from testnet4 
through a flag day hard fork on 2026-01-01.

You can do that in a soft-fork way. Just rejecting blocks with 
difficulty=1, and requiring always a block with the true network 
difficulty, is a valid soft-fork.

To better see that, you can imagine, what would happen, if someone would 
apply difficulty adjustment rule on mainnet. Then, it would be possible to 
temporarily mine a block on a CPU, see it confirmed by your node (and 
rejected by the rest of the network), and then, when the next real block 
would appear, your client would automatically switch to a stronger chain 
(and then, those CPU-mined blocks would be truly worthless).

So, I assume if you change "fPowAllowMinDifficultyBlocks" from "true" to 
"false", when block time will be greater than unix time "1767225600", then 
you will get a valid soft-fork. Non-upgraded clients could then still see 
some CPU-mined blocks, but they will disappear, if the hashrate majority 
will support your changes, and then old clients will automatically follow 
your chain. Also note that a single ASIC block can reorg a lot of CPU-mined 
blocks, so it is always guaranteed, that this change will be 
chainwork-compatible.

wtorek, 18 marca 2025 o 22:24:49 UTC+1 Antoine Poinsot napisał(a):

> Hi,
>
> Testnet4 was rolled out a year ago to address the shortcomings of 
> testnet3. One of those shortcomings was the difficulty reset creating 
> havoc. [0] In spite of this a similar rule was adopted for testnet4. [1] As 
> a result, testnet4 is similarly creating havoc. [2]
>
> The goal of testnet is to mimic the Bitcoin mainnet. This is why it is 
> useful to have in addition to a more control testing environment such as 
> Signet.
>
> The given rationale for a difficulty reset was to let developers 
> occasionally mine blocks on their laptop. But you cannot have your cake and 
> eat it too: either the network is permissionless (PoW) or you assign 
> identities and privileges to some (Signet). By trying to do both at the 
> same time testnet4 created a loophole for abuse. As a result it failed on 
> both count: it neither mimics mainnet nor allows developers to mine active 
> blocks on their laptop.
>
> I propose to fix this by removing the difficulty reset rule from testnet4 
> through a flag day hard fork on 2026-01-01. I picked a date well in the 
> future to minimize disruption. This leaves enough time for a patch to be 
> reviewed, merged, included in the next major Bitcoin Core release, 
> backported to previous releases and adopted by the infrastructure running 
> on testnet4. That should be enough for a test network.
>
> Let me know what you think,
> Antoine
>
> [0] 
> https://gnusha.org/pi/bitcoindev/CADL_X_eXjbRFROuJU0b336vP...@mail.gmail.com 
> <https://gnusha.org/pi/bitcoindev/CADL_X_eXjbRFROuJU0b336vPVy5Q2RJvhcx64NSNPH-3fDCUfw@mail.gmail.com>
> [1] 
> https://github.com/bitcoin/bips/blob/master/bip-0094.mediawiki#rule-specification
> [2] https://fork.observer - pick the network on the top right corner
>

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/f0cace2b-d734-4b36-b8a1-d4364a573a19n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 5238 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bitcoindev] Unbreaking testnet4
  2025-03-19  7:01 ` [bitcoindev] " Garlo Nicon
@ 2025-03-19  7:56   ` Sjors Provoost
  2025-03-19  8:43     ` Garlo Nicon
  0 siblings, 1 reply; 5+ messages in thread
From: Sjors Provoost @ 2025-03-19  7:56 UTC (permalink / raw)
  To: Bitcoin Development Mailing List; +Cc: Garlo Nicon



> Op 19 mrt 2025, om 08:01 heeft Garlo Nicon <garlonicon@gmail•com> het volgende geschreven:
> 
> > I propose to fix this by removing the difficulty reset rule from testnet4 through a flag day hard fork on 2026-01-01.
> 
> You can do that in a soft-fork way. Just rejecting blocks with difficulty=1, and requiring always a block with the true network difficulty, is a valid soft-fork.

Unfortunately it's a hard-fork.

> So, I assume if you change "fPowAllowMinDifficultyBlocks" from "true" to "false", when block time will be greater than unix time "1767225600", then you will get a valid soft-fork.


The fPowAllowMinDifficultyBlocks rule says that after 20 minutes the new block MUST have difficulty 1.  A block with the real difficulty will be rejected.

This is because in general the block nBits value, which announces how much work the block has, must have an exact value. It can't be higher.

In validation.cpp we have this:

if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
    return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "bad-diffbits", "incorrect proof of work");

Inside GetNextWorkRequired there is the testnet exception rule, which Antoine proposes to drop:

 if (params.fPowAllowMinDifficultyBlocks) {
    // Special difficulty rule for testnet:
    // If the new block's timestamp is more than 2* 10 minutes
    // then allow mining of a min-difficulty block.
    if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
        return nProofOfWorkLimit;
    else
       ... (same difficulty as last block, unless it's a retarget)

The code comment is misleading, "allow" should be "require".

- Sjors

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/688E575D-C370-4D7D-A6DB-11E0B56710B1%40sprovoost.nl.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bitcoindev] Unbreaking testnet4
  2025-03-18 14:29 [bitcoindev] Unbreaking testnet4 'Antoine Poinsot' via Bitcoin Development Mailing List
  2025-03-19  7:01 ` [bitcoindev] " Garlo Nicon
@ 2025-03-19  8:32 ` Sjors Provoost
  1 sibling, 0 replies; 5+ messages in thread
From: Sjors Provoost @ 2025-03-19  8:32 UTC (permalink / raw)
  To: 'Antoine Poinsot' via Bitcoin Development Mailing List
  Cc: Antoine Poinsot

[-- Attachment #1: Type: text/plain, Size: 2804 bytes --]

Antoine Poinsot wrote:

> The given rationale for a difficulty reset was to let developers occasionally mine blocks on their laptop. But you cannot have your cake and eat it too: either the network is permissionless (PoW) or you assign identities and privileges to some (Signet). By trying to do both at the same time testnet4 created a loophole for abuse. As a result it failed on both count: it neither mimics mainnet nor allows developers to mine active blocks on their laptop.

Let me clarify why developers can't mine on their own laptop with testnet4.

The way you would do that is to move your computer clock forward by 20 minutes (or use faketime), at which point the difficulty drops to 1. You would then mine your (presumably non-standard transaction) and broadcast it to the network.

This is also the strategy used to acquire more testnet coins if you don't have an ASIC and don't want to use a faucet.

On testnet3 the latter wasn't very productive because at height 4 million the block subsidy is under 10k sats.

But on testnet4 every block yields 50 tBTC. So several people try to mine such a block, leading to the many parallel forks. 

If you're a developer trying to mine a non-standard transaction, you have to be fast, well connected and lucky to be the first block picked up by the rest of the network.

But why mine just one if you can mine many?

Some CPU miners are now mining as many testnet4 blocks as they can by bumping their clock 20 minutes not just once, but several times in a row. Until they run against the limit other nodes put on how far a block can be in the future, namely two hours. So when a real difficulty block appears, you may see 5 blocks on top of it instantly.

This behavior is even worse from the point of view of a developer trying to mine a non-standard transaction. Because the tip of your node is always going to be about two hours in the future, when you mine on top of that by moving your clock even further, it will be rejected by your peers.

So this use case of CPU mining non-standard transactions is simply dead as long as this behaviour exists. We might as well reduce code complexity.

That said, testnet will never mimic mainnet. It has no value, or worse, very little value. So the incentives are different, which leads to different behavior. That's a whack-a-mole game, which we should probably not dedicate time to.

- Sjors


 

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/2064B7F4-B23A-44B0-A361-0EC4187D8E71%40sprovoost.nl.

[-- Attachment #2: Type: text/html, Size: 3788 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bitcoindev] Unbreaking testnet4
  2025-03-19  7:56   ` [bitcoindev] " Sjors Provoost
@ 2025-03-19  8:43     ` Garlo Nicon
  0 siblings, 0 replies; 5+ messages in thread
From: Garlo Nicon @ 2025-03-19  8:43 UTC (permalink / raw)
  To: Bitcoin Development Mailing List


[-- Attachment #1.1: Type: text/plain, Size: 3474 bytes --]

It seems you are right. However, this rule is based on block timestamps, 
which gives me another idea: what about simply invalidating a block, if the 
block time difference is bigger than 20 minutes? Because that's what ASIC 
miners would want to do anyway, to reorg a long chain of CPU-mined blocks: 
if the difficulty is 12345678, and you can see hundreds of blocks with 
difficulty 1, then a single block with difficulty 12345678 will reorg all 
of these CPU-mined blocks in a single shot.

By the way: if we are entering a hard-fork territory, and if testnet4 coins 
are traded, then what about switching to testnet5 with new rules instead?

And also, in case of any forks, there is a question, how many miners will 
actually support new changes. Because in case of new timewarp rules, we saw 
hundreds of blocks being reorged, because some ASIC miners didn't upgrade 
their code: https://github.com/bitcoin/bitcoin/issues/30786

And even when mempool.space upgraded their code, a few weeks after that, I 
could still see some ASIC nodes in the wild, which were mining on the wrong 
branch, and with just a CPU, it was possible to fork them once every 2016 
blocks, for a few hundred blocks.

środa, 19 marca 2025 o 08:59:26 UTC+1 Sjors Provoost napisał(a):

>
>
> > Op 19 mrt 2025, om 08:01 heeft Garlo Nicon <garlo...@gmail•com> het 
> volgende geschreven:
> > 
> > > I propose to fix this by removing the difficulty reset rule from 
> testnet4 through a flag day hard fork on 2026-01-01.
> > 
> > You can do that in a soft-fork way. Just rejecting blocks with 
> difficulty=1, and requiring always a block with the true network 
> difficulty, is a valid soft-fork.
>
> Unfortunately it's a hard-fork.
>
> > So, I assume if you change "fPowAllowMinDifficultyBlocks" from "true" to 
> "false", when block time will be greater than unix time "1767225600", then 
> you will get a valid soft-fork.
>
>
> The fPowAllowMinDifficultyBlocks rule says that after 20 minutes the new 
> block MUST have difficulty 1. A block with the real difficulty will be 
> rejected.
>
> This is because in general the block nBits value, which announces how much 
> work the block has, must have an exact value. It can't be higher.
>
> In validation.cpp we have this:
>
> if (block.nBits != GetNextWorkRequired(pindexPrev, &block, 
> consensusParams))
> return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, 
> "bad-diffbits", "incorrect proof of work");
>
> Inside GetNextWorkRequired there is the testnet exception rule, which 
> Antoine proposes to drop:
>
> if (params.fPowAllowMinDifficultyBlocks) {
> // Special difficulty rule for testnet:
> // If the new block's timestamp is more than 2* 10 minutes
> // then allow mining of a min-difficulty block.
> if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + 
> params.nPowTargetSpacing*2)
> return nProofOfWorkLimit;
> else
> ... (same difficulty as last block, unless it's a retarget)
>
> The code comment is misleading, "allow" should be "require".
>
> - Sjors

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/66e51750-56d3-4fc7-b55b-eb838c07adb4n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 4198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-19  9:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-18 14:29 [bitcoindev] Unbreaking testnet4 'Antoine Poinsot' via Bitcoin Development Mailing List
2025-03-19  7:01 ` [bitcoindev] " Garlo Nicon
2025-03-19  7:56   ` [bitcoindev] " Sjors Provoost
2025-03-19  8:43     ` Garlo Nicon
2025-03-19  8:32 ` Sjors Provoost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox