Intelligent contract calling method, device and equipment based on block chain

文档序号:487952 发布日期:2022-01-04 浏览:5次 中文

阅读说明:本技术 基于区块链的智能合约调用方法、装置及设备 (Intelligent contract calling method, device and equipment based on block chain ) 是由 郭锐 李辉忠 范瑞彬 张开翔 于 2021-12-07 设计创作,主要内容包括:本公开实施例提供一种基于区块链的智能合约调用方法、装置及设备,该方法包括:接收客户端发送的交易信息,其中交易信息中包含交易信息对应的待执行的智能合约的路径信息;将接收到的各交易信息放入调度器以使调度器将各交易信息分发至不同的执行器;通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的;通过各执行器对交易信息执行智能合约,得到执行结果。不需要各执行器在并行执行交易时进行智能合约相关的CNS表数据的同步,提升了区块链在对交易信息并行执行智能合约的效率。(The embodiment of the disclosure provides a method, a device and equipment for calling an intelligent contract based on a block chain, wherein the method comprises the following steps: receiving transaction information sent by a client, wherein the transaction information comprises path information of an intelligent contract to be executed corresponding to the transaction information; putting the received transaction information into a dispatcher so that the dispatcher distributes the transaction information to different executors; inquiring a storage unit to obtain the intelligent contract corresponding to each transaction information through each actuator based on the path information of the intelligent contract to be executed corresponding to each transaction information, wherein the storage unit comprises each intelligent contract stored according to a tree file directory structure, and the storage path of each intelligent contract is unique; and executing the intelligent contract on the transaction information through each executor to obtain an execution result. The synchronization of CNS table data related to the intelligent contract is not needed when the executors execute the transaction in parallel, and the efficiency of the blockchain in executing the intelligent contract on the transaction information in parallel is improved.)

1. An intelligent contract calling method based on a blockchain is applied to any node of the blockchain, wherein a scheduler for scheduling and distributing transaction information, an executor for executing an intelligent contract and a storage unit for storing the intelligent contract are arranged in the node, and the method comprises the following steps:

receiving transaction information sent by a client, wherein the transaction information comprises path information of an intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path;

putting the received transaction information into a dispatcher so that the dispatcher distributes the transaction information to different executors;

inquiring a storage unit to obtain the intelligent contract corresponding to each transaction information through each actuator based on the path information of the intelligent contract to be executed corresponding to each transaction information, wherein the storage unit comprises each intelligent contract stored according to a tree file directory structure, and the storage path of each intelligent contract is unique;

and executing the intelligent contract on the transaction information through each actuator to obtain an execution result.

2. The method according to claim 1, wherein the storage unit includes each intelligent contract stored according to a tree file directory structure, and a storage path of each intelligent contract is unique, specifically: the storage unit comprises directory resources and intelligent contract resources which are stored in a storage table form; each directory resource comprises a plurality of sub-resources, the intelligent contract resources of the same type belong to the tail-end sub-resources of the same directory resource, and the intelligent contract resources comprise code segment information and state information of an intelligent contract.

3. The method according to claim 2, wherein the querying, by each executor, the storage unit to obtain the intelligent contract corresponding to each transaction information based on the path information of the intelligent contract to be executed corresponding to each transaction information includes:

splitting path information of an intelligent contract to be executed corresponding to any transaction information to obtain names of storage tables corresponding to the path information;

and sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables so as to obtain the intelligent contract resources corresponding to the path information.

4. The method according to claim 3, wherein sequentially accessing the corresponding storage tables in the storage unit according to the storage table names to obtain the intelligent contract resource corresponding to the path information comprises:

accessing a cache, and sequentially reading each storage table with the name of each storage table from the cache; if the storage tables can be read from the cache, sequentially inquiring the storage tables from the cache according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource;

and if the storage tables cannot be read from the cache, sequentially inquiring the storage tables from the storage unit of the block chain according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined, so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource.

5. The method according to claim 4, wherein the sequentially querying the storage tables according to the storage table names until determining the storage table corresponding to the intelligent contract resource so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource comprises:

and according to the level of each storage table name in the path information, sequentially inquiring the storage tables corresponding to each storage table name one by one to obtain the storage tables corresponding to the intelligent contract resources so as to obtain the intelligent contract resources corresponding to the path information from the storage tables corresponding to the intelligent contract resources.

6. The method of any one of claims 1 to 5, further comprising the step of storing each smart contract in a tree file directory structure, as follows:

determining any directory resource through creation or query;

and writing the intelligent contract to be created in the directory resource.

7. The method of claim 6, wherein determining any directory resource by creating or querying comprises:

generating a storage table name of any directory resource according to the input of a user;

judging whether the storage table name of the directory resource exists or not;

if not, creating the directory resource, wherein the directory resource comprises meta-information of a directory;

if the directory resource exists, judging whether the storage table name is the table name of the intelligent contract resource, and if not, returning a prompt that the directory resource exists.

8. The method of claim 6, wherein writing the smart contract to be created in the directory resource comprises:

