WO2022205956A1 - Method and apparatus for communication between blockchain and off-chain device - Google Patents

Method and apparatus for communication between blockchain and off-chain device Download PDF

Info

Publication number
WO2022205956A1
WO2022205956A1 PCT/CN2021/133008 CN2021133008W WO2022205956A1 WO 2022205956 A1 WO2022205956 A1 WO 2022205956A1 CN 2021133008 W CN2021133008 W CN 2021133008W WO 2022205956 A1 WO2022205956 A1 WO 2022205956A1
Authority
WO
WIPO (PCT)
Prior art keywords
session
transaction
blockchain
chain device
message
Prior art date
Application number
PCT/CN2021/133008
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 WO2022205956A1 publication Critical patent/WO2022205956A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • 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/04Payment circuits
    • G06Q20/06Private payment circuits, e.g. involving electronic currency used among participants of a common payment scheme
    • G06Q20/065Private payment circuits, e.g. involving electronic currency used among participants of a common payment scheme using e-cash
    • 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
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management

Definitions

  • the embodiments of this specification relate to the field of blockchain technology, and more particularly, to a method and apparatus for communication between a blockchain and an off-chain device.
  • Blockchain technology also known as distributed ledger technology, is a decentralized distributed database technology characterized by decentralization, openness, transparency, immutability, and trustworthiness. Each transaction of the blockchain will be broadcast to the blockchain nodes of the entire network, and each full node has full and consistent data. Since the blockchain is a closed environment, the blockchain cannot actively initiate network calls, and the smart contracts on the chain can only passively receive data. Therefore, the blockchain cannot actively obtain data or resources outside the chain.
  • off-chain trusted devices can log in to the blockchain client and exchange information between the blockchain smart contracts, thereby providing off-chain data or resources to the blockchain, such as It can provide off-chain information, off-chain data processing capabilities, etc. to the blockchain.
  • off-chain trusted devices can log in to the blockchain client and exchange information between the blockchain smart contracts, thereby providing off-chain data or resources to the blockchain, such as It can provide off-chain information, off-chain data processing capabilities, etc. to the blockchain.
  • only one-way communication is realized in which the blockchain receives information from off-chain devices through contracts
  • the embodiments of this specification aim to provide a more effective communication solution between the blockchain and off-chain devices, so as to solve the deficiencies in the prior art.
  • one aspect of this specification provides a communication method between a blockchain and an off-chain device, the method being executed by a blockchain node, including: executing a first transaction to provide the off-chain device with A pre-opening message for a first session, wherein the first session is a session between the blockchain and the off-chain device; execute a second transaction sent by the off-chain device to send the off-chain device to the off-chain device An opening message of the first session is provided, and confirmation information for the pre-opening message is included in the second transaction.
  • executing the first transaction further includes executing the first transaction to store a pre-opening message of the first session in the blockchain.
  • executing the first transaction further includes executing the first transaction to record the state of the first session as a pre-opened state in the blockchain.
  • the first contract is invoked in the first transaction, wherein recording the state of the first session as a pre-opened state in the blockchain includes, in the account of the first contract In the state, the state of the first session is recorded as a pre-opened state.
  • the first contract is invoked in the second transaction
  • the executing the second transaction sent by the off-chain device includes executing the first contract invoked in the second transaction , so that it is determined whether the second transaction is executed within the first predetermined period, and in the case where it is determined that the second transaction is executed within the first predetermined period, an opening message of the first session is provided to the off-chain device.
  • executing the first contract invoked in the second transaction further results in ending the first session if the second transaction is determined to be executed after a first predetermined period of time.
  • providing the off-chain device with an open message of the first session includes modifying the state of the first session to an open state.
  • providing the off-chain device with the opening message of the first session includes storing the opening message of the first session in the blockchain.
  • the method further includes, after providing the off-chain device with the opening message of the first session, executing a third transaction invoking the first contract, the third transaction including the pending first session A piece of data, so as to determine whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, it is stored in the blockchain in association with the first session the first data.
  • the method further includes: executing a fourth transaction sent by the off-chain device, the fourth transaction including pre-closing information, so that it is determined whether the off-chain device has received All messages sent; in a case where it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
  • providing the off-chain device with a close message of the first session includes modifying the state of the first session to a closed state.
  • executing the fourth transaction further causes, in the event that it is determined that the message sent at least in part by the off-chain device has not been received, storing in the blockchain in association with the first session incoming request information, where the request information is used to request the off-chain device to resend the at least part of the message.
  • executing the fourth transaction further results in modifying the state of the first session to a pre-closed state in the event that it is determined that a message sent at least in part by the off-chain device has not been received.
  • Another aspect of this specification provides a method for communication between a blockchain and an off-chain device, the method being performed by the off-chain device, comprising: acquiring a pre-opening message of a first session from the blockchain, the first session A session is a session between the blockchain and the off-chain device; send a second transaction to the blockchain, the second transaction includes confirmation information for the pre-opening message; open the first The data retention period for the session.
  • sending the second transaction to the blockchain includes sending the second transaction to the blockchain within a first predetermined period of time.
  • the method further includes, after the data retention period is opened, determining whether to obtain the open message of the first session from the blockchain within a second predetermined period, when the second predetermined period In the case where the opening message of the first session is not obtained from the blockchain within the period, the data retention period is ended.
  • the method further includes, when a preset condition is met, sending a fourth transaction to the blockchain, where the fourth transaction includes pre-closing information of the first session.
  • the method further includes, after sending the fourth transaction to the blockchain, obtaining a close message for the first session from the blockchain; and ending the data retention period.
  • the method further comprises, after sending the fourth transaction to the blockchain, obtaining a request message from the blockchain for at least a portion of the messages in the first session that have been sent ; sending a fifth transaction to the blockchain, the fifth transaction including the at least part of the message.
  • Another aspect of the present specification provides a communication device between a blockchain and an off-chain device, the device is deployed on a blockchain node, and includes: a first execution unit configured to execute a first transaction to send a transaction to the blockchain.
  • the off-chain device provides a pre-opening message of a first session, where the first session is a session between the blockchain and the off-chain device; the second execution unit is configured to execute a session sent by the off-chain device to provide the off-chain device with an opening message of the first session, and the second transaction includes confirmation information for the pre-opening message.
  • the first execution unit is further configured to execute a first transaction to store a pre-opening message of the first session in the blockchain.
  • the first execution unit is further configured to execute a first transaction to record the state of the first session as a pre-opened state in the blockchain.
  • the first contract is invoked in the first transaction, wherein the first execution unit is further configured to record the state of the first session in the account state of the first contract as pre-opened state.
  • the first contract is invoked in the second transaction
  • the second execution unit is further configured to execute the first contract invoked in the second transaction, so as to determine whether the first contract is invoked in the second transaction.
  • the second transaction is executed within a predetermined period of time, and in the event that the second transaction is determined to be executed within the first predetermined period of time, an opening message of the first session is provided to the off-chain device.
  • the first execution unit is further configured to end the first session if it is determined that the second transaction is executed after a first predetermined period of time.
  • the second execution unit is further configured to modify the state of the first session to an open state.
  • the second execution unit is further configured to store an opening message of the first session in the blockchain.
  • the apparatus further includes a third execution unit configured to, after providing the off-chain device with an opening message of the first session, execute a third transaction that invokes the first contract, the first The first data to be processed is included in the third transaction, so that it is determined whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, the blockchain is connected with all and storing the first data in association with the first session.
  • a third execution unit configured to, after providing the off-chain device with an opening message of the first session, execute a third transaction that invokes the first contract, the first The first data to be processed is included in the third transaction, so that it is determined whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, the blockchain is connected with all and storing the first data in association with the first session.
  • the apparatus further includes: a fourth execution unit configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information, so as to determine whether to All messages sent by the off-chain device are received; in a case where it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
  • a fourth execution unit configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information, so as to determine whether to All messages sent by the off-chain device are received; in a case where it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
  • the fourth execution unit is further configured to modify the state of the first session to a closed state.
  • the fourth execution unit is further configured to, in the event of determining that a message sent at least in part by the off-chain device has not been received, in the blockchain associated with the first session storing request information, where the request information is used to request the off-chain device to resend the at least part of the message.
  • the fourth execution unit is further configured to, in a case where it is determined that a message sent at least in part by the off-chain device has not been received, modify the state of the first session to a pre-closed state .
  • Another aspect of this specification provides a communication device between a blockchain and an off-chain device, the device is deployed on the off-chain device, and includes: a first obtaining unit configured to obtain a first session from the blockchain The first session is a session between the blockchain and the off-chain device; the first sending unit is configured to send a second transaction to the blockchain, in which the second transaction Including confirmation information for the pre-opening message; an opening unit, configured to open a data retention period of the first session.
  • the first sending unit is further configured to send a second transaction to the blockchain within a first predetermined period of time.
  • the apparatus further includes a determining unit configured to, after the data retention period is enabled, determine whether to acquire the opening message of the first session from the blockchain within a second predetermined period, A first ending unit, configured to end the data retention period when the opening message of the first session is not obtained from the blockchain within a second predetermined period of time.
  • the apparatus further includes a second sending unit configured to, when a preset condition is met, send a fourth transaction to the blockchain, where the fourth transaction includes the first session pre-close information.
  • the apparatus further includes a second obtaining unit configured to obtain a closing message of the first session from the blockchain after the fourth transaction is sent to the blockchain; A second end unit configured to end the data retention period.
  • the apparatus further includes a third obtaining unit, configured to, after sending the fourth transaction to the blockchain, obtain from the blockchain a request for the first session that has been sent A request message for at least part of the message in the third sending unit, configured to send a fifth transaction to the blockchain, where the fifth transaction includes the at least part of the message.
  • Another aspect of the present specification provides a computer-readable storage medium on which a computer program is stored, when the computer program is executed in a computer, the computer is made to execute any one of the above methods.
  • Another aspect of the present specification provides a computing device, including a memory and a processor, where a computer program is stored in the memory, and the processor implements any one of the above methods when executing the computer program.
  • the session can be opened after both the blockchain and the off-chain device confirm the channel, and the off-chain device guarantees the session during the session opening.
  • the data retention period ensures secure two-way communication between the blockchain and off-chain devices.
  • by using a smart contract in the blockchain to conduct a session with an off-chain device, and recording the session status in the account status of the smart contract it is convenient for each node to query the session status, and Communication with off-chain devices can be done based on session state.
  • FIG. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification
  • FIG. 2 shows a flowchart of a communication method between the blockchain 11 and the off-chain device 12 according to an embodiment of the present specification
  • FIG. 3 shows a communication apparatus 300 between a blockchain and an off-chain device according to an embodiment of the present specification
  • FIG. 4 is a communication apparatus 400 used between a blockchain and an off-chain device according to an embodiment of the present specification.
  • FIG. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification.
  • the system includes a blockchain 11 and off-chain devices 12 .
  • the contract C1 and the communication contract C2 are deployed in the blockchain 11 .
  • the communication contract C2 is used for two-way communication with the off-chain device, and the contract C1 realizes data interaction with the off-chain device by calling the communication contract C2.
  • the off-chain device 12 is a trusted device, and the trusted device can realize its trustworthiness through hardware, software, etc.
  • the off-chain device 12 can include a trusted execution environment (TEE), and the TEE has its own hardware
  • TEE trusted execution environment
  • the private key and public key, or the off-chain device 12 realizes its credibility through algorithms such as secure multi-party computation and zero-knowledge implementation, or the off-chain device 12 may be a device of a trusted authority, and so on.
  • the communication contract C2 can have a session with at least one off-chain device.
  • the communication contract C2 includes, for example, a request to open a session function, a session open function, a data transmission function, a result return function, and a session close function, and the account database of the blockchain 11 records the communication between the communication contract C2 and each off-chain device.
  • the session state for example, the session state includes: a pre-open state, an open state, a pre-close state, and a closed state.
  • node 1 in blockchain 11 wishes to call contract C1 for data processing. Since contract C1 calls communication contract C2, node 1 can first query the status of communication contract C2 in the account database of the blockchain to determine the status of communication contract C2. Whether the communication contract C2 has established a session with the off-chain device 12. If the session status between the communication contract C2 and the off-chain device 12 is found to be closed, node 1 can send transaction 1, and in transaction 1, call the request open session function in the communication contract C2 to send the pre-open session to the off-chain device 12. information.
  • the "pre-opening message” sent by the communication contract C2 to the off-chain device 12 is stored in the blockchain, and the communication contract C2 and the off-chain device's session 1 are stored in the blockchain.
  • the state is recorded as "pre-open state”.
  • the off-chain device 12 can read the above-mentioned "pre-opening message” by reading the data in the blockchain 11, and send transaction 2 to the blockchain 11, and the transaction 2 calls the session opening function in the communication contract C2.
  • the off-chain device 12 enables the data retention period while sending transaction 2, thereby ensuring the security of the data in the session.
  • the node in the blockchain 11 modifies the state of the session 1 to "open state".
  • node 1 After node 1 determines that the state of session 1 has changed to "open state", it can send transaction 3 that calls contract C1.
  • contract C1 uses data D1 as a parameter to call the data sending function in communication contract C2.
  • the node in the blockchain 11 executes the transaction 3, it executes the communication contract C2 called therein, thereby storing the data D1 in the blockchain for sending to the off-chain device 12.
  • data D1 is sent to off-chain device 12 in blockchain 11 in the form of receipt R1 and Spv proof including data D1.
  • the blockchain 11 can be any blockchain, such as Bitcoin chain, Ethereum chain, Hyperledger Fabric blockchain (hereinafter referred to as Fabric chain) and so on. Different blockchains have different on-chain data proof methods.
  • the Fabric chain uses the endorsement node signature method
  • the Ethereum chain uses the Spv proof method.
  • the blockchain 11 is used as an example to illustrate the Ethereum chain.
  • the off-chain device 12 can then read the receipt R1 and its Spv proof from the blockchain 11 .
  • the off-chain device 12 includes an Spv client. After obtaining the receipt R1 and the Spv certificate, the off-chain device 12 uses the Spv client to verify the receipt R1 through the Spv verification method, and obtains the data from the receipt R1 after the verification. Data D1 sent by contract C2, and data D1 is processed.
  • the off-chain device 12 is, for example, a TEE device, and after processing the data D1, for example, the acquired processing result is the processing result E1.
  • the off-chain device 12 signs the processing result E1 using its hardware private key, and sends a transaction 4 that calls the communication contract C2 to the blockchain, where the call returns the result of calling the communication contract C2 with the processing result E1 and its signature as parameters function to provide the processing result E1 and its signature to the communication contract C2. Therefore, when the transaction 4 is executed in the blockchain, the communication contract C2 uses the preset public key of the off-chain device 12 to verify the signature of the processing result E1, and after the verification is passed, the contract C1 is called back to send the The processing result E1 is provided to the contract C1.
  • the off-chain device 12 When the off-chain device 12 is about to end the session with the communication contract C2, it sends a transaction 5 to the blockchain 11, and in the transaction 5 calls the communication contract C2's request to close the session function. When the node in the blockchain 11 is executing transaction 5, it determines whether the reception of the data from the off-chain device 12 is completed. Change the state of session 1 to closed, thus ending the execution of transaction 5. The off-chain device 12 ends the above data retention period after reading the "session close message" from the blockchain 11, that is, deletes the data in the above session.
  • the blockchain 11 is not limited to calling the communication contract through the contract C1.
  • the communication contract C2 can also be called directly with the data D1 as the incoming parameter in the transaction, so that the data D1 can be processed by the off-chain device 12.
  • the communication process between the above-mentioned blockchain and off-chain devices will be described in detail below.
  • FIG. 2 shows a flowchart of a communication method between the blockchain 11 and the off-chain device 12 according to an embodiment of the present specification.
  • the blockchain 11 and the off-chain device 12 communicate interactively, thereby realizing the session between the blockchain 11 and the off-chain device 12 .
  • the node in the blockchain 11 can send the desired data in the form of provable data (eg transaction receipt, account data, etc.) by sending a transaction Stored in the blockchain so that the off-chain device 12 can receive this data by reading the receipt in the blockchain.
  • the off-chain device 12 may send a transaction to the blockchain through the blockchain client therein, thereby providing data to the blockchain through the transaction.
  • the blockchain 11 can communicate with the off-chain device 12 by executing a transaction that invokes the communication contract C2, which will be described below as an example. It can be understood that the communication method provided by the embodiments of this specification is not limited to executing a transaction that invokes the communication contract C2, but can also be executed by executing a transaction including a data field, as long as a message that can be explicitly sent through the data field of the transaction, and Either the recipient or the sender of the message is sufficient.
  • step S202 the blockchain 11 sends a pre-opening message to the off-chain device 12.
  • the account status of the communication contract C2 records the session status between the communication contract C2 and the off-chain device. For example, initially, the account status of the communication contract C2 records that the status of session 1 with the off-chain device 12 is closed, or the account status of the communication contract C2 does not record any session with the off-chain device 12, that is, The session state between the communication contract C2 and the off-chain device is closed.
  • the node 1 in the blockchain 11 wishes to perform data processing by invoking the communication contract C2, it can first query the account status of the communication contract C2, so as to know that the communication contract C2 has not established a session with the off-chain device 12. Therefore, node 1 may send transaction 1, in which the request to open session function in communication contract C2 is called with the off-chain device 12 identifier as an incoming parameter in transaction 1 to send a pre-open message to off-chain device 12.
  • Each node in the blockchain executes transaction 1 after consensus on transaction 1 to obtain a consistent state.
  • the receipt R1 includes the account of the communication contract C2, the identifier of the off-chain device 12, and the pre-opening message.
  • the pre-opening message is, for example, "OpenSyncMsg".
  • the receipt R1 may further include an identifier of session 1 (eg "session 1").
  • the nodes in the blockchain also record the session status between the communication contract C2 and the off-chain device 12 in the account status of the communication contract C2. For example, session 1 is used as the identifier of the session, and the status of session 1 is recorded as "pre- On state".
  • Table 1 schematically shows a table of session states recorded in the account state of the communication contract C2 in the blockchain node.
  • multiple sessions may be recorded in the account state of the communication contract C2, such as session 1, session 2, and different sessions are sessions with different off-chain devices, and may have different session states .
  • session 1 is a session between communication contract C2 and off-chain device 12, and the state of session 1 is a pre-opened state.
  • the off-chain device 12 can monitor the receipt including the account address of the communication contract C2 and the identification of the off-chain device 12 through its Spv client, or the off-chain device 12 can monitor the receipt including "session 1", whenever the area is determined.
  • the receipt can be read from the blockchain 11, and the Spv certification data of the receipt can be read accordingly.
  • the blockchain 11 can actively push information, and each time it is determined that the blockchain 11 stores the receipt generated by the execution of the communication contract C2 and sent to the off-chain device 12, the receipt and the corresponding Spv proof data are stored in the blockchain 11. Actively push to off-chain device 12. Therefore, after the above-mentioned receipt R1 is stored in the blockchain 11, the off-chain device 12 can read the receipt R1 and its Spv proof from the blockchain 11, that is, receive the pre-opening message of the session 1 in the receipt R1.
  • the embodiment of the present specification is not limited thereto.
  • blockchain 11 may provide a pre-open message to off-chain device 12 through the state of session 1 in the account state of communication contract C2.
  • the off-chain device 12 can obtain the message by reading the state of the session 1 in the blockchain 11 .
  • the node 1 in the blockchain 11 can query whether the transaction sent by the off-chain device 12 for confirming the above-mentioned pre-opening message is included in the predetermined number of blocks after the transaction 1 is formed into a block, if not included, the node 1 can be as follows: As shown by the dotted line in Figure 2, a transaction that calls the session closing function in the communication contract C2 is sent. After the transaction is executed, the information of the session 1 recorded in the account state of the communication contract C2 is deleted, or the state of the session 1 is modified to Disabled. Optionally, after the transaction is executed, a session close message is stored in the blockchain 11 so that the off-chain device 12 can obtain the information.
  • step S204 the off-chain device 12 sends pre-opening confirmation information to the blockchain 11.
  • the off-chain device 12 After reading the receipt R1 and its Spv proof, the off-chain device 12 verifies the receipt R1 by using the Spv proof through the Spv client. After the verification is passed, the "OpenSyncMsg" message can be read from the receipt R1.
  • the off-chain device 12 can send transaction 2 to the blockchain 11 through the client within a predetermined period after the receipt R1 is read. In the transaction 2, for example, the session opening function in the communication contract C2 is called to send the pre-received transaction to the blockchain 11. Turn on the confirmation message.
  • the off-chain device 12 After sending transaction 2, the off-chain device 12 opens a session with the communication contract C2 in the blockchain 11, and accordingly opens a data retention period corresponding to the session, during which the off-chain device 12 has a pair of Any communication data with the communication contract C2 in this period is retained to ensure data security.
  • Table 2 schematically shows a table of data retention periods for individual sessions recorded in the off-chain device 12 .
  • session ID contract address Data retention period session 1 Communication contract C2 address turn on session 2 Contract C3 address closure ...
  • communication device 12 may establish sessions with multiple contracts, such as session 1 and session 2, and so on.
  • the communication data in each session can be associated with "session 1", so that when the data retention period of the session 1 is on according to Table 2, the communication in the session 1 is reserved in the communication device 12 data, when it is determined that the data retention period of session 2 is closed according to Table 2, the communication data in session 2 can be deleted, and the record of session 2 can be deleted in Table 2.
  • step S206 the blockchain 11 sends an opening message to the off-chain device 12.
  • a node in blockchain 11 executes transaction 2 after consensus on transaction 2, it is first determined whether the state of session 1 is a pre-open state. If the state of session 1 is the pre-open state, change the state of session 1 to the open state, and store the receipt R2 corresponding to transaction 2 in the blockchain 11.
  • the receipt R2 includes the account and chain of the communication contract C2.
  • the off-chain device 12 determines whether the above-mentioned opening message sent by the blockchain 11 is read within a predetermined period of time, and if the above-mentioned opening message is read within the predetermined period of time, it can be confirmed that the blockchain 11 has received To the transaction 2 sent by it, then continue to retain the above-mentioned data retention period (as shown in the data retention period T1 in Figure 2), if the above-mentioned opening message is not read within a predetermined period of time, then end the above-mentioned data retention period (as shown in Figure 2). 2 in the data retention period T2).
  • the predetermined period of time may be predetermined based on transaction block times in the blockchain 11 .
  • the off-chain device 12 can determine whether the transaction 2 is read by the blockchain within a predetermined period of time after the transaction 2 is sent. 11 The pending data sent to it, if the pending data sent to it is read within a predetermined period, continue to retain the data retention period, and if the pending data is not read within the predetermined period, end the data retention period.
  • step S208 the blockchain 11 sends the data D1 to be processed to the off-chain device 12.
  • node 1 After node 1 executes transaction 2 so that the state of session 1 becomes the open state, node 1 can start data processing through off-chain device 12 .
  • Node 1 sends transaction 3, in which transaction 3 calls the data sending function in communication contract C2 with data D1 and the identifier of off-chain device 12 as parameters.
  • Nodes in the blockchain execute transaction 3 after consensus on transaction 3, and deposit receipt 3 of transaction 3 after executing transaction 3.
  • the receipt 3 includes the identification of the communication contract C2, the identification of the off-chain device 12 and the data D1. Similar to the above reading receipt R1, the off-chain device 12 can read the receipt 3 and its Spv proof from the blockchain 11 through the client, verify the receipt 3, and obtain the data D1 and the communication contract C2 from the receipt 3. logo.
  • step S210 the off-chain device 12 sends the processing result of the data D1 to the blockchain 11.
  • the off-chain device 12 is, for example, a TEE device, in which a data processing program is preset and has its hardware private key and public key. After obtaining the identifiers of the data D1 and the communication contract C2, the off-chain device 12 uses the preset data processing program to process the data D1, thereby obtaining the processing result (processing result E1) of the data D1, and uses its hardware private key to process the data D1. The result E1 is digitally signed. After that, the off-chain device 12 sends transaction 4 to the blockchain 11, in which the result-returning function in the communication contract C2 is called with the processing result E1 and the TEE signature as incoming parameters. The hardware public key of the off-chain device 12 is preset in the result return function.
  • the node 1 in the blockchain 11 executes the transaction 4, it uses the hardware public key to verify the TEE signature, and the data D1 can be obtained after the verification is passed.
  • the contract C1 is called in the transaction 3 and the communication contract C2 is called in the contract C1 as shown in Fig. 1, the result return function in the communication contract C2 is called in the transaction 4, and the result E1 is processed in the function.
  • nodes such as node 2 in the blockchain 11 want to call the communication contract C2, similar to the node 1, they first query the session status between the communication contract C2 and the off-chain device 12 in the account status of the communication contract C2, When the status of the session 1 between the communication contract C2 and the off-chain device 12 is queried, the node 2 can send data to the off-chain device 12 similar to the node 1 (for example, the data D2 shown in FIG. 2 ). ) and receive the processing result E2 of the data D2.
  • step S212 the off-chain device 12 sends pre-shutdown information to the blockchain 11.
  • the off-chain device 12 sends a pre-close message for session 1 to the blockchain when predetermined conditions are met.
  • the predetermined condition is, for example, any one of the following: the off-chain device 12 has not received the data to be processed for a continuous predetermined length of time, and the blockchain 11 stores the request chain in the blockchain 11 by executing the communication contract C2.
  • the off-chain device 12 sends transaction 5 to the blockchain 11 through the client, and in the transaction 5 calls the close session function of the communication contract C2 to send a pre-close message to the blockchain 11 .
  • step S214 the blockchain 11 sends a shutdown message to the off-chain device 12.
  • the node in the blockchain 11 executes the transaction 5, it determines whether it has received all the messages or data sent by the off-chain device 12;
  • the state of session 1 in the account state in contract C2 is deleted (ie, session 1 is closed), or the state of session 1 is modified to the closed state, the execution of transaction 5 is ended, and receipt 5 is stored in blockchain 11.
  • the receipt 5 includes the account of the communication contract C2, the identification of the off-chain device 12 and the session close message (eg "CloseMsg").
  • the communication contract C2 can number the data sent each time.
  • the sent data are numbered as data D1 and data D2, and the off-chain device 12 also sends back corresponding numbers.
  • the data results of the blockchain are numbered, for example, the processing result of the data D1 is numbered as the processing result E1, and the processing result of the data D2 is numbered as the processing result E2.
  • the blockchain 11 can determine which data the processing result corresponds to based on the number of the received processing result.
  • the off-chain device 12 sends the pre-close message
  • the number of the last processing result (for example, "10") sent by it in transaction 5 can be used as a parameter to call the request to close the session function in the communication contract C2.
  • the transaction 5 When the transaction 5 is executed in 11, it is determined whether the processing result E1-processing result E10 has been received, thereby determining whether all the messages or data sent by the off-chain device 12 have been received.
  • the off-chain device 12 After the off-chain device 12 sends the pre-close message through transaction 5, it is possible that the pending data D11, data D12, etc. have been sent to the off-chain device 12 on the blockchain 11 side, and the transaction is executed At 5:00, these data numbers can also be recorded in the state of session 1 of the communication contract C2 for the user to query, or for processing when the session is opened next time.
  • the communication contract C2 and the off-chain device 12 are pre-configured: the off-chain device 12 closes the session after processing a predetermined number (eg, 20) of data.
  • a predetermined number eg, 20
  • a transaction that invokes contract C1, which invokes communication contract C2, is executed for data processing, for example, in the blockchain.
  • the off-chain device 12 returns the processing of the data by calling back the transaction of the communication contract C2, wherein the communication contract C2 returns the returned processing result to the contract C1 through the callback contract C1, and the contract C1 stores the processing result in the contract C1 after obtaining the processing result in the account status. Therefore, the blockchain node can determine whether to receive all the messages or data sent by the off-chain device 12 by querying the account status of the contract C1.
  • the off-chain device 12 After the off-chain device 12 reads the receipt 5 and its Spv certificate from the blockchain 11, it verifies the receipt 5, and obtains the account and "CloseMsg" of the communication contract C2 from the receipt 5, so as to correspond to the communication contract C2
  • the data retention period T1 is ended, that is, the communication data in the session 1 is deleted, thereby ending the session 1.
  • a receipt 5 is deposited in the blockchain, the receipt 5 including the account of the communication contract C2, the off-chain device 12 and the identifiers of the unreceived partial messages (such as message numbers), and modify the state of session 1 to the pre-closed state.
  • the off-chain device 12 After reading the receipt 5, the off-chain device 12 sends the transaction 6, in which the partial message is used as the incoming parameter to call the close session function of the communication contract C2, and the blockchain 11 receives the transaction 6 and After executing transaction 6, in the case of determining that all messages or data sent by the off-chain device 12 are received, delete the information of session 1 in the account state in the communication contract C2 (ie close session 1), or delete session 1's information.
  • the state is modified to a closed state, and a receipt 6 is deposited in the blockchain 11, which includes the account of the communication contract C2, the identification of the off-chain device 12, and a session close message (eg "CloseMsg").
  • the embodiment of this specification is not limited to this.
  • it can be performed on the blockchain 11 side by sending a transaction including a data field
  • a session identifier such as "session 1”
  • message content such as pre-opening message, pre-opening confirmation message, open message, Pending data, pre-close messages, close messages, etc.
  • the blockchain node can also create a session state database locally to record the state of each session similarly to the contract account state, so as to facilitate the query of the session state.
  • the node of the blockchain 11 needs to determine the session state between the blockchain 11 and the off-chain device 12, it is determined by querying the session state in the account state of the communication contract C2. It can be understood that, The embodiment of the present application is not limited to this, and the nodes in the blockchain 11 can also determine the status of the session 1 by querying the ledger data of the blockchain for the receipts of each transaction related to the session 1. For example, when the receipt of transaction 2 is queried in the ledger data, but the receipt that includes the pre-close message sent by the off-chain device 12 is not queried, it can be determined that the state of session 1 is the open state.
  • other statuses of session 1 may be determined based on the queried other transaction receipts related to session 1 . That is to say, in the solution of the embodiment of the present application, it is not necessary to record the state of the session 1 in the account state of the communication contract C2.
  • FIG. 3 is a communication apparatus 300 between a blockchain and off-chain devices according to an embodiment of the present specification.
  • the apparatus is deployed on a blockchain node and includes: a first execution unit 31 configured to execute a first execution unit 31.
  • the second execution unit 32 is configured to execute the
  • the second transaction sent by the off-chain device is used to provide the off-chain device with an opening message of the first session, and the second transaction includes confirmation information for the pre-opening message.
  • the first execution unit 31 is further configured to execute a first transaction to store the pre-opening message of the first session in the blockchain.
  • the first execution unit 31 is further configured to execute a first transaction, so as to record the state of the first session as a pre-opened state in the blockchain.
  • the first contract is invoked in the first transaction, wherein the first execution unit 31 is further configured to record the state of the first session in the account state of the first contract is pre-opened.
  • the first contract is invoked in the second transaction
  • the second execution unit 32 is further configured to execute the first contract invoked in the second transaction, so as to determine whether to The second transaction is executed within a first predetermined period of time, and in a case where it is determined that the second transaction is executed within the first predetermined period of time, an opening message of the first session is provided to the off-chain device.
  • the first execution unit 31 is further configured to end the first session if it is determined that the second transaction is executed after a first predetermined period of time.
  • the second execution unit 32 is further configured to modify the state of the first session to an open state.
  • the second execution unit 32 is further configured to store the opening message of the first session in the blockchain.
  • the apparatus 300 further includes a third execution unit 33 configured to, after providing the off-chain device with the opening message of the first session, execute a third transaction that invokes the first contract, where the The third transaction includes the pending first data, so that it is determined whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, in the blockchain
  • the first data is stored in association with the first session.
  • the apparatus 300 further includes: a fourth execution unit 34 configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information, so that: determining whether all messages sent by the off-chain device are received; in the case of determining that all messages sent by the off-chain device are received, providing the off-chain device with a close message of the first session.
  • a fourth execution unit 34 configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information, so that: determining whether all messages sent by the off-chain device are received; in the case of determining that all messages sent by the off-chain device are received, providing the off-chain device with a close message of the first session.
  • the fourth execution unit 34 is further configured to modify the state of the first session to a closed state.
  • the fourth execution unit 34 is further configured to associate in the blockchain with the first session in the event that it is determined that a message sent at least in part by the off-chain device has not been received request information for requesting the off-chain device to resend the at least part of the message.
  • the fourth execution unit 34 is further configured to, in a case where it is determined that a message sent at least in part by the off-chain device has not been received, modify the state of the first session to pre-closed state.
  • FIG. 4 shows an apparatus 400 for communication between a blockchain and an off-chain device according to an embodiment of the present specification.
  • the apparatus is deployed in the off-chain device, and includes: a first obtaining unit 401 configured to:
  • the blockchain obtains a pre-opening message of a first session, where the first session is a session between the blockchain and the off-chain device;
  • the first sending unit 402 is configured to send a second transaction to the blockchain , the second transaction includes confirmation information for the pre-opening message;
  • the opening unit 403 is configured to open the data retention period of the first session.
  • the first sending unit 402 is further configured to send the second transaction to the blockchain within a first predetermined period of time.
  • the apparatus 400 further includes a determining unit 404 configured to, after the data retention period is enabled, determine whether to obtain the opening of the first session from the blockchain within a second predetermined period of time message, the first ending unit 405 is configured to end the data retention period in the case that the opening message of the first session is not obtained from the blockchain within a second predetermined period of time.
  • the apparatus 400 further includes a second sending unit 406 configured to, when a preset condition is met, send a fourth transaction to the blockchain, where the fourth transaction includes the first transaction Pre-close information for a session.
  • the apparatus 400 further includes a second obtaining unit 407 configured to, after sending the fourth transaction to the blockchain, obtain the closure of the first session from the blockchain message; and a second ending unit 408, configured to end the data retention period.
  • the apparatus further includes a third obtaining unit 409, configured to, after sending the fourth transaction to the blockchain, obtain from the blockchain a pair of the sent first transaction A request message for at least part of the messages in the session; the third sending unit 410 is configured to send a fifth transaction to the blockchain, where the fifth transaction includes the at least part of the message.
  • Another aspect of the present specification provides a computer-readable storage medium on which a computer program is stored, when the computer program is executed in a computer, the computer is made to execute any one of the above methods.
  • Another aspect of the present specification provides a computing device, including a memory and a processor, where a computer program is stored in the memory, and the processor implements any one of the above methods when executing the computer program.
  • the session can be opened after both the blockchain and the off-chain device confirm the channel, and the off-chain device guarantees the session during the session opening.
  • the data retention period ensures secure two-way communication between the blockchain and off-chain devices.
  • by using a smart contract in the blockchain to conduct a session with an off-chain device, and recording the session status in the account status of the smart contract it is convenient for each node to query the session status, and Communication with off-chain devices can be done based on session state.
  • the software module can be placed in random access memory (RAM), internal memory, read only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or technical fields in any other form of storage medium known in the art.
  • RAM random access memory
  • ROM read only memory
  • electrically programmable ROM electrically erasable programmable ROM
  • registers hard disks, removable disks, CD-ROMs, or technical fields in any other form of storage medium known in the art.

