Skip to content

Commit f4bb0f6

Browse files
committed
tx-submission: check tx-sizes up to _MAX_SIZE_DISCREPENCY
1 parent b67becc commit f4bb0f6

File tree

1 file changed

+16
-1
lines changed
  • ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound/V2

1 file changed

+16
-1
lines changed

ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound/V2/State.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Ouroboros.Network.TxSubmission.Inbound.V2.State
1515
, acknowledgeTxIds
1616
, splitAcknowledgedTxIds
1717
, tickTimedTxs
18+
, const_MAX_TX_SIZE_DISCREPENCY
1819
-- * Internals, only exported for testing purposes:
1920
, RefCountDiff (..)
2021
, updateRefCounts
@@ -360,6 +361,11 @@ receivedTxIdsImpl
360361
unacknowledgedTxIds = unacknowledgedTxIds',
361362
requestedTxIdsInflight = requestedTxIdsInflight - reqNo }
362363

364+
-- | We check advertised sizes up in a fuzzy way. The advertised and received
365+
-- sizes need to agree up to `const_MAX_TX_SIZE_DISCREPENCY`.
366+
--
367+
const_MAX_TX_SIZE_DISCREPENCY :: SizeInBytes
368+
const_MAX_TX_SIZE_DISCREPENCY = 32
363369

364370
collectTxsImpl
365371
:: forall peeraddr tx txid.
@@ -415,13 +421,22 @@ collectTxsImpl txSize peeraddr requestedTxIdsMap receivedTxs
415421
Map.dropMissing
416422
Map.dropMissing
417423
(Map.zipWithMaybeMatched \_ receivedSize advertisedSize ->
418-
if receivedSize == advertisedSize
424+
if receivedSize `checkTxSize` advertisedSize
419425
then Nothing
420426
else Just (receivedSize, advertisedSize)
421427
)
422428
(txSize `Map.map` receivedTxs)
423429
requestedTxIdsMap
424430

431+
checkTxSize :: SizeInBytes
432+
-> SizeInBytes
433+
-> Bool
434+
checkTxSize received advertised
435+
| received > advertised
436+
= received - advertised <= const_MAX_TX_SIZE_DISCREPENCY
437+
| otherwise
438+
= advertised - received <= const_MAX_TX_SIZE_DISCREPENCY
439+
425440
requestedTxIds = Map.keysSet requestedTxIdsMap
426441
notReceived = requestedTxIds Set.\\ Map.keysSet receivedTxs
427442
downloadedTxs' = downloadedTxs ps <> receivedTxs

0 commit comments

Comments
 (0)