-
Notifications
You must be signed in to change notification settings - Fork 38.7k
ModifyNewCoins saves database lookups #6932
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
Conversation
When processing a new transaction, in addition to spending the Coins of its txin's it creates a new Coins for its outputs. The existing ModifyCoins function will first make sure this Coins does not already exist. It can not exist due to BIP 30, but because of that the lookup can't be cached and always has to go to the database. Since we are creating the coins to match the new tx anyway, there is no point in checking if they exist first anyway. However this should not be used for coinbase tx's in order to preserve the historical behavior of overwriting the two existing duplicate tx pairs.
|
ConceptACK, will review further and test. |
|
Untested, code review ACK. Needs a unit test, though. |
|
Together with #5967 it should be possible to also avoid the db read that's still done for coinbase transactions. |
|
@sipa I'm not sure if this was the kind of unit test that you had in mind? I thought it was important to actually test UpdateCoins instead of modifyNewCoins directly because it's how it is used that matters. This test passes on master, passes on this PR, but fails when UpdateCoins is changed to just mark coinbases as un-FRESH but still skip the lookup (assuming the assert is commented out to permit this). However if #5967 is merged then the test passes once again. |
|
@morcos Awesome test. |
dd338ca to
1cf3dd8
Compare
|
ok fixed the mess with the random nValue. |
|
ACK |
|
lightly tested ACK |
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.
If the purpose is to do this every 100 iterations, why use random?
Either the comment or the code is wrong :)
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.
It's copied from the test above that I wrote. It's intended to be random, so the comment is wrong :)
|
Code review ACK |
Bitcoin 0.12 performance improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6918 - bitcoin/bitcoin#6932 Part of #2074.
Bitcoin 0.12 performance improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6918 - bitcoin/bitcoin#6932 Part of #2074.
Bitcoin 0.12 performance improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6918 - bitcoin/bitcoin#6932 Part of #2074.
Bitcoin 0.12 performance improvements Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6918 - bitcoin/bitcoin#6932 Part of #2074.
9d97db0 Add unit test for UpdateCoins (random-zebra) 0965d3a Make CCoinsViewTest behave like CCoinsViewDB (Alex Morcos) 7d23d5c [Core] PIVX: remove db lookup for coinbase outputs (random-zebra) 1e88b7f ModifyNewCoins saves database lookups (Alex Morcos) Pull request description: Adapted version of bitcoin#6932 > When processing a new transaction, in addition to spending the Coins of its txin's, it creates a new Coins for its outputs. The existing ModifyCoins function will first make sure this Coins does not already exist. It can not exist due to BIP 30, but because of that, the lookup can't be cached and always has to go to the database. Since we are creating the Coins to match the new tx anyway, there is no point in checking if it exists first anyway. However this should not be used for coinbase tx's in order to preserve the historical behavior of overwriting the two existing duplicate tx pairs. > > In conjunction with bitcoin#6931 this will help ConnectBlock be much more efficient with caching access to the database. We remove the restriction on coinbases, and thus use always `ModifyNewCoins` instead of `ModifyCoins`, since duplicated coinbases are not possible on PIVX (ref. #1775). Accordingly, we remove the logic for checking the effects of duplicate coinbase txs in the unit test. ACKs for top commit: furszy: code looking good, tests and reindex went well too, ACK 9d97db0 Fuzzbawls: utACK 9d97db0 Tree-SHA512: e427f00699dfda29a9536b4e43919aecbfea90cf30195fe5a3835a49a715abf4f353a4672e6e99213b2016fb5b93f4ebfc94998a420ee8dc10626658069993af
When processing a new transaction, in addition to spending the Coins of its txin's, it creates a new Coins for its outputs. The existing ModifyCoins function will first make sure this Coins does not already exist. It can not exist due to BIP 30, but because of that, the lookup can't be cached and always has to go to the database. Since we are creating the Coins to match the new tx anyway, there is no point in checking if it exists first anyway. However this should not be used for coinbase tx's in order to preserve the historical behavior of overwriting the two existing duplicate tx pairs.
In conjunction with #6931 this will help ConnectBlock be much more efficient with caching access to the database.
This still needs unit tests which exercise the new functionality.