Abstract

The embodiments of the present specification provide a method and apparatus for communication between a blockchain and an off-chain device. The method is executed by a blockchain node and comprises: executing a first transaction so as to provide to an off-chain device a pre-enable message of a first session, the first session being a session between a blockchain and the off-chain device; and executing a second transaction sent by the off-chain device so as to provide the off-chain device with an enable message of the first session, the second transaction comprising acknowledgment information for the pre-enable message.

Description

一种用于区块链与链下设备之间的通信方法和装置A method and device for communication between blockchain and off-chain devices 技术领域technical field
本说明书实施例涉及区块链技术领域,更具体地,涉及一种用于区块链与链下设备之间的通信方法和装置。The embodiments of this specification relate to the field of blockchain technology, and more particularly, to a method and apparatus for communication between a blockchain and an off-chain device.
背景技术Background technique
区块链技术也被称之为分布式账本技术,是一种去中心化的分布式数据库技术,其特点是去中心化、公开透明、不可篡改、可信任。区块链的每笔交易,都会广播到全网的区块链节点,每个全节点都有全量的、一致的数据。由于区块链是一个封闭的环境,区块链无法主动发起网络调用,链上智能合约也只能被动接收数据,因此,区块链无法主动获取链外的数据或资源。在现有技术中,为了克服上述问题,链下可信设备通过登录区块链客户端与区块链智能合约之间进行信息交互,从而可向区块链提供链外的数据或资源,例如可向区块链提供链外信息、链外数据处理能力等等。然而,在目前已有的区块链与链下设备的通信方案中,只实现了区块链通过合约从链下设备接收信息的单方向通信。Blockchain technology, also known as distributed ledger technology, is a decentralized distributed database technology characterized by decentralization, openness, transparency, immutability, and trustworthiness. Each transaction of the blockchain will be broadcast to the blockchain nodes of the entire network, and each full node has full and consistent data. Since the blockchain is a closed environment, the blockchain cannot actively initiate network calls, and the smart contracts on the chain can only passively receive data. Therefore, the blockchain cannot actively obtain data or resources outside the chain. In the prior art, in order to overcome the above problems, off-chain trusted devices can log in to the blockchain client and exchange information between the blockchain smart contracts, thereby providing off-chain data or resources to the blockchain, such as It can provide off-chain information, off-chain data processing capabilities, etc. to the blockchain. However, in the existing communication solutions between blockchain and off-chain devices, only one-way communication is realized in which the blockchain receives information from off-chain devices through contracts.
因此,需要一种更有效的在区块链与链下设备进行通信的方案。Therefore, there is a need for a more efficient solution for communicating with off-chain devices on the blockchain.
发明内容SUMMARY OF THE INVENTION
本说明书实施例旨在提供一种更有效的用于区块链与链下设备之间的通信方案,以解决现有技术中的不足。The embodiments of this specification aim to provide a more effective communication solution between the blockchain and off-chain devices, so as to solve the deficiencies in the prior art.
为实现上述目的,本说明书一个方面提供一种用于区块链与链下设备之间的通信方法,所述方法由区块链节点执行,包括:执行第一交易,以向链下设备提供第一会话的预开启消息,其中,所述第一会话为所述区块链与所述链下设备的会话;执行由所述链下设备发送的第二交易,以向所述链下设备提供所述第一会话的开启消息,所述第二交易中包括对所述预开启消息的确认信息。In order to achieve the above object, one aspect of this specification provides a communication method between a blockchain and an off-chain device, the method being executed by a blockchain node, including: executing a first transaction to provide the off-chain device with A pre-opening message for a first session, wherein the first session is a session between the blockchain and the off-chain device; execute a second transaction sent by the off-chain device to send the off-chain device to the off-chain device An opening message of the first session is provided, and confirmation information for the pre-opening message is included in the second transaction.
在一种实施方式中,执行第一交易还包括,执行第一交易,以在所述区块链中存入所述第一会话的预开启消息。In one embodiment, executing the first transaction further includes executing the first transaction to store a pre-opening message of the first session in the blockchain.
在一种实施方式中,执行第一交易还包括,执行第一交易,以在所述区块链中将所 述第一会话的状态记录为预开启状态。In one embodiment, executing the first transaction further includes executing the first transaction to record the state of the first session as a pre-opened state in the blockchain.
在一种实施方式中,所述第一交易中调用第一合约,其中,在所述区块链中将所述第一会话的状态记录为预开启状态包括,在所述第一合约的账户状态中将所述第一会话的状态记录为预开启状态。In one embodiment, the first contract is invoked in the first transaction, wherein recording the state of the first session as a pre-opened state in the blockchain includes, in the account of the first contract In the state, the state of the first session is recorded as a pre-opened state.
在一种实施方式中,所述第二交易中调用所述第一合约,所述执行由所述链下设备发送的第二交易包括,执行所述第二交易中调用的所述第一合约,使得确定是否在第一预定时段内执行所述第二交易,在确定在第一预定时段内执行所述第二交易的情况中,向链下设备提供第一会话的开启消息。In one embodiment, the first contract is invoked in the second transaction, and the executing the second transaction sent by the off-chain device includes executing the first contract invoked in the second transaction , so that it is determined whether the second transaction is executed within the first predetermined period, and in the case where it is determined that the second transaction is executed within the first predetermined period, an opening message of the first session is provided to the off-chain device.
在一种实施方式中,执行所述第二交易中调用的所述第一合约还使得,在确定在第一预定时段之后执行所述第二交易的情况中,结束所述第一会话。In one embodiment, executing the first contract invoked in the second transaction further results in ending the first session if the second transaction is determined to be executed after a first predetermined period of time.
在一种实施方式中,向所述链下设备提供第一会话的开启消息包括,将所述第一会话的状态修改为开启状态。In one embodiment, providing the off-chain device with an open message of the first session includes modifying the state of the first session to an open state.
在一种实施方式中,向所述链下设备提供第一会话的开启消息包括,在区块链中存入所述第一会话的开启消息。In one embodiment, providing the off-chain device with the opening message of the first session includes storing the opening message of the first session in the blockchain.
在一种实施方式中,所述方法还包括,在向所述链下设备提供第一会话的开启消息之后,执行调用第一合约的第三交易,所述第三交易中包括待处理的第一数据,以使得,确定所述第一会话的状态是否为开启状态,在确定所述第一会话的状态为开启状态的情况中,在区块链中与所述第一会话关联地存入所述第一数据。In one embodiment, the method further includes, after providing the off-chain device with the opening message of the first session, executing a third transaction invoking the first contract, the third transaction including the pending first session A piece of data, so as to determine whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, it is stored in the blockchain in association with the first session the first data.
在一种实施方式中,所述方法还包括:执行由所述链下设备发送的第四交易,所述第四交易中包括预关闭信息,以使得,确定是否接收到由所述链下设备发送的全部消息;在确定接收到由所述链下设备发送的全部消息的情况中,向所述链下设备提供所述第一会话的关闭消息。In one embodiment, the method further includes: executing a fourth transaction sent by the off-chain device, the fourth transaction including pre-closing information, so that it is determined whether the off-chain device has received All messages sent; in a case where it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
在一种实施方式中,向所述链下设备提供所述第一会话的关闭消息包括,将所述第一会话的状态修改为关闭状态。In one embodiment, providing the off-chain device with a close message of the first session includes modifying the state of the first session to a closed state.
在一种实施方式中,执行所述第四交易还使得,在确定未接收到至少部分由所述链下设备发送的消息的情况中,在区块链中与所述第一会话关联地存入请求信息,所述请求信息用于请求所述链下设备重新发送所述至少部分消息。In one embodiment, executing the fourth transaction further causes, in the event that it is determined that the message sent at least in part by the off-chain device has not been received, storing in the blockchain in association with the first session incoming request information, where the request information is used to request the off-chain device to resend the at least part of the message.
在一种实施方式中,执行所述第四交易还使得,在确定未接收到至少部分由所述链 下设备发送的消息的情况中,将所述第一会话的状态修改为预关闭状态。In one embodiment, executing the fourth transaction further results in modifying the state of the first session to a pre-closed state in the event that it is determined that a message sent at least in part by the off-chain device has not been received.
本说明书另一方面提供一种用于区块链与链下设备之间的通信方法,所述方法由链下设备执行,包括:从区块链获取第一会话的预开启消息,所述第一会话为所述区块链与所述链下设备的会话;向所述区块链发送第二交易,所述第二交易中包括对所述预开启消息的确认信息;开启所述第一会话的数据保留时段。Another aspect of this specification provides a method for communication between a blockchain and an off-chain device, the method being performed by the off-chain device, comprising: acquiring a pre-opening message of a first session from the blockchain, the first session A session is a session between the blockchain and the off-chain device; send a second transaction to the blockchain, the second transaction includes confirmation information for the pre-opening message; open the first The data retention period for the session.
在一种实施方式中,向所述区块链发送第二交易包括,在第一预定时段内向所述区块链发送第二交易。In one embodiment, sending the second transaction to the blockchain includes sending the second transaction to the blockchain within a first predetermined period of time.
在一种实施方式中,所述方法还包括,在开启数据保留时段之后,在第二预定时段内确定是否从所述区块链获取所述第一会话的开启消息,当在第二预定时段内未从所述区块链获取所述第一会话的开启消息的情况中,结束所述数据保留时段。In one embodiment, the method further includes, after the data retention period is opened, determining whether to obtain the open message of the first session from the blockchain within a second predetermined period, when the second predetermined period In the case where the opening message of the first session is not obtained from the blockchain within the period, the data retention period is ended.
在一种实施方式中,所述方法还包括,在符合预设条件时,向所述区块链发送第四交易,所述第四交易包括所述第一会话的预关闭信息。In one embodiment, the method further includes, when a preset condition is met, sending a fourth transaction to the blockchain, where the fourth transaction includes pre-closing information of the first session.
在一种实施方式中,所述方法还包括,在向所述区块链发送第四交易之后,从所述区块链获取所述第一会话的关闭消息;结束所述数据保留时段。In one embodiment, the method further includes, after sending the fourth transaction to the blockchain, obtaining a close message for the first session from the blockchain; and ending the data retention period.
在一种实施方式中,所述方法还包括,在向所述区块链发送第四交易之后,从所述区块链获取对已发送的所述第一会话中的至少部分消息的请求消息;向所述区块链发送第五交易,所述第五交易中包括所述至少部分消息。In one embodiment, the method further comprises, after sending the fourth transaction to the blockchain, obtaining a request message from the blockchain for at least a portion of the messages in the first session that have been sent ; sending a fifth transaction to the blockchain, the fifth transaction including the at least part of the message.
本说明书另一方面提供一种用于区块链与链下设备之间的通信装置,所述装置部署于区块链节点,包括:第一执行单元,配置为,执行第一交易,以向链下设备提供第一会话的预开启消息,其中,所述第一会话为所述区块链与所述链下设备的会话;第二执行单元,配置为,执行由所述链下设备发送的第二交易,以向所述链下设备提供所述第一会话的开启消息,所述第二交易中包括对所述预开启消息的确认信息。Another aspect of the present specification provides a communication device between a blockchain and an off-chain device, the device is deployed on a blockchain node, and includes: a first execution unit configured to execute a first transaction to send a transaction to the blockchain. The off-chain device provides a pre-opening message of a first session, where the first session is a session between the blockchain and the off-chain device; the second execution unit is configured to execute a session sent by the off-chain device to provide the off-chain device with an opening message of the first session, and the second transaction includes confirmation information for the pre-opening message.
在一种实施方式中,所述第一执行单元还配置为,执行第一交易,以在所述区块链中存入所述第一会话的预开启消息。In one embodiment, the first execution unit is further configured to execute a first transaction to store a pre-opening message of the first session in the blockchain.
在一种实施方式中,所述第一执行单元还配置为,执行第一交易,以在所述区块链中将所述第一会话的状态记录为预开启状态。In one embodiment, the first execution unit is further configured to execute a first transaction to record the state of the first session as a pre-opened state in the blockchain.
在一种实施方式中,所述第一交易中调用第一合约,其中,所述第一执行单元还配置为,在所述第一合约的账户状态中将所述第一会话的状态记录为预开启状态。In an implementation manner, the first contract is invoked in the first transaction, wherein the first execution unit is further configured to record the state of the first session in the account state of the first contract as pre-opened state.
在一种实施方式中,所述第二交易中调用所述第一合约,所述第二执行单元还配置为,执行所述第二交易中调用的所述第一合约,使得确定是否在第一预定时段内执行所述第二交易,在确定在第一预定时段内执行所述第二交易的情况中,向链下设备提供第一会话的开启消息。In one embodiment, the first contract is invoked in the second transaction, and the second execution unit is further configured to execute the first contract invoked in the second transaction, so as to determine whether the first contract is invoked in the second transaction. The second transaction is executed within a predetermined period of time, and in the event that the second transaction is determined to be executed within the first predetermined period of time, an opening message of the first session is provided to the off-chain device.
在一种实施方式中,所述第一执行单元还配置为,在确定在第一预定时段之后执行所述第二交易的情况中,结束所述第一会话。In one embodiment, the first execution unit is further configured to end the first session if it is determined that the second transaction is executed after a first predetermined period of time.
在一种实施方式中,所述第二执行单元还配置为,将所述第一会话的状态修改为开启状态。In one embodiment, the second execution unit is further configured to modify the state of the first session to an open state.
在一种实施方式中,所述第二执行单元还配置为,在区块链中存入所述第一会话的开启消息。In an implementation manner, the second execution unit is further configured to store an opening message of the first session in the blockchain.
在一种实施方式中,所述装置还包括,第三执行单元,配置为,在向所述链下设备提供第一会话的开启消息之后,执行调用第一合约的第三交易,所述第三交易中包括待处理的第一数据,以使得,确定所述第一会话的状态是否为开启状态,在确定所述第一会话的状态为开启状态的情况中,在区块链中与所述第一会话关联地存入所述第一数据。In one embodiment, the apparatus further includes a third execution unit configured to, after providing the off-chain device with an opening message of the first session, execute a third transaction that invokes the first contract, the first The first data to be processed is included in the third transaction, so that it is determined whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, the blockchain is connected with all and storing the first data in association with the first session.
在一种实施方式中,所述装置还包括:第四执行单元,配置为,执行由所述链下设备发送的第四交易,所述第四交易中包括预关闭信息,以使得,确定是否接收到由所述链下设备发送的全部消息;在确定接收到由所述链下设备发送的全部消息的情况中,向所述链下设备提供所述第一会话的关闭消息。In one embodiment, the apparatus further includes: a fourth execution unit configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information, so as to determine whether to All messages sent by the off-chain device are received; in a case where it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
在一种实施方式中,所述第四执行单元还配置为,将所述第一会话的状态修改为关闭状态。In an embodiment, the fourth execution unit is further configured to modify the state of the first session to a closed state.
在一种实施方式中,所述第四执行单元还配置为,在确定未接收到至少部分由所述链下设备发送的消息的情况中,在区块链中与所述第一会话关联地存入请求信息,所述请求信息用于请求所述链下设备重新发送所述至少部分消息。In one embodiment, the fourth execution unit is further configured to, in the event of determining that a message sent at least in part by the off-chain device has not been received, in the blockchain associated with the first session storing request information, where the request information is used to request the off-chain device to resend the at least part of the message.
在一种实施方式中,所述第四执行单元还配置为,在确定未接收到至少部分由所述链下设备发送的消息的情况中,将所述第一会话的状态修改为预关闭状态。In one embodiment, the fourth execution unit is further configured to, in a case where it is determined that a message sent at least in part by the off-chain device has not been received, modify the state of the first session to a pre-closed state .
本说明书另一方面提供一种用于区块链与链下设备之间的通信装置,所述装置部署于链下设备,包括:第一获取单元,配置为,从区块链获取第一会话的预开启消息,所述第一会话为所述区块链与所述链下设备的会话;第一发送单元,配置为,向所述区块链发送第二交易,所述第二交易中包括对所述预开启消息的确认信息;开启单元,配置 为,开启所述第一会话的数据保留时段。Another aspect of this specification provides a communication device between a blockchain and an off-chain device, the device is deployed on the off-chain device, and includes: a first obtaining unit configured to obtain a first session from the blockchain The first session is a session between the blockchain and the off-chain device; the first sending unit is configured to send a second transaction to the blockchain, in which the second transaction Including confirmation information for the pre-opening message; an opening unit, configured to open a data retention period of the first session.
在一种实施方式中,所述第一发送单元还配置为,在第一预定时段内向所述区块链发送第二交易。In one embodiment, the first sending unit is further configured to send a second transaction to the blockchain within a first predetermined period of time.
在一种实施方式中,所述装置还包括,确定单元,配置为,在开启数据保留时段之后,在第二预定时段内确定是否从所述区块链获取所述第一会话的开启消息,第一结束单元,配置为,当在第二预定时段内未从所述区块链获取所述第一会话的开启消息的情况中,结束所述数据保留时段。In one embodiment, the apparatus further includes a determining unit configured to, after the data retention period is enabled, determine whether to acquire the opening message of the first session from the blockchain within a second predetermined period, A first ending unit, configured to end the data retention period when the opening message of the first session is not obtained from the blockchain within a second predetermined period of time.
在一种实施方式中,所述装置还包括,第二发送单元,配置为,在符合预设条件时,向所述区块链发送第四交易,所述第四交易包括所述第一会话的预关闭信息。In one embodiment, the apparatus further includes a second sending unit configured to, when a preset condition is met, send a fourth transaction to the blockchain, where the fourth transaction includes the first session pre-close information.
在一种实施方式中,所述装置还包括,第二获取单元,配置为,在向所述区块链发送第四交易之后,从所述区块链获取所述第一会话的关闭消息;第二结束单元,配置为,结束所述数据保留时段。In one embodiment, the apparatus further includes a second obtaining unit configured to obtain a closing message of the first session from the blockchain after the fourth transaction is sent to the blockchain; A second end unit configured to end the data retention period.
在一种实施方式中,所述装置还包括,第三获取单元,配置为,在向所述区块链发送第四交易之后,从所述区块链获取对已发送的所述第一会话中的至少部分消息的请求消息;第三发送单元,配置为,向所述区块链发送第五交易,所述第五交易中包括所述至少部分消息。In one embodiment, the apparatus further includes a third obtaining unit, configured to, after sending the fourth transaction to the blockchain, obtain from the blockchain a request for the first session that has been sent A request message for at least part of the message in the third sending unit, configured to send a fifth transaction to the blockchain, where the fifth transaction includes the at least part of the message.
本说明书另一方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行上述任一项方法。Another aspect of the present specification provides a computer-readable storage medium on which a computer program is stored, when the computer program is executed in a computer, the computer is made to execute any one of the above methods.
本说明书另一方面提供一种计算设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器在执行所述计算机程序时,实现上述任一项方法。Another aspect of the present specification provides a computing device, including a memory and a processor, where a computer program is stored in the memory, and the processor implements any one of the above methods when executing the computer program.
通过根据本说明书实施例的用于区块链与链下设备之间的通信方案,可在区块链与链下设备都进行信道确认之后开启会话,并且,链下设备在会话开启期间保证会话数据保留时段,保证了区块链与链下设备之间的安全双向通信。另外,在本说明书实施例中,通过使用区块链中的智能合约与链下设备之间进行会话,并在智能合约的账户状态中记录会话的状态,方便各个节点对会话状态的查询,并可基于会话状态进行与链下设备的通信。Through the communication scheme between the blockchain and the off-chain device according to the embodiment of this specification, the session can be opened after both the blockchain and the off-chain device confirm the channel, and the off-chain device guarantees the session during the session opening. The data retention period ensures secure two-way communication between the blockchain and off-chain devices. In addition, in the embodiment of this specification, by using a smart contract in the blockchain to conduct a session with an off-chain device, and recording the session status in the account status of the smart contract, it is convenient for each node to query the session status, and Communication with off-chain devices can be done based on session state.
附图说明Description of drawings
通过结合附图描述本说明书实施例,可以使得本说明书实施例更加清楚:By describing the embodiments of the present specification in conjunction with the accompanying drawings, the embodiments of the present specification can be made clearer:
图1示出根据本说明书实施例的区块链系统示意图;FIG. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification;
图2示出根据本说明书实施例的区块链11与链下设备12之间的通信方法流程图;FIG. 2 shows a flowchart of a communication method between the blockchain 11 and the off-chain device 12 according to an embodiment of the present specification;
图3示出根据本说明书实施例的一种用于区块链与链下设备之间的通信装置300;FIG. 3 shows a communication apparatus 300 between a blockchain and an off-chain device according to an embodiment of the present specification;
图4为根据本说明书实施例的一种用于区块链与链下设备之间的通信装置400。FIG. 4 is a communication apparatus 400 used between a blockchain and an off-chain device according to an embodiment of the present specification.
具体实施方式Detailed ways
下面将结合附图描述本说明书实施例。The embodiments of the present specification will be described below with reference to the accompanying drawings.
图1示出根据本说明书实施例的区块链系统示意图。如图1所示,所述系统包括区块链11和链下设备12。其中,区块链11中部署有合约C1和通信合约C2。其中,所述通信合约C2用于与链下设备进行双向通信,合约C1通过调用通信合约C2而实现与链下设备的数据交互。链下设备12为可信设备,该可信设备可通过硬件、软件等形式来实现其可信性,例如,链下设备12中可包括可信执行环境(TEE),该TEE具有自身的硬件私钥和公钥,或者链下设备12中通过安全多方计算、零知识实现等算法实现其可信性,或者链下设备12可以为可信权威方的设备,等等。FIG. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification. As shown in FIG. 1 , the system includes a blockchain 11 and off-chain devices 12 . Among them, the contract C1 and the communication contract C2 are deployed in the blockchain 11 . The communication contract C2 is used for two-way communication with the off-chain device, and the contract C1 realizes data interaction with the off-chain device by calling the communication contract C2. The off-chain device 12 is a trusted device, and the trusted device can realize its trustworthiness through hardware, software, etc. For example, the off-chain device 12 can include a trusted execution environment (TEE), and the TEE has its own hardware The private key and public key, or the off-chain device 12 realizes its credibility through algorithms such as secure multi-party computation and zero-knowledge implementation, or the off-chain device 12 may be a device of a trusted authority, and so on.
所述通信合约C2可以与至少一个链下设备进行会话。通信合约C2中例如包括请求开启会话函数、会话开启函数、数据发送函数、结果返回函数、和会话关闭函数,并且,在区块链11的账户数据库中记录有通信合约C2与各个链下设备的会话状态,所述会话状态例如包括:预开启状态、开启状态、预关闭状态和关闭状态。The communication contract C2 can have a session with at least one off-chain device. The communication contract C2 includes, for example, a request to open a session function, a session open function, a data transmission function, a result return function, and a session close function, and the account database of the blockchain 11 records the communication between the communication contract C2 and each off-chain device. The session state, for example, the session state includes: a pre-open state, an open state, a pre-close state, and a closed state.
例如,区块链11中的节点1希望调用合约C1进行数据处理,由于合约C1中调用通信合约C2,因此,节点1可首先在区块链的账户数据库中查询通信合约C2的状态,以确定通信合约C2是否已经与链下设备12建立会话。如果查询到通信合约C2与链下设备12的会话状态为关闭状态,节点1可发送交易1,并在交易1中调用通信合约C2中的请求开启会话函数,以向链下设备12发送预开启消息。当区块链11的节点执行该交易1之后,在区块链中存入通信合约C2发送给链下设备12的“预开启消息”,同时将通信合约C2的与链下设备的会话1的状态记录为“预开启状态”。链下设备12可通过读取区块链11中的数据而读取到上述“预开启消息”,并向区块链11发送交易2,该交易2调用通信合约C2中的会话开启函数。链下设备12在发送交易2的同时开启数据保留时段,从而保证会话中的数据的安全性。区块链11中的节点在执行该交易2之后,将会话1的状态修改为“开启状态”。For example, node 1 in blockchain 11 wishes to call contract C1 for data processing. Since contract C1 calls communication contract C2, node 1 can first query the status of communication contract C2 in the account database of the blockchain to determine the status of communication contract C2. Whether the communication contract C2 has established a session with the off-chain device 12. If the session status between the communication contract C2 and the off-chain device 12 is found to be closed, node 1 can send transaction 1, and in transaction 1, call the request open session function in the communication contract C2 to send the pre-open session to the off-chain device 12. information. After the node of the blockchain 11 executes the transaction 1, the "pre-opening message" sent by the communication contract C2 to the off-chain device 12 is stored in the blockchain, and the communication contract C2 and the off-chain device's session 1 are stored in the blockchain. The state is recorded as "pre-open state". The off-chain device 12 can read the above-mentioned "pre-opening message" by reading the data in the blockchain 11, and send transaction 2 to the blockchain 11, and the transaction 2 calls the session opening function in the communication contract C2. The off-chain device 12 enables the data retention period while sending transaction 2, thereby ensuring the security of the data in the session. After executing the transaction 2, the node in the blockchain 11 modifies the state of the session 1 to "open state".
节点1在确定会话1的状态变为“开启状态”之后,可发送调用合约C1的交易3,如图1中所示,合约C1中以数据D1为参数调用通信合约C2中的数据发送函数。区块链11中的节点执行交易3时,执行其中调用的通信合约C2,从而在区块链中存入用于发送给链下设备12的数据D1。例如,如图1中所示,在区块链11中以包括数据D1的收据R1和Spv证明的形式将数据D1发送给链下设备12。区块链11可以为任意区块链,如比特币链、以太坊链、Hyperledger Fabric区块链(下文称为Fabric链)等等。不同的区块链具有不同的链上数据证明方式,例如,Fabric链使用背书节点签名的方式,以太坊链使用Spv证明的方式。下文中以区块链11为太坊链进行示例说明。After node 1 determines that the state of session 1 has changed to "open state", it can send transaction 3 that calls contract C1. As shown in Figure 1, contract C1 uses data D1 as a parameter to call the data sending function in communication contract C2. When the node in the blockchain 11 executes the transaction 3, it executes the communication contract C2 called therein, thereby storing the data D1 in the blockchain for sending to the off-chain device 12. For example, as shown in FIG. 1, data D1 is sent to off-chain device 12 in blockchain 11 in the form of receipt R1 and Spv proof including data D1. The blockchain 11 can be any blockchain, such as Bitcoin chain, Ethereum chain, Hyperledger Fabric blockchain (hereinafter referred to as Fabric chain) and so on. Different blockchains have different on-chain data proof methods. For example, the Fabric chain uses the endorsement node signature method, and the Ethereum chain uses the Spv proof method. In the following, the blockchain 11 is used as an example to illustrate the Ethereum chain.
然后,链下设备12可从区块链11中读取所述收据R1及其Spv证明。链下设备12中包括Spv客户端,在获取收据R1和Spv证明之后,链下设备12使用所述Spv客户端通过Spv验证方式对收据R1进行验证,并在验证之后从收据R1中获取由通信合约C2发送的数据D1,并对数据D1进行数据处理。The off-chain device 12 can then read the receipt R1 and its Spv proof from the blockchain 11 . The off-chain device 12 includes an Spv client. After obtaining the receipt R1 and the Spv certificate, the off-chain device 12 uses the Spv client to verify the receipt R1 through the Spv verification method, and obtains the data from the receipt R1 after the verification. Data D1 sent by contract C2, and data D1 is processed.
链下设备12例如为TEE设备,其在处理数据D1之后,例如获取的处理结果为处理结果E1。链下设备12使用其硬件私钥对处理结果E1进行签名,并向区块链发送调用通信合约C2的交易4,其中,该调用以处理结果E1及其签名为参数调用通信合约C2的结果返回函数,以将处理结果E1及其签名提供给通信合约C2。从而,当在区块链中执行该交易4时,使得通信合约C2使用其中预设的链下设备12的公钥对处理结果E1的签名进行验证,并在验证通过之后通过回调合约C1而将处理结果E1提供给合约C1。The off-chain device 12 is, for example, a TEE device, and after processing the data D1, for example, the acquired processing result is the processing result E1. The off-chain device 12 signs the processing result E1 using its hardware private key, and sends a transaction 4 that calls the communication contract C2 to the blockchain, where the call returns the result of calling the communication contract C2 with the processing result E1 and its signature as parameters function to provide the processing result E1 and its signature to the communication contract C2. Therefore, when the transaction 4 is executed in the blockchain, the communication contract C2 uses the preset public key of the off-chain device 12 to verify the signature of the processing result E1, and after the verification is passed, the contract C1 is called back to send the The processing result E1 is provided to the contract C1.
链下设备12在将要结束与通信合约C2的会话时,向区块链11发送交易5,在交易5中调用通信合约C2的请求关闭会话函数。当区块链11中的节点在执行交易5时,确定对来自链下设备12的数据是否接收完成,在确定接收完成的情况中,使得在区块链中存入“会话关闭消息”,同时将会话1的状态修改为关闭状态,从而结束对交易5的执行。链下设备12在从区块链11中读取到“会话关闭消息”之后结束上述数据保留时段,即,对上述会话中的数据进行删除。When the off-chain device 12 is about to end the session with the communication contract C2, it sends a transaction 5 to the blockchain 11, and in the transaction 5 calls the communication contract C2's request to close the session function. When the node in the blockchain 11 is executing transaction 5, it determines whether the reception of the data from the off-chain device 12 is completed. Change the state of session 1 to closed, thus ending the execution of transaction 5. The off-chain device 12 ends the above data retention period after reading the "session close message" from the blockchain 11, that is, deletes the data in the above session.
可以理解,上述参考图1的描述只是示意性的,而不用于对本说明书实施例的范围进行限制。例如,在区块链11中不限于通过合约C1调用通信合约,例如也可以在交易中直接以数据D1为传入参数调用通信合约C2,以通过链外设备12对数据D1进行处理。下文将详细描述上述区块链与链下设备之间的通信过程。It can be understood that the above description with reference to FIG. 1 is only illustrative, and is not used to limit the scope of the embodiments of the present specification. For example, the blockchain 11 is not limited to calling the communication contract through the contract C1. For example, the communication contract C2 can also be called directly with the data D1 as the incoming parameter in the transaction, so that the data D1 can be processed by the off-chain device 12. The communication process between the above-mentioned blockchain and off-chain devices will be described in detail below.
图2示出根据本说明书实施例的区块链11与链下设备12之间的通信方法流程图。FIG. 2 shows a flowchart of a communication method between the blockchain 11 and the off-chain device 12 according to an embodiment of the present specification.
如图2中所示,该方法由区块链11和链下设备12交互通信,从而实现区块链11与链下设备12之间的会话。当区块链11中的节点希望向链下设备12发送数据时,区块链11中的节点可通过发送交易而将希望发送的数据以可证明数据(例如交易收据、账户数据等)的形式存入区块链中,从而链下设备12可通过读取区块链中的收据而接收到该数据。当链下设备12希望向链上发送数据时,链下设备12可通过其中的区块链客户端向区块链发送交易,从而通过该交易向区块链提供数据。在一种实施方式中,在区块链11中可通过执行调用通信合约C2的交易,从而与链下设备12进行通信,下文中将以此为示例进行描述。可以理解,本说明书实施例提供的通信方法不限于通过执行调用通信合约C2的交易进行,而也可以通过执行包括数据字段的交易而执行,只要通过该交易的数据字段可明确发送的消息、及消息的接收方或发送方即可。As shown in FIG. 2 , in this method, the blockchain 11 and the off-chain device 12 communicate interactively, thereby realizing the session between the blockchain 11 and the off-chain device 12 . When a node in the blockchain 11 wishes to send data to the off-chain device 12, the node in the blockchain 11 can send the desired data in the form of provable data (eg transaction receipt, account data, etc.) by sending a transaction Stored in the blockchain so that the off-chain device 12 can receive this data by reading the receipt in the blockchain. When the off-chain device 12 wishes to send data to the on-chain, the off-chain device 12 may send a transaction to the blockchain through the blockchain client therein, thereby providing data to the blockchain through the transaction. In one embodiment, the blockchain 11 can communicate with the off-chain device 12 by executing a transaction that invokes the communication contract C2, which will be described below as an example. It can be understood that the communication method provided by the embodiments of this specification is not limited to executing a transaction that invokes the communication contract C2, but can also be executed by executing a transaction including a data field, as long as a message that can be explicitly sent through the data field of the transaction, and Either the recipient or the sender of the message is sufficient.
首先,在步骤S202,区块链11向链下设备12发送预开启消息。First, in step S202, the blockchain 11 sends a pre-opening message to the off-chain device 12.
如上文所述,通信合约C2的账户状态中记录了通信合约C2与链下设备的会话状态。例如,在初始,通信合约C2的账户状态中记录了与链下设备12的会话1的状态为关闭状态,或者通信合约C2的账户状态中未记录与链下设备12的任意会话,也即,通信合约C2与链下设备的会话状态为关闭状态。区块链11中的节点1在希望通过调用通信合约C2进行数据处理时,可首先查询通信合约C2的账户状态,从而可获知通信合约C2还未与链下设备12建立会话。因此,节点1可发送交易1,其中,在交易1中以链下设备12标识为传入参数调用通信合约C2中的请求开启会话函数,以向链下设备12发送预开启消息。As mentioned above, the account status of the communication contract C2 records the session status between the communication contract C2 and the off-chain device. For example, initially, the account status of the communication contract C2 records that the status of session 1 with the off-chain device 12 is closed, or the account status of the communication contract C2 does not record any session with the off-chain device 12, that is, The session state between the communication contract C2 and the off-chain device is closed. When the node 1 in the blockchain 11 wishes to perform data processing by invoking the communication contract C2, it can first query the account status of the communication contract C2, so as to know that the communication contract C2 has not established a session with the off-chain device 12. Therefore, node 1 may send transaction 1, in which the request to open session function in communication contract C2 is called with the off-chain device 12 identifier as an incoming parameter in transaction 1 to send a pre-open message to off-chain device 12.
区块链中的各个节点在对交易1进行共识之后分别执行交易1以获取一致的状态。区块链中的任一节点在执行交易1时,在区块链中存入交易1的收据R1,该收据R1中包括通信合约C2的账户、链下设备12的标识、以及预开启消息,所述预开启消息例如为“OpenSyncMsg”。在一种实施方式中,在所述收据R1中还可以包括会话1的标识(例如“会话1”)。同时,区块链中的节点还在通信合约C2的账户状态中记录通信合约C2与链下设备12的会话状态,例如以会话1作为该会话的标识,并将会话1的状态记录为“预开启状态”。表1示意示出在区块链节点中的通信合约C2的账户状态中记录的会话状态的表格。Each node in the blockchain executes transaction 1 after consensus on transaction 1 to obtain a consistent state. When any node in the blockchain executes transaction 1, it stores the receipt R1 of transaction 1 in the blockchain. The receipt R1 includes the account of the communication contract C2, the identifier of the off-chain device 12, and the pre-opening message. The pre-opening message is, for example, "OpenSyncMsg". In one embodiment, the receipt R1 may further include an identifier of session 1 (eg "session 1"). At the same time, the nodes in the blockchain also record the session status between the communication contract C2 and the off-chain device 12 in the account status of the communication contract C2. For example, session 1 is used as the identifier of the session, and the status of session 1 is recorded as "pre- On state". Table 1 schematically shows a table of session states recorded in the account state of the communication contract C2 in the blockchain node.
表1Table 1
会话标识session ID 链下设备标识Off-chain device identification 会话状态 session state
会话1session 1 链下设备12Off-Chain Devices 12 预开启状态pre-opened state
会话2session 2 链下设备16Off-Chain Devices 16 开启状态open state
     
