-
Notifications
You must be signed in to change notification settings - Fork 36.5k
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
Cache transaction validation successes #6077
Conversation
Reimplemented the mrumap using boost::multiindex, which is more compact, and offers erasing elements too. Entries are now removed from the tx validation cache when they are accepted into a block, meaning the last 33k valid unconfirmed transactions are cached, rather than just the last 33k whatsoever. |
0dd16da
to
3f29d91
Compare
Rebased on new #6064. |
Rebased. |
Actually rebased. |
Been running on bitcoin.sipa.be for a week, no problems. |
ping
|
"it works" positive & negative test + review ACK |
Rebased. |
As suggested by Greg Maxwell-- unit test to make sure a block with a double-spend in it doesn't pass validation if half of the double-spend is already in the memory pool (so full-blown transaction validation is skipped) when the block is received.
ACK |
Backported to 0.11 as bc484ef |
I missed this.. EDIT: As in, couldn't this have been done in AcceptToMemoryPool instead of CheckScript (which, by the way, it's called twice inside AcceptToMemoryPool)? |
@jtimon To avoid rechecking the same transaction when it enters a block, when it has already been verified for the mempool (or whatever other reason). |
@sipa Thanks, I guess this the simplest way to do that right now. |
As mentioned on IRC, I think there's a problem with transaction checks involving block height. Consider a coinbase spend that is valid when the transaction arrives and is accepted into the mempool, but is invalid at any earlier block height because of the coinbase maturity test. If there's a reorg, then when validating blocks at earlier heights, we'd consider blocks valid even if they include this transaction at a too-early height, because of this validation cache. (A test that demonstrates this is here: https://gist.github.com/sdaftuar/23a3db523e68541a3195) |
@sdaftuar now that you say it, that's why I repeated the checks even when the transaction had been fully validated here: jtimon@935ee1e#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR779 |
Going to revert, thanks for pointing this out, @sdaftuar. |
This wasn't fully reverted, sipa@517e6dd broke #6235 and #6382 |
Misc upstream PRs Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6077 - Second commit only (first was already applied to 0.11.X and then reverted) - bitcoin/bitcoin#6284 - bitcoin/bitcoin#6489 - bitcoin/bitcoin#6462 - bitcoin/bitcoin#6647 - bitcoin/bitcoin#6235 - bitcoin/bitcoin#6905 - bitcoin/bitcoin#6780 - Excluding second commit (QT) and third commit (requires bitcoin/bitcoin#6993) - bitcoin/bitcoin#6961 - Excluding QT parts, and a small `src/policy/policy.cpp` change which depends on a bunch of other PRs, which we'll have to remember to come back to. - bitcoin/bitcoin#7044 - bitcoin/bitcoin#8856 - bitcoin/bitcoin#9002 Part of #2074 and #2132.
Misc upstream PRs Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6077 - Second commit only (first was already applied to 0.11.X and then reverted) - bitcoin/bitcoin#6284 - bitcoin/bitcoin#6489 - bitcoin/bitcoin#6235 - bitcoin/bitcoin#6905 - bitcoin/bitcoin#6780 - Excluding second commit (QT) and third commit (requires bitcoin/bitcoin#6993) - bitcoin/bitcoin#6961 - Excluding QT parts, and a small `src/policy/policy.cpp` change which depends on a bunch of other PRs, which we'll have to remember to come back to. - bitcoin/bitcoin#7044 - bitcoin/bitcoin#8856 - bitcoin/bitcoin#9002 Part of #2074 and #2132.
This is an alternative to @gavinandresen's #5835, which caches transaction validation results in an mru cache in main, rather than relying on the mempool in consensus code. The cache keeps the last 33k results, and uses around 3 MB on 64-bit systems.
This pull request also contains a rebased version of the unit test from #5835, and the optimizations from #6064.