Skip to content

Commit ecaa786

Browse files
committed
rpc: add signet_challenge field to getblockchaininfo and getmininginfo
1 parent 477b357 commit ecaa786

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

src/rpc/blockchain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,7 @@ RPCHelpMan getblockchaininfo()
13071307
{RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "height of the last block pruned, plus one (only present if pruning is enabled)"},
13081308
{RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"},
13091309
{RPCResult::Type::NUM, "prune_target_size", /*optional=*/true, "the target size used by pruning (only present if automatic pruning is enabled)"},
1310+
{RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "the block challenge (aka. block script), in hexadecimal (only present if the current network is a signet)"},
13101311
(IsDeprecatedRPCEnabled("warnings") ?
13111312
RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
13121313
RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",
@@ -1351,6 +1352,11 @@ RPCHelpMan getblockchaininfo()
13511352
obj.pushKV("prune_target_size", chainman.m_blockman.GetPruneTarget());
13521353
}
13531354
}
1355+
if (chainman.GetParams().GetChainType() == ChainType::SIGNET) {
1356+
const std::vector<uint8_t>& signet_challenge =
1357+
chainman.GetParams().GetConsensus().signet_challenge;
1358+
obj.pushKV("signet_challenge", HexStr(signet_challenge));
1359+
}
13541360

13551361
NodeContext& node = EnsureAnyNodeContext(request.context);
13561362
obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));

src/rpc/mining.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ static RPCHelpMan getmininginfo()
424424
{RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
425425
{RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
426426
{RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"},
427+
{RPCResult::Type::STR_HEX, "signet_challenge", /*optional=*/true, "The block challenge (aka. block script), in hexadecimal (only present if the current network is a signet)"},
427428
(IsDeprecatedRPCEnabled("warnings") ?
428429
RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
429430
RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",
@@ -453,6 +454,11 @@ static RPCHelpMan getmininginfo()
453454
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
454455
obj.pushKV("pooledtx", (uint64_t)mempool.size());
455456
obj.pushKV("chain", chainman.GetParams().GetChainTypeString());
457+
if (chainman.GetParams().GetChainType() == ChainType::SIGNET) {
458+
const std::vector<uint8_t>& signet_challenge =
459+
chainman.GetParams().GetConsensus().signet_challenge;
460+
obj.pushKV("signet_challenge", HexStr(signet_challenge));
461+
}
456462
obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));
457463
return obj;
458464
},

test/functional/feature_signet.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import assert_equal
1111

12+
SIGNET_DEFAULT_CHALLENGE = '512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae'
13+
1214
signet_blocks = [
1315
'00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf4070001010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff025151feffffff0200f2052a010000001600149243f727dd5343293eb83174324019ec16c2630f0000000000000000776a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf94c4fecc7daa2490047304402205e423a8754336ca99dbe16509b877ef1bf98d008836c725005b3c787c41ebe46022047246e4467ad7cc7f1ad98662afcaf14c115e0095a227c7b05c5182591c23e7e01000120000000000000000000000000000000000000000000000000000000000000000000000000',
1416
'00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b0001010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff025251feffffff0200f2052a01000000160014fd09839740f0e0b4fc6d5e2527e4022aa9b89dfa0000000000000000776a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf94c4fecc7daa24900473044022031d64a1692cdad1fc0ced69838169fe19ae01be524d831b95fcf5ea4e6541c3c02204f9dea0801df8b4d0cd0857c62ab35c6c25cc47c930630dc7fe723531daa3e9b01000120000000000000000000000000000000000000000000000000000000000000000000000000',
@@ -22,21 +24,31 @@
2224
'00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e0001010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff025a51feffffff0200f2052a01000000160014aaa671c82b138e3b8f510cd801e5f2bd0aa305940000000000000000776a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf94c4fecc7daa24900473044022042309f4c3c7a1a2ac8c24f890f962df1c0086cec10be0868087cfc427520cb2702201dafee8911c269b7e786e242045bb57cef3f5b0f177010c6159abae42f646cc501000120000000000000000000000000000000000000000000000000000000000000000000000000',
2325
]
2426

27+
class SignetParams:
28+
def __init__(self, challenge=None):
29+
if challenge is None:
30+
self.challenge = SIGNET_DEFAULT_CHALLENGE
31+
self.shared_args = []
32+
else:
33+
self.challenge = challenge
34+
self.shared_args = [f"-signetchallenge={challenge}"]
2535

2636
class SignetBasicTest(BitcoinTestFramework):
2737
def set_test_params(self):
2838
self.chain = "signet"
2939
self.num_nodes = 6
3040
self.setup_clean_chain = True
31-
shared_args1 = ["-signetchallenge=51"] # OP_TRUE
32-
shared_args2 = [] # default challenge
33-
# we use the exact same challenge except we do it as a 2-of-2, which means it should fail
34-
shared_args3 = ["-signetchallenge=522103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae"]
41+
self.signets = [
42+
SignetParams(challenge='51'), # OP_TRUE
43+
SignetParams(), # default challenge
44+
# default challenge as a 2-of-2, which means it should fail
45+
SignetParams(challenge='522103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae')
46+
]
3547

3648
self.extra_args = [
37-
shared_args1, shared_args1,
38-
shared_args2, shared_args2,
39-
shared_args3, shared_args3,
49+
self.signets[0].shared_args, self.signets[0].shared_args,
50+
self.signets[1].shared_args, self.signets[1].shared_args,
51+
self.signets[2].shared_args, self.signets[2].shared_args,
4052
]
4153

4254
def setup_network(self):
@@ -50,14 +62,28 @@ def setup_network(self):
5062
def run_test(self):
5163
self.log.info("basic tests using OP_TRUE challenge")
5264

65+
self.log.info('getblockchaininfo')
66+
def check_getblockchaininfo(node_idx, signet_idx):
67+
blockchain_info = self.nodes[node_idx].getblockchaininfo()
68+
assert_equal(blockchain_info['chain'], 'signet')
69+
assert_equal(blockchain_info['signet_challenge'], self.signets[signet_idx].challenge)
70+
check_getblockchaininfo(node_idx=1, signet_idx=0)
71+
check_getblockchaininfo(node_idx=2, signet_idx=1)
72+
check_getblockchaininfo(node_idx=5, signet_idx=2)
73+
5374
self.log.info('getmininginfo')
54-
mining_info = self.nodes[0].getmininginfo()
55-
assert_equal(mining_info['blocks'], 0)
56-
assert_equal(mining_info['chain'], 'signet')
57-
assert 'currentblocktx' not in mining_info
58-
assert 'currentblockweight' not in mining_info
59-
assert_equal(mining_info['networkhashps'], Decimal('0'))
60-
assert_equal(mining_info['pooledtx'], 0)
75+
def check_getmininginfo(node_idx, signet_idx):
76+
mining_info = self.nodes[node_idx].getmininginfo()
77+
assert_equal(mining_info['blocks'], 0)
78+
assert_equal(mining_info['chain'], 'signet')
79+
assert 'currentblocktx' not in mining_info
80+
assert 'currentblockweight' not in mining_info
81+
assert_equal(mining_info['networkhashps'], Decimal('0'))
82+
assert_equal(mining_info['pooledtx'], 0)
83+
assert_equal(mining_info['signet_challenge'], self.signets[signet_idx].challenge)
84+
check_getmininginfo(node_idx=0, signet_idx=0)
85+
check_getmininginfo(node_idx=3, signet_idx=1)
86+
check_getmininginfo(node_idx=4, signet_idx=2)
6187

6288
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
6389

0 commit comments

Comments
 (0)