区块链中的节点

huangapple go评论110阅读模式
英文:

Nodes in blockchain

问题

  1. 我对区块链中的节点理解有些困惑。
    这是我的问题:
  2. 我不确定,但我听说节点是软件。那么,所有的链数据都存储在客户端吗?客户端可能无法存储那么多数据,或者我错了吗?
  3. 他们如何同步?如果一个节点在交易发生时离线会怎样?

我已经在Stackoverflow上搜索过类似的问题,但没有找到满意的答案。

谢谢!

英文:

I'm confused to understand nodes in blockchain.
Here are my questions:

  1. Not sure but I heard that a node is software. So, is all the chain data stored on the client side? The client might not be able to store so much data, or am I wrong?
  2. How do they synchronize? what if a node is offline when a transaction happens?

I already have searched Stackoverflow for similar questions but there weren't accepted good answers

Thanks!

答案1

得分: 1

在这个上下文中,节点是点对点(P2P)网络的成员。它们在层次上都是相等的 - 不像客户端-服务器模型,其中客户端只发起请求,服务器只回应请求。

例如,在以太坊中,连接到网络的所有计算机(节点)都能够:

  • 向其他节点广播交易
  • 验证来自其他节点的区块
  • 提议新的区块(根据以太坊网络的规则,例如需要抵押至少32 ETH)
  • 收发其他类型的消息。

关于“客户端”这个词,你可能听说过“节点客户端软件”。这可以是例如Go EthereumEthereumJS或其他软件,它可以将你的计算机(节点)连接到以太坊网络,监听传入消息(例如新区块),并广播消息(例如你希望包含在未来区块中的新交易)。

运行自己的节点并不容易。如果你计划开发一个利用区块链的简单应用程序,你可以只连接到第三方节点提供者(大多数提供有限的免费计划和不那么有限的付费计划),并通过RPC API或使用RPC包装库(如web3jsethers.js)与之通信。


> 不太确定,但我听说节点是软件。

节点是网络的成员,但你需要一种软件(节点客户端软件)才能与网络的其他成员进行通信。

> 那么,所有的链数据都存储在客户端吗?

每个节点都持有相同的数据。

更具体地说 - 所有节点都持有最新的状态(例如所有地址的当前余额),而一些节点还选择持有存档状态(例如在当前区块之前的所有区块的所有地址的余额)。

> 客户端可能无法存储这么多数据,对吗?

当前状态目前大约需要1.2 TB(图表)。存档状态目前大约为15 TB(图表)。在普通笔记本电脑上可能难以管理,但拥有足够大基础设施的企业仍然能够相对轻松地存储这么多数据。

话虽如此,目前还在研究和概念验证阶段的一些倡议,旨在将当前状态在多个节点之间进行分片(节点可以持有少于1.2 TB的完整数据,并在需要时向其他节点请求剩余数据)。

> 它们如何同步?

每个节点都有一个“引导节点”列表,最初连接到这些节点,然后请求它们的“邻居” - 这些引导节点知道的其他节点。然后它请求这些邻居的邻居列表,...直到达到已知邻居的限制数(可以在你的节点客户端软件中配置)。

一旦你的节点接收到一条消息(例如有新的区块),它应该将此消息传递给它的邻居。

这种通信标准称为DevP2P

> 如果一个节点在交易发生时处于离线状态会怎么样?

当节点重新在线时,它会向其邻居请求最新状态,并更新自己的数据库。

英文:

In this context, nodes are members of a peer-to-peer (P2P) network. All of them are hierarchically equal - unlike the client-server model for example, where the client only initiates requests and the server only responds to them.

For example with Ethereum, all computers (nodes) that are connected to the network are able to

  • broadcast transactions to other nodes
  • validate blocks incoming from other nodes
  • propose new blocks (in according with the rules of the Ethereum network, e.g. need to have staked at least 32 ETH)
  • and receive/send other types of messages.

What you possibly heard in connection with the word "client", is a "node client software". This is for example Go Ethereum or EthereumJS or other software that can connect your computer (node) to the Ethereum network, listen for incoming messages (e.g. new blocks), and broadcast messages (e.g. new transactions that you want to include in a future block).

Running your own node is not easy. If you're planning to develop a simple app that leverages blockchain, you can just connect to a 3rd party node provider (most of them have limited free plans, and less limited paid plans) and communicate with it over RPC API or using RPC wrapper libraries such as web3js and ethers.js.


> Not sure but I heard that a node is software.

Node is a member of a network, but you need a software (node client sw) in order to communicate with other members of the network.

> So, is all the chain data stored on the client side?

Each node holds the same data.

To be more specific - all nodes hold the latest state (e.g. current balance of all addresses), and some opt in to also hold the archival state (e.g. balances of all addresses at all blocks prior to the current one).

> The client might not be able to store so much data, or am I wrong?

