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

More intelligent transaction requests #1476

Closed
wants to merge 8 commits into from
Closed

Conversation

intricate
Copy link
Contributor

@intricate intricate commented Jan 20, 2020

Closes #1161

@intricate intricate requested a review from mrBliss January 20, 2020 02:16
@intricate intricate self-assigned this Jan 20, 2020
@intricate intricate force-pushed the intricate/1161 branch 4 times, most recently from 3058fa4 to 8d49781 Compare February 11, 2020 17:54
@intricate intricate requested a review from dcoutts February 11, 2020 18:21
@mrBliss mrBliss self-requested a review February 12, 2020 16:44
@mrBliss mrBliss marked this pull request as ready for review February 17, 2020 09:12
Copy link
Contributor

@dcoutts dcoutts left a 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.

ouroboros-consensus/src/Ouroboros/Consensus/NodeKernel.hs Outdated Show resolved Hide resolved
Just expTime -> pure expTime
currentTime <- getMonotonicTime
let toWait = max 0 (timeScheduledForExpiry `diffTime` currentTime)
threadDelay toWait
Copy link
Contributor

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-consensus/src/Ouroboros/Consensus/Node.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))
Copy link
Contributor

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.

Copy link
Contributor Author

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))
Copy link
Contributor

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.

@intricate intricate force-pushed the intricate/1161 branch 2 times, most recently from 8d77e16 to f8f1a68 Compare February 20, 2020 02:08
@intricate intricate requested a review from dcoutts February 20, 2020 02:08
@mrBliss
Copy link
Contributor

mrBliss commented Feb 20, 2020

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 RecentTxIds. In prop_general, check for each node (by looking at its traces) that it never requested a transaction that is still in its RecentTxIds.

@intricate intricate force-pushed the intricate/1161 branch 2 times, most recently from 12d0bdf to 4dd484c Compare February 24, 2020 20:19
@intricate intricate requested a review from mrBliss February 24, 2020 20:19
@intricate intricate added the byron Required for a Byron mainnet: replace the old core nodes with cardano-node label Feb 24, 2020
@intricate intricate added consensus issues related to ouroboros-consensus networking labels Feb 24, 2020
@intricate intricate force-pushed the intricate/1161 branch 4 times, most recently from eace5fd to 18b7997 Compare February 25, 2020 05:57
ouroboros-network/src/Ouroboros/Network/Util/Orphans.hs Outdated Show resolved Hide resolved
Comment on lines +162 to +167
![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'.
Copy link
Contributor

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.

Comment on lines +958 to +964
, 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.
Copy link
Contributor

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 =
Copy link
Contributor

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 👍).

@intricate
Copy link
Contributor Author

Closed in favour of #1749 which implements the new plan.

@intricate intricate closed this Mar 5, 2020
@intricate intricate deleted the intricate/1161 branch April 1, 2020 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
byron Required for a Byron mainnet: replace the old core nodes with cardano-node consensus issues related to ouroboros-consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More intelligent transaction requests
4 participants