Blockchain JVM data access method, device and storage medium

By configuring the JVM data access method on the blockchain node and using the callback function to bind the database handle and the environment handle, the difficulty of selecting a database interface for contract users and the problem of malicious attacks are solved, and correct data access and system security are achieved.

CN112363805BActive Publication Date: 2024-10-29QIANYI HESHENG (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011281320.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-16
Publication Date
2024-10-29
Estimated Expiration
2040-11-16

AI Technical Summary

Technical Problem

In the blockchain system, it is difficult for users who develop contracts to correctly select the database interface, resulting in data inconsistency and security risks. Especially when using the Java Virtual Machine (JVM) as a smart contract execution platform, malicious attacks may occur.

Method used

By configuring the JVM data access method on the blockchain node, and using the callback function to bind the database handle and the environment handle to the blockchain module, ensure that the corresponding database can be correctly accessed when executing transactions or queries, and avoid user selection errors. database interface.

Benefits of technology

It achieves correct access without the need to develop contract users to select the database interface in the contract, prevents malicious attacks, and ensures data consistency and system security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112363805B_ABST
    Figure CN112363805B_ABST
Patent Text Reader

Abstract

The present invention provides a blockchain JVM data access method, device and storage medium, the method comprising: a jvm execution thread receives a transaction execution parameter of a first transaction; wherein the transaction execution parameter includes a first database handle corresponding to a first exchange; the jvm execution thread binds and registers the corresponding relationship between the first database handle and the first jvm environment handle to a blockchain execution module through a callback function; wherein the first jvm environment handle is a handle of a first thread executing a first transaction; when the first thread executes the first transaction through a first contract, the first thread requests access to a database from the blockchain execution module according to the first jvm environment handle; the blockchain execution module finds out the first database handle according to the first jvm environment handle and each registered corresponding relationship, so that the first thread can access the database corresponding to the first database handle to execute the first transaction. The present invention realizes that there is no need to develop a user to select a database interface, and ensures that the contract cannot call a wrong interface for malicious attacks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a blockchain JVM data access method, device and storage medium. Background Art

[0002] In the blockchain system developed by the applicant and some other blockchain systems, the blockchain nodes are configured with both a state database and a local database. For example, when node A executes a block with a height of 10001, the data in the state database of node A is the data with a height of 10001, while the data in the local database of node A is still the data with a height of 10000 that has been agreed upon. At this time, the data in the state database of node A is inconsistent with the data in the local database.

[0003] When the above system introduces the Java Virtual Machine (JVM) as the execution platform of the smart contract, the common means in this field is to provide two different sets of interfaces, namely the state database interface and the local database interface, to users who develop Java contracts, so that users who develop Java contracts can selectively use different database interfaces when developing contracts.

[0004] The defects of the above scheme are:

[0005] On the one hand, many users who develop contracts are not familiar with the database mechanisms of the state database and the local database. When developing contracts, it may be difficult to tell which set of database interfaces should be called (or use both sets at the same time), which makes it difficult for some users to correctly develop Java contracts.

[0006] On the other hand, if the user who develops the contract uses the database interface to develop a malicious contract, for example, when the data in the local database should be queried, the state database interface is called to modify the data in the state database to carry out a malicious attack, it will cause security risks to the JVM contract platform. Summary of the invention

[0007] In view of the above-mentioned defects or deficiencies in the prior art, it is desired to provide a blockchain JVM data access method, device and storage medium that allows users to select the database interface to be called in the contract without developing a contract, while ensuring that the contract cannot call the wrong database interface to carry out malicious attacks.

[0008] In a first aspect, the present invention provides a blockchain JVM data access method applicable to a blockchain node, wherein the blockchain node is configured with a state database and a local database, and the method comprises:

[0009] The jvm execution thread receives the transaction execution parameters of the first transaction; wherein the transaction execution parameters include the first database handle corresponding to the first exchange;

[0010] The jvm execution thread binds and registers the correspondence between the first database handle and the first jvm environment handle in the blockchain execution module through a callback function; wherein the first jvm environment handle is the handle of the first thread executing the first transaction;

[0011] When executing the first transaction through the first contract, the first thread requests access to the database from the blockchain execution module according to the first jvm environment handle;

[0012] The blockchain execution module searches out the first database handle according to the first jvm environment handle and the registered corresponding relationships, so that the first thread can access the database corresponding to the first database handle to execute the first transaction.

[0013] In a second aspect, the present invention provides another blockchain JVM data access method applicable to a blockchain node, wherein the blockchain node is configured with a state database and a local database, and the method comprises:

[0014] The jvm query thread receives a first query request; wherein the query parameter of the first query request includes a second database handle;

[0015] The jvm query thread binds and registers the corresponding relationship between the second database handle and the second jvm environment handle in the blockchain query module through a callback function; wherein the second jvm environment handle is the handle of the second thread that executes the query according to the first query request;

[0016] When the second thread executes the query requested by the first query request through the second contract, it requests the blockchain query module to access the database according to the second jvm environment handle;

[0017] The blockchain query module searches for the second database handle according to the second jvm environment handle and the registered corresponding relationships, so that the second thread can access the database corresponding to the second database handle to execute the query.

[0018] In a third aspect, the present invention also provides a device, comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors so that the one or more processors execute the blockchain JVM data access method provided according to various embodiments of the present invention.

[0019] In a fourth aspect, the present invention also provides a storage medium storing a computer program, which enables a computer to execute the blockchain JVM data access method provided according to various embodiments of the present invention.

[0020] The blockchain JVM data access method, device and storage medium provided by many embodiments of the present invention configure a database handle in the transaction execution parameters of the transaction to be executed or the query parameters of the query request, so that the corresponding JVM thread can bind and register the database handle and the environment handle to the blockchain module through a callback function, and then when the database needs to be accessed during the execution of a transaction or a query, the database handle can be found according to the corresponding relationship between the environment handle and the bound and registered handle, and finally the corresponding database is accessed according to the database handle to complete the transaction execution or query execution, so that users who do not need to develop a contract can correctly access the database by selecting the called database interface in the contract, and at the same time, it is ensured that the contract cannot call the wrong database interface for malicious attacks. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0022] Figure 1 A flowchart of a blockchain JVM data access method provided by one embodiment of the present invention.

