diff --git a/ouroboros-network/CHANGELOG.md b/ouroboros-network/CHANGELOG.md index 148dd7439a..28b2f17f78 100644 --- a/ouroboros-network/CHANGELOG.md +++ b/ouroboros-network/CHANGELOG.md @@ -23,6 +23,9 @@ * Added `daMinBigLedgerPeersForTrustedState` to `ArgumentsExtra` when starting diffusion. It is used by `outboundConnectionsState` when signaling trust state when syncing in Genesis mode. Default value is provided by the Configuration module. +* `txSubmissionInbound` takes an additional callback which exposes + CBOR-encoded transaction size as it is when transmitted over the + network, except for some top level wrapping (cf. PR#4926 description) ### Non-Breaking changes diff --git a/ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs b/ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs index 36f804938d..2e480dd602 100644 --- a/ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs +++ b/ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs @@ -44,6 +44,7 @@ import Network.TypedProtocol.Pipelined (N, Nat (..), natToInt) import Ouroboros.Network.NodeToNode.Version (NodeToNodeVersion) import Ouroboros.Network.Protocol.Limits import Ouroboros.Network.Protocol.TxSubmission2.Server +import Ouroboros.Network.SizeInBytes import Ouroboros.Network.Protocol.TxSubmission2.Type import Ouroboros.Network.TxSubmission.Inbound.Types (ProcessedTxCount (..), TraceTxSubmissionInbound (..), TxSubmissionMempoolWriter (..), @@ -135,9 +136,10 @@ txSubmissionInbound -> NumTxIdsToAck -- ^ Maximum number of unacknowledged txids allowed -> TxSubmissionMempoolReader txid tx idx m -> TxSubmissionMempoolWriter txid tx idx m + -> (tx -> SizeInBytes) -- ^ get size of CBOR encoded transaction -> NodeToNodeVersion -> TxSubmissionServerPipelined txid tx m () -txSubmissionInbound tracer (NumTxIdsToAck maxUnacked) mpReader mpWriter _version = +txSubmissionInbound tracer (NumTxIdsToAck maxUnacked) mpReader mpWriter txSize _version = TxSubmissionServerPipelined $ do #ifdef TXSUBMISSION_DELAY -- make the client linger before asking for tx's and expending @@ -262,8 +264,14 @@ txSubmissionInbound tracer (NumTxIdsToAck maxUnacked) mpReader mpWriter _version -- for. We should never get a tx we did not ask for. We take a strict -- approach to this and check it. -- - let txsMap :: Map txid tx - txsMap = Map.fromList [ (txId tx, tx) | tx <- txs ] + let availableTxidsMap = availableTxids st + txsMap :: Map txid tx + txsMap = Map.fromList [ (txId', assert sizesMatch tx) + | tx <- txs + , let txId' = txId tx + calcSize = Just $ txSize tx + advertisedSize = availableTxidsMap Map.!? txId' + sizesMatch = calcSize == advertisedSize] txidsReceived = Map.keysSet txsMap txidsRequested = Set.fromList txids diff --git a/ouroboros-network/src/Ouroboros/Network/TxSubmission/Outbound.hs b/ouroboros-network/src/Ouroboros/Network/TxSubmission/Outbound.hs index 29814d78e2..8c913baffb 100644 --- a/ouroboros-network/src/Ouroboros/Network/TxSubmission/Outbound.hs +++ b/ouroboros-network/src/Ouroboros/Network/TxSubmission/Outbound.hs @@ -27,6 +27,7 @@ import Ouroboros.Network.ControlMessage (ControlMessage, ControlMessageSTM, timeoutWithControlMessage) import Ouroboros.Network.NodeToNode.Version (NodeToNodeVersion) import Ouroboros.Network.Protocol.TxSubmission2.Client +import Ouroboros.Network.SizeInBytes import Ouroboros.Network.Protocol.TxSubmission2.Type import Ouroboros.Network.TxSubmission.Mempool.Reader (MempoolSnapshot (..), TxSubmissionMempoolReader (..))