节点提供商#
本指南介绍如何搭建支持 Flashblocks 的 RPC 节点。
快速开始#
前提条件#
- Docker 和 Docker Compose
- 最低硬件要求(详见 Setup RPC)
- 可访问 Flashblocks WebSocket 端点
搭建步骤#
更多信息请参阅 xlayer-toolkit 的 README。
shell
mkdir -p /data/xlayer-mainnet && cd /data/xlayer-mainnet
curl -fsSL https://raw.githubusercontent.com/okx/xlayer-toolkit/main/rpc-setup/one-click-setup.sh -o one-click-setup.sh
chmod +x one-click-setup.sh
./one-click-setup.sh --rpc_type=reth
配置#
one-click-setup.sh 脚本包含交互式提示,用于配置 Flashblocks 相关变量。Flashblocks 专项配置请参考下表:
| 变量 | 值 |
|---|---|
FLASHBLOCKS_ENABLED | true |
FLASHBLOCKS_URL | wss://xlayerws.okx.com/flashblocks |
注意,RPC 节点必须运行 reth 而非 geth。
验证 Flashblocks 功能#
已启用 Flashblocks 的节点将在待确认区块(pending block)中返回预确认交易(preconfirmed transactions):
shell
curl http://localhost:8545 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["pending",true],"id":1}'
Flashblocks WebSocket#
以下端点暴露公共 WebSocket API,用于流式传输原始 Flashblocks 数据,也是 RPC 节点配置时所需的 URL。
| 网络 | URL |
|---|---|
| 主网 | wss://ws.xlayer.tech/flashblocks |
| 主网 | wss://xlayerws.okx.com/flashblocks |
| 测试网 | wss://testws.xlayer.tech/flashblocks |
| 测试网 | wss://xlayertestws.okx.com/flashblocks |
Flashblocks 数据#
Flashblock 消息采用增量压缩(delta compression):
- 索引 0:完整的 base 与 diff 对象(区块属性 + 交易)。
- 索引 1+:仅含 diff 对象(该 flashblock 中的新增交易)。
增量压缩通过仅传输增量变更来减小消息体积。
Base + Diff 响应#
json
{
"base": {
"base_fee_per_gas": "0x5f5e0ff",
"block_number": "0x8328ab",
"extra_data": "0x...",
"fee_recipient": "0x...",
"gas_limit": "0xbebc200",
"parent_beacon_block_root": "0x...",
"parent_hash": "0x...",
"prev_randao": "0x...",
"timestamp": "0x695dd9b6"
},
"diff": {
"blob_gas_used": "0x0",
"block_hash": "0x...",
"gas_used": "0x6c63",
"logs_bloom": "0x...",
"receipts_root": "0x...",
"state_root": "0x...",
"transactions": [],
"withdrawals": [],
"withdrawals_root": "0x..."
},
"index": 0,
"metadata": {
"block_number": 8595627,
"new_account_balances": {
"0x0000f90827f1c53a10cb7a02335b175320002935": "0x0"
},
"receipts": {
"0x56d542ee662d9a7e1696880346a3f2fb1ed091c15b7c6b607f64ae95e431b097": {
"Deposit": {}
}
}
},
"payload_id": "0x03307607ad2ba79d"
}
Diff 响应#
json
{
"diff": {
"blob_gas_used": "0x0",
"block_hash": "0x...",
"gas_used": "0xbe6b",
"logs_bloom": "0x...",
"receipts_root": "0x...",
"state_root": "0x...",
"transactions": [],
"withdrawals": [],
"withdrawals_root": "0x..."
},
"index": 1,
"metadata": {
"block_number": 8595627,
"new_account_balances": {
"0x0000f90827f1c53a10cb7a02335b175320002935": "0x0"
},
"receipts": {
"0x30130a020af408787a9388dcf0272635fff7bc15ae118edb76d207391bb57b51": {
"Legacy": {}
}
}
},
"payload_id": "0x03307607ad2ba79d"
}
在线测试#
使用我们的公共 RPC 端点在 X Layer 上测试 Flashblocks。在终端中运行以下命令,将占位符替换为实际参数。
eth_getBlockByNumber#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["pending",true],"id":1}'
eth_getTransactionReceipt#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0x..."],"id":1}'
eth_getBalance#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x...","pending"],"id":1}'
eth_getTransactionCount#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["0x...","pending"],"id":1}'
eth_getTransactionByHash#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x..."],"id":1}'
eth_call#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x...","data":"0x..."},"pending"],"id":1}'
eth_estimateGas#
shell
curl https://rpc.xlayer.tech/flashblocks -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to":"0x...","data":"0x..."},"pending"],"id":1}'
