Skip to content

Commit

Permalink
Merge branch 'main' of github.com:starcoinorg/starcoin-cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed Jul 4, 2022
2 parents 4930616 + 41f9a45 commit a6e9f57
Show file tree
Hide file tree
Showing 69 changed files with 5,607 additions and 252 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Starcoin CookBook

Learn how to build on Starcoin, the document URL: https://starcoinorg.github.io/starcoin-cookbook/
Learn how to build on Starcoin, the document URL:

* [https://starcoinorg.github.io/starcoin-cookbook/](https://starcoinorg.github.io/starcoin-cookbook/)
* [https://starcoin-cookbook.4everland.app/](https://starcoin-cookbook.4everland.app/)

### How to contribute

First off, thanks for taking the time to contribute! Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**.
First off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**.

Contributions in the following are welcome:

1. Ask a question about "How to develop on Starcoin", "How to use Move", etc. [Ask Question](https://github.com/starcoinorg/starcoin-cookbook/issues/new?assignees=&labels=question&template=02_QUESTION.md&title=%5Bquestion%5D).
2. Report a document bug. [Document Bug Report](https://github.com/starcoinorg/starcoin-cookbook/issues/new?assignees=&labels=bug&template=01_BUG_REPORT.md&title=%5Bbug%5D).
3. Submit a document suggestion. [Document improvement](https://github.com/starcoinorg/starcoin-cookbook/issues/new?assignees=&labels=doc&template=03_DOC_IMPROVEMENT.md&title=%5Bdoc%5D).
4. Contributing to write document. You can learn more about contributing to the Starcoin Cookbook by reading our [Contribution Guide](./docs/100-miscellaneous/99-contributing.md) |[贡献指南](./i18n/zh/docusaurus-plugin-content-docs/current/100-miscellaneous/99-contributing.md)
2. Report a documentation bug. [Document Bug Report](https://github.com/starcoinorg/starcoin-cookbook/issues/new?assignees=&labels=bug&template=01_BUG_REPORT.md&title=%5Bbug%5D).
3. Submit a documentation suggestion. [Document improvement](https://github.com/starcoinorg/starcoin-cookbook/issues/new?assignees=&labels=doc&template=03_DOC_IMPROVEMENT.md&title=%5Bdoc%5D).
4. Contributing to writing documents. You can learn more about contributing to the Starcoin Cookbook by reading our [Contribution Guide](./docs/100-miscellaneous/99-contributing.md) |[贡献指南](./i18n/zh/docusaurus-plugin-content-docs/current/100-miscellaneous/99-contributing.md)

You can view our [Code of Conduct](./CODE_OF_CONDUCT.md).

## Support

### Support

Reach out to the maintainer at one of the following places:

Expand Down
13 changes: 11 additions & 2 deletions docs/01-intro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

# Starcoin CookBook Intro

TODO introduce starcoin cookbook
The goal of the Starcoin Cookbook is to provide a full-stack learning resource for developers to learn how to develop on Starcoin.

It contains three main sections.

1. Knowledge about the Starcoin blockchain. Learn how to run nodes, understand blocks, transactions and state.
2. Knowledge about the Move programming language and the StarcoinFramework. Learn how to write, test, and deploy Move smart contracts. Learn about the features offered by StarcoinFramework.
3. Knowledge about Web3. Learn how DApps interact with smart contracts, how to call the Starcoin chain's RPC API, etc.

These learning resources are mainly related to Starcoin, but they can also be used as general learning resources for blockchain and smart contracts, because the smart contract blockchains are similar in technical principles.

This document is still being improved, and welcome to improve it [Contribution Guide](./miscellaneous/contributing).
2 changes: 1 addition & 1 deletion docs/02-getting-started/02-setup/02-starcoin-console.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Refer to [the second method in the startup console](#method-two).
Note: In Windows, the path to the IPC file is different.
```shell
starcoin.exe -c \\.\\pipe\starcoin\dev\starcoin.ipc console
starcoin.exe -c \\.\pipe\starcoin\dev\starcoin.ipc console
```
### via WebSocket
Expand Down
138 changes: 135 additions & 3 deletions docs/02-getting-started/02-setup/05-fast-sync-data.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,137 @@
# How to sync the block and state faster

TODO
1. Download block and import local.
2. Download the database snapshot and import local.
Usually, starting a new main network node will automatically synchronize block data, and this process is very long.

Next, we will introduce how to use the data export tool provided by the Starcoin toolchains to speed up the speed of new nodes synchronizing block data, and how to synchronize the state of the chain.

## Download and install

Download the corresponding precompiled [Starcoin toolchains](https://github.com/starcoinorg/starcoin/releases) according to the system you are using.
If you have already [downloaded and installed](https://starcoinorg.github.io/starcoin-cookbook/docs/getting-started/install/) `starcoin`, you can skip this step.

```shell
# Take Ubuntu as an example
wget https://github.com/starcoinorg/starcoin/releases/download/v1.11.10/starcoin-ubuntu-latest.zip

# Unzip
unzip starcoin-ubuntu-latest.zip

# Enter the decompression directory and check
cd starcoin-artifacts/
./starcoin_db_exporter -h
```

Tip: If you use it frequently, it is recommended to add it to the PATH environment variable.

## Sync block data

If a new full node is started, it is usually to download the main network block data of other nodes to the new node, and start the node with the downloaded block data.
Downloaded (exported) block data is stored on a CSV file for easy data exchange and storage.


### Export block

The `export-block-range` subcommand is used to export block data.

```shell
# Create a directory to store the block data exported from the node
mkdir ~/bak

# export block
./starcoin_db_exporter export-block-range -i ~/.starcoin/main/ -s 1 -e 10000 -n main -o ~/bak
```

- `-i` Specifies the data directory for the node.
- `-s` Specifies the starting height of block data.
- `-e` Specifies the end height of the block data.
- `-n` Specifies the network.
- `-o` Specifies the directory to store the exported data.

After the export, you can see that the export file is `~/bak/block_1_10000.csv` in the `~/bak` directory.

### Import block

The `apply-block` subcommand is used to import block data.

```shell
./starcoin_db_exporter apply-block -i block_1_10000.csv -n main -o ~/.starcoin/main/
```

- `-i` Specifies the path to the CSV file to import block data.
- `-n` Specifies the network.
- `-o` Specifies the data directory for the node.

### Import block data using script (recommended)

The `import_block.sh` script is provided in the `starcoin` repository, and the precompiled version is also packaged with the corresponding script.
It is more convenient to import block data using a script instead of having to export and import manually.

```shell
./import_block.sh main ~/.starcoin/main
```

This script accepts two parameters, parameter 1 specifies the network name, such as `main`, `barnard`, `proxima` or `halley`, and parameter 2 specifies the directory where the data is stored, such as `~/.starcoin/main` or any custom path.
This script will skip the existing blocks, and each time a block is acquired, the progress will be automatically updated.
After the script is interrupted and executed, the import will continue at the original height.

After executing the script, the mainnet block data will be automatically downloaded to the `~/.starcoin/main` directory and imported.
Wait for the download and import to complete, then you can run a new node with these block data.

Note: To use this script, make sure `starcoin_db_exporter` and `import_block.sh` are in the same path.

## Status of the sync chain

The `starcoin_db_exporter` command provides a snapshot function of offline export and import of `main`, `barnard`, `proxima`, `halley` networks, which is convenient to quickly build a blockchain network.

### Export snapshot

The `export-snapshot` subcommand is used to export snapshots.

**Normal export:**

```shell
# Create a directory for storing snapshot data exported from the node
mkdir ~/snapshot

# Export snapshot
./starcoin_db_exporter export-snapshot -i ~/.starcoin/main -n main -o ~/snapshot
```

- `-i` Specifies the data directory for the node.
- `-n` Specifies the network.
- `-o` Specifies the directory where the exported snapshots are stored.

**Incremental export:**

```shell
./starcoin_db_exporter export-snapshot -i ~/.starcoin/main -n main -o ~/snapshot -t true
```

Use the `-t` option to specify whether to use incremental export, `true` to enable, `false` to disable.
If you want to use incremental export, you need to ensure that there are old snapshots in the `~/snapshot` directory.
For example, the original snapshot height in the `~/snapshot` directory is `1-400w`, and now you need to export snapshots with a height of `1-500w`.
If incremental export is used, the subsequent `400w-500w` snapshots will be exported first, and then merged with the original snapshots to save time.

### Import snapshot

The `apply-snapshot` subcommand is used to import snapshots.

```shell
./starcoin_db_exporter apply-snapshot -i ~/snapshot -n main -o ~/.starcoin/main
```

- `-i` Specifies the directory where snapshots are stored.
- `-n` Specifies the network.
- `-o` Specifies the data directory for the node.

### Import snapshots using a script

The `import_snapshot.sh` script is provided in the [`starcoin`](https://github.com/starcoinorg/starcoin/blob/master/scripts/import_snapshot.sh) repository, and the precompiled version is also packaged with the corresponding script.

```shell
./import_snapshot.sh main ~/snapshot/ ~/.starcoin/main
```

This script needs to pass 3 parameters, parameter 1 specifies the name of the network, parameter 2 specifies the storage path of the snapshot, and parameter 3 specifies the data directory of the node.

Note: To use this script, make sure `starcoin_db_exporter` and `import_snapshot.sh` are in the same path.
Loading

0 comments on commit a6e9f57

Please sign in to comment.