generating a storage table name of any intelligent contract according to the input of a user;

judging whether the storage table name of the intelligent contract exists;

if the intelligent contract does not exist, the directory resource is obtained, the virtual machine is started to execute the intelligent contract, and if the intelligent contract is executed successfully, code segment information and state information of the intelligent contract are written into the directory resource.

9. An intelligent contract invoking device based on a blockchain, which is applied to any node of the blockchain, wherein a scheduler for scheduling and allocating transaction information, an executor for executing an intelligent contract and a storage unit for storing the intelligent contract are arranged in the node, and the device comprises:

the system comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving transaction information sent by a client, the transaction information comprises path information of an intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path;

the scheduling module is used for putting the received transaction information into a scheduler so that the scheduler can distribute the transaction information to different executors;

the scheduling module is used for inquiring the storage unit to acquire the intelligent contracts corresponding to the transaction information through the actuators based on the path information of the intelligent contracts to be executed corresponding to the transaction information, wherein the storage unit comprises the intelligent contracts stored according to a tree file directory structure, and the storage paths of the intelligent contracts are unique;

and the execution module is used for executing the intelligent contract on the transaction information through each executor to obtain an execution result.

10. A service device, comprising:

a processor and a memory;

the memory stores computer-executable instructions;

the processor executing the memory-stored computer-executable instructions causing the processor to perform the blockchain-based smart contract invocation method of any of claims 1 to 8.

11. A computer-readable storage medium having stored thereon computer-executable instructions which, when executed by a processor, implement a blockchain-based intelligent contract invocation method according to any one of claims 1 to 8.

Technical Field

The embodiment of the disclosure relates to the technical field of financial technology (Fintech), in particular to an intelligent contract calling method, device and equipment based on a block chain.

Background

With the development of computer technology, more and more technologies are applied in the financial field, the traditional financial industry is gradually changing to financial technology (Fintech), and the intelligent contract technology related to the block chain is not an exception, but higher requirements are provided for the intelligent contract technology due to the requirements of security and real-time performance of the financial industry.

At present, in an existing intelligent Contract management process based on a block chain of an alliance, an executor (an ethernet intelligent Contract virtual machine) executing an intelligent Contract in a node of the block chain generally maintains a CNS (Contract Name Service) table, where a mapping relationship between an intelligent Contract Name and an intelligent Contract address is stored in the CNS table, and when the executor needs to execute an intelligent Contract on an obtained transaction, the executor accesses the CNS table to query a corresponding intelligent Contract address, obtains a corresponding intelligent Contract from the intelligent Contract address, and executes the transaction.

However, in some scenarios, the blockchain requires parallel execution of processing on transactions, and multiple executors of the blockchain are required to execute intelligent contracts in parallel. In this case, each executor needs to maintain a CNS table (mapping relationship between the intelligent contract name and the intelligent contract address), and when a user modifies information related to the intelligent contract in the CNS table of a certain executor, the data of the modified CNS table must be synchronized to all other executors, otherwise, other executors may execute wrong intelligent contracts, which results in frequent synchronization of the CNS table data among the executors, and affects the processing efficiency of the block chain to execute multiple intelligent contracts in parallel.

Disclosure of Invention

The embodiment of the disclosure provides an intelligent contract calling method, an intelligent contract calling device and intelligent contract calling equipment based on a block chain, so as to overcome the problem that in the related art, synchronization of CNS table data needs to be frequently performed between executors, and the processing efficiency of executing a plurality of intelligent contracts in parallel by the block chain is influenced.

In a first aspect, the disclosed embodiment provides a method for calling an intelligent contract based on a blockchain, where the method is applied to any node of the blockchain, where a scheduler for scheduling and allocating transaction information, an executor for executing the intelligent contract, and a storage unit for storing the intelligent contract are provided in the node, and the method includes:

receiving transaction information sent by a client, wherein the transaction information comprises path information of an intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path;

putting the received transaction information into a dispatcher so that the dispatcher distributes the transaction information to different executors;

inquiring a storage unit to obtain the intelligent contract corresponding to each transaction information through each actuator based on the path information of the intelligent contract to be executed corresponding to each transaction information, wherein the storage unit comprises each intelligent contract stored according to a tree file directory structure, and the storage path of each intelligent contract is unique;

and executing the intelligent contract on the transaction information through each actuator to obtain an execution result.

In one possible design, the storage unit includes each intelligent contract stored according to a tree file directory structure, and a storage path of each intelligent contract is unique, specifically: the storage unit comprises directory resources and intelligent contract resources which are stored in a storage table form; each directory resource comprises a plurality of sub-resources, the intelligent contract resources of the same type belong to the tail-end sub-resources of the same directory resource, and the intelligent contract resources comprise code segment information and state information of an intelligent contract.

In a possible design, the querying, by each executor, the storage unit to obtain the intelligent contract corresponding to each transaction information based on the path information of the intelligent contract to be executed corresponding to each transaction information includes: splitting path information of an intelligent contract to be executed corresponding to any transaction information to obtain names of storage tables corresponding to the path information; and sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables so as to obtain the intelligent contract resources corresponding to the path information.

