From ba6702c8807009c6e2688c1f254664fd27822226 Mon Sep 17 00:00:00 2001 From: si-meng-spec Date: Sun, 5 Oct 2025 17:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vuepress/notes.ts | 6 +- .../blockchain/practice/console-operator.md | 59 +++ .../blockchain/practice/node-deployment.md | 13 + .../blockchain/theory/fisco-bcos-node-type.md | 342 ++++++++++++++++++ 4 files changed, 418 insertions(+), 2 deletions(-) create mode 100644 docs/notes/ops/blockchain/practice/console-operator.md create mode 100644 docs/notes/ops/blockchain/theory/fisco-bcos-node-type.md diff --git a/docs/.vuepress/notes.ts b/docs/.vuepress/notes.ts index 1dd6401..6f325fa 100644 --- a/docs/.vuepress/notes.ts +++ b/docs/.vuepress/notes.ts @@ -45,14 +45,16 @@ const blockchain = defineNoteConfig({ sidebar: [ { text: "区块链运维指南", link: "/ops/blockchain/" }, { - text: "区块链理论基础", items: [ + text: "区块链理论基础", prefix: "/theory", items: [ { text: "区块链的基本原理", link: "/ops/blockchain/theory/basic-principles/" }, + { text: "FISCO-BCOS 节点类型", link: "/ops/blockchain/theory/fisco-bcos-node-type/" } ] }, { text: "区块链运维", items: [ { text: "区块链产品设计和基本部署", link: "/ops/blockchain/practice/basic-deployment/" }, - { text: "区块链网络部署与管理", link: "/ops/blockchain/practice/node-deployment/" } + { text: "区块链网络部署与管理", link: "/ops/blockchain/practice/node-deployment/" }, + { text: "Console 控制台操作", link: "/ops/blockchain/practice/console-operator/" } ] } ] diff --git a/docs/notes/ops/blockchain/practice/console-operator.md b/docs/notes/ops/blockchain/practice/console-operator.md new file mode 100644 index 0000000..d89a8e7 --- /dev/null +++ b/docs/notes/ops/blockchain/practice/console-operator.md @@ -0,0 +1,59 @@ +--- +title: Console 控制台操作 +createTime: 2025/10/03 02:55:49 +permalink: /ops/blockchain/practice/console-operator/ +--- + +## Console 控制台是什么? +Console 是 FISCO BCOS 官方提供的一个交互式命令行工具,用于直接与区块链节点交互。 +主要功能包括: +- 查询区块链状态(如区块链高度、节点列表、群组信息) +- 部署和调用智能合约(支持 Solidity) +- 管理节点(如查看节点共识状态、动态添加节点) +- 调试交易和查看回执 + +## 部署 Console 控制台 +获取下载脚本:`wget https://gitee.com/FISCO-BCOS/console/releases/download/v2.8.0/console.tar.gz` +解压控制台安装包:`tar -zxf console.tar.gz console/` + +复制配置文件:`cp conf/config-example.toml conf/config.toml` +编辑配置文件:`vim conf/config.toml` +```bash +# enSslKey = "conf/gm/gmensdk.key" # GM ssl cert file path + # default load the GM SSL encryption privateKey from ${certPath}/gm/gmensdk.key + +[network] +# 请确保这里的连接地址都有节点 +peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connect [!code warning] + +# Configure a private topic as a topic message sender. + +``` + +复制节点证书到 Console 的配置目录下 +```bash +cp -r ../nodes/127.0.0.1/sdk/* conf/ +``` + +通过 `bash start.sh` 就可以启动 Console 控制台啦! +![启动Console控制台](https://image.simengweb.com/notes/ops/blockchain/practice/console-operator/2025-10-03-161500.png) + +## 常用控制台命令 + +这里的区块链的搭建是根据前一篇文章中的多机构多群组多节点的关系 + +### 合约相关命令 +### 其他命令 +- 查询区块高度:`getBlockNumber` +```bash title='output_example' +[group:1]> getBlockNumber +0 +``` +- 查看共识节点列表:`getSealerList` +```bash title='output_example' +[group:1]> getSealerList +[ + d036a22f16909cba4c8521cd3c31db3be381e673c9749e3fd2848ab25eca134ef917cb9306f41893295c535078bce77bdc241eba3f92549a73efe4699d3c0df8, + f0535616759000b473a285d60814bc2c5927a9cb897644da46890de71e59df590cd6fe1b226a95e19a566b6fc127fd85032de0d9fdd3d529e5e50cd96ad51f28 +] +``` \ No newline at end of file diff --git a/docs/notes/ops/blockchain/practice/node-deployment.md b/docs/notes/ops/blockchain/practice/node-deployment.md index 3133454..26febfd 100644 --- a/docs/notes/ops/blockchain/practice/node-deployment.md +++ b/docs/notes/ops/blockchain/practice/node-deployment.md @@ -76,6 +76,19 @@ info|2025-10-02 17:08:33.807504|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generat ``` 不断输出带有 `++++Generating seal` 的日志,说明共识正常 +检查群组之间的共识 +```bash +tail -f nodes/127.0.0.1/node0/log/log* | grep 'g:1.*+++' +``` +输出样例如下: +```bash +info|2025-10-02 17:59:59.194525|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=fdb2da54... +info|2025-10-02 18:59:59.225102|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=b7d87997... +info|2025-10-02 19:59:59.327677|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=38dea43f... +info|2025-10-02 20:59:59.462059|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=cb0e89fa... +info|2025-10-02 21:59:59.284218|[g:1][CONSENSUS][SEALER]++++++++++++++++ Generating seal on,blkNum=1,tx=0,nodeIdx=1,hash=721e8904... +``` + ### 部署多机构多群组多节点 在很多时候,我们需要部署多机构多群组多节点的联盟链,来满足不同业务场景下的需求。 diff --git a/docs/notes/ops/blockchain/theory/fisco-bcos-node-type.md b/docs/notes/ops/blockchain/theory/fisco-bcos-node-type.md new file mode 100644 index 0000000..f5d1d40 --- /dev/null +++ b/docs/notes/ops/blockchain/theory/fisco-bcos-node-type.md @@ -0,0 +1,342 @@ +--- +title: fisco-bcos-node-type +createTime: 2025/10/05 13:07:05 +permalink: /ops/blockchain/theory/fisco-bcos-node-type/ +--- + +## 节点的基础概念 + +FISCO BCOS 引入了[游离节点、观察者节点和共识节点](https://fisco-bcos-documentation.readthedocs.io/zh-cn/latest/docs/design/security_control/node_management.html#id6),这三种节点类型可以通过控制台互相转换。 + +组员: +- 共识节点:参与共识的节点,拥有群组的所有数据(搭链时默认都生成共识节点)。 +- 观察者节点:不参与共识,但能实时同步链上数据的节点。 + +非组员: +- 游离节点:已启动,等待加入群组的节点。处在一种暂时的节点状态,不能获取链上的数据。 + +## 节点配置文件详解 + +节点搭建完成之后会有`config.ini`、`conf/group.%group_id.genesis`、`conf/group.%group_id.ini`、`node.nodeid` 等配置文件 + +::: code-tabs +@tab config.ini +```bash +# RPC (Remote Proceduce Call 远程过程调用) +# 用于配置节点对外提供的 RPC 服务,包括 JSON-RPC ( 用于 Web3.js,控制台等 )和 Channel 通信( 用于 SDK,Java 应用等 ) +[rpc] + # 允许外部访问 + channel_listen_ip=0.0.0.0 + channel_listen_port=20200 + # 只允许内部访问 + jsonrpc_listen_ip=127.0.0.1 + jsonrpc_listen_port=8545 + +# P2P (Peer-to-Peer 点对点通信) +# 用于配置节点之间的 P2P 通信 +[p2p] + listen_ip=0.0.0.0 + listen_port=30300 + ; nodes to connect + node.0=127.0.0.1:30300 + node.1=127.0.0.1:30301 + node.2=127.0.0.1:30400 + node.3=127.0.0.1:30401 + node.4=127.0.0.1:30500 + node.5=127.0.0.1:30501 + node.6=127.0.0.1:30600 + node.7=127.0.0.1:30601 + +# 证书的黑白名单控制 +[certificate_blacklist] + ; crl.0 should be nodeid, nodeid's length is 128 + ;crl.0= + +[certificate_whitelist] + ; cal.0 should be nodeid, nodeid's length is 128 + ;cal.0= + +# 群组的配置目录和数据目录 +# 启动的时候会自动加载 group_config_path 下的所有群组 +[group] + group_data_path=data/ + group_config_path=conf/ + +# 配置网络安全 +[network_security] + ; directory the certificates located in + # 网络部分的配置文件目录 + data_path=conf/ + ; the node private key file + # 节点的私钥文件 + key=node.key + ; the node certificate file + # 节点的证书文件 + cert=node.crt + ; the ca certificate file + # CA 的证书文件 + ca_cert=ca.crt + +# 配置加密存储 +# 用于对接 KMS ,实现落盘数据加密 +# 具体的可以查看参考文献中的第2篇文章,落盘加密 +[storage_security] + enable=false + key_manager_ip= + key_manager_port= + cipher_data_key= + +# 链的基本信息 +[chain] + # 链的 ID ,不同链ID的节点无法通信 + id=1 + ; use SM crypto or not, should nerver be changed + # 是否启动国密算法,这一步在创建的时候就应该规划好 + # 一旦设定,不可更改,否则无法和其他节点通信 + sm_crypto=false + # cannel 是否启用国密,需和 SDK 一致 + sm_crypto_channel=false + +# 兼容性配置 +[compatibility] + ; supported_version should nerver be changed + # 指定节点兼容的 FISCO BCOS 的版本 + # 默认值即可,不应手动修改 + supported_version=2.8.0 + +# 日志配置 +[log] + # 启用配置 + enable=true + # 日志配置目录 + log_path=./log + ; enable/disable the statistics function + # 是否启用统计功能 + enable_statistic=false + ; network statistics interval, unit is second, default is 60s + # 统计信息刷新间隔(单位:秒) + stat_flush_interval=60 + ; info debug trace + # 日志级别,可选值(trace < debug < info < warning < error) + level=info + ; MB + # 单个日志文件最大大小(单位:MB) + max_log_file_size=200 + # 是否实时刷盘 + flush=true + +# 流量控制 +[flow_control] + ; restrict QPS of the node + # 限制 QPS 每秒请求数,防止 DDOS + ;limit_req=1000 + ; restrict the outgoing bandwidth of the node + ; Mb, can be a decimal + ; when the outgoing bandwidth exceeds the limit, the block synchronization operation will not proceed + # 限制节点出带宽(单位Mbps) + # 超出之后会暂停区块同步,避免网络拥塞 + ;outgoing_bandwidth_limit=2 +``` +@tab group.1.genesis +```bash +# 共识机制配置 +[consensus] + ; consensus algorithm now support PBFT(consensus_type=pbft), Raft(consensus_type=raft) + ; rpbft(consensus_type=rpbft) + # 共识算法 + consensus_type=pbft + ; the max number of transactions of a block + # 每个区块的最大打包量,超出的部分会留在交易池,等待下一次打包 + max_trans_num=1000 + ; in seconds, block consensus timeout, at least 3s + # 共识算法的超时时间 + consensus_timeout=3 + ; rpbft related configuration + ; the working sealers num of each consensus epoch + # 仅在 rpbft 的时候生效,每轮共识 epoch 中参与打包的共识节点数。 + epoch_sealer_num=2 + ; the number of generated blocks each epoch + # 仅在 rpbft 的时候生效,每轮 epoch 持续的区块数。 + epoch_block_num=1000 + ; the node id of consensusers + # 群组中共识节点的列表 + node.0=f0535616759000b473a285d60814bc2c5927a9cb897644da46890de71e59df590cd6fe1b226a95e19a566b6fc127fd85032de0d9fdd3d529e5e50cd96ad51f28 + node.1=d036a22f16909cba4c8521cd3c31db3be381e673c9749e3fd2848ab25eca134ef917cb9306f41893295c535078bce77bdc241eba3f92549a73efe4699d3c0df8 + +# 存储区块链的状态信息 +# 支持 storage state 和 MPT state +# storage state 效率高 +# MPT state 效率低,但是包含完整的历史信息 +[state] + type=storage +# transaction (交易)相关配置 +# gas 是一种计算智能合约执行过程中消耗的计算和存储资源,包括交易的gas的最大值的限制和区块的gas最大值的限制 +# 如果交易或区块执行消耗的 gas 超过限制,则会丢弃交易区块 +# FISCO BCOS 是联盟链,简化了 gas 的设计,仅保留交易最大 gas 限制,区块最大 gas 是通过共识配置的 +[tx] + ; transaction gas limit + gas_limit=300000000 +# 群组的配置 +[group] + # 群组 ID + id=1 + # 群组的创世区块的时间戳(ms) + timestamp=1759397321000 + +# 群组的 EVM 配置 +# 是否开启 free storage +# 这里具体的内容,可以查看参考文献中的第4篇文章,【教程】如何修改FISCO-BCOS内的EVM的gas... +[evm] + enable_free_storage=false +``` +@tab group.1.ini +```bash +# 共识运行参数(PBFT 优化) +[consensus] + ; the ttl for broadcasting pbft message + # PBFT 消息在网络中最多转发 2 跳 + ttl=2 + ; min block generation time(ms) + # 最小出块时间 500ms + min_block_generation_time=500 + # 动态调整区块大小 genesis 中的 max_trans_num + enable_dynamic_block_size=true + # 优化 TLL 转发逻辑,提升 PBFT 在大规模网络中的效率 + enable_ttl_optimization=true + # Prepare 消息中只包含交易哈希,减少网络传输量 + # 大幅提示大区块场景下的共识效率 + enable_prepare_with_txsHash=true + ; The following is the relevant configuration of rpbft + ; set true to enable broadcast prepare request by tree + # 使用树状拓扑广播 Prepare 广播(而非全网广播) + # 适合节点多的场景 + # 仅在 rpbft 或优化版 PBFT 中有效 + broadcast_prepare_by_tree=true + ; percent of nodes that broadcast prepare status to, must be between 25 and 100 + # 广播 Prepare 状态给33%的节点,必须在 25%~100% 之间 + prepare_status_broadcast_percent=33 + ; max wait time before request missed transactions, ms, must be between 5ms and 1000ms + # 请求缺失交易前,最多等待 100ms(收集更多交易) + # 范围 5 ~ 1000ms + max_request_missedTxs_waitTime=100 + ; maximum wait time before requesting a prepare, ms, must be between 10ms and 1000ms + # 请求缺失 Prepare 消息前,最多等待 100ms + # 范围 10ms ~ 1000ms + max_request_prepare_waitTime=100 + +[storage] + ; storage db type, rocksdb / mysql / scalable, rocksdb is recommended + # 存储引擎 + # 推荐使用 rocksdb (高性能,嵌入式 KV 数据库) + # 支持 mysql ( 不推荐,性能差 ) , scalable (分布式存储,实验性) + type=rocksdb + ; set true to turn on binary log + # 开启二进制日志,默认关闭,开启会增加IO + binary_log=false + ; scroll_threshold=scroll_threshold_multiple*1000, only for scalable + # 仅在 scalable 存储引擎下生效 + scroll_threshold_multiple=2 + ; set fasle to disable CachedStorage + # 启用缓存层(非常推荐) + cached_storage=true + ; max cache memeory, MB + # 缓存最大内容,32MB + max_capacity=32 + # 允许节点最多超前同步10个区块 + max_forward_block=10 + ; only for external, deprecated in v2.3.0 + # 最大重试次数,默认 60 次 + max_retry=60 + topic=DB + ; only for mysql + db_ip=127.0.0.1 + db_port=3306 + db_username= + db_passwd= + db_name= +# 交易池 +[tx_pool] + # 交易池最大容量,默认 150000 + limit=150000 + ; transaction pool memory size limit, MB + # 交易池最大内存占用:512 MB + memory_limit=512 + ; number of threads responsible for transaction notification, + ; default is 2, not recommended for more than 8 + # 用于通知 SDK 交易上链结果的线程数 + notify_worker_num=2 +# 区块同步优化 +[sync] + ; max memory size used for block sync, must >= 32MB + # 区块同步最大内存:512MB,必须大于等于 32 MB + max_block_sync_memory_size=512 + # 同步空闲时,等待 200ms 再检查新块 + idle_wait_ms=200 + ; send block status by tree-topology, only supported when use pbft + # 使用树状拓扑同步区块 + # 可以大幅度降低网络带宽 + # 仅在 PBFT 下支持 + sync_block_by_tree=true + ; send transaction by tree-topology, only supported when use pbft + ; recommend to use when deploy many consensus nodes + # 交易广播也使用树状拓扑 + send_txs_by_tree=true + ; must between 1000 to 3000 + ; only enabled when sync_by_tree is true + # Gossip 协议心跳间隔 + gossip_interval_ms=1000 + # 每个节点维护 3 个gossip邻居 + gossip_peers_number=3 + ; max number of nodes that broadcast txs status to, recommended less than 5 + # 交易状态最多广播给5个节点 + txs_max_gossip_peers_num=5 + +# 群组级的流量控制 +[flow_control] + ; restrict QPS of the group + # 限制群组的 QPS 为 1000 + ;limit_req=1000 + ; restrict the outgoing bandwidth of the group + ; Mb, can be a decimal + ; when the outgoing bandwidth exceeds the limit, the block synchronization operation will not proceed + # 限制群组的出链带宽为 2Mbps/s + ;outgoing_bandwidth_limit=2 + +# SDK 连接白名单 +[sdk_allowlist] + ; When sdk_allowlist is empty, all SDKs can connect to this node + ; when sdk_allowlist is not empty, only the SDK in the allowlist can connect to this node + ; public_key.0 should be nodeid, nodeid's length is 128 + ;public_key.0= +``` +@tab node.nodeid +```bash +# 节点的 ID +f0535616759000b473a285d60814bc2c5927a9cb897644da46890de71e59df590cd6fe1b226a95e19a566b6fc127fd85032de0d9fdd3d529e5e50cd96ad51f28 +``` +::: + +## 节点操作命令 + +- `addSealer`:将节点转换为共识节点。 +- `addObserver`:将节点转换为观察节点。 +- `removeNode`:将节点设置为游离节点。 + +- `getSealerList`:查询当前的共识节点的列表 +- `getObserverList`:查询当前的观察者节点的列表· +- `getNodeList`:查询当前的所有节点的列表 + +操作节点的时候是通过节点ID进行操作的,节点ID可以在节点目录的`conf/node.nodeid`中获取 + +请确保节点加入的区块链所有节点共识正常:正常的节点会输出`+++`日志 + + +## 参考文章: + +1. [组员节点管理](https://fisco-bcos-documentation.readthedocs.io/zh-cn/latest/docs/manual/node_management.html) + +2. [落盘加密](https://fisco-bcos-documentation.readthedocs.io/zh-cn/latest/docs/design/features/storage_security.html) + +3. [【全网首发】FISCO-BCOS从底层讲起链从配置文件开始解析...](https://blog.csdn.net/LforikQ/article/details/130920092) + +4. [【教程】如何修改FISCO-BCOS内的EVM的gas值,让区块链预防DOS攻击...](https://blog.csdn.net/qq_57309855/article/details/126334115) \ No newline at end of file