From 772809e1be1b44dcdd70392bd7e6aff76d514af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20W=C3=B3jtowicz?= <158484752+crocodile-dentist@users.noreply.github.com> Date: Fri, 20 Sep 2024 17:32:36 +0200 Subject: [PATCH] Expose transaction size to tx submission (#4926) * Added callback providing tx size to txSubmissionInbound * changelog update --- ouroboros-network/CHANGELOG.md | 3 +++ .../Test/Ouroboros/Network/TxSubmission/AppV1.hs | 1 + .../src/Ouroboros/Network/TxSubmission/Inbound.hs | 14 +++++++++++--- .../src/Ouroboros/Network/TxSubmission/Outbound.hs | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) 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/sim-tests-lib/Test/Ouroboros/Network/TxSubmission/AppV1.hs b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/TxSubmission/AppV1.hs index 7a15c9404f..8d9ca6a65f 100644 --- a/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/TxSubmission/AppV1.hs +++ b/ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/TxSubmission/AppV1.hs @@ -138,6 +138,7 @@ txSubmissionSimulation tracer maxUnacked outboundTxs maxUnacked (getMempoolReader inboundMempool) (getMempoolWriter inboundMempool) + getTxSize NodeToNodeV_7 prop_txSubmission :: Positive Word16 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 (..))