比特币最成熟的二层解决方案:闪电网络的一些技术点

币圈资讯 阅读:38 2024-04-22 09:13:49 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

作者:胡飞瞳

闪电网络是比特币最成熟的二层解决方案,其理论探索和工程构建已经有接近10年的时间,虽然仍然存在不少弱点,但相对于其他比特币创新的二层解决方案而言,闪电网络不仅及in是最完善和最成熟,可能也会是其他二层解决方案的一个基础。本文就闪电网络的技术进行一个简单介绍,希望起到一点科普的作用。

引言

在当前比特币生态突然繁荣、各种创新和项目如雨后春笋般涌现的时候,来谈闪电网络似乎有些过时。但如果仔细分析比特币生态的各种创新,你也不得不承认,闪电网络在设计上和工程实践上都最为完善。闪电网络概念从2015年提出,2016年初白皮书完善并发布,2018年闪电网络诞生落地,并实现你1个BTC的链下转移支付,到2023年底闪电网络节点达到14000个以上,容量达到5000BTC左右。 

针对比特币的低TPS,超长确认时间,以及网络拥堵等问题,闪电网络希望能够通过链下交易,并借助比特币自身网路的安全性来解决这三大问题,也就是要实现:

  1. 交易的即时性;

  2. 高吞吐量的交易;

  3. 降低交易费用

当然,对于当前比特币Layer 2 的一些其他方案,还希望解决一个比特币网络的另一个重要问题 - 图灵完备合约。这本身对于区块链技术而言不是一个大问题,因为这已经是成熟的技术,关键在于如何做到去中心化地比特币资产转移和确认,并且借助比特币网络的安全性。从这个方面来讲,还没有一个能够替代闪电网络(状态通道)的完善方案。

闪电网络的一些技术要点

闪电网络通过在比特币区块链之上创建一个支付通道网络来实现前文所述的三大目标。它主要包含以下一些技术要点: 

  1. 支付通道(Payment Channels):支付通道是闪电网络的核心概念。它允许两个用户在不必每次都在比特币主链上发起交易的情况下进行多次交易。用户首先在比特币区块链上创建一个多签名钱包,这个钱包需要两个用户的私钥来进行资金转移。然后,他们将一定数量的比特币存入这个钱包,这个存款交易在区块链上进行确认。 

  2. 链下交易(Off-Chain Transactions):一旦支付通道开启,双方可以在不与主链交互的情况下进行无限次数的链下交易。这些交易是通过签署新的交易来更新通道内资金的分配。这些交易记录代表了在关闭通道时应该如何分配资金,但在通道开放期间,这些交易不会被广播到比特币网络。 

  3. 通道关闭(Channel Closing):当任一方想要取回在通道中的资金时,他们可以关闭支付通道。这通过在比特币区块链上广播最终状态的交易来实现。一旦交易被确认,通道中的资金将根据最后一次链下交易的状态被分配给两方。 

  4.  路由和多跳支付(Routing and Multi-hop Payments):用户可以通过网络中其他用户的支付通道发送支付,即使他们没有直接的支付通道连接。这是通过路由支付通过一个或多个中间节点来实现的。每个中间节点收取微小的费用作为提供流动性的补偿。 

  5. Hash Time-Locked Contracts (HTLCs,哈希时间锁):为了安全地进行多跳支付,闪电网络使用了HTLCs。这允许创建条件支付,只有在接收方提供支付预像(一个由发送方生成的随机数的哈希值)的证明时支付才能完成。这保证了沿途的每个节点只有在确保自己能收到支付的情况下才会转发支付。 

  6. 网络容量和流动性:虽然闪电网络可以大大降低交易费用并提高速度,但它的性能也取决于网络的容量和流动性。每个通道的资金容量限制了可以通过该通道发送的最大支付量。此外,资金必须在网络中正确分布,以便支付可以找到有效的路径。 

  7. 安全和隐私:闪电网络提高了隐私,因为不需要将所有交易记录在公共区块链上。然而,它也带来了新的安全考虑,例如需要用户定期在线以响应潜在的欺诈尝试。

闪电网络支付的基本过程

支付通道是闪电网络中最关键的组成部分,允许两个参与者在不必每次都广播到比特币主链的情况下进行多次交易。双方通过闪电网络进行多次交易的过程可以分为三步:1)开启支付通道;2)多次链下交易;3)关闭通道。以下是从技术角度对支付通道及相关概念的详细解释:

支付通道的建立基于多签钱包,这是一个需要多个私钥签名才能进行交易的特殊类型钱包。在闪电网络中,通常是两个参与方各持有一个私钥,共同控制这个钱包。多签钱包确保没有一方可以单独移动资金,只有当双方同意时才能进行交易。