In a possible design, the sequentially accessing, according to the names of the storage tables, the corresponding storage tables in the storage unit to obtain the intelligent contract resources corresponding to the path information includes: accessing a cache, and sequentially reading each storage table with the name of each storage table from the cache; if the storage tables can be read from the cache, sequentially inquiring the storage tables from the cache according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource; and if the storage tables cannot be read from the cache, sequentially inquiring the storage tables from the storage unit of the block chain according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined, so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource.

In a possible design, sequentially querying each storage table according to the name of each storage table until determining the storage table corresponding to the intelligent contract resource, so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource, includes: and according to the level of each storage table name in the path information, sequentially inquiring the storage tables corresponding to each storage table name one by one to obtain the storage tables corresponding to the intelligent contract resources so as to obtain the intelligent contract resources corresponding to the path information from the storage tables corresponding to the intelligent contract resources.

In one possible design, the method further includes the step of storing the intelligent contracts in a tree file directory structure, as follows: determining any directory resource through creation or query; and writing the intelligent contract to be created in the directory resource.

In one possible design, the determining any directory resource by creating or querying includes:

generating a storage table name of any directory resource according to the input of a user; judging whether the storage table name of the directory resource exists or not; if not, creating the directory resource, wherein the directory resource comprises meta-information of a directory; if the directory resource exists, judging whether the storage table name is the table name of the intelligent contract resource, and if not, returning a prompt that the directory resource exists.

In one possible design, the writing of the intelligent contract to be created in the directory resource includes: generating a storage table name of any intelligent contract according to the input of a user; judging whether the storage table name of the intelligent contract exists; if the intelligent contract does not exist, the directory resource is obtained, the virtual machine is started to execute the intelligent contract, and if the intelligent contract is executed successfully, code segment information and state information of the intelligent contract are written into the directory resource.

In a second aspect, the disclosed embodiment provides an apparatus for intelligent contract invoking based on a blockchain, where the apparatus is applied to any node of the blockchain, and a scheduler for scheduling and allocating transaction information, an executor for executing an intelligent contract, and a storage unit for storing the intelligent contract are disposed in the node, and the apparatus includes:

the system comprises a receiving module, a processing module and a processing module, wherein the receiving module is used for receiving transaction information sent by a client, the transaction information comprises path information of an intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path;

the scheduling module is used for putting the received transaction information into a scheduler so that the scheduler can distribute the transaction information to different executors;

the scheduling module is used for inquiring the storage unit to acquire the intelligent contracts corresponding to the transaction information through the actuators based on the path information of the intelligent contracts to be executed corresponding to the transaction information, wherein the storage unit comprises the intelligent contracts stored according to a tree file directory structure, and the storage paths of the intelligent contracts are unique;

and the execution module is used for executing the intelligent contract on the transaction information through each executor to obtain an execution result.

In a third aspect, an embodiment of the present disclosure provides a service device, including: a processor and a memory;

the memory stores computer-executable instructions;

the processor executes the memory-stored computer-executable instructions to cause the processor to perform the blockchain-based intelligent contract invocation method as described above in the first aspect and in various possible designs of the first aspect.

In a fourth aspect, the embodiments of the present disclosure provide a computer-readable storage medium, where computer-executable instructions are stored, and when a processor executes the computer-executable instructions, the block chain-based intelligent contract invoking method according to the first aspect and various possible designs of the first aspect is implemented.

According to the intelligent contract calling method, device and equipment based on the block chain, any node of the block chain carries path information of an intelligent contract to be executed corresponding to transaction information in the transaction information, and the path information corresponds to a unique intelligent contract storage path; the storage unit of each node of the block chain stores each intelligent contract stored according to a tree file directory structure, the storage path of each intelligent contract is unique, each actuator of the block chain node accesses the storage unit according to the path information to obtain the corresponding intelligent contract according to the unique intelligent contract storage path, and executes the transaction information according to the intelligent contract to obtain the execution result. Because each intelligent contract stored in the storage unit according to the tree file directory structure is unique and isolated when being scheduled by different executors, the synchronization of CNS table data related to the intelligent contracts is not needed when the executors execute transactions in parallel, and the efficiency of the block chain in executing the intelligent contracts in parallel on transaction information is improved.

Drawings

In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present disclosure, and for those skilled in the art, other drawings can be obtained according to the drawings without inventive exercise.

FIG. 1 is a schematic diagram of a block chain-based intelligent contract invocation method provided by the present disclosure;

fig. 2 is a first flowchart illustrating a block chain-based intelligent contract invoking method according to an embodiment of the present disclosure;

FIG. 3 is a logical structure diagram of the storage of smart contracts according to a tree file directory structure according to an embodiment of the present disclosure;

FIG. 4 is a schematic diagram of an actual storage form of an intelligent contract provided by an embodiment of the present disclosure;

fig. 5 is a schematic flowchart of a second method for invoking an intelligent contract based on a blockchain according to an embodiment of the present disclosure;

