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 #1161

Closed
mrBliss opened this issue Oct 24, 2019 · 6 comments · Fixed by #1749
Closed

More intelligent transaction requests #1161

mrBliss opened this issue Oct 24, 2019 · 6 comments · Fixed by #1749
Assignees
Labels
byron Required for a Byron mainnet: replace the old core nodes with cardano-node consensus issues related to ouroboros-consensus
Milestone

Comments

@mrBliss
Copy link
Contributor

mrBliss commented Oct 24, 2019

UPDATE: new plan described in #1161 (comment)

Old plan:


Currently the txSubmissionInbound protocol handler does not look at the Mempool to see if txs are already there before requesting them. So in practice, it will needlessly download txs it already has. More confusingly, we can observe that node A sends a tx to B, which then sends it right back to A.

There are multiple options to improve this situation:

  1. Look at the Mempool and don't request txs already in there.
  2. Maintain a shared (across all txSubmissionInbound protocol handlers) set of TxIds that were recently in the Mempool. They should also expire from this set, so perhaps a PSQ would be a good fit. This can subsume (1).
  3. Keep track of which TxIds we're asking from which peers and don't ask for the same one from multiple peers unless that would otherwise cause things to stall, in which case we should make another request for the same TxId.

Because of the more complex concurrency of (3), we'll keep that for later. Getting (1) working will be easy. Our current aim is to achieve (2).

@mrBliss mrBliss added networking consensus issues related to ouroboros-consensus labels Oct 24, 2019
@mrBliss mrBliss added this to the Consensus_Mempool milestone Oct 24, 2019
@edsko
Copy link
Contributor

edsko commented Nov 14, 2019

Moving to 1.1 as it's inessential and we need to cut the release soon.

@mrBliss mrBliss added consensus issues related to ouroboros-consensus and removed consensus issues related to ouroboros-consensus labels Nov 28, 2019
@mrBliss mrBliss modified the milestones: Sprint 1.1.0, Sprint 1.2.0 Nov 28, 2019
@intricate
Copy link
Contributor

@dcoutts has also informed me that this PSQ should be shared between all the tx submission handlers, remote and local.

@mrBliss mrBliss modified the milestones: S2 2019-12-19, S3 2020-01-02 Dec 9, 2019
@mrBliss mrBliss modified the milestones: S3 2020-01-02, S4 2020-01-16 Jan 2, 2020
@mrBliss mrBliss added the byron Required for a Byron mainnet: replace the old core nodes with cardano-node label Jan 3, 2020
@mrBliss mrBliss modified the milestone: S4 2020-01-16 Jan 6, 2020
@mrBliss mrBliss modified the milestones: S4 2020-01-16, S5 2020-01-30 Jan 17, 2020
@mrBliss mrBliss modified the milestones: S5 2020-01-30, S6 2020-02-13 Jan 31, 2020
@edsko edsko removed this from the S6 2020-02-13 milestone Feb 13, 2020
@mrBliss
Copy link
Contributor Author

mrBliss commented Mar 4, 2020

While working on #1514, @nfrisby discovered that unlike duplicate txs, duplicate votes are not rejected. Without the improvements described in this issue, the nodes end up resubmitting the votes to each other so that blocks end up containing the same votes many, many times. (I'll use tx to mean generalised transaction, which includes votes)

The approach taken in #1476 (option 2 from the description of this issue) would mitigate this, but not entirely. It helps avoid requesting duplicate txs from other nodes, but it doesn't avoid receiving duplicate txs from the (local) wallet.

A proper solution would be to track in the Mempool which txids it contains and reject incoming txs/votes that are already in the Mempool.

However, this would largely duplicate the txids cache of RecentTxIds.

Therefore, @edsko and I came up with a new approach:

  • Remove RecentTxIds.
  • Add MempoolSnapshot.hasTx :: GenTxId blk -> Bool, implement it by keeping a Set (GenTxId blk) in the Mempool. (Let it return Maybe (GenTx blk) and keep a Map (GenTxId blk) (GenTx blk)? Would that be useful? YAGNI?)
  • Instead of using RecentTxIds to check which txs to request/acknowledge in TxSubmission.Inbound, use MempoolSnapshot.hasTx to do this.
  • In Mempool.tryAddTxs, reject txs already in the Mempool. Use the following type for results:
    data AddTxResult blk
      = TxAdded
      | TxRejected (ApplyTxErr blk)
      | TxAlreadyInMempool

We believe this approach is simpler than the one described in (2) (reason about "recent" and time is more complicated), it fixes the duplicate votes problem @nfrisby discovered, it avoids complex interactions in #1496.

The only scenario we believe in which it is worse than option (2):

  1. We receive or forge a block containing txs
  2. We remove these txs from our mempool
  3. Another node receives some of those txs
  4. That node informs us about these txs
  5. We request them, even though we have requested them in the past, which we could have avoided with RecentTxIds
  6. We receive the txs, but the Mempool rejects them, as they are part of our ledger already (except for votes).

I have split off option (3) in #1743.

@mrBliss
Copy link
Contributor Author

mrBliss commented Mar 4, 2020

@dcoutts What do you think about the new direction (let's call it option 1+) for this issue and #1743?

@intricate
Copy link
Contributor

intricate commented Mar 4, 2020

It's worth noting that we could mitigate this duplicate votes issue using the RecentTxIds approach by performing a lookup before attempting to add a tx received by the local tx submission server to the mempool. However, I'd say that the new approach is worth pursuing for the reasons mentioned by @mrBliss:

We believe this approach is simpler than the one described in (2) (reason about "recent" and time is more complicated), it fixes the duplicate votes problem @nfrisby discovered, it avoids complex interactions in #1496.

@edsko
Copy link
Contributor

edsko commented Mar 5, 2020

Note that we have to be very cautious: the wallet will monitor the blockchain to verify whether or not transactions that it has submitted are eventually included, and if they aren't, resubmit them. We have to be sure that such resubmitted transactions aren't ignored.

@iohk-bors iohk-bors bot closed this as completed in f4d1c4b Mar 6, 2020
iohk-bors bot added a commit that referenced this issue Mar 9, 2020
1747: check that Byron can increment its adopted protocol version r=nfrisby a=nfrisby

I'm not sure if this should be considered to fully address #1514, but it's good first step.

It originally that #1161 is high-priority because of votes: they are replicated and fill up the blocks, making the test quite expensive. Other transactions (so far) haven't been as problematic because duplicate transactions other than votes are invalid.

Therefore this PR is rooted on top of a potential fix for 1161; it's blocked by the corresponding PR. Good news, though: the protocol version update is succeeding when expected.

I'm opening this as Draft since it currently includes the latest state of the other PR.

Co-authored-by: Nicolas Frisby <[email protected]>
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
3 participants