WO2023103341A1 - Blockchain-based smart contract invocation method, apparatus and device - Google Patents

Blockchain-based smart contract invocation method, apparatus and device Download PDF

Info

Publication number
WO2023103341A1
WO2023103341A1 PCT/CN2022/100650 CN2022100650W WO2023103341A1 WO 2023103341 A1 WO2023103341 A1 WO 2023103341A1 CN 2022100650 W CN2022100650 W CN 2022100650W WO 2023103341 A1 WO2023103341 A1 WO 2023103341A1
Authority
WO
WIPO (PCT)
Prior art keywords
smart contract
storage
resource
transaction information
information
Prior art date
Application number
PCT/CN2022/100650
Other languages
French (fr)
Chinese (zh)
Inventor
郭锐
李辉忠
范瑞彬
张开翔
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023103341A1 publication Critical patent/WO2023103341A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9017Indexing; Data structures therefor; Storage structures using directory or table look-up
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9027Trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3827Use of message hashing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/405Establishing or using transaction specific rules

Definitions

  • Embodiments of the present disclosure relate to the technical field of financial technology (Fintech), and in particular to a blockchain-based smart contract calling method, device and equipment.
  • Fetech technical field of financial technology
  • Embodiments of the present disclosure relate to the technical field of financial technology (Fintech), and in particular to a blockchain-based smart contract calling method, device and equipment.
  • the executor that executes the smart contract in the node of the blockchain will maintain a CNS (Contract Name Service , contract naming service) table
  • the CNS table stores the mapping relationship between the smart contract name and the smart contract address. Smart contract address, and obtain the corresponding smart contract from the smart contract address to execute the transaction.
  • the blockchain needs to execute transactions in parallel, and multiple executors of the blockchain need to execute smart contracts in parallel.
  • each executor needs to maintain a CNS table (the mapping relationship between the smart contract name and the smart contract address), when the user modifies the smart contract related information in the CNS table in an executor , it is necessary to synchronize the data of the modified CNS table to all other executors, otherwise other executors will execute wrong smart contracts, thus resulting in frequent synchronization of CNS table data between executors, affecting the blockchain Processing efficiency for executing multiple smart contracts in parallel.
  • CNS table the mapping relationship between the smart contract name and the smart contract address
  • Embodiments of the present disclosure provide a blockchain-based smart contract calling method, device, and equipment to overcome the need for frequent synchronization of CNS table data between executors in the related art, which affects the parallel execution of multiple smart contracts by the blockchain. problem of processing efficiency.
  • an embodiment of the present disclosure provides a method for invoking a smart contract based on blockchain, the method is applied to any node of the blockchain, and the node is provided with a system for scheduling and distributing transaction information.
  • a scheduler, an executor for executing smart contracts and a storage unit for storing smart contracts, the method includes:
  • the transaction information includes path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path;
  • each executor queries the storage unit to obtain the smart contract corresponding to each transaction information, wherein the storage unit contains each smart contract stored according to the tree file directory structure. contract, and the storage path of each smart contract is unique;
  • Each executor executes the smart contract on the transaction information to obtain an execution result.
  • the storage unit contains smart contracts stored in a tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: the storage unit contains Stored directory resources and smart contract resources; each directory resource contains multiple sub-resources, the same type of smart contract resources belong to the last sub-resource under the same directory resource, and the smart contract resource contains the code segment information of the smart contract and status information.
  • each executor queries the storage unit to obtain the smart contract corresponding to each transaction information based on the path information of the smart contract to be executed corresponding to each transaction information, including: corresponding to any transaction information Split the path information of the smart contract to be executed to obtain the names of the storage tables corresponding to the path information; access the corresponding storage tables in the storage unit in turn according to the names of the storage tables to obtain the corresponding smart contract resources.
  • the sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables to obtain the smart contract resources corresponding to the path information includes: accessing the cache, from the cache Read each storage table whose name is the name of each storage table in turn; if each storage table can be read from the cache, then query each storage table sequentially from the cache according to the names of each storage table until it is determined The storage table corresponding to the smart contract resource, to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource; if the storage table cannot be read from the cache, then from the storage unit of the block chain Query each storage table in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource.
  • the storage tables are queried sequentially according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart information corresponding to the path information from the storage table corresponding to the smart contract resource.
  • Contract resources including: according to the level of each storage table name in the path information, query the storage tables corresponding to each storage table name one by one to obtain the storage table corresponding to the smart contract resource, so as to obtain the storage table corresponding to the smart contract resource. Obtain the smart contract resource corresponding to the path information.
  • each smart contract also includes the step of storing each smart contract according to the tree file directory structure, as follows: determine any directory resource by creating or querying; write the smart contract to be created in the directory resource.
  • any directory resource is determined by creation or query, including:
  • the writing the smart contract to be created in the directory resource includes: generating the storage table name of any smart contract according to user input; judging whether the storage table name of the smart contract is Exist; if not, then obtain the directory resource, and start the virtual machine to execute the smart contract, if the execution is successful, then write the code segment information and status information of the smart contract in the directory resource.
  • the embodiment of the present disclosure provides a block chain-based smart contract calling device, the device is applied to any node of the block chain, and the node is provided with a system for scheduling and distributing transaction information.
  • a scheduler, an executor for executing smart contracts and a storage unit for storing smart contracts, the device includes:
  • the receiving module is used to receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path;
  • a scheduling module configured to put the received transaction information into a scheduler so that the scheduler distributes the transaction information to different executors
  • the dispatching module is used to query the storage unit to obtain the smart contract corresponding to each transaction information through each executor based on the path information of the smart contract to be executed corresponding to each transaction information, wherein the storage unit contains the following information according to the tree file directory Each smart contract stored in the structure, and the storage path of each smart contract is unique;
  • the execution module is configured to execute the smart contract on the transaction information through each executor to obtain an execution result.
  • 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 computer-executed instructions stored in the memory, so that the processor executes the blockchain-based smart contract calling method described in the first aspect and various possible designs of the first aspect.
  • an embodiment of the present disclosure provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the above first aspect and the first The smart contract calling method based on the block chain described in various possible designs.
  • any node of the blockchain carries the path information of the smart contract to be executed corresponding to the transaction information in the transaction information, and the The path information corresponds to the unique storage path of the smart contract; the storage unit of each node of the blockchain stores the smart contracts stored according to the tree file directory structure, and the storage path of each smart contract is unique, the blockchain node According to the path information, each executor accesses the storage unit to obtain the corresponding smart contract according to the unique smart contract storage path, and executes the transaction information according to the smart contract to obtain the execution result.
  • FIG. 1 is a schematic diagram of a scenario of a blockchain-based smart contract calling method provided by the present disclosure
  • FIG. 2 is a first schematic flow diagram of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure
  • FIG. 3 is a logical structure diagram of smart contracts stored according to the tree-shaped file directory structure provided by the embodiment of the present disclosure
  • Fig. 4 is a schematic diagram of the actual storage form of the smart contract provided by the embodiment of the present disclosure.
  • FIG. 5 is a second schematic flow diagram of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure
  • FIG. 6 is a schematic structural diagram of a block chain-based smart contract calling device provided by an embodiment of the present disclosure
  • FIG. 7 is a second structural diagram of a blockchain-based smart contract calling device provided by an embodiment of the present disclosure.
  • FIG. 8 is a schematic diagram of a hardware structure of a service device provided by an embodiment of the present disclosure.
  • the blockchain system can be understood as a distributed storage system maintained and trusted by multiple nodes.
  • the bottom layer of the blockchain is a chain composed of a series of blocks.
  • each block also records the hash value of the previous block.
  • a block consists of a block header and a block body, where the block header defines important fields such as the height of the block and the hash value of the previous block, while the block body mainly stores transaction data.
  • the blockchain uses cryptography to ensure the security of data transmission and access, and uses a chain structure to ensure that the data on the chain cannot be tampered with.
  • Smart contract refers to a contract defined in digital form that can automatically execute terms.
  • the digital form means that the contract must be implemented with computer code, because as long as the participants reach an agreement, the rights and obligations established by the smart contract will be automatically executed. And the results cannot be denied.
  • blockchain applications when the transaction to deploy the smart contract reaches a consensus among most nodes, it can be considered that the smart contract has been embedded in the blockchain system.
  • Ethereum Virtual Machine (the executor of the smart contract): After the smart contract is compiled into a binary file, it is deployed to the node of the blockchain. The user triggers the execution of the smart contract by calling the interface of the smart contract. As the executor of the smart contract code, the Ethereum virtual machine executes the code of the smart contract and modifies the data (state) on the current blockchain. The modified data will be consensused to ensure consistency.
  • FIG. 1 is a schematic diagram of a scenario of a blockchain-based smart contract calling method provided by the present disclosure.
  • client 101 includes: client 101 and blockchain node 102, which can install SDK (Software Development Kit, software development kit) for initiating transactions and generating transaction information.
  • SDK Software Development Kit, software development kit
  • the client 101 may be a personal computer, a mobile terminal or other devices such as servers.
  • the blockchain node 102 can be any node in the blockchain system, for example, it can be any node participating in the consensus process in the blockchain, or a leader node elected from the consensus nodes, and this disclosure does not make any any restrictions.
  • the blockchain node 102 is used to receive the transaction information sent by the client, and obtain the smart contract corresponding to the transaction information. Based on the smart contract, the Ethereum virtual machine (executor) is used to execute the transaction information to obtain the execution result. Consensus is carried out in the blockchain, and after the consensus is completed, it is stored on the blockchain.
  • the executor (Ethereum smart contract virtual machine) that executes the smart contract in the node of the blockchain will maintain a CNS table.
  • the CNS table will be accessed first to query the corresponding smart contract address, and the corresponding smart contract will be obtained from the smart contract address to execute the transaction.
  • the blockchain needs to execute transactions in parallel, multiple executors of the blockchain need to execute smart contracts in parallel.
  • the data of the modified CNS table must be synchronized to all other executors, otherwise other executors will execute wrong smart contracts, thus resulting in the need for frequent synchronization of CNS table data between executors, affecting blockchain parallelism Processing efficiency for executing multiple smart contracts.
  • this disclosure provides the following technical solutions: carrying the path information of the smart contract to be executed corresponding to the transaction information in the transaction information, and the path information corresponds to the unique storage path of the smart contract;
  • the storage unit stores smart contracts that are stored according to the tree-shaped file directory structure, and the storage path of each smart contract is unique.
  • Each executor of the blockchain node accesses the storage unit according to the path information and stores them according to the unique smart contract.
  • the path obtains the corresponding smart contract, executes the transaction information according to the smart contract, and obtains the execution result.
  • FIG. 2 is a first schematic flowchart of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure. This embodiment is applied to any node of the block chain shown in Figure 1, and the node is provided with a scheduler for scheduling and distributing transaction information, an executor for executing smart contracts, and a storage device for storing smart contracts. unit, the above method is detailed as follows:
  • S201 Receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique storage path of the smart contract.
  • the client may be any client that has a transaction behavior, and the client generates transaction information according to the transaction behavior and sends it to any node of the blockchain.
  • a user purchases goods in an online mall and completes the transaction through the client, and the client sends the transaction information of the purchased goods to any node in the blockchain.
  • any node of the blockchain is any node among the consensus 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.
  • the user can specify the smart contract to be executed corresponding to the transaction information on the client side, and add the path information of the smart contract to be executed to the transaction information.
  • the path information corresponds to a unique smart contract storage path, and the corresponding smart contract is obtained through the unique smart contract storage path according to the path information.
  • S202 Put the received transaction information into the scheduler so that the scheduler distributes the transaction information to different executors.
  • the scheduler is a virtual scheduler set in the nodes of the blockchain, and the virtual scheduler distributes each transaction information that can execute the smart contract in parallel to different executors according to preset rules.
  • the preset rule may be to evenly distribute each transaction information to each executor. For example, if there are 10 transaction information and 2 executors, 5 transaction information can be assigned to one executor, and the other 5 transaction information can be assigned to another executor.
  • S203 Through each executor, based on the path information of the smart contract to be executed corresponding to each transaction information, query the storage unit to obtain the smart contract corresponding to each transaction information, wherein the storage unit contains each smart contract stored according to the tree file directory structure contract, and the storage path of each smart contract is unique.
  • the storage unit contains smart contracts stored according to the tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: the storage unit contains directory resources stored in the form of a storage table and smart contract resources; each directory resource contains multiple sub-resources, and the same type of smart contract resources belong to the last sub-resource under the same directory resource, and the smart contract resource contains the code segment information and status information of the smart contract.
  • FIG. 3 is a logical structure diagram of smart contracts stored in a tree-shaped file directory structure according to an embodiment of the present disclosure.
  • “/" is the root directory, which contains multiple directory resources, as shown in Figure 3
  • "sys”, “usr”, “apps”, and “tables” are all directory resources, which are system class directories Resources, user class directory resources, application class directory resources, and table class directory resources.
  • each directory resource includes a plurality of sub-resources, and the sub-resources may be a sub-resource of the current directory resource, or may directly be smart contract resources.
  • the sub-resources of "sys1" and “sys2" contained in “sys” are the directory resources of the next level of directory resources, and "sys1" and “sys2" each contain two system smart contract resources , where “sys1” includes “system smart contract resource 1” and “system smart contract resource 2"; “sys2” includes “system smart contract resource 3” and “system smart contract resource 4".
  • FIG. 4 is a schematic diagram of the actual storage form of the smart contract provided by the embodiment of the present disclosure.
  • the storage unit contains directory resources and smart contract resources stored in the form of storage tables.
  • the storage table name is: "/tables” is a directory resource, and the storage table names of the smart contract resources contained in it are “/tables/table1" and “/tables/table2".
  • the storage table named "/tables” describes the meta information of smart contract resources
  • the storage table named “/tables/table1" and “/tables/table2” respectively contain tables Data for smart contracts "table1" and "table2".
  • each executor based on the path information of the smart contract to be executed corresponding to each transaction information, query the storage unit to obtain the smart contract corresponding to each transaction information, including:
  • path information "/apps/Hello1" is taken as an example for description:
  • the corresponding storage tables in the storage unit are sequentially accessed to obtain the smart contract resources corresponding to the path information, including: accessing the cache, and sequentially reading the storage tables whose names are the names of the storage tables from the cache ; If the storage tables can be read from the cache, query the storage tables in sequence according to the names of the storage tables from the cache until the storage table corresponding to the smart contract resource is determined, so as to obtain path information from the storage table corresponding to the smart contract resource Corresponding smart contract resources; if the storage tables cannot be read from the cache, query each storage table in turn from the storage unit of the blockchain according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the data from the smart contract. Get the smart contract resource corresponding to the path information in the storage table corresponding to the resource.
  • each storage table in turn according to the name of each storage table until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource, including: according to the name of each storage table in the path The level in the information, query the storage table corresponding to each storage table name one by one to obtain the storage table corresponding to the smart contract resource, and obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource.
  • each executor after the transaction information of the smart contract that can be executed in parallel is distributed to different executors, each executor will first read the cache. If the executor has executed the same smart contract before, then the execution The server will cache the data corresponding to the smart contract, and the data corresponding to the smart contract includes each storage table corresponding to the storage path of the smart contract.
  • the executor will first read the storage table named "/apps” and the storage table “/tables” from the cache; and then read the Take the storage table whose names are “/apps/Hello1" and “/tables/table1", respectively, where the storage table of "/apps/Hello1" and “/tables/table1” respectively contain Smart contract resources for the "Hello1" smart contract and the "table1" smart contract.
  • the executor If the executor does not read the above storage tables from the cache, it will obtain the corresponding storage tables from the storage unit, and write the storage tables obtained from the storage unit into the executor.
  • the writing process For slow writing, it takes longer than reading directly from the buffer.
  • each storage table of the smart contract can support distributed storage of data in the storage unit, so that when the executor loads each storage table from the storage unit, all data is dispersed.
  • the executor when the executor loads the smart contract from the storage unit, it can also specify the path of a certain directory resource, and load all the smart contracts under the directory resource to the same executor, so that different execution
  • the directory resources loaded by the server are different, so as to achieve the isolation of smart contracts at the directory resource level.
  • S204 Execute the smart contract on the transaction information through each executor, and obtain the execution result.
  • the executor executes the smart contract on the transaction information, obtains the execution result of the transaction information, and then sends the execution result of the transaction information to other consensus nodes in the blockchain for consensus. After the consensus of the execution result, the execution result of the transaction information is stored on the chain in the blockchain.
  • each executor of the blockchain node accesses the storage unit according to the path information to obtain the corresponding smart contract according to the unique smart contract storage path, and Execute the transaction information according to the smart contract and get the execution result. Since the smart contracts stored in the storage unit according to the tree-shaped file directory structure are unique and isolated from each other when they are scheduled by different executors, it is not necessary for each executor to perform smart contract-related CNS when executing transactions in parallel. The synchronization of table data improves the efficiency of blockchain in parallel execution of smart contracts for transaction information.
  • FIG. 5 is a second schematic flow diagram of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure. This embodiment also describes the steps of how to store each smart contract according to the tree-shaped file directory structure, which is detailed as follows:
  • S501 Determine any directory resource by creating or querying.
  • any directory resource including:
  • the user can create a new directory resource under any existing directory resource.
  • S502 Write the smart contract to be created in the directory resource.
  • write the smart contract to be created in the directory resource including:
  • the directory resource is obtained, and the virtual machine is started to execute the smart contract. If the execution is successful, the code segment information and status information of the smart contract are written in the directory resource.
  • the virtual machine when deploying a contract, it will be pre-determined that the parent directory of the level directory already exists and information can be written, and then the virtual machine is started to execute the deployment and creation contract operation; after the virtual machine is successfully executed, the contract table is created, And write the contract code segment, ABI, state data, etc. after the virtual machine is executed into the contract table, and finally record the meta information of the newly deployed contract in the data table of the parent directory.
  • users can access the meta information of resources (directory resources and smart contract resources) under any path through the interface.
  • it is pre-determined whether there is a resource in the path, and if it exists, access the storage table of the upper-level directory resource to check whether the target resource under the path is a smart contract resource or a directory resource. If it is a smart contract resource, it will return the meta information of the smart contract; if it is a directory resource type, it will return the meta information of the directory resource, and return all sub-resources under the path (which contains all the smart contract meta information).
  • FIG. 6 is a first structural diagram of a block chain-based smart contract calling device provided by an embodiment of the present disclosure.
  • the block chain-based smart contract calling device 60 is applied to any node of the block chain, and the node is provided with a scheduler for scheduling and distributing transaction information, for executing An executor of the smart contract and a storage unit for storing the smart contract, the device includes: a receiving module 601 , a scheduling module 602 , a processing module 603 and an executing module 604 .
  • the receiving module 601 is used to receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path ;
  • the processing module 603 is used to query the storage unit to obtain the smart contract corresponding to each transaction information through each executor based on the path information of the smart contract to be executed corresponding to each transaction information, wherein the storage unit contains information according to the tree file Each smart contract stored in the directory structure, and the storage path of each smart contract is unique;
  • the execution module 604 is configured to execute the smart contract on the transaction information through each executor to obtain an execution result.
  • the storage unit of each node of the blockchain stores the information according to the tree file directory structure
  • Each stored smart contract, and the storage path of each smart contract is unique, each executor of the blockchain node accesses the storage unit according to the path information to obtain the corresponding smart contract according to the unique smart contract storage path, and executes the transaction according to the smart contract information to get the execution result. Since the smart contracts stored in the storage unit according to the tree-shaped file directory structure are unique and isolated from each other when they are scheduled by different executors, it is not necessary for each executor to perform smart contract-related CNS when executing transactions in parallel. The synchronization of table data improves the efficiency of blockchain in parallel execution of smart contracts for transaction information.
  • the storage unit contains smart contracts stored in a tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: the storage unit contains the following Store directory resources and smart contract resources stored in the form of tables; each directory resource contains multiple sub-resources, the same type of smart contract resources belong to the last sub-resource under the same directory resource, and the smart contract resource contains the code of the smart contract segment information and status information.
  • the scheduling module 602 is specifically configured to: split the path information of the smart contract to be executed corresponding to any transaction information, and obtain the storage Table name; according to the names of the storage tables, access the corresponding storage tables in the storage unit in order to obtain the smart contract resources corresponding to the path information.
  • the scheduling module 602 is specifically configured to sequentially access the corresponding storage tables in the storage unit according to the names of the storage tables, so as to obtain the intelligence information corresponding to the path information.
  • the process of contract resources including: accessing the cache, sequentially reading the storage tables whose names are the names of the storage tables from the cache; if the storage tables can be read from the cache, then from the cache Query each storage table in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource;
  • Each storage table is read from the storage unit of the blockchain, and each storage table is queried sequentially according to the names of the storage tables in the blockchain until the storage table corresponding to the smart contract resource is determined, so as to obtain all data from the storage table corresponding to the smart contract resource.
  • the smart contract resource corresponding to the above path information.
  • the scheduling module 602 is specifically used to inquire each storage table in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain from the smart contract resource
  • the process of obtaining the smart contract resource corresponding to the path information in the corresponding storage table includes: according to the level of each storage table name in the path information, query the storage table corresponding to each storage table name one by one to obtain the smart contract resource
  • the corresponding storage table is used to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource.
  • the device provided in this embodiment can be used to implement the technical solutions of the above method embodiments, and its implementation principle and technical effect are similar, so this embodiment will not repeat them here.
  • FIG. 7 is a second schematic structural diagram of a blockchain-based smart contract calling device provided by an embodiment of the present disclosure. As shown in Figure 7, the block chain-based smart contract calling device 60 also includes:
  • a directory creation module 605, configured to determine any directory resource by creating or querying
  • a contract creation module 606, configured to write the smart contract to be created in the directory resource.
  • the directory creation module 605 is specifically configured to generate the storage table name of any directory resource according to user input; determine whether the storage table name of the directory resource already exists; if If it does not exist, then create the directory resource, wherein the directory resource includes the meta information of the directory; if it exists, then judge whether the storage table name is the table name of the smart contract resource, if not, then return that the directory resource has been hints that exist.
  • the directory creation module 606 is specifically configured to generate the storage table name of any smart contract according to user input; determine whether the storage table name of the smart contract already exists; if If it does not exist, then obtain the directory resource, start a virtual machine to execute the smart contract, and if the execution is successful, write the code segment information and status information of the smart contract in the directory resource.
  • the device provided in this embodiment can be used to implement the technical solutions of the above method embodiments, and its implementation principle and technical effect are similar, so this embodiment will not repeat them here.
  • FIG. 8 is a schematic diagram of a hardware structure of a service device provided by an embodiment of the present disclosure.
  • the service device 80 of this embodiment includes: a processor 801 and a memory 802;
  • memory 802 for storing computer-executable instructions
  • the processor 801 is configured to execute the computer-executed instructions stored in the memory, so as to realize the various steps executed by the server-side blockchain in the above-mentioned embodiments. For details, refer to the related descriptions in the foregoing method embodiments.
  • the memory 802 can be independent or integrated with the processor 801 .
  • the service-based device further includes a bus 803 for connecting the memory 802 and the processor 801 .
  • An embodiment of the present disclosure also provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the aforementioned blockchain-based intelligence Contract call method.
  • An embodiment of the present disclosure also provides a computer program product, when the computer program is executed by a processor, it implements the blockchain-based smart contract calling method as described above.
  • the disclosed devices and methods may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the modules is only a logical function division. In actual implementation, there may be other division methods, for example, multiple modules can be combined or integrated. to another system, or some features may be ignored, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or modules may be in electrical, mechanical or other forms.
  • modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to implement the solution of this embodiment.
  • each functional module in each embodiment of the present disclosure may be integrated into one processing unit, each module may exist separately physically, or two or more modules may be integrated into one unit.
  • the units formed by the above modules can be implemented in the form of hardware, or in the form of hardware plus software functional units.
  • the above-mentioned integrated modules implemented in the form of software function modules can be stored in a computer-readable storage medium.
  • the above-mentioned software function modules are stored in a storage medium, and include several instructions for enabling a computer device (which may be a personal computer, server, or network device, etc.) or a processor to execute some steps of the methods described in various embodiments of the present disclosure.
  • processor may be a central processing unit (Central Processing Unit, referred to as CPU), and may also be other general-purpose processors, digital signal processors (Digital Signal Processor (DSP for short), Application Specific Integrated Circuit (ASIC for short), etc.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the steps of the method disclosed in conjunction with the invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
  • the storage may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage, and may also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk, or an optical disk.
  • NVM non-volatile storage
  • the bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI for short) bus or Extended Industry Standard Architecture (Extended Industry Standard Architecture, EISA for short) bus, etc.
  • ISA Industry Standard Architecture
  • PCI Peripheral Component Interconnect
  • EISA Extended Industry Standard Architecture
  • the bus can be divided into address bus, data bus, control bus and so on.
  • the buses in the drawings of the present disclosure are not limited to only one bus or one type of bus.
  • the above-mentioned storage medium can be realized by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable In addition to programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
  • SRAM static random access memory
  • EEPROM electrically erasable programmable read-only memory
  • EPROM programmable read-only memory
  • ROM read-only memory
  • magnetic memory magnetic memory
  • flash memory magnetic disk or optical disk.
  • 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.
  • the storage medium may also be a component of the processor.
  • Processors and storage media can be located in application-specific integrated circuits (Application Specific Integrated Circuits, referred to as ASIC).
  • ASIC Application Specific Integrated Circuits
  • the processor and the storage medium can also exist in the electronic device or the main control device as discrete components.
  • the aforementioned program can be stored in a computer-readable storage medium.
  • the program executes the steps including the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other various media that can store program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Theoretical Computer Science (AREA)
  • Accounting & Taxation (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Finance (AREA)
  • Strategic Management (AREA)
  • General Business, Economics & Management (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Provided in the embodiments of the present disclosure are a blockchain-based smart contract invocation method, apparatus and device. The method comprises: receiving pieces of transaction information sent by a client, wherein each piece of transaction information includes path information of a smart contract, to be executed, corresponding to the transaction information; putting the pieces of received transaction information into a scheduler, so that the scheduler distributes the pieces of transaction information to different executors; querying a storage unit by means of the executors and on the basis of the path information of the smart contracts, to be executed, corresponding to the pieces of transaction information, so as to acquire smart contracts corresponding to the pieces of transaction information, wherein the storage unit includes smart contracts which are stored according to a tree file directory structure, and the storage path of each smart contract is unique; and executing the smart contracts on the pieces of transaction information by means of the executors, so as to obtain an execution result. There is no need for executors to synchronize CNS table data related to smart contracts while concurrent execution is performed on a transaction, thereby improving the efficiency of a blockchain when concurrent execution of smart contracts is performed on transaction information.

Description

基于区块链的智能合约调用方法、装置及设备Smart contract call method, device and equipment based on block chain
本申请要求于2021年12月07日提交中国专利局、申请号为202111478999.7、申请名称为“基于区块链的智能合约调用方法、装置及设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202111478999.7 and the application title "Blockchain-based smart contract call method, device and equipment" submitted to the China Patent Office on December 07, 2021, the entire content of which is passed References are incorporated in this application.
技术领域technical field
本公开实施例涉及金融科技(Fintech)技术领域,尤其涉及一种基于区块链的智能合约调用方法、装置及设备。Embodiments of the present disclosure relate to the technical field of financial technology (Fintech), and in particular to a blockchain-based smart contract calling method, device and equipment.
背景技术Background technique
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,与区块链相关的智能合约技术也不例外,但由于金融行业的安全性、实时性要求,也对智能合约技术提出了更高的要求。With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming into financial technology (Fintech), and the smart contract technology related to blockchain is no exception. However, due to the security of the financial industry It also puts forward higher requirements for smart contract technology.
目前,现有的基于联盟区块链的智能合约管理过程中,通常是在区块链的节点中的执行智能合约的执行器(以太坊智能合约虚拟机)会维护一张CNS(Contract Name Service,合约命名服务)表,该CNS表格中存储了智能合约名称与智能合约地址的映射关系,当执行器需要对得到的某个交易执行智能合约时,会访先问该CNS表格以查询对应的智能合约地址,并从智能合约地址获取对应的智能合约,执行交易。At present, in the existing smart contract management process based on the consortium blockchain, usually the executor (Ethereum smart contract virtual machine) that executes the smart contract in the node of the blockchain will maintain a CNS (Contract Name Service , contract naming service) table, the CNS table stores the mapping relationship between the smart contract name and the smart contract address. Smart contract address, and obtain the corresponding smart contract from the smart contract address to execute the transaction.
然而,在某些场景下,区块链需要对交易并行执行处理,则需要区块链的多个执行器并行执行智能合约。这种情况下,需要每个执行器都维护了一张CNS表(智能合约名称与智能合约地址的映射关系),当用户对某个执行器中的CNS表中的智能合约相关信息进行了修改时,就必须将修改的CNS表的数据同步至其他的所有执行器,否则其他执行器会执行错误的智能合约,因此导致执行器之间需要频繁的进行CNS表数据的同步,影响区块链并行执行多个智能合约的处理效率。However, in some scenarios, the blockchain needs to execute transactions in parallel, and multiple executors of the blockchain need to execute smart contracts in parallel. In this case, each executor needs to maintain a CNS table (the mapping relationship between the smart contract name and the smart contract address), when the user modifies the smart contract related information in the CNS table in an executor , it is necessary to synchronize the data of the modified CNS table to all other executors, otherwise other executors will execute wrong smart contracts, thus resulting in frequent synchronization of CNS table data between executors, affecting the blockchain Processing efficiency for executing multiple smart contracts in parallel.
技术解决方案technical solution
本公开实施例提供一种基于区块链的智能合约调用方法、装置及设备,以克服相关技术中执行器之间需要频繁的进行CNS表数据的同步,影响区块链并行执行多个智能合约的处理效率的问题。Embodiments of the present disclosure provide a blockchain-based smart contract calling method, device, and equipment to overcome the need for frequent synchronization of CNS table data between executors in the related art, which affects the parallel execution of multiple smart contracts by the blockchain. problem of processing efficiency.
第一方面,本公开实施例提供一种基于区块链的智能合约调用方法,所述方法应用于所述区块链的任一节点,所述节点中设置有用于对交易信息进行调度分配的调度器、用于执行智能合约的执行器和用于存储智能合约的存储单元,所述方法包括:In the first aspect, an embodiment of the present disclosure provides a method for invoking a smart contract based on blockchain, the method is applied to any node of the blockchain, and the node is provided with a system for scheduling and distributing transaction information. A scheduler, an executor for executing smart contracts and a storage unit for storing smart contracts, the method includes:
接收客户端发送的交易信息,其中所述交易信息中包含所述交易信息对应的待执行的智能合约的路径信息,其中所述路径信息对应唯一的智能合约存储路径;receiving the transaction information sent by the client, wherein the transaction information includes path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path;
将接收到的各交易信息放入调度器以使所述调度器将所述各交易信息分发至不同的执行器;Putting the received transaction information into the scheduler so that the scheduler distributes the transaction information to different executors;
通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的;Based on the path information of the smart contract to be executed corresponding to each transaction information, each executor queries the storage unit to obtain the smart contract corresponding to each transaction information, wherein the storage unit contains each smart contract stored according to the tree file directory structure. contract, and the storage path of each smart contract is unique;
通过各执行器对所述交易信息执行所述智能合约,得到执行结果。Each executor executes the smart contract on the transaction information to obtain an execution result.
在一种可能的设计中,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,具体为:存储单元中包含以存储表形式存储的目录资源和智能合约资源;其中每个目录资源下包含多个子资源,相同类型的智能合约资源属于同一个目录资源下最末端的子资源,智能合约资源中包含智能合约的代码段信息和状态信息。In a possible design, the storage unit contains smart contracts stored in a tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: the storage unit contains Stored directory resources and smart contract resources; each directory resource contains multiple sub-resources, the same type of smart contract resources belong to the last sub-resource under the same directory resource, and the smart contract resource contains the code segment information of the smart contract and status information.
在一种可能的设计中,述通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元中以获取各交易信息对应的智能合约,包括:对任一交易信息对应的待执行的智能合约的路径信息进行拆分,得到所述路径信息对应的各存储表名称;根据所述各存储表名称依次访问存储单元中对应的各存储表,以获取所述路径信息对应的智能合约资源。In a possible design, each executor queries the storage unit to obtain the smart contract corresponding to each transaction information based on the path information of the smart contract to be executed corresponding to each transaction information, including: corresponding to any transaction information Split the path information of the smart contract to be executed to obtain the names of the storage tables corresponding to the path information; access the corresponding storage tables in the storage unit in turn according to the names of the storage tables to obtain the corresponding smart contract resources.
在一种可能的设计中,所述根据所述各存储表名称依次访问存储单元中对应的各存储表,以获取所述路径信息对应的智能合约资源,包括:访问缓存,从所述缓存中依次读取名称为所述各存储表名称的各存储表;若能够从所述缓存中读取到各存储表,则从所述缓存中按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源;若无法从所述缓存中读取各存储表,则从区块链的存储单元中按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源。In a possible design, the sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables to obtain the smart contract resources corresponding to the path information includes: accessing the cache, from the cache Read each storage table whose name is the name of each storage table in turn; if each storage table can be read from the cache, then query each storage table sequentially from the cache according to the names of each storage table until it is determined The storage table corresponding to the smart contract resource, to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource; if the storage table cannot be read from the cache, then from the storage unit of the block chain Query each storage table in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource.
在一种可能的设计中,所述按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源,包括:按照各存储表名称在所述路径信息中的级别,逐个依次查询各存储表名称对应的存储表以获取智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源。In a possible design, the storage tables are queried sequentially according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart information corresponding to the path information from the storage table corresponding to the smart contract resource. Contract resources, including: according to the level of each storage table name in the path information, query the storage tables corresponding to each storage table name one by one to obtain the storage table corresponding to the smart contract resource, so as to obtain the storage table corresponding to the smart contract resource. Obtain the smart contract resource corresponding to the path information.
在一种可能的设计中,还包括按照树形文件目录结构存储各智能合约的步骤,如下:通过创建或查询,确定任一目录资源;在所述目录资源中写入待创建的智能合约。In a possible design, it also includes the step of storing each smart contract according to the tree file directory structure, as follows: determine any directory resource by creating or querying; write the smart contract to be created in the directory resource.
在一种可能的设计中,述通过创建或查询,确定任一目录资源,包括:In one possible design, any directory resource is determined by creation or query, including:
根据用户的输入生成任一目录资源的存储表名称;判断所述目录资源的存储表名称是否已存在;若不存在,则创建所述目录资源,其中所述目录资源包括目录的元信息;若存在,则判断所述存储表名称是否为智能合约资源的表名,若不是,则返回所述目录资源已存在的提示。Generate the storage table name of any directory resource according to the user's input; judge whether the storage table name of the directory resource already exists; if not, create the directory resource, wherein the directory resource includes the meta information of the directory; if If it exists, it is judged whether the name of the storage table is the table name of the smart contract resource, and if not, a prompt that the directory resource already exists is returned.
在一种可能的设计中,所述在所述目录资源中写入待创建的智能合约,包括:根据用户的输入生成任一智能合约的存储表名称;判断所述智能合约的存储表名称是否已存在;若不存在,则获取所述目录资源,并启动虚拟机执行所述智能合约,若执行成功,则在所述目录资源中写入所述智能合约的代码段信息和状态信息。In a possible design, the writing the smart contract to be created in the directory resource includes: generating the storage table name of any smart contract according to user input; judging whether the storage table name of the smart contract is Exist; if not, then obtain the directory resource, and start the virtual machine to execute the smart contract, if the execution is successful, then write the code segment information and status information of the smart contract in the directory resource.
第二方面,本公开实施例提供一种基于区块链的智能合约调用装置,所述装置应用于所述区块链的任一节点,所述节点中设置有用于对交易信息进行调度分配的调度器、用于执行智能合约的执行器和用于存储智能合约的存储单元,所述装置包括:In the second aspect, the embodiment of the present disclosure provides a block chain-based smart contract calling device, the device is applied to any node of the block chain, and the node is provided with a system for scheduling and distributing transaction information. A scheduler, an executor for executing smart contracts and a storage unit for storing smart contracts, the device includes:
接收模块,用于接收客户端发送的交易信息,其中所述交易信息中包含所述交易信息对应的待执行的智能合约的路径信息,其中所述路径信息对应唯一的智能合约存储路径;The receiving module is used to receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path;
调度模块,用于将接收到的各交易信息放入调度器以使所述调度器将所述各交易信息分发至不同的执行器;A scheduling module, configured to put the received transaction information into a scheduler so that the scheduler distributes the transaction information to different executors;
调度模块,用于通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的;The dispatching module is used to query the storage unit to obtain the smart contract corresponding to each transaction information through each executor based on the path information of the smart contract to be executed corresponding to each transaction information, wherein the storage unit contains the following information according to the tree file directory Each smart contract stored in the structure, and the storage path of each smart contract is unique;
执行模块,用于通过各执行器对所述交易信息执行所述智能合约,得到执行结果。The execution module is configured to execute the smart 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 computer-executed instructions stored in the memory, so that the processor executes the blockchain-based smart contract calling method described in the first aspect and various possible designs of the first aspect.
第四方面,本公开实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如上第一方面以及第一方面各种可能的设计所述的基于区块链的智能合约调用方法。In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the above first aspect and the first The smart contract calling method based on the block chain described in various possible designs.
本公开实施例提供的基于区块链的智能合约调用方法、装置及设备,区块链的的任一节点,通过在交易信息中携带交易信息对应的待执行的智能合约的路径信息,且该路径信息对应唯一的智能合约存储路径;区块链各节点的存储单元中存储了包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,区块链节点的各执行器根据路径信息访问存储单元按照唯一的智能合约存储路径获取对应的智能合约,并根据智能合约执行交易信息,得到执行结果。由于存储单元中按照树形文件目录结构存储的各智能合约在被不同的执行器调度时,是唯一的且是相互隔离的,因此不需要各执行器在并行执行交易时进行智能合约相关的CNS表数据的同步,提升了区块链在对交易信息并行执行智能合约的效率。In the blockchain-based smart contract calling method, device, and equipment provided by the embodiments of the present disclosure, any node of the blockchain carries the path information of the smart contract to be executed corresponding to the transaction information in the transaction information, and the The path information corresponds to the unique storage path of the smart contract; the storage unit of each node of the blockchain stores the smart contracts stored according to the tree file directory structure, and the storage path of each smart contract is unique, the blockchain node According to the path information, each executor accesses the storage unit to obtain the corresponding smart contract according to the unique smart contract storage path, and executes the transaction information according to the smart contract to obtain the execution result. Since the smart contracts stored in the storage unit according to the tree-shaped file directory structure are unique and isolated from each other when they are scheduled by different executors, it is not necessary for each executor to perform smart contract-related CNS when executing transactions in parallel. The synchronization of table data improves the efficiency of blockchain in parallel execution of smart contracts for transaction information.
附图说明Description of drawings
图1为本公开提供的基于区块链的智能合约调用方法的场景示意图;FIG. 1 is a schematic diagram of a scenario of a blockchain-based smart contract calling method provided by the present disclosure;
图2为本公开实施例提供的基于区块链的智能合约调用方法的流程示意图一;FIG. 2 is a first schematic flow diagram of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure;
图3为本公开实施例提供的各智能合约按照树形文件目录结构存储的逻辑结构图;FIG. 3 is a logical structure diagram of smart contracts stored according to the tree-shaped file directory structure provided by the embodiment of the present disclosure;
图4为本公开实施例提供的智能合约实际存储形式的示意图;Fig. 4 is a schematic diagram of the actual storage form of the smart contract provided by the embodiment of the present disclosure;
图5为本公开实施例提供的基于区块链的智能合约调用方法的流程示意图二;FIG. 5 is a second schematic flow diagram of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure;
图6为本公开实施例提供的基于区块链的智能合约调用装置的结构示意图一;FIG. 6 is a schematic structural diagram of a block chain-based smart contract calling device provided by an embodiment of the present disclosure;
图7为本公开实施例提供的基于区块链的智能合约调用装置的结构示意图二;FIG. 7 is a second structural diagram of a blockchain-based smart contract calling device provided by an embodiment of the present disclosure;
图8为本公开实施例提供的服务设备的硬件结构示意图。FIG. 8 is a schematic diagram of a hardware structure of a service device provided by an embodiment of the present disclosure.
本发明的实施方式Embodiments of the present invention
为使本公开实施例的目的、技术方案和优点更加清楚,下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments It is a part of the embodiments of the present disclosure, but not all of them. Based on the embodiments in the present disclosure, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present disclosure.
技术名词解释:Explanation of technical terms:
区块链:区块链系统可以理解是一种由多个节点共同维护的及信任的分布式存储系统。区块链底层是由一系列区块组成的一条链,每个块上除了记录本块的数据还会记录上一块的哈希值,通过这种方式组成链式的数据结构。一个区块由块头和块体组成,其中块头定义包括该区块高度、上一个区块的哈希值等重要字段,而块体主要存储交易数据。区块链利用密码学的方式保证数据传输和访问的安全,并利用链式结构保证链上数据不可被篡改。Blockchain: The blockchain system can be understood as a distributed storage system maintained and trusted by multiple nodes. The bottom layer of the blockchain is a chain composed of a series of blocks. In addition to recording the data of this block, each block also records the hash value of the previous block. In this way, a chained data structure is formed. A block consists of a block header and a block body, where the block header defines important fields such as the height of the block and the hash value of the previous block, while the block body mainly stores transaction data. The blockchain uses cryptography to ensure the security of data transmission and access, and uses a chain structure to ensure that the data on the chain cannot be tampered with.
智能合约:智能合约指以数字形式定义的能自动执行条款的合约,数字形式意味着合约必须用计算机代码实现,因为只要参与方达成协定,智能合约建立的权利和义务,就会被自动执行,且结果不能被否认。在区块链应用中,当部署智能合约的交易在大多数节点中达成共识,就可以认为智能合约已嵌入区块链系统中。Smart contract: A smart contract refers to a contract defined in digital form that can automatically execute terms. The digital form means that the contract must be implemented with computer code, because as long as the participants reach an agreement, the rights and obligations established by the smart contract will be automatically executed. And the results cannot be denied. In blockchain applications, when the transaction to deploy the smart contract reaches a consensus among most nodes, it can be considered that the smart contract has been embedded in the blockchain system.
以太坊虚拟机(智能合约的执行器):当智能合约被编译成二进制文件后,被部署到区块链的节点上。用户通过调用智能合约的接口,来触发智能合约的执行操作。以太坊虚拟机作为智能合约代码的执行器执行智能合约的代码,修改当前区块链上的数据(状态)。被修改的数据,会被共识,确保一致性。Ethereum Virtual Machine (the executor of the smart contract): After the smart contract is compiled into a binary file, it is deployed to the node of the blockchain. The user triggers the execution of the smart contract by calling the interface of the smart contract. As the executor of the smart contract code, the Ethereum virtual machine executes the code of the smart contract and modifies the data (state) on the current blockchain. The modified data will be consensused to ensure consistency.
参考图1,图1为本公开提供的基于区块链的智能合约调用方法的场景示意图。在该场景中,包括:客户端101和区块链节点102,可以安装SDK(Software Development Kit,软件开发工具包),用于发起交易,并产生交易信息。其中客户端101,可以是个人电脑、移动终端或其他服务器等设备。Referring to FIG. 1 , FIG. 1 is a schematic diagram of a scenario of a blockchain-based smart contract calling method provided by the present disclosure. In this scenario, it includes: client 101 and blockchain node 102, which can install SDK (Software Development Kit, software development kit) for initiating transactions and generating transaction information. Wherein the client 101 may be a personal computer, a mobile terminal or other devices such as servers.
其中,区块链节点102,可以是区块链系统中任一节点,例如可以是区块链中参与共识过程的任一节点,或者是共识节点中选举产生一个领导节点,对此本公开不作任何限制。区块链节点102,用于接收客户端发送的交易信息,并获取交易信息对应的智能合约,基于智能合约利用以太坊虚拟机(执行器)执行交易信息,得到执行结果,对执行结果过在区块链中进行共识,共识完成后进行区块链上链存储。Among them, the blockchain node 102 can be any node in the blockchain system, for example, it can be any node participating in the consensus process in the blockchain, or a leader node elected from the consensus nodes, and this disclosure does not make any any restrictions. The blockchain node 102 is used to receive the transaction information sent by the client, and obtain the smart contract corresponding to the transaction information. Based on the smart contract, the Ethereum virtual machine (executor) is used to execute the transaction information to obtain the execution result. Consensus is carried out in the blockchain, and after the consensus is completed, it is stored on the blockchain.
目前,基于联盟区块链的智能合约管理调用中,通常是在区块链的节点中的执行智能合约的执行器(以太坊智能合约虚拟机)会维护一张CNS表,当执行器需要对得到的某个交易执行智能合约时,会访先问该CNS表格以查询对应的智能合约地址,并从智能合约地址获取对应的智能合约,执行交易。但是,若区块链需要对交易并行执行处理时,则需要区块链的多个执行器并行执行智能合约,当用户对某个执行器中的CNS表中的智能合约相关信息进行了修改时,就必须将修改的CNS表的数据同步至其他的所有执行器,否则其他执行器会执行错误的智能合约,因此导致执行器之间需要频繁的进行CNS表数据的同步,影响区块链并行执行多个智能合约的处理效率。At present, in the smart contract management call based on the alliance blockchain, usually the executor (Ethereum smart contract virtual machine) that executes the smart contract in the node of the blockchain will maintain a CNS table. When the executor needs to When executing a smart contract for a certain transaction obtained, the CNS table will be accessed first to query the corresponding smart contract address, and the corresponding smart contract will be obtained from the smart contract address to execute the transaction. However, if the blockchain needs to execute transactions in parallel, multiple executors of the blockchain need to execute smart contracts in parallel. , the data of the modified CNS table must be synchronized to all other executors, otherwise other executors will execute wrong smart contracts, thus resulting in the need for frequent synchronization of CNS table data between executors, affecting blockchain parallelism Processing efficiency for executing multiple smart contracts.
为了解决上述技术问题,本公开提供了如下技术方案:在交易信息中携带交易信息对应的待执行的智能合约的路径信息,且该路径信息对应唯一的智能合约存储路径;区块链各节点的存储单元中存储了包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,区块链节点的各执行器根据路径信息访问存储单元按照唯一的智能合约存储路径获取对应的智能合约,并根据智能合约执行交易信息,得到执行结果。由于存储单元中按照树形文件目录结构存储的各智能合约在被不同的执行器调度时,是唯一的且是相互隔离的,因此不需要各执行器在并行执行交易时进行CNS表数据的同步,使得区块链在对交易信息并行执行智能合约时效率得到大大提升。In order to solve the above technical problems, this disclosure provides the following technical solutions: carrying the path information of the smart contract to be executed corresponding to the transaction information in the transaction information, and the path information corresponds to the unique storage path of the smart contract; The storage unit stores smart contracts that are stored according to the tree-shaped file directory structure, and the storage path of each smart contract is unique. Each executor of the blockchain node accesses the storage unit according to the path information and stores them according to the unique smart contract. The path obtains the corresponding smart contract, executes the transaction information according to the smart contract, and obtains the execution result. Since the smart contracts stored in the storage unit according to the tree-shaped file directory structure are unique and isolated from each other when they are scheduled by different executors, it is not necessary for each executor to synchronize the CNS table data when executing transactions in parallel , which greatly improves the efficiency of the blockchain in parallel execution of smart contracts for transaction information.
参考图2,图2为本公开实施例提供的基于区块链的智能合约调用方法的流程示意图一。本实施例应用于图1所示的区块链的任一节点,该节点中设置有用于对交易信息进行调度分配的调度器、用于执行智能合约的执行器和用于存储智能合约的存储单元,上述方法详述如下:Referring to FIG. 2 , FIG. 2 is a first schematic flowchart of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure. This embodiment is applied to any node of the block chain shown in Figure 1, and the node is provided with a scheduler for scheduling and distributing transaction information, an executor for executing smart contracts, and a storage device for storing smart contracts. unit, the above method is detailed as follows:
S201:接收客户端发送的交易信息,其中交易信息中包含交易信息对应的待执行的智能合约的路径信息,其中路径信息对应唯一的智能合约存储路径。S201: Receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique storage path of the smart contract.
在本公开实施例中,客户端可以为任一发生交易行为的客户端,客户端根据交易行为生产交易信息,并发送至区块链的任一节点上。例如,用户在网上商城购买商品,通过客户端完成交易,客户端将购买商品的交易信息发送至区块链的任一节点。在本实施例中,区块链的任一节点为区块链中的共识节点中的任一节点。领导节点由区块链的共识节点中选举产生。任一共识节点既可以是领导节点,也可以是副本节点。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 it to any node of the blockchain. For example, a user purchases goods in an online mall and completes the transaction through the client, and the client sends the transaction information of the purchased goods to any node in the blockchain. In this embodiment, any node of the blockchain is any node among the consensus 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 generates transaction information according to the transaction behavior, the user can specify the smart contract to be executed corresponding to the transaction information on the client side, and add the path information of the smart contract to be executed to the transaction information. Wherein, the path information corresponds to a unique smart contract storage path, and the corresponding smart contract is obtained through the unique smart contract storage path according to the path information.
S202:将接收到的各交易信息放入调度器以使调度器将各交易信息分发至不同的执行器。S202: Put the received transaction information into the scheduler so that the scheduler distributes the transaction information to different executors.
在本公开实施例中,调度器为设置在区块链的节点中的虚拟调度器,该虚拟调度器按照预设规则将可并行执行智能合约的各交易信息分发至不同的执行器。In the embodiment of the present disclosure, the scheduler is a virtual scheduler set in the nodes of the blockchain, and the virtual scheduler distributes each transaction information that can execute the smart contract in parallel to different executors according to preset rules.
其中,预设规则可以是将各交易信息平均分配至各个执行器。例如,交易信息为10个,执行器为2个,可以将5个交易信息分配给一个执行器,另5个交易信息分配给另一个执行器。Wherein, the preset rule may be to evenly distribute each transaction information to each executor. For example, if there are 10 transaction information and 2 executors, 5 transaction information can be assigned to one executor, and the other 5 transaction information can be assigned to another executor.
S203:通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的。S203: Through each executor, based on the path information of the smart contract to be executed corresponding to each transaction information, query the storage unit to obtain the smart contract corresponding to each transaction information, wherein the storage unit contains each smart contract stored according to the tree file directory structure contract, and the storage path of each smart contract is unique.
在本公开实施例中, 存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,具体为:存储单元中包含以存储表形式存储的目录资源和智能合约资源;其中每个目录资源下包含多个子资源,相同类型的智能合约资源属于同一个目录资源下最末端的子资源,智能合约资源中包含智能合约的代码段信息和状态信息。In the embodiment of the present disclosure, the storage unit contains smart contracts stored according to the tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: the storage unit contains directory resources stored in the form of a storage table and smart contract resources; each directory resource contains multiple sub-resources, and the same type of smart contract resources belong to the last sub-resource under the same directory resource, and the smart contract resource contains the code segment information and status information of the smart contract.
参考图3,图3为本公开实施例提供的各智能合约按照树形文件目录结构存储的逻辑结构图。其中,“/”为根目录,根目录中包含多个目录资源,如图3中所示的“sys”、“usr”、“apps”、“tables”均为目录资源,分别为系统类目录资源、用户类目录资源、应用类目录资源、表类目录资源。其中,每个目录资源中包括多个子资源,该子资源可以是当前目录资源的下一级的目录资源,也可以直接是智能合约资源。如图3中所示的“sys”中包含的“sys1”和“sys2”的子资源为目录资源的下一级的目录资源,“sys1”和“sys2”中各包含两个系统智能合约资源,其中,“sys1”中包含“系统智能合约资源1”、“系统智能合约资源2”;“sys2”中包含“系统智能合约资源3”、“系统智能合约资源4”。其他的“usr”、“apps”、“tables”均为目录资源,其对应的子资源直接为智能合约资源;其中,“usr”中包含“用户智能合约资源1”、“用户智能合约资源2”;“apps”中包含“应用智能合约资源1”、“应用智能合约资源2”;“tables”中包含“表智能合约资源1”、“表智能合约资源2”。在本实施例中,上述各“资源”可以是以文件或表格的形式存储,对此本公开不作任何限制。Referring to FIG. 3 , FIG. 3 is a logical structure diagram of smart contracts stored in a tree-shaped file directory structure according to an embodiment of the present disclosure. Among them, "/" is the root directory, which contains multiple directory resources, as shown in Figure 3, "sys", "usr", "apps", and "tables" are all directory resources, which are system class directories Resources, user class directory resources, application class directory resources, and table class directory resources. Wherein, each directory resource includes a plurality of sub-resources, and the sub-resources may be a sub-resource of the current directory resource, or may directly be smart contract resources. As shown in Figure 3, the sub-resources of "sys1" and "sys2" contained in "sys" are the directory resources of the next level of directory resources, and "sys1" and "sys2" each contain two system smart contract resources , where "sys1" includes "system smart contract resource 1" and "system smart contract resource 2"; "sys2" includes "system smart contract resource 3" and "system smart contract resource 4". Other "usr", "apps", and "tables" are directory resources, and their corresponding sub-resources are directly smart contract resources; among them, "usr" includes "user smart contract resource 1", "user smart contract resource 2 "; "apps" includes "application smart contract resource 1" and "application smart contract resource 2"; "tables" includes "table smart contract resource 1" and "table smart contract resource 2". In this embodiment, the above "resources" may be stored in the form of files or tables, and this disclosure does not impose any limitation on this.
参考图4,图4为本公开实施例提供的智能合约实际存储形式的示意图。存储单元中包含以存储表形式存储的目录资源和智能合约资源。如图4所示,存储表名称为:“/tables”的存储表为目录资源,其包含的智能合约资源的存储表名称分别为“/tables/table1”和“/tables/table2”。其中,存储表名称为“/tables”的存储表描述了智能合约资源的元信息,存储表名称为“/tables/table1”的存储表和“/tables/table2”的存储表中分别包含了表智能合约“table1”和“table2”的数据。Referring to FIG. 4, FIG. 4 is a schematic diagram of the actual storage form of the smart contract provided by the embodiment of the present disclosure. The storage unit contains directory resources and smart contract resources stored in the form of storage tables. As shown in Figure 4, the storage table name is: "/tables" is a directory resource, and the storage table names of the smart contract resources contained in it are "/tables/table1" and "/tables/table2". Among them, the storage table named "/tables" describes the meta information of smart contract resources, and the storage table named "/tables/table1" and "/tables/table2" respectively contain tables Data for smart contracts "table1" and "table2".
具体地,通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元中以获取各交易信息对应的智能合约,包括:Specifically, through each executor, based on the path information of the smart contract to be executed corresponding to each transaction information, query the storage unit to obtain the smart contract corresponding to each transaction information, including:
对任一交易信息对应的待执行的智能合约的路径信息进行拆分,得到路径信息对应的各存储表名称;根据各存储表名称依次访问存储单元中对应的各存储表,以获取路径信息对应的智能合约资源。Split the path information of the smart contract to be executed corresponding to any transaction information to obtain the names of the storage tables corresponding to the path information; access the corresponding storage tables in the storage unit in turn according to the names of the storage tables to obtain the path information corresponding smart contract resources.
在本公开实施例中,以路径信息“/apps/Hello1”为例,进行说明:In the embodiment of the present disclosure, the path information "/apps/Hello1" is taken as an example for description:
将路径信息“/apps/Hello1”拆分为“/”、“/apps”和“/apps/Hello1”;“/”、“/apps”和“/apps/Hello1”分别对应一个存储表名称,其中“/”为根目录资源的存储表名称,“/apps”为目录资源的存储表名称,/apps/Hello1”为智能合约资源的存储表名称。Split the path information "/apps/Hello1" into "/", "/apps" and "/apps/Hello1"; "/", "/apps" and "/apps/Hello1" respectively correspond to a storage table name, Among them, "/" is the name of the storage table of the root directory resource, "/apps" is the name of the storage table of the directory resource, and /apps/Hello1" is the name of the storage table of the smart contract resource.
具体地,根据各存储表名称依次访问存储单元中对应的各存储表,以获取路径信息对应的智能合约资源,包括:访问缓存,从缓存中依次读取名称为各存储表名称的各存储表;若能够从缓存中读取到各存储表,则从缓存中按照各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取路径信息对应的智能合约资源;若无法从缓存中读取各存储表,则从区块链的存储单元中按照各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取路径信息对应的智能合约资源。Specifically, according to the names of the storage tables, the corresponding storage tables in the storage unit are sequentially accessed to obtain the smart contract resources corresponding to the path information, including: accessing the cache, and sequentially reading the storage tables whose names are the names of the storage tables from the cache ; If the storage tables can be read from the cache, query the storage tables in sequence according to the names of the storage tables from the cache until the storage table corresponding to the smart contract resource is determined, so as to obtain path information from the storage table corresponding to the smart contract resource Corresponding smart contract resources; if the storage tables cannot be read from the cache, query each storage table in turn from the storage unit of the blockchain according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the data from the smart contract. Get the smart contract resource corresponding to the path information in the storage table corresponding to the resource.
其中,按照各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取路径信息对应的智能合约资源,包括:按照各存储表名称在路径信息中的级别,逐个依次查询各存储表名称对应的存储表以获取智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取路径信息对应的智能合约资源。Among them, query each storage table in turn according to the name of each storage table until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource, including: according to the name of each storage table in the path The level in the information, query the storage table corresponding to each storage table name one by one to obtain the storage table corresponding to the smart contract resource, and obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource.
在本公开实施例中,可并行执行智能合约的各交易信息分发至不同的执行器后,每个执行器会先读取缓存,如果该执行器之前已经执行过相同的智能合约,那么该执行器就会缓存智能合约对应的数据,智能合约对应的数据包括智能合约所存储路径对应的各存储表。In the embodiment of the present disclosure, after the transaction information of the smart contract that can be executed in parallel is distributed to different executors, each executor will first read the cache. If the executor has executed the same smart contract before, then the execution The server will cache the data corresponding to the smart contract, and the data corresponding to the smart contract includes each storage table corresponding to the storage path of the smart contract.
以任一执行器执行路径信息分别为“/apps/Hello1”和“/tables/table1”两个智能合约为例,进行说明:Take two smart contracts whose execution path information is "/apps/Hello1" and "/tables/table1" respectively for any executor as an example to illustrate:
该执行器会先从缓存中读取存储表名称分别为“/apps”的存储表和“/tables”的存储表;然后再根据“/apps”的存储表和“/tables”的存储表读取存储表名称分别为“/apps/Hello1”的存储表和“/tables/table1”的存储表,其中“/apps/Hello1”的存储表和“/tables/table1”的存储表中分别包含了“Hello1”智能合约和“table1”智能合约的智能合约资源。The executor will first read the storage table named "/apps" and the storage table "/tables" from the cache; and then read the Take the storage table whose names are "/apps/Hello1" and "/tables/table1", respectively, where the storage table of "/apps/Hello1" and "/tables/table1" respectively contain Smart contract resources for the "Hello1" smart contract and the "table1" smart contract.
若该执行器会没有从缓存中读取到上述各存储表格,则从存储单元中获取对应上述各存储表格,并将从存储单元中获取的各存储表格写入执行器中,该写入过程为慢写入,相较于直接从缓冲读取耗时较长。If the executor does not read the above storage tables from the cache, it will obtain the corresponding storage tables from the storage unit, and write the storage tables obtained from the storage unit into the executor. The writing process For slow writing, it takes longer than reading directly from the buffer.
需要说明的是:智能合约的各存储表在存储单元可以支持数据的分布式存储,这样使得执行器从存储单元中加载各存储表格时,所有数据都是分散的。It should be noted that each storage table of the smart contract can support distributed storage of data in the storage unit, so that when the executor loads each storage table from the storage unit, all data is dispersed.
参考图3和图4,可以理解的是,执行器从存储单元中加载智能合约时,每个目录资源下的子资源都不能是同名的,因此,从根目录向下到每个智能合约资源的路径都是唯一的,使得执行器加载的智能合约具有唯一性。此外,执行器从存储单元中加载智能合约时,不同路径的智能合约可以被不同的执行器执行,使得不同的智能合约是相互隔离的。Referring to Figure 3 and Figure 4, it can be understood that when the executor loads the smart contract from the storage unit, the sub-resources under each directory resource cannot have the same name. Therefore, from the root directory down to each smart contract resource The path of each is unique, making the smart contract loaded by the executor unique. In addition, when the executor loads the smart contract from the storage unit, the smart contracts of different paths can be executed by different executors, so that different smart contracts are isolated from each other.
在本公开的一个实施例中,执行器从存储单元中加载智能合约时,也可以指定某个目录资源的路径,将该目录资源下的所有智能合约都加载至同一个执行器,使得不同执行器加载的目录资源是不同的,从而达到目录资源级别的智能合约的隔离性。In an embodiment of the present disclosure, when the executor loads the smart contract from the storage unit, it can also specify the path of a certain directory resource, and load all the smart contracts under the directory resource to the same executor, so that different execution The directory resources loaded by the server are different, so as to achieve the isolation of smart contracts at the directory resource level.
S204:通过各执行器对交易信息执行智能合约,得到执行结果。S204: Execute the smart contract on the transaction information through each executor, and obtain the execution result.
在本公开实施例中,执行器对交易信息执行智能合约,得到交易信息的执行结果,然后将交易信息的执行结果发送至区块链中其他的共识节点进行共识,当完成了对交易信息的执行结果的共识后,将该交易信息的执行结果在区块链中进行上链存储。In the embodiment of the present disclosure, the executor executes the smart contract on the transaction information, obtains the execution result of the transaction information, and then sends the execution result of the transaction information to other consensus nodes in the blockchain for consensus. After the consensus of the execution result, the execution result of the transaction information is stored on the chain in the blockchain.
从上述描述可知,通过在交易信息中携带交易信息对应的待执行的智能合约的路径信息,且该路径信息对应唯一的智能合约存储路径;区块链各节点的存储单元中存储了包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,区块链节点的各执行器根据路径信息访问存储单元按照唯一的智能合约存储路径获取对应的智能合约,并根据智能合约执行交易信息,得到执行结果。由于存储单元中按照树形文件目录结构存储的各智能合约在被不同的执行器调度时,是唯一的且是相互隔离的,因此不需要各执行器在并行执行交易时进行智能合约相关的CNS表数据的同步,提升了区块链在对交易信息并行执行智能合约的效率。It can be seen from the above description that by carrying the path information of the smart contract to be executed corresponding to the transaction information in the transaction information, and the path information corresponds to the unique storage path of the smart contract; Each smart contract stored in the tree-shaped file directory structure, and the storage path of each smart contract is unique, each executor of the blockchain node accesses the storage unit according to the path information to obtain the corresponding smart contract according to the unique smart contract storage path, and Execute the transaction information according to the smart contract and get the execution result. Since the smart contracts stored in the storage unit according to the tree-shaped file directory structure are unique and isolated from each other when they are scheduled by different executors, it is not necessary for each executor to perform smart contract-related CNS when executing transactions in parallel. The synchronization of table data improves the efficiency of blockchain in parallel execution of smart contracts for transaction information.
参考图5,图5为本公开实施例提供的基于区块链的智能合约调用方法的流程示意图二。本实施例还描述了如何按照树形文件目录结构存储各智能合约的步骤,详述如下:Referring to FIG. 5 , FIG. 5 is a second schematic flow diagram of a blockchain-based smart contract calling method provided by an embodiment of the present disclosure. This embodiment also describes the steps of how to store each smart contract according to the tree-shaped file directory structure, which is detailed as follows:
S501:通过创建或查询,确定任一目录资源。S501: Determine any directory resource by creating or querying.
具体地,通过创建或查询,确定任一目录资源,包括:Specifically, by creating or querying, determine any directory resource, including:
根据用户的输入生成任一目录资源的存储表名称;Generate the storage table name of any directory resource according to the user's input;
判断目录资源的存储表名称是否已存在;Determine whether the storage table name of the directory resource already exists;
若不存在,则创建目录资源,并在目录资源写入目录的元信息;If it does not exist, create a directory resource and write the meta information of the directory in the directory resource;
若存在,则判断存储表名称是否为智能合约资源的表名,若不是,则返回目录资源已存在的提示。If it exists, judge whether the storage table name is the table name of the smart contract resource, if not, return the prompt that the directory resource already exists.
在本公开实施例中,用户可以在任意现有的目录资源下创建新的目录资源。In the embodiment of the present disclosure, the user can create a new directory resource under any existing directory resource.
以创建“/apps/Hello”的目录资源为例,进行说明:Take the creation of the directory resource of "/apps/Hello" as an example to illustrate:
生成“/apps/Hello/World”的存储表名称;Generate the storage table name of "/apps/Hello/World";
判断“/apps/Hello/World”是否已存在;Determine whether "/apps/Hello/World" already exists;
若不存在,则创建目录“/apps/Hello/”,并创建“/apps/Hello/World”存储表,并在“/apps/Hello/World”存储表写入目录的元信息,得到“/apps/Hello/”的目录资源,并返回目录创建成功的提示;If it does not exist, create the directory "/apps/Hello/", and create the "/apps/Hello/World" storage table, and write the meta information of the directory in the "/apps/Hello/World" storage table, and get "/ apps/Hello/" directory resource, and returns a prompt that the directory was created successfully;
若存在,则访问目录“/apps/Hello/”的存储表“/apps/Hello/World”,并判断“/apps/Hello/World”存储表类型;若该存储表类型为目录资源,则返回目录资源已存在的提示;若该存储表类型为智能合约资源,则返回智能合约资源已存在的提示。If it exists, access the storage table "/apps/Hello/World" of the directory "/apps/Hello/", and determine the storage table type of "/apps/Hello/World"; if the storage table type is a directory resource, return A reminder that the directory resource already exists; if the storage table type is a smart contract resource, a reminder that the smart contract resource already exists will be returned.
S502:在目录资源中写入待创建的智能合约。S502: Write the smart contract to be created in the directory resource.
具体地,在目录资源中写入待创建的智能合约,包括:Specifically, write the smart contract to be created in the directory resource, including:
根据用户的输入生成任一智能合约的存储表名称;Generate the storage table name of any smart contract according to the user's input;
判断智能合约的存储表名称是否已存在;Determine whether the storage table name of the smart contract already exists;
若不存在,则获取目录资源,并启动虚拟机执行智能合约,若执行成功,则在目录资源中写入智能合约的代码段信息和状态信息。If it does not exist, the directory resource is obtained, and the virtual machine is started to execute the smart contract. If the execution is successful, the code segment information and status information of the smart contract are written in the directory resource.
在本公开实施例中,部署合约时,将会预先确定该级目录父目录均已经存在且可以写入信息,然后启动虚拟机执行部署创建合约操作;虚拟机执行成功后,创建合约的表,并将虚拟机执行后的合约代码段、ABI、状态数据等写入合约表,最后在父目录的数据表中记录新部署的合约的元信息。In the embodiment of the present disclosure, when deploying a contract, it will be pre-determined that the parent directory of the level directory already exists and information can be written, and then the virtual machine is started to execute the deployment and creation contract operation; after the virtual machine is successfully executed, the contract table is created, And write the contract code segment, ABI, state data, etc. after the virtual machine is executed into the contract table, and finally record the meta information of the newly deployed contract in the data table of the parent directory.
以“/apps/Hello”的智能合约test1为例,进行说明:Take the smart contract test1 of "/apps/Hello" as an example to illustrate:
部署智能合约“/apps/Hello/test1”的存储表名称;Deployment smart contract "/apps/Hello/test1" storage table name;
判断存储表名称“/apps/Hello/test1”是否已存在;Determine whether the storage table name "/apps/Hello/test1" already exists;
若不存在,则获取目录资源“/apps/Hello”,并启动虚拟机执行待部署的智能合约test1,若执行成功,则在目录资源中写入智能合约test1的代码段信息和状态信息,并反馈部署成功的提示;若执行失败,则返回执行失败的提示;If it does not exist, obtain the directory resource "/apps/Hello", and start the virtual machine to execute the smart contract test1 to be deployed. If the execution is successful, write the code segment information and status information of the smart contract test1 in the directory resource, and Feedback the prompt of successful deployment; if the execution fails, return the prompt of execution failure;
若存在,则返回智能合约“/apps/Hello/test1”已存在的提示。If it exists, return the prompt that the smart contract "/apps/Hello/test1" already exists.
需要说明的是:用户可以通过接口访问任意路径下的资源(目录资源和智能合约资源)的元信息。在访问时,预先判断该路径是否存在资源,如果存在则访问上一级目录资源的存储表,查看该路径下的目标资源是智能合约资源还是目录资源。如果是智能合约资源,则返回智能合约的元信息;如果是目录资源类型,则返回目录资源的元信息,并返回该路径下所有子资源(其中包含了所有的智能合约的元信息)。It should be noted that users can access the meta information of resources (directory resources and smart contract resources) under any path through the interface. When accessing, it is pre-determined whether there is a resource in the path, and if it exists, access the storage table of the upper-level directory resource to check whether the target resource under the path is a smart contract resource or a directory resource. If it is a smart contract resource, it will return the meta information of the smart contract; if it is a directory resource type, it will return the meta information of the directory resource, and return all sub-resources under the path (which contains all the smart contract meta information).
参考图6,图6为本公开实施例提供的基于区块链的智能合约调用装置的结构示意图一。如图6所示,该基于区块链的智能合约调用装置60,应用于所述区块链的任一节点,所述节点中设置有用于对交易信息进行调度分配的调度器、用于执行智能合约的执行器和用于存储智能合约的存储单元,所述装置包括:接收模块601、调度模块602、处理模块603和执行模块604。Referring to FIG. 6 , FIG. 6 is a first structural diagram of a block chain-based smart contract calling device provided by an embodiment of the present disclosure. As shown in Figure 6, the block chain-based smart contract calling device 60 is applied to any node of the block chain, and the node is provided with a scheduler for scheduling and distributing transaction information, for executing An executor of the smart contract and a storage unit for storing the smart contract, the device includes: a receiving module 601 , a scheduling module 602 , a processing module 603 and an executing module 604 .
其中,接收模块601,用于接收客户端发送的交易信息,其中所述交易信息中包含所述交易信息对应的待执行的智能合约的路径信息,其中所述路径信息对应唯一的智能合约存储路径;Wherein, the receiving module 601 is used to receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path ;
调度模块602,用于将接收到的各交易信息放入调度器以使所述调度器将所述各交易信息分发至不同的执行器;A scheduling module 602, configured to put the received transaction information into the scheduler so that the scheduler distributes the transaction information to different executors;
处理模块603,用于通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的;The processing module 603 is used to query the storage unit to obtain the smart contract corresponding to each transaction information through each executor based on the path information of the smart contract to be executed corresponding to each transaction information, wherein the storage unit contains information according to the tree file Each smart contract stored in the directory structure, and the storage path of each smart contract is unique;
执行模块604,用于通过各执行器对所述交易信息执行所述智能合约,得到执行结果。The execution module 604 is configured to execute the smart contract on the transaction information through each executor to obtain an execution result.
通过在交易信息中携带交易信息对应的待执行的智能合约的路径信息,且该路径信息对应唯一的智能合约存储路径;区块链各节点的存储单元中存储了包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,区块链节点的各执行器根据路径信息访问存储单元按照唯一的智能合约存储路径获取对应的智能合约,并根据智能合约执行交易信息,得到执行结果。由于存储单元中按照树形文件目录结构存储的各智能合约在被不同的执行器调度时,是唯一的且是相互隔离的,因此不需要各执行器在并行执行交易时进行智能合约相关的CNS表数据的同步,提升了区块链在对交易信息并行执行智能合约的效率。By carrying the path information of the smart contract to be executed corresponding to the transaction information in the transaction information, and the path information corresponds to the unique storage path of the smart contract; the storage unit of each node of the blockchain stores the information according to the tree file directory structure Each stored smart contract, and the storage path of each smart contract is unique, each executor of the blockchain node accesses the storage unit according to the path information to obtain the corresponding smart contract according to the unique smart contract storage path, and executes the transaction according to the smart contract information to get the execution result. Since the smart contracts stored in the storage unit according to the tree-shaped file directory structure are unique and isolated from each other when they are scheduled by different executors, it is not necessary for each executor to perform smart contract-related CNS when executing transactions in parallel. The synchronization of table data improves the efficiency of blockchain in parallel execution of smart contracts for transaction information.
在本公开的一个或多个实施例中,所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,具体为:存储单元中包含以存储表形式存储的目录资源和智能合约资源;其中每个目录资源下包含多个子资源,相同类型的智能合约资源属于同一个目录资源下最末端的子资源,智能合约资源中包含智能合约的代码段信息和状态信息。In one or more embodiments of the present disclosure, the storage unit contains smart contracts stored in a tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: the storage unit contains the following Store directory resources and smart contract resources stored in the form of tables; each directory resource contains multiple sub-resources, the same type of smart contract resources belong to the last sub-resource under the same directory resource, and the smart contract resource contains the code of the smart contract segment information and status information.
在本公开的一个或多个实施例中,所述调度模块602,具体用于:对任一交易信息对应的待执行的智能合约的路径信息进行拆分,得到所述路径信息对应的各存储表名称;根据所述各存储表名称依次访问存储单元中对应的各存储表,以获取所述路径信息对应的智能合约资源。In one or more embodiments of the present disclosure, the scheduling module 602 is specifically configured to: split the path information of the smart contract to be executed corresponding to any transaction information, and obtain the storage Table name; according to the names of the storage tables, access the corresponding storage tables in the storage unit in order to obtain the smart contract resources corresponding to the path information.
在本公开的一个或多个实施例中,所述调度模块602,具体用于所述根据所述各存储表名称依次访问存储单元中对应的各存储表,以获取所述路径信息对应的智能合约资源的过程,包括:访问缓存,从所述缓存中依次读取名称为所述各存储表名称的各存储表;若能够从所述缓存中读取到各存储表,则从所述缓存中按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源;若无法从所述缓存中读取各存储表,则从区块链的存储单元中按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源。In one or more embodiments of the present disclosure, the scheduling module 602 is specifically configured to sequentially access the corresponding storage tables in the storage unit according to the names of the storage tables, so as to obtain the intelligence information corresponding to the path information. The process of contract resources, including: accessing the cache, sequentially reading the storage tables whose names are the names of the storage tables from the cache; if the storage tables can be read from the cache, then from the cache Query each storage table in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource; Each storage table is read from the storage unit of the blockchain, and each storage table is queried sequentially according to the names of the storage tables in the blockchain until the storage table corresponding to the smart contract resource is determined, so as to obtain all data from the storage table corresponding to the smart contract resource. The smart contract resource corresponding to the above path information.
在本公开的一个或多个实施例中,所述调度模块602,具体用于所述按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源的过程,包括:按照各存储表名称在所述路径信息中的级别,逐个依次查询各存储表名称对应的存储表以获取智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源。In one or more embodiments of the present disclosure, the scheduling module 602 is specifically used to inquire each storage table in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain from the smart contract resource The process of obtaining the smart contract resource corresponding to the path information in the corresponding storage table includes: according to the level of each storage table name in the path information, query the storage table corresponding to each storage table name one by one to obtain the smart contract resource The corresponding storage table is used to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource.
本实施例提供的装置,可用于执行上述方法实施例的技术方案,其实现原理和技术效果类似,本实施例此处不再赘述。The device provided in this embodiment can be used to implement the technical solutions of the above method embodiments, and its implementation principle and technical effect are similar, so this embodiment will not repeat them here.
参考图7,图7为本公开实施例提供的基于区块链的智能合约调用装置的结构示意图二。如图7所示,该基于区块链的智能合约调用装置60,还包括:Referring to FIG. 7 , FIG. 7 is a second schematic structural diagram of a blockchain-based smart contract calling device provided by an embodiment of the present disclosure. As shown in Figure 7, the block chain-based smart contract calling device 60 also includes:
目录创建模块605,用于通过创建或查询,确定任一目录资源;A directory creation module 605, configured to determine any directory resource by creating or querying;
合约创建模块606,用于在所述目录资源中写入待创建的智能合约。A contract creation module 606, configured to write the smart contract to be created in the directory resource.
在本公开的一个或多个实施例中,所述目录创建模块605,具体用于根据用户的输入生成任一目录资源的存储表名称;判断所述目录资源的存储表名称是否已存在;若不存在,则创建所述目录资源,其中所述目录资源包括目录的元信息;若存在,则判断所述存储表名称是否为智能合约资源的表名,若不是,则返回所述目录资源已存在的提示。In one or more embodiments of the present disclosure, the directory creation module 605 is specifically configured to generate the storage table name of any directory resource according to user input; determine whether the storage table name of the directory resource already exists; if If it does not exist, then create the directory resource, wherein the directory resource includes the meta information of the directory; if it exists, then judge whether the storage table name is the table name of the smart contract resource, if not, then return that the directory resource has been hints that exist.
在本公开的一个或多个实施例中,所述目录创建模块606,具体用于根据用户的输入生成任一智能合约的存储表名称;判断所述智能合约的存储表名称是否已存在;若不存在,则获取所述目录资源,并启动虚拟机执行所述智能合约,若执行成功,则在所述目录资源中写入所述智能合约的代码段信息和状态信息。In one or more embodiments of the present disclosure, the directory creation module 606 is specifically configured to generate the storage table name of any smart contract according to user input; determine whether the storage table name of the smart contract already exists; if If it does not exist, then obtain the directory resource, start a virtual machine to execute the smart contract, and if the execution is successful, write the code segment information and status information of the smart contract in the directory resource.
本实施例提供的装置,可用于执行上述方法实施例的技术方案,其实现原理和技术效果类似,本实施例此处不再赘述。The device provided in this embodiment can be used to implement the technical solutions of the above method embodiments, and its implementation principle and technical effect are similar, so this embodiment will not repeat them here.
参考图8,图8为本公开实施例提供的服务设备的硬件结构示意图。如图8所示,本实施例的服务设备80包括:处理器801以及存储器802;其中Referring to FIG. 8 , FIG. 8 is a schematic diagram of a hardware structure of a service device provided by an embodiment of the present disclosure. As shown in FIG. 8, the service device 80 of this embodiment includes: a processor 801 and a memory 802;
存储器802,用于存储计算机执行指令;memory 802, for storing computer-executable instructions;
处理器801,用于执行存储器存储的计算机执行指令,以实现上述实施例中服务端的区块链所执行的各个步骤。具体可以参见前述方法实施例中的相关描述。The processor 801 is configured to execute the computer-executed instructions stored in the memory, so as to realize the various steps executed by the server-side blockchain in the above-mentioned embodiments. For details, refer to the related descriptions in the foregoing method embodiments.
可选地,存储器802既可以是独立的,也可以跟处理器801集成在一起。Optionally, the memory 802 can be independent or integrated with the processor 801 .
当存储器802独立设置时,该基于服务设备还包括总线803,用于连接所述存储器802和处理器801。When the memory 802 is set independently, the service-based device further includes a bus 803 for connecting the memory 802 and the processor 801 .
本公开实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如上所述的基于区块链的智能合约调用方法。An embodiment of the present disclosure also provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the aforementioned blockchain-based intelligence Contract call method.
本公开实施例还提供一种计算机程序产品,所述计算机程序被处理器执行时,实现如上所述的基于区块链的智能合约调用方法。An embodiment of the present disclosure also provides a computer program product, when the computer program is executed by a processor, it implements the blockchain-based smart contract calling method as described above.
在本公开所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。例如,以上所描述的设备实施例仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个模块可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或模块的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods may be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division. In actual implementation, there may be other division methods, for example, multiple modules can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or modules may be in electrical, mechanical or other forms.
所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案。The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to implement the solution of this embodiment.
另外,在本公开各个实施例中的各功能模块可以集成在一个处理单元中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个单元中。上述模块成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional module in each embodiment of the present disclosure may be integrated into one processing unit, each module may exist separately physically, or two or more modules may be integrated into one unit. The units formed by the above modules can be implemented in the form of hardware, or in the form of hardware plus software functional units.
上述以软件功能模块的形式实现的集成的模块,可以存储在一个计算机可读取存储介质中。上述软件功能模块存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器执行本公开各个实施例所述方法的部分步骤。The above-mentioned integrated modules implemented in the form of software function modules can be stored in a computer-readable storage medium. The above-mentioned software function modules are stored in a storage medium, and include several instructions for enabling a computer device (which may be a personal computer, server, or network device, etc.) or a processor to execute some steps of the methods described in various embodiments of the present disclosure.
应理解,上述处理器可以是中央处理单元(Central Processing Unit,简称CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,简称DSP)、专用集成电路(Application Specific Integrated Circuit,简称ASIC)等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合发明所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。It should be understood that the above-mentioned processor may be a central processing unit (Central Processing Unit, referred to as CPU), and may also be other general-purpose processors, digital signal processors (Digital Signal Processor (DSP for short), Application Specific Integrated Circuit (ASIC for short), etc. A general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like. The steps of the method disclosed in conjunction with the invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
存储器可能包含高速RAM存储器,也可能还包括非易失性存储NVM,例如至少一个磁盘存储器,还可以为U盘、移动硬盘、只读存储器、磁盘或光盘等。The storage may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage, and may also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk, or an optical disk.
总线可以是工业标准体系结构(Industry Standard Architecture,简称ISA)总线、外部设备互连(Peripheral Component Interconnect,简称PCI)总线或扩展工业标准体系结构(Extended Industry Standard Architecture,简称EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,本公开附图中的总线并不限定仅有一根总线或一种类型的总线。The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI for short) bus or Extended Industry Standard Architecture (Extended Industry Standard Architecture, EISA for short) bus, etc. The bus can be divided into address bus, data bus, control bus and so on. For ease of representation, the buses in the drawings of the present disclosure are not limited to only one bus or one type of bus.
上述存储介质可以是由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。存储介质可以是通用或专用计算机能够存取的任何可用介质。The above-mentioned storage medium can be realized by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable In addition to programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
一种示例性的存储介质耦合至处理器,从而使处理器能够从该存储介质读取信息,且可向该存储介质写入信息。当然,存储介质也可以是处理器的组成部分。处理器和存储介质可以位于专用集成电路(Application Specific Integrated Circuits,简称ASIC)中。当然,处理器和存储介质也可以作为分立组件存在于电子设备或主控设备中。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 a component of the processor. Processors and storage media can be located in application-specific integrated circuits (Application Specific Integrated Circuits, referred to as ASIC). Of course, the processor and the storage medium can also exist in the electronic device or the main control device as discrete components.
本领域普通技术人员可以理解:实现上述各方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成。前述的程序可以存储于一计算机可读取存储介质中。该程序在执行时,执行包括上述各方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps for implementing the above method embodiments can be completed by program instructions and related hardware. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other various media that can store program codes.
最后应说明的是:以上各实施例仅用以说明本公开的技术方案,而非对其限制;尽管参照前述各实施例对本公开进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本公开各实施例技术方案的范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present disclosure, not to limit them; although the present disclosure has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: It is still possible to modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the various embodiments of the present disclosure. scope.

Claims (12)

  1. 一种基于区块链的智能合约调用方法,其特征在于,所述方法应用于所述区块链的任一节点,所述节点中设置有用于对交易信息进行调度分配的调度器、用于执行智能合约的执行器和用于存储智能合约的存储单元,所述方法包括:A blockchain-based smart contract calling method, characterized in that the method is applied to any node of the blockchain, and the node is provided with a scheduler for scheduling and distributing transaction information, for An executor for executing smart contracts and a storage unit for storing smart contracts, the method includes:
    接收客户端发送的交易信息,其中所述交易信息中包含所述交易信息对应的待执行的智能合约的路径信息,其中所述路径信息对应唯一的智能合约存储路径;receiving the transaction information sent by the client, wherein the transaction information includes path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path;
    将接收到的各交易信息放入调度器以使所述调度器将所述各交易信息分发至不同的执行器;Putting the received transaction information into the scheduler so that the scheduler distributes the transaction information to different executors;
    通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的;Based on the path information of the smart contract to be executed corresponding to each transaction information, each executor queries the storage unit to obtain the smart contract corresponding to each transaction information, wherein the storage unit contains each smart contract stored according to the tree file directory structure. contract, and the storage path of each smart contract is unique;
    通过各执行器对所述交易信息执行所述智能合约,得到执行结果。Each executor executes the smart contract on the transaction information to obtain an execution result.
  2. 根据权利要求1所述的方法,其特征在于,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的,具体为:存储单元中包含以存储表形式存储的目录资源和智能合约资源;其中每个目录资源下包含多个子资源,相同类型的智能合约资源属于同一个目录资源下最末端的子资源,智能合约资源中包含智能合约的代码段信息和状态信息。The method according to claim 1, wherein the storage unit includes each smart contract stored according to a tree-shaped file directory structure, and the storage path of each smart contract is unique, specifically: in the storage unit Contains directory resources and smart contract resources stored in the form of storage tables; each directory resource contains multiple sub-resources, and smart contract resources of the same type belong to the last sub-resource under the same directory resource, and smart contract resources contain smart contracts Code segment information and status information for .
  3. 根据权利要求2所述的方法,其特征在于,所述通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元中以获取各交易信息对应的智能合约,包括:The method according to claim 2, characterized in that, each executor queries the storage unit to obtain the smart contract corresponding to each transaction information based on the path information of the smart contract to be executed corresponding to each transaction information, including:
    对任一交易信息对应的待执行的智能合约的路径信息进行拆分,得到所述路径信息对应的各存储表名称;Split the path information of the smart contract to be executed corresponding to any transaction information to obtain the names of the storage tables corresponding to the path information;
    根据所述各存储表名称依次访问存储单元中对应的各存储表,以获取所述路径信息对应的智能合约资源。The corresponding storage tables in the storage unit are sequentially accessed according to the names of the storage tables, so as to obtain the smart contract resources corresponding to the path information.
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述各存储表名称依次访问存储单元中对应的各存储表,以获取所述路径信息对应的智能合约资源,包括:The method according to claim 3, wherein the sequentially accessing the corresponding storage tables in the storage unit according to the names of the storage tables to obtain the smart contract resources corresponding to the path information includes:
    访问缓存,从所述缓存中依次读取名称为所述各存储表名称的各存储表;若能够从所述缓存中读取到各存储表,则从所述缓存中按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源;Accessing the cache, sequentially reading the storage tables whose names are the names of the storage tables from the cache; if the storage tables can be read from the cache, then from the cache according to the storage tables The name inquires each storage table in turn until the storage table corresponding to the smart contract resource is determined, so as to obtain the smart contract resource corresponding to the path information from the storage table corresponding to the smart contract resource;
    若无法从所述缓存中读取各存储表,则从区块链的存储单元中按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源。If the storage tables cannot be read from the cache, then query each storage table in turn from the storage unit of the block chain according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the corresponding storage table from the smart contract resource. Obtain the smart contract resource corresponding to the path information in the storage table of
  5. 根据权利要求4所述的方法,其特征在于,所述按照所述各存储表名称依次查询各存储表直至确定智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源,包括:The method according to claim 4, wherein the storage tables are inquired in turn according to the names of the storage tables until the storage table corresponding to the smart contract resource is determined, so as to obtain the storage table corresponding to the smart contract resource. Smart contract resources corresponding to path information, including:
    按照各存储表名称在所述路径信息中的级别,逐个依次查询各存储表名称对应的存储表以获取智能合约资源对应的存储表,以从智能合约资源对应的存储表中获取所述路径信息对应的智能合约资源。According to the level of each storage table name in the path information, query the storage table corresponding to each storage table name one by one to obtain the storage table corresponding to the smart contract resource, so as to obtain the path information from the storage table corresponding to the smart contract resource The corresponding smart contract resource.
  6. 根据权利要求1至5任一项所述的方法,其特征在于,还包括按照树形文件目录结构存储各智能合约的步骤,如下:The method according to any one of claims 1 to 5, further comprising the step of storing each smart contract according to a tree-shaped file directory structure, as follows:
    通过创建或查询,确定任一目录资源;Identify any catalog resource by creating or querying;
    在所述目录资源中写入待创建的智能合约。Write the smart contract to be created in the directory resource.
  7. 根据权利要求6所述的方法,其特征在于,所述通过创建或查询,确定任一目录资源,包括:The method according to claim 6, wherein said determining any directory resource by creating or querying comprises:
    根据用户的输入生成任一目录资源的存储表名称;Generate the storage table name of any directory resource according to the user's input;
    判断所述目录资源的存储表名称是否已存在;Judging whether the name of the storage table of the directory resource already exists;
    若不存在,则创建所述目录资源,其中所述目录资源包括目录的元信息;If it does not exist, create the directory resource, wherein the directory resource includes meta information of the directory;
    若存在,则判断所述存储表名称是否为智能合约资源的表名,若不是,则返回所述目录资源已存在的提示。If it exists, it is judged whether the storage table name is the table name of the smart contract resource, and if not, a prompt that the directory resource already exists is returned.
  8. 根据权利要求6或7所述的方法,其特征在于,所述在所述目录资源中写入待创建的智能合约,包括:The method according to claim 6 or 7, wherein the writing the smart contract to be created in the directory resource includes:
    根据用户的输入生成任一智能合约的存储表名称;Generate the storage table name of any smart contract according to the user's input;
    判断所述智能合约的存储表名称是否已存在;Judging whether the name of the storage table of the smart contract already exists;
    若不存在,则获取所述目录资源,并启动虚拟机执行所述智能合约,若执行成功,则在所述目录资源中写入所述智能合约的代码段信息和状态信息。If it does not exist, the directory resource is obtained, and the virtual machine is started to execute the smart contract. If the execution is successful, the code segment information and status information of the smart contract are written in the directory resource.
  9. 一种基于区块链的智能合约调用装置,其特征在于,所述装置应用于所述区块链的任一节点,所述节点中设置有用于对交易信息进行调度分配的调度器、用于执行智能合约的执行器和用于存储智能合约的存储单元,所述装置包括:A block chain-based smart contract calling device, characterized in that the device is applied to any node of the block chain, and the node is provided with a scheduler for scheduling and distributing transaction information, for An executor for executing smart contracts and a storage unit for storing smart contracts, the device includes:
    接收模块,用于接收客户端发送的交易信息,其中所述交易信息中包含所述交易信息对应的待执行的智能合约的路径信息,其中所述路径信息对应唯一的智能合约存储路径;The receiving module is used to receive the transaction information sent by the client, wherein the transaction information includes the path information of the smart contract to be executed corresponding to the transaction information, wherein the path information corresponds to a unique smart contract storage path;
    调度模块,用于将接收到的各交易信息放入调度器以使所述调度器将所述各交易信息分发至不同的执行器;A scheduling module, configured to put the received transaction information into a scheduler so that the scheduler distributes the transaction information to different executors;
    调度模块,用于通过各执行器基于各交易信息对应的待执行的智能合约的路径信息,查询存储单元以获取各交易信息对应的智能合约,其中所述存储单元中包含了按照树形文件目录结构存储的各智能合约、且各个智能合约的存储路径是唯一的;The dispatching module is used to query the storage unit to obtain the smart contract corresponding to each transaction information through each executor based on the path information of the smart contract to be executed corresponding to each transaction information, wherein the storage unit contains the following information according to the tree file directory Each smart contract stored in the structure, and the storage path of each smart contract is unique;
    执行模块,用于通过各执行器对所述交易信息执行所述智能合约,得到执行结果。The execution module is configured to execute the smart contract on the transaction information through each executor to obtain an execution result.
  10. 一种服务设备,其特征在于,包括:A service device, characterized in that it comprises:
    处理器和存储器;processor and memory;
    所述存储器存储计算机执行指令;the memory stores computer-executable instructions;
    所述处理器执行所述存储器存储的计算机执行指令,使得所述处理器执行如权利要求1至8任一项所述的基于区块链的智能合约调用方法。The processor executes the computer-executed instructions stored in the memory, so that the processor executes the blockchain-based smart contract calling method according to any one of claims 1 to 8.
  11. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如权利要求1至8任一项所述的基于区块链的智能合约调用方法。A computer-readable storage medium, characterized in that the computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method described in any one of claims 1 to 8 is realized. Blockchain-based smart contract calling method.
  12. 一种计算机程序产品,包括计算机程序,其特征在于,所述计算机程序被处理器执行时实现实现如权利要求1至8任一项所述的基于区块链的智能合约调用方法。A computer program product, comprising a computer program, characterized in that, when the computer program is executed by a processor, the blockchain-based smart contract calling method according to any one of claims 1 to 8 is realized.
PCT/CN2022/100650 2021-12-07 2022-06-23 Blockchain-based smart contract invocation method, apparatus and device WO2023103341A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111478999.7 2021-12-07
CN202111478999.7A CN113888173B (en) 2021-12-07 2021-12-07 Intelligent contract calling method, device and equipment based on block chain

Publications (1)

Publication Number Publication Date
WO2023103341A1 true WO2023103341A1 (en) 2023-06-15

Family

ID=79015658

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/100650 WO2023103341A1 (en) 2021-12-07 2022-06-23 Blockchain-based smart contract invocation method, apparatus and device

Country Status (2)

Country Link
CN (1) CN113888173B (en)
WO (1) WO2023103341A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113888173B (en) * 2021-12-07 2022-04-26 深圳前海微众银行股份有限公司 Intelligent contract calling method, device and equipment based on block chain
CN114827002B (en) * 2022-03-17 2023-04-07 西安电子科技大学 Multi-domain network security path calculation method, system, device, medium and terminal

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109271255A (en) * 2018-09-25 2019-01-25 深圳市元征科技股份有限公司 Resource regulating method, system and electronic equipment and storage medium
CN110135985A (en) * 2019-04-04 2019-08-16 杭州抖音科技有限公司 A kind of parallel execution method and system traded on block chain
CN112261156A (en) * 2020-12-21 2021-01-22 支付宝(杭州)信息技术有限公司 Method and system for submitting cross-fragment transaction, main chain node and source fragment node
CN113888173A (en) * 2021-12-07 2022-01-04 深圳前海微众银行股份有限公司 Intelligent contract calling method, device and equipment based on block chain

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107590189B (en) * 2017-08-10 2020-05-22 深圳先进技术研究院 Intelligent contract execution method, device, equipment and storage medium
US20200177373A1 (en) * 2018-11-14 2020-06-04 Royal Bank Of Canada System and method for storing contract data structures on permissioned distributed ledgers
CN112261163B (en) * 2020-12-21 2021-03-12 支付宝(杭州)信息技术有限公司 State storage method in block chain system, block chain system and node
CN112749152A (en) * 2021-01-19 2021-05-04 矩阵元技术(深圳)有限公司 Data migration method and device of intelligent contract and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109271255A (en) * 2018-09-25 2019-01-25 深圳市元征科技股份有限公司 Resource regulating method, system and electronic equipment and storage medium
CN110135985A (en) * 2019-04-04 2019-08-16 杭州抖音科技有限公司 A kind of parallel execution method and system traded on block chain
CN112261156A (en) * 2020-12-21 2021-01-22 支付宝(杭州)信息技术有限公司 Method and system for submitting cross-fragment transaction, main chain node and source fragment node
CN113888173A (en) * 2021-12-07 2022-01-04 深圳前海微众银行股份有限公司 Intelligent contract calling method, device and equipment based on block chain

Also Published As

Publication number Publication date
CN113888173A (en) 2022-01-04
CN113888173B (en) 2022-04-26

Similar Documents

Publication Publication Date Title
WO2020063786A1 (en) Data backup method, storage medium, and computing device
WO2020063820A1 (en) Asset transaction method, storage medium and computer device
WO2020082871A1 (en) Method, device and system for executing blockchain transactions in parallel
TWI727467B (en) Trustworthiness verification method, system, device and equipment of alliance chain
US11675774B2 (en) Remote policy validation for managing distributed system resources
CN109669709B (en) Data migration method and data migration system for block chain upgrading
WO2020211483A1 (en) Method and apparatus for storing and executing smart contract in blockchain, and electronic device
WO2023103341A1 (en) Blockchain-based smart contract invocation method, apparatus and device
WO2020220764A1 (en) Blockchain-based data compression and query method and apparatus, and electronic device
CN110189121B (en) Data processing method and device, block chain client and block chain link point
US10454786B2 (en) Multi-party updates to distributed systems
KR20120037397A (en) Catalog-based software component management
WO2022077186A1 (en) Execution method and apparatus for smart contract in blockchain, and electronic device
CN110569108B (en) Method for creating execution environment of mini-game virtual machine and related product
CN109032803B (en) Data processing method and device and client
US11775507B2 (en) Methods and apparatuses for reading and updating data structures, and electronic devices
CN111639309B (en) Data processing method and device, node equipment and storage medium
WO2021139431A1 (en) Data synchronization method and apparatus for microservice, electronic device and storage medium
WO2022134797A1 (en) Data fragmentation storage method and apparatus, a computer device, and a storage medium
WO2023160083A1 (en) Method for executing transactions, blockchain, master node, and slave node
CN109145053B (en) Data processing method and device, client and server
WO2019153880A1 (en) Method for downloading mirror file in cluster, node, and query server
US20200202355A1 (en) Storage and execution of smart contracts in blockchains
WO2022247316A1 (en) Storage object processing system, request processing method, gateway, and storage medium
CN109614271A (en) Control method, device, equipment and the storage medium of multiple company-data consistency

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22902778

Country of ref document: EP

Kind code of ref document: A1