如表1中所示,在通信合约C2的账户状态中可能记录了多个会话,例如会话1,会话2,不同的会话为与不同的链下设备进行的会话,并且可具有不同的会话状态。例如,会话1为通信合约C2与链下设备12之间的会话,并且会话1的状态为预开启状态。As shown in Table 1, multiple sessions may be recorded in the account state of the communication contract C2, such as session 1, session 2, and different sessions are sessions with different off-chain devices, and may have different session states . For example, session 1 is a session between communication contract C2 and off-chain device 12, and the state of session 1 is a pre-opened state.
链下设备12可通过其Spv客户端对包括通信合约C2的账户地址和链下设备12标识的收据进行监听,或者链下设备12可对包括“会话1”的收据进行监听,每当确定区块链11中存入了所述收据时,即可从区块链11中读取该收据,并相应地读取该收据的Spv证明数据。或者,区块链11中可主动进行信息推送,每次在确定区块链11中存入了执行通信合约C2所产生发送给链下设备12的收据时,将该收据及相应的Spv证明数据主动推送给链下设备12。从而,在区块链11中存入上述收据R1之后,链下设备12可从区块链11读取收据R1及其Spv证明,即接收到收据R1中的会话1的预开启消息。The off-chain device 12 can monitor the receipt including the account address of the communication contract C2 and the identification of the off-chain device 12 through its Spv client, or the off-chain device 12 can monitor the receipt including "session 1", whenever the area is determined. When the receipt is stored in the blockchain 11, the receipt can be read from the blockchain 11, and the Spv certification data of the receipt can be read accordingly. Alternatively, the blockchain 11 can actively push information, and each time it is determined that the blockchain 11 stores the receipt generated by the execution of the communication contract C2 and sent to the off-chain device 12, the receipt and the corresponding Spv proof data are stored in the blockchain 11. Actively push to off-chain device 12. Therefore, after the above-mentioned receipt R1 is stored in the blockchain 11, the off-chain device 12 can read the receipt R1 and its Spv proof from the blockchain 11, that is, receive the pre-opening message of the session 1 in the receipt R1.
可以理解,上文中虽然描述了以收据的形式向链下设备12提供预开启消息,本说明书实施例不限于此。例如,区块链11可通过通信合约C2的账户状态中的会话1的状态向链下设备12提供预开启消息。链下设备12通过在区块链11中读取会话1的状态从而可获取该消息。It can be understood that although it is described above that the pre-opening message is provided to the off-chain device 12 in the form of a receipt, the embodiment of the present specification is not limited thereto. For example, blockchain 11 may provide a pre-open message to off-chain device 12 through the state of session 1 in the account state of communication contract C2. The off-chain device 12 can obtain the message by reading the state of the session 1 in the blockchain 11 .
区块链11中的节点1可在交易1成块之后的预定数目的区块中查询是否包括由链下设备12发送的用于确认上述预开启消息的交易,如果不包括,节点1可如图2中虚线所示,发送调用通信合约C2中的会话关闭函数的交易,该交易在执行之后使得将通信合约C2的账户状态中记录的会话1的信息删除,或者将会话1的状态修改为关闭状态。可选地,该交易在被执行之后,向区块链11中存入会话关闭消息,以使得链下设备12可获取该信息。The node 1 in the blockchain 11 can query whether the transaction sent by the off-chain device 12 for confirming the above-mentioned pre-opening message is included in the predetermined number of blocks after the transaction 1 is formed into a block, if not included, the node 1 can be as follows: As shown by the dotted line in Figure 2, a transaction that calls the session closing function in the communication contract C2 is sent. After the transaction is executed, the information of the session 1 recorded in the account state of the communication contract C2 is deleted, or the state of the session 1 is modified to Disabled. Optionally, after the transaction is executed, a session close message is stored in the blockchain 11 so that the off-chain device 12 can obtain the information.
在步骤S204,链下设备12向区块链11发送预开启确认信息。In step S204, the off-chain device 12 sends pre-opening confirmation information to the blockchain 11.
链下设备12在读取收据R1及其Spv证明之后,通过Spv客户端使用所述Spv证明对收据R1进行验证。在验证通过之后,可从收据R1中读取“OpenSyncMsg”消息。链下设备12可在读取收据R1之后的预定时段内通过客户端向区块链11发送交易2,该交易2中例如调用通信合约C2中的会话开启函数,以向区块链11发送预开启确认信息。 在发送交易2之后,链下设备12开启了与区块链11中的通信合约C2的会话,并相应地开启与该会话对应的数据保留时段,在该数据保留时段中,链下设备12对该时段中的与通信合约C2的任何通信数据进行保留,以保证数据安全性。表2示意示出了在链下设备12中记录的各个会话的数据保留时段的表格。After reading the receipt R1 and its Spv proof, the off-chain device 12 verifies the receipt R1 by using the Spv proof through the Spv client. After the verification is passed, the "OpenSyncMsg" message can be read from the receipt R1. The off-chain device 12 can send transaction 2 to the blockchain 11 through the client within a predetermined period after the receipt R1 is read. In the transaction 2, for example, the session opening function in the communication contract C2 is called to send the pre-received transaction to the blockchain 11. Turn on the confirmation message. After sending transaction 2, the off-chain device 12 opens a session with the communication contract C2 in the blockchain 11, and accordingly opens a data retention period corresponding to the session, during which the off-chain device 12 has a pair of Any communication data with the communication contract C2 in this period is retained to ensure data security. Table 2 schematically shows a table of data retention periods for individual sessions recorded in the off-chain device 12 .
表2Table 2
会话标识session ID 合约地址contract address 数据保留时段Data retention period
会话1session 1 通信合约C2地址Communication contract C2 address 开启turn on
会话2session 2 合约C3地址Contract C3 address 关闭closure
     
