Skip to content

Commit da083d4

Browse files
committed
Merge bitcoin#29775: Testnet4 including PoW difficulty adjustment fix
6bfa260 testnet: Add timewarp attack prevention for Testnet4 (Fabian Jahr) 0100907 testnet: Add Testnet4 difficulty adjustment rules fix (Fabian Jahr) 74a04f9 testnet: Introduce Testnet4 (Fabian Jahr) Pull request description: To supplement the [ongoing conceptual discussion about a testnet reset](https://groups.google.com/g/bitcoindev/c/9bL00vRj7OU/m/9yCPo3uUBwAJ) I have drafted a move to v4 including a fix to the difficulty adjustment mechanism, which was part of the motivation that started the discussion. Conceptual considerations: - The conceptual discussion about doing a testnet4 or softforking the fix into testnet3 is outside of the scope of this PR and I would ask reviewers to contribute their opinions on this on the ML instead. However, I am happy to adapt this PR to a softfork change on testnet3 if there is consensus for that instead. - The difficulty adjustment fix suggested here touches the `CalculateNextWorkRequired` function and uses the same logic used in `GetNextWorkRequired` to find the last previous block that was not mined with difficulty 1 under the exceptionf. An alternative fix briefly mentioned on the mailing list by Jameson Lopp would be to "restrict the special testnet minimum difficulty rule so that it can't be triggered on the block right before a difficulty retarget". That would also fix the issue but I find my suggestion here a bit more elegant. ACKs for top commit: jsarenik: tACK 6bfa260 achow101: ACK 6bfa260 murchandamus: tACK 6bfa260 Tree-SHA512: 0b8b69a621406a944da5be551b863d065358ba94d85dd3b80d83c412660e230ee93b27316081fbee9b4851cc4ff8585db64c7dfa26cb5148ac835663f2712c3d
2 parents 676abd1 + 6bfa260 commit da083d4

28 files changed

+283
-31
lines changed

contrib/completions/bash/bitcoin-cli.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ _bitcoin_rpc() {
99
local rpcargs=()
1010
for i in ${COMP_LINE}; do
1111
case "$i" in
12-
-conf=*|-datadir=*|-regtest|-rpc*|-testnet)
12+
-conf=*|-datadir=*|-regtest|-rpc*|-testnet|-testnet4)
1313
rpcargs=( "${rpcargs[@]}" "$i" )
1414
;;
1515
esac

