Repository navigation
rpc: fill the coinbase witness reserved value in submitblock like Core - #1066
Conversation
Core's submitblock adds 32 zero bytes as the coinbase witness when the block has a witness commitment, the coinbase has no witness, and segwit is active for the block (UpdateUncommittedBlockStructures). rbitcoin rejected the same block as bad-witness-nonce-size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review: `header_height` drops a header-only parent once its child's header arrives, so the fill was skipped where Core's LookupBlockIndex finds the parent. Use `stored_header_height`. The test also pins a block with no commitment and the headers-first case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Summary
submitblock now inserts the BIP141 coinbase witness reserved value (one 32-byte zero stack item) before the usual accept path. That matches Core UpdateUncommittedBlockStructures: only when segwit is active for this block, the coinbase has a witness-commitment output, and the coinbase has no witness. An existing reserved value is left alone, a pre-segwit commitment stays bare data, and P2P accept_received_block does not grow a second fill. The reserved value is always zeros, so a wrong parent cannot invent a different nonce. The gap is fail-closed: an unresolved parent height is treated as segwit-off, and the block this PR exists to accept is still rejected with bad-witness-nonce-size.
Issue counts by severity
- bugs: 0
- suggestions: 1
- nits: 1
Review: assert the headers-first submit is held (`inconclusive`), and say on the submitblock row that a parent past the 10,000-header walk is treated as before segwit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@rearden-grok please re-review the latest commit (f49cd66). |
There was a problem hiding this comment.
Summary
submitblock fills the BIP141 coinbase witness reserved value the way Core's UpdateUncommittedBlockStructures does: 32 zero bytes only when segwit is active for this block, the coinbase has a witness commitment, and the coinbase witness stack is empty. An existing reserved value is left alone, a pre-segwit commitment stays ordinary data, and P2P accept_received_block does not grow a second fill. The headers-first case asserts inconclusive. The 10,000-header parent walk stays fail-closed past the cap, and docs/rpc.md matches that.
Prior notes on the parent walk and the held-result assert are addressed on f49cd66d. No new comment restates the code.
Issue counts by severity
- bugs: 0
- suggestions: 0
- nits: 0
Rebase is not required. This head is mergeable, and the four commits on master since the base are the BIP30 ancestor work. They do not touch these files.
Summary
Bitcoin Core's
submitblockadds the coinbase witness reserved value (32 zero bytes) when the block has a witness commitment but the coinbase has no witness. It only does this once segwit is active. SeeUpdateUncommittedBlockStructuresin Core'srpc/mining.cpp.rbitcoin did not do this. The same block was rejected with
bad-witness-nonce-size. Mining software that leaves the coinbase witness out would lose the block.submit_received_block prev-blk-not-found check + fill_witness_reserved_value # Core UpdateUncommittedBlockStructures cheap_submit_tx_reject accept_received_blockThe fill is skipped below segwit and when the coinbase already has a witness, like Core.
Evidence
Same block bytes sent to Core v31.1 and rbitcoin on regtest:
bad-witness-nonce-sizebad-witness-nonce-sizeCore's own
p2p_segwit.pytest_submit_blocknow passes too. The only difference left is the reject string for a wrong nonce (witness commitment mismatchvsbad-witness-merkle-match).New test
submitblock_adds_the_witness_reserved_value_once_segwit_is_active(segwit@2):bad-witness-nonce-size.Merge Danger
Door: two-way
Blast Radius: small. Only
submitblock. P2P block handling does not change.🤖 Generated with Claude Code