如表2所示,通信设备12可与多个合约建立会话,例如会话1和会话2等等。在通信设备12中,可将各个会话中的通信数据与“会话1”进行关联,从而,当根据表2,会话1的数据保留时段为开启时,在通信设备12中保留会话1中的通信数据,当根据表2,确定会话2的数据保留时段为关闭时,则可删除会话2中的通信数据,并在表2中删除对会话2的记录。As shown in Table 2, communication device 12 may establish sessions with multiple contracts, such as session 1 and session 2, and so on. In the communication device 12, the communication data in each session can be associated with "session 1", so that when the data retention period of the session 1 is on according to Table 2, the communication in the session 1 is reserved in the communication device 12 data, when it is determined that the data retention period of session 2 is closed according to Table 2, the communication data in session 2 can be deleted, and the record of session 2 can be deleted in Table 2.
在步骤S206,区块链11向链下设备12发送开启消息。In step S206, the blockchain 11 sends an opening message to the off-chain device 12.
当区块链11中的节点在对交易2进行共识之后执行交易2时,首先确定会话1的状态是否为预开启状态。如果会话1的状态为预开启状态,则将会话1的状态修改为开启状态,并在区块链11中存入与交易2对应的收据R2,该收据R2中包括通信合约C2的账户、链下设备12的标识和开启消息(例如OpenMsg)。如果通信合约C2的账户状态中不包括会话1的信息(或者会话1的状态为关闭状态),则结束对交易2的执行,即不进行上述对会话状态的修改和存入收据R2的操作。When a node in blockchain 11 executes transaction 2 after consensus on transaction 2, it is first determined whether the state of session 1 is a pre-open state. If the state of session 1 is the pre-open state, change the state of session 1 to the open state, and store the receipt R2 corresponding to transaction 2 in the blockchain 11. The receipt R2 includes the account and chain of the communication contract C2. The identification of the lower device 12 and an opening message (eg OpenMsg). If the account state of the communication contract C2 does not include the information of the session 1 (or the state of the session 1 is closed), the execution of the transaction 2 is ended, that is, the above operations of modifying the session state and depositing the receipt R2 are not performed.
链下设备12在发送交易2之后,确定是否在预定时段内读取到由区块链11发送的上述开启消息,如果在预定时段内读取到上述开启消息,则可确认区块链11接收到其发送的交易2,则继续保留上述数据保留时段(如图2中的数据保留时段T1所示),如果在预定时段内未读取到上述开启消息,则结束上述数据保留时段(如图2中的数据保留时段T2所示)。该预定时段可基于区块链11中的交易成块时间预先确定。在一种实施方式中,在执行交易2之后,不向区块链11中存入上述收据R2,链下设备12可在发送交易2之后,确定是否在预定时段内读取到由区块链11向其发送的待处理数据, 如果在预定时段内读取到向其发送的待处理数据,则继续保留数据保留时段,如果在预定时段内未读取到所述待处理数据,则结束数据保留时段。After sending the transaction 2, the off-chain device 12 determines whether the above-mentioned opening message sent by the blockchain 11 is read within a predetermined period of time, and if the above-mentioned opening message is read within the predetermined period of time, it can be confirmed that the blockchain 11 has received To the transaction 2 sent by it, then continue to retain the above-mentioned data retention period (as shown in the data retention period T1 in Figure 2), if the above-mentioned opening message is not read within a predetermined period of time, then end the above-mentioned data retention period (as shown in Figure 2). 2 in the data retention period T2). The predetermined period of time may be predetermined based on transaction block times in the blockchain 11 . In one embodiment, after the transaction 2 is executed, the above-mentioned receipt R2 is not stored in the blockchain 11, and the off-chain device 12 can determine whether the transaction 2 is read by the blockchain within a predetermined period of time after the transaction 2 is sent. 11 The pending data sent to it, if the pending data sent to it is read within a predetermined period, continue to retain the data retention period, and if the pending data is not read within the predetermined period, end the data retention period.
在步骤S208,区块链11向链下设备12发送待处理的数据D1。In step S208, the blockchain 11 sends the data D1 to be processed to the off-chain device 12.
节点1在执行交易2以使得会话1的状态变为开启状态之后,节点1可开始通过链下设备12进行数据处理。节点1例如发送交易3,该交易3中以数据D1和链下设备12标识为参数调用通信合约C2中的数据发送函数。区块链中的节点在对交易3进行共识之后执行交易3,在执行交易3之后存入交易3的收据3。该收据3中包括通信合约C2的标识、链下设备12标识和数据D1。与上述读取收据R1类似地,链下设备12可通过客户端从区块链11读取收据3及其Spv证明,对收据3进行验证,并从收据3中获取数据D1和通信合约C2的标识。After node 1 executes transaction 2 so that the state of session 1 becomes the open state, node 1 can start data processing through off-chain device 12 . Node 1, for example, sends transaction 3, in which transaction 3 calls the data sending function in communication contract C2 with data D1 and the identifier of off-chain device 12 as parameters. Nodes in the blockchain execute transaction 3 after consensus on transaction 3, and deposit receipt 3 of transaction 3 after executing transaction 3. The receipt 3 includes the identification of the communication contract C2, the identification of the off-chain device 12 and the data D1. Similar to the above reading receipt R1, the off-chain device 12 can read the receipt 3 and its Spv proof from the blockchain 11 through the client, verify the receipt 3, and obtain the data D1 and the communication contract C2 from the receipt 3. logo.
在步骤S210,链下设备12向区块链11发送数据D1的处理结果。In step S210, the off-chain device 12 sends the processing result of the data D1 to the blockchain 11.
链下设备12例如为TEE设备,其中预设了数据处理程序,并且具有其硬件私钥和公钥。链下设备12在获取数据D1和通信合约C2的标识之后,使用预设的数据处理程序对数据D1进行处理,从而获取数据D1的处理结果(处理结果E1),并使用其硬件私钥对处理结果E1进行数字签名。之后,链下设备12向区块链11发送交易4,在该交易4中以处理结果E1及TEE签名为传入参数调用通信合约C2中的结果返回函数。该结果返回函数中预设有链下设备12的硬件公钥,当区块链11中的节点1在执行交易4时,使用硬件公钥对TEE签名进行验证,在验证通过之后可获取数据D1的处理结果E1。当如图1中所示交易3中调用合约C1、且合约C1中调用通信合约C2的情况中,则在交易4中调用通信合约C2中的结果返回函数,并在该函数中以处理结果E1为传入参数调用合约C1,从而,当节点1执行交易4时,在通过通信合约C2获取处理结果E1之后以处理结果E1为参数执行合约C1,从而获取最终合约C1的执行结果。The off-chain device 12 is, for example, a TEE device, in which a data processing program is preset and has its hardware private key and public key. After obtaining the identifiers of the data D1 and the communication contract C2, the off-chain device 12 uses the preset data processing program to process the data D1, thereby obtaining the processing result (processing result E1) of the data D1, and uses its hardware private key to process the data D1. The result E1 is digitally signed. After that, the off-chain device 12 sends transaction 4 to the blockchain 11, in which the result-returning function in the communication contract C2 is called with the processing result E1 and the TEE signature as incoming parameters. The hardware public key of the off-chain device 12 is preset in the result return function. When the node 1 in the blockchain 11 executes the transaction 4, it uses the hardware public key to verify the TEE signature, and the data D1 can be obtained after the verification is passed. The processing result E1. When the contract C1 is called in the transaction 3 and the communication contract C2 is called in the contract C1 as shown in Fig. 1, the result return function in the communication contract C2 is called in the transaction 4, and the result E1 is processed in the function. Call the contract C1 for the incoming parameters, so that when the node 1 executes the transaction 4, after obtaining the processing result E1 through the communication contract C2, the contract C1 is executed with the processing result E1 as the parameter, so as to obtain the final execution result of the contract C1.
区块链11中的其它节点(例如节点2)在希望调用通信合约C2时,也与节点1类似地,首先在通信合约C2的账户状态中查询通信合约C2与链下设备12的会话状态,当查询到通信合约C2与链下设备12之间的会话1的状态为开启状态的情况中,节点2可与节点1类似地向链下设备12发送数据(例如图2中所示的数据D2)并接收数据D2的处理结果E2。When other nodes (such as node 2) in the blockchain 11 want to call the communication contract C2, similar to the node 1, they first query the session status between the communication contract C2 and the off-chain device 12 in the account status of the communication contract C2, When the status of the session 1 between the communication contract C2 and the off-chain device 12 is queried, the node 2 can send data to the off-chain device 12 similar to the node 1 (for example, the data D2 shown in FIG. 2 ). ) and receive the processing result E2 of the data D2.
在步骤S212,链下设备12向区块链11发送预关闭信息。In step S212, the off-chain device 12 sends pre-shutdown information to the blockchain 11.
链下设备12在符合预定条件时向区块链发送对会话1的预关闭消息。所述预定条件 例如为以下任一种:链下设备12在连续预定长度时间中未接收到待处理数据、区块链11中通过执行通信合约C2向区块链11中存入用于请求链下设备12关闭会话1的消息、链下设备12处理完成预定数量的数据,等等。The off-chain device 12 sends a pre-close message for session 1 to the blockchain when predetermined conditions are met. The predetermined condition is, for example, any one of the following: the off-chain device 12 has not received the data to be processed for a continuous predetermined length of time, and the blockchain 11 stores the request chain in the blockchain 11 by executing the communication contract C2. The message that the off-chain device 12 closes session 1, the off-chain device 12 completes processing a predetermined amount of data, and so on.
具体是,链下设备12通过客户端向区块链11发送交易5,在交易5中调用通信合约C2的关闭会话函数,以向区块链11发送预关闭消息。Specifically, the off-chain device 12 sends transaction 5 to the blockchain 11 through the client, and in the transaction 5 calls the close session function of the communication contract C2 to send a pre-close message to the blockchain 11 .
在步骤S214,区块链11向链下设备12发送关闭消息。In step S214, the blockchain 11 sends a shutdown message to the off-chain device 12.
区块链11中的节点在执行交易5时,确定是否接收到全部由链下设备12发送的消息或数据;在确定接收到全部由链下设备12发送的消息或数据的情况中,将通信合约C2中账户状态中的会话1的状态删除(即关闭会话1),或者将会话1的状态修改为关闭状态,结束对交易5的执行,并在区块链11中存入收据5,该收据5中包括通信合约C2的账户、链下设备12的标识以及会话关闭消息(例如“CloseMsg”)。When the node in the blockchain 11 executes the transaction 5, it determines whether it has received all the messages or data sent by the off-chain device 12; The state of session 1 in the account state in contract C2 is deleted (ie, session 1 is closed), or the state of session 1 is modified to the closed state, the execution of transaction 5 is ended, and receipt 5 is stored in blockchain 11. The receipt 5 includes the account of the communication contract C2, the identification of the off-chain device 12 and the session close message (eg "CloseMsg").
其中,在执行交易5时,根据通信合约C2与链下设备12之间的预先设定,可通过不同的方法确定是否接收到全部由链下设备12发送的消息或数据。When executing the transaction 5, according to the preset between the communication contract C2 and the off-chain device 12, it can be determined by different methods whether all messages or data sent by the off-chain device 12 are received.
在一种实施方式中,通信合约C2可对每次发送的数据进行编号,例如如图2中所示,将发送的数据编号为数据D1、数据D2,链下设备12也相应地对发送回区块链的数据结果进行编号,例如将数据D1的处理结果编号为处理结果E1,将数据D2的处理结果编号为处理结果E2。区块链11可基于接收的处理结果的编号确定该处理结果是与哪个数据对应的处理结果。当链下设备12发送预关闭消息中可在交易5中将其发送的最后一个处理结果的编号(例如“10”)作为参数调用通信合约C2中的请求关闭会话函数,从而当在区块链11中执行交易5时,确定是否已经接收到处理结果E1-处理结果E10,从而确定是否接收到全部由链下设备12发送的消息或数据。在该实施方式中,在链下设备12通过交易5发送预关闭消息之后,有可能在区块链11侧已经向链下设备12发送了待处理的数据D11、数据D12等等,在执行交易5时,还可以在通信合约C2的会话1的状态中记录这些数据编号,以供用户查询,或者下次会话开启时进行处理。In one embodiment, the communication contract C2 can number the data sent each time. For example, as shown in FIG. 2 , the sent data are numbered as data D1 and data D2, and the off-chain device 12 also sends back corresponding numbers. The data results of the blockchain are numbered, for example, the processing result of the data D1 is numbered as the processing result E1, and the processing result of the data D2 is numbered as the processing result E2. The blockchain 11 can determine which data the processing result corresponds to based on the number of the received processing result. When the off-chain device 12 sends the pre-close message, the number of the last processing result (for example, "10") sent by it in transaction 5 can be used as a parameter to call the request to close the session function in the communication contract C2. When the transaction 5 is executed in 11, it is determined whether the processing result E1-processing result E10 has been received, thereby determining whether all the messages or data sent by the off-chain device 12 have been received. In this embodiment, after the off-chain device 12 sends the pre-close message through transaction 5, it is possible that the pending data D11, data D12, etc. have been sent to the off-chain device 12 on the blockchain 11 side, and the transaction is executed At 5:00, these data numbers can also be recorded in the state of session 1 of the communication contract C2 for the user to query, or for processing when the session is opened next time.
在另一种实施方式中,例如,通信合约C2与链下设备12预先设定:链下设备12在处理完预定数目(例如20)个数据之后关闭会话。从而,在区块链11中执行交易5时,可确定是否已经接收到20个处理结果,从而确定是否接收到全部由链下设备12发送的消息或数据。In another embodiment, for example, the communication contract C2 and the off-chain device 12 are pre-configured: the off-chain device 12 closes the session after processing a predetermined number (eg, 20) of data. Thus, when transaction 5 is executed in blockchain 11, it can be determined whether 20 processing results have been received, and thus whether all messages or data sent by off-chain device 12 have been received.
在一种实施方式中,例如在区块链中执行调用合约C1的交易以进行数据处理,其 中合约C1中调用通信合约C2。链下设备12通过回调通信合约C2的交易返回对数据的处理,其中通信合约C2通过回调合约C1将返回的处理结果返回给合约C1,合约C1在获取处理结果之后将该处理结果存储到合约C1的账户状态中。从而,区块链节点可通过查询合约C1的账户状态从而确定是否接收到全部由链下设备12发送的消息或数据。In one embodiment, a transaction that invokes contract C1, which invokes communication contract C2, is executed for data processing, for example, in the blockchain. The off-chain device 12 returns the processing of the data by calling back the transaction of the communication contract C2, wherein the communication contract C2 returns the returned processing result to the contract C1 through the callback contract C1, and the contract C1 stores the processing result in the contract C1 after obtaining the processing result in the account status. Therefore, the blockchain node can determine whether to receive all the messages or data sent by the off-chain device 12 by querying the account status of the contract C1.
链下设备12在从区块链11读取到收据5及其Spv证明之后,对收据5进行验证,并从收据5中获取通信合约C2的账户及“CloseMsg”,从而将与通信合约C2对应的数据保留时段T1结束,即,将会话1中的通信数据删除,从而结束会话1。After the off-chain device 12 reads the receipt 5 and its Spv certificate from the blockchain 11, it verifies the receipt 5, and obtains the account and "CloseMsg" of the communication contract C2 from the receipt 5, so as to correspond to the communication contract C2 The data retention period T1 is ended, that is, the communication data in the session 1 is deleted, thereby ending the session 1.
当在执行交易5时,在确定未接收到部分由链下设备12发送的消息的情况中,在区块链中存入收据5,该收据5中包括通信合约C2的账户、链下设备12的标识以及未接收到的部分消息的标识(例如消息编号),并将会话1的状态修改为预关闭状态。链下设备12在读取到该收据5之后,发送交易6,在该交易6中以所述部分消息为传入参数调用通信合约C2的关闭会话函数,区块链11在接收到交易6并执行交易6之后,在确定接收到全部由链下设备12发送的消息或数据的情况中,将通信合约C2中账户状态中的会话1的信息删除(即关闭会话1),或者将会话1的状态修改为关闭状态,并在区块链11中存入收据6,该收据6中包括通信合约C2的账户、链下设备12的标识以及会话关闭消息(例如“CloseMsg”)。When executing transaction 5, in the event that it is determined that the message partially sent by the off-chain device 12 is not received, a receipt 5 is deposited in the blockchain, the receipt 5 including the account of the communication contract C2, the off-chain device 12 and the identifiers of the unreceived partial messages (such as message numbers), and modify the state of session 1 to the pre-closed state. After reading the receipt 5, the off-chain device 12 sends the transaction 6, in which the partial message is used as the incoming parameter to call the close session function of the communication contract C2, and the blockchain 11 receives the transaction 6 and After executing transaction 6, in the case of determining that all messages or data sent by the off-chain device 12 are received, delete the information of session 1 in the account state in the communication contract C2 (ie close session 1), or delete session 1's information. The state is modified to a closed state, and a receipt 6 is deposited in the blockchain 11, which includes the account of the communication contract C2, the identification of the off-chain device 12, and a session close message (eg "CloseMsg").
可以理解,上文中虽然以通信合约C2为例对本说明书实施例提供的通信方案进行了描述,本说明书实施例不限于此,例如,可在区块链11侧通过发送包括数据字段的交易而进行图2所示的通信过程,其中,在每次发送消息时,在交易的数据字段中包括会话标识(例如“会话1”)和消息内容(如预开启消息、预开启确认消息、开启消息、待处理数据、预关闭消息、关闭消息等),从而在各个交易中记录会话状态及数据。优选地,区块链节点还可以在本地创建会话状态数据库,以与合约账户状态中类似地记录各个会话的状态,从而便于会话状态的查询。It can be understood that although the communication scheme provided by the embodiment of this specification is described above by taking the communication contract C2 as an example, the embodiment of this specification is not limited to this. For example, it can be performed on the blockchain 11 side by sending a transaction including a data field The communication process shown in FIG. 2, wherein each time a message is sent, a session identifier (such as "session 1") and message content (such as pre-opening message, pre-opening confirmation message, open message, Pending data, pre-close messages, close messages, etc.) to record session state and data in each transaction. Preferably, the blockchain node can also create a session state database locally to record the state of each session similarly to the contract account state, so as to facilitate the query of the session state.
另外,在上文的描述中,当区块链11的节点需要确定区块链11与链下设备12的会话状态时,通过查询通信合约C2的账户状态中的会话状态来确定,可以理解,本申请实施例不限于此,区块链11中的节点还可以通过在区块链的账本数据中查询与会话1相关的各个交易的收据,从而确定会话1的状态。例如,当在账本数据中查询到交易2的收据,但是未查询包括由链下设备12发送的预关闭消息的收据时,则可确定会话1的状态为开启状态。类似地,可基于查询到的与会话1相关的其它交易收据情况确定会话1的其它状态。也就是说,在本申请实施例的方案中,在通信合约C2的账户状态中 记录会话1的状态并不是必需的。In addition, in the above description, when the node of the blockchain 11 needs to determine the session state between the blockchain 11 and the off-chain device 12, it is determined by querying the session state in the account state of the communication contract C2. It can be understood that, The embodiment of the present application is not limited to this, and the nodes in the blockchain 11 can also determine the status of the session 1 by querying the ledger data of the blockchain for the receipts of each transaction related to the session 1. For example, when the receipt of transaction 2 is queried in the ledger data, but the receipt that includes the pre-close message sent by the off-chain device 12 is not queried, it can be determined that the state of session 1 is the open state. Similarly, other statuses of session 1 may be determined based on the queried other transaction receipts related to session 1 . That is to say, in the solution of the embodiment of the present application, it is not necessary to record the state of the session 1 in the account state of the communication contract C2.
图3为根据本说明书实施例的一种用于区块链与链下设备之间的通信装置300,所述装置部署于区块链节点,包括:第一执行单元31,配置为,执行第一交易,以向链下设备提供第一会话的预开启消息,其中,所述第一会话为所述区块链与所述链下设备的会话;第二执行单元32,配置为,执行由所述链下设备发送的第二交易,以向所述链下设备提供所述第一会话的开启消息,所述第二交易中包括对所述预开启消息的确认信息。FIG. 3 is a communication apparatus 300 between a blockchain and off-chain devices according to an embodiment of the present specification. The apparatus is deployed on a blockchain node and includes: a first execution unit 31 configured to execute a first execution unit 31. A transaction to provide a pre-opening message of a first session to an off-chain device, wherein the first session is a session between the blockchain and the off-chain device; the second execution unit 32 is configured to execute the The second transaction sent by the off-chain device is used to provide the off-chain device with an opening message of the first session, and the second transaction includes confirmation information for the pre-opening message.
在一种实施方式中,所述第一执行单元31还配置为,执行第一交易,以在所述区块链中存入所述第一会话的预开启消息。In an embodiment, the first execution unit 31 is further configured to execute a first transaction to store the pre-opening message of the first session in the blockchain.
在一种实施方式中,所述第一执行单元31还配置为,执行第一交易,以在所述区块链中将所述第一会话的状态记录为预开启状态。In one embodiment, the first execution unit 31 is further configured to execute a first transaction, so as to record the state of the first session as a pre-opened state in the blockchain.
在一种实施方式中,所述第一交易中调用第一合约,其中,所述第一执行单元31还配置为,在所述第一合约的账户状态中将所述第一会话的状态记录为预开启状态。In an implementation manner, the first contract is invoked in the first transaction, wherein the first execution unit 31 is further configured to record the state of the first session in the account state of the first contract is pre-opened.
在一种实施方式中,所述第二交易中调用所述第一合约,所述第二执行单元32还配置为,执行所述第二交易中调用的所述第一合约,使得确定是否在第一预定时段内执行所述第二交易,在确定在第一预定时段内执行所述第二交易的情况中,向链下设备提供第一会话的开启消息。In an implementation manner, the first contract is invoked in the second transaction, and the second execution unit 32 is further configured to execute the first contract invoked in the second transaction, so as to determine whether to The second transaction is executed within a first predetermined period of time, and in a case where it is determined that the second transaction is executed within the first predetermined period of time, an opening message of the first session is provided to the off-chain device.
在一种实施方式中,所述第一执行单元31还配置为,在确定在第一预定时段之后执行所述第二交易的情况中,结束所述第一会话。In one embodiment, the first execution unit 31 is further configured to end the first session if it is determined that the second transaction is executed after a first predetermined period of time.
在一种实施方式中,所述第二执行单元32还配置为,将所述第一会话的状态修改为开启状态。In an embodiment, the second execution unit 32 is further configured to modify the state of the first session to an open state.
在一种实施方式中,所述第二执行单元32还配置为,在区块链中存入所述第一会话的开启消息。In an embodiment, the second execution unit 32 is further configured to store the opening message of the first session in the blockchain.
在一种实施方式中,所述装置300还包括,第三执行单元33,配置为,在向所述链下设备提供第一会话的开启消息之后,执行调用第一合约的第三交易,所述第三交易中包括待处理的第一数据,以使得,确定所述第一会话的状态是否为开启状态,在确定所述第一会话的状态为开启状态的情况中,在区块链中与所述第一会话关联地存入所述第一数据。In one embodiment, the apparatus 300 further includes a third execution unit 33 configured to, after providing the off-chain device with the opening message of the first session, execute a third transaction that invokes the first contract, where the The third transaction includes the pending first data, so that it is determined whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, in the blockchain The first data is stored in association with the first session.
在一种实施方式中,所述装置300还包括:第四执行单元34,配置为,执行由所 述链下设备发送的第四交易,所述第四交易中包括预关闭信息,以使得,确定是否接收到由所述链下设备发送的全部消息;在确定接收到由所述链下设备发送的全部消息的情况中,向所述链下设备提供所述第一会话的关闭消息。In one embodiment, the apparatus 300 further includes: a fourth execution unit 34 configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information, so that: determining whether all messages sent by the off-chain device are received; in the case of determining that all messages sent by the off-chain device are received, providing the off-chain device with a close message of the first session.
在一种实施方式中,所述第四执行单元34还配置为,将所述第一会话的状态修改为关闭状态。In an embodiment, the fourth execution unit 34 is further configured to modify the state of the first session to a closed state.
在一种实施方式中,所述第四执行单元34还配置为,在确定未接收到至少部分由所述链下设备发送的消息的情况中,在区块链中与所述第一会话关联地存入请求信息,所述请求信息用于请求所述链下设备重新发送所述至少部分消息。In one embodiment, the fourth execution unit 34 is further configured to associate in the blockchain with the first session in the event that it is determined that a message sent at least in part by the off-chain device has not been received request information for requesting the off-chain device to resend the at least part of the message.
在一种实施方式中,所述第四执行单元34还配置为,在确定未接收到至少部分由所述链下设备发送的消息的情况中,将所述第一会话的状态修改为预关闭状态。In one embodiment, the fourth execution unit 34 is further configured to, in a case where it is determined that a message sent at least in part by the off-chain device has not been received, modify the state of the first session to pre-closed state.
图4示出根据本说明书实施例的一种用于区块链与链下设备之间的通信装置400,所述装置部署于链下设备,包括:第一获取单元401,配置为,从区块链获取第一会话的预开启消息,所述第一会话为所述区块链与所述链下设备的会话;第一发送单元402,配置为,向所述区块链发送第二交易,所述第二交易中包括对所述预开启消息的确认信息;开启单元403,配置为,开启所述第一会话的数据保留时段。FIG. 4 shows an apparatus 400 for communication between a blockchain and an off-chain device according to an embodiment of the present specification. The apparatus is deployed in the off-chain device, and includes: a first obtaining unit 401 configured to: The blockchain obtains a pre-opening message of a first session, where the first session is a session between the blockchain and the off-chain device; the first sending unit 402 is configured to send a second transaction to the blockchain , the second transaction includes confirmation information for the pre-opening message; the opening unit 403 is configured to open the data retention period of the first session.
在一种实施方式中,所述第一发送单元402还配置为,在第一预定时段内向所述区块链发送第二交易。In one embodiment, the first sending unit 402 is further configured to send the second transaction to the blockchain within a first predetermined period of time.
在一种实施方式中,所述装置400还包括,确定单元404,配置为,在开启数据保留时段之后,在第二预定时段内确定是否从所述区块链获取所述第一会话的开启消息,第一结束单元405,配置为,当在第二预定时段内未从所述区块链获取所述第一会话的开启消息的情况中,结束所述数据保留时段。In one embodiment, the apparatus 400 further includes a determining unit 404 configured to, after the data retention period is enabled, determine whether to obtain the opening of the first session from the blockchain within a second predetermined period of time message, the first ending unit 405 is configured to end the data retention period in the case that the opening message of the first session is not obtained from the blockchain within a second predetermined period of time.
在一种实施方式中,所述装置400还包括,第二发送单元406,配置为,在符合预设条件时,向所述区块链发送第四交易,所述第四交易包括所述第一会话的预关闭信息。In one embodiment, the apparatus 400 further includes a second sending unit 406 configured to, when a preset condition is met, send a fourth transaction to the blockchain, where the fourth transaction includes the first transaction Pre-close information for a session.
在一种实施方式中,所述装置400还包括,第二获取单元407,配置为,在向所述区块链发送第四交易之后,从所述区块链获取所述第一会话的关闭消息;第二结束单元408,配置为,结束所述数据保留时段。In one embodiment, the apparatus 400 further includes a second obtaining unit 407 configured to, after sending the fourth transaction to the blockchain, obtain the closure of the first session from the blockchain message; and a second ending unit 408, configured to end the data retention period.
在一种实施方式中,所述装置还包括,第三获取单元409,配置为,在向所述区块链发送第四交易之后,从所述区块链获取对已发送的所述第一会话中的至少部分消息的请求消息;第三发送单元410,配置为,向所述区块链发送第五交易,所述第五交易中 包括所述至少部分消息。In an implementation manner, the apparatus further includes a third obtaining unit 409, configured to, after sending the fourth transaction to the blockchain, obtain from the blockchain a pair of the sent first transaction A request message for at least part of the messages in the session; the third sending unit 410 is configured to send a fifth transaction to the blockchain, where the fifth transaction includes the at least part of the message.
本说明书另一方面提供一种计算机可读存储介质,其上存储有计算机程序,当所述计算机程序在计算机中执行时,令计算机执行上述任一项方法。Another aspect of the present specification provides a computer-readable storage medium on which a computer program is stored, when the computer program is executed in a computer, the computer is made to execute any one of the above methods.
本说明书另一方面提供一种计算设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器在执行所述计算机程序时,实现上述任一项方法。Another aspect of the present specification provides a computing device, including a memory and a processor, where a computer program is stored in the memory, and the processor implements any one of the above methods when executing the computer program.
通过根据本说明书实施例的用于区块链与链下设备之间的通信方案,可在区块链与链下设备都进行信道确认之后开启会话,并且,链下设备在会话开启期间保证会话数据保留时段,保证了区块链与链下设备之间的安全双向通信。另外,在本说明书实施例中,通过使用区块链中的智能合约与链下设备之间进行会话,并在智能合约的账户状态中记录会话的状态,方便各个节点对会话状态的查询,并可基于会话状态进行与链下设备的通信。Through the communication scheme between the blockchain and the off-chain device according to the embodiment of this specification, the session can be opened after both the blockchain and the off-chain device confirm the channel, and the off-chain device guarantees the session during the session opening. The data retention period ensures secure two-way communication between the blockchain and off-chain devices. In addition, in the embodiment of this specification, by using a smart contract in the blockchain to conduct a session with an off-chain device, and recording the session status in the account status of the smart contract, it is convenient for each node to query the session status, and Communication with off-chain devices can be done based on session state.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the various embodiments may be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for related parts, please refer to the partial descriptions of the method embodiments.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments and still achieve desirable results. Additionally, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
本领域普通技术人员应该还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。本领域普通技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。其中,软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。Those of ordinary skill in the art should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software or a combination of the two, in order to clearly illustrate the hardware and software interchangeability, the components and steps of each example have been generally described in terms of functions in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Persons of ordinary skill in the art may use different methods of implementing the described functionality for each particular application, but such implementations should not be considered beyond the scope of this application. Wherein, the software module can be placed in random access memory (RAM), internal memory, read only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or technical fields in any other form of storage medium known in the art.
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above further describe the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above descriptions are only specific embodiments of the present invention, and are not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims (40)

  1. 一种用于区块链与链下设备之间的通信方法,所述方法由区块链节点执行,包括:A method for communication between a blockchain and off-chain devices, the method being performed by a blockchain node, comprising:
    执行第一交易,以向链下设备提供第一会话的预开启消息,其中,所述第一会话为所述区块链与所述链下设备的会话;executing a first transaction to provide an off-chain device with a pre-opening message of a first session, wherein the first session is a session between the blockchain and the off-chain device;
    执行由所述链下设备发送的第二交易,以向所述链下设备提供所述第一会话的开启消息,所述第二交易中包括对所述预开启消息的确认信息。A second transaction sent by the off-chain device is executed to provide the off-chain device with an opening message of the first session, the second transaction including confirmation information for the pre-opening message.
  2. 根据权利要求1所述的方法,其中,执行第一交易还包括,执行第一交易,以在所述区块链中存入所述第一会话的预开启消息。The method of claim 1, wherein executing the first transaction further comprises executing the first transaction to deposit a pre-opening message for the first session in the blockchain.
  3. 根据权利要求1或2所述的方法,执行第一交易还包括,执行第一交易,以在所述区块链中将所述第一会话的状态记录为预开启状态。According to the method of claim 1 or 2, executing the first transaction further comprises executing the first transaction to record the state of the first session as a pre-open state in the blockchain.
  4. 根据权利要求3所述的方法,其中,所述第一交易中调用第一合约,其中,在所述区块链中将所述第一会话的状态记录为预开启状态包括,在所述第一合约的账户状态中将所述第一会话的状态记录为预开启状态。The method according to claim 3, wherein the first contract is invoked in the first transaction, wherein recording the state of the first session as a pre-opened state in the blockchain comprises: The state of the first session is recorded as a pre-opened state in the account state of a contract.
  5. 根据权利要求4所述的方法,其中,所述第二交易中调用所述第一合约,所述执行由所述链下设备发送的第二交易包括,执行所述第二交易中调用的所述第一合约,使得确定是否在第一预定时段内执行所述第二交易,在确定在第一预定时段内执行所述第二交易的情况中,向链下设备提供第一会话的开启消息。The method of claim 4, wherein the first contract is invoked in the second transaction, and the executing the second transaction sent by the off-chain device comprises executing all the functions invoked in the second transaction. the first contract such that it is determined whether the second transaction is to be executed within a first predetermined period of time, and in the case where it is determined that the second transaction is to be executed within the first predetermined period of time, an opening message of the first session is provided to the off-chain device .
  6. 根据权利要求5所述的方法,其中,执行所述第二交易中调用的所述第一合约还使得,在确定在第一预定时段之后执行所述第二交易的情况中,结束所述第一会话。6. The method of claim 5, wherein executing the first contract invoked in the second transaction further causes, in the event that the second transaction is determined to be executed after a first predetermined period of time, ending the first contract a session.
  7. 根据权利要求1-2、4-6任一项所述的方法,其中,向所述链下设备提供第一会话的开启消息包括,将所述第一会话的状态修改为开启状态。The method according to any one of claims 1-2 and 4-6, wherein providing the off-chain device with an open message of the first session comprises modifying the state of the first session to an open state.
  8. 根据权利要求7所述的方法,其中,向所述链下设备提供第一会话的开启消息包括,在区块链中存入所述第一会话的开启消息。7. The method of claim 7, wherein providing the off-chain device with the start message of the first session comprises storing the start message of the first session in a blockchain.
  9. 根据权利要求8所述的方法,还包括,在向所述链下设备提供第一会话的开启消息之后,执行调用第一合约的第三交易,所述第三交易中包括待处理的第一数据,以使得,确定所述第一会话的状态是否为开启状态,在确定所述第一会话的状态为开启状态的情况中,在区块链中与所述第一会话关联地存入所述第一数据。The method of claim 8, further comprising, after providing the off-chain device with the opening message of the first session, executing a third transaction invoking the first contract, the third transaction including the pending first data, so as to determine whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, it is stored in the blockchain in association with the first session. Describe the first data.
  10. 根据权利要求1所述的方法,还包括:The method of claim 1, further comprising:
    执行由所述链下设备发送的第四交易,所述第四交易中包括预关闭信息,executing a fourth transaction sent by the off-chain device, the fourth transaction including pre-closing information,
    以使得,确定是否接收到由所述链下设备发送的全部消息;so as to determine whether all messages sent by the off-chain device are received;
    在确定接收到由所述链下设备发送的全部消息的情况中,向所述链下设备提供所述 第一会话的关闭消息。In the event that it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
  11. 根据权利要求10所述的方法,其中,向所述链下设备提供所述第一会话的关闭消息包括,将所述第一会话的状态修改为关闭状态。11. The method of claim 10, wherein providing a close message of the first session to the off-chain device comprises modifying the state of the first session to a closed state.
  12. 根据权利要求10所述的方法,其中,执行所述第四交易还使得,在确定未接收到至少部分由所述链下设备发送的消息的情况中,在区块链中与所述第一会话关联地存入请求信息,所述请求信息用于请求所述链下设备重新发送所述至少部分消息。11. The method of claim 10, wherein executing the fourth transaction further causes, in the event of a determination that a message sent at least in part by the off-chain device was not received, communicate with the first transaction in the blockchain Request information is stored in association with the session, and the request information is used to request the off-chain device to resend the at least part of the message.
  13. 根据权利要求12所述的方法,其中,执行所述第四交易还使得,在确定未接收到至少部分由所述链下设备发送的消息的情况中,将所述第一会话的状态修改为预关闭状态。13. The method of claim 12, wherein executing the fourth transaction further causes, in the event that a message sent at least in part by the off-chain device is determined not to be received, modifying the state of the first session to Pre-closed state.
  14. 一种用于区块链与链下设备之间的通信方法,所述方法由链下设备执行,包括:A method for communication between a blockchain and an off-chain device, the method being performed by the off-chain device, comprising:
    从区块链获取第一会话的预开启消息,所述第一会话为所述区块链与所述链下设备的会话;Obtain a pre-opening message of a first session from the blockchain, where the first session is a session between the blockchain and the off-chain device;
    向所述区块链发送第二交易,所述第二交易中包括对所述预开启消息的确认信息;sending a second transaction to the blockchain, where the second transaction includes confirmation information for the pre-opening message;
    开启所述第一会话的数据保留时段。A data retention period for the first session is started.
  15. 根据权利要求14所述的方法,其中,向所述区块链发送第二交易包括,在第一预定时段内向所述区块链发送第二交易。15. The method of claim 14, wherein sending the second transaction to the blockchain comprises sending the second transaction to the blockchain within a first predetermined time period.
  16. 根据权利要求14或15所述的方法,还包括,在开启数据保留时段之后,在第二预定时段内确定是否从所述区块链获取所述第一会话的开启消息,当在第二预定时段内未从所述区块链获取所述第一会话的开启消息的情况中,结束所述数据保留时段。The method according to claim 14 or 15, further comprising, after the data retention period is opened, determining whether to obtain the open message of the first session from the blockchain within a second predetermined period, when the second predetermined period In the case where the opening message of the first session is not obtained from the blockchain within the period, the data retention period is ended.
  17. 根据权利要求14所述的方法,还包括,在符合预设条件时,向所述区块链发送第四交易,所述第四交易包括所述第一会话的预关闭信息。The method of claim 14, further comprising, when a preset condition is met, sending a fourth transaction to the blockchain, the fourth transaction including pre-close information for the first session.
  18. 根据权利要求17所述的方法,还包括,在向所述区块链发送第四交易之后,从所述区块链获取所述第一会话的关闭消息;结束所述数据保留时段。18. The method of claim 17, further comprising, after sending a fourth transaction to the blockchain, obtaining a close message for the first session from the blockchain; ending the data retention period.
  19. 根据权利要求17所述的方法,还包括,在向所述区块链发送第四交易之后,从所述区块链获取对已发送的所述第一会话中的至少部分消息的请求消息;向所述区块链发送第五交易,所述第五交易中包括所述至少部分消息。18. The method of claim 17, further comprising, after sending the fourth transaction to the blockchain, obtaining a request message from the blockchain for at least a portion of the sent messages in the first session; Sending a fifth transaction to the blockchain, the fifth transaction including the at least part of the message.
  20. 一种用于区块链与链下设备之间的通信装置,所述装置部署于区块链节点,包括:A communication device between a blockchain and an off-chain device, the device is deployed on a blockchain node, comprising:
    第一执行单元,配置为,执行第一交易,以向链下设备提供第一会话的预开启消息,其中,所述第一会话为所述区块链与所述链下设备的会话;a first execution unit configured to execute a first transaction to provide an off-chain device with a pre-opening message of a first session, where the first session is a session between the blockchain and the off-chain device;
    第二执行单元,配置为,执行由所述链下设备发送的第二交易,以向所述链下设备 提供所述第一会话的开启消息,所述第二交易中包括对所述预开启消息的确认信息。A second execution unit configured to execute a second transaction sent by the off-chain device to provide the off-chain device with an opening message of the first session, where the second transaction includes the pre-opening message Acknowledgment of the message.
  21. 根据权利要求20所述的装置,其中,所述第一执行单元还配置为,执行第一交易,以在所述区块链中存入所述第一会话的预开启消息。The apparatus of claim 20, wherein the first execution unit is further configured to execute a first transaction to store a pre-opening message of the first session in the blockchain.
  22. 根据权利要求20或21所述的装置,所述第一执行单元还配置为,执行第一交易,以在所述区块链中将所述第一会话的状态记录为预开启状态。The apparatus according to claim 20 or 21, wherein the first execution unit is further configured to execute a first transaction to record the state of the first session as a pre-open state in the blockchain.
  23. 根据权利要求22所述的装置,其中,所述第一交易中调用第一合约,其中,所述第一执行单元还配置为,在所述第一合约的账户状态中将所述第一会话的状态记录为预开启状态。The apparatus of claim 22, wherein a first contract is invoked in the first transaction, wherein the first execution unit is further configured to convert the first session in an account state of the first contract The state is recorded as the pre-open state.
  24. 根据权利要求23所述的装置,其中,所述第二交易中调用所述第一合约,所述第二执行单元还配置为,执行所述第二交易中调用的所述第一合约,使得确定是否在第一预定时段内执行所述第二交易,在确定在第一预定时段内执行所述第二交易的情况中,向链下设备提供第一会话的开启消息。The apparatus of claim 23, wherein the first contract is invoked in the second transaction, and the second execution unit is further configured to execute the first contract invoked in the second transaction, such that It is determined whether to execute the second transaction within a first predetermined period of time, and in the event that the second transaction is determined to be executed within the first predetermined period of time, an open message of the first session is provided to the off-chain device.
  25. 根据权利要求24所述的装置,其中,所述第一执行单元还配置为,在确定在第一预定时段之后执行所述第二交易的情况中,结束所述第一会话。25. The apparatus of claim 24, wherein the first execution unit is further configured to end the first session if the second transaction is determined to be executed after a first predetermined period of time.
  26. 根据权利要求20-21、23-24任一项所述的装置,其中,所述第二执行单元还配置为,将所述第一会话的状态修改为开启状态。The apparatus according to any one of claims 20-21 and 23-24, wherein the second execution unit is further configured to modify the state of the first session to an open state.
  27. 根据权利要求26所述的装置,其中,所述第二执行单元还配置为,在区块链中存入所述第一会话的开启消息。The apparatus of claim 26, wherein the second execution unit is further configured to store an opening message of the first session in the blockchain.
  28. 根据权利要求27所述的装置,还包括,第三执行单元,配置为,在向所述链下设备提供第一会话的开启消息之后,执行调用第一合约的第三交易,所述第三交易中包括待处理的第一数据,以使得,确定所述第一会话的状态是否为开启状态,在确定所述第一会话的状态为开启状态的情况中,在区块链中与所述第一会话关联地存入所述第一数据。The apparatus of claim 27, further comprising a third execution unit configured to execute a third transaction invoking the first contract after providing the off-chain device with an opening message of the first session, the third The transaction includes the first data to be processed, so as to determine whether the state of the first session is an open state, and in the case of determining that the state of the first session is an open state, in the blockchain with the The first session stores the first data in association.
  29. 根据权利要求20所述的装置,还包括:The apparatus of claim 20, further comprising:
    第四执行单元,配置为,执行由所述链下设备发送的第四交易,所述第四交易中包括预关闭信息,a fourth execution unit, configured to execute a fourth transaction sent by the off-chain device, where the fourth transaction includes pre-closing information,
    以使得,确定是否接收到由所述链下设备发送的全部消息;so as to determine whether all messages sent by the off-chain device are received;
    在确定接收到由所述链下设备发送的全部消息的情况中,向所述链下设备提供所述第一会话的关闭消息。In the event that it is determined that all messages sent by the off-chain device are received, a close message of the first session is provided to the off-chain device.
  30. 根据权利要求29所述的装置,其中,所述第四执行单元还配置为,将所述第一会话的状态修改为关闭状态。The apparatus of claim 29, wherein the fourth execution unit is further configured to modify the state of the first session to a closed state.
  31. 根据权利要求29所述的装置,其中,所述第四执行单元还配置为,在确定未接收到至少部分由所述链下设备发送的消息的情况中,在区块链中与所述第一会话关联地存入请求信息,所述请求信息用于请求所述链下设备重新发送所述至少部分消息。29. The apparatus of claim 29, wherein the fourth execution unit is further configured to, in the event of determining that a message sent at least in part by the off-chain device has not been received, communicate with the fourth execution unit in the blockchain The request information is stored in association with a session, and the request information is used to request the off-chain device to resend the at least part of the message.
  32. 根据权利要求31所述的装置,其中,所述第四执行单元还配置为,在确定未接收到至少部分由所述链下设备发送的消息的情况中,将所述第一会话的状态修改为预关闭状态。31. The apparatus of claim 31, wherein the fourth execution unit is further configured to modify the state of the first session if it is determined that a message sent at least in part by the off-chain device has not been received for the pre-closed state.
  33. 一种用于区块链与链下设备之间的通信装置,所述装置部署于链下设备,包括:A communication device between a blockchain and an off-chain device, the device is deployed on the off-chain device, comprising:
    第一获取单元,配置为,从区块链获取第一会话的预开启消息,所述第一会话为所述区块链与所述链下设备的会话;a first obtaining unit, configured to obtain a pre-opening message of a first session from the blockchain, where the first session is a session between the blockchain and the off-chain device;
    第一发送单元,配置为,向所述区块链发送第二交易,所述第二交易中包括对所述预开启消息的确认信息;a first sending unit, configured to send a second transaction to the blockchain, where the second transaction includes confirmation information for the pre-opening message;
    开启单元,配置为,开启所述第一会话的数据保留时段。An enabling unit, configured to enable a data retention period of the first session.
  34. 根据权利要求33所述的装置,其中,所述第一发送单元还配置为,在第一预定时段内向所述区块链发送第二交易。The apparatus of claim 33, wherein the first sending unit is further configured to send a second transaction to the blockchain within a first predetermined period of time.
  35. 根据权利要求33或34所述的装置,还包括,确定单元,配置为,在开启数据保留时段之后,在第二预定时段内确定是否从所述区块链获取所述第一会话的开启消息,第一结束单元,配置为,当在第二预定时段内未从所述区块链获取所述第一会话的开启消息的情况中,结束所述数据保留时段。The apparatus according to claim 33 or 34, further comprising a determination unit configured to, after a data retention period is opened, determine whether to acquire an open message of the first session from the blockchain within a second predetermined period of time , a first end unit configured to end the data retention period when the opening message of the first session is not obtained from the blockchain within a second predetermined period of time.
  36. 根据权利要求33所述的装置,还包括,第二发送单元,配置为,在符合预设条件时,向所述区块链发送第四交易,所述第四交易包括所述第一会话的预关闭信息。The apparatus according to claim 33, further comprising a second sending unit configured to send a fourth transaction to the blockchain when a preset condition is met, the fourth transaction including the first session Pre-close information.
  37. 根据权利要求36所述的装置,还包括,第二获取单元,配置为,在向所述区块链发送第四交易之后,从所述区块链获取所述第一会话的关闭消息;第二结束单元,配置为,结束所述数据保留时段。The apparatus according to claim 36, further comprising a second obtaining unit configured to obtain a closing message of the first session from the blockchain after sending the fourth transaction to the blockchain; and a second end unit, configured to end the data retention period.
  38. 根据权利要求36所述的装置,还包括,第三获取单元,配置为,在向所述区块链发送第四交易之后,从所述区块链获取对已发送的所述第一会话中的至少部分消息的请求消息;第三发送单元,配置为,向所述区块链发送第五交易,所述第五交易中包括所述至少部分消息。The apparatus according to claim 36, further comprising a third obtaining unit configured to, after sending the fourth transaction to the blockchain, obtain, from the blockchain, a link to the first session that has been sent. A request message for at least part of the message; a third sending unit, configured to send a fifth transaction to the blockchain, where the fifth transaction includes the at least part of the message.
  39. 一种计算机可读存储介质,其上存储有计算机程序或指令,当所述计算机程序或指令在计算机中执行时,令计算机执行权利要求1-19中任一项的所述的方法。A computer-readable storage medium on which computer programs or instructions are stored, which, when executed in a computer, cause the computer to perform the method of any one of claims 1-19.
  40. 一种计算设备,包括存储器和处理器,所述存储器中存储有计算机程序或指令,所述处理器在执行所述计算机程序或指令时,实现权利要求1-19中任一项所述的方法。A computing device, comprising a memory and a processor, wherein a computer program or instruction is stored in the memory, and the processor implements the method according to any one of claims 1-19 when executing the computer program or instruction .
