-
Notifications
You must be signed in to change notification settings - Fork 86
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
More intelligent transaction requests #1476
Conversation
4c3cdff
to
da30a03
Compare
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
da30a03
to
3ee99f6
Compare
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
3ee99f6
to
2a5baee
Compare
2a5baee
to
b3576f4
Compare
3058fa4
to
8d49781
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned that we've broken the clean pattern here with serverReqTxs
, and I wonder if we can keep to it, despite the extra feature we've gained.
So previously we had canRequestMoreTxs
which was pure and told is if we did indeed have more txs to request, and then serverReqTxs
simply did the request.
What we have now is a bit of a mish-mash. We still have a pure canRequestMoreTxs
but it's now not definitive. Instead we have serverReqTxs
which no longer performs the request at all. Instead it does the impure tests that were not covered by canRequestMoreTxs
and returns what the request should be, or updates the state with extra txids that can be acknowledged.
My suggestion is this: introduce a new step at appropriate points in the server loop where we read the current recent txs set
recentTxIds <- atomically $ readTVar recentTxIdsVar
This is the only actual action needed. After this we can update the various bits of server state purely. Then the old pattern works again: canRequestMoreTxs
is again definitive since it just looks at the updated server state, and serverReqTxs
can actually request txs.
Just expTime -> pure expTime | ||
currentTime <- getMonotonicTime | ||
let toWait = max 0 (timeScheduledForExpiry `diffTime` currentTime) | ||
threadDelay toWait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really need to fix threadDelay
on 32bit systems. Any wait over ~35min will fail, and our expiry here is an hour. Lets file a ticket so we don't forget.
That said 60min is probably 60x too long.
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
@@ -642,7 +643,7 @@ runThreadNetwork ThreadNetworkArgs | |||
, blockProduction = Just blockProduction | |||
, blockFetchSize = nodeBlockFetchSize | |||
, blockMatchesHeader = nodeBlockMatchesHeader | |||
, recentTxIdsExpiryThresh = Time (secondsToDiffTime (60 * 60)) -- TODO | |||
, recentTxIdsExpiryThresh = RecentTxIds.ExpiryThreshold (secondsToDiffTime (60 * 60)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be just RecentTxIds.ExpiryThreshold 60.0
I think. There's a Num
instance for DiffTime
and the interpretation is seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be obvious to someone reading the code that the value is interpreted in seconds? If so, I can make the change.
@@ -271,7 +273,7 @@ mkNodeArgs registry cfg initState tracers btime chainDB isProducer = NodeArgs | |||
, blockProduction | |||
, blockFetchSize = nodeBlockFetchSize | |||
, blockMatchesHeader = nodeBlockMatchesHeader | |||
, recentTxIdsExpiryThresh = Time (secondsToDiffTime 3600) | |||
, recentTxIdsExpiryThresh = RecentTxIds.ExpiryThreshold (secondsToDiffTime (60 * 60)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
60s will be enough. Ideally I'd make it scale automatically with the expected block time for the protocol, and use 3x the block time.
Also, we don't need secondsToDiffTime
here, since the Num.fromIntegral
for DiffTime
uses seconds.
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Outdated
Show resolved
Hide resolved
8d77e16
to
f8f1a68
Compare
f8f1a68
to
039066b
Compare
To test this, I have the following approach in mind: Modify the protocol tracers of the ThreadNet tests to trace all requests for transactions. Also trace transactions added and expired to/from the |
12d0bdf
to
4dd484c
Compare
eace5fd
to
18b7997
Compare
![txid] | ||
-- ^ Transaction IDs that have been inserted into the 'RecentTxIds'. | ||
!Time | ||
-- ^ The time at which the transactions were added to the 'RecentTxIds'. | ||
| TraceRecentTxIdsExpired | ||
![(txid, Time)] | ||
-- ^ Transaction IDs, along with their expiration times, that have been | ||
-- expired from the 'RecentTxIds'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1688 (comment).
If there's the potential to hold onto memory memory, then some forcing might not be crazy.
On the other hand: we have #1386 open for that.
, nodeEventsTxRequests :: ev ([GenTxId blk], RecentTxIds (GenTxId blk)) | ||
-- ^ every request for transactions made by the node-to-node | ||
-- 'TxSubmission' mini-protocol along with the 'RecentTxIds' at the time | ||
-- each request was made. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we store the RecentTxIds
each time a request for txs is sent. I suppose it will be fine, but can you check that the memory usage while running the tests doesn't increase by too much? And can you check what the impact on the run time is? (Use the same seed to run the tests a few times with and without the new checks.) The tests are already slow enough 🙂
-- i.e. Transactions that are in a node's 'RecentTxIds' should not be | ||
-- requested from a peer. | ||
prop_no_txs_repeatedly_requested :: Property | ||
prop_no_txs_repeatedly_requested = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! This is exactly what I meant (even simpler 👍).
18b7997
to
45a709d
Compare
Co-authored-by: Thomas Winant <[email protected]>
45a709d
to
97d07d0
Compare
Closes #1161