开启支付通道:

资金存入:参与者共同创建一个多签钱包,并从各自的常规钱包向这个多签钱包发送比特币。这个交易在比特币主链上广播并确认,表明他们共同对这些资金有控制权。

交易记录:双方各自保留一份交易记录,记录当前的资金分配。这个交易不会广播到比特币网络,只在双方之间共享。

链下交易:

Author Hu Feitong's lightning network is the most mature two-tier solution of Bitcoin, and its theoretical exploration and engineering construction have been nearly years. Although there are still many weaknesses, compared with other innovative two-tier solutions of Bitcoin, lightning network is not only the most perfect and mature, but also the foundation of other two-tier solutions. This paper gives a brief introduction to the technology of lightning network, hoping to play a role in popular science. It seems a little outdated to talk about lightning network when new projects are springing up like mushrooms after rain, but if you carefully analyze all kinds of innovations in bitcoin ecology, you have to admit that lightning network is the most perfect in design and engineering practice. The concept of lightning network has been perfected since the white paper was put forward at the beginning of 2000, and the lightning network was born and landed in 2000, and your offline transfer payment was realized. By the end of the year, the capacity of lightning network nodes reached more than 10, and the low and long confirmation time for bitcoin and network congestion were achieved. The problem lightning network hopes to solve these three problems through offline transactions and the security of Bitcoin's own network, that is, to realize the immediacy of transactions and reduce transaction costs. Of course, for some other current bitcoin schemes, it also hopes to solve another important problem of a bitcoin network, Turing complete contract, which is not a big problem for blockchain technology itself, because it is a mature technical key, which is how to decentralize Bitcoin. Asset transfer and confirmation, and with the help of the security of bitcoin network, there is not a perfect scheme that can replace the status channel of lightning network in this respect. Some technical points of lightning network realize the above three goals by creating a payment channel network on the bitcoin blockchain. It mainly includes the following technical points: payment channel is the core concept of lightning network, which allows two users to initiate exchanges on the bitcoin main chain every time. When it is easy to make multiple transactions, users first create a multi-signature wallet on the bitcoin blockchain. This wallet needs two users' private keys to transfer funds, and then they deposit a certain amount of bitcoin into this wallet. This deposit transaction is confirmed on the blockchain. Once the payment channel is opened, both parties can make unlimited offline transactions without interacting with the main chain. These transactions are to update the distribution of funds in the channel by signing new transactions. Easy-to-record represents how to allocate funds when the channel is closed, but these transactions will not be broadcast to the bitcoin network during the channel opening. When any party wants to get back the funds in the channel, they can close the payment channel. This is achieved by broadcasting the final state of the transaction on the bitcoin blockchain. Once the transaction is confirmed, the funds in the channel will be distributed to both parties according to the state of the last offline transaction, and users can make multi-hop payments through the branches of other users in the network. Payment channels send payment even if they don't have direct payment channel connection, which is realized by routing payment through one or more intermediate nodes. Each intermediate node charges a small fee as compensation for providing liquidity. In order to make multi-hop payment safely, the lightning network uses this to allow the creation of conditional payment, which can only be completed when the receiver provides proof that the payment preview is a hash value of a random number generated by the sender, which ensures that each node along the way is only. The capacity and liquidity of the payment network will be forwarded only when you are sure that you can receive the payment. Although the lightning network can greatly reduce the transaction cost and improve the speed, its performance also depends on the capacity and liquidity of the network. The capital capacity of each channel limits the maximum payment that can be sent through this channel. In addition, the funds must be correctly distributed in the network so that the payment can find an effective path. Security and privacy are improved by the lightning network because there is no need to record all transactions in public areas. On the block chain, however, it also brings new security considerations, such as the need for users to be online regularly to respond to potential fraud attempts. The payment channel is the most critical part of the lightning network, allowing two participants to make multiple transactions without broadcasting to the bitcoin main chain every time. The process of multiple transactions between the two parties through the lightning network can be divided into three steps: opening the payment channel and closing the offline transaction for multiple times. The following is a technical view of the payment channel and related. Detailed explanation of the concept The establishment of payment channel is based on multi-signature wallet, which is a special type of wallet that needs multiple private keys to make transactions. In lightning network, usually, two participants each hold a private key to jointly control this wallet. Multi-signature wallet ensures that no one can move funds alone, and only when both parties agree can transactions be made. Open the payment channel and deposit the funds into the participants to jointly create a multi-signature wallet and send bitcoin to this multi-signature wallet from their respective conventional wallets. A transaction is broadcast on the bitcoin main chain and confirmed to show that they jointly have control over these funds. Both parties keep a transaction record to record the current allocation of funds. This transaction will not be broadcast to the bitcoin network, but only the offline transactions are shared between the two parties. 比特币今日价格行情网_okx交易所app_永续合约_比特币怎么买卖交易_虚拟币交易所平台