fig. 6 is a first schematic structural diagram of an intelligent contract invoking apparatus based on a blockchain according to an embodiment of the present disclosure;

fig. 7 is a schematic structural diagram of a block chain-based intelligent contract invoking apparatus according to an embodiment of the present disclosure;

fig. 8 is a schematic hardware structure diagram of a service device according to an embodiment of the present disclosure.

Detailed Description

To make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are some, but not all embodiments of the present disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.

The technical noun explains:

block chains: a blockchain system may be understood to be a distributed storage system that is commonly maintained and trusted by multiple nodes. The block chain bottom layer is a chain formed by a series of blocks, each block records the hash value of the block besides the data of the block, and the chained data structure is formed in this way. A chunk consists of a chunk header and a chunk body, where the chunk header definition includes important fields such as the height of the chunk, the hash value of the last chunk, and the chunk body primarily stores transaction data. The block chain guarantees the safety of data transmission and access in a cryptographic mode, and guarantees that data on the chain cannot be tampered by using a chain structure.

Intelligent contract: intelligent contracts refer to contracts defined in digital form that automatically enforce terms, meaning that the contracts must be implemented in computer code, because the rights and obligations established by the intelligent contract are automatically enforced whenever a party reaches an agreement, and the results cannot be repudiated. In blockchain applications, when a transaction deploying an intelligent contract reaches consensus in most nodes, the intelligent contract may be considered embedded in the blockchain system.

Ethernet virtual machine (executor of smart contract): after the intelligent contracts are compiled into binary files, the binary files are deployed on the nodes of the blockchain. And the user triggers the execution operation of the intelligent contract by calling the interface of the intelligent contract. The ethernet virtual machine executes the code of the intelligent contract as an executor of the intelligent contract code, modifying the data (state) on the current block chain. The modified data will be recognized to ensure consistency.

Referring to fig. 1, fig. 1 is a schematic view of a scenario of an intelligent contract invocation method based on a block chain according to the present disclosure. In this scenario, the method includes: the client 101 and the tile chain node 102 may install an SDK (Software Development Kit) for initiating a transaction and generating transaction information. The client 101 may be a personal computer, a mobile terminal, or other devices such as a server.

The blockchain link point 102 may be any node in the blockchain system, for example, any node participating in the consensus process in the blockchain, or a leader node selected from the consensus nodes, which is not limited in this disclosure. The block chain node 102 is configured to receive transaction information sent by a client, acquire an intelligent contract corresponding to the transaction information, execute the transaction information by using an ethernet virtual machine (actuator) based on the intelligent contract to obtain an execution result, perform consensus on the execution result in the block chain, and perform block chain uplink storage after the consensus is completed.

Currently, in an intelligent contract management invocation based on a block chain of an alliance, an executor (an ethernet intelligent contract virtual machine) executing an intelligent contract in a node of the block chain generally maintains a CNS table, and when the executor needs to execute an intelligent contract on an obtained transaction, the executor accesses the CNS table to query a corresponding intelligent contract address, obtains a corresponding intelligent contract from the intelligent contract address, and executes the transaction. However, if the blockchain needs to execute the transaction in parallel, the multiple executors of the blockchain need to execute the intelligent contract in parallel, and when the user modifies information related to the intelligent contract in the CNS table of a certain executor, the data of the modified CNS table must be synchronized to all other executors, otherwise, other executors execute the wrong intelligent contract, which results in frequent synchronization of the CNS table data among the executors, and affects the processing efficiency of executing multiple intelligent contracts in parallel by the blockchain.

In order to solve the technical problem, the present disclosure provides the following technical solutions: the transaction information carries path information of the intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path; the storage unit of each node of the block chain stores each intelligent contract stored according to a tree file directory structure, the storage path of each intelligent contract is unique, each actuator of the block chain node accesses the storage unit according to the path information to obtain the corresponding intelligent contract according to the unique intelligent contract storage path, and executes the transaction information according to the intelligent contract to obtain the execution result. Because each intelligent contract stored in the storage unit according to the tree file directory structure is unique and isolated when being scheduled by different executors, the executors are not required to synchronize data of a CNS (Central system network) table when executing transactions in parallel, and the efficiency of a block chain when executing the intelligent contracts to transaction information in parallel is greatly improved.

Referring to fig. 2, fig. 2 is a first flowchart illustrating a method for intelligent contract invocation based on a blockchain according to an embodiment of the present disclosure. The present embodiment is applied to any node of the block chain shown in fig. 1, in which a scheduler for scheduling and allocating transaction information, an executor for executing an intelligent contract, and a storage unit for storing the intelligent contract are provided, and the method is detailed as follows:

s201: and receiving transaction information sent by the client, wherein the transaction information comprises path information of the intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path.

In the embodiment of the present disclosure, the client may be any client that has a transaction behavior, and the client generates transaction information according to the transaction behavior and sends the transaction information to any node of the block chain. For example, a user purchases a commodity in an online shopping mall, a transaction is completed through a client, and the client sends transaction information of the purchased commodity to any node of the block chain. In this embodiment, any node of the blockchain is any node of the common nodes in the blockchain. The leader node is elected from the consensus nodes of the blockchain. Any consensus node can be either a leader node or a replica node.

