Skip to content

Commit e8990f1

Browse files
kallewoofajtowns
andcommitted
add signet chain and accompanying parameters
Co-authored-by: Anthony Towns <[email protected]>
1 parent 404682b commit e8990f1

File tree

5 files changed

+117
-11
lines changed

5 files changed

+117
-11
lines changed

src/chainparams.cpp

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <chainparamsseeds.h>
99
#include <consensus/merkle.h>
10+
#include <hash.h> // for signet block challenge hash
1011
#include <tinyformat.h>
1112
#include <util/system.h>
1213
#include <util/strencodings.h>
@@ -63,6 +64,8 @@ class CMainParams : public CChainParams {
6364
public:
6465
CMainParams() {
6566
strNetworkID = CBaseChainParams::MAIN;
67+
consensus.signet_blocks = false;
68+
consensus.signet_challenge.clear();
6669
consensus.nSubsidyHalvingInterval = 210000;
6770
consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
6871
consensus.BIP34Height = 227931;
@@ -172,6 +175,8 @@ class CTestNetParams : public CChainParams {
172175
public:
173176
CTestNetParams() {
174177
strNetworkID = CBaseChainParams::TESTNET;
178+
consensus.signet_blocks = false;
179+
consensus.signet_challenge.clear();
175180
consensus.nSubsidyHalvingInterval = 210000;
176181
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
177182
consensus.BIP34Height = 21111;
@@ -250,13 +255,98 @@ class CTestNetParams : public CChainParams {
250255
}
251256
};
252257

258+
/**
259+
* Signet
260+
*/
261+
class SigNetParams : public CChainParams {
262+
public:
263+
explicit SigNetParams(const ArgsManager& args) {
264+
std::vector<uint8_t> bin;
265+
vSeeds.clear();
266+
267+
if (!args.IsArgSet("-signetchallenge")) {
268+
throw std::runtime_error(strprintf("%s: -signetchallenge is mandatory for signet networks", __func__));
269+
}
270+
const auto signet_challenge = args.GetArgs("-signetchallenge");
271+
if (signet_challenge.size() != 1) {
272+
throw std::runtime_error(strprintf("%s: -signetchallenge cannot be multiple values.", __func__));
273+
}
274+
bin = ParseHex(signet_challenge[0]);
275+
if (args.IsArgSet("-signetseednode")) {
276+
vSeeds = args.GetArgs("-signetseednode");
277+
}
278+
279+
LogPrintf("Signet with challenge %s\n", signet_challenge[0]);
280+
281+
strNetworkID = CBaseChainParams::SIGNET;
282+
consensus.signet_blocks = true;
283+
consensus.signet_challenge.assign(bin.begin(), bin.end());
284+
consensus.nSubsidyHalvingInterval = 210000;
285+
consensus.BIP34Height = 1;
286+
consensus.BIP65Height = 1;
287+
consensus.BIP66Height = 1;
288+
consensus.CSVHeight = 1;
289+
consensus.SegwitHeight = 1;
290+
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
291+
consensus.nPowTargetSpacing = 10 * 60;
292+
consensus.fPowAllowMinDifficultyBlocks = false;
293+
consensus.fPowNoRetargeting = false;
294+
consensus.nRuleChangeActivationThreshold = 1916;
295+
consensus.nMinerConfirmationWindow = 2016;
296+
consensus.powLimit = uint256S("00000377ae000000000000000000000000000000000000000000000000000000");
297+
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
298+
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
299+
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
300+
301+
// message start is defined as the first 4 bytes of the sha256d of the block script
302+
CHashWriter h(SER_DISK, 0);
303+
h << consensus.signet_challenge;
304+
uint256 hash = h.GetHash();
305+
memcpy(pchMessageStart, hash.begin(), 4);
306+
LogPrintf("Signet derived magic (message start): %s\n", HexStr({pchMessageStart, pchMessageStart + 4}));
307+
308+
nDefaultPort = 38333;
309+
nPruneAfterHeight = 1000;
310+
m_assumed_blockchain_size = 0;
311+
m_assumed_chain_state_size = 0;
312+
313+
genesis = CreateGenesisBlock(1598918400, 52613770, 0x1e0377ae, 1, 50 * COIN);
314+
consensus.hashGenesisBlock = genesis.GetHash();
315+
assert(consensus.hashGenesisBlock == uint256S("0x00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6"));
316+
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
317+
318+
vFixedSeeds.clear();
319+
320+
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
321+
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
322+
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
323+
base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
324+
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
325+
326+
bech32_hrp = "tb";
327+
328+
fDefaultConsistencyChecks = false;
329+
fRequireStandard = true;
330+
m_is_test_chain = true;
331+
m_is_mockable_chain = false;
332+
333+
chainTxData = ChainTxData{
334+
0,
335+
0,
336+
0
337+
};
338+
}
339+
};
340+
253341
/**
254342
* Regression test
255343
*/
256344
class CRegTestParams : public CChainParams {
257345
public:
258346
explicit CRegTestParams(const ArgsManager& args) {
259347
strNetworkID = CBaseChainParams::REGTEST;
348+
consensus.signet_blocks = false;
349+
consensus.signet_challenge.clear();
260350
consensus.nSubsidyHalvingInterval = 150;
261351
consensus.BIP16Exception = uint256();
262352
consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
@@ -391,12 +481,15 @@ const CChainParams &Params() {
391481

392482
std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
393483
{
394-
if (chain == CBaseChainParams::MAIN)
484+
if (chain == CBaseChainParams::MAIN) {
395485
return std::unique_ptr<CChainParams>(new CMainParams());
396-
else if (chain == CBaseChainParams::TESTNET)
486+
} else if (chain == CBaseChainParams::TESTNET) {
397487
return std::unique_ptr<CChainParams>(new CTestNetParams());
398-
else if (chain == CBaseChainParams::REGTEST)
488+
} else if (chain == CBaseChainParams::SIGNET) {
489+
return std::unique_ptr<CChainParams>(new SigNetParams(gArgs));
490+
} else if (chain == CBaseChainParams::REGTEST) {
399491
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
492+
}
400493
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
401494
}
402495

src/chainparamsbase.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
const std::string CBaseChainParams::MAIN = "main";
1515
const std::string CBaseChainParams::TESTNET = "test";
16+
const std::string CBaseChainParams::SIGNET = "signet";
1617
const std::string CBaseChainParams::REGTEST = "regtest";
1718

1819
void SetupChainParamsBaseOptions(ArgsManager& argsman)
@@ -23,6 +24,9 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman)
2324
argsman.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
2425
argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2526
argsman.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
27+
argsman.AddArg("-signet", "Use the signet chain. Note that the network is defined by the -signetchallenge parameter", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
28+
argsman.AddArg("-signetchallenge", "Blocks must satisfy the given script to be considered valid (only for signet networks)", ArgsManager::ALLOW_STRING, OptionsCategory::CHAINPARAMS);
29+
argsman.AddArg("-signetseednode", "Specify a seed node for the signet network, in the hostname[:port] format, e.g. sig.net:1234 (may be used multiple times to specify multiple seed nodes)", ArgsManager::ALLOW_STRING, OptionsCategory::CHAINPARAMS);
2630
}
2731

2832
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
@@ -35,14 +39,16 @@ const CBaseChainParams& BaseParams()
3539

3640
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
3741
{
38-
if (chain == CBaseChainParams::MAIN)
42+
if (chain == CBaseChainParams::MAIN) {
3943
return MakeUnique<CBaseChainParams>("", 8332);
40-
else if (chain == CBaseChainParams::TESTNET)
44+
} else if (chain == CBaseChainParams::TESTNET) {
4145
return MakeUnique<CBaseChainParams>("testnet3", 18332);
42-
else if (chain == CBaseChainParams::REGTEST)
46+
} else if (chain == CBaseChainParams::SIGNET) {
47+
return MakeUnique<CBaseChainParams>("signet", 38332);
48+
} else if (chain == CBaseChainParams::REGTEST) {
4349
return MakeUnique<CBaseChainParams>("regtest", 18443);
44-
else
45-
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
50+
}
51+
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
4652
}
4753

4854
void SelectBaseParams(const std::string& chain)

src/chainparamsbase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CBaseChainParams
2121
/** Chain name strings */
2222
static const std::string MAIN;
2323
static const std::string TESTNET;
24+
static const std::string SIGNET;
2425
static const std::string REGTEST;
2526
///@}
2627

src/test/util_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup)
11061106
// Results file is formatted like:
11071107
//
11081108
// <input> || <output>
1109-
BOOST_CHECK_EQUAL(out_sha_hex, "f0b3a3c29869edc765d579c928f7f1690a71fbb673b49ccf39cbc4de18156a0d");
1109+
BOOST_CHECK_EQUAL(out_sha_hex, "f263493e300023b6509963887444c41386f44b63bc30047eb8402e8c1144854c");
11101110
}
11111111

11121112
BOOST_AUTO_TEST_CASE(util_ReadWriteSettings)

src/util/system.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ const std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const
263263
// Section names to be recognized in the config file.
264264
static const std::set<std::string> available_sections{
265265
CBaseChainParams::REGTEST,
266+
CBaseChainParams::SIGNET,
266267
CBaseChainParams::TESTNET,
267268
CBaseChainParams::MAIN
268269
};
@@ -916,16 +917,21 @@ std::string ArgsManager::GetChainName() const
916917
};
917918

918919
const bool fRegTest = get_net("-regtest");
920+
const bool fSigNet = get_net("-signet");
919921
const bool fTestNet = get_net("-testnet");
920922
const bool is_chain_arg_set = IsArgSet("-chain");
921923

922-
if ((int)is_chain_arg_set + (int)fRegTest + (int)fTestNet > 1) {
923-
throw std::runtime_error("Invalid combination of -regtest, -testnet and -chain. Can use at most one.");
924+
if ((int)is_chain_arg_set + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
925+
throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
924926
}
925927
if (fRegTest)
926928
return CBaseChainParams::REGTEST;
929+
if (fSigNet) {
930+
return CBaseChainParams::SIGNET;
931+
}
927932
if (fTestNet)
928933
return CBaseChainParams::TESTNET;
934+
929935
return GetArg("-chain", CBaseChainParams::MAIN);
930936
}
931937

0 commit comments

Comments
 (0)