rpc: Add signet_challenge field to getblockchaininfo and getmininginfo #31531

pull A-Manning wants to merge 1 commits into bitcoin:master from A-Manning:signet-rpc changing 3 files +52 −14
  1. A-Manning commented at 3:42 pm on December 18, 2024: none

    Signet challenges are currently only available via getblocktemplate RPC. getblockchaininfo and getmininginfo both provide inadequate information to distinguish signets. Since these are the RPCs used to determine the current network, they should also provide the signet challenge for signets.

    Test coverage is included in test/functional/feature_signet.py.

  2. DrahtBot commented at 3:42 pm on December 18, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31531.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK Sjors, zaidmstrr, sipa
    Concept ACK pinheadmz, i-am-yuvi, BrandonOdiwuor, kallewoof

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29365 (Extend signetchallenge to set target block spacing by starius)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label RPC/REST/ZMQ on Dec 18, 2024
  4. pinheadmz commented at 3:53 pm on December 18, 2024: member
    concept ACK, I’ve needed the signet challenge before from RPC (to determine network magic bytes for warnet) and it seems like it should be available from a pure “getter” rather than GBT which also requires parameters like "rules"
  5. in test/functional/feature_signet.py:33 in f37c737fa4 outdated
    30         self.setup_clean_chain = True
    31-        shared_args1 = ["-signetchallenge=51"]  # OP_TRUE
    32+
    33+        self.signet_challenge1 = '51' # OP_TRUE
    34+        # signet 2 uses the default challenge
    35+        self.signet_challenge2 = '512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae'
    


    Sjors commented at 6:57 am on December 19, 2024:
    nit: could make this a constant: SIGNET_DEFAULT_CHALLENGE = ... at the top.

    A-Manning commented at 9:43 am on December 19, 2024:
    Resolved in 4a21c49e26e78a2820b9603cf765710323efd700
  6. in test/functional/feature_signet.py:31 in f37c737fa4 outdated
    28         self.chain = "signet"
    29         self.num_nodes = 6
    30         self.setup_clean_chain = True
    31-        shared_args1 = ["-signetchallenge=51"]  # OP_TRUE
    32+
    33+        self.signet_challenge1 = '51' # OP_TRUE
    


    Sjors commented at 6:58 am on December 19, 2024:
    nit: could make self.signet_challenges an array, which is a more common pattern in the tests.

    A-Manning commented at 9:43 am on December 19, 2024:
    Resolved in 4a21c49e26e78a2820b9603cf765710323efd700
  7. in test/functional/feature_signet.py:93 in f37c737fa4 outdated
     95+        assert_equal(mining_info3['chain'], 'signet')
     96+        assert_equal(mining_info3['signet_challenge'], self.signet_challenge3)
     97 
     98         self.generate(self.nodes[0], 1, sync_fun=self.no_op)
     99 
    100+
    


    Sjors commented at 6:58 am on December 19, 2024:
    nit: stray new blank line

    A-Manning commented at 9:43 am on December 19, 2024:
    Resolved in 4a21c49e26e78a2820b9603cf765710323efd700
  8. Sjors approved
  9. Sjors commented at 7:05 am on December 19, 2024: member

    tACK f37c737fa44c101d46afca4632dc67a867de8c0d

    Tested against testnet4 (no field), default signet and a custom OP_TRUE signet.

    P.S. if you like this PR, you may also like #29032

  10. DrahtBot requested review from pinheadmz on Dec 19, 2024
  11. A-Manning requested review from Sjors on Dec 19, 2024
  12. Sjors commented at 11:10 am on December 19, 2024: member

    @A-Manning thanks, can you squash the commits?

    cc @maflcko

  13. A-Manning force-pushed on Dec 19, 2024
  14. A-Manning commented at 11:16 am on December 19, 2024: none

    @Sjors

    thanks, can you squash the commits?

    Squashed in ccb41ce0e782470a5e6e9d95a8bd337a1d07adcf

  15. in test/functional/feature_signet.py:45 in ccb41ce0e7 outdated
    50+
    51+        self.signets = [
    52+            SignetParams(challenge='51'), # OP_TRUE
    53+            SignetParams(), # default challenge
    54+            # default challenge as a 2-of-2, which means it should fail
    55+            SignetParams(challenge='522103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae')
    


    Sjors commented at 11:19 am on December 19, 2024:
    nit: wrong indentation and unnecessary blank line
  16. in test/functional/feature_signet.py:49 in ccb41ce0e7 outdated
    57 
    58         self.extra_args = [
    59-            shared_args1, shared_args1,
    60-            shared_args2, shared_args2,
    61-            shared_args3, shared_args3,
    62+            self.signets[0].shared_args, self.signets[0].shared_args,
    


    Sjors commented at 11:21 am on December 19, 2024:
    I don’t understand why this was duplicated in the original version. @kallewoof do you remember?

    kallewoof commented at 0:07 am on December 20, 2024:

    Makes no sense to me. I read through the entire thread in #18267 where this was added, and it looks like I put it there right at the end before it was merged, so it may have slipped under the radar.

    Anyway, my suggestion: remove the duplication. Try the tests. If the tests fail, we know this at least has a purpose.


    Sjors commented at 1:50 am on December 20, 2024:
    Oh I get it now. There’s two nodes for each signet, six in total. So this is fine.

    kallewoof commented at 1:59 am on December 20, 2024:
    3 sets of pairs of nodes where each pair shares their set of args? OK, that sounds reasonable.
  17. in test/functional/feature_signet.py:76 in ccb41ce0e7 outdated
    79-        assert_equal(mining_info['chain'], 'signet')
    80-        assert 'currentblocktx' not in mining_info
    81-        assert 'currentblockweight' not in mining_info
    82-        assert_equal(mining_info['networkhashps'], Decimal('0'))
    83-        assert_equal(mining_info['pooledtx'], 0)
    84+        # mining info for node on signet 0
    


    Sjors commented at 11:24 am on December 19, 2024:
    Maybe also add a check_getmininginfo helper?

    A-Manning commented at 12:24 pm on December 19, 2024:
    Added in edc34044362628f2994cb5fa5de74ca49fce0fd1
  18. A-Manning force-pushed on Dec 19, 2024
  19. A-Manning force-pushed on Dec 19, 2024
  20. rpc: add signet_challenge field to getblockchaininfo and getmininginfo ecaa786cc1
  21. in test/functional/feature_signet.py:75 in edc3404436 outdated
    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+        def check_getmininginfo(node_idx, signet_idx):
    


    Sjors commented at 1:53 am on December 20, 2024:

    Thanks for adding the helper. But now it’s inconsistent with the check_getblockchaininfo helper. No strong preference for which style to use.

    Maybe make it def check_getmininginfo(self, node_idx, signet_idx): and check_getblockchaininfo(self, node_idx, signet_idx) and put them above run_test.


    A-Manning commented at 10:01 am on December 20, 2024:
    Both helper functions are internal to run_test in ecaa786cc103cf7cc63ae899ec13d81a54e2fd1e. check_getmininginfo makes specific assertions on values for fields such as blocks, which may change during a test. It is best to keep it as localized as possible, since it is unlikely to be broadly useful.
  22. A-Manning force-pushed on Dec 20, 2024
  23. A-Manning requested review from Sjors on Dec 20, 2024
  24. i-am-yuvi approved
  25. i-am-yuvi commented at 7:44 pm on December 20, 2024: none

    Concept ACK ecaa786cc103cf7cc63ae899ec13d81a54e2fd1e

    Both the RPC seems to be giving enough information about the signet challenges!! Thanks @A-Manning for this!!

    I have used custom signet(OP_TRUE) on Linux x86_64:

    getblockchaininfo:

     0{
     1  "chain": "signet",
     2  "blocks": 0,
     3  "headers": 0,
     4  "bestblockhash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
     5  "difficulty": 0.001126515290698186,
     6  "time": 1598918400,
     7  "mediantime": 1598918400,
     8  "verificationprogress": 1,
     9  "initialblockdownload": true,
    10  "chainwork": "000000000000000000000000000000000000000000000000000000000049d414",
    11  "size_on_disk": 293,
    12  "pruned": false,
    13  "signet_challenge": "512102ee856c56a5aaadd1656f849bafa4c9dacc86a2878fe546c6189185f842ae2c1851ae",
    14  "warnings": [
    15    "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
    16  ]
    17}
    

    getmininginfo:

     0{
     1  "blocks": 0,
     2  "difficulty": 0.001126515290698186,
     3  "networkhashps": 0,
     4  "pooledtx": 0,
     5  "chain": "signet",
     6  "signet_challenge": "512102ee856c56a5aaadd1656f849bafa4c9dacc86a2878fe546c6189185f842ae2c1851ae",
     7  "warnings": [
     8    "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
     9  ]
    10}
    

    The test also seems to pass:

     0./build/test/functional/test_runner.py feature_signet.py
     1Temporary test directory at /tmp/test_runner_₿_🏃_20241221_004806
     2Remaining jobs: [feature_signet.py]
     31/1 - feature_signet.py passed, Duration: 1 s
     4
     5TEST              | STATUS    | DURATION
     6
     7feature_signet.py | ✓ Passed  | 1 s
     8
     9ALL               | ✓ Passed  | 1 s (accumulated) 
    10Runtime: 1 s
    
  26. Sjors approved
  27. Sjors commented at 2:42 am on December 21, 2024: member
    ACK ecaa786cc103cf7cc63ae899ec13d81a54e2fd1e
  28. DrahtBot requested review from i-am-yuvi on Dec 21, 2024
  29. BrandonOdiwuor commented at 11:35 am on December 21, 2024: contributor
    Concept ACK
  30. in src/rpc/blockchain.cpp:1310 in ecaa786cc1
    1306@@ -1307,6 +1307,7 @@ RPCHelpMan getblockchaininfo()
    1307                 {RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "height of the last block pruned, plus one (only present if pruning is enabled)"},
    1308                 {RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"},
    1309                 {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)"},
    


    kallewoof commented at 2:17 pm on December 21, 2024:
    When used as an argument it is -signetchallenge, perhaps use that here as well.

    A-Manning commented at 10:31 pm on December 21, 2024:
    signet_challenge is consistent with getblocktemplate https://github.com/bitcoin/bitcoin/blob/master/src/rpc/mining.cpp#L660

    Sjors commented at 8:12 am on December 24, 2024:
    Indeed the general pattern seems to be that for RPC we use argument_name whereas for startup arguments we use -argumentname.
  31. in src/rpc/mining.cpp:427 in ecaa786cc1
    423@@ -424,6 +424,7 @@ static RPCHelpMan getmininginfo()
    424                         {RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
    425                         {RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
    426                         {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)"},
    


    kallewoof commented at 2:17 pm on December 21, 2024:
    See above note about -signetchallenge.

    A-Manning commented at 10:31 pm on December 21, 2024:
    signet_challenge is consistent with getblocktemplate https://github.com/bitcoin/bitcoin/blob/master/src/rpc/mining.cpp#L660
  32. kallewoof commented at 11:23 pm on December 21, 2024: contributor
    Concept ACK
  33. zaidmstrr approved
  34. zaidmstrr commented at 8:00 am on December 23, 2024: none
    Tested ACK ecaa786 I tested the changes on the default signet and the result provided by both getblockchaininfo and getmininginfo RPC includes signet_challenge field. I also manually reviewed the new code for any errors and missing statements. The updated test test/functional/feature_signet.py also works fine.
  35. DrahtBot requested review from BrandonOdiwuor on Dec 23, 2024
  36. DrahtBot requested review from kallewoof on Dec 23, 2024
  37. kallewoof approved
  38. DrahtBot requested review from kallewoof on Dec 23, 2024
  39. sipa commented at 3:16 pm on December 23, 2024: member
    utACK ecaa786cc103cf7cc63ae899ec13d81a54e2fd1e

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-30 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me