Conversation
|
| const tooMany = Array.from({ length: MAX_BLOCK_TXS_PER_REQUEST + 1 }, () => TxHash.random()); | ||
| const request = makeRequest(Fr.random(), BitVector.init(0, []), [], tooMany); | ||
|
|
||
| await expect(callHandler(request)).rejects.toThrow(); |
There was a problem hiding this comment.
Protocol status remains untested
This assertion only checks that an exception is thrown, so the test would still pass if the handler returned the wrong protocol status. Assert that the error is a ReqRespStatusError with BADLY_FORMED_REQUEST to protect the wire-level behavior introduced by this change.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
7c784f0 to
59330f7
Compare
The BLOCK_TXS handler serves explicit request.txHashes even when it lacks the block, so a peer could send an empty bit list with a huge explicit-hash list and force one full tx to be served per hash (~1 GB from a ~64 KB request). Cap the explicit-hash count at a shared MAX_BLOCK_TXS_PER_REQUEST, clamp the batch requester's batch size to the same bound so honest requests never exceed it, and count explicit hashes in calculateBlockTxsResponseSize so the size estimate reflects them. Adds a handler regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
59330f7 to
3199ff0
Compare
…ED_REQUEST The cap test only checked that something threw, so it would pass on the wrong protocol status. Assert a ReqRespStatusError with BADLY_FORMED_REQUEST so the wire-level behavior is pinned. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A BLOCK_TXS request can name transactions by explicit hash. The response-size estimate counted only the bit-list positions, so a peer could send a small request with an empty bit list and many explicit hashes and force the node to serialize a full tx per hash: a large response from a small request.
Fix: count explicit hashes in the size estimate, cap explicit hashes per request (shared MAX_BLOCK_TXS_PER_REQUEST), and clamp the batch requester to the same bound so honest requests stay under it.
Test: a request naming more explicit hashes than the cap is rejected before the pool lookup. Verified red/green on the built base (block_txs 42/42, batch-tx-requester 37/37); prettier and tsgo clean.
🤖 Generated with Claude Code
Fixes A-2026