Skip to content

Conversation

@furszy
Copy link

@furszy furszy commented Sep 2, 2021

This work aims to improve the structure and performance of the wallet's Sapling increment witnesses flow.

The process is essentially walking through the entire wallet's txs map a minimum of 2 times, if there is no shield tx in the arriving block, and adds one more for each shield tx inside the block. Which affects mainly to wallets with a large number of transactions as the wallet is locked while this operation is being executed.

So, straight to the point, the current increment witness workflow is:

1) for-each tx in wallet : call CopyPreviousWitnesses.
2) for-each tx in block:
   a) for-each note in tx:
      a1) for-each tx in wallet : call AppendNoteCommitment.
      a2) if note is mine : call WitnessNoteIfMine.
3) for-each tx in wallet : call UpdateWitnessHeights.

And, have re-structured it into:

1) for-each tx in block : gather note commitments in vecComm.
2) for-each shield tx in wallet:
  a) copy the previous witness.
  b) for-each note commitment in vecComm:
      b1) append notes commitment.
      b2) witness note if ours.
  c) Update witness last processed height.

Finishing with only one loop over the wallet's txs map in the entire increment witnesses workflow.

PD: The benchmark that did is still a bit raw..

@furszy furszy self-assigned this Sep 2, 2021
@furszy furszy force-pushed the 2021_restructure_incrementWitness branch 2 times, most recently from 01bb72a to 18e8157 Compare September 2, 2021 12:39
@furszy furszy changed the title [Wallet] Sapling, restructure increment witnesses workflow [WIP][Wallet] Sapling, restructure increment witnesses workflow Sep 2, 2021
@furszy furszy force-pushed the 2021_restructure_incrementWitness branch 3 times, most recently from 26e9a81 to c9043c3 Compare September 3, 2021 15:26
@furszy furszy changed the title [WIP][Wallet] Sapling, restructure increment witnesses workflow [Wallet] Sapling, restructure increment witnesses workflow Sep 3, 2021
Mainly to get a rough measure of the Sapling witness cache/accumulation time.
Reworked the Sapling witnesses increment and cache workflow, so it does not loop over the entire wallet txs map indiscriminately.

From:
```
1) for-each tx in wallet : call CopyPreviousWitnesses.
2) for-each tx in block:
   a) for-each tx in wallet : call AppendNoteCommitment().
   b) if tx is mine : call WitnessNoteIfMine.
3) for-each tx in wallet : call UpdateWitnessHeights.
```

To:

```
1) for-each tx in block:
   a) gather note commitments in vecComm.
   b) witness note if ours.
2) for-each shield tx in wallet:
   a) copy the previous witness.
   b) append vecComm notes commitment.
   c) Update witness last processed height.
```
@furszy furszy force-pushed the 2021_restructure_incrementWitness branch from c9043c3 to e6f7158 Compare October 13, 2021 15:56
@furszy
Copy link
Author

furszy commented Oct 13, 2021

rebased, ready.

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.

Very nice. ACK e6f7158

As discussed, the benchmark needs more love, and it can be changed to a unit test for the time being (future PR).

@furszy furszy merged commit 8f2d530 into PIVX-Project:master Nov 5, 2021
@furszy furszy deleted the 2021_restructure_incrementWitness branch November 29, 2022 15:44
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.

2 participants