您现在的位置是:首页 >技术杂谈 >Tendermint介绍网站首页技术杂谈
Tendermint介绍
Tendermint Spec
Tendermint是一个区块链共识引擎和应用程序平台。它提供了一种高效且安全的方式来达成区块链参与者之间的共识,支持多种编程语言和不同类型的应用。
Tendermint包括两个主要技术组件:区块链共识引擎和通用应用程序接口。 共识引擎,被称作Tendermint Core,保证所有的机器按照相同的顺序记录相同的交易。 应用程序接口,被称为应用程序区块链接口ABCI,实现任意编程语言处理交易的功能。
1.区块链共识引擎
The latest gossip on BFT consensus
https://arxiv.org/abs/1807.04938
Tendermint通过依赖节点之间的p2p协议简化了BFT算法的设计。
一般情况下,区块链交易的流程如下:
1.交易广播:客户将交易发送到区块链网络中,让其他节点知道这笔交易已经存在了。
2.验证交易:节点会验证交易是否合法,如确认交易双方的身份和余额是否足够完成交易。
3.交易打包:验证通过后,节点将该笔交易打包进一个区块。
4.区块生成:当一个区块中的交易达到一定数量时,该区块就会被生成并添加到区块链中。
5.区块链确认:一旦区块被添加到区块链中,该笔交易就被确认了。其余节点也会更新它们的账本,将这笔交易加入到它们的账本中。最终,交易完成。交易的确认速度取决于区块链采用的共识算法以及网络拥堵情况等因素。
区块链基本的共识流程如下:
区块链共识的流程可以分为以下几个步骤:
1.提案:参与者通过提议创建一个新区块
2.验证:网络的所有节点开始验证这个新提案,确保它符合规则、有效和正确
3.投票:节点通过投票来决定是否接受这个提案,通常使用代币或权益来进行投票
4.更新区块链:一旦足够多的节点达成一致,新区块就被添加到区块链上,完成共识过程
不同的共识算法会采用不同的流程,但以上步骤是共识算法核心流程的基础。
Tendermint共识流程:
Tendermint是一个易于理解的、主要是异步操作的BFT共识协议。
协议的参与者称为validators(验证者);他们轮流提出区块并对其进行投票。 在链中提交的每一个区块都有一个height(高度)。 当一个区块提交失败时,协议将进入到下一round(轮),新的验证者将为该高度提出一个新的区块。 成功提交一个块需要两个阶段的投票,分别是pre-vote(预投票)和pre-commit(预提交)。 当超过2/3的验证者在同一轮中预提交同一个区块时,区块就会被提交到区块链中。
验证者可能由于多种原因未能提交区块: 当前的区块提交者可能离线,或者网络可能拥堵。 Tendermint允许他们确认应当跳过这个验证者。 在投票进入下一轮之前,验证者们会等待一小段时间从提交者处收到完整的区块。 由于依赖超时,Tendermint成为弱同步协议,而不是异步协议。 不过协议的其余部分是异步的,只有在收到超过三分之二验证者集合的消息后,验证者才会进行下一步工作。 Tendermint一个可以被简化的地方在于,和跳到下一轮投票一样,它使用了同样的机制进行提交区块处理。
只要拜占庭验证节点数目不少于1/3,那么Tendermint保证永远不会违背安全性, 也就是说,验证者永远不会在同一高度提交冲突的区块。 为此,它引入了一些**locking(锁定)**规则,这些规则对流程图中的路径进行了模块化。 一旦验证者预提交一个块,它就锁定在该块上。那么,1.验证者一定为锁定到的区块预投票2.当超过2/3的验证者在同一轮中预提交同一个区块时,区块就会被提交到区块链中。此区块才可以解锁并预通过新区块。
Tendermint并不关注验证者数目的三分之一或三分之二, 而是关注总投票权的比例。此外,这个比例可能不是在各个验证者中均匀分布的。
2.Tendermint架构概述
通信方式
Tendermint Core中可以发生三种通信(如请求、响应、连接)形式:节点间通信、节点内通信和客户端通信。
节点间通信:发生在节点和其他对等节点之间。这种通信基于TCP或HTTP进行。
节点间通信有两种方式:
1.基于P2P报文的TCP连接
节点间通信最常见的形式 ,基于switch,节点间的连接被持久化并在reactor之间共享
2.基于HTTP/websocket的RPC
针对短期一次性请求,如:reactor特定状态,像高度信息
同样存在:为了获取通知信息,连接到通道的websocket(类似新交易请求)
TCP特性及mconnection介绍:
为了在Tendermint环境中有较好的TCP连接效果, 基于TCP协议,创建了mconnection或叫做多路复用连接。 它允许重用TCP连接以最小化开销,并在必要时通过发送辅助消息来保持高通信窗口
以下是Reactor的一些特征:
-
每个reactor都持有全局Switch的指针(通过SetSwitch()配置)
Switch持有每个reactor的指针(通过addReactor()添加) -
每个reactor都在node.go中配置(如果使用自定义reactor,也需要在node.go中指定)
-
Switch调用addReactor方法;addReactor方法中为传递的reactor变量调用setSwitch方法
-
由于Switch持有每个reactor的指针,因此,reactor通过Switch获取彼此的引用来相互通信。
reactor列表:Blockchain Reactor 、Consensus Reactor、Evidence Reactor、Mempool Reactor、PEX Reactor
node.go是启动节点的入口。它配置reactor和switch,并注册节点的所有RPC服务。
节点类型
1.验证节点
2.全节点
3.种子节点
节点内通信:发生在节点自身内部(也就是在节点内的reactor和其他组件之间)。通常都使用函数或方法调用,偶尔也依靠事件总线通信。
客户端通信:发生在客户端(如钱包或浏览器)和区块链网络节点之间
Tendermint Core
1.创世文件genesis.json 在目录$TMHOME/config/下
{
“genesis_time”: “2023-04-04T15:21:30.411959694Z”,//区块链创世时间
“chain_id”: “test-chain-r29QhZ”,//区块链ID 唯一
“initial_height”: “0”,//初始高度
“consensus_params”: {//共识参数
“block”: {
“max_bytes”: “22020096”,
“max_gas”: “-1”,
“time_iota_ms”: “1000”
},
“evidence”: {//
“max_age_num_blocks”: “100000”,
“max_age_duration”: “172800000000000”,
“max_bytes”: “1048576”
},
“validator”: {
“pub_key_types”: [
“ed25519”
]
},
“version”: {}
},
“validators”: [//初始验证者列表
{
“address”: “BAD2525484CD268755FBDB13AB22110D24479803”,
“pub_key”: {//第一个元素的公钥
“type”: “tendermint/PubKeyEd25519”,
“value”: “2J8jYlZHhjdsyHMSArm3FiUJdxiTQcbqmj788hD5+Jc=”
},
“power”: “10”,//验证者节点的投票权
“name”: “”
}
],
“app_hash”: “”//在创世中期望的应用程序哈希(由 ResponseInfo ABCI消息返回)
}
2.复位
tendermint unsafe_reset_all //不安全的重置区块链,该命令将删除数据目录并重置私有验证者和地址簿文件
3.配置文件详解 目录$TMHOME/config/config.toml文件下
由tendermint init创建的默认配置文件使用默认值设置了所有参数
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
# NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or
# relative to the home directory (e.g. "data"). The home directory is
# "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable
# or --home cmd flag.
#######################################################################
### Main Base Config Options ###
#######################################################################
# TCP or UNIX socket address of the ABCI application,
# or the name of an ABCI application compiled in with the Tendermint binary
proxy_app = "tcp://127.0.0.1:26658"
# A custom human readable name for this node
moniker = "harry"
# If this node is many blocks behind the tip of the chain, FastSync
# allows them to catchup quickly by downloading blocks in parallel
# and verifying their commits
fast_sync = true//快速同步
# Database backend: goleveldb | cleveldb | boltdb | rocksdb | badgerdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
# - fast
# - requires gcc
# - use cleveldb build tag (go build -tags cleveldb)
# * boltdb (uses etcd's fork of bolt - github.com/etcd-io/bbolt)
# - EXPERIMENTAL
# - may be faster is some use-cases (random reads - indexer)
# - use boltdb build tag (go build -tags boltdb)
# * rocksdb (uses github.com/tecbot/gorocksdb)
# - EXPERIMENTAL
# - requires gcc
# - use rocksdb build tag (go build -tags rocksdb)
# * badgerdb (uses github.com/dgraph-io/badger)
# - EXPERIMENTAL
# - use badgerdb build tag (go build -tags badgerdb)
db_backend = "goleveldb"
# Database directory
db_dir = "data"
# Output level for logging, including package level options
log_level = "info"
# Output format: 'plain' (colored text) or 'json'
log_format = "plain"
##### additional base config options #####
# Path to the JSON file containing the initial validator set and other meta data
genesis_file = "config/genesis.json"
# Path to the JSON file containing the private key to use as a validator in the consensus protocol
priv_validator_key_file = "config/priv_validator_key.json"
# Path to the JSON file containing the last sign state of a validator
priv_validator_state_file = "data/priv_validator_state.json"
# TCP or UNIX socket address for Tendermint to listen on for
# connections from an external PrivValidator process
priv_validator_laddr = ""
# Path to the JSON file containing the private key to use for node authentication in the p2p protocol
node_key_file = "config/node_key.json"
# Mechanism to connect to the ABCI application: socket | grpc
abci = "socket"
# If true, query the ABCI app on connecting to a new peer
# so the app can decide if we should keep the connection or not
filter_peers = false
#######################################################################
### Advanced Configuration Options ###
#######################################################################
#######################################################
### RPC Server Configuration Options ###
#######################################################
[rpc]
# TCP or UNIX socket address for the RPC server to listen on
laddr = "tcp://127.0.0.1:26657"
# A list of origins a cross-domain request can be executed from
# Default value '[]' disables cors support
# Use '["*"]' to allow any origin
cors_allowed_origins = []
# A list of methods the client is allowed to use with cross-domain requests
cors_allowed_methods = ["HEAD", "GET", "POST", ]
# A list of non simple headers the client is allowed to use with cross-domain requests
cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", ]
# TCP or UNIX socket address for the gRPC server to listen on //gRPC是google开发的高性能、通用的开源RPC框架,主要面向移动应用开发
# NOTE: This server only supports /broadcast_tx_commit
grpc_laddr = ""
# Maximum number of simultaneous connections.
# Does not include RPC (HTTP&WebSocket) connections. See max_open_connections
# If you want to accept a larger number than the default, make sure
# you increase your OS limits.
# 0 - unlimited.
# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
# 1024 - 40 - 10 - 50 = 924 = ~900
grpc_max_open_connections = 900//grpc最大连接数量
# Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
unsafe = false
# Maximum number of simultaneous connections (including WebSocket).
# Does not include gRPC connections. See grpc_max_open_connections
# If you want to accept a larger number than the default, make sure
# you increase your OS limits.
# 0 - unlimited.
# Should be < {ulimit -Sn} - {MaxNumInboundPeers} - {MaxNumOutboundPeers} - {N of wal, db and other open files}
# 1024 - 40 - 10 - 50 = 924 = ~900
max_open_connections = 900 //最大的同时连接数量
# Maximum number of unique clientIDs that can /subscribe
# If you're using /broadcast_tx_commit, set to the estimated maximum number
# of broadcast_tx_commit calls per block.
max_subscription_clients = 100
# Maximum number of unique queries a given client can /subscribe to
# If you're using GRPC (or Local RPC client) and /broadcast_tx_commit, set to
# the estimated # maximum number of broadcast_tx_commit calls per block.
max_subscriptions_per_client = 5
# Experimental parameter to specify the maximum number of events a node will
# buffer, per subscription, before returning an error and closing the
# subscription. Must be set to at least 100, but higher values will accommodate
# higher event throughput rates (and will use more memory).
experimental_subscription_buffer_size = 200
# Experimental parameter to specify the maximum number of RPC responses that
# can be buffered per WebSocket client. If clients cannot read from the
# WebSocket endpoint fast enough, they will be disconnected, so increasing this
# parameter may reduce the chances of them being disconnected (but will cause
# the node to use more memory).
#
# Must be at least the same as "experimental_subscription_buffer_size",
# otherwise connections could be dropped unnecessarily. This value should
# ideally be somewhat higher than "experimental_subscription_buffer_size" to
# accommodate non-subscription-related RPC responses.
experimental_websocket_write_buffer_size = 200
# If a WebSocket client cannot read fast enough, at present we may
# silently drop events instead of generating an error or disconnecting the
# client.
#
# Enabling this experimental parameter will cause the WebSocket connection to
# be closed instead if it cannot read fast enough, allowing for greater
# predictability in subscription behaviour.
experimental_close_on_slow_client = false
# How long to wait for a tx to be committed during /broadcast_tx_commit.
# WARNING: Using a value larger than 10s will result in increasing the
# global HTTP write timeout, which applies to all connections and endpoints.
# See https://github.com/tendermint/tendermint/issues/3435
timeout_broadcast_tx_commit = "10s"
# Maximum size of request body, in bytes
max_body_bytes = 1000000
# Maximum size of request header, in bytes
max_header_bytes = 1048576
# The path to a file containing certificate that is used to create the HTTPS server.
# Might be either absolute path or path related to Tendermint's config directory.
# If the certificate is signed by a certificate authority,
# the certFile should be the concatenation of the server's certificate, any intermediates,
# and the CA's certificate.
# NOTE: both tls_cert_file and tls_key_file must be present for Tendermint to create HTTPS server.
# Otherwise, HTTP server is run.
tls_cert_file = ""
# The path to a file containing matching private key that is used to create the HTTPS server.
# Might be either absolute path or path related to Tendermint's config directory.
# NOTE: both tls-cert-file and tls-key-file must be present for Tendermint to create HTTPS server.
# Otherwise, HTTP server is run.
tls_key_file = ""
# pprof listen address (https://golang.org/pkg/net/http/pprof)
pprof_laddr = ""
#######################################################
### P2P Configuration Options ###
#######################################################
[p2p]
# Address to listen for incoming connections
laddr = "tcp://0.0.0.0:26656"
# Address to advertise to peers for them to dial
# If empty, will use the same port as the laddr,
# and will introspect on the listener or use UPnP
# to figure out the address. ip and port are required
# example: 159.89.10.97:26656
external_address = ""
# Comma separated list of seed nodes to connect to
seeds = ""
# Comma separated list of nodes to keep persistent connections to
persistent_peers = ""
# UPNP port forwarding
upnp = false
# Path to address book
addr_book_file = "config/addrbook.json"
# Set true for strict address routability rules
# Set false for private or local networks
addr_book_strict = true//默认情况下,地址簿限制,检查该地址是否可路由
# Maximum number of inbound peers
max_num_inbound_peers = 40
# Maximum number of outbound peers to connect to, excluding persistent peers
max_num_outbound_peers = 10
# List of node IDs, to which a connection will be (re)established ignoring any existing limits
unconditional_peer_ids = ""
# Maximum pause when redialing a persistent peer (if zero, exponential backoff is used)
persistent_peers_max_dial_period = "0s"
# Time to wait before flushing messages out on the connection
flush_throttle_timeout = "100ms"
# Maximum size of a message packet payload, in bytes
max_packet_msg_payload_size = 1024
# Rate at which packets can be sent, in bytes/second
send_rate = 5120000
# Rate at which packets can be received, in bytes/second
recv_rate = 5120000
# Set true to enable the peer-exchange reactor
pex = true
# Seed mode, in which node constantly crawls the network and looks for
# peers. If another node asks it for addresses, it responds and disconnects.
#
# Does not work if the peer-exchange reactor is disabled.
seed_mode = false
# Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
private_peer_ids = ""
# Toggle to disable guard against peers connecting from the same ip.
allow_duplicate_ip = false
# Peer connection configuration.
handshake_timeout = "20s"
dial_timeout = "3s"
#######################################################
### Mempool Configuration Option ###
#######################################################
[mempool]
# Mempool version to use:
# 1) "v0" - (default) FIFO mempool.
# 2) "v1" - prioritized mempool.
version = "v0"
recheck = true//重新检查内存池中剩下的每个交易
broadcast = true//false时阻止内存池将交易转发给其他节点
wal_dir = ""//mempool中WAL日志的目录
# Maximum number of transactions in the mempool
size = 5000
# Limit the total size of all txs in the mempool.
# This only accounts for raw transactions (e.g. given 1MB transactions and
# max_txs_bytes=5MB, mempool will only accept 5 transactions).
max_txs_bytes = 1073741824
# Size of the cache (used to filter transactions we saw earlier) in transactions
cache_size = 10000
# Do not remove invalid transactions from the cache (default: false)
# Set to true if it's not possible for any invalid transaction to become valid
# again in the future.
keep-invalid-txs-in-cache = false
# Maximum size of a single transaction.
# NOTE: the max size of a tx transmitted over the network is {max_tx_bytes}.
max_tx_bytes = 1048576
# Maximum size of a batch of transactions to send to a peer
# Including space needed by encoding (one varint per transaction).
# XXX: Unused due to https://github.com/tendermint/tendermint/issues/5796
max_batch_bytes = 0
# ttl-duration, if non-zero, defines the maximum amount of time a transaction
# can exist for in the mempool.
#
# Note, if ttl-num-blocks is also defined, a transaction will be removed if it
# has existed in the mempool at least ttl-num-blocks number of blocks or if it's
# insertion time into the mempool is beyond ttl-duration.
ttl-duration = "0s"
# ttl-num-blocks, if non-zero, defines the maximum number of blocks a transaction
# can exist for in the mempool.
#
# Note, if ttl-duration is also defined, a transaction will be removed if it
# has existed in the mempool at least ttl-num-blocks number of blocks or if
# it's insertion time into the mempool is beyond ttl-duration.
ttl-num-blocks = 0
#######################################################
### State Sync Configuration Options ###
#######################################################
[statesync]
# State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine
# snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in
# the network to take and serve state machine snapshots. State sync is not attempted if the node
# has any local state (LastBlockHeight > 0). The node will have a truncated block history,
# starting from the height of the snapshot.
enable = false//启用状态同步
# RPC servers (comma-separated) for light client verification of the synced state machine and
# retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding
# header hash obtained from a trusted source, and a period during which validators can be trusted.
#
# For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2
# weeks) during which they can be financially punished (slashed) for misbehavior.
rpc_servers = ""//需要rpc servers用于轻节点验证
trust_height = 0//信任区块链的高度
trust_hash = ""//信任区块哈希
trust_period = "168h0m0s"
# Time to spend discovering snapshots before initiating a restore.
discovery_time = "15s"
# Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp).
# Will create a new, randomly named directory within, and remove it when done.
temp_dir = ""//状态同步数据临时存储目录
# The timeout duration before re-requesting a chunk, possibly from a different
# peer (default: 1 minute).
chunk_request_timeout = "10s"
# The number of concurrent chunk fetchers to run (default: 1).
chunk_fetchers = "4"
#######################################################
### Fast Sync Configuration Connections ###
#######################################################
[fastsync]
# Fast Sync version to use:
# 1) "v0" (default) - the legacy fast sync implementation
# 2) "v1" - refactor of v0 version for better testability
# 2) "v2" - complete redesign of v0, optimized for testability & readability
version = "v0"
#######################################################
### Consensus Configuration Options ###
#######################################################
[consensus]
wal_file = "data/cs.wal/wal"
# How long we wait for a proposal block before prevoting nil
timeout_propose = "3s"//等待多久提案被否决
# How much timeout_propose increases with each round
timeout_propose_delta = "500ms"//每轮增加的timeout_propose
# How long we wait after receiving +2/3 prevotes for “anything” (ie. not a single block or nil)
timeout_prevote = "1s"//预投票timeout
# How much the timeout_prevote increases with each round
timeout_prevote_delta = "500ms"//每轮增加的timeout_prevote
# How long we wait after receiving +2/3 precommits for “anything” (ie. not a single block or nil)
timeout_precommit = "1s"//在收到大于2/3的预提交要等多久
# How much the timeout_precommit increases with each round
timeout_precommit_delta = "500ms"//每轮增加的timeout_precommit
# How long we wait after committing a block, before starting on the new
# height (this gives us a chance to receive some more precommits, even
# though we already have +2/3).
timeout_commit = "1s"//create_empty_block=true时调节产生块之间的延迟,每隔多少秒产生一个块;false时提交一个块之后,在开始新的高度之前等待的时间
# How many blocks to look back to check existence of the node's consensus votes before joining consensus
# When non-zero, the node will panic upon restart
# if the same consensus key was used to sign {double_sign_check_height} last blocks.
# So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic.
double_sign_check_height = 0
# Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
skip_timeout_commit = false//跳过提交超时,默认为false
# EmptyBlocks mode and possible interval between empty blocks
create_empty_blocks = false//是否允许产生空块,false时在接收交易时创建块
create_empty_blocks_interval = "0s"//设置为默认值0以外的值,Tendermint 将创建空块,即使在每个 create_empty_blocks_interval 都没有交易的情况下也是如此。例如,使用 create_empty_blocks = false 和 create_empty_blocks_interval = "30s",Tendermint 只在有交易时创建块,或者在等待 30 秒后没有收到任何交易时创建块。
#共识超时解释
# Reactor sleep duration parameters
peer_gossip_sleep_duration = "100ms"//peer休眠时间
peer_query_maj23_sleep_duration = "2s"//
#######################################################
### Storage Configuration Options ###
#######################################################
[storage]
# Set to true to discard ABCI responses from the state store, which can save a
# considerable amount of disk space. Set to false to ensure ABCI responses are
# persisted. ABCI responses are required for /block_results RPC queries, and to
# reindex events in the command-line tool.
discard_abci_responses = false
#######################################################
### Transaction Indexer Configuration Options ###
#######################################################
[tx_index]
# What indexer to use for transactions
#
# The application will set which txs to index. In some cases a node operator will be able
# to decide which txs to index based on configuration set in the application.
#
# Options:
# 1) "null"
# 2) "kv" (default) - the simplest possible indexer, backed by key-value storage (defaults to levelDB; see DBBackend).
# - When "kv" is chosen "tx.height" and "tx.hash" will always be indexed.
# 3) "psql" - the indexer services backed by PostgreSQL.
# When "kv" or "psql" is chosen "tx.height" and "tx.hash" will always be indexed.
indexer = "kv"
# The PostgreSQL connection configuration, the connection format:
# postgresql://<user>:<password>@<host>:<port>/<db>?<opts>
psql-conn = ""
#######################################################
### Instrumentation Configuration Options ###
#######################################################
[instrumentation]
# When true, Prometheus metrics are served under /metrics on
# PrometheusListenAddr.
# Check out the documentation for the list of available metrics.
prometheus = true
# Address to listen for Prometheus collector(s) connections
prometheus_listen_addr = ":26660"
# Maximum number of simultaneous connections.
# If you want to accept a larger number than the default, make sure
# you increase your OS limits.
# 0 - unlimited.
max_open_connections = 3
# Instrumentation namespace
namespace = "tendermint"
4.Running in production
- 数据库
默认情况下goleveldb
高性能使用cleveldb
Tendermint 在 $TMROOT/data 中保存多个不同级别的 db 数据库:
blockstore.db: 保存整个区块链 - 存储块、块提交和块元数据,每个块按高度索引。用来同步新的节点。
evidence.db: 储存所有已证实的不当行为的证据。
state.db: 存储当前区块链状态(即高度、验证者、共识参数)。只有在共识参数或验证者发生更改时才会增长。也用于在块处理期间临时存储中间结果。
tx_index.db: 通过 tx 散列和 DeliverTx 结果标记索引交易(及其结果)。 - 日志记录
默认日志级别info,调整日志级别
tendermint --log_level
预写日志WAL:Tendermint 使用预写日志来达成共识 (cs.wal) 和内存池 (mempool.wal)。
共识WAL: 它将所有共识消息(超时、建议、块部分或投票)写到一个文件中,确保我们可以从共识状态机中的任何崩溃中恢复。
内存池WAL:在运行 CheckTx 之前记录所有传入的交易。mempool.wal 默认情况下是禁用的。若要启用,请设置 mempool.wal_dir 指向希望 WAL 位于的位置(例如 data/mempool.wal)
5.P2P
核心MConnection
6.RPC
见RPC文档
7.调试Tendermint
读取日志
8.快速同步
为了支持更快的同步,tendermint 提供了一种 fast-sync 模式,默认情况下是启用的,可以在 config.toml 中或者通过 --fast_sync=false 切换。
9.状态同步
持续同步节点最新状态
10.内存池
交易排序:目前,除了交易到达的顺序(通过 RPC 或来自其他节点)之外,没有其他交易的顺序。
11.Light Client
tendermint light
通过WebSocket订阅事件
wscat工具使用(类比于curl)
sudo npm install -g wscat
wscat ws://127.0.0.1:26657/websocket
3.Tendermint的ABCI:
Tendermint是一种基于共识算法的区块链协议,它的应用层接口被称为ABCI(Application Blockchain Interface)。ABCI提供了一个标准的接口,用于驱动共识引擎和应用程序之间的通信,允许在Tendermint上构建任何类型的去中心化应用程序。
ABCI的设计使得应用程序可以独立地开发和演化,而无需考虑共识引擎的实现。应用程序可以用任何编程语言编写,运行在任何操作系统上。同时,共识引擎可以独立于应用程序进行开发和升级,以确保性能和可靠性。
ABCI还提供了充分的安全性保证,因为它在共识引擎和应用程序之间提供了明确定义的隔离层。这确保了共识引擎无法访问应用程序的数据,而应用程序也无法影响共识引擎的决策。
总之,ABCI为Tendermint提供了一个灵活且安全的应用层接口,使得开发者可以更容易地构建出去中心化的应用程序。
如何使用:
1.编写自己的ABCI应用程序,使用Tendermint的ABCI规范进行交互。您可以使用任何编程语言编写自己的应用程序,只要能够遵循Tendermint ABCI规范。
2.将您的应用程序打包成可执行文件,并部署到您选择的服务器上。
3.在Tendermint节点初始化时,指定您的应用程序作为ABCI应用程序。您可以在Tendermint的配置文件中设置"abci": "[path-to-your-app]"的字段来指定您的应用程序路径。
4.运行Tendermint节点并启动您的应用程序。由于您的应用程序已经与Tendermint节点通过ABCI进行连接,您可以在您的应用程序中处理与Tendermint网络相关的交易和状态。
请注意,为了与Tendermint网络交互,您的应用程序必须能够处理Tendermint节点通过ABCI发送的请求和响应,包括交易、区块信息、验证等。阅读和使用Tendermint ABCI规范。
abci-cli
为了方便 ABCI 服务器和简单应用程序的测试和调试,构建了一个 CLI,即 abci-cli,用于从命令行发送 ABCI 消息