From 1163b08378a50a9be00ced434d55f1b04bc9dea6 Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Wed, 7 Aug 2024 21:07:23 +0200 Subject: [PATCH 1/4] chainparams: Add initial minimum chain work for Testnet4 This chainwork was observed at height 38487. --- src/kernel/chainparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/chainparams.cpp b/src/kernel/chainparams.cpp index bbddc3dfec9..d0de3a4eab6 100644 --- a/src/kernel/chainparams.cpp +++ b/src/kernel/chainparams.cpp @@ -334,7 +334,7 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT; consensus.vDeployments[Consensus::DEPLOYMENT_TAPROOT].min_activation_height = 0; // No activation delay - consensus.nMinimumChainWork = uint256{}; + consensus.nMinimumChainWork = uint256{"000000000000000000000000000000000000000000000056faca98a0cd9bdf5f"}; consensus.defaultAssumeValid = uint256{}; pchMessageStart[0] = 0x1c; From f7cc97313b91483ed4fed298919ecb16054931ee Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Wed, 7 Aug 2024 21:12:28 +0200 Subject: [PATCH 2/4] doc: Align deprecation warnings --- src/chainparamsbase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 2b57b4ca551..1c1b97430b9 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -17,7 +17,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman) argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. " "This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name' (segwit, bip34, dersig, cltv, csv). (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); - argsman.AddArg("-testnet", "Use the testnet3 chain. Equivalent to -chain=test. Support for testnet3 is deprecated and will be removed with the next release. Consider moving to testnet4 now by using -testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); + argsman.AddArg("-testnet", "Use the testnet3 chain. Equivalent to -chain=test. Support for testnet3 is deprecated and will be removed in an upcoming release. Consider moving to testnet4 now by using -testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-testnet4", "Use the testnet4 chain. Equivalent to -chain=testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-vbparams=deployment:start:end[:min_activation_height]", "Use given start/end times and min_activation_height for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-signet", "Use the signet chain. Equivalent to -chain=signet. Note that the network is defined by the -signetchallenge parameter", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); From 4b2fad502e5c264012e94d2915476f4dfcbd192d Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Wed, 7 Aug 2024 21:28:35 +0200 Subject: [PATCH 3/4] doc: Add release notes for 29775 --- doc/release-notes-29775.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 doc/release-notes-29775.md diff --git a/doc/release-notes-29775.md b/doc/release-notes-29775.md new file mode 100644 index 00000000000..6cb3ed3e8d1 --- /dev/null +++ b/doc/release-notes-29775.md @@ -0,0 +1,10 @@ +Testnet4/BIP94 support +----- + +Support for Testnet4 as specified in [BIP94](https://github.com/bitcoin/bips/blob/master/bip-0094.mediawiki) +has been added. The network can be selected with the `-testnet4` option and +the section header is also named `[testnet4]`. + +While the intention is to phase out support for Testnet3 in an upcoming +version, support for it is still available via the known options in this +release. From 92c1d7d1f8664fe2d259cc609c87f603609b2b60 Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Thu, 8 Aug 2024 22:02:20 +0200 Subject: [PATCH 4/4] validation: Use MAX_TIMEWARP constant as testnet4 timewarp defense delta The value is equal to MAX_FUTURE_BLOCK_TIME. --- src/validation.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index f7250778fcb..f3502b2da6c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -107,6 +107,21 @@ const std::vector CHECKLEVEL_DOC { * */ static constexpr int PRUNE_LOCK_BUFFER{10}; +/** + * Maximum number of seconds that the timestamp of the first + * block of a difficulty adjustment period is allowed to + * be earlier than the last block of the previous period (BIP94). + */ +static constexpr int64_t MAX_TIMEWARP{MAX_FUTURE_BLOCK_TIME}; + +/** + * If the timestamp of the last block in a difficulty period is set + * MAX_FUTURE_BLOCK_TIME seconds in the future, an honest miner should + * be able to mine the first block using the current time. This is not + * a consensus rule, but changing MAX_TIMEWARP should be done with caution. + */ +static_assert(MAX_FUTURE_BLOCK_TIME <= MAX_TIMEWARP); + GlobalMutex g_best_block_mutex; std::condition_variable g_best_block_cv; uint256 g_best_block; @@ -4188,7 +4203,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio // Check timestamp for the first block of each difficulty adjustment // interval, except the genesis block. if (nHeight % consensusParams.DifficultyAdjustmentInterval() == 0) { - if (block.GetBlockTime() < pindexPrev->GetBlockTime() - 60 * 60 * 2) { + if (block.GetBlockTime() < pindexPrev->GetBlockTime() - MAX_TIMEWARP) { return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "time-timewarp-attack", "block's timestamp is too early on diff adjustment block"); } }