[0023] Figure 2 A flowchart of another blockchain JVM data access method provided by an embodiment of the present invention.

[0024] Figure 3 A schematic diagram of the structure of a device provided in one embodiment of the present invention. DETAILED DESCRIPTION

[0025] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant inventions, rather than to limit the inventions. It should also be noted that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.

[0026] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0027] Figure 1 A flowchart of a blockchain JVM data access method provided by one embodiment of the present invention.

[0028] like Figure 1 As shown, in this embodiment, the present invention provides a blockchain JVM data access method, the blockchain node is configured with a state database and a local database, and the method includes:

[0029] S11: The jvm execution thread receives the transaction execution parameters of the first transaction; wherein the transaction execution parameters include the first database handle corresponding to the first exchange;

[0030] S13: The jvm execution thread binds and registers the correspondence between the first database handle and the first jvm environment handle in the blockchain execution module through a callback function; wherein the first jvm environment handle is the handle of the first thread executing the first transaction;

[0031] S15: When executing the first transaction through the first contract, the first thread requests the blockchain execution module to access the database according to the first jvm environment handle;

[0032] S17: The blockchain execution module searches out the first database handle according to the first jvm environment handle and the registered corresponding relationships, so that the first thread can access the database corresponding to the first database handle to execute the first transaction.

[0033] Specifically, the following example takes the case where user A's client sends transaction tx1 of user A transferring 100 aaa coins to user B to the blockchain network, and blockchain node A executes transaction tx1 through JVM. Figure 1 The method shown is explained by way of example.

[0034] In step S11, the blockchain execution module of blockchain node A sends the transaction execution parameters (contractName0, para0, para1, ...) of tx1 to the jvm execution thread jvm_Exec.

[0035] Among them, para1 is the database handle chain33-jvmHandle1 used to execute tx1, and the handle corresponds to the state database required to access to execute tx1.

[0036] In step S13, the jvm execution thread jvm_Exec binds the correspondence between the above database handle chain33-jvmHandle1 and the jvm environment handle jvmEnvHandle1 of tx1 to the blockchain execution module through the callback function bind.

[0037] Specifically, in this embodiment, the thread executing tx1 is the jvm execution thread jvm_Exec, so the jvm environment handle jvmEnvHandle1 of tx1 is the handle of jvm_Exec; in other embodiments, the thread executing tx1 can also be configured as a different thread such as a new thread created by the jvm execution thread according to actual needs, and the jvm environment handle jvmEnvHandle1 of tx1 is the handle of the thread executing tx1.

[0038] In step S15, when the jvm execution thread jvm_Exec executes tx1 through the tx method of the first contract contractName0, it is necessary to query the account balance of user A and the account balance of user B in the status database, and request access to the database from the blockchain execution module according to the jvm environment handle jvmEnvHandle1 of tx1.

[0039] Specifically, in this embodiment, the Java compiler of the blockchain node is configured with a native type of blockchain interface implemented in C language. These blockchain interfaces include account type interface, state database type interface, local database type interface, blockchain random number acquisition interface, blockchain height acquisition interface, transaction sending address acquisition interface, etc. The contract contractName0 will call some of the above types of interfaces according to the specific business logic, such as the data reading interface and data writing interface in the state database type interface. When jvm_Exec executes tx1 through the tx method of the first contract contractName0, and needs to query the account balance of user A and the account balance of user B in the state database, it will obtain the jvm environment handle jvmEnvHandle1 of tx1, combine the relevant parameters in the transaction execution parameters of tx1, and request the blockchain execution module to access the database through the data reading interface in the above state database type interface.

[0040] In step S17, the blockchain execution module finds the database handle chain33-jvmHandle1 corresponding to jvmEnvHandle1 according to the jvm environment handle jvmEnvHandle1 of tx1 and the registered corresponding relationships, and provides the state database corresponding to chain33-jvmHandle1 to jvm_Exec for access.

[0041] jvm_Exec queries the account balance of user A and user B from the status database and executes tx1:

[0042] If the balance of AAA coins in user A's account is less than 100, tx1 execution fails;

[0043] If the AAA coin balance in user A's account is not less than 100, then the AAA coin balance in user A's account is -100, and the AAA coin balance in user B's account is +100, and the two balances are written into the status database.

[0044] The above example takes the executed transaction as a transfer transaction, the database handle in the transaction execution parameter corresponds to the state database, and the first thread is the jvm execution thread as an example. Figure 1The method shown is exemplarily explained; in more embodiments, the above method can be used to execute different types of transactions, the database handle in the transaction execution parameters can correspond to the state database and the local database at the same time according to the actual business logic, and the first thread can also be configured as a new thread created by the jvm execution thread and other different threads according to actual needs, all of which can achieve the same technical effect and are not limited to the above examples.

[0045] Figure 2 A flowchart of another blockchain JVM data access method provided by an embodiment of the present invention.

[0046] like Figure 2 As shown, in this embodiment, the present invention also provides another blockchain JVM data access method applicable to a blockchain node, the blockchain node is configured with a state database and a local database, and the method includes:

[0047] S21: the jvm query thread receives a first query request; wherein the query parameter of the first query request includes a second database handle;

[0048] S23: The jvm query thread binds and registers the corresponding relationship between the second database handle and the second jvm environment handle in the blockchain query module through a callback function; wherein the second jvm environment handle is the handle of the second thread that executes the query according to the first query request;

[0049] S25: When the second thread executes the query requested by the first query request through the second contract, it requests the blockchain query module to access the database according to the second jvm environment handle;

