CN114816509A - Blockchain version compatibility verification method and device, electronic device - Google Patents
Blockchain version compatibility verification method and device, electronic device Download PDFInfo
- Publication number
- CN114816509A CN114816509A CN202210473975.0A CN202210473975A CN114816509A CN 114816509 A CN114816509 A CN 114816509A CN 202210473975 A CN202210473975 A CN 202210473975A CN 114816509 A CN114816509 A CN 114816509A
- Authority
- CN
- China
- Prior art keywords
- transaction
- software version
- blockchain
- block
- historical
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/65—Updates
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Business, Economics & Management (AREA)
- Accounting & Taxation (AREA)
- Databases & Information Systems (AREA)
- Finance (AREA)
- Computer Security & Cryptography (AREA)
- Development Economics (AREA)
- Data Mining & Analysis (AREA)
- Computing Systems (AREA)
- Economics (AREA)
- Marketing (AREA)
- Strategic Management (AREA)
- Technology Law (AREA)
- General Business, Economics & Management (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本说明书实施例提供一种区块链版本兼容性验证方法及装置、电子设备。所述方法应用于所述区块链中的目标节点设备;其中,所述区块链支持进行软件版本升级;所述方法包括:获取待验证的历史区块,并从所述历史区块中读取待验证的交易;基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;以及,基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果;将所述第一交易执行结果与所述第二交易执行结果进行匹配,并基于所述匹配的结果以确定所述第一软件版本与所述第二软件版本是否兼容。
The embodiments of this specification provide a blockchain version compatibility verification method and device, and an electronic device. The method is applied to the target node device in the blockchain; wherein, the blockchain supports software version upgrade; the method includes: acquiring a historical block to be verified, and extracting the historical block from the historical block reading the transaction to be verified; executing the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result; and executing the transaction based on the second software version supported by the blockchain, Obtain a second transaction execution result; match the first transaction execution result with the second transaction execution result, and determine whether the first software version and the second software version are compatible based on the matching result .
Description
技术领域technical field
本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种区块链版本兼容性验证方法及装置、电子设备。One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a method and apparatus for verifying version compatibility of a blockchain, and an electronic device.
背景技术Background technique
区块链技术,也被称之为分布式账本技术,是一种由若干台计算设备共同参与“记账”,共同维护一份完整的分布式数据库的新兴技术。由于区块链技术具有去中心化、公开透明、每台计算设备可以参与数据库记录、并且各计算设备之间可以快速的进行数据同步的特性,使得区块链技术已在众多的领域中广泛的进行应用。Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Due to the characteristics of decentralization, openness and transparency of blockchain technology, each computing device can participate in database records, and data synchronization between computing devices can be performed quickly, blockchain technology has been widely used in many fields. to apply.
发明内容SUMMARY OF THE INVENTION
本说明书实施例提供的一种提高信息安全的方法及装置、电子设备。The embodiments of this specification provide a method and apparatus for improving information security, and an electronic device.
根据本说明书实施例的第一方面,提供一种区块链版本兼容性验证方法,所述方法应用于所述区块链中的目标节点设备;其中,所述区块链支持进行软件版本升级;所述方法包括:According to a first aspect of the embodiments of this specification, a method for verifying version compatibility of a blockchain is provided, and the method is applied to a target node device in the blockchain; wherein the blockchain supports software version upgrades ; the method includes:
获取待验证的历史区块,并从所述历史区块中读取待验证的交易;Obtain the historical block to be verified, and read the transaction to be verified from the historical block;
基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;以及,基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果;Execute the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result; and execute the transaction based on the second software version supported by the blockchain to obtain a second transaction execution result;
将所述第一交易执行结果与所述第二交易执行结果进行匹配,并基于所述匹配的结果以确定所述第一软件版本与所述第二软件版本是否兼容。The first transaction execution result is matched with the second transaction execution result, and based on the matching result, it is determined whether the first software version is compatible with the second software version.
可选的,在所述基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;以及,基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果之前,还包括:Optionally, executing the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result; and executing the transaction based on the second software version supported by the blockchain, Before obtaining the execution result of the second transaction, it also includes:
从所述区块链对应的历史状态数据库中,获取与所述历史区块对应的历史状态数据;其中,与所述历史区块对应的历史状态数据被设置为只读状态;Obtain the historical state data corresponding to the historical block from the historical state database corresponding to the blockchain; wherein, the historical state data corresponding to the historical block is set to a read-only state;
从与所述历史区块对应的历史状态数据中读取与所述交易相关的区块链账户对应的初始账户状态。The initial account state corresponding to the blockchain account associated with the transaction is read from the historical state data corresponding to the historical block.
可选的,所述交易执行结果包括执行交易后生成的交易收据;Optionally, the transaction execution result includes a transaction receipt generated after the transaction is executed;
所述基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;performing the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result;
基于所述区块链支持的第一软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第一软件版本的第一交易收据;Execute the transaction based on the first software version supported by the blockchain, generate an updated account state corresponding to the initial account state, and generate the transaction corresponding to the initial account state and the updated account state based on the initial account state and the updated account state the first transaction receipt for the first software version;
所述基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果,包括:The execution of the transaction based on the second software version supported by the blockchain to obtain a second transaction execution result includes:
基于所述区块链支持的第二软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第二软件版本的第二交易收据。Execute the transaction based on the second software version supported by the blockchain, generate an updated account state corresponding to the initial account state, and generate the transaction corresponding to the initial account state based on the initial account state and the updated account state and a second transaction receipt for the second software version.
可选的,所述目标节点设备搭载了用于记录交易执行结果的服务端口;Optionally, the target node device is equipped with a service port for recording transaction execution results;
在所述将所述第一交易执行结果与所述第二交易执行结果进行匹配之前,还包括:Before the matching of the first transaction execution result with the second transaction execution result, the method further includes:
调用所述服务端口,在本地存储生成的所述第一交易收据和所述第二交易收据。The service port is called to locally store the generated first transaction receipt and the second transaction receipt.
可选的,所述将所述第一交易执行结果与所述第二交易执行结果进行匹配,并基于所述匹配的结果以确定所述第一软件版本与所述第二软件版本是否兼容,包括:Optionally, matching the first transaction execution result with the second transaction execution result, and determining whether the first software version and the second software version are compatible based on the matching result, include:
读取所述服务端口记录的所述第一交易收据和所述第二交易收据;reading the first transaction receipt and the second transaction receipt recorded by the service port;
将读取到的所述第一交易收据和所述第二交易收据进行匹配;matching the read first transaction receipt and the second transaction receipt;
如果所述第一交易收据与所述第二交易收据匹配,确定所述第一软件版本与所述第二软件版本兼容;反之,确定所述第一软件版本与所述第二软件版本不兼容。If the first transaction receipt matches the second transaction receipt, it is determined that the first software version is compatible with the second software version; otherwise, it is determined that the first software version is not compatible with the second software version .
可选的,所述获取待验证的历史区块,包括:Optionally, the obtaining the historical block to be verified includes:
获取用户指定的待验证的历史区块对应的区块号区间;Obtain the block number range corresponding to the historical block to be verified specified by the user;
从所述区块号区间中读取待验证的历史区块的区块号,并在本地维护的所述区块链的区块数据中读取与所述区块号对应的历史区块。The block number of the historical block to be verified is read from the block number interval, and the historical block corresponding to the block number is read from the block data of the blockchain maintained locally.
可选的,所述本地维护的所述区块链的区块数据为预先拷贝至所述目标节点设备的区块数据。Optionally, the locally maintained block data of the blockchain is the block data copied to the target node device in advance.
可选的,所述区块链支持进行软件版本的灰度升级;所述第一软件版本包括最新软件版本;所述第二软件版本包括将所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本之前,所述部分节点设备支持的历史软件版本。Optionally, the blockchain supports grayscale upgrade of software versions; the first software version includes the latest software version; the second software version includes software that supports some node devices in the blockchain. The version is the historical software version supported by some node devices before the grayscale upgrade is to the latest software version.
可选的,在所述获取待验证的历史区块,并从所述历史区块中读取待验证的交易之前,还包括:Optionally, before acquiring the historical block to be verified and reading the transaction to be verified from the historical block, the method further includes:
响应于所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本,获取待验证的历史区块,并从所述历史区块中读取待验证的交易。In response to the grayscale upgrade of the software version supported by some node devices in the blockchain to the latest software version, the historical block to be verified is obtained, and the transaction to be verified is read from the historical block.
可选的,所述方法还包括:Optionally, the method further includes:
如果确定所述最新软件版本与所述历史软件版本兼容,向所述区块链对应的服务平台发送升级指示,以触发所述服务平台将所述部分节点设备支持的软件版本由所述历史软件版本升级为所述最新软件版本。If it is determined that the latest software version is compatible with the historical software version, send an upgrade instruction to the service platform corresponding to the blockchain, so as to trigger the service platform to transfer the software versions supported by the part of the node devices to the historical software The version is upgraded to the latest software version described.
可选的,所述服务平台包括Bass平台。Optionally, the service platform includes a Bass platform.
可选的,所述目标节点设备包括所述区块链中预设的不参与共识的非共识节点。Optionally, the target node device includes a preset non-consensus node in the blockchain that does not participate in the consensus.
根据本说明书实施例的第二方面,提供一种区块链版本兼容性验证装置,所述装置应用于所述区块链中的目标节点设备;其中,所述区块链支持进行软件版本升级;所述装置包括:According to a second aspect of the embodiments of the present specification, a blockchain version compatibility verification device is provided, the device is applied to a target node device in the blockchain; wherein the blockchain supports software version upgrade ; the device includes:
获取单元,获取待验证的历史区块,并从所述历史区块中读取待验证的交易;an acquisition unit that acquires the historical block to be verified, and reads the transaction to be verified from the historical block;
执行单元,基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;以及,基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果;an execution unit that executes the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result; and executes the transaction based on the second software version supported by the blockchain to obtain a second transaction Results of the;
验证单元,将所述第一交易执行结果与所述第二交易执行结果进行匹配,并基于所述匹配的结果以确定所述第一软件版本与所述第二软件版本是否兼容。A verification unit that matches the first transaction execution result with the second transaction execution result, and determines whether the first software version and the second software version are compatible based on the matching result.
可选的,在所述执行单元之前,还包括:Optionally, before the execution unit, it further includes:
数据获取子单元,从所述区块链对应的历史状态数据库中,获取与所述历史区块对应的历史状态数据;其中,与所述历史区块对应的历史状态数据被设置为只读状态;从与所述历史区块对应的历史状态数据中读取与所述交易相关的区块链账户对应的初始账户状态。The data acquisition subunit acquires the historical state data corresponding to the historical block from the historical state database corresponding to the blockchain; wherein, the historical state data corresponding to the historical block is set to a read-only state ; Read the initial account state corresponding to the blockchain account related to the transaction from the historical state data corresponding to the historical block.
可选的,所述交易执行结果包括执行交易后生成的交易收据;Optionally, the transaction execution result includes a transaction receipt generated after the transaction is executed;
所述执行单元,进一步包括:The execution unit further includes:
第一执行子单元,基于所述区块链支持的第一软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第一软件版本的第一交易收据;a first execution subunit that executes the transaction based on the first software version supported by the blockchain, generates an updated account state corresponding to the initial account state, and generates an updated account state based on the initial account state and the updated account state the transaction corresponds to a first transaction receipt for the first software version;
第二执行子单元,基于所述区块链支持的第二软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第二软件版本的第二交易收据。The second execution subunit executes the transaction based on the second software version supported by the blockchain, generates an updated account state corresponding to the initial account state, and generates an updated account state based on the initial account state and the updated account state The transaction corresponds to a second transaction receipt for the second software version.
可选的,所述目标节点设备搭载了用于记录交易执行结果的服务端口;Optionally, the target node device is equipped with a service port for recording transaction execution results;
在所述验证单元之前,还包括:Before the verification unit, it also includes:
调用单元,调用所述服务端口,在本地存储生成的所述第一交易收据和所述第二交易收据。The calling unit calls the service port to locally store the generated first transaction receipt and the second transaction receipt.
可选的,所述验证单元,进一步包括:Optionally, the verification unit further includes:
读取子单元,读取所述服务端口记录的所述第一交易收据和所述第二交易收据;a reading subunit, to read the first transaction receipt and the second transaction receipt recorded by the service port;
匹配子单元,将读取到的所述第一交易收据和所述第二交易收据进行匹配;a matching subunit, which matches the read first transaction receipt and the second transaction receipt;
确定子单元,如果所述第一交易收据与所述第二交易收据匹配,确定所述第一软件版本与所述第二软件版本兼容;反之,确定所述第一软件版本与所述第二软件版本不兼容。A determination subunit, if the first transaction receipt matches the second transaction receipt, determine that the first software version is compatible with the second software version; otherwise, determine that the first software version is compatible with the second software version Incompatible software version.
可选的,所述获取单元,进一步包括:获取用户指定的待验证的历史区块对应的区块号区间,从所述区块号区间中读取待验证的历史区块的区块号,并在本地维护的所述区块链的区块数据中读取与所述区块号对应的历史区块。Optionally, the obtaining unit further includes: obtaining the block number interval corresponding to the historical block to be verified specified by the user, and reading the block number of the historical block to be verified from the block number interval, And read the historical block corresponding to the block number in the block data of the block chain maintained locally.
可选的,所述本地维护的所述区块链的区块数据为预先拷贝至所述目标节点设备的区块数据。Optionally, the locally maintained block data of the blockchain is the block data copied to the target node device in advance.
可选的,所述区块链支持进行软件版本的灰度升级;所述第一软件版本包括最新软件版本;所述第二软件版本包括将所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本之前,所述部分节点设备支持的历史软件版本。Optionally, the blockchain supports grayscale upgrade of software versions; the first software version includes the latest software version; the second software version includes software that supports some node devices in the blockchain. The version is the historical software version supported by some node devices before the grayscale upgrade is to the latest software version.
可选的,在所述获取单元之前,还包括:Optionally, before the obtaining unit, it further includes:
响应单元,响应于所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本,获取待验证的历史区块,并从所述历史区块中读取待验证的交易。The response unit, in response to the grayscale upgrade of the software version supported by some node devices in the blockchain to the latest software version, obtains the historical block to be verified, and reads the historical block to be verified from the historical block. trade.
可选的,所述装置还包括:Optionally, the device further includes:
处理单元,如果确定所述最新软件版本与所述历史软件版本兼容,向所述区块链对应的服务平台发送升级指示,以触发所述服务平台将所述部分节点设备支持的软件版本由所述历史软件版本升级为所述最新软件版本。The processing unit, if it is determined that the latest software version is compatible with the historical software version, sends an upgrade instruction to the service platform corresponding to the blockchain, so as to trigger the service platform to update the software version supported by the part of the node device by the service platform. The historical software version is upgraded to the latest software version.
可选的,所述服务平台包括Bass平台。Optionally, the service platform includes a Bass platform.
可选的,所述目标节点设备包括所述区块链中预设的不参与共识的非共识节点。Optionally, the target node device includes a preset non-consensus node in the blockchain that does not participate in the consensus.
根据本说明书实施例的第三方面,提供一种电子设备,包括:According to a third aspect of the embodiments of the present specification, an electronic device is provided, including:
处理器;processor;
用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;
其中,所述处理器被配置为上述任一项区块链版本兼容性验证方法。Wherein, the processor is configured as any one of the above-mentioned blockchain version compatibility verification methods.
本说明书实施例,提供了一种区块链版本兼容性验证方案,由区块链支持的第一软件版本和第二软件版本分别执行历史区块中交易,通过比较两者的交易执行结果,以验证第一软件版本与所述第二软件版本是否兼容。The embodiment of this specification provides a blockchain version compatibility verification scheme. The first software version and the second software version supported by the blockchain execute transactions in historical blocks respectively, and by comparing the transaction execution results of the two, to verify whether the first software version is compatible with the second software version.
附图说明Description of drawings
图1是一示例性实施例提供的一种区块链版本兼容性验证方法的流程图;1 is a flowchart of a method for verifying version compatibility of a blockchain provided by an exemplary embodiment;
图2是一示例性实施例提供的一种电子设备的结构示意图;FIG. 2 is a schematic structural diagram of an electronic device provided by an exemplary embodiment;
图3是一示例性实施例提供的一种区块链版本兼容性验证装置的框图。FIG. 3 is a block diagram of a blockchain version compatibility verification device provided by an exemplary embodiment.
具体实施方式Detailed ways
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实现方式并不代表与本说明书一个或多个实施例相一致的所有实现方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. When the following description refers to the drawings, the same numerals in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatus and methods consistent with some aspects of one or more embodiments of this specification, as recited in the appended claims.
需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。It should be noted that: in other embodiments, the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step in other embodiments. describe.
区块链一般被划分为三种类型:公有链(Public Blockchain),私有链(PrivateBlockchain)和联盟链(Consortium Blockchain)。此外,还可以有上述多种类型的结合,比如私有链+联盟链、联盟链+公有链等。Blockchains are generally divided into three types: Public Blockchain, Private Blockchain and Consortium Blockchain. In addition, there can also be a combination of the above-mentioned types, such as private chain + alliance chain, alliance chain + public chain, etc.
其中,去中心化程度最高的是公有链。加入公有链的参与者(也可称为区块链中的节点)可以读取链上的数据记录、参与交易、以及竞争新区块的记账权等。而且,各节点可自由加入或者退出网络,并进行相关操作。Among them, the most decentralized is the public chain. Participants who join the public chain (also known as nodes in the blockchain) can read data records on the chain, participate in transactions, and compete for the accounting rights of new blocks. Moreover, each node can freely join or leave the network and perform related operations.
私有链则相反,该网络的写入权限由某个组织或者机构控制,数据读取权限受组织规定。简单来说,私有链可以为一个弱中心化系统,其对节点具有严格限制且节点数量较少。这种类型的区块链更适合于特定机构内部使用。The private chain is on the contrary, the write permission of the network is controlled by an organization or institution, and the data read permission is regulated by the organization. In simple terms, a private chain can be a weakly centralized system with strict restrictions on nodes and a small number of nodes. This type of blockchain is more suitable for internal use by specific institutions.
联盟链则是介于公有链以及私有链之间的区块链,可实现“部分去中心化”。联盟链中各个节点通常有与之相对应的实体机构或者组织;节点通过授权加入网络并组成利益相关联盟,共同维护区块链运行。The consortium chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization". Each node in the alliance chain usually has a corresponding entity or organization; the node joins the network through authorization and forms a stakeholder alliance to jointly maintain the operation of the blockchain.
基于区块链的基本特性,区块链通常是由若干个区块构成。在这些区块中分别记录有与该区块的创建时刻对应的时间戳,所有的区块严格按照区块中记录的时间戳,构成一条在时间上有序的数据链条。Based on the basic characteristics of the blockchain, the blockchain is usually composed of several blocks. Timestamps corresponding to the creation time of the blocks are respectively recorded in these blocks, and all blocks form a time-ordered data chain strictly according to the timestamps recorded in the blocks.
对于物理世界产生的真实数据,可以将其构建成区块链所支持的标准的交易(transaction)格式,然后发布至区块链,由区块链中的节点设备对收到的交易进行共识处理,并在达成共识后,由区块链中作为记账节点的节点设备,将这笔交易打包进区块,在区块链中进行持久化存证。For the real data generated in the physical world, it can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain, and the node devices in the blockchain will perform consensus processing on the received transactions , and after reaching a consensus, the node device in the blockchain as the accounting node will package the transaction into the block and store the certificate persistently in the blockchain.
一般的,本轮的记账节点可以将接收到的交易打包以生成候选区块,并将生成的候选区块或者该候选区块的区块头发送至其它节点设备进行共识验证。如果其它节点设备接收到候选区块或者该候选区块的区块头后,经验证没有问题,可以将该候选区块作为最新区块追加到原有的区块链末尾,从而完成区块链的记账过程。其它节点验证记账节点发来的新的区块或区块头的过程中,也可以执行该区块中的包含的交易。Generally, the accounting node of this round can package the received transaction to generate a candidate block, and send the generated candidate block or the block header of the candidate block to other node devices for consensus verification. If other node devices receive the candidate block or the block header of the candidate block and verify that there is no problem, the candidate block can be added to the end of the original blockchain as the latest block, thereby completing the blockchain. accounting process. In the process of verifying the new block or block header sent by the accounting node, other nodes can also execute the transactions contained in the block.
在区块链领域,有一个重要的概念就是账户(Account);通常将账户划分为外部账户和合约账户两类;外部账户就是由用户直接控制的账户,也称之为用户账户;而合约账户则是由用户通过外部账户创建的,包含合约代码的账户(即智能合约)。In the field of blockchain, an important concept is Account; accounts are usually divided into two categories: external accounts and contract accounts; external accounts are accounts directly controlled by users, also known as user accounts; and contract accounts It is an account (ie, a smart contract) that is created by the user through an external account and contains the contract code.
当然,对于一些账户模型的区块链(比如蚂蚁区块链),还可以对区块链支持的账户类型,进行进一步的扩展,在本说明书中不进行特别限定。Of course, for some blockchains with account models (such as Ant blockchain), the account types supported by the blockchain can be further expanded, which is not particularly limited in this specification.
对于区块链中的账户而言,通常会通过一个结构体,来维护账户的账户状态。当区块中的交易被执行后,区块链中与该交易相关的账户的状态通常也会发生变化。For an account in the blockchain, a structure is usually used to maintain the account state of the account. When a transaction in a block is executed, the state of the account associated with that transaction in the blockchain usually changes as well.
一般的,账户的结构体通常包括Balance,Nonce,Code和Storage等字段。其中:Generally, the structure of the account usually includes fields such as Balance, Nonce, Code and Storage. in:
Balance字段,用于维护账户目前的账户余额;The Balance field is used to maintain the current account balance of the account;
Nonce字段,用于维护该账户的交易次数;它是用于保障每笔交易能且只能被处理一次的计数器,有效避免重放攻击;The Nonce field is used to maintain the number of transactions of the account; it is a counter used to ensure that each transaction can be processed only once, effectively avoiding replay attacks;
Code字段,用于维护该账户的合约代码;在实际应用中,Code字段中通常仅维护合约代码的hash值;因而,Code字段通常也称之为Codehash字段。The Code field is used to maintain the contract code of the account; in practical applications, the Code field usually only maintains the hash value of the contract code; therefore, the Code field is usually also called the Codehash field.
Storage字段,用于维护该账户的存储内容(默认字段值为空);对于合约账户而言,通常会分配一个独立的存储空间,用以存储该合约账户的存储内容;该独立的存储空间通常称之为该合约账户的账户存储。合约账户的存储内容通常会构建成MPT(MerklePatricia Trie)树的数据结构存储在上述独立的存储空间之中;其中,基于合约账户的存储内容构建成的MPT树,通常也称之为Storage树。而Storage字段通常仅维护该Storage树的根节点;因此,Storage字段通常也称之为StorageRoot字段。The Storage field is used to maintain the storage content of the account (the default field value is empty); for a contract account, an independent storage space is usually allocated to store the storage content of the contract account; the independent storage space is usually Call it the account storage for this contract account. The storage content of the contract account is usually constructed as a data structure of the MPT (Merkle Patricia Trie) tree and stored in the above-mentioned independent storage space; among them, the MPT tree constructed based on the storage content of the contract account is usually also called the Storage tree. The Storage field usually only maintains the root node of the Storage tree; therefore, the Storage field is usually also called the StorageRoot field.
其中,对于外部账户而言,以上示出的Code字段和Storage字段的字段值均为空值。Wherein, for the external account, the field values of the Code field and the Storage field shown above are all null values.
对于大多数区块链模型,通常都会使用Merkle树;或者,基于Merkle树的数据结构,来存储和维护数据。例如使用MPT树(一种Merkle树变种)作为数据组织形式,用来组织和管理账户状态、交易信息等重要数据。For most blockchain models, a Merkle tree; or, a data structure based on a Merkle tree, is usually used to store and maintain data. For example, MPT tree (a Merkle tree variant) is used as a data organization form to organize and manage important data such as account status and transaction information.
对区块链中需要存储和维护的数据,设计了三棵MPT树,分别是MPT状态树、MPT交易树和MPT收据树。其中,除了以上三棵MPT树以外,实际上还存在一棵基于合约账户的存储内容构建的Storage树。For the data that needs to be stored and maintained in the blockchain, three MPT trees are designed, which are MPT state tree, MPT transaction tree and MPT receipt tree. Among them, in addition to the above three MPT trees, there is actually a Storage tree constructed based on the storage content of the contract account.
MPT状态树,是由区块链中所有账户的账户状态(state)数据组织成的MPT树;MPT交易树,是由区块链中的交易(transaction)数据组织成的MPT树;MPT收据树,是区块中的交易在执行完毕后生成的与每笔交易对应的交易(receipt)收据组织成的MPT树。以上示出的MPT状态树、MPT交易树和MPT收据树的根节点的hash值,最终都会被添加至对应区块的区块头中。MPT state tree is an MPT tree organized by the account state data of all accounts in the blockchain; MPT transaction tree is an MPT tree organized by transaction data in the blockchain; MPT receipt tree , is the MPT tree organized by the transaction receipt corresponding to each transaction generated after the transaction in the block is executed. The hash values of the root nodes of the MPT state tree, MPT transaction tree, and MPT receipt tree shown above will eventually be added to the block header of the corresponding block.
其中,MPT交易树和MPT收据树均与区块相对应,即每一个区块都有自己的MPT交易树和MPT收据树。而MPT状态树是一个全局的MPT树,并不与某一个特定的区块相对应,而是涵盖了区块链中所有账户的账户状态数据。Among them, the MPT transaction tree and the MPT receipt tree correspond to blocks, that is, each block has its own MPT transaction tree and MPT receipt tree. The MPT state tree is a global MPT tree, which does not correspond to a specific block, but covers the account state data of all accounts in the blockchain.
对于组织成的MPT交易树、MPT收据树和MPT状态树,最终都会在采用多级数据存储结构的Key-Value型数据库(比如,LevelDB)中进行存储。The organized MPT transaction tree, MPT receipt tree and MPT state tree will eventually be stored in a Key-Value database (for example, LevelDB) that adopts a multi-level data storage structure.
而采用多级数据存储结构的上述数据库,通常采用多级数据存储的结构,可以被划分为n级数据存储;例如,各级数据存储可以依次设为L0,L1,L2,L3....L(n-1);对于上述数据库中的各级数据存储而言,等级编号越小通常级别越高;例如,L0存储的是最新的若干区块的数据,L1存储的是次新的若干区块的数据,以此类推。The above-mentioned databases adopting a multi-level data storage structure usually adopt a multi-level data storage structure, which can be divided into n-level data storage; for example, the data storage of each level can be set as L0, L1, L2, L3.... L(n-1); For the data storage of all levels in the above database, the smaller the level number is, the higher the level is; for example, L0 stores the data of the latest blocks, and L1 stores the next new ones. block data, and so on.
其中,各级数据存储对应的存储介质的读写性能,通常也可以存在性能差异;例如,级别高(即等级编号较小的)的数据存储对应的存储介质的读写性能,可以高于级别低的数据存储对应的存储介质的读写性能。在实际应用中,级别高的数据存储,可以使用存储成本较高,存储性能较优的存储介质;而级别低的数据存储,可以使用单位成本低,且容量较大的存储介质。Among them, the read and write performance of the storage medium corresponding to the data storage at all levels may also have performance differences; for example, the read and write performance of the storage medium corresponding to the data storage with a high level (that is, with a smaller level number) may be higher than that of the level. The read and write performance of the storage medium corresponding to low data storage. In practical applications, high-level data storage can use storage media with higher storage costs and better storage performance; while low-level data storage can use storage media with low unit cost and larger capacity.
在实际应用中,随着区块链的区块号的增长(也称之为区块高度),在数据库中存储的数据,会包含很多历史数据;而且,区块号越小的区块中的数据越久远,越不重要。因此,为了降低整体的存储成本,通常可以对不同区块高度的数据进行“区别对待”;例如,可以将区块号较小的区块中的数据,存储至成本较低的存储介质上;而将区块号较大的区块中的数据,存储在成本较高的存储介质上。In practical applications, as the block number of the blockchain increases (also called the block height), the data stored in the database will contain a lot of historical data; The older the data, the less important it is. Therefore, in order to reduce the overall storage cost, data of different block heights can usually be "differently treated"; for example, the data in the block with a smaller block number can be stored on a lower-cost storage medium; On the other hand, the data in the block with the larger block number is stored on the storage medium with higher cost.
需要说明的是,区块链每产生一个最新区块,则在该最新区块中的交易被执行之后,区块链中这些被执行交易的相关账户(可以是外部账户也可以是合约账户)的账户状态,通常也会随之发生变化;It should be noted that each time the blockchain generates a newest block, after the transactions in the latest block are executed, the relevant accounts of these executed transactions in the blockchain (can be external accounts or contract accounts) account status, usually changes accordingly;
例如,当区块中的一笔“转账交易”执行完毕后,与该“转账交易”相关的转出方账户和转入方账户的余额(即这些账户的Balance字段的字段值),通常也会随之发生变化。For example, when a "transfer transaction" in the block is executed, the balances of the sender's account and the transferer's account related to the "transfer transaction" (that is, the field value of the Balance field of these accounts) are usually also will change accordingly.
而节点设备在区块链产生的最新区块中的交易执行完毕后,由于当前区块链中的账户状态发生了变化,因此节点设备需要根据区块链中所有账户当前的账户状态数据,来构建MPT状态树,用于维护区块链中所有账户的最新状态。After the node device completes the execution of the transaction in the latest block generated by the blockchain, since the account status in the current blockchain has changed, the node device needs to use the current account status data of all accounts in the blockchain. Build the MPT state tree to maintain the latest state of all accounts in the blockchain.
也即,每当区块链中产生一个最新区块,并且该最新区块中的交易执行完毕后,导致区块链中的账户状态发生了变化,节点设备都需要基于区块链中所有账户最新的账户状态数据,重新构建一棵MPT状态树。换句话说,区块链中每一个区块,都有一个与之对应的MPT状态树;该MPT状态树,维护了在该区块中的交易在执行完毕后,区块链中所有账户最新的账户状态。That is, whenever a latest block is generated in the blockchain and the transaction in the latest block is executed, the account status in the blockchain changes, and the node device needs to be based on all the accounts in the blockchain. The latest account status data, rebuild an MPT status tree. In other words, each block in the blockchain has a corresponding MPT state tree; the MPT state tree maintains that after the transaction in the block is executed, all accounts in the blockchain are up-to-date. account status.
以区块链的账户状态数据组织成的MPT状态树为例进行说明。Take the MPT state tree organized by the account state data of the blockchain as an example to illustrate.
MPT树,是一种较为传统的经过改良的Merkle树变种,其融合了Merkle树和Trie字典树(也称之为前缀树)两种树形结构的优点。MPT tree is a more traditional and improved variant of Merkle tree, which combines the advantages of two tree structures of Merkle tree and Trie dictionary tree (also called prefix tree).
在MPT树中通常包括三种数据节点,分别为叶子节点(leaf node),扩展节点(extension node)和分支节点(branch node)。An MPT tree usually includes three kinds of data nodes, which are leaf nodes, extension nodes, and branch nodes.
扩展节点,表示为[key,value]的一个键值对,其中key是种特殊的十六进制编码字符,表示账户地址的共享字符前缀;其中,所述共享字符前缀,是指多有区块链账户地址所具有的相同的一个或者多个字符组成的前缀;value是其它节点的hash值(hash指针),也就是说可以通过hash指针链接到其它节点。Extended node, represented as a key-value pair of [key, value], where key is a special hexadecimal coded character, which represents the shared character prefix of the account address; wherein, the shared character prefix refers to the multi-area The address of the blockchain account has the same prefix of one or more characters; the value is the hash value (hash pointer) of other nodes, that is to say, it can be linked to other nodes through the hash pointer.
分支节点,包含17个元素,前16个元素对应着key中的16个可能的十六进制字符,一个字符对应一个nibble(半字节),分别表示一个账户地址的共享字符前缀(长度为一个字符)。其中,如果有一个[key,value]对在这个分支节点终止,则该分支节点可以充当叶子节点的角色,最后一个元素则代表叶子节点的value值;反之,分支节点的最后一个元素,可以为空值。Branch node, including 17 elements, the first 16 elements correspond to the 16 possible hexadecimal characters in the key, and one character corresponds to a nibble (nibble), which respectively represent the shared character prefix of an account address (length is one character). Among them, if there is a [key, value] pair terminated at this branch node, the branch node can act as a leaf node, and the last element represents the value of the leaf node; otherwise, the last element of the branch node can be Null value.
叶子节点,是表示为[key,value]的一个键值对,其中key也是种特殊的十六进制编码字符,表示账户地址的字符后缀;其中,账户地址的字符后缀和账户地址的共享字符前缀共同组成了一个完整的账户地址;所述字符后缀,是指除了账户地址的共享字符前缀以外的最后一个或者多个字符组成的后缀;value是该叶子节点对应的账户地址的状态数据(即以上示出的结构体)。A leaf node is a key-value pair expressed as [key, value], where key is also a special hexadecimal coded character, representing the character suffix of the account address; among them, the character suffix of the account address and the shared character of the account address The prefixes together form a complete account address; the character suffix refers to the suffix consisting of the last one or more characters except the shared character prefix of the account address; value is the status data of the account address corresponding to the leaf node (ie structure shown above).
由于在MPT树上,从根节点到一个叶子节点的搜索路径上的字符,组成一个完整的账户地址;因此,对于分支节点而言,其既可以是上述搜索路径的终止节点,也可以是上述搜索路径的中间节点。Because on the MPT tree, the characters on the search path from the root node to a leaf node form a complete account address; therefore, for the branch node, it can be either the termination node of the above search path, or the above Intermediate nodes of the search path.
假设需要组织成MTP状态树的账户状态数据如下表1所示:Assume that the account state data that needs to be organized into an MTP state tree is shown in Table 1 below:
表1Table 1
在表1中,账户地址是由若干16进制的字符构成的字符串。账户状态state,是由上述Balance,Nonce,Code和Storage等字段构成的结构体。In Table 1, the account address is a string composed of several hexadecimal characters. The account state state is a structure composed of the above fields such as Balance, Nonce, Code, and Storage.
最终按照表1中的账户状态数据组织成的MPT状态树;该MPT状态树是由4个叶子节点,2个分支节点,和2个扩展节点(其中一个扩展节点作为根节点)构成。The MPT state tree is finally organized according to the account state data in Table 1; the MPT state tree is composed of 4 leaf nodes, 2 branch nodes, and 2 extension nodes (one of which is the root node).
prefix字段为扩展节点和叶子节点共同具有的前缀字段。该prefix字段的不同字段值可以用于表示不同的节点类型。The prefix field is a prefix field shared by the extension node and the leaf node. Different field values of the prefix field can be used to represent different node types.
例如,prefix字段的取值为0,表示包含偶数个nibbles的扩展节点;如前所述,nibble表示半字节,由4位二进制组成,一个nibble可以对应一个组成账户地址的字符。prefix字段的取值为1,表示包含奇数个nibble(s)的扩展节点;prefix字段的取值为2,表示包含偶数个nibbles的叶子节点;prefix字段的取值为3,表示包含奇数个nibble(s)的叶子节点。For example, the value of the prefix field is 0, indicating an extension node containing an even number of nibbles; as mentioned above, a nibble represents a nibble, which is composed of 4-bit binary, and a nibble can correspond to a character that constitutes an account address. The value of the prefix field is 1, which means that the extension node contains an odd number of nibble(s); the value of the prefix field is 2, which means that the leaf node contains an even number of nibbles; the value of the prefix field is 3, which means that it contains an odd number of nibbles. (s) leaf node.
而分支节点,由于其是并列单nibble的前缀节点,因此分支节点不具有上述prefix字段。For the branch node, since it is a prefix node of a parallel single nibble, the branch node does not have the above prefix field.
扩展节点中的Shared nibble字段,对应该扩展节点所包含的键值对的key值,表示账户地址之间的共同字符前缀;比如,上表中的所有账户地址均具有共同的字符前缀a7。Next Node字段中填充下一个节点的hash值(hash指针)。The Shared nibble field in the extension node corresponds to the key value of the key-value pair contained in the extension node, indicating the common character prefix between account addresses; for example, all account addresses in the above table have a common character prefix a7. The Next Node field is filled with the hash value (hash pointer) of the next node.
分支节点中的16进制字符0~f字段,对应该分支节点所包含的键值对的key值;如果该分支节点为账户地址在MPT树上的搜索路径上的中间节点,则该分支节点的Value字段可以为空值。0~f字段中用于填充下一个节点的hash值。The hexadecimal character 0~f field in the branch node corresponds to the key value of the key-value pair contained in the branch node; if the branch node is an intermediate node on the search path of the account address in the MPT tree, then the branch node The Value field can be null. The hash value used to fill the next node in the 0~f field.
叶子节点中的Key-end,对应该叶子节点所包含的键值对的key值,表示账户地址的最后几个字符(账户地址的字符后缀)。从根节点搜索到叶子节点的搜索路径上的各个节点的key值,构成了一个完整的账户地址。该叶子节点的Value字段填充账户地址对应的账户状态数据;例如,可以对上述Balance,Nonce,Code和storage等字段构成的结构体进行编码后,填充至叶子节点的Value字段。The Key-end in the leaf node corresponds to the key value of the key-value pair contained in the leaf node, and represents the last few characters of the account address (the character suffix of the account address). The key value of each node on the search path from the root node to the leaf node constitutes a complete account address. The Value field of the leaf node is filled with the account status data corresponding to the account address; for example, the structure composed of the fields such as Balance, Nonce, Code, and storage can be encoded, and then filled into the Value field of the leaf node.
进一步的,MPT状态树上的node,最终也是以Key-Value键值对的形式存储在数据库中;Further, the nodes on the MPT state tree are finally stored in the database in the form of Key-Value key-value pairs;
其中,当MPT状态树上的node在数据库中进行存储时,MPT状态树上的node的键值对中的key,可以为node所包含的数据内容的hash值;MPT状态树上的node的键值对中的Value,为node所包含的数据内容。Among them, when the node on the MPT state tree is stored in the database, the key in the key-value pair of the node on the MPT state tree can be the hash value of the data content contained in the node; the key of the node on the MPT state tree The Value in the value pair is the data content contained in the node.
也即,在将MPT状态树上的node存储至数据库时,可以计算该node所包含的数据内容的hash值(即对node整体进行hash计算),并将计算出的hash值作为key,将该node所包含的数据内容作为value,生成Key-Value键值对;然后,将生成的Key-Value键值对存储至数据库中。That is, when the node on the MPT state tree is stored in the database, the hash value of the data content contained in the node can be calculated (that is, hash calculation is performed on the entire node), and the calculated hash value can be used as the key. The data content contained in the node is used as value to generate a Key-Value key-value pair; then, the generated Key-Value key-value pair is stored in the database.
由于MPT状态树上的node,是以node所包含的数据内容的hash值为Key,node所包含的数据内容为value进行存储;因此,在需要查询MPT状态树上的node时,通常可以基于node所包含的数据内容的hash值作为key来进行内容寻址。Because the node on the MPT state tree is stored as the key with the hash value of the data content contained in the node, and the data content contained in the node is stored as the value; therefore, when you need to query the node on the MPT state tree, you can usually The hash value of the contained data content is used as a key for content addressing.
在实际应用中,不论是公有链、私有链还是联盟链,都可能提供智能合约(Smartcontract)的功能。区块链上的智能合约是在区块链上可以被交易触发执行的合约。智能合约可以通过代码的形式定义。In practical applications, whether it is a public chain, a private chain or a consortium chain, it is possible to provide the function of smart contracts. A smart contract on the blockchain is a contract that can be triggered and executed by a transaction on the blockchain. Smart contracts can be defined in the form of code.
智能合约创建后,区块链上出现一个与该智能合约对应的合约账户,并拥有一个特定的地址;合约代码(Code)和账户存储(Storage)将保存在该合约账户的账户存储中。智能合约的行为由合约代码控制,而智能合约的账户存储则保存了合约的状态。换句话说,智能合约使得区块链上产生包含合约代码和账户存储的虚拟账户。After the smart contract is created, a contract account corresponding to the smart contract appears on the blockchain and has a specific address; the contract code (Code) and account storage (Storage) will be stored in the account storage of the contract account. The behavior of the smart contract is controlled by the contract code, and the account storage of the smart contract saves the state of the contract. In other words, smart contracts create virtual accounts on the blockchain that contain contract code and account storage.
前述提到,包含创建智能合约的交易的Data字段保存的可以是该智能合约的字节码。字节码由一连串的字节组成,每一字节可以标识一个操作。基于开发效率、可读性等多方面考虑,开发者可以不直接书写字节码,而是选择一门高级语言编写智能合约代码。例如,高级语言可以采用诸如Solidity、Serpent、LLL语言等。对于采用高级语言编写的智能合约代码,可以经过编译器编译,生成可以部署到区块链上的字节码。As mentioned above, the Data field containing the transaction that creates the smart contract can store the bytecode of the smart contract. Bytecode consists of a series of bytes, each of which can identify an operation. Based on development efficiency, readability and other considerations, developers can choose a high-level language to write smart contract code instead of writing bytecode directly. For example, high-level languages such as Solidity, Serpent, LLL, etc. may be used. For smart contract code written in a high-level language, it can be compiled by a compiler to generate bytecode that can be deployed on the blockchain.
以Solidity语言为例,用其编写的合约代码与面向对象编程语言中的类(Class)很相似,在一个合约中可以声明多种成员,包括状态变量、函数、函数修改器、事件等。状态变量是永久存储在智能合约的账户存储(Storage)字段中的值,用于保存合约的状态。Taking the Solidity language as an example, the contract code written in it is very similar to the class (Class) in the object-oriented programming language. A variety of members can be declared in a contract, including state variables, functions, function modifiers, events, etc. A state variable is a value that is permanently stored in a smart contract's account storage (Storage) field and is used to save the state of the contract.
在现有区块链技术中,区块链的软件版本存在需要升级的需求。每次区块链的版本升级都需要发布一个新版本的区块链,用于替换旧版本的区块链。In the existing blockchain technology, the software version of the blockchain needs to be upgraded. Every time the version of the blockchain is upgraded, a new version of the blockchain needs to be released to replace the old version of the blockchain.
由于每次区块链的版本升级都是直接将旧版本替换为新版本,中间没有过度期,替换后直接影响区块链的所有用户。如果新旧版本的区块链存在不兼容的问题,那么使用新版本的区块链来处理的交易就会出现错误。Since each version upgrade of the blockchain directly replaces the old version with the new version, there is no transition period in between, and all users of the blockchain are directly affected after the replacement. If there is an incompatibility between the old and new versions of the blockchain, errors will occur in transactions processed using the new version of the blockchain.
因此,如何提前发现新版本与旧版本区块链之间的兼容性问题称为业内亟待解决的问题。Therefore, how to discover the compatibility between the new version and the old version of the blockchain in advance is called an urgent problem to be solved in the industry.
本说明书针对上述问题,提出了一种区块链版本兼容性验证方案。通过该方案可以在新版本正式使用之前预先验证新老版本是否存在兼容性问题。In view of the above problems, this specification proposes a blockchain version compatibility verification scheme. Through this solution, it is possible to pre-verify whether there is a compatibility problem between the old and new versions before the new version is officially used.
请参见图1,图1是一示例性实施例提供的一种区块链版本兼容性验证方法的流程图。所述方法应用于所述区块链中的目标节点设备;其中,所述区块链支持进行软件版本升级。在接收到区块链的最新软件版本,不用马上进行区块链的版本升级,而是可以执行以下步骤:Please refer to FIG. 1 , which is a flowchart of a method for verifying version compatibility of a blockchain provided by an exemplary embodiment. The method is applied to the target node device in the blockchain; wherein, the blockchain supports software version upgrade. After receiving the latest software version of the blockchain, instead of upgrading the blockchain version immediately, you can perform the following steps:
步骤210:获取待验证的历史区块,并从所述历史区块中读取待验证的交易。Step 210: Obtain the historical block to be verified, and read the transaction to be verified from the historical block.
目标节点设备首先可以获取待验证的历史区块,并从所述历史区块中读取待验证的交易。The target node device can first obtain the historical block to be verified, and read the transaction to be verified from the historical block.
其中,所述历史区块可以是预设的历史区块,也可以是用户指定的历史区块。Wherein, the historical block may be a preset historical block or a historical block designated by a user.
以预设的历史区块为例,可以从本地维护的所述区块链的区块数据中读取最新一个的历史区块。Taking a preset historical block as an example, the latest historical block can be read from the block data of the blockchain maintained locally.
以用户指定的历史区块为例,所述获取待验证的历史区块,可以包括:Taking the historical block specified by the user as an example, the obtaining of the historical block to be verified may include:
获取用户指定的待验证的历史区块对应的区块号区间;Obtain the block number range corresponding to the historical block to be verified specified by the user;
从所述区块号区间中读取待验证的历史区块的区块号,并在本地维护的所述区块链的区块数据中读取与所述区块号对应的历史区块。The block number of the historical block to be verified is read from the block number interval, and the historical block corresponding to the block number is read from the block data of the blockchain maintained locally.
其中,所述本地维护的所述区块链的区块数据为预先拷贝至所述目标节点设备的区块数据。为了保证目标节点设备可以正确获取到的历史区块,需要将区块链中最新的区块数据同步到目标节点设备的本地。Wherein, the locally maintained block data of the blockchain is the block data pre-copied to the target node device. In order to ensure that the target node device can correctly obtain the historical blocks, it is necessary to synchronize the latest block data in the blockchain to the local of the target node device.
在一示例性的实施例中,所述目标节点设备包括所述区块链中预设的不参与共识的非共识节点。In an exemplary embodiment, the target node device includes a preset non-consensus node in the blockchain that does not participate in the consensus.
一般的,区块链中的节点可以分为共识节点和非共识节点,所述非共识节点是指不进行共识的区块链节点。其中,共识节点一般用于处理需要进行共识的交易;而非共识节点可以用于处理无需共识的交易。Generally, nodes in a blockchain can be divided into consensus nodes and non-consensus nodes, and the non-consensus nodes refer to blockchain nodes that do not perform consensus. Among them, consensus nodes are generally used to process transactions that require consensus; non-consensus nodes can be used to process transactions that do not require consensus.
而本实施例中第一软件版本和第二软件版本执行的交易为历史区块中的历史交易,这列交易并不需要共识,因此可以将不参与共识的非共识节点作为目标节点设备。如此,不会因为占用共识节点的资源而影响正常交易。In this embodiment, the transactions executed by the first software version and the second software version are historical transactions in the historical block, and this list of transactions does not require consensus, so non-consensus nodes that do not participate in consensus can be used as target node devices. In this way, normal transactions will not be affected by occupying the resources of consensus nodes.
类似的,在有的实施例中,为了不占用区块链中现有的共识节点和非共识节点资源,还可以在所述区块链上新增一个用于验证软件版本兼容性的非共识节点。Similarly, in some embodiments, in order not to occupy the resources of existing consensus nodes and non-consensus nodes in the blockchain, a non-consensus node for verifying software version compatibility may be added to the blockchain. node.
步骤220:基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;以及,基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果;Step 220: Execute the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result; and execute the transaction based on the second software version supported by the blockchain to obtain a second transaction Results of the;
其中,所述第一软件版本可以包括最新软件版本;所述第二软件版本可以包括将所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本之前,所述部分节点设备支持的历史软件版本。Wherein, the first software version may include the latest software version; the second software version may include the grayscale upgrade of the software version supported by some node devices in the blockchain to the latest software version, the Historical software versions supported by some node devices.
目标节点设备在读取到待验证的交易后,可以分别基于最新软件版本和历史软件版本执行相同的待验证的交易。After reading the transaction to be verified, the target node device can execute the same transaction to be verified based on the latest software version and the historical software version respectively.
在一示例性的实施例中,在所述步骤220之前,所述方法还可以包括:In an exemplary embodiment, before the
从所述区块链对应的历史状态数据库中,获取与所述历史区块对应的历史状态数据;其中,与所述历史区块对应的历史状态数据被设置为只读状态;Obtain the historical state data corresponding to the historical block from the historical state database corresponding to the blockchain; wherein, the historical state data corresponding to the historical block is set to a read-only state;
从与所述历史区块对应的历史状态数据中读取与所述交易相关的区块链账户对应的初始账户状态。The initial account state corresponding to the blockchain account associated with the transaction is read from the historical state data corresponding to the historical block.
该示例中,待验证交易被再次执行是为了验证区块链软件版本的兼容性,并非正常的交易执行,因此不管是第一软件版本还是第二软件版本执行该交易的结果都不应该记入状态数据中;不然会导致状态数据的异常。例如,假设待验证交易为账户A向账户B转账,如果允许将执行结果记入状态数据,那么账户A会真的向账户B进行转账,而实际上账户A并未发起转账,从而导致出现重大错误。如此,通过将历史区块对应的历史状态数据设置为只读状态,可以避免步骤220中执行交易后更新历史交易的状态数据。In this example, the transaction to be verified is executed again to verify the compatibility of the blockchain software version, which is not a normal transaction execution. Therefore, the result of executing the transaction in either the first software version or the second software version should not be recorded in the In the status data; otherwise it will cause an exception to the status data. For example, assuming that the transaction to be verified is a transfer from account A to account B, if the execution result is allowed to be recorded in the status data, then account A will actually transfer money to account B, but in fact account A does not initiate the transfer, resulting in a major mistake. In this way, by setting the historical state data corresponding to the historical block to a read-only state, it is possible to avoid updating the state data of the historical transaction after executing the transaction in
在一示例性的实施例中,所述交易执行结果包括执行交易后生成的交易收据;In an exemplary embodiment, the transaction execution result includes a transaction receipt generated after executing the transaction;
所述基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;performing the transaction based on the first software version supported by the blockchain to obtain a first transaction execution result;
基于所述区块链支持的第一软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第一软件版本的第一交易收据;Execute the transaction based on the first software version supported by the blockchain, generate an updated account state corresponding to the initial account state, and generate the transaction corresponding to the initial account state and the updated account state based on the initial account state and the updated account state the first transaction receipt for the first software version;
所述基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果,包括:The execution of the transaction based on the second software version supported by the blockchain to obtain a second transaction execution result includes:
基于所述区块链支持的第二软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第二软件版本的第二交易收据。Execute the transaction based on the second software version supported by the blockchain, generate an updated account state corresponding to the initial account state, and generate the transaction corresponding to the initial account state based on the initial account state and the updated account state and a second transaction receipt for the second software version.
其中,所述目标节点设备搭载了用于记录交易执行结果的服务端口;Wherein, the target node device is equipped with a service port for recording transaction execution results;
在所述将所述第一交易执行结果与所述第二交易执行结果进行匹配之前,还包括:Before the matching of the first transaction execution result with the second transaction execution result, the method further includes:
调用所述服务端口,在本地存储生成的所述第一交易收据和所述第二交易收据。The service port is called to locally store the generated first transaction receipt and the second transaction receipt.
该示例中,所述服务端口可以将交易执行结果以交易收据的形式进行记录。具体可以是将交易收据存储到MPT收据树中。In this example, the service port may record the transaction execution result in the form of a transaction receipt. Specifically, the transaction receipt can be stored in the MPT receipt tree.
值得一提的是,假设将基于所述区块链支持的第一软件版本执行所述交易称为第一次执行交易;而将基于所述区块链支持的第二软件版本执行所述交易称为第二次执行交易。It is worth mentioning that it is assumed that the execution of the transaction based on the first software version supported by the blockchain is called the first execution of the transaction; and the execution of the transaction based on the second software version supported by the blockchain Called the second execution of the transaction.
那么,在第一次执行交易后,并得到第一交易收据后,还需要回滚(rollback)第一次执行的交易,从而将第一次执行交易后的更新账户状态恢复回初始账户状态。这样做的目的是不影响世界状态。Then, after executing the transaction for the first time and obtaining the first transaction receipt, it is necessary to rollback the transaction executed for the first time, so as to restore the updated account state after the first execution of the transaction to the initial account state. The purpose of this is not to affect the state of the world.
由于第一次和第二次执行的是相同的交易,通常区块链在执行交易后会更新交易涉及到的账户状态。如果不回滚第一次执行的交易,那么在第二次执行时,相同交易的初始账户状态就会不同,那么其结果也必然是不同的。因此,通过回滚,使得第一次执行交易不影响世界状态,进而不会影响第二次执行交易的执行结果。Since the same transaction is executed the first time and the second time, usually the blockchain will update the account state involved in the transaction after the transaction is executed. If the transaction executed the first time is not rolled back, then the initial account state of the same transaction will be different on the second execution, and the result must be different. Therefore, through rollback, the first execution of the transaction does not affect the world state, and thus will not affect the execution result of the second executed transaction.
举例说明,假设某个交易是用户A向用户B转账10元,世界状态中用户A的账户余额为100元(初始账户状态),用户B的账户余额为50元(初始账户状态)。For example, suppose a transaction is that user A transfers 10 yuan to user B, the account balance of user A in the world state is 100 yuan (initial account state), and the account balance of user B is 50 yuan (initial account state).
那么,在第一次执行后,世界状态中用户A的账户余额就会变为90元(更新账户状态),而用户B的账户余额就会变为60元(更新账户状态)。Then, after the first execution, user A's account balance in the world state will become 90 yuan (update account state), and user B's account balance will become 60 yuan (update account state).
如果不回滚,那么在第二次执行时,是从用户A的账户余额90元中转账10元到用户B的账户余额60元。而不是最初所要执行的从用户A的账户余额100元中转账10元到用户B的账户余额50元。If it is not rolled back, then in the second execution, 10 yuan is transferred from user A's account balance of 90 yuan to user B's account balance of 60 yuan. Instead of the initial transfer of 10 yuan from user A's account balance of 100 yuan to user B's account balance of 50 yuan.
因此,需要回滚第一次执行的交易,使得世界状态维持在用户A的账户余额为100元,用户B的账户余额为50元。这样,在第二次执行时,就与第一次执行相同,都是从用户A的账户余额100元中转账10元到用户B的账户余额50元。Therefore, it is necessary to roll back the transaction executed for the first time, so that the world state is maintained at user A's account balance of 100 yuan and user B's account balance of 50 yuan. In this way, the second execution is the same as the first execution, which is to transfer 10 yuan from user A's account balance of 100 yuan to user B's account balance of 50 yuan.
值得一提的是,第一软件版本和第二软件版本可能存在版本逻辑的不同。从而在第一软件版本和第二软件版本执行相同交易时产生不同的交易收据。It is worth mentioning that there may be differences in version logic between the first software version and the second software version. Thus, different transaction receipts are generated when the first software version and the second software version perform the same transaction.
依然沿用前述示例,某个交易是用户A向用户B转账10元,世界状态中用户A的账户余额为100元,用户B的账户余额为50元。其中,新版本的区块链需要收取1元的手续费;旧版本的区块链需要收取2元的手续费。Still using the previous example, a transaction is that user A transfers 10 yuan to user B, the account balance of user A in the world state is 100 yuan, and the account balance of user B is 50 yuan. Among them, the new version of the blockchain needs to charge a handling fee of 1 yuan; the old version of the blockchain needs to charge a handling fee of 2 yuan.
那么,在第一次执行交易后,得到的第一交易收据为,从用户A的账户余额100元中提取10元转到用户B的账户余额50元。并且,从用户A的账户余额100中额外提取2元的手续费。即用户A的账户余额剩余88元,用户B的账户余额为60元。Then, after executing the transaction for the first time, the first transaction receipt obtained is that 10 yuan is withdrawn from the account balance of user A of 100 yuan and transferred to the account balance of user B of 50 yuan. In addition, an additional handling fee of 2 yuan is withdrawn from the account balance 100 of user A. That is, user A's account balance remains 88 yuan, and user B's account balance is 60 yuan.
在第二次执行交易后,得到的第二交易收据为,从用户A的账户余额100元中提取10元转到用户B的账户余额50元。并且,从用户A的账户余额100中额外提取1元的手续费。即用户A的账户余额剩余89元,用户B的账户余额为60元。After the second transaction is performed, the second transaction receipt obtained is that 10 yuan is withdrawn from the user A's account balance of 100 yuan and transferred to the user B's account balance of 50 yuan. In addition, an additional handling fee of 1 yuan is withdrawn from the account balance 100 of user A. That is, user A's account balance remains 89 yuan, and user B's account balance is 60 yuan.
可见,分别通过第一软件版本和第二软件版本执行相同交易,会由于版本逻辑差异导致交易收据的不同。It can be seen that when the same transaction is executed through the first software version and the second software version respectively, the transaction receipts will be different due to the logical differences of the versions.
为了解决这一问题,可以为第一软件版本和第二软件版本配置向前兼容的配置文件,所述配置文件包括第一软件版本和第二软件版本中存在差异的逻辑。如此可以弥补软件版本之间的差异。To solve this problem, the first software version and the second software version may be configured with forward compatible configuration files, the configuration files including logic for differences in the first software version and the second software version. This makes up for differences between software versions.
具体地,在第一次执行交易时,目标节点设备可以基于预先配置的配置文件,将第一软件版本和第二软件版本中存在差异的逻辑,替换为相同的逻辑。如此,通过配置文件,弥补新老版本之间的兼容差异,使得分别执行相同交易后不会因为版本逻辑原因导致不同。Specifically, when executing the transaction for the first time, the target node device may replace the logic that is different between the first software version and the second software version with the same logic based on the preconfigured configuration file. In this way, the configuration file is used to make up for the compatibility differences between the old and new versions, so that the same transaction will not be different due to version logic after executing the same transaction.
步骤230:将所述第一交易执行结果与所述第二交易执行结果进行匹配,并基于所述匹配的结果以确定所述第一软件版本与所述第二软件版本是否兼容。Step 230: Match the first transaction execution result with the second transaction execution result, and determine whether the first software version and the second software version are compatible based on the matching result.
目标节点设备在得到第一交易执行结果和第二交易执行结果后,通过将所述第一交易执行结果与所述第二交易执行结果进行匹配,从而基于所述匹配的结果可以确定所述第一软件版本与所述第二软件版本是否兼容。After obtaining the first transaction execution result and the second transaction execution result, the target node device matches the first transaction execution result with the second transaction execution result, so as to determine the first transaction execution result based on the matching result. Whether a software version is compatible with the second software version.
在一示例性的实施例中,所述步骤230,可以包括:In an exemplary embodiment, the
读取所述服务端口记录的所述第一交易收据和所述第二交易收据;reading the first transaction receipt and the second transaction receipt recorded by the service port;
将读取到的所述第一交易收据和所述第二交易收据进行匹配;matching the read first transaction receipt and the second transaction receipt;
如果所述第一交易收据与所述第二交易收据匹配,确定所述第一软件版本与所述第二软件版本兼容;反之,确定所述第一软件版本与所述第二软件版本不兼容。If the first transaction receipt matches the second transaction receipt, it is determined that the first software version is compatible with the second software version; otherwise, it is determined that the first software version is not compatible with the second software version .
该示例中,所述第一交易收据与所述第二交易收据匹配可以是指第一交易收据和第二交易收据相同或一致。In this example, the matching of the first transaction receipt with the second transaction receipt may mean that the first transaction receipt and the second transaction receipt are identical or consistent.
在实际应用总,在将读取到的所述第一交易收据和所述第二交易收据进行匹配时,可以获取所述第一交易收据所在交易收据树的第一根哈希,和所述第二交易收据所在交易收据树的第二根哈希;如果所述第一根哈希和第二根哈希一致,则确认所述第一交易收据和第二交易收据匹配。In practical applications, when matching the read first transaction receipt and the second transaction receipt, the first root hash of the transaction receipt tree where the first transaction receipt is located can be obtained, and the The second root hash of the transaction receipt tree where the second transaction receipt is located; if the first root hash and the second root hash are consistent, it is confirmed that the first transaction receipt and the second transaction receipt match.
如前所述,所述交易收据是位于交易收据树上的,而交易收据树是一颗Merkle树。对于Merkle树来说,其根哈希是由树上所有数据哈希共同计算得到的。树上任意一个数据哈希的不同都会影响最终的根哈希。As mentioned above, the transaction receipt is located on the transaction receipt tree, and the transaction receipt tree is a Merkle tree. For a Merkle tree, the root hash is calculated by all the data hashes in the tree. Any difference in the hash of any data in the tree will affect the final root hash.
因此,在分别由第一软件版本和第二软件版本执行相同交易后,应当具有相同的交易收据树,也就应当具有相同的根哈希。如果两者的根哈希不一致,那么就可以确定两者存在兼容性问题。Therefore, after the same transaction is executed by the first software version and the second software version respectively, there should be the same transaction receipt tree, and thus should have the same root hash. If the root hashes of the two are inconsistent, then it can be determined that there is a compatibility problem between the two.
通过这种方式无需从交易收据树中查找到执行交易的交易收据,直接通过比较交易收据树的根哈希更为快速。In this way, it is faster to compare the root hash of the transaction receipt tree directly without looking up the transaction receipt for the executed transaction from the transaction receipt tree.
在实际应用中,区块链中交易的类型可以包括创建帐号、创建合约、转账、发行资产、赎回资产等不同的类型。每种交易类型的执行都需要版本中相关逻辑的支持。In practical applications, the types of transactions in the blockchain can include account creation, contract creation, transfer, asset issuance, and asset redemption. The execution of each transaction type requires the support of the associated logic in the version.
通过图1所示实施例执行不同的交易类型,可以确定是什么类型的交易在执行什么版本区块链时存在兼容性问题。By executing different transaction types in the embodiment shown in FIG. 1 , it can be determined what type of transaction has compatibility problems when executing what version of the blockchain.
例如,在执行创建帐号交易时,交易收据是相同的,而在执行转账时,交易收据是不同的;那么就可以确定新版本中关于转账的版本逻辑存在兼容性问题。For example, when the account creation transaction is executed, the transaction receipt is the same, but when the transfer is executed, the transaction receipt is different; then it can be determined that there is a compatibility problem with the version logic of the transfer in the new version.
另外,当存在多个历史区块时,不同区块中交易类型也可以是不同的,如此可以验证不同交易类型下区块链软件版本之间是否存在兼容性问题。In addition, when there are multiple historical blocks, the transaction types in different blocks can also be different, so it can be verified whether there is a compatibility problem between the blockchain software versions under different transaction types.
在一示例性的实施例中,当存在多个历史区块时,目标节点设备可以在多线程下并行以第一软件版本执行交易,以及以第二软件版本执行交易。In an exemplary embodiment, when there are multiple historical blocks, the target node device may execute transactions with the first software version and execute transactions with the second software version in parallel under multi-threading.
该示例中,为了快速得到验证结果,可以在多线程下并行执行不同区块的交易;由于执行的区块之间不互相影响,且执行结果也不影响世界状态。相当于各区块处于隔离状态,因此这种多线程并行执行具有可行性,提高了验证速度。In this example, in order to obtain the verification result quickly, transactions of different blocks can be executed in parallel under multi-threading; since the executed blocks do not affect each other, and the execution result does not affect the world state. It is equivalent to the isolation of each block, so this multi-threaded parallel execution is feasible and improves the verification speed.
在一示例性的实施例中,所述区块链支持进行软件版本的灰度升级;所述第二软件版本包括将所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本之前,所述部分节点设备支持的历史软件版本。In an exemplary embodiment, the blockchain supports grayscale upgrade of software versions; the second software version includes grayscale upgrade of the software versions supported by some node devices in the blockchain to all versions. The historical software versions supported by some node devices before the latest software version.
相应地,在所述步骤210之前,还可以包括:Correspondingly, before the
响应于所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本,获取待验证的历史区块,并从所述历史区块中读取待验证的交易。In response to the grayscale upgrade of the software version supported by some node devices in the blockchain to the latest software version, the historical block to be verified is obtained, and the transaction to be verified is read from the historical block.
该示例中,所述灰度升级可以是指一种平滑过渡的升级方式。在灰度升级过程中,先采用A/B testing,即让一部分用户继续使用历史软件版本,一部分用户开始用最新软件版本;如果用户对最新软件版本没有什么反对意见,那么逐渐扩大最新软件版本的使用范围,慢慢将所有用户都迁移到最新软件版本上。In this example, the grayscale upgrade may refer to a smooth transition upgrade manner. In the grayscale upgrade process, A/B testing is used first, that is, some users continue to use the historical software version, and some users start to use the latest software version; if users have no objection to the latest software version, then gradually expand the latest software version. Using scope, slowly migrate all users to the latest software version.
采用灰度升级的方式可以保证整体区块链的稳定运行,在初始灰度升级时就可以发现问题并及时处理,由于初始灰度升级的用户群体较少即使出现问题影响范围也有限。The grayscale upgrade method can ensure the stable operation of the overall blockchain. Problems can be found and dealt with in time during the initial grayscale upgrade. Since the initial grayscale upgrade has fewer user groups, even if the problem occurs, the impact scope is limited.
在一示例性的实施例中,如果确定所述最新软件版本与所述历史软件版本兼容,向所述区块链对应的服务平台发送升级指示,以触发所述服务平台将所述部分节点设备支持的软件版本由所述历史软件版本升级为所述最新软件版本。In an exemplary embodiment, if it is determined that the latest software version is compatible with the historical software version, an upgrade instruction is sent to the service platform corresponding to the blockchain to trigger the service platform to update the part of the node devices. The supported software version is upgraded from the historical software version to the latest software version.
其中,所述服务平台包括用于提供区块链即服务(BaaS,Blockchain as aService)的BaaS平台(也称之为BaaS云)。BaaS平台可以通过为区块链上发生的活动(诸如订阅和通知、用户验证、数据库管理和远程更新),提供预先编写的软件的方式,面向与BaaS平台耦接的客户端侧计算设备,提供简单易用,一键部署,快速验证,灵活可定制的区块链服务,进而可以加速区块链业务应用开发、测试、上线,助力各行业区块链商业应用场景的落地。The service platform includes a BaaS platform (also referred to as a BaaS cloud) for providing Blockchain as a Service (BaaS, Blockchain as a Service). The BaaS platform can target client-side computing devices coupled to the BaaS platform by providing pre-written software for activities that take place on the blockchain, such as subscriptions and notifications, user authentication, database management, and remote updates. Simple and easy to use, one-click deployment, fast verification, flexible and customizable blockchain services, which can accelerate the development, testing, and launch of blockchain business applications, and help the implementation of blockchain business application scenarios in various industries.
与上述方法实施例相对应,本说明书还提供了一种区块链版本兼容性验证装置的实施例。Corresponding to the above method embodiments, this specification also provides an embodiment of a blockchain version compatibility verification device.
本说明书的区块链版本兼容性验证装置的实施例可以应用在电子设备上。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。The embodiments of the blockchain version compatibility verification apparatus of this specification can be applied to electronic equipment. The apparatus embodiment may be implemented by software, or may be implemented by hardware or a combination of software and hardware. Taking software implementation as an example, a device in a logical sense is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the processor of the electronic device where the device is located.
从硬件层面而言,如图2所示,为本说明书的区块链版本兼容性验证装置所在电子设备的一种硬件结构图,除了图2所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的电子设备通常根据该电子设备的实际功能,还可以包括其他硬件,对此不再赘述。From the perspective of hardware, as shown in Figure 2, it is a hardware structure diagram of the electronic device where the blockchain version compatibility verification device of this specification is located, except for the processor, memory, network interface, and non-volatile hardware shown in Figure 2. In addition to the volatile memory, the electronic device in which the apparatus in the embodiment is located generally may also include other hardware according to the actual function of the electronic device, which will not be repeated here.
图3是本说明书一示例性实施例示出的一种区块链版本兼容性验证装置的框图。FIG. 3 is a block diagram of a block chain version compatibility verification apparatus shown in an exemplary embodiment of the present specification.
请参考图3,所述区块链版本兼容性验证装置可以应用在前述图2所示的电子设备中,所述装置应用于所述区块链中的目标节点设备;其中,所述区块链支持进行软件版本升级;所述装置包括:Please refer to FIG. 3 , the blockchain version compatibility verification device can be applied to the electronic equipment shown in the aforementioned FIG. 2 , and the device is applied to the target node device in the blockchain; wherein, the block The chain supports software version upgrades; the device includes:
获取单元310,获取待验证的历史区块,并从所述历史区块中读取待验证的交易;The obtaining
执行单元320,基于所述区块链支持的第一软件版本执行所述交易,得到第一交易执行结果;以及,基于所述区块链支持的第二软件版本执行所述交易,得到第二交易执行结果;The executing
验证单元330,将所述第一交易执行结果与所述第二交易执行结果进行匹配,并基于所述匹配的结果以确定所述第一软件版本与所述第二软件版本是否兼容。The
可选的,在所述执行单元320之前,还包括:Optionally, before the
数据获取子单元,从所述区块链对应的历史状态数据库中,获取与所述历史区块对应的历史状态数据;其中,与所述历史区块对应的历史状态数据被设置为只读状态;从与所述历史区块对应的历史状态数据中读取与所述交易相关的区块链账户对应的初始账户状态。The data acquisition subunit acquires the historical state data corresponding to the historical block from the historical state database corresponding to the blockchain; wherein, the historical state data corresponding to the historical block is set to a read-only state ; Read the initial account state corresponding to the blockchain account related to the transaction from the historical state data corresponding to the historical block.
可选的,所述交易执行结果包括执行交易后生成的交易收据;Optionally, the transaction execution result includes a transaction receipt generated after the transaction is executed;
所述执行单元320,进一步包括:The
第一执行子单元,基于所述区块链支持的第一软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第一软件版本的第一交易收据;a first execution subunit that executes the transaction based on the first software version supported by the blockchain, generates an updated account state corresponding to the initial account state, and generates an updated account state based on the initial account state and the updated account state the transaction corresponds to a first transaction receipt for the first software version;
第二执行子单元,基于所述区块链支持的第二软件版本执行所述交易,生成针对所述初始账户状态对应的更新账户状态,并基于所述初始账户状态和所述更新账户状态生成所述交易对应于所述第二软件版本的第二交易收据。The second execution subunit executes the transaction based on the second software version supported by the blockchain, generates an updated account state corresponding to the initial account state, and generates an updated account state based on the initial account state and the updated account state The transaction corresponds to a second transaction receipt for the second software version.
可选的,所述目标节点设备搭载了用于记录交易执行结果的服务端口;Optionally, the target node device is equipped with a service port for recording transaction execution results;
在所述验证单元330之前,还包括:Before the
调用单元,调用所述服务端口,在本地存储生成的所述第一交易收据和所述第二交易收据。The calling unit calls the service port to locally store the generated first transaction receipt and the second transaction receipt.
可选的,所述验证单元330,进一步包括:Optionally, the
读取子单元,读取所述服务端口记录的所述第一交易收据和所述第二交易收据;a reading subunit, to read the first transaction receipt and the second transaction receipt recorded by the service port;
匹配子单元,将读取到的所述第一交易收据和所述第二交易收据进行匹配;a matching subunit, which matches the read first transaction receipt and the second transaction receipt;
确定子单元,如果所述第一交易收据与所述第二交易收据匹配,确定所述第一软件版本与所述第二软件版本兼容;反之,确定所述第一软件版本与所述第二软件版本不兼容。A determination subunit, if the first transaction receipt matches the second transaction receipt, determine that the first software version is compatible with the second software version; otherwise, determine that the first software version is compatible with the second software version Incompatible software version.
可选的,所述获取单元310,进一步包括:获取用户指定的待验证的历史区块对应的区块号区间,从所述区块号区间中读取待验证的历史区块的区块号,并在本地维护的所述区块链的区块数据中读取与所述区块号对应的历史区块。Optionally, the obtaining
可选的,所述本地维护的所述区块链的区块数据为预先拷贝至所述目标节点设备的区块数据。Optionally, the locally maintained block data of the blockchain is the block data copied to the target node device in advance.
可选的,所述区块链支持进行软件版本的灰度升级;所述第一软件版本包括最新软件版本;所述第二软件版本包括将所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本之前,所述部分节点设备支持的历史软件版本。Optionally, the blockchain supports grayscale upgrade of software versions; the first software version includes the latest software version; the second software version includes software that supports some node devices in the blockchain. The version is the historical software version supported by some node devices before the grayscale upgrade is to the latest software version.
可选的,在所述获取单元310之前,还包括:Optionally, before the obtaining
响应单元,响应于所述区块链中的部分节点设备支持的软件版本灰度升级为所述最新软件版本,获取待验证的历史区块,并从所述历史区块中读取待验证的交易。The response unit, in response to the grayscale upgrade of the software version supported by some node devices in the blockchain to the latest software version, obtains the historical block to be verified, and reads the historical block to be verified from the historical block. trade.
可选的,所述装置还包括:Optionally, the device further includes:
处理单元,如果确定所述最新软件版本与所述历史软件版本兼容,向所述区块链对应的服务平台发送升级指示,以触发所述服务平台将所述部分节点设备支持的软件版本由所述历史软件版本升级为所述最新软件版本。The processing unit, if it is determined that the latest software version is compatible with the historical software version, sends an upgrade instruction to the service platform corresponding to the blockchain, so as to trigger the service platform to change the software version supported by the part of the node device from the The historical software version is upgraded to the latest software version.
可选的,所述服务平台包括Bass平台。Optionally, the service platform includes a Bass platform.
可选的,所述目标节点设备包括所述区块链中预设的不参与共识的非共识节点。Optionally, the target node device includes a preset non-consensus node in the blockchain that does not participate in the consensus.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules or units described in the above embodiments may be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, e-mail device, game control desktop, tablet, wearable device, or a combination of any of these devices.
在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computer includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-persistent memory in computer readable media, random access memory (RAM) and/or non-volatile memory in the form of, for example, read only memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes both persistent and non-permanent, removable and non-removable media, and storage of information may be implemented by any method or technology. Information may be computer readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), Flash Memory or other memory technology, Compact Disc Read Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic tape cartridges, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the terms "comprising", "comprising" or any other variation thereof are intended to encompass a non-exclusive inclusion such that a process, method, article or device comprising a series of elements includes not only those elements, but also Other elements not expressly listed, or which are inherent to such a process, method, article of manufacture, or apparatus are also included. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, article of manufacture, or device that includes the element.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实现方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments and still achieve desirable results. Additionally, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some implementations, multitasking and parallel processing are also possible or may be advantageous.
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。The terminology used in one or more embodiments of this specification is for the purpose of describing a particular embodiment only and is not intended to limit the one or more embodiments of this specification. As used in the specification or embodiments and the appended claims, the singular forms "a," "the," and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It will also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It will be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, such information should not be limited by these terms. These terms are only used to distinguish the same type of information from each other. For example, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information without departing from the scope of one or more embodiments of the present specification. Depending on the context, the word "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determining."
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。The above descriptions are only preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. All within the spirit and principles of one or more embodiments of this specification, Any modifications, equivalent replacements, improvements, etc. made should be included within the protection scope of one or more embodiments of this specification.
Claims (14)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210473975.0A CN114816509A (en) | 2022-04-29 | 2022-04-29 | Blockchain version compatibility verification method and device, electronic device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210473975.0A CN114816509A (en) | 2022-04-29 | 2022-04-29 | Blockchain version compatibility verification method and device, electronic device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114816509A true CN114816509A (en) | 2022-07-29 |
Family
ID=82510566
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210473975.0A Pending CN114816509A (en) | 2022-04-29 | 2022-04-29 | Blockchain version compatibility verification method and device, electronic device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114816509A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116755747A (en) * | 2023-08-16 | 2023-09-15 | 深圳市德兰明海新能源股份有限公司 | Software development and upgrade management method and device and electronic equipment |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112835605A (en) * | 2021-03-30 | 2021-05-25 | 中国工商银行股份有限公司 | Block chain version gray scale upgrading verification method, device and system |
CN114281388A (en) * | 2021-12-30 | 2022-04-05 | 杭州溪塔科技有限公司 | Method and system for data compatibility during block chain upgrading |
-
2022
- 2022-04-29 CN CN202210473975.0A patent/CN114816509A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112835605A (en) * | 2021-03-30 | 2021-05-25 | 中国工商银行股份有限公司 | Block chain version gray scale upgrading verification method, device and system |
CN114281388A (en) * | 2021-12-30 | 2022-04-05 | 杭州溪塔科技有限公司 | Method and system for data compatibility during block chain upgrading |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116755747A (en) * | 2023-08-16 | 2023-09-15 | 深圳市德兰明海新能源股份有限公司 | Software development and upgrade management method and device and electronic equipment |
CN116755747B (en) * | 2023-08-16 | 2023-10-24 | 深圳市德兰明海新能源股份有限公司 | Software development and upgrade management method and device and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
TWI731595B (en) | Block chain state data storage method and device, and electronic equipment | |
WO2021017421A1 (en) | Blockchain state data recovery method and device, and electronic device | |
CN110493325B (en) | Block chain state data synchronization method and device and electronic equipment | |
US11113272B2 (en) | Method and apparatus for storing blockchain state data and electronic device | |
US10956444B2 (en) | Block chain state data synchronization method, apparatus, and electronic device | |
CN111898139B (en) | Data reading and writing method and device and electronic equipment | |
US11361054B2 (en) | Blockchain-based infringement detection method, apparatus, and electronic device | |
WO2021017438A1 (en) | Blockchain-based electronic bill cancellation method and apparatus, and electronic device | |
CN110032598B (en) | Method and device for updating field and electronic equipment | |
WO2020258853A1 (en) | Blockchain-based hierarchical storage method and apparatus, and electronic device | |
US11386054B2 (en) | Blockchain-based hierarchical data storage | |
WO2022077186A1 (en) | Execution method and apparatus for smart contract in blockchain, and electronic device | |
TWI724570B (en) | Method, device, electronic equipment and storage medium for reading and updating data structure | |
WO2021017439A1 (en) | Block chain-based electronic bill number application method and apparatus, and electronic device | |
WO2021017442A1 (en) | Method and device for electronic negotiable instrument reimbursement based on blockchain, and electronic device | |
US10846765B2 (en) | Blockchain-based e-bill number application method, apparatus, and electronic device | |
US11036720B2 (en) | Blockchain-based hierarchical data storage | |
US11288247B2 (en) | Blockchain based hierarchical data storage | |
US20200279309A1 (en) | Blockchain-based electronic bill cancellation method, apparatus, and electronic device | |
CN114816509A (en) | Blockchain version compatibility verification method and device, electronic device | |
WO2024021417A1 (en) | Data account creation method and apparatus | |
CN115203746A (en) | Data account access authorization method and device | |
HK40017471B (en) | Block chain state data storage method and device and electronic equipment | |
HK40017471A (en) | Block chain state data storage method and device and electronic equipment | |
CN115098886A (en) | Access authorization method and device of intelligent contract |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |