Skip to content

Commit

Permalink
Expose transaction size to tx submission (#4926)
Browse files Browse the repository at this point in the history
* Added callback providing tx size to txSubmissionInbound

* changelog update
  • Loading branch information
crocodile-dentist committed Sep 20, 2024
1 parent d900a38 commit 7a2f47b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand Down

0 comments on commit 7a2f47b

Please sign in to comment.