ProvableHQ/snarkOS

GitHub: ProvableHQ/snarkOS

Aleo 网络的去中心化操作系统,为零知识应用提供交易验证与加密状态存储的节点基础设施。

Stars: 4525 | Forks: 2694

snarkOS

## 目录 * [1. 概述](#1-overview) * [2. 构建指南](#2-build-guide) * [2.1 环境要求](#21-requirements) * [2.2 安装说明](#22-installation) * [3. 运行 Aleo 节点](#3-run-an-aleo-node) * [3.1 运行 Aleo 客户端](#31-run-an-aleo-client) * [3.2 运行 Aleo 验证者](#32-run-an-aleo-validator) * [3.3 运行 Aleo 证明者](#33-run-an-aleo-prover) * [4. 常见问题](#4-faqs) * [5. 命令行界面](#5-command-line-interface) * [6. 开发指南](#6-development-guide) * [6.1 快速开始](#61-quick-start) * [6.2 操作](#62-operations) * [6.3 本地 Devnet](#63-local-devnet) * [6.4 Feature Flags](#64-feature-flags) * [6.5 本地备份](#65-local-backups) * [7. 贡献者](#7-contributors) * [8. 许可证](#8-license) ## 1. 概述 __snarkOS__ 是一个用于零知识应用程序的去中心化操作系统。 此代码构成了 [Aleo](https://aleo.org/) 网络的骨干, 它以公开可验证的方式验证交易并存储加密状态的应用程序。 ## 2. 构建指南 ### 2.1 定义 Aleo 网络中存在以下 snarkOS 节点类型: - **Validator**:Validator 节点参与共识,并且必须使用已绑定到委员会的账户来启动。 - **Client**:Client 不参与共识但维护账本。它们能够提供有关网络的信息,以及接受解决方案和交易并将其传达给它们的节点。所有客户端都运行相同的软件,但是,出于配置管理的目的,本文档定义了两种类型的客户端: - Core Client:直接连接到 validator 节点的 Client 节点。 - Outer Client:仅连接到其他 Client 或 Prover 节点的 Client 节点。 - **Prover**:Prover 节点专门用于解决 Aleo 难题。它们不参与共识也不维护账本的副本。 ### 2.2 环境要求 以下是运行 Aleo 节点的要求: - **OS**:仅限 64 位架构,需为安全保持最新版本 - Clients:Ubuntu 22.04 (LTS)、macOS Ventura 或更高版本、Windows 11 或更高版本 - Validators:Ubuntu 22.04 (LTS) - **CPU**:仅限 64 位架构,最新的 Intel Xeon 或更好 - Clients:24 核(推荐 32 核或更多) - Validators:64 核(推荐 128 核或更多) - **RAM**:DDR4 或更好 - Clients:128GiB 内存(推荐 192GiB 或更大) - Validators:256GiB 内存(推荐 384GiB 或更大) - **Storage**:PCIe Gen 3 x4、PCIe Gen 4 x2 NVME SSD 或更好 - Clients:2TB 磁盘空间(推荐 4TB 或更大) - Validators:4TB 磁盘空间(推荐 6TB 或更大) - **Network**:对称、商业、始终在线 - Clients:250Mbps 的上传**和**下载带宽 - Validators:500Mbps 的上传**和**下载带宽 ### 2.3 安装说明 在开始之前,请确保您的机器已安装 Rust,且至少为[此版本](rust-toolchain)。[安装 Rust 的说明可以在这里找到。](https://www.rust-lang.org/tools/install) 首先克隆此 GitHub 仓库: ``` git clone --branch mainnet --single-branch https://github.com/ProvableHQ/snarkOS.git ``` 接下来,进入 `snarkOS` 目录: ``` cd snarkOS ``` **[针对 Ubuntu 用户]** 提供了一个安装依赖项的辅助脚本。在 `snarkOS` 目录中运行: ``` ./build_ubuntu.sh ``` 最后,安装 `snarkOS`: ``` cargo install --locked --path . ``` #### 可选:Prover 的 CUDA 加速 ``` cargo install --locked --path . --features cuda ``` 请确保您的路由器和 OS 防火墙上开放了端口 `4130/tcp` 和 `3030/tcp`。 ### 2.4 端口配置 #### 2.4.1 对于 Core Clients | 端口 | 协议 | 允许/拒绝 | 来源 | 解释 | |----------|----------|------------|------------------------------|------------------------------------------------------------| | 4130/tcp | TCP | 允许 | 所有 IPv4/IPv6 | 连接至 peers 的 TCP 流量 | #### 2.4.2 对于 Outer Clients | 端口 | 协议 | 允许/拒绝 | 来源 | 解释 | |----------|----------|------------|------------------------------|------------------------------------------------------------| | 3030/tcp | TCP | 允许 | 所有 IPv4/IPv6 | REST server | | 4130/tcp | TCP | 允许 | 所有 IPv4/IPv6 | 连接至 peers 的 TCP 流量 | #### 2.4.3 对于 Validators | 端口 | 协议 | 允许/拒绝 | 来源 | 解释 | |----------|----------|------------|------------------------------|------------------------------------------------------------| | 4130/tcp | TCP | 允许 | 所有 IPv4/IPv6 | 连接至 peers 的 TCP 流量 | | 5000/tcp | TCP | 允许 | 受信任的 Validator IP | Validators 之间用于 BFT 通信的 TCP 流量 | | 3000/tcp | TCP | 允许 | 内部 VPC 或 VPN | 监控仪表板,应仅在内部 VPC 或 VPN 中开放 | | 3030/tcp | TCP | 拒绝 | 所有 IPv4/IPv6 | REST server。对于 validators,应**始终**禁用此项 | | 9000/tcp | TCP | 允许 | 内部 VPC 或 VPN | 监控指标导出,应仅在内部 VPC 或 VPN 中开放 | | 9090/tcp | TCP | 允许 | 内部 VPC 或 VPN | Prometheus 监控指标,应仅在内部 VPC 或 VPN 中开放 | **注意:** 确保您的打开文件数限制设置为 16,384 或更高。 要设置推荐配置,请运行: ``` # 提高当前用户的打开文件数限制(将 替换为您的用户名) echo " - nofile 65536" | sudo tee -a /etc/security/limits.conf # 提高系统默认的打开文件数限制 sudo bash -c 'echo "DefaultLimitNOFILE=65536" >> /etc/systemd/system.conf' ``` ## 3. 运行 Aleo 节点 ## 3.1 运行 Aleo 客户端 首先请按照[构建指南](#2-build-guide)中的说明进行操作。 以下指南提供了有关运行 `core` 和 `outer` 客户端(定义见第 2.2 节)的信息。建议运行 validators 的 Aleo 社区成员运行 1-3 个 `core` 客户端作为其专属的客户端 peers。这将确保在到达 validator 之前,对来自公共互联网的网络流量进行验证。 任何**未**直接连接到 validator 的客户端都可以被视为 `outer` 客户端。 ### 3.1.1 运行 Aleo Core Client 启动连接到 validator 的 Client 节点时,建议使用以下命令: `snarkos start --client --nodisplay --node 0.0.0.0:4130 --peers "validator_ip:4130,core_client_ip_1:4130,core_client_ip_2:4130,core_client_ip3:4130,outer_client_ip_1:4130,..." --verbosity 1 --norest` 要启动 core client 节点,您也可以在 `snarkOS` 目录中运行以下命令: ``` ./scripts/run-core-client.sh ``` ### 3.1.2 运行 Aleo Outer Client 启动**未**连接到 validator 的 Client 节点时,建议使用以下命令: `snarkos start --client --nodisplay --node 0.0.0.0:4130 --peers "core_client_ip_1:4130,core_client_ip_2:4130,core_client_ip3:4130,outer_client_ip_1:4130,..." --verbosity 1 --rest 0.0.0.0:3030` 要启动 outer client 节点,您也可以在 `snarkOS` 目录中运行以下命令: ``` ./scripts/run-outer-client.sh ``` Outer clients 可以作为引导客户端,充当具有公开已知或静态 IP 的新节点加入网络的入口点。 对于引导客户端,我们还建议使用 `--rotate-external-peers`,以防止引导节点列表被填满。 ## 3.2 运行 Aleo Validator 首先请按照[构建指南](#2-build-guide)中的说明进行操作。 启动 validator 节点时,建议使用以下命令: `snarkos start --validator --nodisplay --bft 0.0.0.0:5000 --node 0.0.0.0:4130 --peers "validator_ip_1:4130,validator_ip_2:4130,...,core_client_ip_1:4130,core_client_ip_2:4130,..." --validators "validator_ip_1:5000,validator_ip_2:5000,..." --verbosity 1 --norest --private-key-file ~/snarkOS/privatekey` 除了指定私钥文件(`--private-key-file` 标志)外,还可以显式定义私钥(`--private-key` 标志)。 要启动 validator,您也可以在 `snarkOS` 目录中运行以下命令: ``` ./scripts/run-validator.sh ``` ### 3.2.1 Validator 遥测指标 Validator 遥测允许您跟踪参与共识的情况。这在标准构建中是默认启用的。 启用后,可以通过以下方式获取遥测指标: 1. 节点日志 2. REST API endpoint // GET /{network}/validators/participation // GET /{network}/validators/participation?metadata={true} 遥测默认启用,您仍然可以显式指定 `telemetry` feature flag: #### 1. [安装](#2.3-installation) 使用默认安装命令: ``` cargo install --locked --path . ``` #### 2. `./run-validator.sh` 运行 `./scripts/run-validator.sh` 时默认包含遥测功能。 ## 3.3 运行 Aleo Prover 首先请按照[构建指南](#2-build-guide)中的说明进行操作。 接下来,生成一个 Aleo 账户地址: ``` snarkos account new ``` 这将在终端中输出一个新的 Aleo 账户。 **请务必保存账户私钥和查看密钥。** 以下是输出示例: ``` Attention - Remember to store this account private key and view key. Private Key APrivateKey1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <-- Save Me And Use In The Next Step View Key AViewKey1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <-- Save Me Address aleo1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <-- Save Me ``` 接下来,要在 `snarkOS` 目录中启动一个证明节点,请运行: ``` ./scripts/run-prover.sh ``` 出现提示时,输入您的 Aleo 私钥: ``` Enter the Aleo Prover account private key: APrivateKey1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` ## 4. 常见问题 ### 1. 我的节点无法编译。 - 确保您的机器已安装 Rust,且至少为[此版本](rust-toolchain)。[安装 Rust 的说明可以在这里找到。](https://www.rust-lang.org/tools/install) - 如果在编译期间出现重大错误,请尝试运行 `cargo clean`。 - 确保使用 `./scripts/run-client.sh` 或 `./scripts/run-prover.sh` 启动 `snarkOS`。 ### 2. 我的节点无法连接到网络上的 peers。 - 确保您的路由器和 OS 防火墙上开放了端口 `4130/tcp` 和 `3030/tcp`。 - 确保使用 `./scripts/run-client.sh` 或 `./scripts/run-prover.sh` 启动 `snarkOS`。 ### 3. 我无法生成新地址 - 在运行上述命令(`snarkos account new`)之前,请尝试运行 `source ~/.bashrc` - 还需仔细检查 `snarkos` 的拼写。请注意目录是 `/snarkOS`,而命令是 `snarkos` ### 4. 如何使用 CLI 签名和验证消息? 1. 如果您尚未拥有账户,请使用 `snarkos account new` 生成一个 2. 使用您的私钥通过 `snarkos account sign --raw -m "Message" --private-key-file=` 对消息进行签名 3. 使用 `snarkos account verify --raw -m "Message" -s sign1SignatureHere -a aleo1YourAccountAddress` 验证您的签名 请注意,在命令中使用 `--raw` 标志会将明文消息作为字节签名,而不是像 `1u8` 或 `100field` 这样的 [Aleo 值](https://developer.aleo.org/guides/aleo/language#data-types-and-values)。 ### 5. `node-data` 和 `ledger` 有什么区别? Ledger 仅包含公共账本信息,而 `node-data` 包含特定于创建它的节点的信息。后者不应与不受信任的来源共享,并且对于 validators 来说,它包含参与共识所需的数据。 6. 在启动时我收到一条错误消息,告诉我节点仍然使用旧的存储格式。我该怎么办? 节点应该已经为节点数据创建了一个新文件夹。例如,对于主网,应该存在一个路径为 `~/.aleo/storage/node-data-0` 的文件夹。 错误消息会告诉您需要迁移哪些数据。或者,您可以使用 `--auto-migrate-node-data` 启动节点,它将尝试自动执行此操作。 以下是可能需要迁移的所有文件的概述。 - JSON Web token 密钥,位于 `~/.aleo/storage/jwt_secrect_{address}.txt`。将其移动到 `~/.aleo/storage/node-data-0/jwt_secret_{address}.txt`。 请注意,如果您在运行具有不同地址的不同节点,可能会有多个此类文件。错误消息会告诉您需要迁移哪一个。 - 路由器 peer 缓存位于 `~/.aleo/storage/ledger-0/cache_router_peers`。将其迁移到 `~/.aleo/storage/node-data-0/router-peer-cache`。 - 网关 peer 缓存位于 `~/.aleo/storage/ledger-0/cache_gateway_peers`(仅适用于 validators)。将其迁移到 `~/.aleo/storage/node-data-0/gateway-peer-cache`。 - 最新的提案缓存位于 `~/.aleo/storage/current-proposal-cache-0`(仅适用于 validators)。将其迁移到 `~/.aleo/storage/node-data-0/current-proposal-cache`。 ## 5. 命令行界面 要使用自定义设置运行节点,请参考 `snarkOS` CLI 中可用的选项和标志。 可以通过 `snarkos --help` 查看完整的 CLI 标志和选项列表: ``` snarkOS The Aleo Team USAGE: snarkos [OPTIONS] OPTIONS: -h, --help Print help information -v, --verbosity Specify the verbosity [options: 0, 1, 2, 3] [default: 2] SUBCOMMANDS: account Commands to manage Aleo accounts clean Cleans the snarkOS node storage help Print this message or the help of the given subcommand(s) start Starts the snarkOS node update Update snarkOS ``` 以下是 `snarkos start` 命令的选项: ``` --network Specify the network ID of this node [options: 0 = mainnet, 1 = testnet, 2 = canary] [default: 0] --prover Start the node as a prover --client Start the node as a client (default). Client are "full nodes", i.e, validate and execute all blocks they receive, but they do not participate in AleoBFT consensus. --bootstrap-client Start the node as a bootstrap client. --validator Start the node as a validator. Validators are "full nodes", like clients, but also participate in AleoBFT. --noupdater Disable checking for new versions at startup --private-key Specify the account private key of the node --private-key-file Specify the path to a file containing the account private key of the node --node Set the IP address and port used for P2P communication --bft Set the IP address and port used for BFT communication. This argument is only allowed for validator nodes --peers Specify the IP address and port of the peer(s) to connect to (as a comma-separated list). These peers will be set as "trusted", which means the node will not disconnect from them when performing peer rotation. Setting peers to "" has the same effect as not setting the flag at all, except when using `--dev`. --validators Specify the IP address and port of the validator(s) to connect to --rest Specify the IP address and port for the REST server --rest-rps Specify the requests per second (RPS) rate limit per IP for the REST server [default: 10] --jwt-secret Specify the JWT secret for the REST server (16B, base64-encoded) --jwt-timestamp Specify the JWT creation timestamp; can be any time in the last 10 years --norest If the flag is set, the node will not initialize the REST server --nojwt If the flag is set, the node will not require JWT authentication for the REST server --trusted-peers-only If the flag is set, the node will only connect to trusted peers and validators --nodisplay Write log message to stdout instead of showing a terminal UI. This is useful, for example, for running a node as a service instead of in the foreground or to pipe its output into a file. --verbosity Specify the log verbosity of the node. [options: 0 (lowest log level) to 6 (highest level)] [default: 1] --log-filter Set a custom log filtering scheme, e.g., "off,snarkos_bft=trace", to show all log messages of snarkos_bft but nothing else --logfile Specify the path to the file where logs will be stored [default: /var/folders/6v/1bwnpyjd1r5f9wr_9hq25qsm0000gn/T/snarkos.log] --metrics Enable the metrics exporter --metrics-ip Specify the IP address and port for the metrics exporter --ledger-storage Specify the directory that holds all ledger data, e.g., blocks and transactions. This flag overrides the default path, even when `--dev` is set. The old name for this flag (`--storage`) is DEPRECATED and will eventually be removed. --node-data-storage Specify the directory that holds node-specific data, that is not part of the global ledger. This flag overrides the default path, even when `--dev` is set. That folder may contain sensitive data, such as the JWT secret, and should not be shared with untrusted parties. For validators, it also contains the latest proposal cache, which is required to participate in consensus. --cdn Enables the node to prefetch initial blocks from a CDN --nocdn If the flag is set, the node will not prefetch from a CDN --dev Enables development mode used to set up test networks. The purpose of this flag is to run multiple nodes on the same machine and in the same working directory. To do this, set the value to a unique ID within the test work. For example if there are four nodes in the network, pass `--dev 0` for the first node, `--dev 1` for the second, and so forth. If you do not explicitly set the `--peers` flag, this will also populate the set of trusted peers, so that the network is fully connected. Additionally, if you do not set the `--rest` or the `--norest` flags, it will also set the REST port to `3030` for the first node, `3031` for the second, and so forth. --dev-num-validators If development mode is enabled, specify the number of genesis validator [default: 4] --dev-num-clients If development mode is enabled, specify the number of clients. This is only used by validators to automatically populate their set of trusted peers. This option cannot be used while also passing the `--peers` flag. --no-dev-txs If development mode is enabled, specify whether node 0 should generate traffic to drive the network --dev-bonded-balances If development mode is enabled, specify the custom bonded balances as a JSON object -h, --help Print help (see a summary with '-h') ``` ## 6. 开发指南 ### 6.1 快速开始 在第一个终端中,通过运行以下命令启动第一个 validator: ``` cargo run --release -- start --nodisplay --dev 0 --validator ``` 在第二个终端中,通过运行以下命令启动第二个 validator: ``` cargo run --release -- start --nodisplay --dev 1 --validator ``` 在第三个终端中,通过运行以下命令启动第三个 validator: ``` cargo run --release -- start --nodisplay --dev 2 --validator ``` 在第四个终端中,通过运行以下命令启动第四个 validator: ``` cargo run --release -- start --nodisplay --dev 3 --validator ``` 接下来,可以使用此过程进一步启动 provers 和 clients。 ### 6.2 操作 请务必从 `0` 开始初始化节点,并为每个新节点递增 `1`。 以下是初始化节点的选项列表(将 `` 替换为从 `0` 开始的数字): ``` cargo run --release -- start --nodisplay --dev --validator cargo run --release -- start --nodisplay --dev --prover cargo run --release -- start --nodisplay --dev --client cargo run --release -- start --nodisplay --dev ``` 如果未指定节点类型,该节点将默认设为 `--client`。 ### 6.3 本地 Devnet #### 6.3.1 安装 `tmux` 要使用脚本运行本地 devnet,请首先安装 `tmux`。
macOS 要在 macOS 上安装 `tmux`,您可以使用 `Homebrew` 包管理器。 如果您尚未安装 `Homebrew`,可以在[他们的网站](https://brew.sh/)上找到相关说明。 ``` # 安装 Homebrew 后,运行: brew install tmux ```
Ubuntu 在 Ubuntu 和其他基于 Debian 的系统上,您可以使用 `apt` 包管理器: ``` sudo apt update sudo apt install tmux ```
Windows 在 Windows 上有几种使用 `tmux` 的方法: ### 使用 Windows Subsystem for Linux (WSL) 1. 首先,安装 [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install)。 2. 设置好 WSL 并安装了 Linux 发行版(例如 Ubuntu)后,打开您的 WSL 终端,像在原生 Linux 系统上一样安装 `tmux`: ``` sudo apt update sudo apt install tmux ```
#### 6.3.2 启动本地 Devnet 要启动本地 devnet,请运行: ``` ./scripts/devnet.sh ``` #### 6.3.3 查看本地 Devnet #### 切换节点(向前) 要切换到本地 devnet 中的下一个节点,请运行: ``` Ctrl+b n ``` #### 切换节点(向后) 要切换到本地 devnet 中的上一个节点,请运行: ``` Ctrl+b p ``` #### 选择节点(choose-tree) 要选择本地 devnet 中的某个节点,请运行: ``` Ctrl+b w ``` #### 选择节点(手动) 要手动选择本地 devnet 中的某个节点,请运行: ``` Ctrl+b :select-window -t {NODE_ID} ``` #### 6.3.4 停止本地 Devnet 要停止本地 devnet,请运行: ``` Ctrl+b :kill-session ``` 然后,按下 `Enter`。 ### 清理 要清理节点存储,请运行: ``` cargo run --release -- clean --dev ``` ## 6.4 Feature Flags 默认情况下,某些内部 crate 会开启指标和遥测功能。 * **history** - 启用 /history REST endpoint。 * **telemetry** - 允许节点上传遥测数据。 * **cuda** - 允许某些操作在(NVidia)GPU 上运行,而不是在 CPU 上。有关安装提示和当前谜题状态,请参阅 [Prover 的 CUDA 加速](#optional-cuda-acceleration-for-provers)。 * **locktick** - 此功能开启用于检测死锁的代码。 * **test_targets** - 此功能允许降低 coinbase 和 proof targets 以进行测试。 ## 6.5 本地备份 snarkOS 节点实现在底层使用了 rocksdb。通过使用其原生的检查点机制,您可以在本地高效地创建备份。这些备份利用您文件系统上的硬链接,因此仅会产生极少量的额外空间。这些本地备份旨在让您的节点发生意外停止时能够快速恢复。 注意:为了使备份保持增量且轻量,它们需要与账本存储在同一个文件系统中(这包括 `btrfs` 子卷);否则,它们将成为完整的副本。 您可以在 `scripts/backup.sh` 中找到一个基本的示例脚本,您可以将其作为 cron-job 运行,例如每分钟运行一次。每次运行脚本都会创建一个带有时间戳后缀的新备份文件夹。它将确保保留一份 1 分钟前、5 分钟前、1 小时前和 1 天前的备份。更详细地说,在每次运行时它将: - 始终覆盖最新的备份 - 仅在 5 分钟前的备份超过 5 分钟时才覆盖它 - 仅在 1 小时前的备份超过 1 小时才覆盖它 - 仅在 1 天前的备份超过 1 天才覆盖它 您可能需要更改 `NETWORK`、`BASE_DIR`、`ENDPOINT` 和 `JWT` 变量。 ## 8. 许可证 我们欢迎所有对 `snarkOS` 的贡献。有关贡献的条款,请参阅[许可证](#7-license)。 [![License: GPL v3](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE.md)
标签:Aleo网络, Rust, 区块链, 去中心化, 操作系统, 网络流量审计, 节点, 通知系统, 零知识证明