[0050] S27: The blockchain query module searches for the second database handle according to the second jvm environment handle and the registered corresponding relationships, so that the second thread can access the database corresponding to the second database handle to execute the query.

[0051] Specifically, the following blockchain node B receives query requests Q1-Q3 and processes Q1-Q3 in parallel through JVM as an example. Figure 2 The method shown is explained by way of example.

[0052] In step S21, the jvm query thread jvm_Query receives query requests Q1-Q3.

[0053] Among them, the query parameter para11 in the query parameters (contractName1, para10, para11, ...) of Q1 is the database handle chain33-jvmHandle2 used to execute the query requested by Q1, and the handle corresponds to the local database that needs to be accessed to execute the query requested by Q1. Similarly, the query parameter para21 in the query parameters (contractName2, para20, para21, ...) of Q2 is the database handle chain33-jvmHandle3 used to execute the query requested by Q2; the query parameter para31 in the query parameters (contractName3, para30, para31, ...) of Q3 is the database handle chain33-jvmHandle4 used to execute the query requested by Q3.

[0054] In step S21, jvm_Query determines in turn whether the current JVM has loaded and cached each contract:

[0055] jvm_Query calls the contract loading method loadContract of the secondary loading package to determine whether the current JVM has loaded and cached the contract contractName1 according to the contract name contractName1 in the query parameter of Q1. If not, the contract contractName1 is loaded and cached through the loadContract method, and the bytecode of the contract contractName1 is cached, and then thread a is created to execute the query requested by Q1.

[0056] jvm_Query calls the loadContract method to determine whether the current JVM has loaded and cached the contract contractName2 according to the contract name contractName2 in the query parameter of Q2. If yes, it creates thread b to execute the query requested by Q1.

[0057] Similarly, jvm_Query calls the loadContract method to determine whether the current JVM has loaded and cached the contract contractName3 based on the contract name contractName3 in the query parameter of Q3: if yes, a thread c is created to execute the query requested by Q3.

[0058] In step S23, jvm_Query binds the correspondence between the above database handle chain33-jvmHandle2 and Q1's jvm environment handle jvmEnvHandle2 to the blockchain query module through the callback function bind.

[0059] Among them, jvmEnvHandle2 is the handle of thread a.

[0060] Similarly, jvm_Query also binds the correspondence between chain33-jvmHandle3 and Q2's jvm environment handle jvmEnvHandle3 (thread b's handle), and the correspondence between chain33-jvmHandle4 and Q3's jvm environment handle jvmEnvHandle4 (thread c's handle) to the blockchain query module through the callback function bind.

[0061] Threads ac execute the queries requested by Q1-Q3 in parallel. Take thread a executing the query requested by Q1 as an example:

[0062] In step S25, when thread a executes the query requested by Q1 through the query method of the second contract contractName1, it requests access to the database from the blockchain query module according to the jvm environment handle jvmEnvHandle2;

[0063] In step S27, the blockchain query module finds the database handle chain33-jvmHandle2 corresponding to jvmEnvHandle2 according to jvmEnvHandle2 and the registered corresponding relationships, and provides the local database corresponding to chain33-jvmHandle2 to thread a for access.

[0064] Thread a executes the query requested by Q1 by accessing the local database, generates the query results and returns them.

[0065] The process of thread b executing the query requested by Q2 and thread c executing the query requested by Q3 is similar to the process of thread a executing the query requested by Q1, and will not be described in detail.

[0066] The above example takes the database handle in the query parameter as an example corresponding to the local database. Figure 2 The method shown is an exemplary description; in more embodiments, the database handle in the query parameter may correspond to both the state database and the local database according to the actual business logic, and the same technical effect may be achieved without being limited to the above examples.

[0067] The above embodiments configure the database handle in the transaction execution parameters of the transaction to be executed or the query parameters of the query request, so that the corresponding JVM thread can bind and register the database handle and the environment handle to the blockchain module through the callback function, and then when the database needs to be accessed during the execution of the transaction or the query, the database handle can be found according to the corresponding relationship between the environment handle and the bound registration, and finally the corresponding database is accessed according to the database handle to complete the transaction execution or query execution, so that users who do not need to develop contracts can correctly access the database by selecting the called database interface in the contract, and at the same time, it also ensures that the contract cannot call the wrong database interface to carry out malicious attacks.

