所谓比特币交易,从广义上讲,就是某用户授权把自己地址里一定数量的比特币资产转移到另一个用户地址里,告诉全网并得到全网认可,交易就成功了。从狭义上讲,交易是将比特币资产从交易输入转移到交易输出,交易输入指明了这笔比特币资产的来源,通常是上一笔关联交易的输出,而交易输出则指明了这笔比特币资产的去向,这笔比特币资产新的有者可以通过另一笔授权将这次获得的比特币资产转移给其他人。随着不同用户授权,此比特币不断地从一个地址转移到另一个地址,这样形成的不仅是一条比特币交易链,也是一条价值所有权转移的链。
The so-called bitcoin transaction, in the broad sense, is that a user authorizes the transfer of a certain amount of bitcoin assets from its address to another user address, telling the whole network and being accepted by the whole network, the transaction succeeds. In the narrow sense, the transaction is the transfer of bitcoin assets from the transaction to the transaction output, which indicates the origin of the bitcoin assets, usually the export of the previous related transaction, while the transaction output indicates the destination of the bitcoin assets, which the new owner of the bitcoin assets can transfer to others through another authorization. With the authorization of different users, the bitcoin is constantly moving from one address to another, which is not only a Bitcoin transaction chain, but also a chain of transfer of value ownership.
比特币交易开始于交易的创建,在创建过程中需要付款方签名,用于对交易所花费的比特币资金进行授权,接着交易被发送到比特币网络上,其他节点对交易进行验证并继续传播,直到所有节点都收到该交易。验证过的交易被矿工节点打包到自己创建的一个区块中,等到包含该交易的区块被某个挖矿成功的矿工提议出来,经过全网验证以后,该区块被确认加入区块链,这样就实现了交易上链。最后,当足够多的区块在包含此区块的链上接龙,那么交易就成功地永久记录在区块链上,并被所有节点所接受。该交易中比特币资金新的所有者又可以使用这笔资金,开始新一轮的交易。比特币交易的完成需要整个比特币系统各个节点之间协同工作。比特币的交易流程大致过程按先后顺序依次为,交易创建交易全网广播交易收集、打包和挖矿全网验证区块全网同步实现交易写入共识区块链。这些流程都是为交易服务的,最终实现交易永久记入区块链。
The transaction of Bitcoin begins with the creation of the transaction, which requires the signature of the payer to authorize the bitcoin money spent on the exchange, and is then sent to the Bitcoin network, where other nodes verify the transaction and continue to disseminate it until it is received by all nodes. The proven transaction is permanently recorded on the node and accepted by all nodes until a block containing the transaction is proposed by a successful miner and, after full web validation, the block is confirmed to be part of the chain. Finally, when a sufficient number of blocks are connected to the chain containing the block, the transaction is successfully permanently recorded on the node and accepted by all nodes.
为了实现比特币交易,首先必须拥有比特币资产。目前比特币的自然供应是由矿工挖矿实现的,对于成功挖矿的节点,比特币系统会奖励给他比特币,这笔特殊交易作为被包含在区块里。币基交易是每个新区块产生的第一笔交易,交易输入中没有上一笔关联交易的信息,因为交易中的比特币来源于系统发放的区块奖励和同一区块内其它交易的交易费用,交易输出指定了矿工接受比特币的地址。比特币系统中除了币基交易以外,其他的交易都可以称为普通交易。
In order to achieve a bitcoin transaction, first of all, there must be a bitcoin asset. The natural supply of bitcoin is currently made by miners who dig mines. For the nodes of successful mining, the bitcoin system rewards the bitcoin, a special transaction that is included as a block. The currency transaction is the first transaction generated by each new block, and there is no information about the last associated transaction in the transaction input, because the bitcoin in the transaction is derived from a block incentive issued by the system and from transaction costs for other transactions within the same block, and the transaction is exported to the miners to receive the bitcoin address.
比特币的交易可以由任何人通过比特币客户端在线或离线生成,特别是在构建和授权交易时,可以不接入比特币网络。只有在执行交易时,因为要将交易广播到比特币网络,所以需要将比特币客户端接人比特币网络。在创建交易这一步中最重要的就是确认是否有足够的比特币资金支付给对方,以便构建交易。
Bitcoin transactions can be generated by anyone online or offline via the Bitcoin client, especially when building and authorizing transactions, without access to the Bitcoin network. Only when a transaction is carried out, because it is broadcast to the Bitcoin network, the Bitcoin client needs to be connected to the Bitcoin network.
此外,创建交易的人并不一定就是最终给交易签名的人。比如,公司财务对公转账,创建好交易后再找总经理签名授权。小明买奶茶的例子中,小明只需要在手机钱包软件中确认接收人的比特币地址和交易金额,其他交易细节都不需要关心。但对于想深入学习比特币交易的人来说,我们需要详细地了解其背后的实现原理。下面来看看比特币系统中每笔交易所隐含的技术细节。
Moreover, the person who created the transaction is not necessarily the person who ultimately signed the transaction. For example, the company’s financial transactions are public transfers, and the transaction is created before the general manager is authorized to sign the transaction. In the case of Siu Ming’s milk tea, only the recipient’s Bitcoin address and transaction amount are to be identified in the mobile wallet software, and no other transaction details are to be taken into account.
通常我们在支付之前需要确认钱包或卡里有没有足够的钱,比特币交易也是一样。首先小明的手机钱包软件必须确认有足够支付给奶茶店的比特币资金作为交易输入。比特币没有账户或余额的概念,用户的比特币资金以未花费的交易输出UTXO的形式分散存储在区块链的若干区块里,可以理解为每次花费的是交易中指定的“上一笔关联交易输出UTXO”。完全节点在本地维护全网当前的UTXO列表,以此来统计全网当前未花费的交易输出。大多数钱包软件保存有用户自己的UTXO列表,用于跟踪用户未花费的比特币资产,这些资产由钱包所有者的私钥管理。钱包软件构建交易前,查询小明所拥有的UTXO是否满足此次交易输出,如果钱包软件没有维护UTXO列表,查不到小明的比特币资产,那么它会向比特币网络询问这些信息,主要是向那些保存完整区块链副本的完全节点询问,完全节点查询本地UTXO列表,若找到小明的比特币地址下有未花费的资产,则将此信息告诉钱包软件,这样钱包软件就依据节点的应答信息构建交易,从而向支付地址发送比特币。
First, smart mobile wallet software must confirm that there is a sufficient amount of bitcoin money to be paid to the tea shop as a transaction input. Bitcoin does not have the concept of an account or balance, and the user’s bitcoin money is stored in several blocks of the block chain in the form of undisbursed transaction output of UTXO, which can be understood as having been spent each time on the transaction’s “up-to-date transaction output UTXO” specified in the transaction. If the wallet software does not maintain the current UTXO list on the whole network locally, so as to account for the unaffordable transaction output on the whole network. Most wallet software maintains its own UTXO list, which is used to track the user’s unused UTXO asset, which is managed by the wallet owner’s private key.
在我们日常的现金交易中,付款方从钱包里拿出现金,如果金额刚好满足,就直接给对方完成交易;如果只有大额钞票,那么支付给对方后需要对方找零;如果没有大额钞票,只能把零散的小额钞票凑足给对方,如果不是正好凑齐对方需要的金额,也会需要对方找零。比特币的交易形式实质上也由上述几种类型组成。当然,还存在多人共同支付,以及支付给多人的情况。现在回到我们的例子,钱包软件发现小明控制的比特币地址xiaoming123456里有一笔未花费的比特币资金20BTC,于是进入下一步:构建交易并签名。
In our day-to-day cash transactions, the payer takes cash out of the wallet and, if the amount is right, makes the transaction directly to the other party; if there is only a large amount of money, then the payment to the other party will be for zero; if there is no large amount of money, only small pieces of money will be collected to the other party, and if not for the amount needed by the other, the other party will be for zero. Bitcoin transactions are essentially composed of the above-mentioned types. Of course, there are multiple co-payments, as well as multiple payments. Now, going back to our example, the wallet software finds that Min controlled Bitco’s address xiaoming 123456 with an unspentable bitcoated bitcoin 20 BTC, the next step: to build the transaction and sign.
钱包软件搜索到小明的比特币资金20BTC,足够支付奶茶费用0.5BTC的同时,还需要找零,于是构建一笔交易。该交易包含了用以证明小明拥有资金所有权的信息和资金接收者的信息。该交易的输出包含两个部分,一部分用于支付奶茶费用,另一部分用于找零.假设奶茶店的比特币地址为:drink123456,支付给奶茶店0.5BTC,找零19.49BTC,交易费0.01BTC。本次交易使用了上一笔关联交易的输出,即小明从比特币交易所购买比特币的交易输出,作为这次交易的输入。上一笔交易的输出地址是小明的公钥哈希地址,要动用这笔资金作为交易的输入,只能由该公钥对应的私钥进行签名,除了这个地址所有人小明以外,其他人是没有该私钥的,所以通过签名证明了小明对这笔资金的所有权。如果其他人用别的私钥进行签名,当这个伪签名的交易被发送到网络上,接收交易的节点经过验证发现不是用上一笔交易输出地址对应的公钥所对应的私钥来签名的,从而丢弃该交易,因此这笔伪签名的交易不会被记入区块链。
The wallet-based software search for Bitcoin 20BTC, which is sufficient to cover 0.5 BTC for milk tea, also needs to find zero. The transaction contains information to prove the ownership of the money and information on the recipient of the money. The transaction consists of two parts, one to cover the cost of milk tea, and the other part to find zero. Assuming that the price of the milk shop is only signed by the private key to the key to the key, except for the owner of the address, which is 019.49 BTC. The other person does not have the private key, thereby proving his ownership of the money by signing it.
每一笔独立的交易都包括交易输入和交易输出,此外还有该笔交易的哈希值,它在区块构建梅克尔树中起到重要作用,同时也可以根据交易哈希值跟踪关联交易和比特币资产流向。
Each stand-alone transaction includes the entry and export of the transaction, in addition to the Hashi value of the transaction, which plays an important role in building the Merkel tree in blocks and can also track associated transactions and the movement of Bitcoin assets according to the Hashi value of the transaction.
钱包软件创建交易后,需要将交易发送到比特币网络中。前面我们提到过,构建交易可以离线实现,但广播交易必须在线。钱包软件并不关心交易是怎样在比特币网络中广播的,因为比特币网络是一个点对点网络,网络中的节点只要接收到新的有效交易,都会转发给相邻的节点,就像扩散的波一样,在极短的时间内,交易就会到达比特币网络中的大多数节点。节点在继续转发交易之前,独立验证交易,确保交易的有效性,主要是检查这笔交易输入的资金来源,即验证上一个交易的输出的确未被花费过,从而防止双重支付;另外,节点还验证签名是否正确。如果验证结果都通过,表示交易有效,节点就会把这笔交易继续转发给与其相邻的其他节点;如果交易异常则直接丢弃,这样可以确保异常交易无法在比特币网络中继续传播。奶茶店的比特币客户端也会在短短几秒内收到这笔交易,并迅速识别出这是一笔支付给自己的交易,因为交易包含有奶茶店的比特币地址。
When a transaction is created, wallet software needs to send the transaction to the Bitcoin network. As we mentioned earlier, building transactions can be offline, but broadcasting transactions must be online. Wallet software does not care how the transaction is broadcast in the Bitcoin network, because the Bitcoin network is a point-to-point network, where nodes are transmitted to adjacent nodes as long as new valid transactions are received. If the validation results are valid, nodes continue to transmit the transaction to other nodes with them in a very short period of time. If the transaction is discarded directly, then the transaction can be verified independently to ensure that the transaction is effective, primarily by checking that the source of the transaction is not spent, thus preventing double payment.
矿工节点收到交易后,除了验证交易的有效性,还要将有效的交易加入自身维护的交易池。真实世界里,不同的交易会源源不断地从用户钱包或其他应用中产生,并流入比特币网络,矿工节点从交易池中按照特定的优先级选择若干交易,并打包成一个临时区块,然后通过控矿来竞争区块记账权。在上述例子中,小明的交易被比特币网络中的节点验证通过,并放入交易池。因为交易中包含有足够的交易费,所以矿工节点都愿意优先处理小明的交易,即把小明的交易放入临时区块中。假设小明的交易被放进矿工节点A的临时区块中,在小明将交易提交给比特币网络以后经历了大约10分钟,矿工节点A挖矿成功,获得记账权。
In the real world, different trading streams are generated from user wallets or other applications and flow into the Bitcoin network, where miners select a number of transactions according to specific priority levels and wrap them into a temporary block, then compete for block rights by controlling the mine. In the above example, Min’s transactions were validated by the Bitcoin network and placed in the trading pool. Because the transaction contains sufficient transaction costs, the Miners’ node is willing to give priority to petty transactions, i.e. to put Min’s transactions in temporary blocks.
矿工节点A把包含小明这笔支付给奶茶店交易的区块进行全网广播,其他节点会立即对这个区块进行验证。除了验证区块头部哈希值是否符合工作量证明要求外,还要验证这个区块包含的每笔交易的有效性,包括是否双重支付,签名是否正确等。只有验证通过,节点才会采纳这个区块,并将它挂接到自己存储的区块链的顶端,被命名为N号区块,N是该区块在区块链中的高度。
In addition to verifying whether the head of the block meets the workload certification requirements, the validity of each transaction included in the block, including whether it is double-paying and whether the signature is correct, etc. The block will only be adopted if it is certified and attached to the top of the chain of its own stored block, known as block N, which is the height of the block in the chain.
如果包含小明交易的N号区块是当前共识区块链的最顶端,那么小明的交易并不能完全确认是安全的,因为有可能存在双重支付的问题,按照惯例,小明的交易经过6个区块的确认就能认定该区块是永久挂链的,N号区块是第一次确认,只有等到N十1、N十2、N十3、N十4以及N十5号区块被确认记入区块链,小明的交易才被认定为安全的、不可改变的有效交易。因为在比特币的挖矿机制下,中本聪已经通过数学建模证明,要在已经得到6个区块的确认后制造分叉并赶上原链条的概率是非常非常小的,基本不可能发生。基于包含小明交易的N号区块之后的每一个区块记入区块链,都是对小明交易的确认,确认的区块越多,那么小明的交易的可信度就越高。经过这一步,小明的交易最终成为比特币区块链账本中不可篡改的一部分了。
If block N, which contains small deals, is the top end of the current consensual block chain, the transaction cannot be fully recognized as safe, because there may be problems of double payment, as it is customary for the transaction to be identified as permanently connected by six blocks, and block N for the first time, only when each block of block N XI, N XII, N XIII, N XIV and N XV is identified as a secure, non-changeable and effective transaction. Because, under the Bitcoin mining mechanism, Bint has already been certified by mathematical modelling, the probability of creating a split after six blocks have been confirmed and catching up with the original chain is very small and virtually impossible.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论