区块链的节点
约 2233 字大约 7 分钟
2025-10-05
节点的基础概念
FISCO BCOS 引入了游离节点、观察者节点和共识节点,这三种节点类型可以通过控制台互相转换。
组员:
- 共识节点:参与共识的节点,拥有群组的所有数据(搭链时默认都生成共识节点)。
- 观察者节点:不参与共识,但能实时同步链上数据的节点。
非组员:
- 游离节点:已启动,等待加入群组的节点。处在一种暂时的节点状态,不能获取链上的数据。
节点配置文件详解
节点搭建完成之后会有config.ini、conf/group.%group_id.genesis、conf/group.%group_id.ini、node.nodeid 等配置文件
config.ini
# 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=2group.1.genesis
# 共识机制配置
[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=falsegroup.1.ini
# 共识运行参数(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=node.nodeid
# 节点的 ID
f0535616759000b473a285d60814bc2c5927a9cb897644da46890de71e59df590cd6fe1b226a95e19a566b6fc127fd85032de0d9fdd3d529e5e50cd96ad51f28节点操作命令
addSealer:将节点转换为共识节点。addObserver:将节点转换为观察节点。removeNode:将节点设置为游离节点。getSealerList:查询当前的共识节点的列表getObserverList:查询当前的观察者节点的列表·getNodeList:查询当前的所有节点的列表
操作节点的时候是通过节点ID进行操作的,节点ID可以在节点目录的conf/node.nodeid中获取
请确保节点加入的区块链所有节点共识正常:正常的节点会输出+++日志