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

[Sapling] Anchors and nullifiers integrated into the chain state view layered cache. #1903

Conversation

furszy
Copy link

@furszy furszy commented Oct 7, 2020

One more PR decoupled from #1798 to make the review process faster.

Essentially, the chain view state will be storing and caching the best anchor hash and 2 new entry types: (1) Anchors, (2) Nullifiers (Each of them with their entry class and map).

Note: This PR is introducing the new capabilities and validating the functionality correct behavior with a good amount of unit tests (test coverage inside coins_tests.cpp), it's not connected to the network flow.

Note2: There is a functional tests in 1798 (sapling_wallet_anchorfork.py) that wasn't able to decouple here due larger features requirements (new RPC calls introduced down 1798 commits line) but can be easily run there.

List of commits gathered here from #1798:

  • CoinsView, Anchor and nullifier view integration. —> 5a8f5eb
  • CCoinsViewCache add missing SetNullifiers method —> 1e3aaf1
  • coins_tests unit test back ported, up-to-date —> 3d46b5c
  • Connect tx GetShieldedValueIn —> 1050850 [PARTIALLY, only the coins view side. No wallet changes]
  • Missing optional sapData correction —> 8afcdd6
  • Add sapling tx priority to the GetPriority calculation —> 6ba51f2
  • fees: Do estimate fee/priority for shielded transaction. Those have fixed fee and priority. —> 84d61df
  • coins_tests: remove not needed BOOST_TEST_CONTEXT. We only have Sapling tests. —> 94aca90

@furszy furszy self-assigned this Oct 7, 2020
@furszy furszy force-pushed the 2020_sapling_anchorAndNullifier_view_integration branch from 1337393 to 7a5b812 Compare October 7, 2020 23:52
@furszy furszy added the Sapling label Oct 8, 2020
@Fuzzbawls Fuzzbawls added this to the 5.0.0 milestone Oct 9, 2020
@furszy furszy force-pushed the 2020_sapling_anchorAndNullifier_view_integration branch from 08f0e8e to 6d6da7f Compare October 10, 2020 14:05
@furszy
Copy link
Author

furszy commented Oct 10, 2020

Rebased on top of master, conflicts solved. Ready for review

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

Pretty good. Code ACK with few notes.

Just an idea for the future:
In the tests here we usually do:

    CCoinsViewTest base;
    CCoinsViewCache cache1(&base);

and then operate on the CCoinsViewCache object cache1.
It would be good, instead, to layer CCoinsViewCacheTest objects on top of the base CCoinsViewTest, and check also the dynamic memory usage with anchors and nullifiers.

src/coins.h Outdated Show resolved Hide resolved
src/coins.h Outdated Show resolved Hide resolved
src/txdb.h Outdated Show resolved Hide resolved
src/coins.cpp Outdated
Comment on lines 354 to 357
// todo: Move field to fees.h when the class gets back ported (this is needed for the mempool unit tests)
static const double MAX_PRIORITY = 1e16;

Choose a reason for hiding this comment

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

The "max" priority is actually INF_PRIORITY (1e25).
Though, we have to consider that, if high-priority txes fill a block up to nBlockPrioritySize (which is customizable by the staker), then the remaining txes are ordered by fee.

@furszy furszy force-pushed the 2020_sapling_anchorAndNullifier_view_integration branch from 6d6da7f to ee8ed26 Compare October 12, 2020 15:38
@furszy furszy force-pushed the 2020_sapling_anchorAndNullifier_view_integration branch from ee8ed26 to 3b4ad0d Compare October 12, 2020 18:28
@furszy
Copy link
Author

furszy commented Oct 12, 2020

updated per feedback.

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 3b4ad0d

Copy link

@random-zebra random-zebra left a comment

Choose a reason for hiding this comment

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

utACK 3b4ad0d and merging...

@random-zebra random-zebra merged commit f1b9b42 into PIVX-Project:master Oct 13, 2020
Fuzzbawls added a commit that referenced this pull request Oct 23, 2020
1403918 Add ZIP209 turnstile violation check. (furszy)
2b6f96b Signal ChainTip in ConnectTip and DisconnectTip methods (furszy)
df71481 Implement ChainTip signal. (furszy)
c605d98 Pass chainparams as argument in DisconnectTip, InvalidateBlock, ReprocessBlocks, DisconnectBlocks, DisconnectTip (furszy)
79dc604 Miner: sapling tree hash connection. (furszy)
e43380d Block: header hashFinalSaplingRoot inclusion. (furszy)
e56982b Track net value entering and exiting the Sapling circuit. (furszy)

Pull request description:

  Another decoupling from #1798, built on top of #1903 and #1915.

  Containing three topics:

  1) Sapling merkle tree root hash inclusion in the block header.
     * Block version bumped to v8.
     * Miner crafting the new merkle tree root hash and setting it into the block.

  2) Track network total value entering and exiting the shielded pool. (*)
     * Similar to the previous, initial, zc failsafe flow. (this can be done much better, like we did with zerocoin supply)
     * Block negative shielded value pool balances. -- Network validation consensus rule --

  3) ChainTip signal implemented.
     * Signal to notify the listeners (wallet) about new blocks (or chain reorgs), broadcasting the new block and the current merkle tree so the listener can build upon it. -- Not connected to anything yet --

  #### This PR is including the following commits decoupled from #1798.

  * Track net value entering and exiting the Sapling circuit.—> 8dd2045
  * Block: header hashFinalSaplingRoot inclusion.—> 5f55a76
  * Sapling: missing nSaplingValue in LoadBlockIndexGuts added.—> fbe0761
  * Miner: sapling tree hash connection.—> cb88fae
  * Implement ChainTip signal. —> 4e96e6c
  * Signal ChainTip in ConnectTip and DisconnectTip methods —> 85f4435
  * Pass chainparams as argument in DisconnectTip, InvalidateBlock, ReprocessBlocks, DisconnectBlocks, DisconnectTip —> 1c80953
  * Do not try to update tree anchor and witnesses if sapling is not active --> 1c64497
  * Validation: Adapted the cached incremental witnesses update flow to the syncTransaction changes. —> 6e6372d

ACKs for top commit:
  random-zebra:
    utACK 1403918
  Fuzzbawls:
    utACK 1403918

Tree-SHA512: c90ef1f358fb7a6e5a87b7b39985d65859048bb023dc8fd66020ee1c3e6ab4635ff595262beeaee93b12f4d83e21fe0613eb490b4a63d7bc96c61e4726ac1720
@furszy furszy deleted the 2020_sapling_anchorAndNullifier_view_integration branch November 29, 2022 14:26
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.

3 participants