PCT/CN2021/133008 2021-03-30 2021-11-25 Method and apparatus for communication between blockchain and off-chain device WO2022205956A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110340111.7A CN112738280B (en) 2021-03-30 2021-03-30 Method and device for communication between block chain and equipment under block chain
CN202110340111.7 2021-03-30

Publications (1)

Publication Number Publication Date
WO2022205956A1 true WO2022205956A1 (en) 2022-10-06

Family

ID=75596143

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/133008 WO2022205956A1 (en) 2021-03-30 2021-11-25 Method and apparatus for communication between blockchain and off-chain device

Country Status (2)

Country Link
CN (2) CN112738280B (en)
WO (1) WO2022205956A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112738280B (en) * 2021-03-30 2021-07-23 支付宝(杭州)信息技术有限公司 Method and device for communication between block chain and equipment under block chain

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109670335A (en) * 2018-12-20 2019-04-23 众安信息技术服务有限公司 For in the method and device interacted between data outside block chain and chain
CN110933125A (en) * 2018-09-19 2020-03-27 英飞凌科技股份有限公司 Block chain entity, down-link entity, authentication device and method for performing collaboration
US20200344042A1 (en) * 2019-04-24 2020-10-29 International Trust Machines Corporation Verification system and method for cooperating with blockchain and off-chain devices
CN112202715A (en) * 2020-08-31 2021-01-08 北京锐格信安技术有限公司 System, method and device for credible interaction between Internet of things and block chain
CN112738280A (en) * 2021-03-30 2021-04-30 支付宝(杭州)信息技术有限公司 Method and device for communication between block chain and equipment under block chain

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110210845B (en) * 2019-06-11 2021-06-18 网易(杭州)网络有限公司 Method, apparatus, medium, and computing device for blockchain data migration
CN110378690B (en) * 2019-06-13 2022-05-27 北京航空航天大学 Transaction method and device based on anonymous secure payment channel
CN111047450A (en) * 2020-03-18 2020-04-21 支付宝(杭州)信息技术有限公司 Method and device for calculating down-link privacy of on-link data

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110933125A (en) * 2018-09-19 2020-03-27 英飞凌科技股份有限公司 Block chain entity, down-link entity, authentication device and method for performing collaboration
CN109670335A (en) * 2018-12-20 2019-04-23 众安信息技术服务有限公司 For in the method and device interacted between data outside block chain and chain
US20200344042A1 (en) * 2019-04-24 2020-10-29 International Trust Machines Corporation Verification system and method for cooperating with blockchain and off-chain devices
CN112202715A (en) * 2020-08-31 2021-01-08 北京锐格信安技术有限公司 System, method and device for credible interaction between Internet of things and block chain
CN112738280A (en) * 2021-03-30 2021-04-30 支付宝(杭州)信息技术有限公司 Method and device for communication between block chain and equipment under block chain