In the disclosed embodiment, while the client produces the transaction information according to the transaction behavior, the user may specify the to-be-executed intelligent contract corresponding to the transaction information at the client, and add the path information of the to-be-executed intelligent contract in the transaction information. The path information corresponds to a unique intelligent contract storage path, and the corresponding intelligent contract is obtained through the unique intelligent contract storage path according to the path information.

S202: the received transaction information is placed into a scheduler such that the scheduler distributes the transaction information to different ones of the executors.

In the embodiment of the disclosure, the scheduler is a virtual scheduler arranged in a node of the block chain, and the virtual scheduler distributes each transaction information capable of executing the intelligent contracts in parallel to different executors according to a preset rule.

The preset rule may be to equally distribute each transaction information to each executor. For example, 10 transaction messages and 2 executors may be assigned 5 transaction messages to one executor and 5 transaction messages to another executor.

S203: and inquiring a storage unit to obtain the intelligent contract corresponding to each transaction information through each executor based on the path information of the intelligent contract to be executed corresponding to each transaction information, wherein each intelligent contract stored according to a tree file directory structure is contained in the storage unit, and the storage path of each intelligent contract is unique.

In the embodiment of the present disclosure, the storage unit includes each intelligent contract stored according to a tree file directory structure, and a storage path of each intelligent contract is unique, specifically: the storage unit comprises directory resources and intelligent contract resources which are stored in a storage table form; each directory resource comprises a plurality of sub-resources, the intelligent contract resources of the same type belong to the tail-end sub-resources of the same directory resource, and the intelligent contract resources comprise code segment information and state information of an intelligent contract.

Referring to fig. 3, fig. 3 is a logical structure diagram of each smart contract stored according to a tree file directory structure provided in the embodiment of the present disclosure. Wherein "/" is a root directory, the root directory includes a plurality of directory resources, as shown in fig. 3, "sys", "usr", "apps", and "tables" are directory resources, and are respectively a system category directory resource, a user category directory resource, an application category directory resource, and a table category directory resource. Each directory resource comprises a plurality of sub-resources, and the sub-resources can be the next-level directory resources of the current directory resources or can be the intelligent contract resources directly. Child resources of "sys 1" and "sys 2" included in "sys" shown in fig. 3 are directory resources at the next level of the directory resources, and each of "sys 1" and "sys 2" includes two system intelligent contract resources, where "sys 1" includes "system intelligent contract resource 1", "system intelligent contract resource 2"; "sys 2" includes "system intelligent contract resource 3" and "system intelligent contract resource 4". Other "usr", "apps" and "tables" are directory resources, and the corresponding sub-resources are directly intelligent contract resources; wherein, "usr" includes "user intelligent contract resource 1" and "user intelligent contract resource 2"; the apps comprises an application intelligent contract resource 1 and an application intelligent contract resource 2; the tables include table intelligent contract resource 1 and table intelligent contract resource 2. In the present embodiment, each "resource" may be stored in the form of a file or a table, and the present disclosure is not limited in any way.

Referring to fig. 4, fig. 4 is a schematic diagram of an actual storage form of an intelligent contract provided by an embodiment of the present disclosure. The storage unit comprises directory resources and intelligent contract resources which are stored in the form of a storage table. As shown in fig. 4, the storage table names are: the storage table of "/tables" is a directory resource, and the storage table names of the intelligent contract resources contained in the storage table are "/tables 1" and "/tables 2", respectively. The storage table with the storage table name of "/tables" describes the meta information of the intelligent contract resource, and the storage table with the storage table name of "/tables/table 1" and the storage table of "/tables/table 2" respectively contain the data of the intelligent contract "tables 1" and "table 2".

Specifically, the method for querying the storage unit to obtain the intelligent contract corresponding to each transaction information through each executor based on the path information of the intelligent contract to be executed corresponding to each transaction information includes:

splitting path information of the intelligent contract to be executed corresponding to any transaction information to obtain names of all storage tables corresponding to the path information; and sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables so as to obtain the intelligent contract resources corresponding to the path information.

In the embodiment of the present disclosure, the path information "/apps/Hello 1" is taken as an example to explain:

split path information "/apps/Hello 1" into "/", "/apps", and "/apps/Hello 1"; "/", "/apps", and "/apps/Hello 1" correspond to a storage table name, respectively, where "/" is the storage table name of the root directory resource, "/apps" is the storage table name of the directory resource, and/apps/Hello 1 "is the storage table name of the intelligent contract resource.

Specifically, sequentially accessing each corresponding storage table in the storage unit according to the name of each storage table to obtain the intelligent contract resource corresponding to the path information, includes: accessing the cache, and sequentially reading each storage table with the name of each storage table from the cache; if the storage tables can be read from the cache, sequentially inquiring the storage tables from the cache according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource; and if the storage tables cannot be read from the cache, sequentially inquiring the storage tables from the storage unit of the block chain according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource.

The method includes the following steps of sequentially inquiring each storage table according to each storage table name until determining the storage table corresponding to the intelligent contract resource so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource, and the method includes the following steps: and according to the level of each storage table name in the path information, sequentially inquiring the storage tables corresponding to each storage table name one by one to obtain the storage tables corresponding to the intelligent contract resources so as to obtain the intelligent contract resources corresponding to the path information from the storage tables corresponding to the intelligent contract resources.

In the embodiment of the present disclosure, after the transaction information of the intelligent contract that can be executed in parallel is distributed to different executors, each executor may first read the cache, and if the same intelligent contract has been executed by the executor before, the executor may cache data corresponding to the intelligent contract, where the data corresponding to the intelligent contract includes each storage table corresponding to a path stored by the intelligent contract.

The following description is given by taking two intelligent contract examples that the execution path information of any actuator is "/apps/Hello 1" and "/tables/table 1", respectively:

the executor reads a storage table with storage table names of "/apps" and a storage table of "/tables" from the cache; then, a storage table with the storage table names of "/apps/Hello 1" and a storage table of "/tables 1" are read according to the storage table of "/apps" and the storage table of "/tables", wherein the storage table of "/apps/Hello 1" and the storage table of "/tables 1" respectively contain intelligent contract resources of "Hello 1" intelligent contracts and "tables 1" intelligent contracts.

If the executor does not read the storage tables from the cache, the corresponding storage tables are obtained from the storage unit, and the storage tables obtained from the storage unit are written into the executor, wherein the writing process is slow writing and takes longer time compared with directly reading from the cache.

It should be noted that: the storage tables of the intelligent contract can support distributed storage of data in the storage unit, so that when the executor loads the storage tables from the storage unit, all data is scattered.

Referring to fig. 3 and 4, it can be understood that, when an executor loads an intelligent contract from a storage unit, the child resources under each directory resource cannot be homonymous, and therefore, the path from the root directory down to each intelligent contract resource is unique, so that the intelligent contract loaded by the executor has uniqueness. In addition, when the executor loads the intelligent contracts from the storage unit, the intelligent contracts of different paths can be executed by different executors, so that the different intelligent contracts are isolated from each other.

In an embodiment of the present disclosure, when the executor loads the intelligent contract from the storage unit, a path of a certain directory resource may also be specified, and all the intelligent contracts under the directory resource are loaded to the same executor, so that the directory resources loaded by different executors are different, thereby achieving isolation of the intelligent contracts at the directory resource level.

S204: and executing the intelligent contract on the transaction information through each executor to obtain an execution result.

In the embodiment of the disclosure, the executor executes the intelligent contract on the transaction information to obtain the execution result of the transaction information, then sends the execution result of the transaction information to other consensus nodes in the block chain for consensus, and after the consensus on the execution result of the transaction information is completed, the execution result of the transaction information is uplink stored in the block chain.

As can be seen from the above description, the transaction information carries path information of the intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path; the storage unit of each node of the block chain stores each intelligent contract stored according to a tree file directory structure, the storage path of each intelligent contract is unique, each actuator of the block chain node accesses the storage unit according to the path information to obtain the corresponding intelligent contract according to the unique intelligent contract storage path, and executes the transaction information according to the intelligent contract to obtain the execution result. Because each intelligent contract stored in the storage unit according to the tree file directory structure is unique and isolated when being scheduled by different executors, the synchronization of CNS table data related to the intelligent contracts is not needed when the executors execute transactions in parallel, and the efficiency of the block chain in executing the intelligent contracts in parallel on transaction information is improved.

Referring to fig. 5, fig. 5 is a schematic flowchart of a block chain-based intelligent contract invoking method according to an embodiment of the present disclosure. This embodiment also describes how to store the intelligent contracts according to the tree file directory structure, which is detailed as follows:

s501: any directory resource is determined by creation or querying.

Specifically, determining any directory resource by creating or querying includes:

generating a storage table name of any directory resource according to the input of a user;

judging whether the storage table name of the directory resource exists or not;

if the directory does not exist, creating directory resources, and writing meta information of the directory in the directory resources;

if the directory resource exists, judging whether the storage table name is the table name of the intelligent contract resource, and if not, returning a prompt that the directory resource exists.

In embodiments of the present disclosure, a user may create a new directory resource under any existing directory resource.

Taking the creation of "/apps/Hello" directory resources as an example, the following is explained:

generating a storage table name of "/apps/Hello/World";

judging whether the "/apps/Hello/World" exists or not;

if the directory does not exist, creating a directory "/apps/Hello/", creating a "/apps/Hello/World" storage table, writing meta-information of the directory in the "/apps/Hello/World" storage table, obtaining a directory resource of "/apps/Hello/", and returning a prompt of successful creation of the directory;

if yes, accessing a storage table of a directory "/apps/Hello/World", and judging the type of the storage table of "/apps/Hello/World"; if the storage table type is the directory resource, returning a prompt that the directory resource exists; if the storage table type is the intelligent contract resource, a prompt that the intelligent contract resource exists is returned.

S502: and writing the intelligent contract to be created in the directory resource.

Specifically, writing an intelligent contract to be created in a directory resource includes:

generating a storage table name of any intelligent contract according to the input of a user;

judging whether the name of a storage table of the intelligent contract exists or not;

if the intelligent contract does not exist, acquiring the directory resource, starting the virtual machine to execute the intelligent contract, and if the intelligent contract is successfully executed, writing the code segment information and the state information of the intelligent contract into the directory resource.

In the embodiment of the disclosure, when a contract is deployed, it is predetermined that the parent directories of the level directory all exist and information can be written in, and then a virtual machine is started to execute the operation of creating the contract for deployment; after the virtual machine is successfully executed, a contract table is created, contract code segments, ABIs, state data and the like after the virtual machine is executed are written into the contract table, and finally meta information of newly deployed contracts is recorded in a data table of a parent directory.

Taking the intelligent contract test1 of "/apps/Hello" as an example, the explanation is as follows:

deploying a storage table name of the intelligent contract "/apps/Hello/test 1";

judging whether the storage table name "/apps/Hello/test 1" exists;

if the directory resources do not exist, acquiring the directory resources, "/apps/Hello", starting the virtual machine to execute the intelligent contract test1 to be deployed, and if the execution is successful, writing code segment information and state information of the intelligent contract test1 into the directory resources, and feeding back a prompt of successful deployment; if the execution fails, returning a prompt of the execution failure;

if so, a prompt is returned that the intelligent contract "/apps/Hello/test 1" already exists.

It should be noted that: the user can access the meta-information of the resources (directory resources and intelligent contract resources) under any path through the interface. And during access, judging whether the path has resources in advance, if so, accessing a storage table of the upper-level directory resource, and checking whether the target resource under the path is the intelligent contract resource or the directory resource. If the contract is an intelligent contract resource, returning meta-information of the intelligent contract; if the type of the directory resource is the directory resource type, the meta-information of the directory resource is returned, and all the sub-resources (including the meta-information of all the intelligent contracts) in the path are returned.

Referring to fig. 6, fig. 6 is a first schematic structural diagram of an intelligent contract invoking apparatus based on a blockchain according to an embodiment of the present disclosure. As shown in fig. 6, the intelligent contract invoking apparatus 60 based on a blockchain is applied to any node of the blockchain, in which a scheduler for scheduling and allocating transaction information, an executor for executing an intelligent contract, and a storage unit for storing the intelligent contract are disposed, and the apparatus includes: a receiving module 601, a scheduling module 602, a processing module 603, and an executing module 604.

The receiving module 601 is configured to receive transaction information sent by a client, where the transaction information includes path information of an intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path;

the scheduling module 602 is configured to place the received transaction information into a scheduler so that the scheduler distributes the transaction information to different executors;

the processing module 603 is configured to query, by each executor based on path information of the to-be-executed intelligent contract corresponding to each transaction information, a storage unit to obtain the intelligent contract corresponding to each transaction information, where the storage unit includes each intelligent contract stored according to a tree file directory structure, and a storage path of each intelligent contract is unique;

the executing module 604 is configured to execute the intelligent contract on the transaction information through each executor, so as to obtain an execution result.

The transaction information carries path information of the intelligent contract to be executed corresponding to the transaction information, and the path information corresponds to a unique intelligent contract storage path; the storage unit of each node of the block chain stores each intelligent contract stored according to a tree file directory structure, the storage path of each intelligent contract is unique, each actuator of the block chain node accesses the storage unit according to the path information to obtain the corresponding intelligent contract according to the unique intelligent contract storage path, and executes the transaction information according to the intelligent contract to obtain the execution result. Because each intelligent contract stored in the storage unit according to the tree file directory structure is unique and isolated when being scheduled by different executors, the synchronization of CNS table data related to the intelligent contracts is not needed when the executors execute transactions in parallel, and the efficiency of the block chain in executing the intelligent contracts in parallel on transaction information is improved.

In one or more embodiments of the present disclosure, the storage unit includes each intelligent contract stored according to a tree file directory structure, and a storage path of each intelligent contract is unique, specifically: the storage unit comprises directory resources and intelligent contract resources which are stored in a storage table form; each directory resource comprises a plurality of sub-resources, the intelligent contract resources of the same type belong to the tail-end sub-resources of the same directory resource, and the intelligent contract resources comprise code segment information and state information of an intelligent contract.

In one or more embodiments of the present disclosure, the scheduling module 602 is specifically configured to: splitting path information of an intelligent contract to be executed corresponding to any transaction information to obtain names of storage tables corresponding to the path information; and sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables so as to obtain the intelligent contract resources corresponding to the path information.

