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

Add a missing protocol check in the tx submission inbound peer #1856

Merged
merged 1 commit into from
Mar 26, 2020
Merged
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
20 changes: 15 additions & 5 deletions ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ data TraceTxSubmissionInbound txid tx = TraceTxSubmissionInbound --TODO

data TxSubmissionProtocolError =
ProtocolErrorTxNotRequested

| ProtocolErrorTxIdsNotRequested
deriving Show

instance Exception TxSubmissionProtocolError where
displayException ProtocolErrorTxNotRequested =
"The peer replied with a transaction we did not ask for."
displayException ProtocolErrorTxIdsNotRequested =
"The peer replied with more txids than we asked for."


-- | Information maintained internally in the 'txSubmissionInbound' server
Expand Down Expand Up @@ -227,6 +229,16 @@ txSubmissionInbound _tracer maxUnacked mpReader mpWriter =
-> Collect txid tx
-> m (ServerStIdle n txid tx m ())
handleReply n st (CollectTxIds reqNo txids) = do

-- Check they didn't send more than we asked for. We don't need to check
-- for a minimum: the blocking case checks for non-zero elsewhere, and
-- for the non-blocking case it is quite normal for them to send us none.
let txidsSeq = Seq.fromList (map fst txids)
txidsMap = Map.fromList txids

unless (Seq.length txidsSeq <= fromIntegral reqNo) $
throwM ProtocolErrorTxIdsNotRequested

-- Upon receiving a batch of new txids we extend our available set,
-- and extended the unacknowledged sequence.
--
Expand All @@ -235,10 +247,8 @@ txSubmissionInbound _tracer maxUnacked mpReader mpWriter =
-- transactions again in the future.
let st' = st {
requestedTxIdsInFlight = requestedTxIdsInFlight st - reqNo,
unacknowledgedTxIds = unacknowledgedTxIds st
<> Seq.fromList (map fst txids),
availableTxids = availableTxids st
<> Map.fromList txids
unacknowledgedTxIds = unacknowledgedTxIds st <> txidsSeq,
availableTxids = availableTxids st <> txidsMap
}
mpSnapshot <- atomically mempoolGetSnapshot
serverIdle n (acknowledgeTxIdsInMempool st' mpSnapshot)
Expand Down