The current state currently takes about 1.2 TB (chart). The archival state is currently about 15 TB (chart). It might not be manageable on a regular laptop, but businesses with large enough infrastructure are still able to store this amount of data fairly easily.

Having said that, there are some initiatives for sharding the current state between multiple nodes (the node could hold less than the full 1.2 TB and could ask others for the remaining data when needed), but they are still mostly in the research and proof-of-concept phase.

> How do they synchronize?

Each node has a list of "bootstrap nodes" where it initially connects to, and asks for "their neighbors" - other nodes that this bootstrap node knows of. Then it asks these neighbors for the list of their neighbors, ... until it reaches a limit number of known neighbors (configurable in your node client software).

Once your node receives a message (e.g. that there is a new block), it's supposed to rely this message to its neighbors.

This communication standard is called DevP2P.

> what if a node is offline when a transaction happens?

When the node comes back online, it asks its neighbors for the latest state, and updates its own database.

答案2

得分: 1

让我用简单的语言解释区块链中的节点:

什么是区块链中的节点?
区块链中的节点实际上是参与网络并通过验证和传播交易和区块来维护区块链完整性的软件。节点可以由个人、组织或公司运行,它们共同形成区块链的去中心化网络。

所有链上数据都存储在客户端吗?
是的,节点存储了整个区块链数据的副本。这就是使区块链去中心化和安全的原因。每个节点都有自己的本地区块链副本,包含了网络上发生的所有交易和区块。由于每个节点都有一份副本,所以不存在单点故障,并且数据分布在网络中。

存储方面的问题:
您说得对,对于一些客户端,特别是在存储容量有限的设备上运行的客户端来说,存储整个区块链可能会成为一个问题。这对于存储整个区块链的全节点更为重要。在某些区块链中,比如比特币,完整的区块链可能达到数百千兆字节的大小。为了解决这个问题,一些用户选择运行“轻量级”或“修剪”节点,只存储区块链数据的子集,依靠其他全节点在需要时提供缺失的信息。

节点如何同步?
当新的节点加入区块链网络时,它需要将其本地的区块链副本与网络中的其他节点同步。它通过连接到其他节点并交换区块和交易来完成这个过程。追赶区块链的当前状态的过程被称为“同步”或“初始区块下载”。

离线交易:
如果节点在交易发生时处于离线状态,它不会立即了解到该交易。但是,一旦节点重新上线并与网络同步,它将从其他节点那里接收到最新的区块和交易,并相应地更新其本地副本。交易被包含在区块中,当新的区块被挖掘或添加到区块链时,它包含了最近交易的列表。

简而言之,区块链网络中的节点是存储整个区块链数据副本并帮助维护网络完整性的软件。它们与其他节点同步以保持最新交易和区块。如果节点在交易期间离线,它将在重新联机后追赶网络。

英文:

Let me explain nodes in a blockchain in simple terms:

What is a Node in a Blockchain?
A node in a blockchain is indeed software that participates in the network and helps maintain the blockchain's integrity by validating and propagating transactions and blocks. Nodes can be run by individuals, organizations, or even companies, and they collectively form the decentralized network of the blockchain.

Is All the Chain Data Stored on the Client Side?
Yes, nodes store a copy of the entire blockchain data. This is what makes blockchains decentralized and secure. Each node has its own local copy of the blockchain, containing all the transactions and blocks that have ever occurred on the network. Since every node has a copy, there's no single point of failure, and the data is distributed across the network.

Storage Concerns:
You are correct that storing the entire blockchain can become a concern for some clients, especially if they are running on devices with limited storage capacity. This is more relevant for full nodes that store the entire blockchain. In some blockchains, like Bitcoin, the full blockchain can be several hundred gigabytes in size. To address this issue, some users choose to run "light" or "pruned" nodes that only store a subset of the blockchain data, relying on other full nodes to provide the missing information when needed.

How Do Nodes Synchronize?
When a new node joins the blockchain network, it needs to synchronize its local copy of the blockchain with the rest of the network. It does this by connecting to other nodes and exchanging blocks and transactions. The process of catching up with the blockchain's current state is known as "synchronization" or "initial block download."

Offline Transactions:
If a node is offline when a transaction happens, it won't immediately know about the transaction. However, once the node comes back online and synchronizes with the network, it will receive the latest blocks and transactions from other nodes and update its local copy accordingly. Transactions are included in blocks, and when a new block is mined or added to the blockchain, it contains a list of the most recent transactions.

In short, nodes in a blockchain network are software that stores a copy of the entire blockchain data and help maintain the network's integrity. They synchronize with other nodes to stay up-to-date with the latest transactions and blocks. If a node is offline during a transaction, it will catch up with the network when it comes back online.

huangapple
  • 本文由 发表于 2023年8月5日 05:46:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76839249.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定