一旦通道建立,参与者可以进行无限次数的链下交易。

交易更新:每进行一次链下交易,双方就更新他们各自保存的最新交易记录,这个记录代表了在关闭通道时资金的最终分配方式。

私密性和速度:这些交易仅在双方之间进行,不需要比特币网络的确认,所以几乎是即时的,并且保持私密。

关闭通道:

广播最终状态:当任一方想要退出通道时,他们可以广播他们同意的最后一笔交易到比特币网络。

结算资金:这个交易一旦被网络确认,多签钱包中的资金将根据最后的交易记录被分配给两方。

支付通道和链下交易是闪电网络提高比特币交易速度和扩展性的关键技术。通过这种方式,只有在通道的建立和关闭时,交易才需要在比特币主链上进行确认,而通道一旦开启,参与者就可以进行无限次数的快速、低成本交易。

那么大家很自然地可以想到,资金的安全如何保证?因为资金只会在关闭通道的时候才回到各自的钱包,那么如果一方提前关闭通道,或者某方不愿意关闭通道,就不能实现一个期望的结算过程。

闪电网络的用户资金安全主要由如下两个机制来保障:

  • 时间锁:为了防止欺诈(例如,一方尝试广播一个过时的交易以获取更多资金),支付通道通常包含时间锁定机制。如果一方尝试广播旧的交易,另一方有时间来反应并广播最新的状态。

  • 监控:参与者需要定期监控网络,以确保对方没有尝试广播旧的交易。

基本过程例子 和 结算安全

我们以一个例子来看说明这个基本过程,在这个例子中,用户A和B希望通过闪电网络来进行多次交易。

第一步 - 建立支付通道:交易双方(例如,Alice和Bob)共同创建一个多签名(multisig)地址,并向该地址存入初始资金(比如,Alice存入5BTC,Bob存入3BTC)。这一初始交易在比特币主链上确认,标志着支付通道的建立。 

第二步 - 双方进行链下交易:一旦支付通道建立,双方可以开始进行无限次数的链下交易,无需每次都在比特币主链上记录。对于每次链下交易,双方更新一个共同维护的平衡表,来反映当前的资金分配。例如,发生了三次交易:1)A转给B 1.0BTC;2)B转给A 0.5BTC;3)A再次转给B 0.2BTC。

在这些交易之后,根据平衡表,A总共转给B 0.7BTC,即 A:4.3BTC, B:3.7BTC

第三步:A 或 B 都可以发送这最后一个结果,A 转 B 0.7 BTC给多钱地址来关闭通道; 

第四步:等待时间锁结束;在时间锁结束前,A 或 B 都可以发送更晚的双方签名的交易结果来防止任何一方不是发送的最终的交易结果来获利; 

第五步:时间锁结束,关闭通道。多签地址处理最后的交易,并返回资金给 A 和 B;在这个例子中,A 将获得4.3BTC,B 将获得3.7BTC 。

为了防止不诚实方提交旧的状态,闪电网络鼓励用户保持在线或委托第三方监控服务(如“监控塔”)来监视网络中的不诚实行为。如果B发现A试图提交一个旧的状态,B可以使用他持有的包含A签名的最新状态作为证据,提交给网络以纠正并惩罚A的不诚实行为。

如果A提交了非最新状态,而B能够证明存在一个更新的状态,那么闪电网络协议允许B不仅收回自己的资金,还可能获得A的部分或全部资金作为惩罚。这种机制极大地增加了尝试欺诈的成本,从而保护了网络的诚实行为。

路由和多跳支付

前面讨论了两方通过支付通道(状态通道)来通过链下支付提高效率和吞吐量,建立交易费的过程。我们知道,不可能让有交易的用户都去建立支付通道,闪电网络可以通过路由和多跳支付来解决这个问题。这类似我们当前的网络系统,每个最终用户只需要数个自己认可的服务商(相当于网关)来建立状态通道,而这些服务商之间再建立起状态通道,这样形成一个网络,从而通过多跳支付来实现整个闪电网络中用户之间的任意交互和转账。

让我们通过一个简单的例子来说明闪电网络中的路由和多跳支付是如何工作的:假设有四个用户在闪电网络上:Alice(A)、Bob(B)、Carol(C)和Dave(D)。Alice有一个支付通道直接连接到Bob,Bob有一个通道连接到Carol,Carol又有一个通道连接到Dave。现在,Alice想要发送一笔支付给Dave,但她和Dave之间没有直接的支付通道。

