-
-
Notifications
You must be signed in to change notification settings - Fork 368
RPC: accept coinbase_message in getblocktemplate for pprpcsb solo mining #1948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reubenyap
wants to merge
1
commit into
master
Choose a base branch
from
claude/firo-solo-coinbase-messages-xinqab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2026 The Firo Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
| """Test coinbase messages for solo mining through getblocktemplate and pprpcsb. | ||
|
|
||
| getblocktemplate({"coinbase_message": text}, reward_address) puts text into the | ||
| coinbase of the block the node builds for pprpcsb and echoes it in the result. | ||
| """ | ||
|
|
||
| import time | ||
|
|
||
| from test_framework.test_framework import BitcoinTestFramework | ||
| from test_framework.util import assert_equal, assert_raises_jsonrpc, connect_nodes_bi, start_nodes, sync_blocks | ||
|
|
||
| RPC_TYPE_ERROR = -3 | ||
| RPC_INVALID_PARAMETER = -8 | ||
| RPC_INVALID_PARAMS = -32602 | ||
|
|
||
|
|
||
| class GetBlockTemplateCoinbaseMessageTest(BitcoinTestFramework): | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.num_nodes = 2 | ||
| self.setup_clean_chain = False | ||
|
|
||
| def setup_network(self): | ||
| # ProgPoW has to be active on regtest for getblocktemplate to hand out pprpcsb jobs | ||
| args = ['-ppswitchtime=%d' % (int(time.time()) - 10)] | ||
| self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [args] * self.num_nodes) | ||
| connect_nodes_bi(self.nodes, 0, 1) | ||
| self.is_network_split = False | ||
| self.sync_all() | ||
|
|
||
| def run_test(self): | ||
| node = self.nodes[0] | ||
| node.generate(1) # getblocktemplate refuses to work on a stale tip | ||
| sync_blocks(self.nodes) | ||
| address = node.getnewaddress() | ||
|
|
||
| plain = node.getblocktemplate({}, address) | ||
| assert 'coinbase_message' not in plain | ||
|
|
||
| # The message is acknowledged and, being part of the coinbase, changes the job | ||
| hello = node.getblocktemplate({'coinbase_message': 'hello'}, address) | ||
| assert_equal(hello['coinbase_message'], 'hello') | ||
| assert hello['pprpcheader'] != plain['pprpcheader'] | ||
|
|
||
| # The same request keeps its job while it is fresh; a different message gets a job of its own | ||
| assert_equal(node.getblocktemplate({'coinbase_message': 'hello'}, address)['pprpcheader'], hello['pprpcheader']) | ||
| world = node.getblocktemplate({'coinbase_message': 'world'}, address) | ||
| assert world['pprpcheader'] not in (plain['pprpcheader'], hello['pprpcheader']) | ||
|
|
||
| # An empty message gives back the job built from the original coinbase | ||
| assert_equal(node.getblocktemplate({'coinbase_message': ''}, address)['pprpcheader'], plain['pprpcheader']) | ||
|
|
||
| # Every job handed out can still be submitted: a wrong solution is a bad solution, not an unknown job | ||
| for header in (plain['pprpcheader'], hello['pprpcheader'], world['pprpcheader']): | ||
| assert_raises_jsonrpc(RPC_INVALID_PARAMS, 'Bad solution', node.pprpcsb, header, '00' * 32, '0x1') | ||
|
|
||
| # 80 UTF-8 bytes fit, more do not, and the value must be a string | ||
| longest = 'a' * 80 | ||
| assert_equal(node.getblocktemplate({'coinbase_message': longest}, address)['coinbase_message'], longest) | ||
| assert_raises_jsonrpc(RPC_INVALID_PARAMETER, 'too long', node.getblocktemplate, {'coinbase_message': longest + 'a'}, address) | ||
| assert_raises_jsonrpc(RPC_INVALID_PARAMETER, 'too long', node.getblocktemplate, {'coinbase_message': 'é' * 41}, address) | ||
| assert_raises_jsonrpc(RPC_TYPE_ERROR, 'must be a string', node.getblocktemplate, {'coinbase_message': 1}, address) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| GetBlockTemplateCoinbaseMessageTest().main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Add
reward_addressto the command synopsis.The heading documents
getblocktemplate [template_request], but this argument list defines a second positional argument. Change the synopsis togetblocktemplate [template_request] [reward_address].🤖 Prompt for AI Agents