Conversation
Note to reviewers: This pull request conflicts with the following ones:
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. |
|
Your OP is empty - can you provide rationale what this is to be used for? |
|
I asked for this as a part of my BetterHash mining protocol work, however I've also wanted this at several points in order to be able to implement chain-sync logic outside of bitcoind over RPC. You'd need this or something like it to do headers-first sync in such a system. |
src/validation.h
Outdated
There was a problem hiding this comment.
Commit "rpc: Expose ProcessNewBlockHeaders"
This should be in commit "doc: Rewrite some validation doc to be machine-readable:".
src/validation.h
Outdated
There was a problem hiding this comment.
Commit "rpc: Expose ProcessNewBlockHeaders"
This should be in commit "doc: Rewrite some validation doc to be machine-readable:".
src/validation.h
Outdated
9e2b936 to
2595028
Compare
| self.log.info('submitheader tests') | ||
| assert_raises_rpc_error(-22, 'Block header decode failed', lambda: node.submitheader(hexdata='xx' * 80)) | ||
| assert_raises_rpc_error(-22, 'Block header decode failed', lambda: node.submitheader(hexdata='ff' * 78)) | ||
| assert_raises_rpc_error(-25, 'Must submit previous header', lambda: node.submitheader(hexdata='ff' * 80)) |
There was a problem hiding this comment.
nit, could include the previous hash.
src/rpc/mining.cpp
Outdated
| } | ||
| { | ||
| LOCK(cs_main); | ||
| if (LookupBlockIndex(h.GetHash())) return NullUniValue; |
There was a problem hiding this comment.
These verifications are done in ProcessNewBlockHeaders -> CChainState::AcceptBlockHeader. Could use ProcessNewBlockHeaders return value.
There was a problem hiding this comment.
See the docstring above: The result is always None and not the return value of PNBH
| } | ||
|
|
||
| CValidationState state; | ||
| ProcessNewBlockHeaders({h}, state, Params(), /* ppindex */ nullptr, /* first_invalid */ nullptr); |
There was a problem hiding this comment.
Since the lock is released above, there is a point where the block can be processed in between.
There was a problem hiding this comment.
That race shouldn't affect the return value.
src/validation.h
Outdated
| * | ||
| * Note that we guarantee that either the proof-of-work is valid on pblock, or | ||
| * (and possibly also) BlockChecked will have been called. | ||
| * |
There was a problem hiding this comment.
supernit: you remove this text in commit doc: Rewrite some validation doc to be machine-readable, and then remove the lines in commit rpc: Expose ProcessNewBlockHeaders. Just remove the lines in the first commit.
Same for ProcessNewBlockHeaders comment below.
test/functional/mining_basic.py
Outdated
| bytes_to_hex_str, | ||
| ) | ||
|
|
||
| b2x = bytes_to_hex_str |
There was a problem hiding this comment.
Can just use:
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
bytes_to_hex_str as b2x,
+)| bad_block2 = copy.deepcopy(block) | ||
| bad_block2.hashPrevBlock = bad_block.sha256 | ||
| bad_block2.solve() | ||
| assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block2).serialize()))) |
There was a problem hiding this comment.
Normal way we do this is:
assert_raises_rpc_error(-25, 'bad-prevblk', node.submitheader, b2x(CBlockHeader(bad_block2).serialize()))Any reason you've chosen to use a lambda?
There was a problem hiding this comment.
I prefer to use named arguments
There was a problem hiding this comment.
This should work:
assert_raises_rpc_error(-25, 'bad-prevblk', node.submitheader, hexdata=b2x(CBlockHeader(bad_block2).serialize()))
src/rpc/mining.cpp
Outdated
| } | ||
| { | ||
| LOCK(cs_main); | ||
| if (LookupBlockIndex(h.GetHash())) return NullUniValue; |
There was a problem hiding this comment.
I think it'd be slightly nicer to have a return value passed to the user, if only to differentiate between whether the header was already in the block index or if it newly added to the block index.
| assert chain_tip(block.hash) in node.getchaintips() | ||
| node.submitheader(hexdata=b2x(CBlockHeader(block).serialize())) # Noop | ||
| assert chain_tip(block.hash) in node.getchaintips() | ||
|
|
There was a problem hiding this comment.
perhaps test submitting a block header that isn't the most-work tip (ie a fork from some earlier block)
There was a problem hiding this comment.
Done at the end of this function
|
#13439 has been merged. Is this PR ready for rebase and rereview? |
2595028 to
03ac2b4
Compare
03ac2b4 to
3ea4750
Compare
dfc8cf6 to
fa7d7dd
Compare
|
utACK fa7d7dd34cbd180ec9587c640078dfb7bf2ead04. Having this functionality can't hurt, as it available with identical semantics via P2P anyway. I have no opinion about the test code style. |
test/functional/mining_basic.py
Outdated
There was a problem hiding this comment.
Does master have a bug? This should be returning "bad-txns-nonfinal", not "invalid"...
|
Please rename either the PR or the RPC method to match the other... |
|
utACK fa7d7dd. |
fa7d7dd to
5ce7446
Compare
5ce7446 to
fa091b0
Compare
|
Rebased. Only conflict was in tests, no other changes. |
|
utACK fa091b0 |
fa091b0 qa: Add tests for submitheader (MarcoFalke) 36b1b63 rpc: Expose ProcessNewBlockHeaders (MarcoFalke) Pull request description: This exposes `ProcessNewBlockHeaders` as an rpc called `submitheader`. This can be used to check for invalid block headers and submission of valid block headers via the rpc. Tree-SHA512: a61e850470f15465f88e450609116df0a98d5d9afadf36b2033d820933d8b6a4012f9f2b3246319c08a0e511bef517f5d808cd0f44ffca91d10895a938004f0b
fa091b0 qa: Add tests for submitheader (MarcoFalke) 36b1b63 rpc: Expose ProcessNewBlockHeaders (MarcoFalke) Pull request description: This exposes `ProcessNewBlockHeaders` as an rpc called `submitheader`. This can be used to check for invalid block headers and submission of valid block headers via the rpc. Tree-SHA512: a61e850470f15465f88e450609116df0a98d5d9afadf36b2033d820933d8b6a4012f9f2b3246319c08a0e511bef517f5d808cd0f44ffca91d10895a938004f0b
* Merge bitcoin#13399: rpc: Add submitheader fa091b0 qa: Add tests for submitheader (MarcoFalke) 36b1b63 rpc: Expose ProcessNewBlockHeaders (MarcoFalke) Pull request description: This exposes `ProcessNewBlockHeaders` as an rpc called `submitheader`. This can be used to check for invalid block headers and submission of valid block headers via the rpc. Tree-SHA512: a61e850470f15465f88e450609116df0a98d5d9afadf36b2033d820933d8b6a4012f9f2b3246319c08a0e511bef517f5d808cd0f44ffca91d10895a938004f0b * Update test/functional/mining_basic.py Co-authored-by: UdjinM6 <[email protected]> Co-authored-by: UdjinM6 <[email protected]>
This exposes
ProcessNewBlockHeadersas an rpc calledsubmitheader. This can be used to check for invalid block headers and submission of valid block headers via the rpc.