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

Mempool: better revalidation and caching of the ledger state #1599

Merged
merged 5 commits into from
Feb 10, 2020

Conversation

mrBliss
Copy link
Contributor

@mrBliss mrBliss commented Feb 6, 2020

Fixes #1565 and #1301.

  • Replace Mempool.addTxs with Mempool.tryAddTxs, which doesn't block. This function will be much easier to test. We provide an implementation of Mempool.addTxs in terms of Mempool.tryAddTxs. We simplify the implementations by relying on the background thread for synchronising the Mempool with an updated ledger state.

  • Cache the TickedLedgerState after applying all transactions in the Mempool to it (Mempool should cache "final ledger state" #1301). Previously, we had to reapply all transactions whenever we added a new transaction. The new approach is much faster.

  • As we're keeping the TickedLedgerState in memory, make sure it is thunk-free.

  • Correct revalidation in (Add optional expiry slot to Mock transactions #1564) after explicitly removing transactions from the Mempool, see revalidateTxsFor.

  • Cleanup of conversion functions in TxSeq.

  • O(1) MempoolSize calculation for a TxSeq using its fingertree measure.

Also includes a rewrite of the Mempool tests using the Mock.Utxo. Using the Mock.Utxo instead of the overly simplistic TestTx we were using allows for more complicated dependencies between transactions. This better resembles the real transactions, at the cost of some complexity. With the former transaction type, we weren't even able to trigger #1565.

@mrBliss mrBliss added consensus issues related to ouroboros-consensus mempool labels Feb 6, 2020
@mrBliss mrBliss requested review from edsko and intricate February 6, 2020 15:35
@mrBliss mrBliss changed the title Mempool: correctly revalidate the Mempool after removeTxs Mempool: better revalidation and caching of the ledger state Feb 10, 2020
@mrBliss mrBliss requested a review from intricate February 10, 2020 14:16
@mrBliss mrBliss marked this pull request as ready for review February 10, 2020 15:17
@mrBliss mrBliss force-pushed the mrBliss/fix-1565 branch 3 times, most recently from 93332d5 to 31fff9c Compare February 10, 2020 16:03
Copy link
Contributor

@edsko edsko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed over Hangout.

Copy link
Contributor

@intricate intricate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not finished reviewing yet but here are some comments.

validationErrorImpossible $
applyByronGenTx validationMode cfg tx st
where
validationMode = CC.ValidationMode CC.NoBlockValidation Utxo.NoTxValidation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we no longer need the NoTxValidation mode in cardano-ledger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed not. @edsko and I have been looking for a ticket about this (that we could close), but we couldn't find it. Do you know which one that would be?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that there has been a ticket in ledger that specifically speaks to removing NoTxValidation.

Using the `Mock.Utxo` instead of the overly simplistic `TestTx` we were using
allows for more complicated dependencies between transactions. This better
resembles the real transactions, at the cost of some complexity.

Moreover, using the new transaction type reveals a bug that was not visible
with the previous transaction type, i.e., #1565.
@mrBliss mrBliss linked an issue Feb 10, 2020 that may be closed by this pull request
@mrBliss
Copy link
Contributor Author

mrBliss commented Feb 10, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 10, 2020
1599: Mempool: better revalidation and caching of the ledger state r=mrBliss a=mrBliss

Fixes #1565 and #1301.

* Replace `Mempool.addTxs` with `Mempool.tryAddTxs`, which doesn't block. This   function will be much easier to test. We provide an implementation of `Mempool.addTxs` in terms of `Mempool.tryAddTxs`. We simplify the implementations by relying on the background thread for synchronising the Mempool with an updated ledger state.

* Cache the `TickedLedgerState` after applying all transactions in the Mempool   to it (#1301). Previously, we had to reapply all transactions whenever we added a new transaction. The new approach is much faster.

* As we're keeping the `TickedLedgerState` in memory, make sure it is thunk-free.

* Correct revalidation in (#1564) after explicitly removing transactions from the Mempool, see `revalidateTxsFor`.

* Cleanup of conversion functions in `TxSeq`.

* O(1) `MempoolSize` calculation for a `TxSeq` using its fingertree measure.


Also includes a rewrite of the Mempool tests using the `Mock.Utxo`. Using the `Mock.Utxo` instead of the overly simplistic `TestTx` we were using allows for more complicated dependencies between transactions. This better resembles the real transactions, at the cost of some complexity. With the former transaction type, we weren't even able to trigger #1565.

Co-authored-by: Thomas Winant <[email protected]>
@mrBliss
Copy link
Contributor Author

mrBliss commented Feb 10, 2020

bors r-

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 10, 2020

Canceled

Fixes #1565 and #1301.

* Replace `Mempool.addTxs` with `Mempool.tryAddTxs`, which doesn't block. This
  function will be much easier to test. We provide an implementation of
  `Mempool.addTxs` in terms of `Mempool.tryAddTxs`. We simplify the
  implementations by relying on the background thread for synchronising the
  Mempool with an updated ledger state.

* Cache the `TickedLedgerState` after applying all transactions in the Mempool
  to it (#1301). Previously, we had to reapply all transactions whenever we
  added a new transaction. The new approach is much faster.

* As we're keeping the `TickedLedgerState` in memory, make sure it is
  thunk-free.

* Correct revalidation in (#1565) after explicitly removing transactions from
  the Mempool, see `revalidateTxsFor`.

* Cleanup of conversion functions in `TxSeq`.

* O(1) `MempoolSize` calculation for a `TxSeq` using its fingertree measure.
This was failing the tests with thunk checking
enabled (`-fchecktvarinvariant`).
@mrBliss
Copy link
Contributor Author

mrBliss commented Feb 10, 2020

bors r+

iohk-bors bot added a commit that referenced this pull request Feb 10, 2020
1599: Mempool: better revalidation and caching of the ledger state r=mrBliss a=mrBliss

Fixes #1565 and #1301.

* Replace `Mempool.addTxs` with `Mempool.tryAddTxs`, which doesn't block. This   function will be much easier to test. We provide an implementation of `Mempool.addTxs` in terms of `Mempool.tryAddTxs`. We simplify the implementations by relying on the background thread for synchronising the Mempool with an updated ledger state.

* Cache the `TickedLedgerState` after applying all transactions in the Mempool   to it (#1301). Previously, we had to reapply all transactions whenever we added a new transaction. The new approach is much faster.

* As we're keeping the `TickedLedgerState` in memory, make sure it is thunk-free.

* Correct revalidation in (#1564) after explicitly removing transactions from the Mempool, see `revalidateTxsFor`.

* Cleanup of conversion functions in `TxSeq`.

* O(1) `MempoolSize` calculation for a `TxSeq` using its fingertree measure.


Also includes a rewrite of the Mempool tests using the `Mock.Utxo`. Using the `Mock.Utxo` instead of the overly simplistic `TestTx` we were using allows for more complicated dependencies between transactions. This better resembles the real transactions, at the cost of some complexity. With the former transaction type, we weren't even able to trigger #1565.

Co-authored-by: Thomas Winant <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Feb 10, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus issues related to ouroboros-consensus mempool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mempool.removeTxs should not use the fast path Mempool should cache "final ledger state"
3 participants