40 个重大版本发布
新版本 0.41.0 | 2024 年 8 月 23 日 |
---|---|
0.39.0 | 2024 年 7 月 29 日 |
0.3.0 | 2024 年 3 月 29 日 |
#49 in 神奇豆
825 次月下载
3MB
9K SLoC
Photon
Solana 压缩索引器
安装
首先安装依赖项(Ubuntu)
apt install -y build-essential pkg-config libssl-dev
然后运行
cargo install photon-indexer
运行 Photon
要运行 photon,请运行
# Against localnet
photon
# Against devnet
photon --rpc-url=https://api.devnet.solana.com
# Streaming new blocks using gRPC instead of polling
photon --rpc-url=https://api.devnet.solana.com --grpc-url=<grpc_url>
# Using your local Postgres database instead of the default temporary SQL database
photon --db-url=postgres://postgres@localhost/postgres
# Specifying a start slot. Defaults to 0 for localnet and current for devnet/mainnet
photon --start-slot=123
# To see more configuration options
photon --help
Photon 快照
Photon 支持快照,这使 Photon 运营商能够更快地加载 Photon。否则,运营商需要索引自 ZK 压缩合约发布以来的所有 Solana 块。
Helius 支持用于加载快照的公共端点。要加载快照,只需运行
photon-snapshot-loader --snapshot-dir=~/snapshot --snapshot-server-url=https://photon-devnet-snapshot.helius-rpc.com
然后使用快照更快地加载 Photon
# Photon will disregard the snapshot if the database is more up-to-date.
photon-indexer --snapshot-dir=~/snapshot --r=https://api.devnet.solana.com --db-url=postgres://postgres@localhost/postgres
要创建快照,您可以运行 Photon 快照器
photon-snapshotter --snapshot-dir=~/snapshot
您还可以指定 R2 存储快照文件而非本地目录的存储桶
# If you specify an R2 bucket, you must set the R2_ACCESS_KEY, R2_ACCOUNT_ID and R2_SECRET_KEY
photon-snapshotter --r2-bucket=some-bucket --r2-prefix=prefix
数据库管理
我们支持 Postgres 和 SQLite 作为数据库后端。Photon 默认使用自动配置的 SQLite 内存数据库。要指定其他数据库后端,请运行迁移并指定运行 Photon 时的数据库 URL。
export DATABASE_URL="postgres://postgres@localhost/postgres" # Or your SQLlite database url
photon-migration up
photon --db-url=$DATABASE_URL
本地开发
运行测试
要运行测试,请本地安装和运行 Postgres 和 SQLite。对于 MacOS 用户,我们建议使用 Homebrew 运行本地 Postgres:https://wiki.postgresql.ac.cn/wiki/Homebrew。
然后导出环境变量以配置您的 RPC 和测试 Postgres URL。对于 SQLite 测试,我们始终使用内存中的 SQLite 数据库,因此无需配置测试 URL。
export MAINNET_RPC_URL=https://api.devnet.solana.com
export DEVNET_RPC_URL=https://api.mainnet-beta.solana.com
export TEST_DATABASE_URL="postgres://postgres@localhost/postgres"
此外,对于测试,我们使用 swagger-cli
验证我们的 OpenAPI 架构。因此,请安装它
npm install -g @apidevtools/swagger-cli
运行 minio 以测试快照功能
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
最后运行 Gnark 验证器,这对于集成测试是必需的
docker run -p 3001:3001 docker.io/pmantica1/light-prover:1
完成设置后,只需简单地运行
cargo test
注意,对于Postgres和SQLite,所有迁移将在测试期间自动运行。因此不需要预先配置。
数据库模型自动生成
要生成数据库模型,首先安装sea-orm-cli
cargo install sea-orm-cli --version 0.10.6
然后运行
sea-orm-cli generate entity -o src/dao/generated
文档生成
为了更新API的OpenAPI模式,请首先通过以下方式安装swagger-cli
npm install -g @apidevtools/swagger-cli
然后运行
cargo run --bin=photon-openapi
依赖项
~124MB
~2.5M SLoC