In one or more embodiments of the present disclosure, the scheduling module 602 is specifically configured to perform a process of sequentially accessing, according to the names of the storage tables, the corresponding storage tables in the storage unit to obtain the intelligent contract resource corresponding to the path information, where the process includes: accessing a cache, and sequentially reading each storage table with the name of each storage table from the cache; if the storage tables can be read from the cache, sequentially inquiring the storage tables from the cache according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource; and if the storage tables cannot be read from the cache, sequentially inquiring the storage tables from the storage unit of the block chain according to the names of the storage tables until the storage table corresponding to the intelligent contract resource is determined, so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource.

In one or more embodiments of the present disclosure, the scheduling module 602 is specifically configured to perform a process of sequentially querying each storage table according to the name of each storage table until determining a storage table corresponding to an intelligent contract resource, so as to obtain the intelligent contract resource corresponding to the path information from the storage table corresponding to the intelligent contract resource, where the process includes: and according to the level of each storage table name in the path information, sequentially inquiring the storage tables corresponding to each storage table name one by one to obtain the storage tables corresponding to the intelligent contract resources so as to obtain the intelligent contract resources corresponding to the path information from the storage tables corresponding to the intelligent contract resources.

The apparatus provided in this embodiment may be used to implement the technical solutions of the above method embodiments, and the implementation principles and technical effects are similar, which are not described herein again.

Referring to fig. 7, fig. 7 is a schematic structural diagram of a block chain-based intelligent contract invoking apparatus according to an embodiment of the present disclosure. As shown in fig. 7, the intelligent contract invoking apparatus 60 based on block chain further includes:

a directory creation module 605 configured to determine any directory resource through creation or query;

and a contract creation module 606, configured to write the intelligent contract to be created in the directory resource.

In one or more embodiments of the present disclosure, the directory creating module 605 is specifically configured to generate a storage table name of any directory resource according to an input of a user; judging whether the storage table name of the directory resource exists or not; if not, creating the directory resource, wherein the directory resource comprises meta-information of a directory; if the directory resource exists, judging whether the storage table name is the table name of the intelligent contract resource, and if not, returning a prompt that the directory resource exists.

In one or more embodiments of the present disclosure, the catalog creation module 606 is specifically configured to generate a storage table name of any intelligent contract according to an input of a user; judging whether the storage table name of the intelligent contract exists; if the intelligent contract does not exist, the directory resource is obtained, the virtual machine is started to execute the intelligent contract, and if the intelligent contract is executed successfully, code segment information and state information of the intelligent contract are written into the directory resource.

The apparatus provided in this embodiment may be used to implement the technical solutions of the above method embodiments, and the implementation principles and technical effects are similar, which are not described herein again.

Referring to fig. 8, fig. 8 is a schematic diagram of a hardware structure of a service device according to an embodiment of the present disclosure. As shown in fig. 8, the service apparatus 80 of the present embodiment includes: a processor 801 and a memory 802; wherein

A memory 802 for storing computer-executable instructions;

the processor 801 is configured to execute the computer-executable instructions stored in the memory to implement the steps performed by the blockchain of the server in the above embodiments. Reference may be made in particular to the description relating to the method embodiments described above.

Alternatively, the memory 802 may be separate or integrated with the processor 801.

When the memory 802 is provided separately, the service-based device further includes a bus 803 for connecting the memory 802 and the processor 801.

The embodiment of the present disclosure also provides a computer-readable storage medium, in which computer execution instructions are stored, and when a processor executes the computer execution instructions, the method for intelligent contract calling based on a block chain is implemented.

The embodiment of the present disclosure further provides a computer program product, and when the computer program is executed by a processor, the method for intelligent contract calling based on a blockchain is implemented.

In the several embodiments provided in the present disclosure, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described device embodiments are merely illustrative, and for example, the division of the modules is only one logical division, and other divisions may be realized in practice, for example, a plurality of modules may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or modules, and may be in an electrical, mechanical or other form.

The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to implement the solution of the present embodiment.

In addition, functional modules in the embodiments of the present disclosure may be integrated into one processing unit, or each module may exist alone physically, or two or more modules are integrated into one unit. The unit formed by the modules can be realized in a hardware form, and can also be realized in a form of hardware and a software functional unit.

The integrated module implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor to execute some steps of the methods according to the embodiments of the present disclosure.

It should be understood that the Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with the present invention may be embodied directly in a hardware processor, or in a combination of the hardware and software modules within the processor.

The memory may comprise a high-speed RAM memory, and may further comprise a non-volatile storage NVM, such as at least one disk memory, and may also be a usb disk, a removable hard disk, a read-only memory, a magnetic or optical disk, etc.

The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (Extended Industry Standard Architecture) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, the buses in the figures of the present disclosure are not limited to only one bus or one type of bus.

The storage medium may be implemented by any type or combination of volatile or non-volatile memory devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.

An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. Of course, the storage medium may also be integral to the processor. The processor and the storage medium may reside in an Application Specific Integrated Circuits (ASIC). Of course, the processor and the storage medium may reside as discrete components in an electronic device or host device.

Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.

Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the present disclosure, and not for limiting the same; while the present disclosure has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present disclosure.

18页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:医疗缴费方法、装置、存储介质及电子设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!