步骤 1: 寻找路由

Alice的客户端使用闪电网络的路由算法来找到一条到达Dave的路径。在这个例子中,最简单的路径是 Alice -> Bob -> Carol -> Dave。

步骤 2: 创建支付

Alice决定发送0.01 BTC给Dave。她的客户端创建一个支付请求,这个请求包含了支付的细节和一个特殊的数字——支付预像(Dave创建的随机数)的哈希值。

步骤 3: 使用HTLCs

为了安全地进行多跳支付,每个中间节点(Bob和Carol)都会创建一个HTLC。HTLC允许中间节点转发支付,但只有在他们知道支付预像的情况下才能最终获得资金。这确保了支付只有在完全到达Dave时才能被最终解锁。

步骤 4: 转发支付

  • Alice首先将支付发送给Bob,锁定在一个HTLC中。

  • Bob看到这个支付要被转发给Carol,所以他创建一个新的HTLC并发送给Carol。

  • Carol做同样的事情,创建一个HTLC并发送给Dave。

在每一步,支付都被锁在一个新的HTLC中,每个节点都只有在知道支付预像时才能解锁这些资金。

步骤 5: 解锁支付

  • 一旦Dave收到了支付,他会提供支付预像给Carol,解锁他那里的HTLC并获得资金。

  • Carol使用这个支付预像解锁Bob发给她的HTLC,并将支付预像发送给Bob来解锁她应得的资金。

  • Bob最后用支付预像解锁Alice给他的HTLC,完成整个支付过程。

步骤 6: 确认和关闭

一旦整个支付链完成,所有中间HTLCs都被解锁,每个人都收到了他们应得的资金。支付被确认,所有参与节点更新了他们的支付通道状态。

闪电网络的优劣势及发展前景分析

根据前面的介绍,我们可以说,闪电网络从技术上解决了比特币网络的一些问题,并具有一下优势:即时交易,低交易费用,高可扩展性和高交易频率,更好的隐私保护以及对微支付的支持。正因为如此,通过闪电网络等技术创新,比特币才有可能成为真正的电子现金,而不是仅仅作为储值货币。

但同时,我们也看到闪电网络的技术复杂性。同时一个网络的构建不仅仅是技术因素,用户的认可度和采用率也非常关键。尽管比特币得到更广泛的价值认可,但是,闪电网络总体容量还不高,在其发展过程中,下面一些弱点会是阻碍因素:

  • 在线要求:为了接收支付,用户的设备需要保持在线,以便实时响应可能的支付请求或欺诈尝试。

  • 资金锁定:在支付通道中的资金在通道关闭之前会被锁定,这意味着资金在一定时间内无法自由使用。

  • 复杂性和用户体验:设置和管理支付通道可能对普通用户来说比较复杂,尤其是涉及到通道的资金管理和路由选择等问题。

  • 网络流动性和路由挑战:虽然理论上闪电网络可以处理大量的交易,但实际上其效率高度依赖于网络中支付通道的分布和资金流动性。找到有效的支付路径有时可能是挑战。

  • 中央化风险:虽然闪电网络旨在是去中心化的,但存在大节点或中心化服务提供者可能控制较大流量的风险,这可能导致网络的某种程度中央化。

随着比特币生态的发展,尽管有各种 BTC Layer2 的方案出台,但同时,总体的发展也给闪电网络带来前所未有的机遇。如果闪电网络的布局者在用户体验、网络规模以及与其他技术相结合的方面有较大的突破的话,相信闪电网络会迎来一个春天。

    文字格式和图片示例

    注册有任何问题请添加 微信:MVIP619 拉你进入群

    弹窗与图片大小一致 文章转载注明 网址:https://netpsp.com/?id=60285

    美化布局示例

    欧易(OKX)最新版本

    【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

    APP下载   全球官网 大陆官网

    币安(Binance)最新版本

    币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

    APP下载   官网地址

    火币HTX最新版本

    火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

    APP下载   官网地址
    可以去百度分享获取分享代码输入这里。
    声明

    1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    发表评论
    平台列表
    美化布局示例

    欧易(OKX)

      全球官网 大陆官网

    币安(Binance)

      官网

    火币(HTX)

      官网

    Gate.io

      官网

    Bitget

      官网

    deepcoin

      官网
    关注我们

    若遇到问题,加微信客服---清歌

    搜索
    排行榜
    扫一扫,加我为微信好友加我为微信好友