Serialize node block in the requested form, stripping witness. - #1069
Serialize node block in the requested form, stripping witness.#1069echennells wants to merge 1 commit into
Conversation
627e27c to
05a1706
Compare
|
Looks like this needs rebase. |
A peer requesting a block without witness (getdata MSG_BLOCK) crashes the node. messages::block held the store's wire bytes plus an advisory witnessed_ flag, and serialize/size guarded on witness == witnessed_. The generic serializer calls serialize with the default witness = true, so the guard fails, serialize returns false, and the null payload is sent without a null check. Any peer can trigger it. The guard is the root error, but the witness argument must also function: a witness node servicing a non-witness peer must strip the witness on serialize, and the serializer cannot rely on the held object's form because one object may be sent to peers with differing requirements. Hold a system::chain::block_view instead of raw bytes and delegate serialize and size to block.to_data(witness) and block.serialized_size(witness); the view strips the witness when serialized without it. protocol_block_out_106 selects the form at read time via get_wire_block(link, witness) and wraps the result in the view. messages::transaction carries the same guard but nothing serializes it yet (transaction-out re-serializes from the parsed transaction), so it is left unchanged. Depends on the libbitcoin-system block_view and transaction_view to_data implementation.
05a1706 to
9bde3f0
Compare
|
Rebased onto master ( The previous CI red was the stale base rather than this change: the old head predated the Re-verified on a from-source build against current deps (system
This build is currently running as a live testnet3 node at tip. CI has not picked up the new head yet — it may need an approve-and-run. |
|
CI is green on the rebased head (14/14). Three jobs failed on the first attempt — two cmake release configs and the macOS gnu job — but that run was cancelled mid-flight; they pass on re-run with no change to the head. |
A peer requesting a block without witness (
getdata MSG_BLOCK) crashes the node.messages::blockheld the store's wire bytes plus an advisorywitnessed_flag, andserialize/sizeguarded onwitness == witnessed_. The generic serializer callsserializewith the defaultwitness = true, so the guard fails,serializereturns false, and the null payload is sent without a null check — any peer can trigger it (in debug thesize()assert trips first).The guard is the root error, but the
witnessargument must also function: a witness node servicing a non-witness peer must strip the witness on serialize, and the serializer cannot rely on the held object's form, because one object may be sent to peers with differing requirements.The message now holds a
system::chain::block_viewinstead of the wire bytes and delegatesserialize/sizetoblock.to_data(witness)/block.serialized_size(witness)— the view strips the witness when serialized without it.protocol_block_out_106selects the form at read time. The incorrect guard and assert are removed.messages::transactioncarries the same guard, but nothing serializes it yet (transaction-out re-serializes from the parsed transaction), so it is left unchanged.Depends on libbitcoin/libbitcoin-system#1905 — will not build without it.
Full node test suite green.