[0068] Figure 3 A schematic diagram of the structure of a device provided in one embodiment of the present invention.

[0069] like Figure 3 As shown, as another aspect, the present application also provides a device 300, including one or more central processing units (CPU) 301, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 302 or the program loaded from the storage part 308 to the random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the device 300 are also stored. The CPU 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0070] The following components are connected to the I / O interface 305: an input section 306 including a keyboard, a mouse, etc.; an output section 307 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 308 including a hard disk, etc.; and a communication section 309 including a network interface card such as a LAN card, a modem, etc. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as needed. A removable medium 311, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 310 as needed, so that a computer program read therefrom is installed into the storage section 308 as needed.

[0071] In particular, according to an embodiment of the present disclosure, the method described in any of the above embodiments can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program tangibly contained on a machine-readable medium, and the computer program includes a program code for executing any of the above methods. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 309, and / or installed from a removable medium 311.

[0072] As another aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the apparatus of the above embodiment; or a computer-readable storage medium that exists independently and is not assembled into the device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the method described in the present application.

[0073] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs a specified function or operation, or can be realized by a combination of dedicated hardware and computer instructions.

[0074] The units or modules involved in the embodiments described in the present application may be implemented by software or by hardware. The units or modules described may also be provided in a processor. For example, each unit may be a software program provided in a computer or a mobile smart device, or may be a separately configured hardware device. The names of these units or modules do not, in some cases, constitute limitations on the units or modules themselves.

[0075] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the concept of the present application. For example, the above features are replaced with the technical features with similar functions disclosed in the present application (but not limited to) to form a technical solution.

Claims

1. A blockchain JVM data access method, It is characterized in that The blockchain node is configured with a state database and a local database. The method is applicable to the blockchain node, and the method includes: The jvm execution thread receives a transaction execution parameter of the first transaction; wherein the transaction execution parameter includes a first database handle corresponding to the first exchange; The jvm execution thread binds and registers the correspondence between the first database handle and the first jvm environment handle in the blockchain execution module through a callback function; wherein the first jvm environment handle is the handle of the first thread that executes the first transaction; when the first thread executes the first transaction through the first contract, the first thread requests access to the database from the blockchain execution module according to the first jvm environment handle; The blockchain execution module searches out the first database handle according to the first jvm environment handle and the registered corresponding relationships, so that the first thread can access the database corresponding to the first database handle to execute the first transaction; The first thread is the jvm execution thread.

2. A blockchain JVM data access method, It is characterized in that The blockchain node is configured with a state database and a local database. The method is applicable to the blockchain node, and the method includes: The jvm query thread receives a first query request; wherein the query parameter of the first query request includes a second database handle; The jvm query thread binds and registers the corresponding relationship between the second database handle and the second jvm environment handle in the blockchain query module through a callback function; wherein the second jvm environment handle is the handle of the second thread that executes the query according to the first query request; When the second thread executes the query requested by the first query request through the second contract, it requests the blockchain query module to access the database according to the second jvm environment handle; The blockchain query module searches out the second database handle according to the second jvm environment handle and the registered corresponding relationships, so that the second thread can access the database corresponding to the second database handle to execute the query; The second thread is a thread created by the jvm query thread after loading the second contract and caching the bytecode of the second contract when the jvm query thread determines that the second contract has not been cached; The second thread is a thread created by the jvm query thread when it is determined that the second contract has been cached.

3. A device, It is characterized in that The device comprises: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are caused to perform the method according to any one of claims 1 to 2.

4. A storage medium storing a computer program, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 2 is implemented.

Citation Information

Patent Citations

  • Database handle processing method and device and computer equipment

    CN107220275A

  • Data processing system, method and device

    CN109919691A