Skip to content

Commit 1edde14

Browse files
authored
Merge pull request #231 from alan-turing-institute/222-request-max-retries
Docs: add hint for setting requestMaxRetries parameter
2 parents c24991b + 5892962 commit 1edde14

File tree

4 files changed

+143
-15
lines changed

4 files changed

+143
-15
lines changed

docs/http-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Under the section headed `[http]`, add or edit the following configuration param
3535

3636
!!! example "Example HTTP server configuration"
3737

38-
After completing the above steps, the `[http]` section of `trustchain_config.toml` should look similar the following example:
38+
After completing the above steps, the `[http]` section of `trustchain_config.toml` should look similar to the following example:
3939
```bash
4040
[http]
4141
root_event_time = 1697213008

docs/ion.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,24 @@ The final configuration step is to set the `bitcoinWalletOrImportString` paramet
569569

570570
On Testnet, a key will be automatically generated when ION runs for the first time which can be used for the `bitcoinWalletOrImportString` parameter, so you don't need to do anything in this step.
571571

572+
!!! tip "Tip: Set the `requestMaxRetries` configuration parameter"
573+
574+
This step is optional but is strongly recommended because it may significantly speed up the synchronisation process which takes place when ION runs for the first time.
575+
576+
When ION requests information from the local Bitcoin node it may have to retry several times before receiving a response. This is particularly common during its initial synchronisation, when many requests are made at high frequency.
577+
578+
After several failed requests ION will stop trying and the synchronisation process will restart, forfeiting the progress already made. By default this will happen after only three failed attempts, but this can be increased by setting the `requestMaxRetries` config parameter.
579+
580+
Run the following command to increase the maximum number of retry attempts:
581+
=== "Linux"
582+
```console
583+
$ N=$(grep -n '\"port\"' $ION_BITCOIN_CONFIG_FILE_PATH | cut -d':' -f1); sed -i "$((N+1))"'i\'$'\n'' "requestMaxRetries": 6,'$'\n' $ION_BITCOIN_CONFIG_FILE_PATH
584+
```
585+
=== "macOS"
586+
```console
587+
$ N=$(grep -n '\"port\"' $ION_BITCOIN_CONFIG_FILE_PATH | cut -d':' -f1); sed -i '' "$((N+1))"'i\'$'\n'' "requestMaxRetries": 6,'$'\n' $ION_BITCOIN_CONFIG_FILE_PATH
588+
```
589+
572590
### Build ION
573591

574592
Change directory into the ION repository:
@@ -886,7 +904,7 @@ Then use this command to list the receiving addresses for this wallet (with thei
886904
$ bitcoin-cli -rpcwallet="sidetreeDefaultWallet" listreceivedbyaddress 1 true
887905
```
888906

889-
To fund your wallet, send Bitcoins to the **first** receive address in this list.
907+
To fund your wallet, send Bitcoins to the **first address** in this list.
890908

891909
=== "Mainnet"
892910

docs/usage.md

Lines changed: 122 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,38 +225,148 @@ In fact, four private key were generated by the CLI when the DID was created. Al
225225

226226
Instructions on how to fund your Bitcoin wallet are available [here](ion.md#funding-your-bitcoin-wallet).
227227

228+
Currently the Trustchain CLI does not include a command for publishing DIDs. This will be added in a future version. In the meantime, DIDs can be published by running a script from the command line.
228229

229-
When you are ready to publish your DID, execute the `publish.sh` script by running the following command:
230+
When you are ready to publish one or more DIDs, execute the `publish.sh` script by running the following command:
230231
```console
231232
$ "$TRUSTCHAIN_REPO"/scripts/publish.sh
232233
```
233234

234-
This script will attempt to publish all of the DID operations that are found in the `$TRUSTCHAIN_DATA/operations/` directory.
235+
This script will attempt to publish all of the DID operations that are found in the `$TRUSTCHAIN_DATA/operations/` directory. The output from this command should include the following message, indicating it was successful:
236+
```
237+
* We are completely uploaded and fine
238+
```
235239

236-
Support for publishing via the Trustchain CLI will be added in a future version.
240+
After the `publish.sh` script has run, there will be some delay before the newly-published DID can be resolved. This is due to i) the ION publication mechanism, which supports batching of DID operations to reduce transaction fees, and ii) the Bitcoin network processing time. For more details, see the information panels below.
237241

238-
!!! tip "Tip: Batching DID operations"
242+
=== "Mainnet"
239243

240-
To save time and reduce transaction fees, multiple DID operations can be batched into a single Bitcoin transaction. In fact, ION supports batching of up to 10,000 operations per transaction.
244+
??? info "ION DID publication mechanism"
241245

242-
To perform batching, simply repeat the create operation as many times as you like before running the `publish.sh` script. Then run the script once to publish all operations in a single batch.
246+
The `publish.sh` script takes all of the DID operations in `$TRUSTCHAIN_DATA/operations/` and dispatches them to the local ION node for publishing. They are then placed in the collection of `queued-operations` inside ION's Mongo database.
243247

