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

ModifyNewCoins saves database lookups #6932

Merged
merged 3 commits into from Nov 18, 2015
Merged

Conversation

morcos
Copy link
Member

@morcos morcos commented Nov 3, 2015

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.

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.
@gmaxwell
Copy link
Contributor

gmaxwell commented Nov 3, 2015

ConceptACK, will review further and test.

@sipa
Copy link
Member

sipa commented Nov 11, 2015

Untested, code review ACK. Needs a unit test, though.

@sipa
Copy link
Member

sipa commented Nov 11, 2015

Together with #5967 it should be possible to also avoid the db read that's still done for coinbase transactions.

@morcos
Copy link
Member Author

morcos commented Nov 12, 2015

@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.

@sipa
Copy link
Member

sipa commented Nov 12, 2015

@morcos Awesome test.

@morcos
Copy link
Member Author

morcos commented Nov 12, 2015

ok fixed the mess with the random nValue.

@sipa
Copy link
Member

sipa commented Nov 12, 2015

ACK

@jgarzik
Copy link
Contributor

jgarzik commented Nov 12, 2015

lightly tested ACK

}

if (insecure_rand() % 100 == 0) {
// Every 100 iterations, change the cache stack.
Copy link
Member

@laanwj laanwj Nov 13, 2015

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 :)

Copy link
Member

@sipa sipa Nov 13, 2015

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 :)

@laanwj
Copy link
Member

laanwj commented Nov 13, 2015

Code review ACK

@laanwj laanwj merged commit 1cf3dd8 into bitcoin:master Nov 18, 2015
1 check passed
laanwj added a commit that referenced this issue Nov 18, 2015
1cf3dd8 Add unit test for UpdateCoins (Alex Morcos)
03c8282 Make CCoinsViewTest behave like CCoinsViewDB (Alex Morcos)
14470f9 ModifyNewCoins saves database lookups (Alex Morcos)
zkbot added a commit to zcash/zcash that referenced this issue May 14, 2018
Bitcoin 0.12 performance improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6918
- bitcoin/bitcoin#6932

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this issue May 14, 2018
Bitcoin 0.12 performance improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6918
- bitcoin/bitcoin#6932

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this issue May 31, 2018
Bitcoin 0.12 performance improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6918
- bitcoin/bitcoin#6932

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this issue Nov 30, 2018
Bitcoin 0.12 performance improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6918
- bitcoin/bitcoin#6932

Part of #2074.
milesmanley pushed a commit to RunOnFlux/fluxd that referenced this issue Mar 5, 2019
Bitcoin 0.12 performance improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6918
- bitcoin/bitcoin#6932

Part of #2074.
random-zebra added a commit to PIVX-Project/PIVX that referenced this issue Aug 8, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants