From 62f9d264eab1f33894f8d30be6deb4ee9a53a856 Mon Sep 17 00:00:00 2001 From: satan Date: Wed, 14 Aug 2024 11:42:28 +0200 Subject: [PATCH 1/2] Added shielded sync documentation --- .../docs/pages/users/shielded-accounts.mdx | 1 + .../pages/users/shielded-accounts/_meta.json | 3 +- .../users/shielded-accounts/shielded-sync.mdx | 80 +++++++++++++++++++ .../shielded-accounts/shielded-transfers.mdx | 21 +---- .../users/shielded-accounts/shielding.mdx | 15 +--- .../users/shielded-accounts/unshielding.mdx | 6 +- 6 files changed, 90 insertions(+), 36 deletions(-) create mode 100644 packages/docs/pages/users/shielded-accounts/shielded-sync.mdx diff --git a/packages/docs/pages/users/shielded-accounts.mdx b/packages/docs/pages/users/shielded-accounts.mdx index 1018df5b..9c4869d4 100644 --- a/packages/docs/pages/users/shielded-accounts.mdx +++ b/packages/docs/pages/users/shielded-accounts.mdx @@ -21,6 +21,7 @@ If you are familiar with Zcash, the set of interactions you can execute with Nam - [Shielding transfers](./shielded-accounts/shielding.mdx): transparent to shielded address - [Shielded transfers](./shielded-accounts/shielded-transfers.mdx): shielded to shielded address - [Unshielding transfers](./shielded-accounts/unshielding.mdx): shielded to transparent address +- [Shielded Sync](./shielded-accounts/shielded-sync.mdx): Sync a user's local view of the MASP with the chain More technical details of these circuits can be found in the [specs](https://specs.namada.net/modules/masp) as well as [this blog post](https://namada.net/blog/understanding-the-masp-and-cc-circuits). diff --git a/packages/docs/pages/users/shielded-accounts/_meta.json b/packages/docs/pages/users/shielded-accounts/_meta.json index 67269d47..76bb7cc5 100644 --- a/packages/docs/pages/users/shielded-accounts/_meta.json +++ b/packages/docs/pages/users/shielded-accounts/_meta.json @@ -2,5 +2,6 @@ "glossary": "Glossary", "masp-keys": "Shielded Key Management", "shielding": "Shielding Assets", - "unshielding": "Unshielding Assets" + "unshielding": "Unshielding Assets", + "shielded-sync": "Shielded Sync" } \ No newline at end of file diff --git a/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx b/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx new file mode 100644 index 00000000..db54549f --- /dev/null +++ b/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx @@ -0,0 +1,80 @@ +import { Callout } from 'nextra-theme-docs' + +# Shielded Sync + +In order to interact with the MASP, users need a local copy of all of the notes. This is +necessary to create new notes with the correct zk-proofs. Additionally, it is the only way +to find out which notes are owned by the user which is necessary for calculating balances. + +Shielded sync is the command which downloads and and processes a local view of the MASP (up to +a given block height) and stores it locally in a `shielded context`. This command must be +run periodically to stay in sync with the tip of the chain. + +## Running shielded sync + +The most basic way to run shielded sync is via the command: +```bash copy +namadac shielded-sync +``` +This assumes several things by default. It will look into the user's wallet and import any MASP +keys into the shielded context. These will be the keys used to attempt to decrypt the downloaded +MASP notes. Additional keys can be provided via: +```bash copy +namadac shielded-sync --spending-keys $SPENDING_KEY +``` +and / or +```bash copy +namadac shielded-sync --viewing-keys $VIEWING_KEY +``` + + +The first time you wish to check the balance of a spending/viewing key, you must provide it to the shielded context with +`--spending-keys|--viewing-keys`. On subsequent runs, you can simply use `namadac shielded-sync` as these +keys will be stored in the shielded context. + + +Shielded sync also assumes that the user wishes to sync to the tip of the chain. If this is not +the case, a height to sync to can be provided: +```bash copy +namadac shielded-sync --to-height $BLOCKHEIGHT +``` + +## Interrupting + +If the shielded context is sufficiently behind the tip of the chain, the amount of data to be downloaded +and the computational load of processing it can be considerable. This is one reason why a user might +wish to specify a height to sync to. + +Additionally, the user can interrupt shielded sync at anytime by pressing `CTRL-C` or similar stop +command. Shielded sync will receive this signal and save its work before stopping. This avoids +lost work and can be resumed the next time shielded sync is run. + +## Using a MASP indexer + +A MASP indexer can do a lot of the processing of MASP data and make it available to users via a +web server that can handle large downloads and many requests. This is in contrast to syncing +by calling the RPC endpoints of node operators. This makes it the preferred way to run shielded +sync. To run with an indexer: +```bash copy +namadac shielded-sync --with-indexer $INDEXER_API_URL +``` +The api endpoint `$INDEXER_API_URL` will be a url to the indexer ending with `/api/v1`. + +## Recovering from data corruption + +If, for some reason, the shielded context gets corrupted and shielded sync cannot function correctly, +a user can try to remove all local data and sync again from scratch. The shielded context is stored +in the user's chain directory and the generated files have the following names: + * `shielded.dat` + * `shielded.tmp` + * `speculative_shielded.dat` + * `shielded_sync.cache` + * `shielded_sync.cache.tmp` + + If these files are deleted, shielded sync can be run and the syncing can be done from scratch. + + +Removing or modifying these files is not recommended and should only be done as a last resort. +Also note that the user will need to provided the necessary viewing and spending keys to +shielded sync again. + \ No newline at end of file diff --git a/packages/docs/pages/users/shielded-accounts/shielded-transfers.mdx b/packages/docs/pages/users/shielded-accounts/shielded-transfers.mdx index ce8ef29c..12643afa 100644 --- a/packages/docs/pages/users/shielded-accounts/shielded-transfers.mdx +++ b/packages/docs/pages/users/shielded-accounts/shielded-transfers.mdx @@ -6,10 +6,7 @@ Once the user has a [shielded balance](./shielding.mdx), it can be transferred t ## Making a shielded transfer -Before making a shielded transfer, it is recommended to first sync the local shielded context: -```bash copy -namadac shielded-sync --spending-keys $SPENDING_KEY -``` +Before making a shielded transfer, it is recommended to first sync the local shielded context. See how to do this [here](shielded-sync.mdx). To make a shielded transfer, you must possess the relevant spending key. See the [glossary](./glossary.mdx) for an explanation on the types of keys and addresses used with the MASP. @@ -30,20 +27,8 @@ Note: you must provide an implicit account which you control containing funds fo ### Viewing your balance -To view the up-to-date balance of your spending key (or viewing key), you must first run the `shielded-sync` command to -sync the local shielded context with any MASP notes owned by your spending/viewing key: -```bash copy -namadac shielded-sync --spending-keys $SPENDING_KEY -``` -or -```bash copy -namadac shielded-sync --viewing-keys $VIEWING_KEY -``` - - -The first time you wish to check the balance of a spending/viewing key, you must provide it to the shielded context with -`--spending-keys|--viewing-keys`. On subsequent runs, you can simply use `namadac shielded-sync`. - +To view the up-to-date balance of your spending key (or viewing key), you must first run the [`shielded-sync`](shielded-sync.mdx) command to +sync the local shielded context with any MASP notes owned by your spending/viewing key. After the sync has completed, check your balance with: ```bash copy diff --git a/packages/docs/pages/users/shielded-accounts/shielding.mdx b/packages/docs/pages/users/shielded-accounts/shielding.mdx index 86bb7398..07d3e69a 100644 --- a/packages/docs/pages/users/shielded-accounts/shielding.mdx +++ b/packages/docs/pages/users/shielded-accounts/shielding.mdx @@ -41,19 +41,8 @@ namadac shield \ ### Viewing your balance To view the up-to-date balance of your spending key (or viewing key), you must first run the `shielded-sync` command to -sync the local shielded context with any MASP notes owned by your spending/viewing key: -```bash copy -namadac shielded-sync --spending-keys $SPENDING_KEY -``` -or -```bash copy -namadac shielded-sync --viewing-keys $VIEWING_KEY -``` - - -The first time you wish to check the balance of a spending/viewing key, you must provide it to the shielded context with -`--spending-keys|--viewing-keys`. On subsequent runs, you can simply use `namadac shielded-sync`. - +sync the local shielded context with any MASP notes owned by your spending/viewing key. +See how to do this [here](shielded-sync.mdx). After the sync has completed, check your balance with: ```bash copy diff --git a/packages/docs/pages/users/shielded-accounts/unshielding.mdx b/packages/docs/pages/users/shielded-accounts/unshielding.mdx index 037eba36..4c680649 100644 --- a/packages/docs/pages/users/shielded-accounts/unshielding.mdx +++ b/packages/docs/pages/users/shielded-accounts/unshielding.mdx @@ -8,10 +8,8 @@ Assets can also be sent directly from a shielded address through IBC -- see the ## Making an unshielding transfer -Before making an unshielding transfer, it is recommended to first sync the local shielded context: -```bash copy -namadac shielded-sync --spending-keys $SPENDING_KEY -``` +Before making an unshielding transfer, it is recommended to first sync the local shielded context. +See how to do that [here](shielded-sync.mdx). To make an unshielding transfer, you must possess the relevant spending key. See the [glossary](./glossary.mdx) for an explanation on the types of keys and addresses used with the MASP. From 94debba6c81c3477e4e73a481b1a38d87ac427e8 Mon Sep 17 00:00:00 2001 From: brentstone Date: Mon, 19 Aug 2024 22:36:00 -0400 Subject: [PATCH 2/2] edits --- .../users/shielded-accounts/shielded-sync.mdx | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx b/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx index db54549f..85983ad0 100644 --- a/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx +++ b/packages/docs/pages/users/shielded-accounts/shielded-sync.mdx @@ -4,15 +4,15 @@ import { Callout } from 'nextra-theme-docs' In order to interact with the MASP, users need a local copy of all of the notes. This is necessary to create new notes with the correct zk-proofs. Additionally, it is the only way -to find out which notes are owned by the user which is necessary for calculating balances. +for a client to find out which notes are owned by the user, which is necessary for calculating balances. -Shielded sync is the command which downloads and and processes a local view of the MASP (up to -a given block height) and stores it locally in a `shielded context`. This command must be +Shielded sync is the command that downloads and processes a local view of the MASP (up to +a given block height) and then stores it locally in a `shielded context`. This command must be run periodically to stay in sync with the tip of the chain. ## Running shielded sync -The most basic way to run shielded sync is via the command: +The simplest way to run shielded sync is via the command: ```bash copy namadac shielded-sync ``` @@ -29,12 +29,12 @@ namadac shielded-sync --viewing-keys $VIEWING_KEY The first time you wish to check the balance of a spending/viewing key, you must provide it to the shielded context with -`--spending-keys|--viewing-keys`. On subsequent runs, you can simply use `namadac shielded-sync` as these +the `--spending-keys|--viewing-keys` argument. On subsequent runs, you can simply use `namadac shielded-sync`, as these keys will be stored in the shielded context. -Shielded sync also assumes that the user wishes to sync to the tip of the chain. If this is not -the case, a height to sync to can be provided: +Shielded sync also assumes by default that the user wishes to sync to the tip of the chain. If this is not +the case, a maximal height to sync to can be provided: ```bash copy namadac shielded-sync --to-height $BLOCKHEIGHT ``` @@ -42,19 +42,20 @@ namadac shielded-sync --to-height $BLOCKHEIGHT ## Interrupting If the shielded context is sufficiently behind the tip of the chain, the amount of data to be downloaded -and the computational load of processing it can be considerable. This is one reason why a user might -wish to specify a height to sync to. +and the computational load of processing it can be cumbersome. This is one reason why a user might +wish to specify a maximal height to which to sync. Additionally, the user can interrupt shielded sync at anytime by pressing `CTRL-C` or similar stop command. Shielded sync will receive this signal and save its work before stopping. This avoids -lost work and can be resumed the next time shielded sync is run. +losing work and can be resumed the next time shielded sync is run. ## Using a MASP indexer A MASP indexer can do a lot of the processing of MASP data and make it available to users via a web server that can handle large downloads and many requests. This is in contrast to syncing -by calling the RPC endpoints of node operators. This makes it the preferred way to run shielded -sync. To run with an indexer: +by calling the RPC endpoints of node operators. + +Thus, the preferred and most efficient way to run shielded sync is by using an indexer: ```bash copy namadac shielded-sync --with-indexer $INDEXER_API_URL ``` @@ -71,7 +72,7 @@ in the user's chain directory and the generated files have the following names: * `shielded_sync.cache` * `shielded_sync.cache.tmp` - If these files are deleted, shielded sync can be run and the syncing can be done from scratch. + If these files are deleted, shielded sync can be run in order to resync from scratch. Removing or modifying these files is not recommended and should only be done as a last resort.