contrib/seeds/generate-seeds.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
'''
66
Script to generate list of seed nodes for kernel/chainparams.cpp.
77
8-
This script expects two text files in the directory that is passed as an
8+
This script expects three text files in the directory that is passed as an
99
argument:
1010
1111
nodes_main.txt
1212
nodes_test.txt
13+
nodes_testnet4.txt
1314
1415
These files must consist of lines in the format
1516
@@ -171,6 +172,9 @@ def main():
171172
g.write('\n')
172173
with open(os.path.join(indir,'nodes_test.txt'), 'r', encoding="utf8") as f:
173174
process_nodes(g, f, 'chainparams_seed_test')
175+
g.write('\n')
176+
with open(os.path.join(indir,'nodes_testnet4.txt'), 'r', encoding="utf8") as f:
177+
process_nodes(g, f, 'chainparams_seed_testnet4')
174178
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')
175179

176180
if __name__ == '__main__':

doc/REST-interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Unauthenticated REST Interface
44
The REST API can be enabled with the `-rest` option.
55

66
The interface runs on the same port as the JSON-RPC interface, by default port 8332 for mainnet, port 18332 for testnet,
7-
port 38332 for signet, and port 18443 for regtest.
7+
port 48332 for testnet4, port 38332 for signet, and port 18443 for regtest.
88

99
REST Interface consistency guarantees
1010
-------------------------------------

doc/files.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ Windows | `%LOCALAPPDATA%\Bitcoin\` <sup>[\[1\]](#note1)</sup>
3434

3535
3. All content of the data directory, except for `bitcoin.conf` file, is chain-specific. This means the actual data directory paths for non-mainnet cases differ:
3636

37-
Chain option | Data directory path
38-
-------------------------------|------------------------------
39-
`-chain=main` (default) | *path_to_datadir*`/`
40-
`-chain=test` or `-testnet` | *path_to_datadir*`/testnet3/`
41-
`-chain=signet` or `-signet` | *path_to_datadir*`/signet/`
42-
`-chain=regtest` or `-regtest` | *path_to_datadir*`/regtest/`
37+
Chain option | Data directory path
38+
---------------------------------|------------------------------
39+
`-chain=main` (default) | *path_to_datadir*`/`
40+
`-chain=test` or `-testnet` | *path_to_datadir*`/testnet3/`
41+
`-chain=testnet4` or `-testnet4` | *path_to_datadir*`/testnet4/`
42+
`-chain=signet` or `-signet` | *path_to_datadir*`/signet/`
43+
`-chain=regtest` or `-regtest` | *path_to_datadir*`/regtest/`
4344

4445
## Data directory layout
4546

doc/release-process.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,15 @@ Both variables are used as a guideline for how much space the user needs on thei
311311
Note that all values should be taken from a **fully synced** node and have an overhead of 5-10% added on top of its base value.
312312

313313
To calculate `m_assumed_blockchain_size`, take the size in GiB of these directories:
314-
- For `mainnet` -> the data directory, excluding the `/testnet3`, `/signet`, and `/regtest` directories and any overly large files, e.g. a huge `debug.log`
314+
- For `mainnet` -> the data directory, excluding the `/testnet3`, `/testnet4`, `/signet`, and `/regtest` directories and any overly large files, e.g. a huge `debug.log`
315315
- For `testnet` -> `/testnet3`
316+
- For `testnet4` -> `/testnet4`
316317
- For `signet` -> `/signet`
317318

318319
To calculate `m_assumed_chain_state_size`, take the size in GiB of these directories:
319320
- For `mainnet` -> `/chainstate`
320321
- For `testnet` -> `/testnet3/chainstate`
322+
- For `testnet4` -> `/testnet4/chainstate`
321323
- For `signet` -> `/signet/chainstate`
322324

323325
Notes:

src/bitcoin-cli.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static void SetupCliArgs(ArgsManager& argsman)
7575

7676
const auto defaultBaseParams = CreateBaseChainParams(ChainType::MAIN);
7777
const auto testnetBaseParams = CreateBaseChainParams(ChainType::TESTNET);
78+
const auto testnet4BaseParams = CreateBaseChainParams(ChainType::TESTNET4);
7879
const auto signetBaseParams = CreateBaseChainParams(ChainType::SIGNET);
7980
const auto regtestBaseParams = CreateBaseChainParams(ChainType::REGTEST);
8081

@@ -98,7 +99,7 @@ static void SetupCliArgs(ArgsManager& argsman)
9899
argsman.AddArg("-rpcconnect=<ip>", strprintf("Send commands to node running on <ip> (default: %s)", DEFAULT_RPCCONNECT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
99100
argsman.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
100101
argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
101-
argsman.AddArg("-rpcport=<port>", strprintf("Connect to JSON-RPC on <port> (default: %u, testnet: %u, signet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), signetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
102+
argsman.AddArg("-rpcport=<port>", strprintf("Connect to JSON-RPC on <port> (default: %u, testnet: %u, testnet4: %u, signet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), testnet4BaseParams->RPCPort(), signetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
102103
argsman.AddArg("-rpcuser=<user>", "Username for JSON-RPC connections", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
103104
argsman.AddArg("-rpcwait", "Wait for RPC server to start", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
104105
argsman.AddArg("-rpcwaittimeout=<n>", strprintf("Timeout in seconds to wait for the RPC server to start, or 0 for no timeout. (default: %d)", DEFAULT_WAIT_CLIENT_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
@@ -428,6 +429,8 @@ class NetinfoRequestHandler : public BaseRequestHandler
428429
std::string ChainToString() const
429430
{
430431
switch (gArgs.GetChainType()) {
432+
case ChainType::TESTNET4:
433+
return " testnet4";
431434
case ChainType::TESTNET:
432435
return " testnet";
433436
case ChainType::SIGNET:

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static std::optional<int> WalletAppInit(ArgsManager& args, int argc, char* argv[
6969
strUsage += "\n"
7070
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
7171
"By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"
72-
"To change the target wallet, use the -datadir, -wallet and -regtest/-signet/-testnet arguments.\n\n"
72+
"To change the target wallet, use the -datadir, -wallet and -regtest/-signet/-testnet/-testnet4 arguments.\n\n"
7373
"Usage:\n"
7474
" bitcoin-wallet [options] <command>\n";
7575
strUsage += "\n" + args.GetHelpMessage();

src/chainparams.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
115115
return CChainParams::Main();
116116
case ChainType::TESTNET:
117117
return CChainParams::TestNet();
118+
case ChainType::TESTNET4:
119+
return CChainParams::TestNet4();
118120
case ChainType::SIGNET: {
119121
auto opts = CChainParams::SigNetOptions{};
120122
ReadSigNetArgs(args, opts);

src/chainparamsbase.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman)
1717
argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
1818
"This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
1919
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);
20-
argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
20+
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);
21+
argsman.AddArg("-testnet4", "Use the testnet4 chain. Equivalent to -chain=testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2122
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);
2223
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);
2324
argsman.AddArg("-signetchallenge", "Blocks must satisfy the given script to be considered valid (only for signet networks; defaults to the global default signet test network challenge)", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::CHAINPARAMS);
@@ -33,7 +34,7 @@ const CBaseChainParams& BaseParams()
3334
}
3435

3536
/**
36-
* Port numbers for incoming Tor connections (8334, 18334, 38334, 18445) have
37+
* Port numbers for incoming Tor connections (8334, 18334, 38334, 48334, 18445) have
3738
* been chosen arbitrarily to keep ranges of used ports tight.
3839
*/
3940
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain)
@@ -43,6 +44,8 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain)
4344
return std::make_unique<CBaseChainParams>("", 8332, 8334);
4445
case ChainType::TESTNET:
4546
return std::make_unique<CBaseChainParams>("testnet3", 18332, 18334);
47+
case ChainType::TESTNET4:
48+
return std::make_unique<CBaseChainParams>("testnet4", 48332, 48334);
4649
case ChainType::SIGNET:
4750
return std::make_unique<CBaseChainParams>("signet", 38332, 38334);
4851
case ChainType::REGTEST:

src/chainparamsseeds.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,4 +1786,16 @@ static const uint8_t chainparams_seed_test[] = {
17861786
0x04,0x20,0xbd,0x0e,0xc8,0x73,0x43,0xa7,0xc6,0x25,0x15,0xcf,0x3e,0x23,0xa8,0xb0,0xbf,0xe8,0x20,0xa7,0xec,0x2a,0xf6,0x37,0x6c,0x60,0x5e,0x4d,0xed,0xf4,0xb1,0xef,0xf7,0xb2,0x47,0x9d,
17871787
0x04,0x20,0xc8,0x88,0xfe,0x71,0x5f,0xa3,0x6c,0x96,0x6a,0xd7,0x9e,0x38,0x84,0x9f,0x44,0xe1,0x6b,0xdc,0x98,0x31,0xad,0x96,0x29,0xe7,0x00,0x83,0x63,0x03,0xae,0x69,0x2e,0x63,0x47,0x9d,
17881788
};
1789+
1790+
static const uint8_t chainparams_seed_testnet4[] = {
1791+
0x01,0x04,0x39,0x80,0xb0,0xa3,0xbc,0xcd,
1792+
0x01,0x04,0x33,0x9e,0xf8,0x08,0xbc,0xcd,
1793+
0x01,0x04,0x5f,0xd9,0x49,0xa2,0xbc,0xcd,
1794+
0x01,0x04,0x12,0xbd,0x9c,0x66,0xbc,0xcd,
1795+
0x01,0x04,0x67,0x63,0xab,0xd4,0xbc,0xcd,
1796+
0x01,0x04,0x52,0x43,0x66,0x0f,0xbc,0xcd,
1797+
0x01,0x04,0x58,0x63,0xf8,0x32,0xbc,0xcd,
1798+
0x01,0x04,0x67,0xa5,0xc0,0xd2,0xbc,0xcd,
1799+
0x01,0x04,0x12,0xc9,0xcf,0x37,0xbc,0xcd,
1800+
};
17891801
#endif // BITCOIN_CHAINPARAMSSEEDS_H

src/common/args.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const
159159
ChainTypeToString(ChainType::REGTEST),
160160
ChainTypeToString(ChainType::SIGNET),
161161
ChainTypeToString(ChainType::TESTNET),
162+
ChainTypeToString(ChainType::TESTNET4),
162163
ChainTypeToString(ChainType::MAIN),
163164
};
164165

@@ -773,10 +774,11 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
773774
const bool fRegTest = get_net("-regtest");
774775
const bool fSigNet = get_net("-signet");
775776
const bool fTestNet = get_net("-testnet");
777+
const bool fTestNet4 = get_net("-testnet4");
776778
const auto chain_arg = GetArg("-chain");
777779

778-
if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
779-
throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
780+
if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet + (int)fTestNet4 > 1) {
781+
throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet, -testnet4 and -chain. Can use at most one.");
780782
}
781783
if (chain_arg) {
782784
if (auto parsed = ChainTypeFromString(*chain_arg)) return *parsed;
@@ -786,6 +788,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
786788
if (fRegTest) return ChainType::REGTEST;
787789
if (fSigNet) return ChainType::SIGNET;
788790
if (fTestNet) return ChainType::TESTNET;
791+
if (fTestNet4) return ChainType::TESTNET4;
789792
return ChainType::MAIN;
790793
}
791794

src/common/args.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ class ArgsManager
423423
fs::path GetDataDir(bool net_specific) const;
424424

425425
/**
426-
* Return -regtest/-signet/-testnet/-chain= setting as a ChainType enum if a
426+
* Return -regtest/-signet/-testnet/-testnet4/-chain= setting as a ChainType enum if a
427427
* recognized chain type was set, or as a string if an unrecognized chain
428428
* name was set. Raise an exception if an invalid combination of flags was
429429
* provided.

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct Params {
108108
/** Proof of work parameters */
109109
uint256 powLimit;
110110
bool fPowAllowMinDifficultyBlocks;
111+
bool enforce_BIP94;
111112
bool fPowNoRetargeting;
112113
int64_t nPowTargetSpacing;
113114
int64_t nPowTargetTimespan;

0 commit comments

Comments
 (0)