244-
The only exception to this rule is that **the root DID must not be published in a batched transaction**. It must be the unique DID operation associated with the transaction in which it is published. The reason for this condition is to enable fast and efficient scanning of the Bitcoin blockchain to identify potential root DID operations.
248+
To view the contents of this database, open the MongoDB shell with this command:
249+
```console
250+
$ mongo --shell
251+
```
252+
Then run the following MongoDB commands (omitting the `>` prompt character) to select the database:
253+
```console
254+
> ion-mainnet-core
255+
```
256+
and check how many queued DID operations exist:
257+
```console
258+
> db["queued-operations"].count()
259+
```
260+
The output from this command will usually be zero, indicating that there are no queued operations. Immediately after running the `publish.sh` script, the number of queued operations will increase to one (or more, if there were multiple files inside `$TRUSTCHAIN_DATA/operations/` when the script was executed).
261+
262+
Periodically, ION will check if there are any queued operations and, if any exist, it will batch them together and publish them in a single Bitcoin operation. The frequency with which this check is performed can be controlled by setting the `batchingIntervalInSeconds` parameter, found in the ION core config file. To view this file, run:
263+
```console
264+
$ less $ION_CORE_CONFIG_FILE_PATH
265+
```
266+
267+
The default batching interval is 600 seconds. This can be reduced by changing the value of the `batchingIntervalInSeconds` parameter and restarting ION.
268+
269+
??? info "Bitcoin network processing time"
270+
271+
When a new (or updated) DID document is published, it will take some time for the Bitcoin network to [process](https://bitcoin.org/en/how-it-works#processing) the relevant transaction so that it becomes visible to all other network participants.
272+
273+
Only after this processing has finished will it be possible to resolve the DID using the Trustchain CLI `resolve` command.
274+
275+
Typically, the processing time will be between 10 and 60 minutes, but it might be longer depending on factors such as the level of congestion on the Bitcoin network and the size of the fee inserted in the relevant transaction.
276+
277+
!!! tip "Tip: Identifying your DID transaction"
278+
279+
While you are waiting for your DID to be published, you can track its progress by observing the Bitcoin wallet address used to publish the DID operation. Run this command to list your Bitcoin addresses:
280+
```console
281+
$ bitcoin-cli -rpcwallet="sidetreeDefaultWallet" listreceivedbyaddress 1 true
282+
```
283+
Then copy the **first address** in the list and paste it into the search bar at [blockstream.info](https://blockstream.info/).
284+
285+
This search will return information about your Bitcoin address, including the number of confirmed transactions that have taken place and the unspent amount in the address (i.e. its current balance). Below the summary information will be a list showing every transaction associated with this address, *including any unconfirmed transactions*.
286+
287+
Assuming the ION publication mechanism has executed (see the panel above), the first transaction in the list will be the new one that was created by that process.
288+
289+
Click on the first transaction ID (this is a long string of hexadecimal characters that uniquely identifies the transactions). This takes you to a new page with details about that particular transaction.
290+
291+
Check the "status" of the transaction. If it is marked as "Unconfirmed", this indicates that it has not yet been processed by the Bitcoin network. In that case it will not yet be possible to resolve the new DID.
292+
293+
By refreshing this page, you can check its progress. When the transaction has been processed its status will change to "$n$ Confirmations", where $n$ is the number of Bitcoin blocks mined since the one containing this transaction.
294+
295+
As soon as the transaction has one or more confirmations, it should be possible to resolve the newly-published DID.
296+
297+
**If your are publishing a root DID**, make a note of the transaction ID so you can easily find it later. You should also make a note of the transactions's timestamp (i.e. the exact date & time that it was confirmed). The timestamp can be found on the same page as the transaction status on [blockstream.info](https://blockstream.info/).
298+
299+
=== "Testnet"
300+
301+
??? info "ION DID publication mechanism"
302+
303+
The `publish.sh` script takes all of the DID operations in `$TRUSTCHAIN_DATA/operations/` and dispatches them to the local ION node for publishing. They are then placed in the collection of `queued-operations` inside ION's Mongo database.
304+
305+
To view the contents of this database, open the MongoDB shell with this command:
306+
```console
307+
$ mongo --shell
308+
```
309+
Then run the following MongoDB commands (omitting the `>` prompt character) to select the database:
310+
```console
311+
> ion-testnet-core
312+
```
313+
and check how many queued DID operations exist:
314+
```console
315+
> db["queued-operations"].count()
316+
```
317+
The output from this command will usually be zero, indicating that there are no queued operations. Immediately after running the `publish.sh` script, the number of queued operations will increase to one (or more, if there were multiple files inside `$TRUSTCHAIN_DATA/operations/` when the script was executed).
318+
319+
Periodically, ION will check if there are any queued operations and, if any exist, it will batch them together and publish them in a single Bitcoin operation. The frequency with which this check is performed can be controlled by setting the `batchingIntervalInSeconds` parameter, found in the ION core config file. To view this file, run:
320+
```console
321+
$ less $ION_CORE_CONFIG_FILE_PATH
322+
```
323+
324+
The default batching interval is 600 seconds. This can be reduced by changing the value of the `batchingIntervalInSeconds` parameter and restarting ION.
325+
326+
??? info "Bitcoin network processing time"
327+
328+
When a new (or updated) DID document is published, it will take some time for the Bitcoin network to [process](https://bitcoin.org/en/how-it-works#processing) the relevant transaction so that it becomes visible to all other network participants.
329+
330+
Only after this processing has finished will it be possible to resolve the DID using the Trustchain CLI `resolve` command.
245331

246-
After running the `publish.sh` script, wait for the transaction to be [processed](https://bitcoin.org/en/how-it-works#processing) by the Bitcoin network, then check that it was successfully published by attempting to resolve the DID (or DIDs, if more than one was published) [using the CLI](#did-resolution).
332+
Typically, the processing time will be between 10 and 60 minutes, but it might be longer depending on factors such as the level of congestion on the Bitcoin network and the size of the fee inserted in the relevant transaction.
333+
334+
!!! tip "Tip: Identifying your DID transaction"
335+
336+
While you are waiting for your DID to be published, you can track its progress by observing the Bitcoin wallet address used to publish the DID operation. Run this command to list your Bitcoin addresses:
337+
```console
338+
$ bitcoin-cli -rpcwallet="sidetreeDefaultWallet" listreceivedbyaddress 1 true
339+
```
340+
Then copy the **first address** in the list and paste it into the search bar at [blockstream.info](https://blockstream.info/testnet/).
341+
342+
This search will return information about your Bitcoin address, including the number of confirmed transactions that have taken place and the unspent amount in the address (i.e. its current balance). Below the summary information will be a list showing every transaction associated with this address, *including any unconfirmed transactions*.
343+
344+
Assuming the ION publication mechanism has executed (see the panel above), the first transaction in the list will be the new one that was created by that process.
345+
346+
Click on the first transaction ID (this is a long string of hexadecimal characters that uniquely identifies the transactions). This takes you to a new page with details about that particular transaction.
347+
348+
Check the "status" of the transaction. If it is marked as "Unconfirmed", this indicates that it has not yet been processed by the Bitcoin network. In that case it will not yet be possible to resolve the new DID.
349+
350+
By refreshing this page, you can check its progress. When the transaction has been processed its status will change to "$n$ Confirmations", where $n$ is the number of Bitcoin blocks mined since the one containing this transaction.
351+
352+
As soon as the transaction has one or more confirmations, it should be possible to resolve the newly-published DID.
353+
354+
**If your are publishing a root DID**, make a note of the transaction ID so you can easily find it later. You should also make a note of the transactions's timestamp (i.e. the exact date & time that it was confirmed). The timestamp can be found on the same page as the transaction status on [blockstream.info](https://blockstream.info/testnet/).
355+
356+
After running the `publish.sh` script, wait for the transaction to be processed, then check that it was successfully published by attempting to resolve the DID (or DIDs, if more than one was published) [using the CLI](#did-resolution).
247357

248358
Once you have confirmed that the DID(s) can be resolved, you can clean up the `.trustchain/operations/` folder by running this command to move all operations files to the `sent/` subdirectory:
249359
```console
250360
$ mv $TRUSTCHAIN_DATA/operations/*.json* $TRUSTCHAIN_DATA/operations/sent/./
251361
```
252362

253-
!!! info "Network processing time"
363+
!!! tip "Tip: Batching DID operations"
254364

255-
When a new (or updated) DID document is published, it will take some time for the Bitcoin network to process the relevant transaction so that it becomes visible to all other network participants.
365+
To save time and reduce transaction fees, multiple DID operations can be batched into a single Bitcoin transaction. In fact, ION supports batching of up to 10,000 operations per transaction.
256366

257-
Only after this processing has finished will it be possible to resolve the DID using the Trustchain CLI `resolve` command.
367+
To perform batching, simply repeat the create operation as many times as you like before running the `publish.sh` script. Then run the script once to publish all operations in a single batch.
258368

259-
Typically, the processing time will be between 10 and 60 minutes, but it might be longer depending on factors such as the level of congestion on the Bitcoin network and the size of the fee inserted in the relevant transaction.
369+
The only exception to this rule is that **the root DID must not be published in a batched transaction**. It must be the unique DID operation associated with the transaction in which it is published. The reason for this condition is to enable fast and efficient scanning of the Bitcoin blockchain to identify potential root DID operations.
260370

261371
## Downstream DID Issuance
262372

scripts/publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Returns:
1010
# OK / Bad Request
1111

12-
for file in $(find "$HOME/.trustchain/operations" -name "*.json" -depth 1); do
12+
for file in $(find "$HOME/.trustchain/operations" -maxdepth 1 -name "*.json"); do
1313
echo $file
1414
curl --tr-encoding -X POST -v -# -o "$file.out.json" -T $file -H "Content-Type: application/json; charset=utf-8" http://localhost:3000/operations
1515
done

0 commit comments

Comments
 (0)