Also Published As

Publication number Publication date
CN112738280A (en) 2021-04-30
CN112738280B (en) 2021-07-23
CN113691633A (en) 2021-11-23

Similar Documents

Publication Publication Date Title
US11848920B2 (en) Manicoding for communication verification
WO2020258846A1 (en) Method and apparatus for sending certifiable messages across chains
WO2020258850A1 (en) Method and apparatus for cross-chain transmission of authenticable message
TW202101440A (en) Cross-blockchain resource transmission
US11422981B2 (en) Information management and access control in a database
WO2021184970A1 (en) Method and device for calling contract
WO2021209052A1 (en) Blockchain-based data processing
CN110009494B (en) Method and device for monitoring transaction content in block chain
WO2019042101A1 (en) Cross-chain trading method and apparatus
TW202101350A (en) Method and device for cross-chain transmission of authenticable message based on processing module
CN110311781A (en) Micro services information is provided
WO2021203853A1 (en) Key generation method, device, apparatus, and medium
CN113114476B (en) Privacy evidence storing method and device based on contract
WO2021184877A1 (en) Node management method for blockchain system, nodes and computing device
CN113364735A (en) Data cross-link access control method, system, equipment and terminal under multi-link scene
WO2022205956A1 (en) Method and apparatus for communication between blockchain and off-chain device
CN111127206B (en) Block chain data access control method and device based on intelligent contract
CN113259456B (en) Cross-chain interaction method and device
WO2022205966A1 (en) Cross-chain access control method and apparatus
WO2020037927A1 (en) Negotiable block chain transaction method, apparatus, device, and storage medium
CN113259460A (en) Cross-chain interaction method and device
WO2022206438A1 (en) Method and apparatus for providing cross-chain message
WO2022206439A1 (en) Method and apparatus for providing cross-chain message
WO2023124746A1 (en) Cross-subnet interaction permission control
CN113923228A (en) Cross-chain interaction method and device

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: 21934592

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21934592

Country of ref document: EP

Kind code of ref document: A1