Skip to content

Conversation

@random-zebra
Copy link

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.

morcos and others added 4 commits July 31, 2020 02:43
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.
As PIVX started with BIP34 already enforced, there are no duplicate
coinbases
(adapted from bitcoin/bitcoin@1cf3dd8,
removing the 'spent_a_duplicate_coinbase' checks)
Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

code looking good, tests and reindex went well too, ACK 9d97db0

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

utACK 9d97db0

@random-zebra random-zebra merged commit 3c767c4 into PIVX-Project:master Aug 8, 2020
random-zebra added a commit that referenced this pull request Aug 18, 2020
cdbb1a6 Remove unused variable in test, fixing warning. (Russell Yanofsky)
03031a5 Check FRESH validity in CCoinsViewCache::BatchWrite (Russell Yanofsky)
3fb3e03 Fix dangerous condition in ModifyNewCoins. (random-zebra)
228d6bc [test] Add CCoinsViewCache Access/Modify/Write tests (random-zebra)

Pull request description:

  Going on with the coins view cache update work (started with #1774 and #1777).
  This backports the following upstream PRs (adapting them with the assumption that duplicate coinbase transactions are not possible):

  - bitcoin#9308 - [test] Add CCoinsViewCache Access/Modify/Write tests
  - bitcoin#9107 - Safer modify new coins
  - bitcoin#9310 - Assert FRESH validity in CCoinsViewCache::BatchWrite
  - bitcoin#9435 - Removed unused variable in test, fixing warning.

  Note: Will rebase #1773 on top of this one (to change `ApplyTxInUndo` return value in the unit test too).

ACKs for top commit:
  furszy:
    pretty nice one, ACK cdbb1a6
  Fuzzbawls:
    ACK cdbb1a6

Tree-SHA512: 69c534da1083c3c4a535923e98da7750474c6698bb45e042778b539a27fab0455d78aaf670bed9485522f9d2ee25e4ad57fa7d35632523fe7376fe5f5febb1e5
@random-zebra random-zebra modified the milestones: 5.0.0, 4.3.0 Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants