











技术领域technical field
本公开涉及区块链技术领域,具体而言,涉及一种基于区块链的数据处理方法、节点设备、终端设备、电子设备及计算机可读介质。The present disclosure relates to the technical field of block chains, in particular, to a data processing method based on block chains, node devices, terminal devices, electronic devices, and computer-readable media.
背景技术Background technique
区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。在分布式的节点系统中,由节点竞争获得当前处理数据的权力,作为区块生成节点;生成的区块再经过其他节点的验证确认后,再进行存储。上述运行机制使得区块链中记录在区块内的数据几乎不可能被篡改。Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm. In a distributed node system, nodes compete to obtain the right to process data as block generation nodes; the generated blocks are verified and confirmed by other nodes before being stored. The above operating mechanism makes it almost impossible for the data recorded in the block to be tampered with in the blockchain.
在业务场景中,常常出现业务方对幂等性的要求。例如,在支付场景中,用户购买商品后支付,支付扣款成功,但结果返回时网络异常导致用户以为未成功支付,一旦用户重复提交支付请求后,会发生针对同一笔订单进行第二次扣款的情况。In business scenarios, business parties often require idempotency. For example, in the payment scenario, the user pays after purchasing the product, and the payment deduction is successful, but when the result is returned, the network exception causes the user to think that the payment has not been successful. Once the user submits the payment request repeatedly, a second deduction will occur for the same order. payment situation.
在实际场景中,由于区块链响应延迟,可能出现业务方重复提交同一个业务的多笔交易请求,由于时间戳不一致等导致每笔交易的hash(哈希)值不一致,但是业务参数一致,区块链识别为多笔不同的业务请求,导致幂等性问题。幂等性是指分布式环境下,用户对于同一操作发起的一次或多次请求的结果是一致的,不会因为多次点击而产生副作用。In actual scenarios, due to the delayed response of the blockchain, the business party may repeatedly submit multiple transaction requests for the same business. Due to inconsistent timestamps, the hash (hash) value of each transaction is inconsistent, but the business parameters are consistent. The blockchain identifies multiple different business requests, leading to idempotency issues. Idempotency means that in a distributed environment, the results of one or more requests initiated by the user for the same operation are consistent, and there will be no side effects due to multiple clicks.
因此,需要一种新的基于区块链的数据处理方法、节点设备、终端设备、电子设备及计算机可读介质。Therefore, a new blockchain-based data processing method, node device, terminal device, electronic device, and computer-readable medium are needed.
发明内容Contents of the invention
本公开实施例提供一种基于区块链的数据处理方法、装置、电子设备及计算机可读介质,进而至少在一定程度上解决相关技术中存在于区块链中的幂等性问题。Embodiments of the present disclosure provide a block chain-based data processing method, device, electronic device, and computer-readable medium, thereby solving the idempotence problem existing in block chains in related technologies at least to a certain extent.
本公开实施例提出一种基于区块链的数据处理方法,所述方法应用于区块链网络中的节点设备,所述区块链网络中部署智能合约,所述智能合约用于维护交易执行表,所述方法包括:获取第一请求方的终端设备发送的第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数;调用所述智能合约生成所述第一传入参数的第一传参哈希值;调用所述智能合约将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配;将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,所述目标交易哈希值与所述第一交易请求的第一交易哈希值不同。The embodiment of the present disclosure proposes a blockchain-based data processing method, the method is applied to node devices in the blockchain network, and smart contracts are deployed in the blockchain network, and the smart contracts are used to maintain transaction execution Table, the method includes: obtaining the first transaction request sent by the terminal device of the first requesting party, the first transaction request carrying the identification of the first business party, the information of the first requesting party and the information used to execute the first transaction request the first incoming parameter; call the smart contract to generate the first passed parameter hash value of the first incoming parameter; call the smart contract to pass the first business party ID, the first requester Match the first reference hash value with the transaction execution table; match the transaction execution table with the first business party identifier, the first requestor information, and the first reference hash value A target transaction execution result and a target transaction hash value whose values match are returned to the terminal device of the first requesting party, and the target transaction hash value is different from the first transaction hash value of the first transaction request.
本公开实施例提出一种基于区块链的数据处理方法,所述方法应用于与区块链网络通信的终端设备,所述区块链网络中部署智能合约,所述智能合约用于维护交易执行表。其中,所述方法包括:通过第一请求方的终端设备生成第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数;通过所述第一请求方的终端设备生成所述第一交易请求的第一交易哈希值;通过所述第一请求方的终端设备向所述区块链网络中的节点设备发送所述第一交易请求,以便所述节点设备调用所述智能合约生成所述第一传入参数的第一传参哈希值,将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配;接收所述节点设备返回的目标交易执行结果和目标交易哈希值,其中所述交易执行表中的所述目标交易执行结果和所述目标交易哈希值与目标业务方标识与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配;确定所述目标交易哈希值与所述第一交易哈希值不同。The embodiment of the present disclosure proposes a blockchain-based data processing method, the method is applied to a terminal device communicating with a blockchain network, and a smart contract is deployed in the blockchain network, and the smart contract is used to maintain transactions Execution table. Wherein, the method includes: generating a first transaction request through the terminal device of the first requesting party, the first transaction request carrying the first business party identification, the first requesting party information and the information used to execute the first transaction request The first incoming parameter; generate the first transaction hash value of the first transaction request through the terminal device of the first requesting party; send the first transaction hash value to the block chain network through the terminal device of the first requesting party The node device sends the first transaction request, so that the node device invokes the smart contract to generate the first parameter hash value of the first incoming parameter, and the first business party identifier, the first The requester information and the hash value of the first parameter are matched with the transaction execution table; receiving the target transaction execution result and the target transaction hash value returned by the node device, wherein the target in the transaction execution table The transaction execution result and the target transaction hash value match the target business party ID with the first business party ID, the first requester information, and the first parameter hash value; determine the target transaction hash value The hash value is different from the first transaction hash value.
本公开实施例提出一种节点设备,所述节点设备设置于区块链网络中,所述区块链网络中部署智能合约,所述智能合约用于维护交易执行表。其中,所述节点设备包括:第一交易请求获取单元,用于获取第一请求方的终端设备发送的第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数;第一传参哈希值生成单元,用于调用所述智能合约生成所述第一传入参数的第一传参哈希值;交易执行表匹配单元,用于调用所述智能合约将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配;目标交易执行结果返回单元,用于将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,所述目标交易哈希值与所述第一交易请求的第一交易哈希值不同。An embodiment of the present disclosure proposes a node device, the node device is set in a blockchain network, a smart contract is deployed in the blockchain network, and the smart contract is used to maintain a transaction execution table. Wherein, the node device includes: a first transaction request obtaining unit, configured to obtain the first transaction request sent by the terminal device of the first requesting party, the first transaction request carrying the first business party identification, the first requesting party information and the first incoming parameter used to execute the first transaction request; the first passed parameter hash value generation unit is used to call the smart contract to generate the first passed parameter hash value of the first incoming parameter ; The transaction execution table matching unit is used to call the smart contract to match the first business party identification, the first requester information and the first passed parameter hash value with the transaction execution table; the target transaction An execution result returning unit, configured to match the target transaction execution result and the target transaction hash value in the transaction execution table with the first business party identifier, the first requester information, and the first parameter hash value The hash value is returned to the terminal device of the first requesting party, and the target transaction hash value is different from the first transaction hash value of the first transaction request.
本公开实施例提出一种终端设备,所述终端设备与区块链网络通信,所述区块链网络中部署智能合约,所述智能合约用于维护交易执行表。其中,所述终端设备包括:第一交易请求生成单元,用于通过第一请求方的终端设备生成第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数;第一交易哈希值生成单元,用于通过所述第一请求方的终端设备生成所述第一交易请求的第一交易哈希值;第一交易请求发送单元,用于通过所述第一请求方的终端设备向所述区块链网络中的节点设备发送所述第一交易请求,以便所述节点设备调用所述智能合约生成所述第一传入参数的第一传参哈希值,将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配;目标交易执行结果接收单元,用于接收所述节点设备返回的目标交易执行结果和目标交易哈希值,其中所述目标交易执行结果和所述目标交易哈希值与所述交易执行表中的目标业务方标识、目标请求方信息和目标传参哈希值对应,所述交易执行表中的目标业务方标识、目标请求方信息和目标传参哈希值分别与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配;目标交易哈希值确定单元,用于确定所述目标交易哈希值与所述第一交易哈希值不同。An embodiment of the present disclosure proposes a terminal device, the terminal device communicates with a blockchain network, a smart contract is deployed in the blockchain network, and the smart contract is used to maintain a transaction execution table. Wherein, the terminal device includes: a first transaction request generating unit, configured to generate a first transaction request through the terminal device of the first requesting party, the first transaction request carrying the first business party identification, the first requesting party information and The first incoming parameter for executing the first transaction request; the first transaction hash value generation unit, configured to generate the first transaction hash of the first transaction request through the terminal device of the first requester value; a first transaction request sending unit, configured to send the first transaction request to the node device in the blockchain network through the terminal device of the first requester, so that the node device calls the smart contract Generate a first passed parameter hash value of the first passed parameter, and match the first business party identifier, the first requester information, and the first passed parameter hash value with the transaction execution table a target transaction execution result receiving unit, configured to receive the target transaction execution result and the target transaction hash value returned by the node device, wherein the target transaction execution result and the target transaction hash value are the same as those in the transaction execution table The target business party ID, target requester information, and target parameter hash value correspond to the target business party ID, target requester information, and target parameter hash value in the transaction execution table, respectively. The identification, the first requester information, and the first reference hash value match; a target transaction hash value determining unit is configured to determine that the target transaction hash value is different from the first transaction hash value.
本公开实施例提出一种电子设备,包括:至少一个处理器;存储装置,用于存储至少一个程序,当所述至少一个程序被所述至少一个处理器执行时,使得所述至少一个处理器实现如上述实施例中所述的基于区块链的数据处理方法。An embodiment of the present disclosure proposes an electronic device, including: at least one processor; a storage device for storing at least one program, and when the at least one program is executed by the at least one processor, the at least one processor Realize the data processing method based on block chain as described in the above-mentioned embodiment.
本公开实施例提出一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现如上述实施例中所述的基于区块链的数据处理方法。Embodiments of the present disclosure propose a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the blockchain-based data processing method as described in the foregoing embodiments is implemented.
根据本申请的一个方面,提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行上述各种可选实现方式中提供的基于区块链的数据处理方法。According to an aspect of the present application there is provided a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the blockchain-based data processing method provided in the various optional implementations above.
在本公开的一些实施例所提供的技术方案中,一方面,通过在区块链网络中部署用于维护交易执行表的智能合约,当区块链网络中的节点设备接收到第一请求方的终端设备发送的第一交易请求时,可以根据第一交易请求携带的第一业务方标识、第一请求方信息和用于执行第一交易请求的第一传入参数查询智能合约维护的交易执行表,若判定交易执行表与第一传入参数的第一传参哈希值、第一业务方标识和第一请求方信息匹配,则节点设备可以确定与该第一交易请求相同的业务在此之前已经被成功执行过,此时,节点设备不执行该第一交易请求,而是将交易执行表中所述第一业务方标识、第一请求方信息和第一传参哈希值匹配的目标交易执行结果和目标交易哈希值直接返回至第一请求方的终端设备,从而可以避免节点设备重复执行相同的业务,确保针对相同业务的交易操作不会被重复执行,确保业务执行的幂等性,即通过智能合约维护的交易执行表可以保证存在多笔相同业务提交的多笔不同交易请求并发提交时,也只有一笔业务能够执行成功。另一方面,接收到目标交易执行结果和目标交易哈希值的第一请求方的终端设备,可以通过判定目标交易哈希值与第一交易请求的第一交易哈希值不同来获知与该第一交易请求相同的业务之前已经被成功执行过。In the technical solutions provided by some embodiments of the present disclosure, on the one hand, by deploying the smart contract for maintaining the transaction execution table in the blockchain network, when the node device in the blockchain network receives the first request When the first transaction request is sent by the terminal device, the transaction maintained by the smart contract can be queried according to the first business party ID carried in the first transaction request, the first requester information, and the first incoming parameters used to execute the first transaction request Execution table, if it is determined that the transaction execution table matches the first parameter hash value of the first incoming parameter, the first business party ID and the first requester information, the node device can determine the same business as the first transaction request It has been successfully executed before. At this time, the node device does not execute the first transaction request, but the first business party ID, first requester information, and first parameter hash value in the transaction execution table The matching target transaction execution result and the target transaction hash value are directly returned to the terminal device of the first requester, thereby avoiding repeated execution of the same business by the node device, ensuring that the transaction operation for the same business will not be executed repeatedly, and ensuring business execution The idempotence, that is, the transaction execution table maintained by the smart contract can guarantee that when there are multiple different transaction requests submitted by the same business concurrently, only one business can be executed successfully. On the other hand, the terminal device of the first requesting party that receives the target transaction execution result and the target transaction hash value can know that the target transaction hash value is different from the first transaction hash value of the first transaction request. The first transaction requests the same business which has been successfully executed before.
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本公开。It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.
附图说明Description of drawings
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本公开的实施例,并与说明书一起用于解释本公开的原理。显而易见地,下面描述中的附图仅仅是本公开的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description serve to explain the principles of the disclosure. Apparently, the drawings in the following description are only some embodiments of the present disclosure, and those skilled in the art can obtain other drawings according to these drawings without creative efforts.
图1是本公开实施例提供的一种基于区块链的数据处理系统的架构示意图。FIG. 1 is a schematic diagram of the architecture of a blockchain-based data processing system provided by an embodiment of the present disclosure.
图2是本公开实施例提供的一种区块链网络的示意图。Fig. 2 is a schematic diagram of a blockchain network provided by an embodiment of the present disclosure.
图3是本公开实施例提供的一种区块的结构示意图。Fig. 3 is a schematic structural diagram of a block provided by an embodiment of the present disclosure.
图4是本公开实施例提供的一种新区块产生过程的示意图。Fig. 4 is a schematic diagram of a new block generation process provided by an embodiment of the present disclosure.
图5示意性示出了根据本公开的一个实施例的基于区块链的数据处理方法的流程图。Fig. 5 schematically shows a flowchart of a blockchain-based data processing method according to an embodiment of the present disclosure.
图6示意性示出了根据本公开的另一个实施例的基于区块链的数据处理方法的流程图。Fig. 6 schematically shows a flow chart of a blockchain-based data processing method according to another embodiment of the present disclosure.
图7示意性示出了根据本公开的一个实施例的基于区块链的数据处理方法的流程示意图。Fig. 7 schematically shows a schematic flowchart of a blockchain-based data processing method according to an embodiment of the present disclosure.
图8示意性示出了根据本公开的又一个实施例的基于区块链的数据处理方法的流程图。Fig. 8 schematically shows a flowchart of a blockchain-based data processing method according to yet another embodiment of the present disclosure.
图9示意性示出了根据本公开的再一个实施例的基于区块链的数据处理方法的流程图。Fig. 9 schematically shows a flowchart of a blockchain-based data processing method according to yet another embodiment of the present disclosure.
图10示意性示出了根据本公开的一实施例的节点设备的框图。Fig. 10 schematically shows a block diagram of a node device according to an embodiment of the present disclosure.
图11示意性示出了根据本公开的一实施例的终端设备的框图。Fig. 11 schematically shows a block diagram of a terminal device according to an embodiment of the present disclosure.
图12示出了适于用来实现本公开实施例的电子设备的结构示意图。FIG. 12 shows a schematic structural diagram of an electronic device suitable for implementing the embodiments of the present disclosure.
具体实施方式detailed description
现在将参考附图更全面地描述示例实施方式。然而,示例实施方式能够以多种形式实施,且不应被理解为限于在此阐述的范例;相反,提供这些实施方式使得本公开将更加全面和完整,并将示例实施方式的构思全面地传达给本领域的技术人员。Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete and will fully convey the concept of example embodiments to those skilled in the art.
此外,所描述的特征、结构或特性可以以任何合适的方式结合在一个或更多实施例中。在下面的描述中,提供许多具体细节从而给出对本公开的实施例的充分理解。然而,本领域技术人员将意识到,可以实践本公开的技术方案而没有特定细节中的一个或更多,或者可以采用其它的方法、组元、装置、步骤等。在其它情况下,不详细示出或描述公知方法、装置、实现或者操作以避免模糊本公开的各方面。Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided in order to give a thorough understanding of embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, means, steps, etc. may be employed. In other instances, well-known methods, apparatus, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the present disclosure.
附图中所示的方框图仅仅是功能实体,不一定必须与物理上独立的实体相对应。即,可以采用软件形式来实现这些功能实体,或在至少一个硬件模块或集成电路中实现这些功能实体,或在不同网络和/或处理器装置和/或微控制器装置中实现这些功能实体。The block diagrams shown in the drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, or in at least one hardware module or integrated circuit, or in different network and/or processor means and/or microcontroller means.
附图中所示的流程图仅是示例性说明,不是必须包括所有的内容和操作/步骤,也不是必须按所描述的顺序执行。例如,有的操作/步骤还可以分解,而有的操作/步骤可以合并或部分合并,因此实际执行的顺序有可能根据实际情况改变。The flow charts shown in the drawings are only exemplary illustrations, and do not necessarily include all contents and operations/steps, nor must they be performed in the order described. For example, some operations/steps can be decomposed, and some operations/steps can be combined or partly combined, so the actual order of execution may be changed according to the actual situation.
本公开实施例所涉及的区块链(blockchain或block chain)是一种分布式数据存储、点对点(Peer to Peer,P2P)传输、共识机制、加密算法等计算机技术的新型应用模式,其本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层;区块链可由多个借由密码学串接并保护内容的串连交易记录(又称区块)构成,用区块链所串接的分布式账本能让多方有效记录交易,且可永久查验此交易(不可篡改)。其中,共识机制是指区块链网络中实现不同节点之间建立信任、获取权益的数学算法,即共识机制是区块链各网络节点共同认可的一种数学算法。The blockchain (blockchain or block chain) involved in the embodiments of the present disclosure is a new application mode of computer technologies such as distributed data storage, point-to-point (Peer to Peer, P2P) transmission, consensus mechanism, and encryption algorithm. It is a decentralized database, which is a series of data blocks associated with cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate next block. The blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer; the blockchain can be composed of multiple concatenated transaction records (also known as blocks) that are connected and protected by cryptography. The distributed ledger connected by the block chain allows multiple parties to effectively record transactions, and this transaction can be permanently verified (not tamperable). Among them, the consensus mechanism refers to the mathematical algorithm that realizes the establishment of trust between different nodes and the acquisition of rights and interests in the blockchain network, that is, the consensus mechanism is a mathematical algorithm commonly recognized by all network nodes of the blockchain.
如图1所示,本公开实施例提供的基于区块链的数据处理系统可以包括区块链网络100及多个终端设备,图1中以包括三个终端设备为例,分别为第一终端201、第二终端202和第三终端203。其中,第一终端201、第二终端202和第三终端203可用于从区块链网络获取交易数据(包括交易请求或者执行交易请求后生成的交易数据),或向区块链网络上传交易数据。As shown in Figure 1, the blockchain-based data processing system provided by the embodiment of the present disclosure may include a blockchain network 100 and multiple terminal devices. In Figure 1, three terminal devices are taken as an example, respectively the first terminal 201, a second terminal 202 and a third terminal 203. Among them, the first terminal 201, the second terminal 202 and the third terminal 203 can be used to obtain transaction data (including transaction requests or transaction data generated after executing transaction requests) from the blockchain network, or upload transaction data to the blockchain network .
如图2所示,图1实施例中的区块链网络100中可以包括多个节点设备101,多个节点设备101可以是指区块链网络中各个客户端,区块链网络100是指用于进行节点设备101与节点设备101之间数据共享的系统。每个节点设备101在进行正常工作时可以接收到交易数据,并基于接收到的交易数据维护该区块链网络100内的共享数据。为了保证区块链网络100内的信息互通,区块链网络100中的每个节点设备101之间可以存在信息连接,节点设备101之间可以通过上述信息连接进行信息传输。例如,当区块链网络100中的任意节点设备101接收到交易数据时,区块链网络100中的其他节点设备101便根据共识算法获取该交易数据,将该交易数据作为共享数据中的数据进行存储,使得区块链网络100中全部节点设备101上存储的数据均一致。As shown in Figure 2, the blockchain network 100 in the embodiment of Figure 1 may include
其中,区块链网络100中的节点设备101、第一终端201、第二终端202和第三终端203可以为任意的电子设备,包括但不限于手机、平板电脑、笔记本电脑、掌上电脑、智能音响、移动互联网设备(mobile internet device,MID)、POS(Point Of Sales,销售点)机、可穿戴设备(例如智能手表、智能手环等);还可以是一台独立的服务器、或由若干台服务器组成的服务器集群、或云计算中心。Among them, the
对于区块链网络100中的每个节点设备101,均具有与其对应的节点设备标识,而且区块链网络100中的每个节点设备101均可以存储有区块链网络100中其他节点设备101的节点设备标识,以便后续根据其他节点设备101的节点设备标识,将生成的区块广播至区块链网络100中的其他节点设备101。每个节点设备101中可维护一个如下表1所示的节点设备标识列表,将节点设备名称和节点设备标识对应存储至该节点设备标识列表中。其中,节点设备标识可为IP(Internet Protocol,网络之间互联的协议)地址以及其他任一种能够用于标识该节点设备的信息,表1中仅以IP地址为例进行说明。其中N为大于或等于1的正整数。For each
表1Table 1
区块链网络100中的每个节点设备101均存储一条相同的区块链。区块链由多个区块组成,每一个区块包含了前一个区块的加密散列(可以用默克尔树(Merkle tree)算法计算的散列值表示)、相应时间戳以及交易数据,这样的设计使得区块内容具有难以篡改的特性。Each
参见图3,区块链由多个区块组成,创始块中包括区块头和区块主体,区块头中存储有交易数据特征值、版本号、时间戳和难度值,区块主体中存储有交易数据;创始块的下一区块以创始块为父区块,下一区块中同样包括区块头和区块主体,区块头中存储有当前区块的交易数据特征值、父区块的区块头特征值、版本号、时间戳和难度值,并以此类推,使得区块链中每个区块中存储的区块数据均与父区块中存储的区块数据存在关联,保证了区块中交易数据的安全性。Referring to Figure 3, the blockchain is composed of multiple blocks. The genesis block includes a block header and a block body. The block header stores transaction data characteristic values, version numbers, timestamps, and difficulty values. The block body stores Transaction data; the next block of the genesis block takes the genesis block as the parent block, and the next block also includes the block header and block body. The block header stores the transaction data characteristic value of the current block, the parent block’s The block header feature value, version number, timestamp and difficulty value, and so on, make the block data stored in each block in the blockchain related to the block data stored in the parent block, ensuring Security of transaction data in blocks.
在生成区块链中的各个区块时,参见图4,区块链所在的节点设备在接收到交易数据时,对交易数据进行校验,完成校验后,将交易数据存储至内存池中,并更新其用于记录交易数据的哈希树;之后,将更新时间戳更新为接收到交易数据的时间,并尝试不同的随机数,多次进行特征值计算,使得计算得到的特征值可以满足下述公式:When generating each block in the blockchain, see Figure 4. When the node device where the blockchain is located receives the transaction data, it verifies the transaction data. After the verification is completed, the transaction data is stored in the memory pool , and update the hash tree used to record the transaction data; after that, update the update timestamp to the time when the transaction data is received, try different random numbers, and perform eigenvalue calculations multiple times, so that the calculated eigenvalues can be satisfy the following formula:
SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET (1)SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET (1)
其中,SHA256为计算特征值所用的特征值算法;version(版本号)为区块链中相关区块协议的版本信息;prev_hash为当前区块的父区块的区块头特征值;merkle_root为交易数据的特征值;ntime为更新时间戳的更新时间;nbits为当前难度,在一段时间内为定值,并在超出固定时间段后再次进行确定;x为随机数;TARGET为特征值阈值,该特征值阈值可以根据nbits确定得到。Among them, SHA256 is the eigenvalue algorithm used to calculate the eigenvalue; version (version number) is the version information of the relevant block protocol in the blockchain; prev_hash is the block header eigenvalue of the parent block of the current block; merkle_root is the transaction data ntime is the update time of the update timestamp; nbits is the current difficulty, which is a fixed value for a period of time, and will be determined again after a fixed period of time; x is a random number; TARGET is the threshold of the feature value, the feature The value threshold can be determined according to nbits.
这样,当计算得到满足上述公式的随机数时,便可将信息对应存储,生成区块头和区块主体,得到当前区块。随后,区块链所在节点设备根据区块链网络100中其他节点设备的节点设备标识,将新生成的区块分别发送给其所在的区块链网络100中的其他节点设备,由其他节点设备对新生成的区块进行校验,并在完成校验后将新生成的区块添加至其存储的区块链中。In this way, when the random number satisfying the above formula is calculated, the information can be stored correspondingly, the block header and block body are generated, and the current block is obtained. Subsequently, according to the node device identifiers of other node devices in the blockchain network 100, the node device where the blockchain is located sends the newly generated blocks to other node devices in the blockchain network 100 where it is located, and the other node devices Verify the newly generated block, and add the newly generated block to its stored blockchain after the verification is completed.
图5示意性示出了根据本公开的一个实施例的基于区块链的数据处理方法的流程图。本公开实施例所提供的方法可以由任意具备计算处理能力的电子设备处理,例如上述图2实施例中的任意节点设备101。Fig. 5 schematically shows a flowchart of a blockchain-based data processing method according to an embodiment of the present disclosure. The method provided by the embodiments of the present disclosure may be processed by any electronic device with computing processing capability, for example, any
图5实施例中,以所提供的方法应用于区块链网络100中的节点设备101为例,区块链网络100中部署智能合约,该智能合约可用于维护交易执行表,该交易执行表中用于记录历史上执行成功的交易的相关信息,以用于对重复接收到的针对同一业务的交易请求进行去重,防止同一业务被重复执行,保证幂等性。In the embodiment of Fig. 5, taking the provided method applied to the
其中,智能合约,是一种旨在以信息化方式传播、验证或执行合同的计算机协议,可以执行某个合约的条款,通过部署在共享账本上的用于满足一定条件时而执行的代码实现,根据实际的业务需求代码用于完成自动化的交易,例如查询买家所购买的物流状态,在买家签收货物后将买家的电子货币转移到商家的地址;当然,智能合约不仅限于执行用于交易的合约,还可以执行对接收的信息进行处理的合约。智能合约允许在没有第三方的情况下进行可信交易,这些交易可追踪且不可逆转。Among them, a smart contract is a computer protocol designed to disseminate, verify or execute a contract in an informatized manner. It can execute the terms of a contract and implement it through code deployed on a shared ledger that is executed when certain conditions are met. According to actual business needs, the code is used to complete automated transactions, such as querying the logistics status of the buyer's purchase, and transferring the buyer's electronic currency to the merchant's address after the buyer signs for the goods; of course, smart contracts are not limited to execution. The contract for transactions can also execute the contract for processing the received information. Smart contracts allow for trusted transactions without third parties, which are traceable and irreversible.
区块链上的智能合约是在区块链上可以被交易触发执行的合约。智能合约可以通过代码的形式定义。Smart contracts on the blockchain are contracts that can be triggered by transactions on the blockchain. Smart contracts can be defined in the form of code.
以以太坊为例,支持用户在以太网网络中创建并调用一些复杂的逻辑。以太坊作为一个可编程区块链,其核心是以太坊虚拟机(Ethereum Virtual Machine,EVM),每个以太坊节点都可以运行EVM。EVM是一个图灵完备的虚拟机,通过它可以实现各种复杂的逻辑。用户在以太坊中发布和调用智能合约就是在EVM上运行的。实际上,EVM直接运行的是虚拟机代码(虚拟机字节码,简称“字节码”),所以部署在区块链上的智能合约可以是字节码。Taking Ethereum as an example, it supports users to create and call some complex logic in the Ethereum network. As a programmable blockchain, Ethereum has an Ethereum Virtual Machine (Ethereum Virtual Machine, EVM) at its core, and each Ethereum node can run the EVM. EVM is a Turing-complete virtual machine through which various complex logic can be realized. Users publish and call smart contracts in Ethereum that run on the EVM. In fact, EVM directly runs the virtual machine code (virtual machine bytecode, referred to as "bytecode"), so the smart contract deployed on the blockchain can be bytecode.
本公开实施例中的任意一个智能合约可以通过以下方式部署到区块链网络上,但本公开并不限定于此。用户将一笔包含创建智能合约的交易(transaction)发送到区块链网络后,各节点均可以在EVM中执行这笔交易。其中,交易中的From字段用于记录发起创建智能合约的账户的地址,交易的Data字段的字段值保存的合约代码可以是字节码,交易的To字段的字段值为一个null(空)的账户。当节点间通过共识机制达成一致后,这个智能合约成功创建,后续用户可以调用这个智能合约。Any smart contract in the embodiments of the present disclosure can be deployed on the blockchain network in the following manner, but the present disclosure is not limited thereto. After the user sends a transaction including the creation of a smart contract to the blockchain network, each node can execute the transaction in the EVM. Among them, the From field in the transaction is used to record the address of the account that initiated the creation of the smart contract, the contract code saved in the field value of the Data field of the transaction can be a bytecode, and the field value of the To field of the transaction is a null (empty) account. When the nodes reach an agreement through the consensus mechanism, the smart contract is successfully created, and subsequent users can call the smart contract.
每个智能合约创建后,区块链上出现一个与各个智能合约对应的合约账户,并拥有一个特定的地址。合约代码(Code)将保存在该合约账户的账户存储(Storage)中。智能合约的行为由合约代码控制,而智能合约的账户存储则保存了合约的状态。即智能合约使得区块链上产生包含合约代码和账户存储的虚拟账户。在一个智能合约中可以声明多种成员,包括状态变量、函数、函数修改器、事件等。状态变量是永久存储在智能合约的账户存储(Storage)字段中的值,用于保存智能合约的状态。After each smart contract is created, a contract account corresponding to each smart contract appears on the blockchain and has a specific address. The contract code (Code) will be saved in the account storage (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. That is, the smart contract makes a virtual account containing contract code and account storage generated on the blockchain. Various members can be declared in a smart contract, including state variables, functions, function modifiers, events, etc. The state variable is a value permanently stored in the account storage (Storage) field of the smart contract, which is used to save the state of the smart contract.
在步骤S510中,获取第一请求方的终端设备发送的第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数。In step S510, the first transaction request sent by the terminal device of the first requesting party is obtained, the first transaction request carries the first business party identification, the first requesting party information and the first transaction request for executing the first transaction request. A parameter is passed in.
本公开实施例中,第一请求方可以是任意业务方,第一请求方的终端设备可以是任意终端设备,在下面的举例说明中,以图1中的第一终端201为例进行举例说明,但本公开并不限定于此。In the embodiment of the present disclosure, the first requesting party may be any business party, and the terminal device of the first requesting party may be any terminal device. In the following examples, the first terminal 201 in FIG. 1 is used as an example for illustration , but the disclosure is not limited thereto.
第一终端201可以向区块链网络100中上传第一交易请求,相应地,区块链网络100中的任意节点设备101均可以接收到第一终端201所发送的第一交易请求。该第一交易请求中可以携带第一业务方标识、第一请求方信息和第一传入参数。The first terminal 201 can upload the first transaction request to the blockchain network 100 , and correspondingly, any
其中,该第一业务方标识是第一请求方在发送第一交易请求之前生成的,以用于唯一区别该第一交易请求所针对的操作对象的标识,例如,若第一交易请求所针对的操作对象是第一数据集中的某个文件,则第一业务方标识可以是第一请求方在第一终端201上生成的该文件的文件名。再例如,若第一交易请求所针对的操作对象是某笔资产,则第一业务方标识可以是该资产的标识。本公开对第一业务方标识的形式不做限定,只要其能够将第一交易请求所针对的操作对象与其他操作对象唯一区别开来即可。Wherein, the first business party identifier is generated by the first requesting party before sending the first transaction request, so as to uniquely distinguish the identifier of the operation object targeted by the first transaction request. For example, if the first transaction request targets If the operation object is a certain file in the first data set, the first business party identifier may be the file name of the file generated by the first requesting party on the first terminal 201 . For another example, if the operation object targeted by the first transaction request is a certain asset, the identifier of the first business party may be the identifier of the asset. The present disclosure does not limit the form of the first business party identifier, as long as it can uniquely distinguish the operation object targeted by the first transaction request from other operation objects.
该第一请求方信息可以包括任意能够用于唯一区别该第一请求方或者该第一请求方的终端设备的标识,例如第一请求方的用户名,第一请求方的终端设备的网络地址、设备编号等。The first requester information may include any identifier that can be used to uniquely distinguish the first requester or the first requester's terminal device, such as the first requester's username and the network address of the first requester's terminal device , device number, etc.
第一传入参数可以包括为了能够执行该第一交易请求所需要的任意输入参数。例如,若第一交易请求是请求将数量为10的电子资源从账户1转移至账户2,则第一传入参数可以包括第一交易账户和大小为10的第一交易量,第一交易账户可以包括作为第一转出账户的账户1和作为第一转入账户的账户2。The first incoming parameter may include any input parameter required to be able to execute the first transaction request. For example, if the first transaction request is a request to transfer 10 electronic resources from account 1 to account 2, the first incoming parameter may include the first transaction account and the first transaction amount of 10, the first transaction account It may include account 1 as the first transfer-out account and account 2 as the first transfer-in account.
在步骤S520中,调用所述智能合约生成所述第一传入参数的第一传参哈希值。In step S520, the smart contract is invoked to generate a first hash value of the first incoming parameter.
节点设备101可以调用智能合约,采用哈希函数生成第一传入参数的第一传参哈希值。第一传参哈希值是根据第一交易请求传入的第一传入参数计算获得的数据指纹。The
本公开实施例中所提及的哈希函数可以采用SHA(Security Hash Algorithm,安全哈希算法)函数,例如SHA256、SHA3等任意一种合适的函数,本公开对此不做限定。The hash function mentioned in the embodiments of the present disclosure may use a SHA (Security Hash Algorithm, secure hash algorithm) function, such as any suitable function such as SHA256 and SHA3, which is not limited in the present disclosure.
在步骤S530中,调用所述智能合约将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配。In step S530, the smart contract is invoked to match the first business party identifier, the first requester information, and the first parameter hash value with the transaction execution table.
在一些实施例中,若交易执行表中记录了历史上执行成功的交易请求的业务方标识、请求方信息、传参哈希值、交易执行结果和交易哈希值,则可以将第一交易请求中携带的第一业务方标识、第一请求方信息和上述步骤计算获得的第一传参哈希值分别与交易执行表中已经记录的各个交易请求的业务方标识、请求方信息和传参哈希值进行比较,查询交易执行表中的业务方标识是否存在与第一业务方标识相同的目标业务方标识,查询交易执行表中的请求方信息是否存在与第一请求方信息相同的目标请求方信息,查询交易执行表中的传参哈希值是否存在与第一传参哈希值相同的目标传参哈希值,若存在与之一一匹配的目标业务方标识、目标请求方信息和目标传参哈希值,则判定为匹配成功,即历史上已经执行过与该第一交易请求相同的业务,可以从交易执行表中获取与目标业务方标识、目标请求方信息和目标传参哈希值关联存储的目标交易执行结果和目标交易哈希值;反之,则判定为匹配失败,即历史上尚未执行过与该第一交易请求相同的业务。In some embodiments, if the business party ID, requester information, reference hash value, transaction execution result, and transaction hash value of the transaction request successfully executed in history are recorded in the transaction execution table, the first transaction can be The first business party ID carried in the request, the first requester information, and the first parameter hash value calculated in the above steps are respectively compared with the business party ID, requester information, and passed data of each transaction request that have been recorded in the transaction execution table. Compare the reference hash value, check whether the business party ID in the transaction execution table has the same target business party ID as the first business party ID, and check whether the requester information in the transaction execution table has the same target business party ID as the first requester information Target requester information, query whether the passed parameter hash value in the transaction execution table has the same target passed parameter hash value as the first passed parameter hash value, if there is a target business party ID, target request Party information and the hash value of the target passed parameters, it is determined that the match is successful, that is, the same business as the first transaction request has been executed in history, and the target business party ID, target requester information and The target transaction execution result and the target transaction hash value are associated with the stored target transaction hash value; otherwise, it is determined that the matching fails, that is, the same business as the first transaction request has not been executed in history.
本公开实施例中,历史上已经执行过与该第一交易请求相同的业务是指,在第一交易请求之前,已经执行过与该第一交易请求所针对的操作对象相同、且针对该操作对象所执行的交易操作也相同的交易请求,同时该之前成功执行的交易请求也是由该第一交易请求的发起者(第一请求方)发起,即该之前成功执行的交易请求的业务方标识与第一业务方标识相同,请求方信息与该第一请求方信息相同,传入参数和该第一传入参数(这里是通过判断传参哈希值与该第一传参哈希值相同来确定的),当上述三个参数存在任意一个不一致时,则可以确定历史上尚未执行过与该第一交易请求相同的业务。通过在交易执行表中关联记录已经成功执行的交易的业务方标识、请求方信息和传参哈希值,从而可以针对相同业务的多笔交易请求区分出来,满足幂等性要求,防止同一笔业务被重复执行,保证交易执行的安全性和可靠性。In the embodiments of the present disclosure, the same business as the first transaction request has been executed in history means that, before the first transaction request, the same operation object as the first transaction request has been executed, and for the operation The transaction operation performed by the object is also the same transaction request, and the transaction request that was successfully executed before is also initiated by the initiator of the first transaction request (the first requester), that is, the business party ID of the transaction request that was successfully executed before The same as the first business party ID, the requester information is the same as the first requester information, the incoming parameter and the first incoming parameter (here by judging that the passed parameter hash value is the same as the first passed parameter hash value determined), when any one of the above three parameters is inconsistent, it can be determined that the same business as the first transaction request has not been executed in history. By associating and recording the business party ID, requester information, and parameter hash value of the successfully executed transaction in the transaction execution table, multiple transaction requests for the same business can be distinguished, meeting the idempotency requirements, and preventing the same The business is executed repeatedly to ensure the safety and reliability of transaction execution.
在另一些实施例中,若交易执行表中记录了历史上执行成功的交易请求的业务方标识、平台方标识、请求方信息、传参哈希值、交易执行结果和交易哈希值,则节点设备可以根据第一业务方标识(例如这里用a表示)给第一交易请求所针对的操作对象分配一个第一平台方标识(例如这里用A表示),其中,节点设备针对同一操作对象所分配的平台方标识是相同的,节点设备接收到不同的交易请求,但若这些不同的交易请求中的业务方标识是相同的,则生成的平台方标识也是相同的,即平台方标识是根据业务方标识生成的,各个平台方标识也具有唯一性,例如假设第一业务方标识为操作对象为文件1的文件名,则第一平台方标识可以是ABC。然后,节点设备可以将第一交易请求中携带的第一业务方标识、第一请求方信息和上述步骤计算获得的第一传参哈希值、以及节点设备生产的第一平台方标识分别与交易执行表中已经记录的各个交易请求的业务方标识、请求方信息、传参哈希值和平台方标识进行比较,查询交易执行表中的业务方标识是否存在与第一业务方标识相同的目标业务方标识,查询交易执行表中的请求方信息是否存在与第一请求方信息相同的目标请求方信息,查询交易执行表中的传参哈希值是否存在与第一传参哈希值相同的目标传参哈希值,查询交易执行表中的平台方标识是否存在与第一平台方标识相同的目标平台方标识,若存在与之一一匹配的目标业务方标识、目标请求方信息、目标传参哈希值和目标平台方标识,则判定为匹配成功,即历史上已经执行过与该第一交易请求相同的业务,可以从交易执行表中获取与目标业务方标识、目标请求方信息、目标传参哈希值和目标平台方标识关联存储的目标交易执行结果和目标交易哈希值;反之,则判定为匹配失败,即历史上尚未执行过与该第一交易请求相同的业务。In other embodiments, if the transaction execution table records the business party ID, platform party ID, requester information, passed parameter hash value, transaction execution result and transaction hash value of the transaction request executed successfully in history, then The node device may allocate a first platform party identifier (for example, A here) to the operation object targeted by the first transaction request according to the first business party identifier (for example, represented by a here), wherein, the node device for the same operation object The assigned platform party IDs are the same, and node devices receive different transaction requests, but if the business party IDs in these different transaction requests are the same, the generated platform party IDs are also the same, that is, the platform party IDs are based on The identification of the business party is generated, and each platform identification is also unique. For example, assuming that the first business identification is the name of the file whose operation object is file 1, the first platform identification can be ABC. Then, the node device can combine the first business party ID carried in the first transaction request, the first requester information, the first parameter hash value calculated by the above steps, and the first platform party ID produced by the node device with Compare the business party ID, requester information, reference hash value and platform party ID of each transaction request recorded in the transaction execution table, and check whether the business party ID in the transaction execution table is the same as the first business party ID Target business party ID, query whether the requester information in the transaction execution table has the same target requester information as the first requester information, query whether the passed parameter hash value in the transaction execution table is the same as the first passed parameter hash value For the same target parameter hash value, check whether the platform party ID in the transaction execution table has the same target platform party ID as the first platform party ID, and if there is a target business party ID and target requester information that matches one by one , the hash value of the target passed parameters and the target platform party ID, it is determined that the match is successful, that is, the same business as the first transaction request has been executed in history, and the target business party ID, target request can be obtained from the transaction execution table Party information, target parameter hash value, and target platform party identifier store the target transaction execution result and target transaction hash value; otherwise, it is judged as a matching failure, that is, the same transaction request as the first transaction request has not been executed in history. business.
本公开实施例中,历史上已经执行过与该第一交易请求相同的业务是指,在第一交易请求之前,已经执行过与该第一交易请求所针对的操作对象相同、且针对该操作对象所执行的交易操作也相同的交易请求,同时该之前成功执行的交易请求也是由该第一交易请求的发起者(第一请求方)发起,即该之前成功执行的交易请求的业务方标识与第一业务方标识以及平台方标识与第一平台方标识相同,请求方信息与该第一请求方信息相同,传入参数和该第一传入参数(这里是通过判断传参哈希值与该第一传参哈希值相同来确定的),当上述四个参数存在任意一个不一致时,则可以确定历史上尚未执行过与该第一交易请求相同的业务。通过在交易执行表中关联记录已经成功执行的交易的业务方标识、请求方信息、传参哈希值和平台方标识,一方面,可以针对相同业务的多笔交易请求区分出来,满足幂等性要求,防止同一笔业务被重复执行,保证交易执行的安全性和可靠性;另一方面,通过业务方标识和平台方标识来联合标识交易请求所针对的操作对象,即由多方来维护操作对象的唯一标识,而不是单纯由业务方来维护,可以进一步确定不同交易请求所针对的是同一操作对象,进一步保证交易执行的安全性和可靠性。In the embodiments of the present disclosure, the same business as the first transaction request has been executed in history means that, before the first transaction request, the same operation object as the first transaction request has been executed, and for the operation The transaction operation performed by the object is also the same transaction request, and the transaction request that was successfully executed before is also initiated by the initiator of the first transaction request (the first requester), that is, the business party ID of the transaction request that was successfully executed before The ID of the first business party and the ID of the platform party are the same as the ID of the first platform party, the information of the requester is the same as that of the first requester, and the incoming parameters and the first incoming parameters (here by judging the hash value of the passed parameters and the hash value of the first passed parameter), when any one of the above four parameters is inconsistent, it can be determined that the same business as the first transaction request has not been executed in history. By associating and recording the business party ID, requester information, passed parameter hash value and platform party ID of the successfully executed transaction in the transaction execution table, on the one hand, multiple transaction requests for the same business can be distinguished, satisfying idempotence To prevent the same business from being executed repeatedly, and ensure the security and reliability of transaction execution; on the other hand, the operation object targeted by the transaction request is jointly identified through the business party ID and the platform party ID, that is, the operation is maintained by multiple parties The unique identification of the object, instead of being maintained solely by the business side, can further determine that different transaction requests are aimed at the same operation object, further ensuring the security and reliability of transaction execution.
在又一些实施例中,若交易执行表中记录了历史上执行成功的交易请求的数据实体标识、请求方信息、传参哈希值、交易执行结果和交易哈希值,该数据实体标识是根据已经执行成功的交易请求的业务方标识和平台方标识生成的,例如级联该业务方标识和该平台方标识生成该数据实体标识,或者对该业务方标识和该平台方标识计算哈希值,获得该数据实体标识,本公开对此不做限定,则节点设备可以根据第一业务方标识给第一交易请求所针对的操作对象分配一个第一平台方标识,之后,节点设备可以根据第一业务方平台和第一平台方标识生成第一数据实体标识,该第一数据实体标识的生成方式不做限定,只要能够唯一区别第一交易请求所针对的操作对象即可。然后,节点设备可以将第一交易请求的第一数据实体标识、第一请求方信息和上述步骤计算获得的第一传参哈希值分别与交易执行表中已经记录的各个交易请求的数据实体标识、请求方信息和传参哈希值进行比较,查询交易执行表中的数据实体标识是否存在与第一数据实体标识相同的目标数据实体标识,查询交易执行表中的请求方信息是否存在与第一请求方信息相同的目标请求方信息,查询交易执行表中的传参哈希值是否存在与第一传参哈希值相同的目标传参哈希值,若存在与之一一匹配的目标数据实体标识、目标请求方信息和目标传参哈希值,则判定为匹配成功,即历史上已经执行过与该第一交易请求相同的业务,可以从交易执行表中获取与目标数据实体标识、目标请求方信息和目标传参哈希值关联存储的目标交易执行结果和目标交易哈希值;反之,则判定为匹配失败,即历史上尚未执行过与该第一交易请求相同的业务。In some other embodiments, if the transaction execution table records the data entity identifier, requester information, reference hash value, transaction execution result and transaction hash value of the transaction request executed successfully in history, the data entity identifier is Generated according to the business party ID and the platform party ID of the successful transaction request, for example, cascading the business party ID and the platform party ID to generate the data entity ID, or calculating the hash of the business party ID and the platform party ID Value, to obtain the data entity ID, which is not limited in this disclosure, then the node device can assign a first platform party ID to the operation object targeted by the first transaction request according to the first business party ID, and then the node device can according to The first business party platform and the first platform party ID generate the first data entity ID, and the method of generating the first data entity ID is not limited, as long as the operation object targeted by the first transaction request can be uniquely distinguished. Then, the node device can combine the first data entity identifier of the first transaction request, the information of the first requester, and the first reference hash value calculated by the above steps with the data entity of each transaction request already recorded in the transaction execution table. ID, requester information and the passed parameter hash value are compared to check whether the data entity ID in the transaction execution table has the same target data entity ID as the first data entity ID, and check whether the requester information in the transaction execution table has the same target data entity ID as For the target requester information that is the same as the first requester information, query whether the passed parameter hash value in the transaction execution table has the same target passed parameter hash value as the first passed parameter hash value, if there is a one-to-one matching The target data entity identifier, target requester information and target parameter hash value are determined to match successfully, that is, the same business as the first transaction request has been executed in history, and the target data entity can be obtained from the transaction execution table. The target transaction execution result and target transaction hash value stored in association with the identification, target requester information, and target parameter hash value; otherwise, it is determined that the matching fails, that is, the same business as the first transaction request has not been executed in history .
本公开实施例中,数据实体可以理解为数据集中一类数据对象的个体,比如可以是具体的人、事、物,也可以为抽象的概念、联系等,数据实体标识可以用于唯一区分各个数据实体。In the embodiments of the present disclosure, a data entity can be understood as an individual of a type of data object in a data set, such as a specific person, thing, thing, or an abstract concept, connection, etc., and the data entity identifier can be used to uniquely distinguish each data entity.
本公开实施例中,历史上已经执行过与该第一交易请求相同的业务是指,在第一交易请求之前,已经执行过与该第一交易请求所针对的操作对象相同、且针对该操作对象所执行的交易操作也相同的交易请求,同时该之前成功执行的交易请求也是由该第一交易请求的发起者(第一请求方)发起,即该之前成功执行的交易请求的数据实体标识与第一数据实体标识相同,请求方信息与该第一请求方信息相同,传入参数和该第一传入参数(这里是通过判断传参哈希值与该第一传参哈希值相同来确定的),当上述三个参数存在任意一个不一致时,则可以确定历史上尚未执行过与该第一交易请求相同的业务。通过在交易执行表中关联记录已经成功执行的交易的数据实体标识、请求方信息和传参哈希值,一方面,可以针对相同业务的多笔交易请求区分出来,满足幂等性要求,防止同一笔业务被重复执行,保证交易执行的安全性和可靠性;另一方面,通过业务方标识和平台方标识来生成交易请求所针对的操作对象的数据实体标识,即由多方来维护操作对象的唯一标识,而不是单纯由业务方来维护,可以进一步确定不同交易请求所针对的是同一操作对象,进一步保证交易执行的安全性和可靠性。In the embodiments of the present disclosure, the same business as the first transaction request has been executed in history means that, before the first transaction request, the same operation object as the first transaction request has been executed, and for the operation The transaction operation performed by the object is also the same as the transaction request, and the transaction request that was successfully executed before is also initiated by the initiator of the first transaction request (the first requester), that is, the data entity identifier of the transaction request that was successfully executed before The same as the first data entity identifier, the requester information is the same as the first requester information, the incoming parameter and the first incoming parameter (here, by judging that the passed parameter hash value is the same as the first passed parameter hash value determined), when any one of the above three parameters is inconsistent, it can be determined that the same business as the first transaction request has not been executed in history. By associating and recording the data entity identifier, requester information and parameter hash value of the transaction that has been successfully executed in the transaction execution table, on the one hand, multiple transaction requests for the same business can be distinguished to meet the requirements of idempotence and prevent The same business is executed repeatedly to ensure the security and reliability of transaction execution; on the other hand, the data entity identification of the operation object targeted by the transaction request is generated through the business party ID and the platform party ID, that is, the operation object is maintained by multiple parties Instead of simply being maintained by the business side, it can be further determined that different transaction requests are aimed at the same operation object, further ensuring the security and reliability of transaction execution.
在再一些实施例中,若交易执行表中记录了历史上执行成功的交易请求的交易执行表唯一键、交易执行结果和交易哈希值,每个交易执行表唯一键是根据对应交易请求的数据实体标识、请求方信息和传参哈希值生成的,以用于唯一区别针对同一数据实体标识所对应的操作对象进行的相同的交易操作,且该相同的交易操作是同一请求方发起的。节点设备可以根据第一交易请求的第一数据实体标识、第一请求方信息和第一传参哈希值生成第一交易执行表唯一键。然后,节点设备可以将第一交易请求的第一交易执行表唯一键与交易执行表中已经记录的各个交易请求的交易执行表唯一键进行比较,查询交易执行表中的交易执行表唯一键是否存在与第一交易执行表唯一键相同的目标交易执行表唯一键,若存在与之匹配的目标交易执行表唯一键,则判定为匹配成功,即历史上已经执行过与该第一交易请求相同的业务,可以从交易执行表中获取与目标交易执行表唯一键关联存储的目标交易执行结果和目标交易哈希值;反之,则判定为匹配失败,即历史上尚未执行过与该第一交易请求相同的业务。In some further embodiments, if the transaction execution table records the transaction execution table unique key, transaction execution result and transaction hash value of the transaction request successfully executed in history, each transaction execution table unique key is based on the corresponding transaction request Generated by the data entity ID, requester information and parameter hash value to uniquely distinguish the same transaction operation performed on the operation object corresponding to the same data entity ID, and the same transaction operation is initiated by the same requester . The node device may generate the unique key of the first transaction execution table according to the first data entity identifier of the first transaction request, the first requester information and the hash value of the first passed parameter. Then, the node device can compare the unique key of the first transaction execution table of the first transaction request with the unique key of the transaction execution table of each transaction request recorded in the transaction execution table, and query whether the unique key of the transaction execution table in the transaction execution table There is a unique key in the target transaction execution table that is the same as the unique key in the first transaction execution table. If there is a matching unique key in the target transaction execution table, it is determined that the match is successful, that is, the same request as the first transaction request has been executed in history. For the business, the target transaction execution result and the target transaction hash value stored in association with the unique key of the target transaction execution table can be obtained from the transaction execution table; otherwise, it is determined that the matching fails, that is, the first transaction has not been executed in history Ask for the same business.
本公开实施例中,历史上已经执行过与该第一交易请求相同的业务是指,在第一交易请求之前,已经执行过与该第一交易请求所针对的操作对象相同、且针对该操作对象所执行的交易操作也相同的交易请求,同时该之前成功执行的交易请求也是由该第一交易请求的发起者(第一请求方)发起,即该之前成功执行的交易请求中存在交易执行表唯一键与第一交易执行表唯一键相同的目标交易执行表唯一键,当不存在与之匹配的目标交易执行表唯一键时,则可以确定历史上尚未执行过与该第一交易请求相同的业务。通过在交易执行表中关联记录已经成功执行的交易的交易执行表唯一键,一方面,可以针对相同业务的多笔交易请求区分出来,满足幂等性要求,防止同一笔业务被重复执行,保证交易执行的安全性和可靠性;另一方面,通过交易执行表唯一键来唯一标记由某一请求方发起的针对某一操作对象的交易操作,该交易执行表唯一键根据对应的数据实体标识、请求方信息和传参哈希值来对应生成,即由多方来维护交易请求的发起者针对操作对象的交易操作的唯一标识,而不是单纯由业务方来维护,可以进一步确定不同交易请求是由相同发起者发起的针对同一操作对象的同一交易操作,进一步保证交易执行的安全性和可靠性。In the embodiments of the present disclosure, the same business as the first transaction request has been executed in history means that, before the first transaction request, the same operation object as the first transaction request has been executed, and for the operation The transaction operation performed by the object is also the same as the transaction request, and the transaction request that was successfully executed before is also initiated by the initiator of the first transaction request (the first requester), that is, there is a transaction execution in the transaction request that was successfully executed before The unique key of the target transaction execution table whose unique key is the same as the unique key of the first transaction execution table. When there is no matching unique key of the target transaction execution table, it can be determined that the same transaction request as the first transaction request has not been executed in history. Business. By associating and recording the unique key of the transaction execution table that has been successfully executed in the transaction execution table, on the one hand, multiple transaction requests for the same business can be distinguished, meeting the idempotence requirements, preventing the same business from being executed repeatedly, and ensuring The security and reliability of transaction execution; on the other hand, the transaction operation initiated by a certain requester for a certain operation object is uniquely marked by the unique key of the transaction execution table. The unique key of the transaction execution table is identified according to the corresponding data entity , the requester information and the passed parameter hash value to generate correspondingly, that is, the initiator of the transaction request maintains the unique identifier of the transaction operation of the operation object by multiple parties, instead of simply being maintained by the business party, which can further determine whether different transaction requests are The same transaction operation for the same operation object initiated by the same initiator further guarantees the security and reliability of transaction execution.
在步骤S540中,将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,所述目标交易哈希值与所述第一交易请求的第一交易哈希值不同。In step S540, the target transaction execution result and the target transaction hash value matched with the first business party identifier, the first requester information and the first parameter hash value in the transaction execution table Returning to the terminal device of the first requesting party, the target transaction hash value is different from the first transaction hash value of the first transaction request.
本公开实施例中,若交易执行表中存在与第一交易请求的第一业务方标识、第一请求方信息和第一传参哈希值匹配的目标交易执行结果和目标交易哈希值,则节点设备可以判定之前已经成功执行过与第一交易请求相同的业务,此时,节点设备可以直接将交易执行表中存储的与之对应的目标交易执行结果和目标交易哈希值返回给第一请求方的终端设备,而不会再重复执行该第一交易请求,第一请求方的终端接收到节点设备返回的目标交易哈希值和目标交易执行结果之后,将接收到的目标交易哈希值与在第一请求方的终端设备上生成的第一交易哈希值进行比较,判定目标交易哈希值与第一交易哈希值不同,则可以获知虽然接收到了目标交易执行结果,但该目标交易执行结果不是执行第一交易请求获得的,而是之前已经成功执行的交易请求获得的。In the embodiment of the present disclosure, if there is a target transaction execution result and a target transaction hash value that match the first transaction request's first business party ID, first requester information, and first parameter hash value in the transaction execution table, Then the node device can determine that the same business as the first transaction request has been successfully executed before, and at this time, the node device can directly return the corresponding target transaction execution result and target transaction hash value stored in the transaction execution table to the first transaction request. A requester’s terminal device will not repeat the first transaction request. After the first requester’s terminal receives the target transaction hash value and target transaction execution result returned by the node device, it will receive the target transaction hash value The hash value is compared with the first transaction hash value generated on the terminal device of the first requester, and it is determined that the target transaction hash value is different from the first transaction hash value, and it can be known that although the target transaction execution result has been received, the The target transaction execution result is not obtained by executing the first transaction request, but obtained by a transaction request that has been successfully executed before.
其中,第一交易哈希值是第一请求方的终端设备在生成第一交易请求之后,对第一交易请求进行哈希运算获得的。Wherein, the first transaction hash value is obtained by performing a hash operation on the first transaction request after the terminal device of the first requester generates the first transaction request.
在示例性实施例中,将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,可包括:验证所述第一交易请求的合法性;若所述第一交易请求具有合法性,则生成包括所述第一交易请求的第一区块;将所述第一区块添加至对应的区块链;若所述第一区块上链成功,则从所述交易执行表中检索到分别与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标业务方标识、目标请求方信息和目标传参哈希值;将与所述目标业务方标识、所述目标请求方信息和所述目标传参哈希值对应的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备。In an exemplary embodiment, the target transaction execution result and the target transaction hash matched with the first business party identifier, the first requester information, and the first parameter hash value in the transaction execution table are Returning the value to the terminal device of the first requesting party may include: verifying the legitimacy of the first transaction request; if the first transaction request is legal, generating a second transaction request including the first transaction request A block; add the first block to the corresponding block chain; if the first block is successfully linked, then retrieve from the transaction execution table the first business party ID, The target business party ID, target requester information and target parameter hash value matched by the first requester information and the first reference hash value; will be matched with the target business party ID, the target requester The target transaction execution result and the target transaction hash value corresponding to the information and the target reference hash value are returned to the terminal device of the first requesting party.
在示例性实施例中,将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,可包括:验证所述第一交易请求的合法性;若所述第一交易请求具有合法性,则生成包括所述第一交易请求的第一区块;将所述第一区块添加至对应的区块链;若所述第一区块上链成功,则根据所述第一业务方标识生成第一平台方标识;根据所述第一业务方标识和所述第一平台方标识生成第一数据实体标识;从所述交易执行表中检索到分别与所述第一数据实体标识、所述第一请求方信息和所述第一传参哈希值匹配的目标数据实体标识、目标请求方信息和目标传参哈希值;将与所述目标数据实体标识、所述目标请求方信息和所述目标传参哈希值对应的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备。In an exemplary embodiment, the target transaction execution result and the target transaction hash matched with the first business party identifier, the first requester information, and the first parameter hash value in the transaction execution table are Returning the value to the terminal device of the first requesting party may include: verifying the legitimacy of the first transaction request; if the first transaction request is legal, generating a second transaction request including the first transaction request One block; add the first block to the corresponding block chain; if the first block is successfully uploaded to the chain, then generate the first platform party ID according to the first business party ID; according to the first A business party ID and the first platform party ID generate a first data entity ID; retrieve the first data entity ID, the first requestor information, and the first data entity ID from the transaction execution table. The target data entity ID, target requester information, and target parameter hash value matched by the passed parameter hash value; The target transaction execution result and the target transaction hash value are returned to the terminal device of the first requesting party.
在示例性实施例中,将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,可包括:验证所述第一交易请求的合法性;若所述第一交易请求具有合法性,则生成包括所述第一交易请求的第一区块;将所述第一区块添加至对应的区块链;若所述第一区块上链成功,则根据所述第一业务方标识生成第一平台方标识;根据所述第一业务方标识和所述第一平台方标识生成第一数据实体标识;根据所述第一数据实体标识、所述第一请求方信息和所述第一传参哈希值生成第一交易执行表唯一键;若所述第一交易执行表唯一键与所述交易执行表中的目标交易执行表唯一键匹配,则将与所述目标交易执行表唯一键对应的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备。In an exemplary embodiment, the target transaction execution result and the target transaction hash matched with the first business party identifier, the first requester information, and the first parameter hash value in the transaction execution table are Returning the value to the terminal device of the first requesting party may include: verifying the legitimacy of the first transaction request; if the first transaction request is legal, generating a second transaction request including the first transaction request One block; add the first block to the corresponding block chain; if the first block is successfully uploaded to the chain, then generate the first platform party ID according to the first business party ID; according to the first A business party identifier and the first platform party identifier generate a first data entity identifier; generate a first transaction execution according to the first data entity identifier, the first requestor information and the first parameter hash value table unique key; if the unique key of the first transaction execution table matches the unique key of the target transaction execution table in the transaction execution table, the target transaction execution result and the target transaction corresponding to the unique key of the target transaction execution table The hash value is returned to the terminal device of the first requesting party.
本公开实施例中,节点设备101可接收各个终端设备所发送的交易请求,其中包括第一终端201所发送的第一交易请求,将所接收到的交易请求确定为待上链的交易数据,将待上链的多个交易数据存储至交易池中,并按照一定的顺序从交易池中读取目标交易数据。其中,目标交易数据可以是指上述多个交易数据中的任一交易数据,这里假设目标交易数据包括上述第一交易请求。目标交易数据包括但不限于电子资源转移的交易数据、股权交易数据以及基金交易数据等。此处顺序可包括交易数据被缓存于交易池的时间顺序、交易数据的重要性优先级、交易类型等,这样有利于有序地对各个交易数据进行验证,提高验证的灵活性和准确度。In the embodiment of the present disclosure, the
在一些实施例中,交易类型可以包括实时性交易类型和非实时性交易类型,实时性交易类型可包括电子资源转移(实时到账)、上链电子证件等等;非实时性交易类型可包括上链新闻数据、用户注册数据等等。节点设备101可以优先读取实时性交易类型的交易数据,然后读取非实时性交易类型的交易数据,这样可以确保实时性交易类型的交易数据能够被实时处理。In some embodiments, transaction types can include real-time transaction types and non-real-time transaction types, and real-time transaction types can include electronic resource transfer (real-time account), electronic certificates on the chain, etc.; non-real-time transaction types can include On-chain news data, user registration data, etc. The
在一些实施例中,重要性优先级可以是根据交易数据所属的机构确定的,例如,该交易数据属于行政部门,则该交易数据的重要性优先级比较高;反之,如果该交易数据属于企业或个人,则该交易数据的重要性优先级比较低。重要性优先级用于指示交易数据的重要性、私密性等等,即重要性优先级越高,交易数据的重要性、私密性越高;重要性优先级越低,交易数据的重要性、私密性越低。因此,节点设备101可以优先读取重要性优先级高的交易数据,然后读取重要性优先级低的交易数据,这样确保重要性优先级高的交易数据能够被实时处理,可有效提高交易数据的安全性,避免重要性优先级高的交易数据被泄露。In some embodiments, the importance priority can be determined according to the institution to which the transaction data belongs. For example, if the transaction data belongs to the administrative department, the priority of the transaction data is relatively high; on the contrary, if the transaction data belongs to the enterprise or individuals, the priority of the transaction data is relatively low. The importance priority is used to indicate the importance, privacy, etc. of the transaction data, that is, the higher the importance priority, the higher the importance and privacy of the transaction data; the lower the importance priority, the higher the importance and privacy of the transaction data. The less privacy. Therefore, the
在一些实施例中,节点设备101可以按照交易池中各个交易数据被接收到的时间由先到后的顺序,依次读取各个交易数据,这样可以提高对各个交易数据处理的公平性。In some embodiments, the
节点设备接收到第一终端201发送的第一交易请求,可以获取该第一交易请求的属性信息,根据该第一交易请求的属性信息验证该第一交易请求的有效性。具体的,验证第一交易请求的有效性可以是指:验证该第一交易请求是否能够被成功执行;如果能够被成功执行,确定该第一交易请求具有有效性;如果不能被成功执行,则确定该第一交易请求不具有有效性。After receiving the first transaction request sent by the first terminal 201, the node device may acquire attribute information of the first transaction request, and verify the validity of the first transaction request according to the attribute information of the first transaction request. Specifically, verifying the validity of the first transaction request may refer to: verifying whether the first transaction request can be successfully executed; if it can be successfully executed, determining that the first transaction request is valid; It is determined that the first transaction request is not valid.
在读取到第一交易请求后,可获取第一交易请求的属性信息,此处属性信息包括为预测执行第一交易请求所需要电子资源的第一数量、第一交易请求的大小、第一交易请求的签名信息、第一交易请求的生成时间等。即第一数量可以是指用户愿意为执行第一交易请求所支付的电子资源的数量。其中,电子资源是指用于购买数字资产的资金,此处的数字资产可包括但不限于:电子票据、游戏资源(如游戏币、游戏装备等),等等。After the first transaction request is read, the attribute information of the first transaction request can be obtained, where the attribute information includes the first quantity of electronic resources required for predicting the execution of the first transaction request, the size of the first transaction request, the first The signature information of the transaction request, the generation time of the first transaction request, etc. That is, the first amount may refer to the amount of electronic resources that the user is willing to pay for executing the first transaction request. Wherein, electronic resources refer to funds used to purchase digital assets, where digital assets may include but not limited to: electronic bills, game resources (such as game currency, game equipment, etc.), and so on.
从交易池中读取第一交易请求之后,获取用户为预测执行第一交易请求所需要电子资源的第一数量,然后再获取预先存储的实际执行该第一交易请求所需要的电子资源的第二数量,将该第一数量与该第二数量进行对比,若该第一数量大于该第二数量,则确定该第一交易请求具有有效性,即说明用户预测执行第一交易请求所需要的电子资源大于实际执行第一交易请求所需要的电子资源,则第一交易请求执行能成功;若该第一数量小于或等于第二数量,则确定该第一交易请求不具有有效性,即说明用户预测执行第一交易请求所需要的电子资源小于或等于实际执行第一交易请求所需要的电子资源,则第一交易请求执行不能成功,第一交易请求就会执行失败。After reading the first transaction request from the transaction pool, obtain the first amount of electronic resources required by the user to predict the execution of the first transaction request, and then obtain the pre-stored number of electronic resources required for actually executing the first transaction request. Two quantities, compare the first quantity with the second quantity, if the first quantity is greater than the second quantity, it is determined that the first transaction request is valid, that is to say, the user predicts that the first transaction request needs to be executed If the electronic resources are greater than the electronic resources required to actually execute the first transaction request, the first transaction request can be executed successfully; if the first quantity is less than or equal to the second quantity, it is determined that the first transaction request is not valid, that is, If the user predicts that the electronic resources required to execute the first transaction request are less than or equal to the electronic resources actually required to execute the first transaction request, then the execution of the first transaction request cannot be successfully executed, and the execution of the first transaction request will fail.
在一些实施例中,将该第一交易请求的大小与预先设定的交易数据的大小对应的阈值进行比对,若该第一交易请求的大小大于该交易数据的大小对应的阈值,表明第一交易请求中存在冗余数据,第一交易请求的大小不满足条件,则确定该第一交易请求不具有有效性。若该第一交易请求的大小小于或等于该交易数据的大小对应的阈值,表明第一交易请求中不存在冗余数据,则确定该第一交易请求具有有效性。In some embodiments, the size of the first transaction request is compared with a preset threshold corresponding to the size of transaction data, and if the size of the first transaction request is greater than the threshold corresponding to the size of the transaction data, it indicates that the first There is redundant data in a transaction request, and the size of the first transaction request does not satisfy the condition, then it is determined that the first transaction request is not valid. If the size of the first transaction request is less than or equal to the threshold corresponding to the size of the transaction data, indicating that there is no redundant data in the first transaction request, it is determined that the first transaction request is valid.
在一些实施例中,验证该第一交易请求是否具有有效性可以是指:验证第一交易请求的真实性、完整性(即是否被篡改),如果该第一交易请求是真实的、完整的(即没有被篡改),则确定该第一交易请求具有有效性;如果该第一交易请求是不真实的、不完整的(即被篡改),则确定该第一交易请求不具有有效性。In some embodiments, verifying whether the first transaction request is valid may refer to: verifying the authenticity and integrity of the first transaction request (that is, whether it has been tampered with), if the first transaction request is true and complete (that is, not tampered with), then determine that the first transaction request is valid; if the first transaction request is untrue and incomplete (that is, tampered with), then determine that the first transaction request is not valid.
在一些实施例中,节点设备101可获取该第一交易请求对应的公钥,该第一交易请求对应的公钥可以是指上传该第一交易请求的第一终端201的公钥。可根据该第一交易请求对应的公钥对该签名信息进行验证,若验证通过,表明该第一交易请求未被篡改,具有完整性,则确定该第一交易请求具有有效性,若验证未通过,表明该第一交易请求被篡改,不具有完整性,则确定该第一交易请求不具有有效性。In some embodiments, the
具体的,在第一交易请求未被上传至节点设备101时,第一终端201可对第一交易请求进行哈希运算,得到第一交易请求的第一交易哈希值,采用私钥对第一交易请求的哈希值进行加密,得到携带第一终端201的签名的第一交易请求,将该第一交易请求和携带终端的签名的第一交易请求一起发送至区块链网络的节点设备101。Specifically, when the first transaction request has not been uploaded to the
相应地,节点设备可以接收第一终端201所发送的该第一交易请求、携带第一终端201的签名的第一交易请求,节点设备可以获取第一终端201的公钥,将该公钥作为该第一交易请求对应的公钥。节点设备对第一交易请求进行哈希运算,得到第一交易哈希值,采用公钥对携带第一终端201的签名的第一交易请求进行解密,得到第三交易哈希值,将第一交易哈希值与第三交易哈希值进行比对,若第一哈希值与第三哈希值不相同,则表明第一交易请求不具有完整性,即第一交易请求被篡改,确定第一交易请求未被验证通过;若第一哈希值与第三哈希值相同,则表明该第一交易请求具有完整性,该第一交易请求未被篡改,确定第一交易请求验证通过。Correspondingly, the node device may receive the first transaction request sent by the first terminal 201 and the first transaction request carrying the signature of the first terminal 201, the node device may obtain the public key of the first terminal 201, and use the public key as The public key corresponding to the first transaction request. The node device performs hash operation on the first transaction request to obtain the first transaction hash value, uses the public key to decrypt the first transaction request carrying the signature of the first terminal 201, obtains the third transaction hash value, and converts the first The transaction hash value is compared with the third transaction hash value. If the first hash value is different from the third hash value, it indicates that the first transaction request does not have integrity, that is, the first transaction request has been tampered with. The first transaction request has not been verified; if the first hash value is the same as the third hash value, it indicates that the first transaction request has integrity, the first transaction request has not been tampered with, and it is determined that the first transaction request has passed the verification .
其中,属性信息中的为预测执行第一交易请求所需要电子资源的第一数量、第一交易请求的生成时间,可用于验证第一交易请求是否能够被成功执行;属性信息中的第一交易请求的大小、第一交易请求的签名信息,用于验证第一交易请求的真实性、完整性(即是否被篡改)。Among them, in the attribute information, the first quantity of electronic resources needed to predict the execution of the first transaction request and the generation time of the first transaction request can be used to verify whether the first transaction request can be successfully executed; the first transaction in the attribute information The size of the request and the signature information of the first transaction request are used to verify the authenticity and integrity of the first transaction request (that is, whether it has been tampered with).
本公开实施例中,若第一交易请求具有有效性,则可以进一步验证第一交易请求是否具有合法性。其中,可以获取该区块链网络中确定该第一交易请求具有有效性的节点设备的数量;若所获取到的数量大于数量阈值(该数量阈值可以根据实际需求进行设置,本公开对此不做限定),则确定该第一交易请求具有合法性;若所获取到的数量小于或等于该数量阈值,则确定该第一交易请求不具有合法性。In the embodiment of the present disclosure, if the first transaction request is valid, it may be further verified whether the first transaction request is legal. Among them, the number of node devices in the block chain network that determines that the first transaction request is valid can be obtained; if the obtained number is greater than the number threshold (the number threshold can be set according to actual needs, this disclosure does not limit), then it is determined that the first transaction request is legal; if the obtained quantity is less than or equal to the quantity threshold, it is determined that the first transaction request is not legal.
需要说明的是,如果交易池中的交易数据被读取后,可以将被读取的交易数据从交易池中删除,以节省存储空间,可有效存储更多新的交易数据。It should be noted that if the transaction data in the transaction pool is read, the read transaction data can be deleted from the transaction pool to save storage space and effectively store more new transaction data.
如果该第一交易请求具有有效性和合法性,表明该第一交易请求具有完整性、真实性、或者能够被成功执行,且确定该第一交易请求具有有效性的节点设备的数量大于数量阈值,因此,节点设备101可将第一交易请求作为目标交易数据存储至区块链网络的区块(这里称之为第一区块)中。If the first transaction request is valid and legal, it indicates that the first transaction request has integrity, authenticity, or can be successfully executed, and the number of node devices that determine that the first transaction request is valid is greater than the number threshold , therefore, the
例如,假设节点设备101将第一交易请求存储至区块10001中,区块10001中包括区块头和区块体,区块10001的区块头中包括10000H、10001H、10001T等,其中,10000H代表区块链中区块10000的区块头哈希值,10001H代表区块10001的区块体中交易数据(包括第一交易请求,还可以包括其它交易数据)所对应的哈希值,10001T代表区块10001的区块生成时间戳。For example, assume that
在示例性实施例中,所述方法还可以包括:若所述第一交易请求不具有合法性,或者所述第一区块上链失败,则向所述第一请求方的终端设备返回执行所述第一交易请求失败的第一交易执行结果。In an exemplary embodiment, the method may further include: if the first transaction request is not legal, or if the first block chaining fails, returning execution to the terminal device of the first requesting party The first transaction execution result of the failure of the first transaction request.
如果第一交易请求不具有有效性和合法性,表明该第一交易请求不具有完整性、真实性或者不能够被成功执行,或者确定该第一交易请求具有有效性的节点设备的数量小于或等于数量阈值,因此,节点设备101可对第一交易请求进行回滚,可避免将无效的交易数据存储至区块中,有利于节省区块的存储空间,从而保证了区块链中数据的有效性。回滚指的是程序或数据处理错误,将程序或数据恢复到上一次正确状态的行为。If the first transaction request does not have validity and legality, it indicates that the first transaction request does not have integrity, authenticity or cannot be successfully executed, or the number of node devices that determine that the first transaction request is valid is less than or equal to the quantity threshold, therefore, the
若被读取的交易数据不具有有效性或者合法性,则从该交易池中移除该被读取的交易数据。If the read transaction data is not valid or legal, the read transaction data is removed from the transaction pool.
本公开实施方式提供的基于区块链的数据处理方法,一方面,通过在区块链网络中部署用于维护交易执行表的智能合约,当区块链网络中的节点设备接收到第一请求方的终端设备发送的第一交易请求时,可以根据第一交易请求携带的第一业务方标识、第一请求方信息和用于执行第一交易请求的第一传入参数查询智能合约维护的交易执行表,若判定交易执行表与第一传入参数的第一传参哈希值、第一业务方标识和第一请求方信息匹配,则节点设备可以确定与该第一交易请求相同的业务在此之前已经被成功执行过,此时,节点设备不执行该第一交易请求,而是将交易执行表中所述第一业务方标识、第一请求方信息和第一传参哈希值匹配的目标交易执行结果和目标交易哈希值直接返回至第一请求方的终端设备,从而可以避免节点设备重复执行相同的业务,确保针对相同业务的交易操作不会被重复执行,确保业务执行的幂等性,即通过智能合约维护的交易执行表可以保证存在多笔相同业务提交的多笔不同交易请求并发提交时,也只有一笔业务能够执行成功。另一方面,接收到目标交易执行结果和目标交易哈希值的第一请求方的终端设备,可以通过判定目标交易哈希值与第一交易请求的第一交易哈希值不同来获知与该第一交易请求相同的业务之前已经被成功执行过。The blockchain-based data processing method provided by the embodiments of the present disclosure, on the one hand, by deploying the smart contract for maintaining the transaction execution table in the blockchain network, when the node device in the blockchain network receives the first request When the first transaction request is sent by the party’s terminal device, it can query the smart contract maintained Transaction execution table, if it is determined that the transaction execution table matches the first parameter hash value of the first incoming parameter, the first business party ID and the first requester information, the node device can determine the same transaction request as the first transaction request The business has been successfully executed before, at this time, the node device does not execute the first transaction request, but hashes the first business party ID, first requester information, and first passed parameters in the transaction execution table The execution result of the target transaction and the hash value of the target transaction that match the value are directly returned to the terminal device of the first requesting party, thereby avoiding repeated execution of the same business by the node device, ensuring that the transaction operation for the same business will not be executed repeatedly, and ensuring that the business The idempotence of execution, that is, the transaction execution table maintained by the smart contract can guarantee that when there are multiple different transaction requests submitted by the same business and submitted concurrently, only one business can be executed successfully. On the other hand, the terminal device of the first requesting party that receives the target transaction execution result and the target transaction hash value can know that the target transaction hash value is different from the first transaction hash value of the first transaction request. The first transaction requests the same business which has been successfully executed before.
图6示意性示出了根据本公开的另一个实施例的基于区块链的数据处理方法的流程图。图6实施例提供的方法与上述图5实施例提供的方法之间的区别在于,在上述步骤S510之前,即在获取第一请求方的终端设备发送的第一交易请求之前,所述方法还可以进一步包括以下步骤。Fig. 6 schematically shows a flow chart of a blockchain-based data processing method according to another embodiment of the present disclosure. The difference between the method provided by the embodiment of FIG. 6 and the method provided by the embodiment of FIG. 5 above is that before the above step S510, that is, before obtaining the first transaction request sent by the terminal device of the first requesting party, the method also The following steps may be further included.
在步骤S610中,获取所述第一请求方的终端设备发送的第二交易请求,所述第二交易请求携带所述第一业务方标识、所述第一请求方信息和用于执行所述第二交易请求的第一传入参数。In step S610, obtain the second transaction request sent by the terminal device of the first requesting party, the second transaction request carries the first business party identification, the first requesting party information and the The first incoming parameter of the second transaction request.
节点设备可以在接收到第一终端201发送的第一交易请求之前,已经接收到该第一终端201发送的第二交易请求,且该第二交易请求与第一交易请求携带相同的第一业务方标识、第一请求方信息和第一传入参数,即第一交易请求和第二交易请求是该同一第一请求方先后发起的针对同一业务的相同交易操作。The node device may have received the second transaction request sent by the first terminal 201 before receiving the first transaction request sent by the first terminal 201, and the second transaction request and the first transaction request carry the same first service The party identifier, the first requester information and the first incoming parameters, that is, the first transaction request and the second transaction request are the same transaction operations for the same business initiated successively by the same first requester.
在步骤S620中,调用所述智能合约计算生成所述第一传入参数的第一传参哈希值。In step S620, the smart contract is invoked to calculate and generate a first hash value of the first incoming parameter.
节点设备接收到第二交易请求之后,会利用哈希函数生成第二交易请求携带的第一传入参数的第一传参哈希值。After receiving the second transaction request, the node device will use a hash function to generate a first passed parameter hash value of the first passed parameter carried in the second transaction request.
在步骤S630中,调用所述智能合约将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配。In step S630, the smart contract is invoked to match the first business party identifier, the first requester information and the first passed parameter hash value with the transaction execution table.
节点设备接收到第二交易请求之后,会将第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值与交易执行表进行匹配。具体的匹配方式可以参照上述节点设备将第一交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值与交易执行表进行匹配。After the node device receives the second transaction request, it will match the first business party identifier, first requester information, and first parameter hash value carried in the second transaction request with the transaction execution table. For a specific matching method, refer to the above-mentioned node device to match the first business party identifier, first requester information, and first parameter hash value carried in the first transaction request with the transaction execution table.
在步骤S640中,若所述交易执行表与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值不匹配,则调用所述智能合约获取所述第二交易请求的第二交易执行结果。In step S640, if the transaction execution table does not match the first business party identifier, the first requester information, and the first parameter hash value, call the smart contract to obtain the first The second transaction execution result of the second transaction request.
本公开实施例中,若交易执行表与第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值匹配,则类似于上述第一交易请求,说明在第二交易请求之前,已经执行过与第二交易请求相同的业务,此时可以直接返回历史上成功执行的与第二交易请求相同的业务的目标交易执行结果和目标交易哈希值,而不需要执行第二交易请求。In the embodiment of the present disclosure, if the transaction execution table matches the first business party ID, first requester information, and first parameter hash value carried in the second transaction request, similar to the above-mentioned first transaction request, the description in Before the second transaction request, the same business as the second transaction request has been executed. At this time, the target transaction execution result and target transaction hash value of the same business as the second transaction request successfully executed in history can be directly returned without the need Execute the second transaction request.
在一些实施例中,交易执行表与第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值不匹配,可以是交易执行表中不存在与第二交易请求携带的第一业务方标识匹配的目标业务方标识,或者交易执行表中不存在与第二交易请求携带的第一请求方信息匹配的目标请求方信息,或者交易执行表中不存在与第二交易请求携带的第一传参哈希值匹配的目标传参哈希值。In some embodiments, the transaction execution table does not match the first business party ID, first requester information, and first parameter hash value carried in the second transaction request. It may be that the transaction execution table does not exist in the second transaction The first business party ID carried in the request matches the target business party ID, or there is no target requester information matching the first requester information carried in the second transaction request in the transaction execution table, or the transaction execution table does not exist in the transaction execution table. The target parameter hash value that matches the first parameter hash value carried in the second transaction request.
在另一些实施例中,节点设备可以根据第二交易请求携带的第一业务方标识生成第一平台方标识,交易执行表与第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值不匹配,可以是交易执行表中不存在与第二交易请求携带的第一业务方标识匹配的目标业务方标识,或者交易执行表中不存在与第一平台方标识匹配的目标平台方标识,或者交易执行表中不存在与第二交易请求携带的第一请求方信息匹配的目标请求方信息,或者交易执行表中不存在与第二交易请求携带的第一传参哈希值匹配的目标传参哈希值。In some other embodiments, the node device may generate the first platform party ID according to the first business party ID carried in the second transaction request, and the transaction execution table and the first business party ID and first requester information carried in the second transaction request If the hash value of the first passed parameter does not match, it may be that there is no target business party ID matching the first business party ID carried in the second transaction request in the transaction execution table, or there is no target business party ID matching the first platform party ID in the transaction execution table. ID matching target platform party ID, or there is no target requester information matching the first requester information carried in the second transaction request in the transaction execution table, or the first requester information carried in the second transaction request does not exist in the transaction execution table The target parameterized hash value that the parameterized hash value matches.
在又一些实施例中,节点设备可以根据第二交易请求携带的第一业务方标识生成第一平台方标识,再根据第一业务方标识和第一平台方标识生成第一数据实体标识,交易执行表与第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值不匹配,可以是交易执行表中不存在与第二交易请求的第一数据实体标识匹配的目标数据实体标识,或者交易执行表中不存在与第二交易请求携带的第一请求方信息匹配的目标请求方信息,或者交易执行表中不存在与第二交易请求携带的第一传参哈希值匹配的目标传参哈希值。In some other embodiments, the node device may generate the first platform party ID according to the first business party ID carried in the second transaction request, and then generate the first data entity ID according to the first business party ID and the first platform party ID, and the transaction The execution table does not match the first business party ID, the first requester information, and the first parameter hash value carried in the second transaction request. It may be that the first data entity ID of the second transaction request does not exist in the transaction execution table. Matching target data entity identifier, or there is no target requestor information matching the first requestor information carried in the second transaction request in the transaction execution table, or the first requestor information carried in the second transaction request does not exist in the transaction execution table The hash value of the target passed parameter that the parameter hash value matches.
在再一些实施例中,节点设备可以根据第二交易请求携带的第一业务方标识生成第一平台方标识,再根据第一业务方标识和第一平台方标识生成第一数据实体标识,再根据第一数据实体标识、第一请求方信息和第一传参哈希值生成第一交易执行表唯一键,交易执行表与第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值不匹配,可以是交易执行表中不存在与第二交易请求的第一交易执行表唯一键匹配的目标交易执行表唯一键。In some other embodiments, the node device may generate the first platform party ID according to the first business party ID carried in the second transaction request, and then generate the first data entity ID according to the first business party ID and the first platform party ID, and then Generate the unique key of the first transaction execution table according to the first data entity identifier, the first requester information and the first parameter hash value, and the transaction execution table and the first business party identifier and first requester information carried in the second transaction request If the hash value of the first passed parameter does not match, it may be that there is no unique key of the target transaction execution table matching the unique key of the first transaction execution table of the second transaction request in the transaction execution table.
在示例性实施例中,调用所述智能合约获取所述第二交易请求的第二交易执行结果,可包括:验证所述第二交易请求的合法性;若所述第二交易请求具有合法性,则生成包括所述第二交易请求的第二区块;将所述第二区块添加至对应的区块链;若所述第二区块上链成功,则调用所述智能合约执行所述第二交易请求;若成功执行所述第二交易请求,则所述第二交易执行结果为成功执行所述第二交易请求。In an exemplary embodiment, calling the smart contract to obtain the second transaction execution result of the second transaction request may include: verifying the legitimacy of the second transaction request; if the second transaction request is legal , then generate a second block including the second transaction request; add the second block to the corresponding block chain; if the second block is successfully linked, call the smart contract to execute the The second transaction request; if the second transaction request is successfully executed, the second transaction execution result is the successful execution of the second transaction request.
第二交易请求的合法性的验证方式可以参照上述第一交易请求的合法性的验证过程。For the method of verifying the legitimacy of the second transaction request, refer to the process of verifying the legitimacy of the first transaction request above.
需要说明的是,虽然本公开实施例以先将具有合法性的交易请求(包括第一交易请求和第二交易请求)上链,然后由节点设备调用智能合约执行上链后的交易请求获得交易执行结果(包括第一交易执行结果、第二交易执行结果和目标交易执行结果)为例进行举例说明,但本公开并不限定于此。It should be noted that although the embodiment of the present disclosure first puts the legal transaction request (including the first transaction request and the second transaction request) on the chain, and then the node device calls the smart contract to execute the transaction request after the chain to obtain the transaction The execution result (including the first transaction execution result, the second transaction execution result and the target transaction execution result) is described as an example, but the present disclosure is not limited thereto.
在其他实施例中,节点设备也可以在验证交易请求具有合法性后,先执行交易请求获得对应的交易执行结果,然后打包交易请求对应的交易执行结果生成新的区块再上链。In other embodiments, the node device may also execute the transaction request to obtain the corresponding transaction execution result after verifying the legitimacy of the transaction request, and then package the transaction execution result corresponding to the transaction request to generate a new block and then upload it to the chain.
在另一些实施例中,节点设备也可以在验证交易请求具有合法性后,将具有合法性的交易请求上链,然后对应的终端例如第二终端202从区块链上拉取该交易请求对应的区块,由第二终端202执行拉取的区块中的交易请求,获得对应的交易执行结果,然后,第二终端202将交易执行结果作为交易数据上传至区块链网络,区块链网络中的节点设备将包括交易执行结果的交易数据打包进区块然后上链。例如,若区块中的交易请求涉及到转账,则第二终端202可以是银行机构。In some other embodiments, the node device may also upload the legal transaction request to the blockchain after verifying that the transaction request is legal, and then the corresponding terminal such as the second terminal 202 pulls the corresponding transaction request from the blockchain. block, the second terminal 202 executes the transaction request in the pulled block to obtain the corresponding transaction execution result, and then, the second terminal 202 uploads the transaction execution result to the blockchain network as transaction data, and the blockchain Node devices in the network pack transaction data including transaction execution results into blocks and then upload them to the chain. For example, if the transaction request in the block involves money transfer, the second terminal 202 may be a banking institution.
在示例性实施例中,调用所述智能合约获取所述第二交易请求的第二交易执行结果,还可包括:若所述第二区块上链失败,或者,所述第二区块上链成功且执行所述第二交易请求失败,则所述第二交易执行结果为执行所述第二交易请求失败。In an exemplary embodiment, invoking the smart contract to obtain the second transaction execution result of the second transaction request may further include: if the second block chaining fails, or, If the chain is successful and the execution of the second transaction request fails, then the execution result of the second transaction is that the execution of the second transaction request fails.
其中,所述方法还可包括:若所述第二交易执行结果为执行所述第二交易请求失败,则回滚所述第二交易请求中成功执行的交易操作;将所述第二交易执行结果返回至所述第一请求方的终端设备。Wherein, the method may further include: if the execution result of the second transaction is that the execution of the second transaction request fails, rolling back the successful execution of the transaction operation in the second transaction request; executing the second transaction The result is returned to the terminal device of the first requesting party.
当在区块链上执行多个交易操作时,可能出现部分交易操作成功、部分交易操作失败的情况,多个交易操作不具有一致性,会降低区块链上交易数据的准确性。When multiple transaction operations are performed on the blockchain, some transaction operations may succeed and some transaction operations may fail. Multiple transaction operations are not consistent, which will reduce the accuracy of transaction data on the blockchain.
区块链具有事务性特点,即当多个交易操作在区块链上执行,且这多个交易操作中部分交易操作执行成功,部分交易操作执行失败时,将执行成功的交易操作进行回滚,使得区块链可以回到执行第二交易请求之前的状态,保证区块链上多个交易操作具有一致性和原子性,避免区块链上出现不准确的交易数据,进而提高区块链的稳定性。The blockchain has transactional characteristics, that is, when multiple transaction operations are executed on the blockchain, and some of the transaction operations in the multiple transaction operations are successfully executed, and some of the transaction operations fail to execute, the successful transaction operations will be rolled back , so that the blockchain can return to the state before the execution of the second transaction request, ensuring the consistency and atomicity of multiple transaction operations on the blockchain, avoiding inaccurate transaction data on the blockchain, and improving the blockchain stability.
具体地,节点设备获取第二交易请求,在区块链上执行第二交易请求对应的至少一个交易操作,当至少一个交易操作中存在任一个操作失败时,对操作成功的交易操作执行回滚处理。下面以至少一个交易操作包括第一交易操作和第二交易操作为例进行举例说明。Specifically, the node device acquires the second transaction request, executes at least one transaction operation corresponding to the second transaction request on the blockchain, and when any operation fails in at least one transaction operation, rollback is performed on the successful transaction operation deal with. The following takes an example where at least one transaction operation includes a first transaction operation and a second transaction operation as an example for illustration.
第一交易操作和第二交易操作可以包括:区块链上的电子资源转移操作,区块链上的消费凭证信息(可以实现消费发票)转移操作,区块链上的鉴权证明操作,区块链上的物流防伪追溯证明操作,以及与区块链相关联的记录表的调整操作等中的至少一个。The first transaction operation and the second transaction operation may include: electronic resource transfer operation on the block chain, transfer operation of consumption certificate information (which can realize consumption invoice) on the block chain, authentication proof operation on the block chain, area At least one of the logistics anti-counterfeit traceability certification operation on the block chain, and the adjustment operation of the record table associated with the block chain.
电子资源或消费凭证信息的转移操作是指将电子资源在区块链上的账户之间进行转移;鉴权证明操作是指将权益证明文件等添加至区块链上(登记),后续可以从区块链上查询权益;物流防伪追溯证明操作是指商品生产到销售过程都被记录至区块链上,依赖于区块链的数据不可篡改性,保证已销售出去的商品信息被永久记录,实现商品从生产到销售的整个过程都有迹可循;交易记录表的调整操作是指在交易记录表中调整区块链上所有账户的剩余资源量。The transfer operation of electronic resources or consumption certificate information refers to the transfer of electronic resources between accounts on the blockchain; the operation of authentication certification refers to the addition of rights and interests certification documents to the blockchain (registration), and subsequent transactions can be made from Query rights and interests on the block chain; logistics anti-counterfeiting traceability certification operation means that the production and sales process of goods are recorded on the block chain, relying on the data of the block chain cannot be tampered with, ensuring that the information of the sold goods is permanently recorded, The entire process from production to sales of goods can be traced; the adjustment operation of the transaction record table refers to the adjustment of the remaining resources of all accounts on the blockchain in the transaction record table.
例如,第一交易操作是电子资源转移操作,第二交易操作是权益证明文件上链操作,就是用户在区块链上支付一定的电子资源,可以在区块链上保存自己的权益证明文件。又或者,第一交易操作是资源数据转移操作,第二交易操作是商品物流上链操作,就是用户在区块链上支付一定的电子资源,可以在区块链上保存商品的物流轨迹,生产视频等。For example, the first transaction operation is an electronic resource transfer operation, and the second transaction operation is an equity certificate file on-chain operation, that is, the user pays a certain amount of electronic resources on the blockchain, and can save his own equity certificate file on the blockchain. Or, the first transaction operation is a resource data transfer operation, and the second transaction operation is a commodity logistics on-chain operation, that is, the user pays a certain amount of electronic resources on the blockchain, and the logistics track of the commodity can be saved on the blockchain, and the production video etc.
下面以第一交易操作和第二交易操作分别为转移操作和调整操作为例进行说明:The following takes the first transaction operation and the second transaction operation as a transfer operation and an adjustment operation as an example for illustration:
其中,当第一交易操作和第二交易操作中存在任一个操作失败时,对操作成功的交易操作执行回滚处理,可包括:当第一交易操作是操作失败的交易操作,且第二交易操作是操作成功的交易操作时,将第二交易操作作为目标交易操作;当第二交易操作是操作失败的交易操作,且第一交易操作是操作成功的交易操作时,将第一交易操作作为目标交易操作;对目标交易操作执行回滚处理。目标交易操作包括目标交易量和目标交易账户。目标交易账户包括转出账户和转入账户。下面均以第二交易操作为目标交易操作为例进行举例说明。Wherein, when any one of the first transaction operation and the second transaction operation fails, performing rollback processing on the successful transaction operation may include: when the first transaction operation is a failed transaction operation, and the second transaction operation When the operation is a successful transaction operation, take the second transaction operation as the target transaction operation; when the second transaction operation is a failed transaction operation, and the first transaction operation is a successful transaction operation, take the first transaction operation as Target transaction operation; perform rollback processing on the target transaction operation. The target trading operation includes a target trading volume and a target trading account. Target transaction accounts include transfer-out accounts and transfer-in accounts. In the following, the second transaction operation is taken as the target transaction operation as an example for illustration.
例如,假设目标交易操作包括转移操作(第一交易操作)和调整操作(第二交易操作),转移操作是指在区块链上转移与目标交易量等量的资源数据,调整操作是指在与区块链关联的交易记录表中调整目标交易账户的剩余资源量,交易记录表用于记录区块链上的所有交易账户的剩余资源量。For example, assume that the target transaction operation includes a transfer operation (the first transaction operation) and an adjustment operation (the second transaction operation). The remaining resources of the target transaction account are adjusted in the transaction record table associated with the blockchain, and the transaction record table is used to record the remaining resources of all transaction accounts on the blockchain.
其中,对目标交易操作执行回滚处理,可包括:将存储在目标区块中的目标交易记录进行作废处理,目标区块属于区块链,目标区块是执行转移操作生成的区块;根据目标交易量,在交易记录表中更新目标交易账户的剩余资源量;更新后的目标交易账户的剩余资源量与执行调整操作前的目标交易账户的剩余资源量相同。Among them, performing rollback processing on the target transaction operation may include: invalidating the target transaction record stored in the target block, the target block belongs to the block chain, and the target block is a block generated by executing the transfer operation; according to For the target transaction volume, update the remaining resources of the target transaction account in the transaction record table; the remaining resources of the updated target transaction account are the same as the remaining resources of the target transaction account before the adjustment operation is performed.
例如,如图2所示,假设4个节点设备都会存储一条区块链。如图3所示,区块链中假设已经包括3个区块。For example, as shown in Figure 2, it is assumed that all four node devices will store a blockchain. As shown in Figure 3, it is assumed that 3 blocks have been included in the blockchain.
节点设备获取区块链上的第二交易请求,假设第二交易请求所请求的是从区块链上的账户1(转出账户)向账户2(转入账户)转移数量为10(目标交易量)的电子资源。The node device obtains the second transaction request on the blockchain, assuming that what the second transaction request requests is to transfer an amount of 10 (target transaction) from account 1 (transfer-out account) to account 2 (transfer-in account) on the blockchain volume) of electronic resources.
节点设备判断账户1和账户2是否是区块链上的账户,当前区块链的长度是否达到最大存储容量(即,是否还能再向区块链中写入数据)等等。若判断出账户1和账户2是区块链上的账户,且判断出当前区块链的长度未达到最大存储容量,节点设备可以从交易记录表中获取转出账户的当前剩余资源量,若转出账户的当前剩余资源量不小于目标交易量,则可以生成与第二交易请求对应的目标交易记录。The node device judges whether account 1 and account 2 are accounts on the blockchain, whether the length of the current blockchain reaches the maximum storage capacity (that is, whether data can be written into the blockchain), and so on. If it is judged that account 1 and account 2 are accounts on the blockchain, and it is judged that the length of the current blockchain has not reached the maximum storage capacity, the node device can obtain the current remaining resource amount of the transferred account from the transaction record table, if If the current remaining resource amount of the transfer-out account is not less than the target transaction amount, a target transaction record corresponding to the second transaction request may be generated.
若转出账户的当前剩余资源量小于目标交易量,或者区块链上根本就不存在转出账户或转入账户,说明当前不满足电子资源转移条件,可以确定第一交易操作执行失败,进而说明第二交易请求执行失败,可以停止第二交易请求中其他还未开始执行的交易操作。If the current remaining resource amount of the transfer-out account is less than the target transaction amount, or there is no transfer-out account or transfer-in account on the blockchain, it means that the current electronic resource transfer condition is not met, and it can be determined that the first transaction operation failed, and then Indicates that the execution of the second transaction request failed, and other transaction operations in the second transaction request that have not yet started to be executed can be stopped.
例如,从交易记录表中查询到账户1的当前剩余资源量等于40,因此账户1的当前剩余资源量大于目标交易量10,则从账户1向账户2转入数量为10的电子资源,可以生成目标交易记录:(转出地址:账户1;转入地址:账户2;资源量:10),第一交易操作执行成功,在区块链上将转移电子资源的目标交易记录存储至区块链上。For example, if it is found from the transaction record table that the current remaining resource amount of account 1 is equal to 40, so the current remaining resource amount of account 1 is greater than the target transaction amount of 10, then transfer 10 electronic resources from account 1 to account 2, you can Generate the target transaction record: (transfer-out address: account 1; transfer-in address: account 2; resource amount: 10), the first transaction operation is successfully executed, and the target transaction record for transferring electronic resources is stored in the block chain chain.
将上述目标交易记录存储至区块体,计算目标交易记录的默克尔根,获取当前区块链的最后一个区块(即第3个区块)的哈希散列值以及当前时间戳,将默克尔根、最后一个区块的哈希散列值以及当前时间戳存储至区块头,将上述区块头以及存储了目标交易记录的区块体组合为目标区块,将新生成的目标添加到区块链中。一旦将目标交易记录添加至区块链上,就证明完成了对电子资源的转移操作,即成功执行了第一交易操作。Store the above target transaction record in the block body, calculate the Merkle root of the target transaction record, obtain the hash value of the last block (that is, the third block) of the current blockchain and the current timestamp, Store the Merkle root, the hash value of the last block and the current timestamp in the block header, combine the above block header and the block body storing the target transaction records into the target block, and store the newly generated target added to the blockchain. Once the target transaction record is added to the block chain, it proves that the transfer operation of the electronic resource is completed, that is, the first transaction operation is successfully executed.
第一交易操作执行成功后,区块链就包括了4个区块,最后一个区块是新生成的目标区块,目标区块中存储了第一交易操作对应的目标交易记录。After the first transaction operation is successfully executed, the blockchain includes 4 blocks, the last block is a newly generated target block, and the target transaction record corresponding to the first transaction operation is stored in the target block.
若判断出账户1或者账户2在区块链上根本不存在,或者判断出当前区块链的长度已经达到最大存储容量,或者判断出账户1的当前剩余资源量小于10,则表明第一交易操作执行失败。If it is judged that account 1 or account 2 does not exist on the blockchain at all, or it is judged that the length of the current blockchain has reached the maximum storage capacity, or it is judged that the current remaining resource of account 1 is less than 10, it indicates that the first transaction Operation execution failed.
第二交易操作可以与第一交易操作可以并行执行,也可以串行执行,即先执行第一交易操作之后再执行第二交易操作,或者先执行第二交易操作再执行第一交易操作,可以根据第一交易操作和第二交易操作之间是否存在依赖关系来确定。The second transaction operation can be executed in parallel with the first transaction operation, or it can be executed in series, that is, the first transaction operation is executed first and then the second transaction operation is executed, or the second transaction operation is executed first and then the first transaction operation is executed. It is determined according to whether there is a dependency relationship between the first transaction operation and the second transaction operation.
若交易记录表中存在转出账户和转入账户,且转出账户的当前剩余资源量不小于目标交易量,根据第二交易请求调整转出账户的剩余资源量和转入账户的剩余资源量。If there are transfer-out accounts and transfer-in accounts in the transaction record table, and the current remaining resources of the transfer-out account are not less than the target transaction amount, adjust the remaining resources of the transfer-out account and the remaining resources of the transfer-in account according to the second transaction request .
例如,还是假设第二交易请求为:请求将资源量为10的电子资源从账户1转移至账户2,从交易记录表中查询到账户1的当前剩余资源量为40,账户2的当前剩余资源量为20,调整操作即第二交易操作即是在交易记录表中将账户1的剩余资源量调整为40-10=30,在交易记录表中将账户2的剩余资源量调整为20+10=30。For example, assume that the second transaction request is: a request to transfer electronic resources with a resource amount of 10 from account 1 to account 2, and it is found from the transaction record table that the current remaining resource amount of account 1 is 40, and the current remaining resource amount of account 2 is The amount is 20, the adjustment operation, that is, the second transaction operation, is to adjust the remaining resource amount of account 1 to 40-10=30 in the transaction record table, and adjust the remaining resource amount of account 2 to 20+10 in the transaction record table =30.
此时,若第一交易操作执行成功,但第二交易操作执行失败,节点设备需要对执行成功的交易操作(即第一交易操作)进行回滚。对第一交易操作进行回滚的具体过程为:由于成功执行了第一交易操作后,对应的目标交易记录1已经被存储在区块链上,因此需要将区块链上的目标交易记录作废,若目标区块中只存储了目标交易记录而没有存储其他交易记录,还可以进一步地将新生成的目标区块设置为无效区块。At this time, if the execution of the first transaction operation is successful, but the execution of the second transaction operation fails, the node device needs to roll back the successful execution of the transaction operation (that is, the first transaction operation). The specific process of rolling back the first transaction operation is as follows: After the first transaction operation is successfully executed, the corresponding target transaction record 1 has been stored on the blockchain, so the target transaction record on the blockchain needs to be invalidated , if only the target transaction record is stored in the target block and no other transaction records are stored, the newly generated target block can be further set as an invalid block.
或者,节点设备根据第二交易请求再生成新的交易请求(称为回滚交易请求),回滚交易请求中的交易账户以及交易量和第二交易请求中的目标交易账户和目标交易量完全相同,不同之处在于第二交易请求中的转入账户是回滚交易请求中的转出账户,第二交易请求中的转出账户是回滚交易请求中的转入账户。Or, the node device regenerates a new transaction request (called a rollback transaction request) according to the second transaction request, and the transaction account and transaction volume in the rollback transaction request are completely equal to the target transaction account and target transaction volume in the second transaction request. The same, except that the transfer-in account in the second transaction request is the transfer-out account in the rollback transaction request, and the transfer-out account in the second transaction request is the transfer-in account in the rollback transaction request.
例如,第二交易请求为:请求将资源量为10的电子资源从账户1转移至账户2,回滚交易请求为:请求将资源量为10的电子资源从账户2转移至账户1。For example, the second transaction request is: a request to transfer electronic resources with a resource amount of 10 from account 1 to account 2, and the rollback transaction request is: a request to transfer electronic resources with a resource amount of 10 from account 2 to account 1.
节点设备可以执行回滚交易请求对应的交易操作,执行完回滚交易请求对应的交易操作后,所达到的效果等同于对第一交易操作中的转移操作进行了回滚处理。The node device can execute the transaction operation corresponding to the rollback transaction request. After executing the transaction operation corresponding to the rollback transaction request, the effect achieved is equivalent to performing rollback processing on the transfer operation in the first transaction operation.
分析知道,若不对第一交易操作进行回滚,相当于账户2中凭空出现了数量为10的电子资源,或者说在区块链上凭空出现了数量为10的电子资源,这种由于多个交易操作不具有一致性所凭空出现的电子资源,就是区块链上的不正确的交易数据,可见不正确的交易数据会破坏区块链的稳定性。The analysis shows that if the first transaction operation is not rolled back, it is equivalent to the number of 10 electronic resources appearing out of thin air in Account 2, or the number of 10 electronic resources appearing out of thin air on the blockchain. The electronic resources that appear out of thin air due to the inconsistency of transaction operations are incorrect transaction data on the blockchain. It can be seen that incorrect transaction data will destroy the stability of the blockchain.
后续基于区块链统计账户1的剩余资源量和账户2的剩余资源量时,由于第一交易操作是无效区块,且第一交易操作的目标交易记录是无效交易记录,因此遍历区块链中的所有区块时,可以不必遍历目标区块;或者遍历区块链中的所有区块时,可以不将目标区块中的目标交易记录纳入统计范围内。Subsequent statistics on the remaining resources of account 1 and account 2 based on the blockchain, since the first transaction operation is an invalid block, and the target transaction record of the first transaction operation is an invalid transaction record, the block chain is traversed When traversing all blocks in the block chain, it is not necessary to traverse the target block; or when traversing all blocks in the blockchain, the target transaction records in the target block may not be included in the statistical range.
若第二交易操作执行成功,但第一交易操作执行失败,节点设备需要对执行成功的交易操作(即第二交易操作)进行回滚。对第二交易操作进行回滚的具体过程为:If the execution of the second transaction operation is successful, but the execution of the first transaction operation fails, the node device needs to roll back the successful execution of the transaction operation (that is, the second transaction operation). The specific process of rolling back the second transaction operation is:
节点设备获取第二交易请求中的目标交易量,根据该目标交易量在交易记录表中更新目标交易账户的剩余资源量,使得更新后的目标交易账户的剩余资源量与执行调整操作前的目标交易账户的剩余资源量相同。The node device acquires the target transaction amount in the second transaction request, and updates the remaining resource amount of the target transaction account in the transaction record table according to the target transaction amount, so that the updated remaining resource amount of the target transaction account is the same as the target amount before the adjustment operation is performed. The trading account has the same amount of remaining resources.
例如,第二交易请求为:请求将资源量为10的电子资源从账户1转移至账户2,执行调整操作前,账户1的剩余资源量等于20,账户2的剩余资源量等于30,成功执行调整操作后,账户1的剩余资源量等于20-10=10,账户2的剩余资源量等于30+10=40,对该调整操作进行回滚处理即是,再将账户1的剩余资源量调整回20:30-10=20,将账户2的剩余资源量调整回30:40-10=30。For example, the second transaction request is: request to transfer electronic resources with a resource amount of 10 from account 1 to account 2. Before the adjustment operation is performed, the remaining resource amount of account 1 is equal to 20, and the remaining resource amount of account 2 is equal to 30, which is successfully executed After the adjustment operation, the remaining resource amount of account 1 is equal to 20-10=10, and the remaining resource amount of account 2 is equal to 30+10=40. The adjustment operation is rolled back, and then the remaining resource amount of account 1 is adjusted Back to 20:30-10=20, adjust the remaining resources of account 2 back to 30:40-10=30.
上述可知,虽然第二交易请求执行失败了,对区块链以及区块链上的账户1和账户2来说,相当于回到了第二交易请求未执行之前的状态,即未从账户1转出电子资源,也未将电子资源转入账户2,多个交易操作具有一致性和原子性,能够保证区块链上的交易数据的准确性和完整性。It can be seen from the above that although the execution of the second transaction request failed, for the blockchain and account 1 and account 2 on the blockchain, it is equivalent to returning to the state before the second transaction request was not executed, that is, the transfer from account 1 to The electronic resources have not been transferred to the account 2, and multiple transaction operations are consistent and atomic, which can ensure the accuracy and integrity of the transaction data on the blockchain.
需要说明的是,执行第二交易请求的过程中可以包括多个交易操作(例如,转移操作和调整操作),只有这多个交易操作都执行成功,才确定该第二交易请求执行成功,反之一旦存在至少一个交易操作执行失败,就确定该第二交易请求执行失败。It should be noted that the process of executing the second transaction request may include multiple transaction operations (for example, a transfer operation and an adjustment operation), and only when all these multiple transaction operations are executed successfully can the execution of the second transaction request be determined to be successful, and vice versa Once at least one transaction operation fails to execute, it is determined that the execution of the second transaction request fails.
当第一交易操作和第二交易操作中存在任一个操作失败时,对操作成功的交易操作执行回滚处理,执行回滚处理可以保证在区块链上的多个操作具有一致性,使得区块链可以回到执行第一交易操作和第二交易操作之前的状态,避免区块链上出现不准确的交易数据,提高区块链的稳定性。When any one of the first transaction operation and the second transaction operation fails, rollback processing is performed on the successful transaction operation. Performing rollback processing can ensure the consistency of multiple operations on the blockchain, making the block The block chain can return to the state before the execution of the first transaction operation and the second transaction operation, avoiding inaccurate transaction data on the block chain, and improving the stability of the block chain.
在步骤S650中,若所述第二交易执行结果为成功执行所述第二交易请求,则将所述第二交易执行结果作为所述目标交易执行结果,并获取所述第二交易请求的目标交易哈希值。In step S650, if the second transaction execution result is the successful execution of the second transaction request, use the second transaction execution result as the target transaction execution result, and obtain the target of the second transaction request Transaction hash.
本公开实施例中,目标交易执行结果中可以包括表明第二交易请求执行成功的指示信息,例如“1”表示第二交易请求执行成功,“0”表示第二交易请求执行失败,但本公开并不限定于此。在另一些实施例中,目标交易执行结果中还可以包括成功执行第二交易请求之后的具体的返回值。In the embodiment of the present disclosure, the target transaction execution result may include indication information indicating that the second transaction request is executed successfully, for example, "1" indicates that the second transaction request is executed successfully, and "0" indicates that the second transaction request fails to be executed, but the present disclosure It is not limited to this. In some other embodiments, the target transaction execution result may also include a specific return value after the second transaction request is successfully executed.
本公开实施例中,对节点设备如何获得第二交易请求的目标交易哈希值不做限定。In the embodiment of the present disclosure, there is no limitation on how the node device obtains the target transaction hash value of the second transaction request.
在一些实施例中,节点设备可以采用哈希函数对第二交易请求进行运算,获得目标交易哈希值。In some embodiments, the node device may use a hash function to perform operations on the second transaction request to obtain a target transaction hash value.
在另一些实施例中,若第一终端201在生成第二交易请求时,对第二交易请求进行哈希运算,得到第二交易请求的第二交易哈希值,并采用私钥对第二交易请求的哈希值进行加密,得到携带第一终端201的签名的第二交易请求,然后将第二交易请求和携带第一终端的签名的第二交易请求一起发送至区块链网络的节点设备,则节点设备在接收到第二交易请求和携带第一终端的签名的第二交易请求后,可以获取第一终端201的公钥,节点设备采用公钥对携带第一终端的签名的第二交易请求进行解密,获得目标交易哈希值。In some other embodiments, if the first terminal 201 performs a hash operation on the second transaction request when generating the second transaction request, obtains the second transaction hash value of the second transaction request, and uses the private key to pair the second The hash value of the transaction request is encrypted to obtain the second transaction request carrying the signature of the first terminal 201, and then the second transaction request and the second transaction request carrying the signature of the first terminal are sent to the nodes of the blockchain network device, the node device can obtain the public key of the first terminal 201 after receiving the second transaction request and the second transaction request carrying the signature of the first terminal, and the node device uses the public key to pair the second transaction request carrying the signature of the first terminal The second transaction request is decrypted to obtain the target transaction hash value.
在步骤S660中,调用所述智能合约将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值关联存储至所述交易执行表中。In step S660, the smart contract is invoked to generate the first business party ID, the first requester information, the first parameter hash value, the target transaction execution result, and the target transaction hash value Value associations are stored in the transaction execution table.
本公开实施例中,在成功执行第二交易请求之后,可以将第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值及其对应的目标交易执行结果和目标交易哈希值存储至交易执行表中,以用于对后续接收到的与第二交易请求针对的是相同业务的交易请求进行去重过滤,防止重复执行,保证幂等性。In the embodiment of the present disclosure, after the second transaction request is successfully executed, the first business party identification, first requester information, first parameter hash value and the corresponding target transaction execution result carried in the second transaction request can be and the target transaction hash value are stored in the transaction execution table, which is used to de-duplicate and filter subsequent received transaction requests for the same business as the second transaction request, to prevent repeated execution, and to ensure idempotence.
在一些实施例中,将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值关联存储至所述交易执行表中,可以是直接将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值存储至交易执行表中,第一业务方标识作为目标业务方标识,第一请求方信息作为目标请求方信息,第一传参哈希值作为目标传参哈希值。In some embodiments, the first business party identifier, the first requester information, the first parameter hash value, the target transaction execution result, and the target transaction hash value are associated and stored in In the transaction execution table, the first business party identifier, the first requester information, the first parameter hash value, the target transaction execution result, and the target transaction hash value may be directly The value is stored in the transaction execution table, the first business party ID is used as the target business party ID, the first requester information is used as the target requester information, and the first passed parameter hash value is used as the target passed parameter hash value.
在另一些实施例中,节点设备可以根据第二交易请求中的第一业务方标识生成第二交易请求的第一平台方标识。其中,将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值关联存储至所述交易执行表中,可以将第二交易请求的所述第一业务方标识、第一平台方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值存储至交易执行表中,第一业务方标识作为目标业务方标识,第一平台方标识作为目标平台方标识,第一请求方信息作为目标请求方信息,第一传参哈希值作为目标传参哈希值。In some other embodiments, the node device may generate the first platform party identifier of the second transaction request according to the first business party identifier in the second transaction request. Wherein, the first business party identifier, the first requester information, the first parameter hash value, the target transaction execution result and the target transaction hash value are associated and stored in the transaction execution In the table, the first business party ID, the first platform party ID, the first requester information, the first parameter hash value, the target transaction execution result and the The target transaction hash value is stored in the transaction execution table, the first business party ID is used as the target business party ID, the first platform party ID is used as the target platform party ID, the first requester information is used as the target requester information, and the first parameter The hash value is passed as the hash value of the target parameter.
在又一些实施例中,节点设备可以根据第二交易请求携带的第一业务方标识生成第一平台方标识,再根据第一业务方标识和第一平台方标识生成第一数据实体标识。将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值关联存储至所述交易执行表中,可以将第二交易请求的第一数据实体标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值存储至交易执行表中,第一数据实体标识作为目标数据实体标识,第一请求方信息作为目标请求方信息,第一传参哈希值作为目标传参哈希值。In some other embodiments, the node device may generate the first platform party ID according to the first business party ID carried in the second transaction request, and then generate the first data entity ID according to the first business party ID and the first platform party ID. Store the first business party identifier, the first requester information, the first parameter hash value, the target transaction execution result, and the target transaction hash value in the transaction execution table , the first data entity identifier of the second transaction request, the first requester information, the first parameter hash value, the target transaction execution result, and the target transaction hash value can be stored in the transaction execution In the table, the first data entity identifier is used as the target data entity identifier, the first requester information is used as the target requester information, and the first passed parameter hash value is used as the target passed parameter hash value.
在再一些实施例中,节点设备可以根据第二交易请求携带的第一业务方标识生成第一平台方标识,再根据第一业务方标识和第一平台方标识生成第一数据实体标识,再根据第一数据实体标识、第一请求方信息和第一传参哈希值生成第一交易执行表唯一键,将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值关联存储至所述交易执行表中,可以将第二交易请求的第一交易执行表唯一键、所述目标交易执行结果和所述目标交易哈希值存储至交易执行表中,第一交易执行表唯一键作为目标交易执行表唯一键。In some other embodiments, the node device may generate the first platform party ID according to the first business party ID carried in the second transaction request, and then generate the first data entity ID according to the first business party ID and the first platform party ID, and then Generate the unique key of the first transaction execution table according to the first data entity identifier, the first requestor information and the first parameter hash value, and combine the first business party identifier, the first requestor information, the first The reference hash value, the target transaction execution result and the target transaction hash value are associated and stored in the transaction execution table, and the unique key of the first transaction execution table of the second transaction request, the target transaction execution The result and the hash value of the target transaction are stored in the transaction execution table, and the unique key of the first transaction execution table is used as the unique key of the target transaction execution table.
在步骤S670中,将所述目标交易执行结果和所述目标交易哈希值返回至所述第一请求方的终端设备,所述目标交易哈希值与所述第二交易请求的第二交易哈希值相同。In step S670, return the target transaction execution result and the target transaction hash value to the terminal device of the first requesting party, the target transaction hash value and the second transaction requested by the second transaction The hashes are the same.
具体的,在第二交易请求未被上传至节点设备101时,第一终端201可对第二交易请求进行哈希运算,得到第二交易请求的第二交易哈希值。当节点设备将成功执行第二交易请求获得的目标交易哈希值返回至第一终端时,第一终端可以将接收到的目标交易哈希值与第二交易哈希值进行比较,若两者一致,则可以判定本次接收到的目标交易执行结果是成功执行第二交易请求返回的,历史上没有执行过与第二交易请求相同的业务。Specifically, when the second transaction request is not uploaded to the
图7示意性示出了根据本公开的一个实施例的基于区块链的数据处理方法的流程示意图。如图7所示,可以包括如下步骤。Fig. 7 schematically shows a schematic flowchart of a blockchain-based data processing method according to an embodiment of the present disclosure. As shown in Fig. 7, the following steps may be included.
在步骤S710中,交易提交。In step S710, the transaction is submitted.
本公开实施例中,交易提交可以是指任意终端设备发送给区块链网络中的节点设备的交易请求,可以包括上述的第一终端201发送给节点设备101的第一交易请求和第二交易请求。In the embodiment of the present disclosure, the transaction submission may refer to the transaction request sent by any terminal device to the node device in the blockchain network, and may include the above-mentioned first transaction request and the second transaction request sent by the first terminal 201 to the
任意终端设备发送给区块链网络中的节点设备的交易请求中均指定了业务方标识,例如上述第一交易请求中指定了第一业务方标识,第二交易请求中也指定了第一业务方标识,以用于区分每次交易请求所针对的操作对象是谁。The business party ID is specified in the transaction request sent by any terminal device to the node device in the blockchain network. For example, the first business party ID is specified in the above-mentioned first transaction request, and the first business party ID is also specified in the second transaction request. The party ID is used to distinguish who is the target of each transaction request.
在步骤S720中,区块链核心(Core)710执行重复交易过滤。In step S720, the blockchain core (Core) 710 performs duplicate transaction filtering.
本公开实施例中,区块链网络接收到任意终端设备发送的交易请求后,可以利用智能合约维护的交易执行表对接收到的交易请求进行重复交易过滤,这里的重复交易过滤是指判断当前接收到的交易请求是否在此之前被成功执行过并记录在交易执行表中,防止针对相同业务的交易请求被重复执行。In the embodiment of the present disclosure, after the blockchain network receives a transaction request sent by any terminal device, it can use the transaction execution table maintained by the smart contract to filter the received transaction request for repeated transactions. The repeated transaction filtering here refers to judging the current Whether the received transaction request has been successfully executed before and recorded in the transaction execution table to prevent repeated execution of transaction requests for the same business.
具体地,上述步骤S720可以进一步包括以下由业务合约720执行的以下步骤。Specifically, the above step S720 may further include the following steps executed by the service contract 720 .
本公开实施例中,业务合约720即上述用于维护交易执行表的智能合约。In the embodiment of the present disclosure, the business contract 720 is the aforementioned smart contract for maintaining the transaction execution table.
在步骤S721中,查询交易执行表。In step S721, query the transaction execution table.
节点设备可以调用业务合约720查询交易执行表,以判断当前接收到的交易请求所针对的业务是否在历史上已经被成功执行过。The node device can call the service contract 720 to query the transaction execution table to determine whether the service targeted by the currently received transaction request has been successfully executed in history.
在步骤S722中,返回历史执行成功交易哈希值和业务结果。In step S722, return history execution successful transaction hash value and business result.
若通过查询交易执行表,获知当前接收到的交易请求已经在历史上被成功执行过,则节点设备可以直接向发送该交易请求的终端设备返回历史执行成功交易哈希值和业务结果。If it is known that the currently received transaction request has been successfully executed in history by querying the transaction execution table, the node device can directly return the historical execution successful transaction hash value and business result to the terminal device that sent the transaction request.
例如,当节点设备接收到第一交易请求时,通过查询发现交易执行表中存在与第一交易请求携带的第一业务方标识、第一请求方信息和第一传入参数(或者第一传参哈希值)匹配的目标业务方标识、目标请求方信息和目标传入参数,可以将交易执行表中与目标业务方标识、目标请求方信息和目标传入参数匹配的目标交易执行结果(业务结果)和目标交易哈希值(历史执行成功交易哈希值)返回给第一终端。For example, when the node device receives the first transaction request, it is found by querying that the transaction execution table contains the first business party identifier, the first requester information and the first incoming parameter (or the first incoming parameter) carried in the first transaction request. reference hash value) matched target business party ID, target requester information and target incoming parameters, the target transaction execution result ( business result) and the target transaction hash value (historical execution successful transaction hash value) are returned to the first terminal.
在步骤S723中,执行业务。In step S723, execute the service.
若通过查询交易执行表,获知当前接收到的交易请求没有在历史上被成功执行过,则节点设备可以执行当前接收到的交易请求所对应的业务。If it is learned that the currently received transaction request has not been successfully executed in history by querying the transaction execution table, the node device can execute the service corresponding to the currently received transaction request.
在步骤S724中,若执行成功,则写入交易执行表。In step S724, if the execution is successful, write the transaction execution table.
例如,当节点设备接收到第二交易请求时,通过查询发现交易执行表中步存在与第二交易请求携带的第一业务方标识、第一请求方信息和第一传入参数(或者第一传参哈希值)匹配的目标业务方标识、目标请求方信息和目标传入参数,则节点设备执行该第二交易请求,获得第二交易请求的目标交易执行结果和目标交易哈希值,并将第二交易请求携带的第一业务方标识、第一请求方信息和第一传参哈希值分别作为目标业务方标识、目标请求方信息和目标传参哈希值,将目标业务方标识、目标请求方信息、目标传参哈希值、目标交易执行结果和目标交易哈希值关联存储至交易执行表中。For example, when the node device receives the second transaction request, it is found by querying the transaction execution table that the first business party identifier, the first requester information and the first incoming parameter (or the first Pass parameter hash value) matching target business party identification, target requester information and target incoming parameters, then the node device executes the second transaction request, and obtains the target transaction execution result and target transaction hash value of the second transaction request, The first business party ID, the first requester information and the first parameter hash value carried in the second transaction request are respectively used as the target business party ID, target requester information and target parameter hash value, and the target business party The identification, target requester information, target parameter hash value, target transaction execution result and target transaction hash value are associated and stored in the transaction execution table.
在步骤S725中,若执行失败或者写入交易执行表失败,则进行失败回滚。In step S725, if the execution fails or the writing into the transaction execution table fails, a failure rollback is performed.
例如,若节点设备没有成功执行第二交易请求,或者将执行成功的第二交易请求的目标业务方标识、目标请求方信息、目标传参哈希值、目标交易执行结果和目标交易哈希值关联存储至交易执行表失败,则进行失败回滚,具体的回滚过程可以参照上述实施例。For example, if the node device does not successfully execute the second transaction request, or will execute the successful second transaction request, the target business party ID, target requester information, target parameter hash value, target transaction execution result and target transaction hash value If the associated storage to the transaction execution table fails, the failure rollback will be performed, and the specific rollback process can refer to the above-mentioned embodiment.
在步骤S726中,返回步骤。具体地为,在步骤S727中,返回当前执行成功交易哈希值和业务结果。In step S726, return to step. Specifically, in step S727, the currently executed successful transaction hash value and business result are returned.
例如,若执行成功,且成功地将第二交易请求的目标业务方标识、目标请求方信息、目标传参哈希值、目标交易执行结果和目标交易哈希值关联存储至交易执行表,则向第一终端返回目标交易执行结果(业务结果)和目标交易哈希值(当前执行成功交易哈希值)。For example, if the execution is successful, and the target business party ID, target requester information, target parameter hash value, target transaction execution result and target transaction hash value of the second transaction request are successfully associated and stored in the transaction execution table, then The target transaction execution result (business result) and the target transaction hash value (currently successfully executed transaction hash value) are returned to the first terminal.
图8示意性示出了根据本公开的一个实施例的基于区块链的数据处理方法的流程示意图。图8实施例提供的方法可以应用于与区块链网络通信的终端设备,区块链网络中部署智能合约,智能合约用于维护交易执行表。Fig. 8 schematically shows a schematic flowchart of a blockchain-based data processing method according to an embodiment of the present disclosure. The method provided by the embodiment in Figure 8 can be applied to a terminal device communicating with a blockchain network, and a smart contract is deployed in the blockchain network, and the smart contract is used to maintain a transaction execution table.
图8实施例提供的方法可以包括以下步骤。The method provided by the embodiment in FIG. 8 may include the following steps.
在步骤S810中,通过第一请求方的终端设备生成第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数。In step S810, a first transaction request is generated by the terminal device of the first requester, and the first transaction request carries the identification of the first business party, the information of the first requester, and the first transaction request for executing the first transaction request. Pass in parameters.
在步骤S820中,通过所述第一请求方的终端设备生成所述第一交易请求的第一交易哈希值。In step S820, a first transaction hash value of the first transaction request is generated by the terminal device of the first requester.
在步骤S830中,通过所述第一请求方的终端设备向所述区块链网络中的节点设备发送所述第一交易请求,以便所述节点设备调用所述智能合约生成所述第一传入参数的第一传参哈希值,将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配。In step S830, the terminal device of the first requester sends the first transaction request to the node device in the blockchain network, so that the node device calls the smart contract to generate the first transaction request The first parameter hash value of the input parameter, and match the first business party identifier, the first requester information, and the first parameter hash value with the transaction execution table.
在步骤S840中,接收所述节点设备返回的目标交易执行结果和目标交易哈希值,其中所述交易执行表中的所述目标交易执行结果和所述目标交易哈希值与目标业务方标识与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配。In step S840, the target transaction execution result and the target transaction hash value returned by the node device are received, wherein the target transaction execution result and the target transaction hash value in the transaction execution table are related to the target business party identification Match the first service party identifier, the first requester information, and the first passed parameter hash value.
在步骤S850中,确定所述目标交易哈希值与所述第一交易哈希值不同。In step S850, it is determined that the target transaction hash value is different from the first transaction hash value.
图9示意性示出了根据本公开的又一个实施例的基于区块链的数据处理方法的流程图。图9实施例提供的方法与上述图8实施例提供的方法之间的区别在于,在上述步骤S810之前,即在通过第一请求方的终端设备生成第一交易请求之前,所述方法还可以进一步包括以下步骤。Fig. 9 schematically shows a flowchart of a blockchain-based data processing method according to yet another embodiment of the present disclosure. The difference between the method provided by the embodiment of FIG. 9 and the method provided by the embodiment of FIG. 8 above is that before the above step S810, that is, before the first transaction request is generated by the terminal device of the first requesting party, the method can also The following steps are further included.
在步骤S910中,通过所述第一请求方的终端设备生成第二交易请求,所述第二交易请求携带所述第一业务方标识、所述第一请求方信息和用于执行所述第二交易请求的第一传入参数。In step S910, a second transaction request is generated by the terminal device of the first requester, and the second transaction request carries the identifier of the first business party, the information of the first requester, and the 2. The first incoming parameter of the transaction request.
在步骤S920中,通过所述第一请求方的终端设备生成所述第二交易请求的第二交易哈希值。In step S920, a second transaction hash value of the second transaction request is generated by the terminal device of the first requester.
在步骤S930中,通过所述第一请求方的终端设备向所述区块链网络中的节点设备发送所述第二交易请求,以便所述节点设备调用所述智能合约生成所述第一传入参数的第一传参哈希值,若所述交易执行表与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值不匹配,则成功执行所述第二交易请求,获得第二交易执行结果和第二交易哈希值,将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述第二交易执行结果和所述第二交易哈希值关联存储至所述交易执行表中,其中所述第二交易执行结果作为所述目标交易执行结果,所述第二交易哈希值作为所述目标交易哈希值。In step S930, the terminal device of the first requester sends the second transaction request to the node device in the blockchain network, so that the node device invokes the smart contract to generate the first transaction request The first passed parameter hash value of the input parameter, if the transaction execution table does not match the first business party identifier, the first requester information and the first passed parameter hash value, then the transaction will be executed successfully The second transaction request is obtained, the second transaction execution result and the second transaction hash value are obtained, and the first business party ID, the first requester information, the first parameter hash value, and the second transaction hash value are obtained. Two transaction execution results and the second transaction hash value are associated and stored in the transaction execution table, wherein the second transaction execution result is used as the target transaction execution result, and the second transaction hash value is used as the Target transaction hash.
在步骤S940中,通过所述第一请求方的终端设备接收所述节点设备返回的所述目标交易执行结果和所述目标交易哈希值。In step S940, the terminal device of the first requester receives the target transaction execution result and the target transaction hash value returned by the node device.
在步骤S950中,确定所述目标交易哈希值与所述第二交易哈希值相同。In step S950, it is determined that the target transaction hash value is the same as the second transaction hash value.
区块链具有数据永久保存,难以篡改,可追溯的特性。同时区块链以交易为单位,通过交易池对上链请求进行管理,理论上任意提交的交易被执行时间是不可预测的,交易也不能被重复提交执行。同时链上操作均是事务性的,要不然一笔交易的执行全部成功,或者全部失败被回滚,不会出现部分操作失败的情景。Blockchain has the characteristics of permanent data storage, difficult to tamper, and traceability. At the same time, the blockchain takes transactions as units, and manages the on-chain requests through the transaction pool. Theoretically, the execution time of any submitted transaction is unpredictable, and the transaction cannot be repeatedly submitted for execution. At the same time, the operations on the chain are all transactional. Otherwise, the execution of a transaction is all successful, or all failures are rolled back, and there will be no scenario where some operations fail.
本公开实施方式提供的基于区块链的数据处理方法,公开了一种基于区块链智能合约的业务请求幂等性问题的解决方案,通过交易执行表保证存在相同业务的多笔交易并发执行的情况下,也只有一笔业务能够执行成功,能够识别不同区块中包括的交易请求对应相同业务,并确保该相同业务的不同交易请求不会被重复性执行。用户可以根据交易请求中携带的业务方标识进行多次上链重试,而无需关心重复上链提交的问题,确保幂等性。通过幂等性保证,业务方在对接区块链网络时,可以避免因为区块链异步上链特性导致的返回超时,或者回包丢失等错误,可通过指定业务方标识进行多次请求重试,减少业务方的开发接入成本。The blockchain-based data processing method provided by the embodiments of the present disclosure discloses a solution to the idempotence problem of business requests based on blockchain smart contracts, and ensures that multiple transactions of the same business are executed concurrently through the transaction execution table In the case where only one business can be executed successfully, it can identify that the transaction requests included in different blocks correspond to the same business, and ensure that different transaction requests of the same business will not be executed repeatedly. Users can retry multiple times on the chain according to the business party ID carried in the transaction request, without worrying about the problem of repeated on-chain submissions to ensure idempotency. Through the guarantee of idempotence, when the business party connects to the blockchain network, it can avoid errors such as return timeout or lost return packets caused by the asynchronous uplink feature of the blockchain, and multiple request retries can be made by specifying the business party ID , to reduce the development access cost of the business side.
以下介绍本公开的相关设备实施例,可以用于执行本公开上述的基于区块链的数据处理方法。对于本公开相关设备实施例中未披露的细节,请参照本公开上述的基于区块链的数据处理方法的实施例。The following introduces related device embodiments of the present disclosure, which can be used to implement the above-mentioned blockchain-based data processing method of the present disclosure. For the details not disclosed in the relevant device embodiments of the present disclosure, please refer to the above embodiments of the blockchain-based data processing method in the present disclosure.
图10示意性示出了根据本公开的一实施例的节点设备的框图。所述节点设备设置于区块链网络中,所述区块链网络中部署智能合约,所述智能合约用于维护交易执行表。Fig. 10 schematically shows a block diagram of a node device according to an embodiment of the present disclosure. The node device is set in a block chain network, and a smart contract is deployed in the block chain network, and the smart contract is used to maintain a transaction execution table.
参照图10所示,根据本公开的一个实施例的节点设备1000可以包括:第一交易请求获取单元1010、第一传参哈希值生成单元1020、交易执行表匹配单元1030以及目标交易执行结果返回单元1040。Referring to FIG. 10 , a
本公开实施例中,第一交易请求获取单元1010可以用于获取第一请求方的终端设备发送的第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数。第一传参哈希值生成单元1020可以用于调用所述智能合约生成所述第一传入参数的第一传参哈希值。交易执行表匹配单元1030可以用于调用所述智能合约将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配。目标交易执行结果返回单元1040可以用于将所述交易执行表中与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备,所述目标交易哈希值与所述第一交易请求的第一交易哈希值不同。In this embodiment of the disclosure, the first transaction request obtaining unit 1010 may be configured to obtain the first transaction request sent by the terminal device of the first requesting party, the first transaction request carrying the first business party identifier, the first requesting party information and The first incoming parameter for executing the first transaction request. The first passed parameter hash value generating unit 1020 may be configured to invoke the smart contract to generate a first passed parameter hash value of the first passed parameter. The transaction execution table matching unit 1030 may be configured to call the smart contract to match the first business party identifier, the first requester information, and the first parameter hash value with the transaction execution table. The target transaction execution result returning unit 1040 may be configured to match the target transaction execution result and The target transaction hash value is returned to the terminal device of the first requesting party, and the target transaction hash value is different from the first transaction hash value of the first transaction request.
在示例性实施例中,目标交易执行结果返回单元1040可包括:第一合法性验证单元,可以用于验证所述第一交易请求的合法性;第一区块生成单元,用于若所述第一交易请求具有合法性,则生成包括所述第一交易请求的第一区块;第一区块上链单元,可以用于将所述第一区块添加至对应的区块链;目标参数检索单元,可以用于若所述第一区块上链成功,则从所述交易执行表中检索到分别与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配的目标业务方标识、目标请求方信息和目标传参哈希值;第一目标交易执行结果返回单元,可以用于将与所述目标业务方标识、所述目标请求方信息和所述目标传参哈希值对应的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备。In an exemplary embodiment, the target transaction execution result returning unit 1040 may include: a first legitimacy verification unit, which may be used to verify the legitimacy of the first transaction request; a first block generation unit, which is used to If the first transaction request is legal, generate the first block including the first transaction request; the first block chaining unit can be used to add the first block to the corresponding block chain; the target The parameter retrieval unit can be used to retrieve from the transaction execution table the first business party identifier, the first requester information and the first The target business party ID, the target requester information and the target parameter hash value matched by the reference hash value; the first target transaction execution result return unit can be used to combine the target business party ID, the target requester The target transaction execution result and the target transaction hash value corresponding to the information and the target reference hash value are returned to the terminal device of the first requesting party.
在示例性实施例中,目标交易执行结果返回单元1040可包括:第二合法性验证单元,可以用于验证所述第一交易请求的合法性;第一区块获得单元,用于若所述第一交易请求具有合法性,则生成包括所述第一交易请求的第一区块;第一区块添加单元,可以用于将所述第一区块添加至对应的区块链;第一平台方标识生成单元,可以用于若所述第一区块上链成功,则根据所述第一业务方标识生成第一平台方标识;第一数据实体标识生成单元,可以用于根据所述第一业务方标识和所述第一平台方标识生成第一数据实体标识;目标参数查询单元,可以用于从所述交易执行表中检索到分别与所述第一数据实体标识、所述第一请求方信息和所述第一传参哈希值匹配的目标数据实体标识、目标请求方信息和目标传参哈希值;第二目标交易执行结果返回单元,可以用于将与所述目标数据实体标识、所述目标请求方信息和所述目标传参哈希值对应的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备。In an exemplary embodiment, the target transaction execution result returning unit 1040 may include: a second legitimacy verification unit, which may be used to verify the legitimacy of the first transaction request; a first block obtaining unit, if the If the first transaction request is legal, a first block including the first transaction request is generated; the first block adding unit can be used to add the first block to the corresponding block chain; the first The platform party identification generation unit can be used to generate the first platform party identification according to the first business party identification if the first block is successfully uploaded to the chain; the first data entity identification generation unit can be used to generate the first platform party identification according to the The first business party ID and the first platform party ID generate the first data entity ID; the target parameter query unit can be used to retrieve the first data entity ID and the second data entity ID respectively from the transaction execution table. A target data entity identifier, target requester information, and target parameter hash value that match the requester information and the first parameter hash value; the second target transaction execution result return unit can be used to match the target transaction execution result with the target The target transaction execution result and the target transaction hash value corresponding to the data entity identifier, the target requester information and the target reference hash value are returned to the terminal device of the first requester.
在示例性实施例中,目标交易执行结果返回单元1040可包括:第三合法性验证单元,可以用于验证所述第一交易请求的合法性;第一区块获取单元,用于若所述第一交易请求具有合法性,则生成包括所述第一交易请求的第一区块;第一区块增加单元,可以用于将所述第一区块添加至对应的区块链;第一平台方标识获得单元,可以用于若所述第一区块上链成功,则根据所述第一业务方标识生成第一平台方标识;第一数据实体标识获得单元,可以用于根据所述第一业务方标识和所述第一平台方标识生成第一数据实体标识;第一交易执行表唯一键生成单元,可以用于根据所述第一数据实体标识、所述第一请求方信息和所述第一传参哈希值生成第一交易执行表唯一键;第三目标交易执行结果返回单元,可以用于若所述第一交易执行表唯一键与所述交易执行表中的目标交易执行表唯一键匹配,则将与所述目标交易执行表唯一键对应的目标交易执行结果和目标交易哈希值返回至所述第一请求方的终端设备。In an exemplary embodiment, the target transaction execution result returning unit 1040 may include: a third legitimacy verification unit, which may be used to verify the legitimacy of the first transaction request; a first block acquisition unit, for if the If the first transaction request is legal, generate a first block including the first transaction request; the first block adding unit can be used to add the first block to the corresponding block chain; the first The platform party identification obtaining unit can be used to generate the first platform party identification according to the first business party identification if the first block is successfully linked; the first data entity identification obtaining unit can be used to generate the first platform party identification according to the first data entity identification. The first business party identifier and the first platform party identifier generate a first data entity identifier; the first transaction execution table unique key generation unit can be used to generate a first data entity identifier, the first requestor information and The hash value of the first passed parameter generates the unique key of the first transaction execution table; the third target transaction execution result return unit can be used to If the unique key of the execution table matches, the target transaction execution result and target transaction hash value corresponding to the unique key of the target transaction execution table are returned to the terminal device of the first requester.
在示例性实施例中,节点设备1000还可包括:第一交易执行结果返回单元,可以用于若所述第一交易请求不具有合法性,或者所述第一区块上链失败,则向所述第一请求方的终端设备返回执行所述第一交易请求失败的第一交易执行结果。In an exemplary embodiment, the
在示例性实施例中,节点设备1000还可以包括:第二交易请求获取单元,可以用于在获取第一请求方的终端设备发送的第一交易请求之前,获取所述第一请求方的终端设备发送的第二交易请求,所述第二交易请求携带所述第一业务方标识、所述第一请求方信息和用于执行所述第二交易请求的第一传入参数;第一传参哈希值获得单元,可以用于调用所述智能合约计算生成所述第一传入参数的第一传参哈希值;第二交易请求匹配单元,可以用于调用所述智能合约将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配;第二交易执行结果获取单元,可以用于若所述交易执行表与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值不匹配,则调用所述智能合约获取所述第二交易请求的第二交易执行结果;目标交易哈希值获取单元,可以用于若所述第二交易执行结果为成功执行所述第二交易请求,则将所述第二交易执行结果作为所述目标交易执行结果,并获取所述第二交易请求的目标交易哈希值;目标参数关联存储单元,可以用于调用所述智能合约将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述目标交易执行结果和所述目标交易哈希值关联存储至所述交易执行表中;目标交易哈希值返回单元,可以用于将所述目标交易执行结果和所述目标交易哈希值返回至所述第一请求方的终端设备,所述目标交易哈希值与所述第二交易请求的第二交易哈希值相同。In an exemplary embodiment, the
在示例性实施例中,第二交易执行结果获取单元可包括:第二交易请求合法性验证单元,可以用于验证所述第二交易请求的合法性;第二区块生成单元,可以用于若所述第二交易请求具有合法性,则生成包括所述第二交易请求的第二区块;第二区块上链单元,可以用于将所述第二区块添加至对应的区块链;第二交易请求执行单元,可以用于若所述第二区块上链成功,则调用所述智能合约执行所述第二交易请求;第二交易请求成功执行结果获得单元,可以用于若成功执行所述第二交易请求,则所述第二交易执行结果为成功执行所述第二交易请求。In an exemplary embodiment, the second transaction execution result acquisition unit may include: a second transaction request legitimacy verification unit, which may be used to verify the legitimacy of the second transaction request; a second block generation unit, which may be used to If the second transaction request is legal, generate a second block including the second transaction request; the second block chaining unit can be used to add the second block to the corresponding block chain; the second transaction request execution unit can be used to call the smart contract to execute the second transaction request if the second block is successfully linked to the chain; the second transaction request successful execution result acquisition unit can be used to If the second transaction request is successfully executed, the second transaction execution result is that the second transaction request is successfully executed.
在示例性实施例中,第二交易执行结果获取单元还可包括:第二交易请求执行失败结果获得单元,可以用于若所述第二区块上链失败,或者,所述第二区块上链成功且执行所述第二交易请求失败,则所述第二交易执行结果为执行所述第二交易请求失败;In an exemplary embodiment, the second transaction execution result acquisition unit may further include: a second transaction request execution failure result acquisition unit, which may be used to if the second block fails to be uploaded to the chain, or the second block If the chaining is successful and the execution of the second transaction request fails, then the execution result of the second transaction is that the execution of the second transaction request fails;
在示例性实施例中,节点设备1000还可包括:操作回滚单元,可以用于若所述第二交易执行结果为执行所述第二交易请求失败,则回滚所述第二交易请求中成功执行的交易操作;第二交易执行结果返回单元,可以用于将所述第二交易执行结果返回至所述第一请求方的终端设备。In an exemplary embodiment, the
图11示意性示出了根据本公开的一实施例的终端设备的框图。所述终端设备与区块链网络通信,所述区块链网络中部署智能合约,所述智能合约用于维护交易执行表。Fig. 11 schematically shows a block diagram of a terminal device according to an embodiment of the present disclosure. The terminal device communicates with a block chain network, and a smart contract is deployed in the block chain network, and the smart contract is used to maintain a transaction execution table.
参照图11所示,根据本公开的一个实施例的终端设备1100可以包括:第一交易请求生成单元1110、第一交易哈希值生成单元1120、第一交易请求发送单元1130、目标交易执行结果接收单元1140以及目标交易哈希值确定单元1150。Referring to FIG. 11 , a
本公开实施例中,第一交易请求生成单元1110可以用于通过第一请求方的终端设备生成第一交易请求,所述第一交易请求携带第一业务方标识、第一请求方信息和用于执行所述第一交易请求的第一传入参数。第一交易哈希值生成单元1120可以用于通过所述第一请求方的终端设备生成所述第一交易请求的第一交易哈希值。第一交易请求发送单元1130可以用于通过所述第一请求方的终端设备向所述区块链网络中的节点设备发送所述第一交易请求,以便所述节点设备调用所述智能合约生成所述第一传入参数的第一传参哈希值,将所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值与所述交易执行表匹配。目标交易执行结果接收单元1140可以用于接收所述节点设备返回的目标交易执行结果和目标交易哈希值,其中所述交易执行表中的所述目标交易执行结果和所述目标交易哈希值与目标业务方标识与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值匹配。目标交易哈希值确定单元1150可以用于确定所述目标交易哈希值与所述第一交易哈希值不同。In this embodiment of the disclosure, the first transaction request generation unit 1110 may be configured to generate the first transaction request through the terminal device of the first requester, and the first transaction request carries the identifier of the first business party, the information of the first requester, and the user The first incoming parameter for executing the first transaction request. The first transaction hash value generating unit 1120 may be configured to generate the first transaction hash value of the first transaction request through the terminal device of the first requester. The first transaction request sending unit 1130 can be used to send the first transaction request to the node device in the blockchain network through the terminal device of the first requester, so that the node device calls the smart contract to generate The first passed parameter hash value of the first passed parameter matches the first business party identifier, the first requester information, and the first passed parameter hash value with the transaction execution table. The target transaction execution result receiving unit 1140 may be configured to receive the target transaction execution result and the target transaction hash value returned by the node device, wherein the target transaction execution result and the target transaction hash value in the transaction execution table Matching the target business party ID with the first business party ID, the first requester information and the first reference hash value. The target transaction hash value determining unit 1150 may be configured to determine that the target transaction hash value is different from the first transaction hash value.
在示例性实施例中,终端设备1100还可包括:第二交易请求生成单元,可以用于在通过第一请求方的终端设备生成第一交易请求之前,通过所述第一请求方的终端设备生成第二交易请求,所述第二交易请求携带所述第一业务方标识、所述第一请求方信息和用于执行所述第二交易请求的第一传入参数;第二交易哈希值生成单元,可以用于通过所述第一请求方的终端设备生成所述第二交易请求的第二交易哈希值;第二交易请求发送单元,可以用于通过所述第一请求方的终端设备向所述区块链网络中的节点设备发送所述第二交易请求,以便所述节点设备调用所述智能合约生成所述第一传入参数的第一传参哈希值,若所述交易执行表与所述第一业务方标识、所述第一请求方信息和所述第一传参哈希值不匹配,则成功执行所述第二交易请求,获得第二交易执行结果和第二交易哈希值,将所述第一业务方标识、所述第一请求方信息、所述第一传参哈希值、所述第二交易执行结果和所述第二交易哈希值关联存储至所述交易执行表中,其中所述第二交易执行结果作为所述目标交易执行结果,所述第二交易哈希值作为所述目标交易哈希值;目标交易执行结果哈希值接收单元,可以用于通过所述第一请求方的终端设备接收所述节点设备返回的所述目标交易执行结果和所述目标交易哈希值;目标交易哈希值相同确定单元,可以用于确定所述目标交易哈希值与所述第二交易哈希值相同。In an exemplary embodiment, the terminal device 1100 may further include: a second transaction request generating unit, which may be used to generate a first transaction request through the terminal device of the first requesting party, Generate a second transaction request, the second transaction request carries the first business party identifier, the first requester information and the first incoming parameters for executing the second transaction request; the second transaction hash The value generating unit may be used to generate the second transaction hash value of the second transaction request through the terminal device of the first requesting party; the second transaction request sending unit may be used to generate the second transaction hash value through the first requesting party's The terminal device sends the second transaction request to the node device in the blockchain network, so that the node device invokes the smart contract to generate the first passed parameter hash value of the first incoming parameter, if the If the transaction execution table does not match the first business party identifier, the first requester information, and the first parameter hash value, the second transaction request is successfully executed, and the second transaction execution result and The second transaction hash value, the first business party identification, the first requester information, the first parameter hash value, the second transaction execution result and the second transaction hash value Associated storage in the transaction execution table, wherein the second transaction execution result is used as the target transaction execution result, and the second transaction hash value is used as the target transaction hash value; the target transaction execution result hash value The receiving unit may be configured to receive the target transaction execution result and the target transaction hash value returned by the node device through the terminal device of the first requester; the target transaction hash value identical determination unit may be used to It is determined that the target transaction hash value is the same as the second transaction hash value.
图12示出了适于用来实现本公开实施例的电子设备的结构示意图。需要说明的是,图12示出的电子设备1200仅是一个示例,不应对本公开实施例的功能和使用范围带来任何限制。FIG. 12 shows a schematic structural diagram of an electronic device suitable for implementing the embodiments of the present disclosure. It should be noted that the
如图12所示,电子设备1200包括中央处理单元(CPU)1201,其可以根据存储在只读存储器(ROM)1202中的程序或者从储存部分1208加载到随机访问存储器(RAM)1203中的程序而执行各种适当的动作和处理。在RAM 1203中,还存储有系统操作所需的各种程序和数据。CPU 1201、ROM 1202以及RAM 1203通过总线1204彼此相连。输入/输出(I/O)接口1205也连接至总线1204。As shown in FIG. 12 , an
以下部件连接至I/O接口1205:包括键盘、鼠标等的输入部分1206;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分1207;包括硬盘等的储存部分1208;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分1209。通信部分1209经由诸如因特网的网络执行通信处理。驱动器1210也根据需要连接至I/O接口1205。可拆卸介质1211,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器1210上,以便于从其上读出的计算机程序根据需要被安装入储存部分1208。The following components are connected to the I/O interface 1205: an
特别地,根据本公开的实施例,下文参考流程图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分1209从网络上被下载和安装,和/或从可拆卸介质1211被安装。在该计算机程序被中央处理单元(CPU)1201执行时,执行本申请的系统中限定的各种功能。In particular, according to an embodiment of the present disclosure, the processes described below with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, where the computer program includes program codes for executing the methods shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via
需要说明的是,本公开所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有至少一个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本公开中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本公开中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. A computer readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, electrical connections having at least one lead, portable computer diskettes, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable Read memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. . Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含至少一个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, program segment, or part of code that includes at least one programmable logic function for implementing a specified logical function. Execute instructions. It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved. It should also be noted that each block in the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a A combination of dedicated hardware and computer instructions.
描述于本公开实施例中所涉及到的模块和/或单元和/或子单元可以通过软件的方式实现,也可以通过硬件的方式来实现,所描述的模块和/或单元和/或子单元也可以设置在处理器中。其中,这些模块和/或单元和/或子单元的名称在某种情况下并不构成对该模块和/或单元和/或子单元本身的限定。The modules and/or units and/or subunits involved in the embodiments described in the present disclosure may be realized by software or by hardware. The described modules and/or units and/or subunits It can also be set in the processor. Wherein, the names of these modules and/or units and/or subunits do not constitute limitations on the modules and/or units and/or subunits themselves under certain circumstances.
作为另一方面,本申请还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该电子设备执行时,使得该电子设备实现如下述实施例中所述的方法。例如,所述的电子设备可以实现如图5或图6或图7或图8或图9所示的各个步骤。As another aspect, the present application also provides a computer-readable medium. The computer-readable medium may be included in the electronic device described in the above-mentioned embodiments; or it may exist independently without being assembled into the electronic device. middle. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by an electronic device, the electronic device is made to implement the methods described in the following embodiments. For example, the electronic device may implement various steps as shown in FIG. 5 or FIG. 6 or FIG. 7 or FIG. 8 or FIG. 9 .
应当注意,尽管在上文详细描述中提及了用于动作执行的设备的若干模块或者单元或者子单元,但是这种划分并非强制性的。实际上,根据本公开的实施方式,上文描述的两个或更多模块或者单元或者子单元的特征和功能可以在一个模块或者单元或者子单元中具体化。反之,上文描述的一个模块或者单元的特征和功能可以进一步划分为由多个模块或者单元或者子单元来具体化。It should be noted that although several modules or units or subunits of the device for action execution are mentioned in the above detailed description, this division is not mandatory. Actually, according to the embodiments of the present disclosure, the features and functions of two or more modules or units or subunits described above may be embodied in one module or unit or subunit. Conversely, the features and functions of one module or unit described above can be further divided to be embodied by multiple modules or units or subunits.
通过以上的实施方式的描述,本领域的技术人员易于理解,这里描述的示例实施方式可以通过软件实现,也可以通过软件结合必要的硬件的方式来实现。因此,根据本公开实施方式的技术方案可以以软件产品的形式体现出来,该软件产品可以存储在一个非易失性存储介质(可以是CD-ROM,U盘,移动硬盘等)中或网络上,包括若干指令以使得一台计算设备(可以是个人计算机、服务器、触控终端、或者网络设备等)执行根据本公开实施方式的方法。Through the description of the above implementations, those skilled in the art can easily understand that the example implementations described here can be implemented by software, or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of the present disclosure can be embodied in the form of software products, and the software products can be stored in a non-volatile storage medium (which can be CD-ROM, U disk, mobile hard disk, etc.) or on the network , including several instructions to make a computing device (which may be a personal computer, a server, a touch terminal, or a network device, etc.) execute the method according to the embodiments of the present disclosure.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110801455.3ACN115619395A (en) | 2021-07-15 | 2021-07-15 | Blockchain-based data processing method and related equipment |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110801455.3ACN115619395A (en) | 2021-07-15 | 2021-07-15 | Blockchain-based data processing method and related equipment |
| Publication Number | Publication Date |
|---|---|
| CN115619395Atrue CN115619395A (en) | 2023-01-17 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110801455.3APendingCN115619395A (en) | 2021-07-15 | 2021-07-15 | Blockchain-based data processing method and related equipment |
| Country | Link |
|---|---|
| CN (1) | CN115619395A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117333298A (en)* | 2023-10-15 | 2024-01-02 | 广东工程职业技术学院 | Stock right transaction method and device based on blockchain |
| CN117952614A (en)* | 2024-03-14 | 2024-04-30 | 深圳市金政软件技术有限公司 | Payment anti-duplicate method, device, terminal equipment and readable storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105719185A (en)* | 2016-01-22 | 2016-06-29 | 杭州复杂美科技有限公司 | Block chain data comparison and consensus method |
| CN107220830A (en)* | 2017-05-08 | 2017-09-29 | 深圳市牛鼎丰科技有限公司 | Method of payment, device, storage medium and computer equipment |
| CN108805569A (en)* | 2018-05-29 | 2018-11-13 | 阿里巴巴集团控股有限公司 | Transaction processing method and device, electronic equipment based on block chain |
| CN111066046A (en)* | 2019-04-26 | 2020-04-24 | 阿里巴巴集团控股有限公司 | Replay attack resistant authentication protocol |
| CN111507724A (en)* | 2019-01-31 | 2020-08-07 | 上海哔哩哔哩科技有限公司 | Payment verification method and system |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105719185A (en)* | 2016-01-22 | 2016-06-29 | 杭州复杂美科技有限公司 | Block chain data comparison and consensus method |
| CN107220830A (en)* | 2017-05-08 | 2017-09-29 | 深圳市牛鼎丰科技有限公司 | Method of payment, device, storage medium and computer equipment |
| CN108805569A (en)* | 2018-05-29 | 2018-11-13 | 阿里巴巴集团控股有限公司 | Transaction processing method and device, electronic equipment based on block chain |
| CN111507724A (en)* | 2019-01-31 | 2020-08-07 | 上海哔哩哔哩科技有限公司 | Payment verification method and system |
| CN111066046A (en)* | 2019-04-26 | 2020-04-24 | 阿里巴巴集团控股有限公司 | Replay attack resistant authentication protocol |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117333298A (en)* | 2023-10-15 | 2024-01-02 | 广东工程职业技术学院 | Stock right transaction method and device based on blockchain |
| CN117952614A (en)* | 2024-03-14 | 2024-04-30 | 深圳市金政软件技术有限公司 | Payment anti-duplicate method, device, terminal equipment and readable storage medium |
| Publication | Publication Date | Title |
|---|---|---|
| US12294642B2 (en) | Separation of accounting node subnetwork and service node subnetwork | |
| US11620642B2 (en) | Digital contracts in blockchain environments | |
| US10977632B2 (en) | Electronic bill management method, apparatus, and storage medium | |
| US11210661B2 (en) | Method for providing payment gateway service using UTXO-based protocol and server using same | |
| US20230080322A1 (en) | User id codes for online verification | |
| CN109359974B (en) | Block chain transaction method and device and electronic equipment | |
| CN111989893B (en) | Method, system and computer readable device for generating and linking zero knowledge proofs | |
| US20190354606A1 (en) | Private Cryptocoinage in Blockchain Environments | |
| TW202018572A (en) | Blockchain data protection based on account note model with zero-knowledge proof | |
| WO2020119294A1 (en) | Data sharing method, apparatus, and system, and electronic device | |
| TWI772654B (en) | Escrowing system for cross-blockchain third-party settlement and method thereof | |
| JP2020528222A (en) | Handling of transaction activities based on smart contracts in blockchain Caution Methods and devices for protecting data | |
| CN110009337A (en) | A kind of data processing method and device based on block chain | |
| WO2020082889A1 (en) | Credit reporting evaluation method and apparatus, and electronic device | |
| JP2023542681A (en) | Integrating device identity into blockchain permission frameworks | |
| WO2022121538A1 (en) | Data synchronization method and system based on blockchain, and related device | |
| CN113706313B (en) | Financing method, system and computer-readable storage medium based on blockchain | |
| US20200250655A1 (en) | Efficient, environmental and consumer friendly consensus method for cryptographic transactions | |
| CN111915298A (en) | Method and device for generating and verifying linkable ring signature in block chain | |
| CN111488372A (en) | A data processing method, device and storage medium | |
| CN111784128A (en) | A blockchain-based asset information processing method and system | |
| US20250173713A1 (en) | Method and system for privately managed digital assets on an enterprise blockchain | |
| JP2025510779A (en) | A unified platform for digital asset registration, tracking and authentication | |
| CN111488626A (en) | Blockchain-based data processing method, device, equipment and medium | |
| CN111915308A (en) | A transaction processing method of a blockchain network and a blockchain network |
| 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 |