Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose transaction size to tx submission #4926

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading