[go: up one dir, main page]

WO2023279970A1 - Blockchain-based data synchronization method and apparatus - Google Patents

Blockchain-based data synchronization method and apparatus Download PDF

Info

Publication number
WO2023279970A1
WO2023279970A1 PCT/CN2022/100606 CN2022100606W WO2023279970A1 WO 2023279970 A1 WO2023279970 A1 WO 2023279970A1 CN 2022100606 W CN2022100606 W CN 2022100606W WO 2023279970 A1 WO2023279970 A1 WO 2023279970A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
storage attribute
empty
transaction
empty block
Prior art date
Application number
PCT/CN2022/100606
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 WO2023279970A1 publication Critical patent/WO2023279970A1/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
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • 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

Definitions

  • This specification relates to the technical field of blockchain, and in particular to a data synchronization method and device based on blockchain.
  • this specification provides a blockchain-based data synchronization method and device.
  • a blockchain-based data synchronization method applied to a data synchronization system the data synchronization system is connected to a blockchain node, including: reaching the trigger condition for data synchronization , the first storage attribute of each block on the blockchain is obtained from the blockchain node; based on the first storage attribute, it is determined whether each block is a non-empty block, and the The business transaction is added to the synchronization queue, and the non-empty block is a block storing the business transaction; the business transaction in the synchronization queue is synchronized to the business system.
  • a data synchronization device based on blockchain comprising: an acquisition unit, which acquires the first storage attribute of each block on the blockchain from a blockchain node when a trigger condition for data synchronization is reached; a determination unit, based on the first A storage attribute determines whether each block is a non-empty block, and adds the business transaction in the block determined as a non-empty block to the synchronization queue, and the non-empty block is a block that stores a business transaction; the synchronization unit will synchronize The business transactions in the queue are synchronized to the business system.
  • a data synchronization device based on blockchain comprising: a processor; a memory for storing machine-executable instructions; wherein, by reading and executing the machine stored in the memory and corresponding to the logic of data synchronization based on blockchain Executable instructions, the processor is prompted: when the trigger condition of data synchronization is reached, obtain the first storage attribute of each block on the blockchain from the blockchain node; determine whether each block is based on the first storage attribute It is a non-empty block, and the business transaction in the block determined to be a non-empty block is added to the synchronization queue, and the non-empty block is a block storing the business transaction; the business transaction in the synchronization queue is synchronized to the business system.
  • An embodiment of this specification realizes that the data synchronization system can obtain the first storage attribute of each block on the blockchain from the blockchain node when the trigger condition for data synchronization is reached, and determine each block based on the first storage attribute Whether it is a non-empty block, and add the business transactions in the block determined to be a non-empty block to the synchronization queue, and then synchronize the business transactions in the synchronization queue to the business system.
  • Fig. 1 is a schematic flow diagram of a blockchain-based data synchronization method shown in an exemplary embodiment of this specification
  • Fig. 2 is a schematic diagram of a block chain shown in an exemplary embodiment of this specification
  • Fig. 3 is a schematic flow diagram of another blockchain-based data synchronization method shown in an exemplary embodiment of this specification
  • FIG. 4 is a hardware structural diagram of an electronic device where a blockchain-based data synchronization device is shown in an exemplary embodiment of this specification;
  • Fig. 5 is a block diagram of a blockchain-based data synchronization device shown in an exemplary embodiment of this specification.
  • first, second, third, etc. may be used in this specification to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this specification, first information may also be called second information, and similarly, second information may also be called first information. Depending on the context, the word “if” as used herein may be interpreted as “at” or “when” or “in response to a determination.”
  • Blockchain technology also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Due to the characteristics of decentralization, openness and transparency, each computing device can participate in database records, and fast data synchronization between computing devices, blockchain technology has been widely used in many fields. to apply.
  • the remittance business can be realized based on the blockchain, and a business transaction for remittance can be sent to the blockchain node, and the blockchain node can execute the transaction after receiving the transaction to update the balance of the accounts of the remittance parties.
  • the blockchain node can execute the transaction after receiving the transaction to update the balance of the accounts of the remittance parties.
  • the remittance transactions on the blockchain can be synchronized through the data synchronization system, and the synchronized data can be provided to the business system for subsequent business processing.
  • the data on the blockchain is usually synchronized in full, that is, each block on the blockchain is synchronized.
  • each block on the blockchain is synchronized.
  • the method of full synchronization will lead to inefficiency.
  • this specification provides a blockchain-based data synchronization method, which can determine whether each block is an empty block during the data synchronization process, and only perform data synchronization on non-empty blocks. Synchronization can greatly improve the efficiency of data synchronization.
  • FIG. 1 is a schematic flow diagram of a blockchain-based data synchronization method shown in an exemplary embodiment of this specification. The method can be applied to a data synchronization system, and the data synchronization system can specifically have a memory , processor server or server cluster.
  • the data synchronization method based on the block chain may include the following steps: step 102, when the trigger condition of data synchronization is reached, obtain the first storage attribute of each block on the block chain from the block chain node; step 104, based on the The first storage attribute determines whether each block is a non-empty block, and adds the business transaction in the block that is determined to be a non-empty block to the synchronization queue, and the non-empty block is a block that stores a business transaction; Step 106, Synchronize the business transactions in the synchronization queue to the business system.
  • the data synchronization system can be connected to the blockchain node to obtain data from the blockchain node and synchronize it to the business system.
  • the data synchronization system and the business system may be the same system, and there is no special limitation on this.
  • a trigger condition for data synchronization may be preset. For example, data synchronization may be performed periodically, and the period may be preset, such as every day, every week, and so on. Then the trigger condition may be when the data synchronization period is reached. For another example, it may also be determined that the trigger condition for data synchronization is met after receiving the data synchronization request.
  • a data synchronization request can be initiated according to a specific business scenario. For example, when the business system needs to obtain data on the blockchain for business processing, it can send a data synchronization request to the data synchronization system. This embodiment does not make special restrictions on this.
  • the data synchronization system can obtain the first storage attribute of each block on the blockchain from any blockchain node, and determine whether each block is non-empty block.
  • the first storage attribute can be recorded in the world state of the blockchain, which will be described in detail in the following embodiments.
  • a block that does not store a business transaction is determined as an empty block, and a block that stores a business transaction is determined as a non-empty block, wherein the business transaction is data that needs to be synchronized, for example, it can be
  • the remittance transaction can also be other types of transactions, which can be set according to specific application scenarios.
  • there may be various types of transactions stored on the block including business transactions and non-business transactions.
  • blocks without business transactions are considered as empty blocks, but it does not mean that There must not be any transactions stored on the empty block, for example, non-business transactions may be stored.
  • related technologies which is not particularly limited in this embodiment.
  • the business transactions in the blocks determined to be non-empty blocks can be added to the synchronization queue, and the synchronization queue can be stored in the data synchronization system. Then the business transactions stored on the non-empty blocks can be synchronized to the business system based on the synchronization queue.
  • the identification of non-empty blocks can be added to the synchronization queue.
  • the corresponding non-empty blocks can be determined according to these identifications, and then the business transactions stored on the non-empty blocks can be obtained and synchronized to the business system.
  • all business transactions stored on non-empty blocks can also be added to the synchronization queue, then when the business transactions are synchronized to the business system, the business transactions can be obtained from the synchronization queue and synchronized to the business system.
  • the data in the queue can also be cleared.
  • the data synchronization system can obtain the first storage attribute of each block on the blockchain from the blockchain node when the trigger condition for data synchronization is reached, based on The first storage attribute determines whether each block is a non-empty block, and adds the business transactions in the blocks determined to be non-empty blocks to the synchronization queue, and then synchronizes the business transactions in the synchronization queue to the business system.
  • the following describes an embodiment of the method for determining whether each block on the block chain is a non-empty block based on the first storage attribute provided by this specification.
  • the first storage attribute indicates whether the block is a non-empty block
  • each block is a non-empty block based on the first storage attribute of each block, and these Blocks determined to be non-empty blocks are added to the synchronization queue.
  • Fig. 2 exemplarily shows a block chain, there may be several blocks in the block chain, respectively block 1, block 2, ..., block n-4, block n-3, block n-2, block n-1, block n.
  • Block n is the latest block
  • block 1 is the genesis block.
  • block 1 is a non-empty block
  • block 2 is a non-empty block
  • block n-4 is a non-empty block
  • block n-3 is a non-empty block
  • block n-2 is an empty block
  • block n- 1 is an empty block
  • block n is a non-empty block.
  • n the latest block
  • the method judges each block until the creation block (block 1) is judged, and then it can be determined that the blocks included in the synchronization queue are: block n, block n-3, block n-4 , ..., block 2, block 1.
  • the latest block on the blockchain Starting from the latest block on the blockchain, it is judged whether the latest block is a non-empty block according to the first storage attribute corresponding to the latest block.
  • the latest block can be added to the synchronization queue to continue to judge whether the previous block of the latest block is a non-empty block; if the latest block is an empty block, the latest block will not be added synchronization queue, and can determine the non-empty block closest to the block height of the latest block, add the non-empty block to the synchronization queue, and continue to judge whether the previous block of the non-empty block is a non-empty block.
  • the above method can be used to determine each non-empty block on the blockchain, and add these non-empty blocks to the synchronization queue, so as to synchronize the business transactions stored on the non-empty block to the business system based on the synchronization queue.
  • FIG. 2 The example shown in FIG. 2 is still used for illustration.
  • block n the latest block
  • the above method can be used to determine each non-empty block in the blockchain, and add the non-empty block to the synchronization queue.
  • the blocks in the synchronization queue in the above example include: block n, block n-3, block n-4, ..., block 2, block 1.
  • the above method can determine the nearest non-empty block n-3 according to the block n-1, without the need to judge the block n-2, which is equivalent to "skipping" the empty block and improving the efficiency.
  • the non-empty block with the closest block height can be determined by the following method.
  • the following is an example of determining the non-empty block closest to the block height of the latest block.
  • a second storage attribute (world state) may also be stored on the blockchain node, and the second storage attribute represents the non-empty block closest to the block height of the current block. Then, when determining the non-empty block closest to the block height of the latest block, the second storage attribute corresponding to the latest block may be obtained, and the closest non-empty block is determined according to the attribute.
  • the first storage attribute indicates whether the previous block of this block is a non-empty block
  • the previous block of the latest block is a non-empty block according to the first storage attribute corresponding to the latest block.
  • the previous block of the latest block can be added to the synchronization queue, and continue to judge whether the previous block of the previous block is a non-empty block; if the latest block If the previous block of the block is an empty block, then the previous block of the latest block will not be added to the synchronization queue, and continue to judge whether the previous block of the previous block is a non-empty block.
  • the above method can be used to determine each non-empty block on the blockchain, and add these non-empty blocks to the synchronization queue, so as to synchronize the business transactions stored on the non-empty block to the business system based on the synchronization queue.
  • FIG. 2 The example shown in FIG. 2 is still used for illustration.
  • the above method can be used to determine each non-empty block in the blockchain, and add the non-empty block to the synchronization queue.
  • the blocks in the synchronization queue in the above example include: block n, block n-3, block n-4, ..., block 2, block 1.
  • the method for judging whether the block n is an empty block can refer to the foregoing embodiments.
  • the previous block of the latest block can be added to the synchronization queue, and continue to judge whether the previous block of the previous block is a non-empty block; if the latest block If the previous block of the latest block is an empty block, the previous block of the latest block will not be added to the synchronization queue, and the non-empty block closest to the block height of the previous block of the latest block can be determined. Add the non-empty block to the synchronization queue, and continue to judge whether the previous block of the non-empty block is a non-empty block.
  • the above method can be used to determine each non-empty block on the blockchain, and add these non-empty blocks to the synchronization queue, so as to synchronize the business transactions stored on the non-empty block to the business system based on the synchronization queue.
  • the method for determining the non-empty block closest to the block height of the previous block of the latest block can refer to the foregoing embodiments.
  • whether it is a non-empty block can be determined according to the method in the foregoing examples, which will not be repeated in this embodiment.
  • FIG. 2 The example shown in FIG. 2 is still used for illustration.
  • the above method can be used to determine each non-empty block in the blockchain, and add the non-empty block to the synchronization queue.
  • the blocks in the synchronization queue in the above example include: block n, block n-3, block n-4, ..., block 2, block 1.
  • the method for judging whether the block n is an empty block can refer to the foregoing embodiments.
  • the non-empty block closest to the block height of the block can also be determined , and then directly add the non-empty block (the business transaction stored on it) to the synchronization queue without processing the empty block contained between the two blocks, which is equivalent to directly "skipping" the empty block, Can greatly improve the efficiency of data synchronization.
  • the first storage attribute and the second storage attribute corresponding to each block can be added to the world state of the block chain, so as to determine whether each block is an empty block and the non-empty block with the closest block height based on these attributes. piece.
  • the recording process of these two attributes will be described first below.
  • the first storage attribute corresponding to each block can be set in the world state of the blockchain.
  • the first storage attribute indicates whether the block is an empty block. For example, see Figure 2, when the attribute value is "1" When , it indicates that this block is a non-empty block, and when the attribute value is "0", it indicates that this block is an empty block.
  • the first attribute can be generated in the following manner.
  • a blockchain node may receive a business transaction, and the business transaction may be initiated by a user or a blockchain platform, and there is no special limitation on this. After the blockchain node receives the business transaction, it can reach a consensus on the business transaction. After the consensus is completed, the business transaction will be stored in the corresponding block, and then the business transaction can be executed. When executing the business transaction, on the one hand, business-related operations (such as changing the balance of the remittance parties' accounts) can be performed, and on the other hand, related operations on the first attribute record can also be performed.
  • business-related operations such as changing the balance of the remittance parties' accounts
  • the first attribute record logic in the smart contract can be called to record the first storage attribute indicating that the block in which the business transaction is located is a non-empty block.
  • the business transaction can be executed to record the first storage attribute corresponding to block n, and the attribute value is set to "1" .
  • the block chain may not store business transactions, so it is impossible to record the first storage attribute corresponding to the blocks by executing business transactions. Then, when determining whether each block is a non-empty block based on the first storage attribute, the block whose corresponding first storage attribute cannot be obtained may be determined as an empty block.
  • the blockchain node may also receive the first storage attribute record transaction.
  • the first storage attribute record transaction may be initiated by, for example, the blockchain platform or other parties, and there is no special limitation on this.
  • the blockchain node After the blockchain node receives the first storage attribute record transaction, it can reach a consensus on the first storage attribute record transaction. After the consensus is completed, the first storage attribute record transaction can be stored in the corresponding block, and then the transaction can be executed.
  • the first storage attribute records the transaction to call the first storage attribute recording logic in the smart contract to determine whether the block where the first storage attribute generates the transaction stores a business transaction, and if so, determines that the block is a non-empty block; If not, it is determined that the block is an empty block. Then, the first storage attribute corresponding to the block may be recorded according to the judgment result.
  • the first storage attribute record transaction may be sent periodically, and the sending cycle may be the same as the block forming cycle on the blockchain.
  • the sending cycle of the first storage attribute record transaction can also be every second.
  • the first storage attribute record transaction can be stored in each block, so as to record the first storage attribute based on the transaction.
  • the above example solves the problem that the business transaction cannot be executed to record the first storage attribute corresponding to the block because there is no business transaction stored in the block.
  • a business transaction can be executed to record the first storage attribute
  • a first storage attribute recording transaction can be executed to record the first storage attribute.
  • the block stores both the business transaction and the first storage attribute record transaction
  • the result obtained from the later execution of the transaction can be used to overwrite the result of the previous execution of the transaction.
  • other methods can also be adopted. This embodiment There are no particular restrictions on this.
  • the first storage attribute can also represent whether the previous block of this block is an empty block, for example, when the attribute value is "1", it indicates that the previous block of this block is a non-empty block, and the attribute When the value is "0", it indicates that the previous block of this block is an empty block.
  • the first storage attribute may be recorded in the following manner.
  • a blockchain node may receive a business transaction, and execute the business transaction to call the first storage attribute record logic in the smart contract to determine whether the business transaction is stored in the previous block of the block where the business transaction is located , and record the first storage attribute of the block where the business transaction is located based on the judgment result.
  • the block preceding the block for which the corresponding first storage attribute cannot be obtained may be determined as an empty block.
  • the blockchain node may also receive the first storage attribute record transaction. Similarly, there is no special restriction on the initiator of the first storage attribute record transaction. After the blockchain node receives the first storage attribute record transaction, it can reach a consensus on the first storage attribute record transaction. After the consensus is completed, the first storage attribute record transaction can be stored in the corresponding block, and then the transaction can be executed. The first storage attribute record transaction is used to call the third storage attribute record logic in the smart contract to judge whether the previous block of the block where the first storage attribute record transaction is located has business transactions stored, and if so, determine the previous block The block is a non-empty block; if not, it is determined that the previous block is an empty block. Then, the first storage attribute corresponding to the block may be recorded according to the judgment result.
  • the first storage attribute record transaction can be sent periodically, and the sending cycle can also be the same as the block forming cycle on the blockchain.
  • the second storage attribute may represent a non-empty block whose block height is closest to the current block.
  • a blockchain node may receive a business transaction, and execute the business transaction to call the second storage attribute recording logic in the smart contract to determine the non-block height closest to the block where the business transaction is located.
  • the blockchain node may also receive the second storage attribute record transaction. Similarly, there is no special restriction on the initiator of the second storage attribute record transaction. After the blockchain node receives the second storage attribute record transaction, it can reach a consensus on the second storage attribute record transaction. After the consensus is completed, the second storage attribute record transaction can be stored in the corresponding block, and then the transaction can be executed. The second storage attribute record transaction is used to call the second storage attribute generation logic in the smart contract to determine the non-empty block closest to the block height of the block where the second storage attribute record transaction is located, and record according to the non-empty block The second storage attribute records the second storage attribute corresponding to the block where the transaction is located.
  • the second storage attribute record transaction can be sent periodically, and the sending cycle can also be the same as the block forming cycle on the blockchain.
  • FIG. 3 is a schematic flowchart of another blockchain-based data synchronization method shown in an exemplary embodiment of this specification. The method may include the following steps:
  • Step 302 determine whether a trigger condition for data synchronization is met. If yes, execute step 304 .
  • the method for determining whether a trigger condition for data synchronization is met may refer to the foregoing embodiments, and details are not repeated here.
  • Step 304 Obtain the first storage attribute corresponding to the latest block from the blockchain node, and determine whether the latest block is a non-empty block based on the first storage attribute. If not, execute steps 306-308; if yes, execute step 310.
  • Step 306 Obtain the second storage attribute corresponding to the latest block from the blockchain node, and determine the non-empty block closest to the block height of the latest block based on the second storage attribute.
  • Step 308 adding the non-empty block to the synchronization queue, and determining whether the previous block is a non-empty block based on the first storage attribute corresponding to the previous block of the non-empty block.
  • processing can be started from the latest block on the blockchain node to determine whether the latest block is a non-empty block.
  • the first storage attribute corresponding to the latest block can be obtained from the blockchain node, and the first storage attribute can indicate whether the block is a non-empty block.
  • the non-empty block is determined based on the first storage attribute.
  • the method of obtaining the first attribute (world state) from the blockchain can refer to related technologies, and this embodiment will not describe them one by one here.
  • the second storage attribute corresponding to the latest block can be obtained from the blockchain node.
  • the second storage attribute may characterize the closest non-empty block to the block height of the block.
  • a non-empty block may be determined according to the second storage attribute, and the non-empty block is added to the synchronization queue.
  • the first storage attribute corresponding to the previous empty block can be obtained from the blockchain node to determine whether it is a non-empty block, and if it is a non-empty block, add it to the synchronization queue; if it is an empty block Get the non-empty block with the closest block height and add it to the synchronization queue. and so on.
  • Step 310 adding the latest block into the synchronization queue, and determining whether the previous block of the latest block is a non-empty block based on the first storage attribute corresponding to the previous block of the latest block.
  • the latest empty block can be added to the synchronization queue. And judge whether the previous block of the latest empty block is a non-empty block, for example, the first storage attribute corresponding to the previous empty block can be obtained to determine whether it is a non-empty block, and if it is a non-empty block, upload it
  • the stored business transaction is added to the synchronization queue, and in the case of an empty block, the non-empty block with the closest block height is obtained, and the business transaction stored on the non-empty block is added to the synchronization queue. and so on.
  • Step 312 after determining each non-empty block in the blockchain, synchronize the data on each block in the synchronization queue.
  • each non-empty block in the blockchain can be determined by using the method of the foregoing steps, and the business transactions in these non-empty blocks can be added to the synchronization queue. Then perform data synchronization on the business transactions stored on each block in the synchronization queue.
  • data synchronization on the blockchain can also be performed in batches.
  • a sliding window that can contain a specified number of blocks can be preset.
  • the size of the sliding window is 10 blocks or 5 blocks. synchronization.
  • the sliding window can be used to determine block n-block n-3, block n-4 ⁇ block n-7, ... ..., and then perform data synchronization processing for each sliding window.
  • block n is an empty block, and if it is not empty, add block n to the synchronization queue, and then continue to judge block n -1 Whether it is an empty block, if it is found to be an empty block, it will not be added to the synchronization queue, and the nearest non-empty block is determined to be block n-3, then block n-3 will be added to the synchronization queue. And block n-3 is the last block in the sliding window, it can be determined that the processing of the sliding window is completed, and data synchronization can be performed on the synchronization queue corresponding to the sliding window.
  • each sliding window can be processed in parallel or serially, which can be set according to actual business scenarios.
  • this specification also provides embodiments of a blockchain-based data synchronization device.
  • the embodiment of the blockchain-based data synchronization device in this specification can be applied to electronic equipment.
  • the device embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the processor of the electronic device where it is located.
  • FIG 4 it is a hardware structure diagram of the electronic device where the blockchain-based data synchronization device in this manual is located, except for the processor, memory, network interface, and non-volatile memory shown in Figure 4
  • the electronic device where the device in the embodiment is located usually may also include other hardware according to the actual function of the electronic device, which will not be repeated here.
  • Fig. 5 is a block diagram of a blockchain-based data synchronization device shown in an exemplary embodiment of this specification.
  • the block chain-based data synchronization device can be applied in the aforementioned electronic device shown in FIG. 4 , including: an acquisition unit 510 , a determination unit 520 and a synchronization unit 530 .
  • the acquisition unit 510 when the trigger condition of data synchronization is reached, acquires the first storage attribute of each block on the blockchain from the blockchain node; the determination unit 520 determines whether each block is non-empty block, and add the business transaction in the block that is determined as the non-empty block to the synchronization queue, and the non-empty block is a block that stores the business transaction; the synchronization unit 530 synchronizes the business transaction in the synchronization queue to the business system.
  • the first storage attribute indicates whether the current block is a non-empty block
  • the determining unit 520 determines whether each block is a non-empty block based on the first storage attribute: starting from the latest block, According to the sequence of block heights from high to low, it is sequentially judged whether each block is a non-empty block based on the first storage attribute of each block.
  • the first storage attribute indicates whether the current block is a non-empty block
  • the determining unit 520 determines whether each block is a non-empty block based on the first storage attribute: based on the latest block corresponding
  • the first storage attribute judges whether the latest block is a non-empty block; if the latest block is a non-empty block, then judge whether the previous block of the latest block is a non-empty block; if the latest block block is an empty block, then determine the non-empty block closest to the block height of the latest block, and judge whether the previous block of the non-empty block is a non-empty block.
  • the recording process of the first storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the first storage attribute record logic record in the smart contract to represent the business exchange
  • the block is the first storage attribute of a non-empty block.
  • the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract
  • a storage attribute record logic judges whether a business transaction is stored on the block of the first storage attribute record transaction, and records the first storage attribute corresponding to the block where the first storage attribute record transaction is located based on the judgment result.
  • the second storage attribute corresponding to each block is stored on the block chain node, and the second storage attribute represents the non-empty block closest to the block height of the block, and the determining unit 520 When determining the non-empty block closest to the block height of the latest block: obtaining the second storage attribute corresponding to the latest block from the blockchain node; The block whose block height is closest to the non-empty block.
  • the recording process of the second storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the second storage attribute recording logic in the smart contract to determine the business transaction In the non-empty block closest to the block height of the block, and based on the non-empty block, record the second storage attribute corresponding to the block where the business transaction is located.
  • the recording process of the second storage attribute includes: after the block chain node receives the second storage attribute record transaction sent periodically, execute the second storage attribute record transaction to call the first storage attribute record transaction in the smart contract
  • the second storage attribute recording logic determines the non-empty block closest to the block height of the block where the second storage attribute update transaction is located, and records the block where the second storage attribute update transaction resides based on the non-empty block The corresponding second storage attribute.
  • the first storage attribute indicates whether the previous block of this block is an empty block
  • the determining unit 520 determines whether each block is a non-empty block based on the first storage attribute: for all The latest block, based on the first storage attribute to determine whether the previous block of the latest block is a non-empty block; if the previous block is a non-empty block, then based on the previous block corresponding
  • the first storage attribute judges whether the previous block of the previous block is a non-empty block; if the previous block is an empty block, then determine the block height closest to the previous block a non-empty block, and judge whether the previous block of the non-empty block is an empty block based on the first storage attribute corresponding to the non-empty block.
  • the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract Three storage attribute record logic judges whether the previous block of the first storage attribute record transaction stores business transactions, and generates the first storage attribute record transaction corresponding to the first block based on the judgment result. store attributes.
  • the trigger condition for data synchronization includes: after receiving a data synchronization request; and/or reaching a data synchronization period.
  • the device embodiment since it basically corresponds to the method embodiment, for related parts, please refer to the part description of the method embodiment.
  • the device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network elements. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution in this specification. It can be understood and implemented by those skilled in the art without creative effort.
  • a typical implementing device is a computer, which may take the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, e-mail device, game control device, etc. desktops, tablets, wearables, or any combination of these.
  • this specification also provides a blockchain-based data synchronization device, which includes: a processor and a memory for storing machine-executable instructions.
  • the processor and the memory are usually connected to each other by an internal bus.
  • the device may further include an external interface, so as to be able to communicate with other devices or components.
  • the processor is prompted to: a blockchain-based data synchronization method, Applied to a data synchronization system, the data synchronization system is docked with a block chain node, and the method includes: when a trigger condition for data synchronization is reached, obtaining the first storage attribute of each block on the block chain from the block chain node; Determine whether each block is a non-empty block based on the first storage attribute, and add the business transaction in the block that is determined to be a non-empty block to the synchronization queue, and the non-empty block is a block that stores a business transaction; The business transactions in the synchronization queue are synchronized to the business system.
  • the first storage attribute indicates whether the current block is a non-empty block, and when determining whether each block is a non-empty block based on the first storage attribute, the processor is prompted to: start from the latest block At first, according to the order of block height from high to low, it is judged whether each block is a non-empty block based on the first storage attribute of each block.
  • the first storage attribute indicates whether the current block is a non-empty block, and when determining whether each block is a non-empty block based on the first storage attribute, the processor is prompted: based on the latest block
  • the corresponding first storage attribute judges whether the latest block is a non-empty block; if the latest block is a non-empty block, then judges whether the previous block of the latest block is a non-empty block; if the If the latest block is an empty block, determine the non-empty block closest to the block height of the latest block, and determine whether the previous block of the non-empty block is a non-empty block.
  • the processor is prompted: after the blockchain node receives the business transaction, execute the business transaction to call the first storage attribute in the smart contract to record the logical record representation
  • the block in which the business transaction is located is the first storage attribute of a non-empty block.
  • the processor is prompted: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call
  • the logic of the first storage attribute record in the smart contract judges whether there is a business transaction stored in the block of the first storage attribute record exchange, and records the first storage attribute record transaction corresponding to the block based on the judgment result.
  • a stored attribute A stored attribute.
  • the second storage attribute corresponding to each block is stored on the block chain node, and the second storage attribute represents the non-empty block closest to the block height of this block.
  • the processor is prompted to: obtain the second storage attribute corresponding to the latest block from the blockchain node; The non-empty block closest to the block height of the latest block.
  • the processor is prompted: after the blockchain node receives the business transaction, executes the business transaction to call the second storage attribute recording logic in the smart contract to determine and The non-empty block with the closest block height of the block where the business transaction is located, and record the second storage attribute corresponding to the block where the business transaction is located based on the non-empty block.
  • the processor is prompted: after the blockchain node receives the periodically sent second storage attribute record transaction, executes the second storage attribute record transaction to call
  • the second storage attribute recording logic in the smart contract determines the non-empty block closest to the block height of the block where the second storage attribute update transaction is located, and records the second storage attribute update based on the non-empty block The second storage attribute corresponding to the block where the transaction is located.
  • the first storage attribute indicates whether the previous block of the current block is an empty block, and when determining whether each block is a non-empty block based on the first storage attribute, the processor is prompted to: For the latest block, determine whether the previous block of the latest block is a non-empty block based on the first storage attribute; if the previous block is a non-empty block, then based on the previous block The first storage attribute corresponding to the block judges whether the previous block of the previous block is a non-empty block; if the previous block is an empty block, then determine the block height closest to the previous block a non-empty block that is close to it, and judge whether the previous block of the non-empty block is an empty block based on the first storage attribute corresponding to the non-empty block.
  • the processor is prompted: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call
  • the third storage attribute record logic in the smart contract judges whether the previous block of the first storage attribute record transaction stores business transactions, and generates the first storage attribute record transaction area based on the judgment result The first storage attribute corresponding to the block.
  • the trigger condition for data synchronization includes: after receiving a data synchronization request; and/or reaching a data synchronization period.
  • this specification also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the following is achieved: Steps: a blockchain-based data synchronization method applied to a data synchronization system, the data synchronization system is connected to a blockchain node, and the method includes: when a trigger condition for data synchronization is reached, the data is obtained from the blockchain node The first storage attribute of each block on the block chain; determine whether each block is a non-empty block based on the first storage attribute, and add the business transaction in the block determined to be a non-empty block to the synchronization queue, the Non-empty blocks are blocks that store business transactions; synchronize the business transactions in the synchronization queue to the business system.
  • the first storage attribute indicates whether the block is a non-empty block
  • determining whether each block is a non-empty block based on the first storage attribute includes: starting from the latest block, according to the block In order of height from high to low, it is determined whether each block is a non-empty block based on the first storage attribute of each block.
  • the first storage attribute indicates whether the current block is a non-empty block
  • determining whether each block is a non-empty block based on the first storage attribute includes: based on the first storage corresponding to the latest block attribute to determine whether the latest block is a non-empty block; if the latest block is a non-empty block, then judge whether the previous block of the latest block is a non-empty block; if the latest block is empty block, then determine the non-empty block closest to the block height of the latest block, and judge whether the previous block of the non-empty block is a non-empty block.
  • the recording process of the first storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the first storage attribute record logic record in the smart contract to represent the business exchange
  • the block is the first storage attribute of a non-empty block.
  • the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract
  • a storage attribute record logic judges whether a business transaction is stored on the block of the first storage attribute record transaction, and records the first storage attribute corresponding to the block where the first storage attribute record transaction is located based on the judgment result.
  • the second storage attribute corresponding to each block is stored on the block chain node, the second storage attribute represents the non-empty block closest to the block height of the block, and the determination is related to the The non-empty block whose block height is closest to the latest block includes: obtaining the second storage attribute corresponding to the latest block from the blockchain node; determining the relationship between the latest block and the latest block based on the second storage attribute The closest non-empty block to the block height.
  • the recording process of the second storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the second storage attribute recording logic in the smart contract to determine the business transaction In the non-empty block closest to the block height of the block, and based on the non-empty block, record the second storage attribute corresponding to the block where the business transaction is located.
  • the recording process of the second storage attribute includes: after the block chain node receives the second storage attribute record transaction sent periodically, execute the second storage attribute record transaction to call the first storage attribute record transaction in the smart contract
  • the second storage attribute recording logic determines the non-empty block closest to the block height of the block where the second storage attribute update transaction is located, and records the block where the second storage attribute update transaction resides based on the non-empty block The corresponding second storage attribute.
  • the first storage attribute indicates whether the previous block of this block is an empty block
  • the determining whether each block is a non-empty block based on the first storage attribute includes: for the latest block block, based on the first storage attribute to determine whether the previous block of the latest block is a non-empty block; if the previous block is a non-empty block, based on the first block corresponding to the previous block
  • the storage attribute judges whether the previous block of the previous block is a non-empty block; if the previous block is an empty block, then determine the non-empty block closest to the block height of the previous block , and judge whether the previous block of the non-empty block is an empty block based on the first storage attribute corresponding to the non-empty block.
  • the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract Three storage attribute record logic judges whether the previous block of the first storage attribute record transaction stores business transactions, and generates the first storage attribute record transaction corresponding to the first block based on the judgment result. store attributes.
  • the trigger condition for data synchronization includes: after receiving a data synchronization request; and/or reaching a data synchronization period.

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Theoretical Computer Science (AREA)
  • Finance (AREA)
  • Databases & Information Systems (AREA)
  • Accounting & Taxation (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Signal Processing (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A blockchain-based data synchronization method, applied to a data synchronization system, wherein the data synchronization system interfaces with a blockchain node. The method comprises: when a trigger condition for data synchronization is reached, obtaining a first storage attribute of each block on a blockchain from the blockchain node; determining, on the basis of the first storage attribute, whether each block is a non-empty block, and add a service transaction in a block that is determined to be a non-empty block to a synchronization queue, the non-empty block is a block in which a service transaction is stored; and synchronizing the service transaction in the synchronization queue to a service system.

Description

基于区块链的数据同步的方法和装置Method and device for data synchronization based on block chain 技术领域technical field
本说明书涉及区块链技术领域,特别涉及一种基于区块链的数据同步方法和装置。This specification relates to the technical field of blockchain, and in particular to a data synchronization method and device based on blockchain.
背景技术Background technique
随着区块链技术的不断发展,区块链技术被应用于越来越多的领域。相关技术中,存在将区块链链上的数据同步至链下以进行相关业务处理的需求,基于此,如何提高区块链上数据同步的速度、提升效率,成为业内关注的重点。With the continuous development of blockchain technology, blockchain technology has been applied in more and more fields. In related technologies, there is a need to synchronize data on the blockchain to off-chain for related business processing. Based on this, how to improve the speed and efficiency of data synchronization on the blockchain has become the focus of the industry.
发明内容Contents of the invention
有鉴于此,本说明书提供一种基于区块链的数据同步方法和装置。In view of this, this specification provides a blockchain-based data synchronization method and device.
具体地,本说明书是通过如下技术方案实现的:一种基于区块链的数据同步方法,应用于数据同步系统,所述数据同步系统与区块链节点对接,包括:达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;将同步队列内的业务交易同步至业务系统。Specifically, this specification is realized through the following technical solution: a blockchain-based data synchronization method applied to a data synchronization system, the data synchronization system is connected to a blockchain node, including: reaching the trigger condition for data synchronization , the first storage attribute of each block on the blockchain is obtained from the blockchain node; based on the first storage attribute, it is determined whether each block is a non-empty block, and the The business transaction is added to the synchronization queue, and the non-empty block is a block storing the business transaction; the business transaction in the synchronization queue is synchronized to the business system.
一种基于区块链的数据同步装置,包括:获取单元,达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;确定单元,基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;同步单元,将同步队列内的业务交易同步至业务系统。A data synchronization device based on blockchain, comprising: an acquisition unit, which acquires the first storage attribute of each block on the blockchain from a blockchain node when a trigger condition for data synchronization is reached; a determination unit, based on the first A storage attribute determines whether each block is a non-empty block, and adds the business transaction in the block determined as a non-empty block to the synchronization queue, and the non-empty block is a block that stores a business transaction; the synchronization unit will synchronize The business transactions in the queue are synchronized to the business system.
一种基于区块链的数据同步装置,包括:处理器;用于存储机器可执行指令的存储器;其中,通过读取并执行所述存储器存储的与基于区块链的数据同步逻辑对应的机器可执行指令,所述处理器被促使:达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;将同步队列内的业务交易同步至业务系统。A data synchronization device based on blockchain, comprising: a processor; a memory for storing machine-executable instructions; wherein, by reading and executing the machine stored in the memory and corresponding to the logic of data synchronization based on blockchain Executable instructions, the processor is prompted: when the trigger condition of data synchronization is reached, obtain the first storage attribute of each block on the blockchain from the blockchain node; determine whether each block is based on the first storage attribute It is a non-empty block, and the business transaction in the block determined to be a non-empty block is added to the synchronization queue, and the non-empty block is a block storing the business transaction; the business transaction in the synchronization queue is synchronized to the business system.
本说明书一个实施例实现了,数据同步系统可以在达到数据同步的触发条件时,从区块链节点上获取区块链上各个区块的第一存储属性,基于第一存储属性确定各个区块 是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,然后将同步队列内的业务交易同步给业务系统。An embodiment of this specification realizes that the data synchronization system can obtain the first storage attribute of each block on the blockchain from the blockchain node when the trigger condition for data synchronization is reached, and determine each block based on the first storage attribute Whether it is a non-empty block, and add the business transactions in the block determined to be a non-empty block to the synchronization queue, and then synchronize the business transactions in the synchronization queue to the business system.
采用上述方法,在对区块链上的数据进行同步时,可以确定出包含业务交易的非空块,仅对这些非空块进行数据同步,避免了对不包含业务交易的空块进行数据同步,相比于相关技术中对区块链上所有区块进行全量同步来说,可以大大提高数据同步效率。Using the above method, when synchronizing data on the blockchain, it is possible to determine non-empty blocks containing business transactions, and only perform data synchronization on these non-empty blocks, avoiding data synchronization on empty blocks that do not contain business transactions , compared to the full synchronization of all blocks on the blockchain in related technologies, the efficiency of data synchronization can be greatly improved.
附图说明Description of drawings
图1是本说明书一示例性实施例示出的一种基于区块链的数据同步方法的流程示意图;Fig. 1 is a schematic flow diagram of a blockchain-based data synchronization method shown in an exemplary embodiment of this specification;
图2是本说明书一示例性实施例示出的一种区块链的示意图;Fig. 2 is a schematic diagram of a block chain shown in an exemplary embodiment of this specification;
图3是本说明书一示例性实施例示出的另一种基于区块链的数据同步方法的流程示意图;Fig. 3 is a schematic flow diagram of another blockchain-based data synchronization method shown in an exemplary embodiment of this specification;
图4是本说明书一示例性实施例示出的一种基于区块链的数据同步装置所在电子设备的一种硬件结构图;FIG. 4 is a hardware structural diagram of an electronic device where a blockchain-based data synchronization device is shown in an exemplary embodiment of this specification;
图5是本说明书一示例性实施例示出的一种基于区块链的数据同步装置的框图。Fig. 5 is a block diagram of a blockchain-based data synchronization device shown in an exemplary embodiment of this specification.
具体实施方式detailed description
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书的一些方面相一致的装置和方法的例子。Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with this specification. Rather, they are merely examples of apparatuses and methods consistent with aspects of the present specification as recited in the appended claims.
在本说明书使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书。在本说明书和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。The terms used in this specification are for the purpose of describing particular embodiments only, and are not intended to limit the specification. As used in this specification and the appended claims, the singular forms "a", "the", and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It should also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
应当理解,尽管在本说明书可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在…… 时”或“当……时”或“响应于确定”。It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this specification, first information may also be called second information, and similarly, second information may also be called first information. Depending on the context, the word "if" as used herein may be interpreted as "at" or "when" or "in response to a determination."
区块链技术,也被称之为分布式账本技术,是一种由若干台计算设备共同参与“记账”,共同维护一份完整的分布式数据库的新兴技术。由于区块链技术具有去中心化、公开透明、每台计算设备可以参与数据库记录、并且各计算设备之间可以快速的进行数据同步的特性,使得区块链技术已在众多的领域中广泛的进行应用。Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Due to the characteristics of decentralization, openness and transparency, each computing device can participate in database records, and fast data synchronization between computing devices, blockchain technology has been widely used in many fields. to apply.
在实际的应用场景中,存在将区块链链上的数据同步至链下以进行相关业务处理的需求。举例来说,可以基于区块链实现汇款业务,可以向区块链节点发送用于实现汇款的业务交易,区块链节点接收到该交易后可以执行交易以更新汇款双方账户的余额。并且,基于区块链不易被篡改、一致性的特点可以确保汇款交易是安全、可靠的。在这一场景中,可以通过数据同步系统对区块链上的汇款交易进行同步,并将同步得到的数据提供给业务系统进行后续的业务处理。In actual application scenarios, there is a need to synchronize data on the blockchain to off-chain for related business processing. For example, the remittance business can be realized based on the blockchain, and a business transaction for remittance can be sent to the blockchain node, and the blockchain node can execute the transaction after receiving the transaction to update the balance of the accounts of the remittance parties. Moreover, based on the characteristics of the block chain, which is not easy to be tampered with and consistent, it can ensure that the remittance transaction is safe and reliable. In this scenario, the remittance transactions on the blockchain can be synchronized through the data synchronization system, and the synchronized data can be provided to the business system for subsequent business processing.
相关技术中,对区块链上的数据进行同步时通常是全量同步的,即对区块链上的每个区块均进行同步,然而,由于区块链上存储的数据量较大,且并非每个区块上都存储有需要同步的数据,全量同步的方法会导致效率低下。In related technologies, the data on the blockchain is usually synchronized in full, that is, each block on the blockchain is synchronized. However, due to the large amount of data stored on the blockchain, and Not every block stores the data that needs to be synchronized, and the method of full synchronization will lead to inefficiency.
基于此,本说明书提供了一种基于区块链的数据同步方法,可以在数据同步的过程中判断各个区块是否为空块,并仅对非空的区块进行数据同步,相比于全量同步来说可以大大提高数据同步效率。Based on this, this specification provides a blockchain-based data synchronization method, which can determine whether each block is an empty block during the data synchronization process, and only perform data synchronization on non-empty blocks. Synchronization can greatly improve the efficiency of data synchronization.
请参见图1,图1是本说明书一示例性实施例示出的一种基于区块链的数据同步方法的流程示意图,所述方法可以应用于数据同步系统,该数据同步系统具体可以是具有存储器、处理器的服务器或服务器集群。Please refer to FIG. 1. FIG. 1 is a schematic flow diagram of a blockchain-based data synchronization method shown in an exemplary embodiment of this specification. The method can be applied to a data synchronization system, and the data synchronization system can specifically have a memory , processor server or server cluster.
所述基于区块链的数据同步方法可以包括以下步骤:步骤102,达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;步骤104,基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;步骤106,将同步队列内的业务交易同步至业务系统。The data synchronization method based on the block chain may include the following steps: step 102, when the trigger condition of data synchronization is reached, obtain the first storage attribute of each block on the block chain from the block chain node; step 104, based on the The first storage attribute determines whether each block is a non-empty block, and adds the business transaction in the block that is determined to be a non-empty block to the synchronization queue, and the non-empty block is a block that stores a business transaction; Step 106, Synchronize the business transactions in the synchronization queue to the business system.
下面对上述步骤进行详细说明。The above steps will be described in detail below.
本实施例中,数据同步系统可以与区块链节点对接,以从区块链节点上获取数据并将其同步给业务系统。当然,在其他实施例中,数据同步系统可以和业务系统是同一个系统,对此不作特殊限制。In this embodiment, the data synchronization system can be connected to the blockchain node to obtain data from the blockchain node and synchronize it to the business system. Of course, in other embodiments, the data synchronization system and the business system may be the same system, and there is no special limitation on this.
本实施例中,可以预先设有数据同步的触发条件。比如,可以是周期性进行数据同步,该周期可以预设,如每天、每星期等。则触发条件可以为达到数据同步周期时。再比如,也可以是接收到数据同步请求后确定达到了数据同步的触发条件。可以根据具体的业务场景来发起数据同步请求,比如业务系统需要获取区块链上的数据以进行业务处理时可以向数据同步系统发送数据同步请求,本实施例对此不作特殊限制。In this embodiment, a trigger condition for data synchronization may be preset. For example, data synchronization may be performed periodically, and the period may be preset, such as every day, every week, and so on. Then the trigger condition may be when the data synchronization period is reached. For another example, it may also be determined that the trigger condition for data synchronization is met after receiving the data synchronization request. A data synchronization request can be initiated according to a specific business scenario. For example, when the business system needs to obtain data on the blockchain for business processing, it can send a data synchronization request to the data synchronization system. This embodiment does not make special restrictions on this.
本实施例中,当达到数据同步的触发条件时,数据同步系统可以从任一区块链节点获取区块链上各个区块的第一存储属性,基于第一存储属性确定各个区块是否为非空块。其中,第一存储属性可以记录在区块链的世界状态中,具体将会在后面的实施例中详细说明。In this embodiment, when the trigger condition for data synchronization is reached, the data synchronization system can obtain the first storage attribute of each block on the blockchain from any blockchain node, and determine whether each block is non-empty block. Among them, the first storage attribute can be recorded in the world state of the blockchain, which will be described in detail in the following embodiments.
本实施例中,将不存储有业务交易的区块确定为空块、将存储有业务交易的区块确定为非空块,其中,业务交易为需要进行同步的数据,比如可以是前述例子中的汇款交易,也可以是其他类型的交易,可根据具体的应用场景设置。并且,值得说明的是,区块上可能会存储有多种类型的交易,包括业务交易、非业务交易,本实施例将不存储有业务交易的区块认为是空块,但并不意味着空块上一定不存储有任何交易,比如可能会存储有非业务交易。区分业务交易、非业务交易的方法可以参照相关技术,本实施例对此不作特殊限制。In this embodiment, a block that does not store a business transaction is determined as an empty block, and a block that stores a business transaction is determined as a non-empty block, wherein the business transaction is data that needs to be synchronized, for example, it can be The remittance transaction can also be other types of transactions, which can be set according to specific application scenarios. Moreover, it is worth noting that there may be various types of transactions stored on the block, including business transactions and non-business transactions. In this embodiment, blocks without business transactions are considered as empty blocks, but it does not mean that There must not be any transactions stored on the empty block, for example, non-business transactions may be stored. For the method of distinguishing business transactions and non-business transactions, reference may be made to related technologies, which is not particularly limited in this embodiment.
本实施例中,可以将确定为非空块的区块中的业务交易加入同步队列,该同步队列可以是存储于数据同步系统的。然后可以基于同步队列将非空块上存储的业务交易同步至业务系统。In this embodiment, the business transactions in the blocks determined to be non-empty blocks can be added to the synchronization queue, and the synchronization queue can be stored in the data synchronization system. Then the business transactions stored on the non-empty blocks can be synchronized to the business system based on the synchronization queue.
比如,可以将非空块的标识加入同步队列,则在将业务交易同步给业务系统时可以根据这些标识确定对应的非空块,然后获取非空块上存储的业务交易并同步给业务系统。For example, the identification of non-empty blocks can be added to the synchronization queue. When synchronizing business transactions to the business system, the corresponding non-empty blocks can be determined according to these identifications, and then the business transactions stored on the non-empty blocks can be obtained and synchronized to the business system.
再比如,也可以将非空块上存储的所有业务交易加入同步队列,则在将业务交易同步给业务系统时可以从同步队列内获取业务交易,并把业务交易同步给业务系统。For another example, all business transactions stored on non-empty blocks can also be added to the synchronization queue, then when the business transactions are synchronized to the business system, the business transactions can be obtained from the synchronization queue and synchronized to the business system.
本实施例中,在同步队列中的数据同步完毕后,还可以清空队列中的数据。In this embodiment, after the data in the synchronization queue is synchronized, the data in the queue can also be cleared.
由以上描述可以看出,在本说明书的一个实施例中,数据同步系统可以在达到数据同步的触发条件时,从区块链节点上获取区块链上各个区块的第一存储属性,基于第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,然后将同步队列内的业务交易同步给业务系统。It can be seen from the above description that in one embodiment of this specification, the data synchronization system can obtain the first storage attribute of each block on the blockchain from the blockchain node when the trigger condition for data synchronization is reached, based on The first storage attribute determines whether each block is a non-empty block, and adds the business transactions in the blocks determined to be non-empty blocks to the synchronization queue, and then synchronizes the business transactions in the synchronization queue to the business system.
采用上述方法,在对区块链上的数据进行同步时,可以确定出包含业务交易的非空 块,仅对这些非空块进行数据同步,避免了对不包含业务交易的空块进行数据同步,相比于相关技术中对区块链上所有区块进行全量同步来说,可以大大提高数据同步效率。Using the above method, when synchronizing data on the blockchain, it is possible to determine non-empty blocks containing business transactions, and only perform data synchronization on these non-empty blocks, avoiding data synchronization on empty blocks that do not contain business transactions , compared to the full synchronization of all blocks on the blockchain in related technologies, the efficiency of data synchronization can be greatly improved.
下面对本说明书提供的基于第一存储属性确定区块链上各个区块是否为非空块的方法的实施例进行说明。The following describes an embodiment of the method for determining whether each block on the block chain is a non-empty block based on the first storage attribute provided by this specification.
1.第一存储属性表征本区块是否为非空块1. The first storage attribute indicates whether the block is a non-empty block
在一个例子中,可以从区块链上的最新区块开始,按照区块高度从高到底的顺序,基于各个区块的第一存储属性依次判断各个区块是否为非空块,并将这些确定为非空块的区块加入同步队列。In one example, starting from the latest block on the blockchain, according to the order of block height from high to low, it is possible to determine whether each block is a non-empty block based on the first storage attribute of each block, and these Blocks determined to be non-empty blocks are added to the synchronization queue.
下面以一个具体的例子进行说明。请参见图2,图2示例性地示出了一种区块链,该区块链中可以若干区块,分别为区块1、区块2、……、区块n-4、区块n-3、区块n-2、区块n-1、区块n。区块n为最新区块,区块1为创世区块。其中,以第一存储属性为“0”代表区块为空块,第一存储属性为“1”代表区块为非空块。则区块1为非空块,区块2为非空块、区块n-4为非空块、区块n-3为非空块、区块n-2为空块,区块n-1为空块,区块n为非空块。A specific example is used below to illustrate. Please refer to Fig. 2, Fig. 2 exemplarily shows a block chain, there may be several blocks in the block chain, respectively block 1, block 2, ..., block n-4, block n-3, block n-2, block n-1, block n. Block n is the latest block, and block 1 is the genesis block. Wherein, if the first storage attribute is "0", it means that the block is an empty block, and if the first storage attribute is "1", it means that the block is a non-empty block. Then block 1 is a non-empty block, block 2 is a non-empty block, block n-4 is a non-empty block, block n-3 is a non-empty block, block n-2 is an empty block, block n- 1 is an empty block, and block n is a non-empty block.
则可以先从区块n(最新区块)开始判断,发现区块n为非空块,则可以将区块n加入同步队列,然后判断区块n-1是否为非空块,发现区块n-1为空块,则不将其加入同步队列,然后判断区块n-2是否为非空块,发现区块n-2为空块,则不将其加入同步队列……可以按照上述方法对各个区块进行判断,直到对创世区块(区块1)判断完毕,则可以确定出同步队列内包括的区块为:区块n、区块n-3、区块n-4、……、区块2、区块1。You can first judge from block n (the latest block), and if you find that block n is a non-empty block, you can add block n to the synchronization queue, and then judge whether block n-1 is a non-empty block, and find that block If n-1 is an empty block, it will not be added to the synchronization queue, and then judge whether the block n-2 is a non-empty block, and if the block n-2 is found to be an empty block, it will not be added to the synchronization queue...you can follow the above The method judges each block until the creation block (block 1) is judged, and then it can be determined that the blocks included in the synchronization queue are: block n, block n-3, block n-4 , ..., block 2, block 1.
当然,该例子虽然描述的是将“区块”加入同步队列,但实际上可以仅将非空区块上存储的业务交易加入同步队列,而不是将区块本身加入同步队列,后面的实施例与此类似。Of course, although this example describes adding "blocks" to the synchronization queue, in fact, only business transactions stored on non-empty blocks can be added to the synchronization queue, instead of adding the block itself to the synchronization queue. The following embodiments Similar to this.
在另一个例子中,在判断各个区块是否为非空块时,也可以直接“跳过”空块。In another example, when judging whether each block is a non-empty block, it is also possible to directly "skip" the empty block.
可以从区块链上的最新区块开始,根据最新区块对应的第一存储属性判断该最新区块是否为非空块。Starting from the latest block on the blockchain, it is judged whether the latest block is a non-empty block according to the first storage attribute corresponding to the latest block.
若最新区块为非空块,则可以将最新区块加入同步队列,继续判断最新区块的前一区块是否为非空块;若最新区块为空块,则不将最新区块加入同步队列,并且可以确定出与该最新区块的区块高度最接近的非空块,把该非空块加入同步队列,并继续判断该 非空块的前一区块是否为非空块。If the latest block is a non-empty block, the latest block can be added to the synchronization queue to continue to judge whether the previous block of the latest block is a non-empty block; if the latest block is an empty block, the latest block will not be added synchronization queue, and can determine the non-empty block closest to the block height of the latest block, add the non-empty block to the synchronization queue, and continue to judge whether the previous block of the non-empty block is a non-empty block.
可以采用上述方法确定出区块链上的各个非空块,并且将这些非空块都加入同步队列,以基于同步队列将非空块上存储的业务交易同步给业务系统。The above method can be used to determine each non-empty block on the blockchain, and add these non-empty blocks to the synchronization queue, so as to synchronize the business transactions stored on the non-empty block to the business system based on the synchronization queue.
仍以图2所示例子进行说明。The example shown in FIG. 2 is still used for illustration.
可以先判断区块n(最新区块)是否为非空块,发现其为非空块,则可以将区块n加入同步队列,并判断区块n的前一区块(区块n-1)是否为非空块,发现区块n-1不为非空块,则不将区块n-1加入同步队列,并确定与区块n-1的区块高度最接近的非空块,为区块n-3,则可以将区块n-3加入同步队列。并判断区块n-3的前一区块(区块n-4)是否为非空块,发现区块n-4为非空块,则可以将其加入同步队列。然后可以判断区块n-4的前一区块是否为非空块,以此类推……。You can first judge whether block n (the latest block) is a non-empty block, and if you find that it is a non-empty block, you can add block n to the synchronization queue, and judge the previous block of block n (block n-1 ) is a non-empty block, if block n-1 is found not to be a non-empty block, block n-1 will not be added to the synchronization queue, and the non-empty block closest to the block height of block n-1 will be determined, is block n-3, block n-3 can be added to the synchronization queue. And judge whether the previous block (block n-4) of block n-3 is a non-empty block, and find that block n-4 is a non-empty block, then it can be added to the synchronization queue. Then it can be judged whether the previous block of block n-4 is a non-empty block, and so on....
可以采用上述的方法确定出区块链中的各个非空块,并将非空块加入同步队列,如上述例子中同步队列内的区块包括:区块n、区块n-3、区块n-4、……、区块2、区块1。并且,采用上述方法可以根据区块n-1确定出最近的非空块n-3,而不需要对区块n-2进行判断,相当于可以“跳过”空块,提高效率。The above method can be used to determine each non-empty block in the blockchain, and add the non-empty block to the synchronization queue. For example, the blocks in the synchronization queue in the above example include: block n, block n-3, block n-4, ..., block 2, block 1. Moreover, the above method can determine the nearest non-empty block n-3 according to the block n-1, without the need to judge the block n-2, which is equivalent to "skipping" the empty block and improving the efficiency.
其中,可以通过以下方法确定区块高度最接近的非空块。下面以确定与最新区块的区块高度最接近的非空块为例进行说明。Among them, the non-empty block with the closest block height can be determined by the following method. The following is an example of determining the non-empty block closest to the block height of the latest block.
比如,区块链节点上还可以存储有第二存储属性(世界状态),该第二存储属性表征与本区块的区块高度最接近的非空块。则在确定与最新区块的区块高度最接近的非空块时,可以获取最新区块对应的第二存储属性,根据该属性确定最接近的非空块。For example, a second storage attribute (world state) may also be stored on the blockchain node, and the second storage attribute represents the non-empty block closest to the block height of the current block. Then, when determining the non-empty block closest to the block height of the latest block, the second storage attribute corresponding to the latest block may be obtained, and the closest non-empty block is determined according to the attribute.
其中,第二存储属性的记录过程将会在后面的实施例中详细说明。Wherein, the recording process of the second storage attribute will be described in detail in the following embodiments.
2.第一存储属性表征本区块的前一区块是否为非空块2. The first storage attribute indicates whether the previous block of this block is a non-empty block
在一个例子中,可以从区块链上的最新区块开始,根据最新区块对应的第一存储属性判断该最新区块的前一区块是否为非空块。In an example, starting from the latest block on the blockchain, it is determined whether the previous block of the latest block is a non-empty block according to the first storage attribute corresponding to the latest block.
若最新区块的前一区块为非空块,则可以将最新区块的前一区块加入同步队列,继续判断该前一区块的前一区块是否为非空块;若最新区块的前一区块为空块,则不将最新区块的前一区块加入同步队列,继续判断该前一区块的前一区块是否为非空块。If the previous block of the latest block is a non-empty block, the previous block of the latest block can be added to the synchronization queue, and continue to judge whether the previous block of the previous block is a non-empty block; if the latest block If the previous block of the block is an empty block, then the previous block of the latest block will not be added to the synchronization queue, and continue to judge whether the previous block of the previous block is a non-empty block.
可以采用上述方法确定出区块链上的各个非空块,并且将这些非空块都加入同步队列,以基于同步队列将非空块上存储的业务交易同步给业务系统。The above method can be used to determine each non-empty block on the blockchain, and add these non-empty blocks to the synchronization queue, so as to synchronize the business transactions stored on the non-empty block to the business system based on the synchronization queue.
其中,对于最新区块,可以根据前述例子中的方法来确定其是否为非空块,本实施例在此不再赘述。Wherein, for the newest block, whether it is a non-empty block can be determined according to the method in the foregoing example, which will not be repeated in this embodiment.
仍以图2所示例子进行说明。The example shown in FIG. 2 is still used for illustration.
可以先从区块n(最新区块)开始,根据区块n对应的第二存储属性判断其前一区块(区块n-1)是否为非空块,发现不为非空块,则不将区块n-1加入同步队列,并判断区块n-1的前一区块(区块n-2)是否为非空块,发现区块n-2不为非空块,则不将区块n-2加入同步队列,并判断区块n-2的前一区块(区块n-3)是否为非空块,发现区块n-3为非空块,则将区块n-3加入同步队列,并判断区块n-3的前一区块(区块n-4)是否为空块,以此类推……。You can start from block n (the latest block), judge whether the previous block (block n-1) is a non-empty block according to the second storage attribute corresponding to block n, and find that it is not a non-empty block, then Do not add block n-1 to the synchronization queue, and judge whether the previous block (block n-2) of block n-1 is a non-empty block, and find that block n-2 is not a non-empty block, then do not Add block n-2 to the synchronization queue, and judge whether the previous block (block n-3) of block n-2 is a non-empty block, and if block n-3 is found to be a non-empty block, then block n-3 joins the synchronization queue, and judges whether the previous block (block n-4) of block n-3 is an empty block, and so on....
可以采用上述的方法确定出区块链中的各个非空块,并将非空块加入同步队列,如上述例子中同步队列内的区块包括:区块n、区块n-3、区块n-4、……、区块2、区块1。其中,区块n是否为空块的判断方法可以参照前述实施例。The above method can be used to determine each non-empty block in the blockchain, and add the non-empty block to the synchronization queue. For example, the blocks in the synchronization queue in the above example include: block n, block n-3, block n-4, ..., block 2, block 1. Wherein, the method for judging whether the block n is an empty block can refer to the foregoing embodiments.
在另一个例子中,类似的,也可以在判断过程中“跳过”空块。In another example, similarly, it is also possible to "skip" empty blocks during the judgment process.
可以从区块链上的最新区块开始,根据最新区块对应的第一存储属性判断该最新区块的前一区块是否为非空块。It is possible to start from the latest block on the blockchain, and judge whether the previous block of the latest block is a non-empty block according to the first storage attribute corresponding to the latest block.
若最新区块的前一区块为非空块,则可以将最新区块的前一区块加入同步队列,继续判断该前一区块的前一区块是否为非空块;若最新区块的前一区块为空块,则不将最新区块的前一区块加入同步队列,并且可以确定出与该最新区块的前一区块的区块高度最接近的非空块,把该非空块加入同步队列,并继续判断该非空块的前一区块是否为非空块。If the previous block of the latest block is a non-empty block, the previous block of the latest block can be added to the synchronization queue, and continue to judge whether the previous block of the previous block is a non-empty block; if the latest block If the previous block of the latest block is an empty block, the previous block of the latest block will not be added to the synchronization queue, and the non-empty block closest to the block height of the previous block of the latest block can be determined. Add the non-empty block to the synchronization queue, and continue to judge whether the previous block of the non-empty block is a non-empty block.
可以采用上述方法确定出区块链上的各个非空块,并且将这些非空块都加入同步队列,以基于同步队列将非空块上存储的业务交易同步给业务系统。The above method can be used to determine each non-empty block on the blockchain, and add these non-empty blocks to the synchronization queue, so as to synchronize the business transactions stored on the non-empty block to the business system based on the synchronization queue.
其中,确定与该最新区块的前一区块的区块高度最接近的非空块的方法可以参照前述实施例。类似的,对于最新区块,可以根据前述例子中的方法来确定其是否为非空块,本实施例在此不再赘述。Wherein, the method for determining the non-empty block closest to the block height of the previous block of the latest block can refer to the foregoing embodiments. Similarly, for the newest block, whether it is a non-empty block can be determined according to the method in the foregoing examples, which will not be repeated in this embodiment.
仍以图2所示例子进行说明。The example shown in FIG. 2 is still used for illustration.
可以先从区块n(最新区块)开始,根据区块n对应的第二存储属性判断其前一区块(区块n-1)是否为非空块,发现为空块,则不将区块n-1加入同步队列,并确定与 区块n-1的区块高度最接近的非空块,为区块n-3,则将区块n-3加入同步队列,并判断区块n-3的前一区块(区块n-4)是否为空块,发现区块n-4不为空块,则将区块n-4加入同步队列,并判断区块n-4的前一区块(区块n-5)是否为非空块,以此类推……。You can start from block n (the latest block), judge whether the previous block (block n-1) is a non-empty block according to the second storage attribute corresponding to block n, and if it is found to be an empty block, then do not Block n-1 is added to the synchronization queue, and the non-empty block closest to the block height of block n-1 is determined to be block n-3, then block n-3 is added to the synchronization queue, and the block is judged Whether the previous block of n-3 (block n-4) is an empty block, and if block n-4 is found to be not empty, block n-4 will be added to the synchronization queue, and the block n-4 will be judged Whether the previous block (block n-5) is a non-empty block, and so on....
可以采用上述的方法确定出区块链中的各个非空块,并将非空块加入同步队列,如上述例子中同步队列内的区块包括:区块n、区块n-3、区块n-4、……、区块2、区块1。其中,区块n是否为空块的判断方法可以参照前述实施例。The above method can be used to determine each non-empty block in the blockchain, and add the non-empty block to the synchronization queue. For example, the blocks in the synchronization queue in the above example include: block n, block n-3, block n-4, ..., block 2, block 1. Wherein, the method for judging whether the block n is an empty block can refer to the foregoing embodiments.
当然,上述例子仅仅为示例性的说明,并不用于限制本说明书。Certainly, the above-mentioned examples are only illustrative descriptions, and are not intended to limit the description.
由以上描述可以看出,在本说明书的一个实施例中,在数据同步的过程中,若确定某个区块为空块,还可以确定与该区块的区块高度最接近的非空块,然后直接将该非空块(上存储的业务交易)加入同步队列,而不需要对这两个区块之间包含的空块进行处理,相当于可以直接“跳过”其中的空块,可以大大提高数据同步效率。It can be seen from the above description that in one embodiment of this specification, in the process of data synchronization, if a block is determined to be an empty block, the non-empty block closest to the block height of the block can also be determined , and then directly add the non-empty block (the business transaction stored on it) to the synchronization queue without processing the empty block contained between the two blocks, which is equivalent to directly "skipping" the empty block, Can greatly improve the efficiency of data synchronization.
下面对本说明书提供的另一种基于区块链的数据同步方法的实施例进行说明。The following describes another embodiment of a blockchain-based data synchronization method provided in this specification.
本实施例中,可以在区块链的世界状态中增加各区块对应的第一存储属性、第二存储属性,以基于这些属性来确定各区块是否为空块、区块高度最接近的非空块。下面首先对这两种属性的记录过程进行说明。In this embodiment, the first storage attribute and the second storage attribute corresponding to each block can be added to the world state of the block chain, so as to determine whether each block is an empty block and the non-empty block with the closest block height based on these attributes. piece. The recording process of these two attributes will be described first below.
1、第一存储属性1. The first storage attribute
本实施例中,可以在区块链的世界状态中设置各区块对应的第一存储属性,第一存储属性表征本区块是否为空块,比如可参见图2,当属性值为“1”时,表征本区块为非空块,当属性值为“0”时,表征本区块为空块。In this embodiment, the first storage attribute corresponding to each block can be set in the world state of the blockchain. The first storage attribute indicates whether the block is an empty block. For example, see Figure 2, when the attribute value is "1" When , it indicates that this block is a non-empty block, and when the attribute value is "0", it indicates that this block is an empty block.
可以通过以下的方式来生成第一属性。The first attribute can be generated in the following manner.
在一个例子中,区块链节点可以接收到业务交易,该业务交易可以是用户发起的,或者也可以是区块链平台发起的,对此不作特殊限制。区块链节点接收到该业务交易后,可以对该业务交易进行共识,共识完毕后该业务交易会被存储于对应区块中,然后可以执行该业务交易。执行该业务交易时,一方面可以进行业务相关操作(比如可以是对汇款双方账户的余额进行变更),另一方面也可以进行第一属性记录的相关操作。由于该区块中存储有业务交易,即为非空块,则可以调用智能合约中的第一属性记录逻辑记录表征所述业务交易所在区块为非空块的第一存储属性。比如,仍以图2所示例子为例,假设业务交易被存储于区块n,则可以执行该业务交易以记录区块n对应的第一存储属性,并将该属性值设置为“1”。In an example, a blockchain node may receive a business transaction, and the business transaction may be initiated by a user or a blockchain platform, and there is no special limitation on this. After the blockchain node receives the business transaction, it can reach a consensus on the business transaction. After the consensus is completed, the business transaction will be stored in the corresponding block, and then the business transaction can be executed. When executing the business transaction, on the one hand, business-related operations (such as changing the balance of the remittance parties' accounts) can be performed, and on the other hand, related operations on the first attribute record can also be performed. Since the business transaction is stored in the block, that is, it is a non-empty block, the first attribute record logic in the smart contract can be called to record the first storage attribute indicating that the block in which the business transaction is located is a non-empty block. For example, still taking the example shown in Figure 2 as an example, assuming that the business transaction is stored in block n, the business transaction can be executed to record the first storage attribute corresponding to block n, and the attribute value is set to "1" .
其中,区块链上还可能存在一些区块不存储有业务交易,那么也就无法通过执行业务交易来记录该区块对应的第一存储属性。那么后续在基于第一存储属性判断各个区块是否为非空块时,可以将无法获取到对应的第一存储属性的区块确定为空块。Among them, there may be some blocks on the block chain that do not store business transactions, so it is impossible to record the first storage attribute corresponding to the blocks by executing business transactions. Then, when determining whether each block is a non-empty block based on the first storage attribute, the block whose corresponding first storage attribute cannot be obtained may be determined as an empty block.
在另一个例子中,区块链节点也可以接收到第一存储属性记录交易。类似的,第一存储属性记录交易比如可以是区块链平台发起的,也可以是其它方发起的,对此不作特殊限制。区块链节点接收到该第一存储属性记录交易后,可以对该第一存储属性记录交易进行共识,共识完毕后该第一存储属性记录交易可以被存储于对应区块中,然后可以执行该第一存储属性记录交易以调用智能合约中的第一存储属性记录逻辑判断所述第一存储属性生成交易所在的区块是否存储有业务交易,若是,则确定该区块为非空块;若否,则确定该区块为空块。然后可以根据判断结果记录该区块对应的第一存储属性。In another example, the blockchain node may also receive the first storage attribute record transaction. Similarly, the first storage attribute record transaction may be initiated by, for example, the blockchain platform or other parties, and there is no special limitation on this. After the blockchain node receives the first storage attribute record transaction, it can reach a consensus on the first storage attribute record transaction. After the consensus is completed, the first storage attribute record transaction can be stored in the corresponding block, and then the transaction can be executed. The first storage attribute records the transaction to call the first storage attribute recording logic in the smart contract to determine whether the block where the first storage attribute generates the transaction stores a business transaction, and if so, determines that the block is a non-empty block; If not, it is determined that the block is an empty block. Then, the first storage attribute corresponding to the block may be recorded according to the judgment result.
其中,第一存储属性记录交易可以是周期性发送的,并且该发送周期可以与区块链上区块成块的周期相同。举例来说,区块链在共识时会周期性生成区块,比如每秒生成一个区块,则第一存储属性记录交易的发送周期也可以是每秒。Wherein, the first storage attribute record transaction may be sent periodically, and the sending cycle may be the same as the block forming cycle on the blockchain. For example, when the blockchain generates blocks periodically during consensus, for example, one block is generated every second, the sending cycle of the first storage attribute record transaction can also be every second.
采用这种方式可以使得各个区块上都存储有第一存储属性记录交易,以基于该交易来记录第一存储属性。解决了上述例子中因区块上不存储有业务交易导致无法执行业务交易来记录本区块对应的第一存储属性的问题。In this way, the first storage attribute record transaction can be stored in each block, so as to record the first storage attribute based on the transaction. The above example solves the problem that the business transaction cannot be executed to record the first storage attribute corresponding to the block because there is no business transaction stored in the block.
并且,本说明书中,还可以同时采用上述两种方法,即既可以执行业务交易来记录第一存储属性,也可以执行第一存储属性记录交易来记录第一存储属性。并且,当区块上既存储有业务交易又存储有第一存储属性记录交易时,可以采用在后执行交易得到的结果覆盖在前执行交易得到的结果,当然也可以采取其他方法,本实施例对此不作特殊限制。Moreover, in this specification, the above two methods can also be used at the same time, that is, a business transaction can be executed to record the first storage attribute, and a first storage attribute recording transaction can be executed to record the first storage attribute. Moreover, when the block stores both the business transaction and the first storage attribute record transaction, the result obtained from the later execution of the transaction can be used to overwrite the result of the previous execution of the transaction. Of course, other methods can also be adopted. This embodiment There are no particular restrictions on this.
在其他实施例中,第一存储属性也可以表征本区块的前一区块是否为空块,比如属性值为“1”时,表征本区块的前一区块为非空块,属性值为“0”时,表征本区块的前一区块为空块。In other embodiments, the first storage attribute can also represent whether the previous block of this block is an empty block, for example, when the attribute value is "1", it indicates that the previous block of this block is a non-empty block, and the attribute When the value is "0", it indicates that the previous block of this block is an empty block.
那么在这种情况下,可以通过以下的方式来记录第一存储属性。In this case, the first storage attribute may be recorded in the following manner.
在一个例子中,区块链节点可以接收到业务交易,通过执行该业务交易以调用智能合约中的第一存储属性记录逻辑判断该业务交易所在区块的前一区块是否存储有业务交易,并基于判断结果记录该业务交易所在区块的第一存储属性。具体可以参照前述实施例,本说明书在此不再赘述。In one example, a blockchain node may receive a business transaction, and execute the business transaction to call the first storage attribute record logic in the smart contract to determine whether the business transaction is stored in the previous block of the block where the business transaction is located , and record the first storage attribute of the block where the business transaction is located based on the judgment result. For details, reference may be made to the aforementioned embodiments, and details will not be repeated here in this specification.
类似的,区块链上还可能存在一些区块不存储有业务交易,那么也就无法通过执行业务交易来记录该区块对应的第一存储属性。那么后续在基于第一存储属性判断各个区块是否为非空块时,可以将无法获取到对应的第一存储属性的区块的前一区块确定为空块。Similarly, there may be some blocks on the blockchain that do not store business transactions, so it is impossible to record the first storage attribute corresponding to the blocks by executing business transactions. Then, when determining whether each block is a non-empty block based on the first storage attribute, the block preceding the block for which the corresponding first storage attribute cannot be obtained may be determined as an empty block.
在另一个例子中,区块链节点也可以接收到第一存储属性记录交易。类似的,对第一存储属性记录交易的发起方不作特殊限制。区块链节点接收到该第一存储属性记录交易后,可以对该第一存储属性记录交易进行共识,共识完毕后该第一存储属性记录交易可以被存储于对应区块中,然后可以执行该第一存储属性记录交易以调用智能合约中的第三存储属性记录逻辑判断所述第一存储属性记录交易所在的区块的前一区块是否存储有业务交易,若是,则确定该前一区块为非空块;若否,则确定该前一区块为空块。然后可以根据判断结果记录该区块对应的第一存储属性。In another example, the blockchain node may also receive the first storage attribute record transaction. Similarly, there is no special restriction on the initiator of the first storage attribute record transaction. After the blockchain node receives the first storage attribute record transaction, it can reach a consensus on the first storage attribute record transaction. After the consensus is completed, the first storage attribute record transaction can be stored in the corresponding block, and then the transaction can be executed. The first storage attribute record transaction is used to call the third storage attribute record logic in the smart contract to judge whether the previous block of the block where the first storage attribute record transaction is located has business transactions stored, and if so, determine the previous block The block is a non-empty block; if not, it is determined that the previous block is an empty block. Then, the first storage attribute corresponding to the block may be recorded according to the judgment result.
类似的,第一存储属性记录交易可以是周期性发送的,并且该发送周期也可以与区块链上区块成块的周期相同。Similarly, the first storage attribute record transaction can be sent periodically, and the sending cycle can also be the same as the block forming cycle on the blockchain.
采用上述方法,由于区块链中的各个区块是按顺序进行共识的,那么在执行某个区块上的第一存储属性记录交易时,其前一区块应当是已经共识完毕的,则执行该第一存储属性记录交易判断得到的前一区块是否为空块的结果是准确的,可以避免因交易未共识成功导致判断结果不准确的问题。Using the above method, since each block in the blockchain is consensused in order, when the first storage attribute record transaction on a block is executed, the previous block should have been consensus completed, then The result of whether the previous block is an empty block obtained by executing the first storage attribute record transaction judgment is accurate, which can avoid the problem of inaccurate judgment results caused by the failure of consensus on the transaction.
当然,上述例子仅仅是本说明书提供的一些示例性的例子,在实际应用中也可以采取其他方法来确定各个区块是否为空块,本说明书在此不一一举例。Of course, the above examples are only some exemplary examples provided in this specification, and other methods can also be adopted in practical applications to determine whether each block is an empty block, and this specification does not give examples one by one here.
2、第二存储属性2. The second storage attribute
本实施例中,第二存储属性可以表征区块高度与本区块最接近的非空块。In this embodiment, the second storage attribute may represent a non-empty block whose block height is closest to the current block.
在一个例子中,区块链节点可以接收到业务交易,通过执行该业务交易以调用智能合约中的第二存储属性记录逻辑确定与所述业务交易所在区块的区块高度最接近的非空块,并基于所述非空块记录该业务交易所在区块对应的第二存储属性。具体可以参照前述实施例,本说明书在此不再赘述。In an example, a blockchain node may receive a business transaction, and execute the business transaction to call the second storage attribute recording logic in the smart contract to determine the non-block height closest to the block where the business transaction is located. An empty block, and based on the non-empty block, record the second storage attribute corresponding to the block where the business transaction is located. For details, reference may be made to the aforementioned embodiments, and details will not be repeated here in this specification.
在另一个例子中,区块链节点也可以接收到第二存储属性记录交易。类似的,对第二存储属性记录交易的发起方不作特殊限制。区块链节点接收到该第二存储属性记录交易后,可以对该第二存储属性记录交易进行共识,共识完毕后该第二存储属性记录交易可以被存储于对应区块中,然后可以执行该第二存储属性记录交易以调用智能合约中的 第二存储属性生成逻辑确定与所述第二存储属性记录交易所在区块的区块高度最接近的非空块,并根据该非空块记录该第二存储属性记录交易所在区块对应的第二存储属性。In another example, the blockchain node may also receive the second storage attribute record transaction. Similarly, there is no special restriction on the initiator of the second storage attribute record transaction. After the blockchain node receives the second storage attribute record transaction, it can reach a consensus on the second storage attribute record transaction. After the consensus is completed, the second storage attribute record transaction can be stored in the corresponding block, and then the transaction can be executed. The second storage attribute record transaction is used to call the second storage attribute generation logic in the smart contract to determine the non-empty block closest to the block height of the block where the second storage attribute record transaction is located, and record according to the non-empty block The second storage attribute records the second storage attribute corresponding to the block where the transaction is located.
类似的,第二存储属性记录交易可以是周期性发送的,并且该发送周期也可以与区块链上区块成块的周期相同。Similarly, the second storage attribute record transaction can be sent periodically, and the sending cycle can also be the same as the block forming cycle on the blockchain.
当然,上述例子仅仅是本说明书提供的一些示例性的例子,在实际应用中也可以采取其他方法来确定区块高度最接近的非空块,本说明书在此不一一举例。Certainly, the above-mentioned examples are only some exemplary examples provided in this specification, and other methods may also be adopted in practical applications to determine the non-empty block with the closest block height, and this specification does not give examples one by one here.
阐明了上述在世界状态中增加各区块对应的属性以及属性的生成方法后,下面对基于区块链的数据同步方法进行说明。After clarifying the above-mentioned method of adding the attributes corresponding to each block in the world state and the method of generating the attributes, the data synchronization method based on the blockchain will be described below.
请参见图3,图3是本说明书一示例性实施例示出的另一种基于区块链的数据同步方法的流程示意图,所述方法可以包括以下步骤:Please refer to FIG. 3. FIG. 3 is a schematic flowchart of another blockchain-based data synchronization method shown in an exemplary embodiment of this specification. The method may include the following steps:
步骤302,确定是否达到数据同步的触发条件。若是,则执行步骤304。 Step 302, determine whether a trigger condition for data synchronization is met. If yes, execute step 304 .
本实施例中,确定是否达到数据同步的触发条件的方法可参照前述实施例,在此不再赘述。In this embodiment, the method for determining whether a trigger condition for data synchronization is met may refer to the foregoing embodiments, and details are not repeated here.
步骤304,从区块链节点上获取最新区块对应的第一存储属性,基于第一存储属性确定最新区块是否为非空块。若否,执行步骤306-308;若是,执行步骤310。Step 304: Obtain the first storage attribute corresponding to the latest block from the blockchain node, and determine whether the latest block is a non-empty block based on the first storage attribute. If not, execute steps 306-308; if yes, execute step 310.
步骤306,从区块链节点上获取最新区块对应的第二存储属性,基于第二存储属性确定与最新区块的区块高度最接近的非空块。Step 306: Obtain the second storage attribute corresponding to the latest block from the blockchain node, and determine the non-empty block closest to the block height of the latest block based on the second storage attribute.
步骤308,将非空块加入同步队列,并基于非空块的前一区块对应的第一存储属性确定该前一区块是否为非空块。 Step 308, adding the non-empty block to the synchronization queue, and determining whether the previous block is a non-empty block based on the first storage attribute corresponding to the previous block of the non-empty block.
本实施例中,可以从区块链节点上的最新区块开始处理,判断该最新区块是否为非空块。比如,可以从区块链节点上获取该最新区块对应的第一存储属性,第一存储属性可以表征该区块是否为非空块。基于第一存储属性进行非空块与否的确定。其中,从区块链上获取第一属性(世界状态)的方法可以参照相关技术,本实施例在此不一一说明。In this embodiment, processing can be started from the latest block on the blockchain node to determine whether the latest block is a non-empty block. For example, the first storage attribute corresponding to the latest block can be obtained from the blockchain node, and the first storage attribute can indicate whether the block is a non-empty block. The non-empty block is determined based on the first storage attribute. Wherein, the method of obtaining the first attribute (world state) from the blockchain can refer to related technologies, and this embodiment will not describe them one by one here.
若最新区块为空块,则可以从区块链节点上获取该最新区块对应的第二存储属性。第二存储属性可以表征与该区块的区块高度最接近的非空块。可以根据第二存储属性确定非空块,将该非空块加入同步队列。If the latest block is an empty block, the second storage attribute corresponding to the latest block can be obtained from the blockchain node. The second storage attribute may characterize the closest non-empty block to the block height of the block. A non-empty block may be determined according to the second storage attribute, and the non-empty block is added to the synchronization queue.
并且,还可以判断非空块的前一区块是否为非空块。比如可以从区块链节点上获取该前一空块对应的第一存储属性,以此确定是否为非空块,并在为非空块的情况下将其 加入同步队列,为空块的情况下获取区块高度最接近的非空块加入同步队列。以此类推。Moreover, it can also be judged whether the previous block of the non-empty block is a non-empty block. For example, the first storage attribute corresponding to the previous empty block can be obtained from the blockchain node to determine whether it is a non-empty block, and if it is a non-empty block, add it to the synchronization queue; if it is an empty block Get the non-empty block with the closest block height and add it to the synchronization queue. and so on.
步骤310,将最新区块加入同步队列,并基于最新区块的前一区块对应的第一存储属性确定该前一区块是否为非空块。 Step 310, adding the latest block into the synchronization queue, and determining whether the previous block of the latest block is a non-empty block based on the first storage attribute corresponding to the previous block of the latest block.
本实施例中,若最新区块为非空块,则可以将最新空块加入同步队列。并判断最新空块的前一区块是否为非空块,比如可以获取该前一空块对应的第一存储属性,以此确定是否为非空块,并为非空块的情况下将其上存储的业务交易加入同步队列,为空块的情况下获取区块高度最接近的非空块,并将该非空块上存储的业务交易加入同步队列。以此类推。In this embodiment, if the latest block is a non-empty block, the latest empty block can be added to the synchronization queue. And judge whether the previous block of the latest empty block is a non-empty block, for example, the first storage attribute corresponding to the previous empty block can be obtained to determine whether it is a non-empty block, and if it is a non-empty block, upload it The stored business transaction is added to the synchronization queue, and in the case of an empty block, the non-empty block with the closest block height is obtained, and the business transaction stored on the non-empty block is added to the synchronization queue. and so on.
步骤312,在确定出区块链中的各个非空块之后,对同步队列内各个区块上的数据进行同步。 Step 312, after determining each non-empty block in the blockchain, synchronize the data on each block in the synchronization queue.
本实施例中,可以采用前述步骤的方法确定出区块链中的各个非空块,并将这些非空块中的业务交易加入同步队列。然后对同步队列内的各个区块上存储的业务交易进行数据同步。具体可以参照前述实施例,在此不再赘述。In this embodiment, each non-empty block in the blockchain can be determined by using the method of the foregoing steps, and the business transactions in these non-empty blocks can be added to the synchronization queue. Then perform data synchronization on the business transactions stored on each block in the synchronization queue. For details, reference may be made to the foregoing embodiments, and details are not repeated here.
在其他实施例中,也可以分批次进行区块链上的数据同步。比如,可以预先设有能够包含指定数量区块的滑动窗口,比如滑动窗口的大小为10个区块、5个区块等,具体可以预先设置,则可以利用滑动窗口来进行区块链上数据的同步。In other embodiments, data synchronization on the blockchain can also be performed in batches. For example, a sliding window that can contain a specified number of blocks can be preset. For example, the size of the sliding window is 10 blocks or 5 blocks. synchronization.
仍以图2所示例子为例,假设滑动窗口的大小为4个区块,可以使用滑动窗口确定出区块n~区块n-3、区块n-4~区块n-7、……,然后针对每个该滑动窗口进行数据同步处理。Still taking the example shown in Figure 2 as an example, assuming that the size of the sliding window is 4 blocks, the sliding window can be used to determine block n-block n-3, block n-4~block n-7, ... ..., and then perform data synchronization processing for each sliding window.
以区块n~区块n-3对应的滑动窗口为例,可以先判断区块n是否为空块,发现其不为空块,则将区块n加入同步队列,然后继续判断区块n-1是否为空块,发现为空块,则不将其加入同步队列,并确定最近的非空块为区块n-3,则将区块n-3加入同步队列。且区块n-3为该滑动窗口中的最后一个区块,则可以确定该滑动窗口处理完成,可以对该滑动窗口对应的同步队列进行数据同步。Taking the sliding window corresponding to block n ~ block n-3 as an example, you can first judge whether block n is an empty block, and if it is not empty, add block n to the synchronization queue, and then continue to judge block n -1 Whether it is an empty block, if it is found to be an empty block, it will not be added to the synchronization queue, and the nearest non-empty block is determined to be block n-3, then block n-3 will be added to the synchronization queue. And block n-3 is the last block in the sliding window, it can be determined that the processing of the sliding window is completed, and data synchronization can be performed on the synchronization queue corresponding to the sliding window.
类似的,其他滑动窗口也可以采用上述方法进行处理。并且,每个滑动窗口可以是并行处理的,也可以是串行处理的,具体可以根据实际业务场景进行设置。Similarly, other sliding windows can also be processed by the above method. Moreover, each sliding window can be processed in parallel or serially, which can be set according to actual business scenarios.
由以上描述可以出,在本说明书的一个实施例中,可以在区块链的世界状态中增加若干属性,基于这些属性来确定各个区块是否为空块、区块高度最接近的非空块。从而在数据同步的过程中确定出空块和非空块,以对非空块进行数据同步,而不需要对区块 链上的所有区块都进行处理,可以提高数据同步的效率。It can be seen from the above description that in one embodiment of this specification, several attributes can be added to the world state of the blockchain, based on these attributes to determine whether each block is an empty block, the non-empty block with the closest block height . Therefore, in the process of data synchronization, empty blocks and non-empty blocks are determined to perform data synchronization on non-empty blocks, without the need to process all blocks on the blockchain, which can improve the efficiency of data synchronization.
与前述基于区块链的数据同步方法的实施例相对应,本说明书还提供了基于区块链的数据同步装置的实施例。Corresponding to the aforementioned embodiments of the blockchain-based data synchronization method, this specification also provides embodiments of a blockchain-based data synchronization device.
本说明书基于区块链的数据同步装置的实施例可以应用在电子设备上。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。从硬件层面而言,如图4所示,为本说明书基于区块链的数据同步装置所在电子设备的一种硬件结构图,除了图4所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的电子设备通常根据该电子设备的实际功能,还可以包括其他硬件,对此不再赘述。The embodiment of the blockchain-based data synchronization device in this specification can be applied to electronic equipment. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the processor of the electronic device where it is located. From the hardware level, as shown in Figure 4, it is a hardware structure diagram of the electronic device where the blockchain-based data synchronization device in this manual is located, except for the processor, memory, network interface, and non-volatile memory shown in Figure 4 In addition to the volatile memory, the electronic device where the device in the embodiment is located usually may also include other hardware according to the actual function of the electronic device, which will not be repeated here.
图5是本说明书一示例性实施例示出的一种基于区块链的数据同步装置的框图。Fig. 5 is a block diagram of a blockchain-based data synchronization device shown in an exemplary embodiment of this specification.
请参考图5,所述基于区块链的数据同步装置可以应用在前述图4所示的电子设备中,包括有:获取单元510、确定单元520和同步单元530。Please refer to FIG. 5 , the block chain-based data synchronization device can be applied in the aforementioned electronic device shown in FIG. 4 , including: an acquisition unit 510 , a determination unit 520 and a synchronization unit 530 .
其中,获取单元510,达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;确定单元520,基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;同步单元530,将同步队列内的业务交易同步至业务系统。Wherein, the acquisition unit 510, when the trigger condition of data synchronization is reached, acquires the first storage attribute of each block on the blockchain from the blockchain node; the determination unit 520 determines whether each block is non-empty block, and add the business transaction in the block that is determined as the non-empty block to the synchronization queue, and the non-empty block is a block that stores the business transaction; the synchronization unit 530 synchronizes the business transaction in the synchronization queue to the business system.
可选的,所述第一存储属性表征本区块是否为非空块,所述确定单元520在基于所述第一存储属性确定各个区块是否为非空块时:从最新区块开始,按照区块高度从高到底的顺序,基于各个区块的第一存储属性依次判断各个区块是否为非空块。Optionally, the first storage attribute indicates whether the current block is a non-empty block, and the determining unit 520 determines whether each block is a non-empty block based on the first storage attribute: starting from the latest block, According to the sequence of block heights from high to low, it is sequentially judged whether each block is a non-empty block based on the first storage attribute of each block.
可选的,所述第一存储属性表征本区块是否为非空块,所述确定单元520在基于所述第一存储属性确定各个区块是否为非空块时:基于最新区块对应的第一存储属性判断所述最新区块是否为非空块;若所述最新区块为非空块,则判断所述最新区块的前一区块是否为非空块;若所述最新区块为空块,则确定与所述最新区块的区块高度最接近的非空块,并判断所述非空块的前一区块是否为非空块。Optionally, the first storage attribute indicates whether the current block is a non-empty block, and the determining unit 520 determines whether each block is a non-empty block based on the first storage attribute: based on the latest block corresponding The first storage attribute judges whether the latest block is a non-empty block; if the latest block is a non-empty block, then judge whether the previous block of the latest block is a non-empty block; if the latest block block is an empty block, then determine the non-empty block closest to the block height of the latest block, and judge whether the previous block of the non-empty block is a non-empty block.
可选的,所述第一存储属性的记录过程,包括:区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第一存储属性记录逻辑记录表征所述业务交易所在区块为非空块的第一存储属性。Optionally, the recording process of the first storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the first storage attribute record logic record in the smart contract to represent the business exchange The block is the first storage attribute of a non-empty block.
可选的,所述第一存储属性的记录过程,包括:区块链节点接收到周期性发送的第 一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第一存储属性记录逻辑判断所述第一存储属性记录交易所在区块上是否存储有业务交易,并基于判断结果记录所述第一存储属性记录交易所在区块对应的第一存储属性。Optionally, the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract A storage attribute record logic judges whether a business transaction is stored on the block of the first storage attribute record transaction, and records the first storage attribute corresponding to the block where the first storage attribute record transaction is located based on the judgment result.
可选的,所述区块链节点上存储有各区块对应的第二存储属性,所述第二存储属性表征与本区块的区块高度最接近的非空块,所述确定单元520在确定与所述最新区块的区块高度最接近的非空块时:从区块链节点上获取所述最新区块对应的第二存储属性;基于所述第二存储属性确定与所述最新区块的区块高度最接近的非空块。Optionally, the second storage attribute corresponding to each block is stored on the block chain node, and the second storage attribute represents the non-empty block closest to the block height of the block, and the determining unit 520 When determining the non-empty block closest to the block height of the latest block: obtaining the second storage attribute corresponding to the latest block from the blockchain node; The block whose block height is closest to the non-empty block.
可选的,所述第二存储属性的记录过程,包括:区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第二存储属性记录逻辑确定与所述业务交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述业务交易所在区块对应的第二存储属性。Optionally, the recording process of the second storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the second storage attribute recording logic in the smart contract to determine the business transaction In the non-empty block closest to the block height of the block, and based on the non-empty block, record the second storage attribute corresponding to the block where the business transaction is located.
可选的,所述第二存储属性的记录过程,包括:区块链节点接收到周期性发送的第二存储属性记录交易后,执行所述第二存储属性记录交易以调用智能合约中的第二存储属性记录逻辑确定与所述第二存储属性更新交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述第二存储属性更新交易所在区块对应的第二存储属性。Optionally, the recording process of the second storage attribute includes: after the block chain node receives the second storage attribute record transaction sent periodically, execute the second storage attribute record transaction to call the first storage attribute record transaction in the smart contract The second storage attribute recording logic determines the non-empty block closest to the block height of the block where the second storage attribute update transaction is located, and records the block where the second storage attribute update transaction resides based on the non-empty block The corresponding second storage attribute.
可选的,所述第一存储属性表征本区块的前一区块是否为空块,所述确定单元520在基于所述第一存储属性确定各个区块是否为非空块时:针对所述最新区块,基于所述第一存储属性确定所述最新区块的前一区块是否为非空块;若所述前一区块为非空块,则基于所述前一区块对应的第一存储属性判断所述前一区块的前一区块是否为非空块;若所述前一区块为空块,则确定与所述前一区块的区块高度最接近的非空块,并基于所述非空块对应的第一存储属性判断所述非空块的前一区块是否为空块。Optionally, the first storage attribute indicates whether the previous block of this block is an empty block, and the determining unit 520 determines whether each block is a non-empty block based on the first storage attribute: for all The latest block, based on the first storage attribute to determine whether the previous block of the latest block is a non-empty block; if the previous block is a non-empty block, then based on the previous block corresponding The first storage attribute judges whether the previous block of the previous block is a non-empty block; if the previous block is an empty block, then determine the block height closest to the previous block a non-empty block, and judge whether the previous block of the non-empty block is an empty block based on the first storage attribute corresponding to the non-empty block.
可选的,所述第一存储属性的记录过程,包括:区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第三存储属性记录逻辑判断所述第一存储属性记录交易所在区块的前一区块是否存储有业务交易,并基于判断结果生成所述第一存储属性记录交易所在区块对应的第一存储属性。Optionally, the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract Three storage attribute record logic judges whether the previous block of the first storage attribute record transaction stores business transactions, and generates the first storage attribute record transaction corresponding to the first block based on the judgment result. store attributes.
可选的,数据同步的触发条件,包括:接收到数据同步请求后;和/或达到数据同步周期。Optionally, the trigger condition for data synchronization includes: after receiving a data synchronization request; and/or reaching a data synchronization period.
上述装置中各个单元的功能和作用的实现过程具体详见上述方法中对应步骤的实现过程,在此不再赘述。For the implementation process of the functions and effects of each unit in the above device, please refer to the implementation process of the corresponding steps in the above method for details, and will not be repeated here.
对于装置实施例而言,由于其基本对应于方法实施例,所以相关之处参见方法实施例的部分说明即可。以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本说明书方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。As for the device embodiment, since it basically corresponds to the method embodiment, for related parts, please refer to the part description of the method embodiment. The device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network elements. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution in this specification. It can be understood and implemented by those skilled in the art without creative effort.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementing device is a computer, which may take the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, e-mail device, game control device, etc. desktops, tablets, wearables, or any combination of these.
与前述基于区块链的数据同步方法的实施例相对应,本说明书还提供一种基于区块链的数据同步装置,该装置包括:处理器以及用于存储机器可执行指令的存储器。其中,处理器和存储器通常借由内部总线相互连接。在其他可能的实现方式中,所述设备还可能包括外部接口,以能够与其他设备或者部件进行通信。Corresponding to the aforementioned embodiments of the blockchain-based data synchronization method, this specification also provides a blockchain-based data synchronization device, which includes: a processor and a memory for storing machine-executable instructions. Wherein, the processor and the memory are usually connected to each other by an internal bus. In other possible implementation manners, the device may further include an external interface, so as to be able to communicate with other devices or components.
在本实施例中,通过读取并执行所述存储器存储的与基于区块链的数据同步逻辑对应的机器可执行指令,所述处理器被促使:一种基于区块链的数据同步方法,应用于数据同步系统,所述数据同步系统与区块链节点对接,所述方法包括:达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;将同步队列内的业务交易同步至业务系统。In this embodiment, by reading and executing the machine-executable instructions stored in the memory and corresponding to the blockchain-based data synchronization logic, the processor is prompted to: a blockchain-based data synchronization method, Applied to a data synchronization system, the data synchronization system is docked with a block chain node, and the method includes: when a trigger condition for data synchronization is reached, obtaining the first storage attribute of each block on the block chain from the block chain node; Determine whether each block is a non-empty block based on the first storage attribute, and add the business transaction in the block that is determined to be a non-empty block to the synchronization queue, and the non-empty block is a block that stores a business transaction; The business transactions in the synchronization queue are synchronized to the business system.
可选的,所述第一存储属性表征本区块是否为非空块,在基于所述第一存储属性确定各个区块是否为非空块时,所述处理器被促使:从最新区块开始,按照区块高度从高到底的顺序,基于各个区块的第一存储属性依次判断各个区块是否为非空块。Optionally, the first storage attribute indicates whether the current block is a non-empty block, and when determining whether each block is a non-empty block based on the first storage attribute, the processor is prompted to: start from the latest block At first, according to the order of block height from high to low, it is judged whether each block is a non-empty block based on the first storage attribute of each block.
可选的,所述第一存储属性表征本区块是否为非空块,在基于所述第一存储属性确定各个区块是否为非空块时,所述处理器被促使:基于最新区块对应的第一存储属性判断所述最新区块是否为非空块;若所述最新区块为非空块,则判断所述最新区块的前一区块是否为非空块;若所述最新区块为空块,则确定与所述最新区块的区块高度最接近的非空块,并判断所述非空块的前一区块是否为非空块。Optionally, the first storage attribute indicates whether the current block is a non-empty block, and when determining whether each block is a non-empty block based on the first storage attribute, the processor is prompted: based on the latest block The corresponding first storage attribute judges whether the latest block is a non-empty block; if the latest block is a non-empty block, then judges whether the previous block of the latest block is a non-empty block; if the If the latest block is an empty block, determine the non-empty block closest to the block height of the latest block, and determine whether the previous block of the non-empty block is a non-empty block.
可选的,所述第一存储属性的记录过程,所述处理器被促使:区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第一存储属性记录逻辑记录表征所述业务交易所在区块为非空块的第一存储属性。Optionally, in the recording process of the first storage attribute, the processor is prompted: after the blockchain node receives the business transaction, execute the business transaction to call the first storage attribute in the smart contract to record the logical record representation The block in which the business transaction is located is the first storage attribute of a non-empty block.
可选的,所述第一存储属性的记录过程,所述处理器被促使:区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第一存储属性记录逻辑判断所述第一存储属性记录交易所在区块上是否存储有业务交易,并基于判断结果记录所述第一存储属性记录交易所在区块对应的第一存储属性。Optionally, in the recording process of the first storage attribute, the processor is prompted: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call The logic of the first storage attribute record in the smart contract judges whether there is a business transaction stored in the block of the first storage attribute record exchange, and records the first storage attribute record transaction corresponding to the block based on the judgment result. A stored attribute.
可选的,所述区块链节点上存储有各区块对应的第二存储属性,所述第二存储属性表征与本区块的区块高度最接近的非空块,在确定与所述最新区块的区块高度最接近的非空块时,所述处理器被促使:从区块链节点上获取所述最新区块对应的第二存储属性;基于所述第二存储属性确定与所述最新区块的区块高度最接近的非空块。Optionally, the second storage attribute corresponding to each block is stored on the block chain node, and the second storage attribute represents the non-empty block closest to the block height of this block. When the non-empty block whose block height is the closest, the processor is prompted to: obtain the second storage attribute corresponding to the latest block from the blockchain node; The non-empty block closest to the block height of the latest block.
可选的,所述第二存储属性的记录过程,所述处理器被促使:区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第二存储属性记录逻辑确定与所述业务交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述业务交易所在区块对应的第二存储属性。Optionally, in the recording process of the second storage attribute, the processor is prompted: after the blockchain node receives the business transaction, executes the business transaction to call the second storage attribute recording logic in the smart contract to determine and The non-empty block with the closest block height of the block where the business transaction is located, and record the second storage attribute corresponding to the block where the business transaction is located based on the non-empty block.
可选的,所述第二存储属性的记录过程,所述处理器被促使:区块链节点接收到周期性发送的第二存储属性记录交易后,执行所述第二存储属性记录交易以调用智能合约中的第二存储属性记录逻辑确定与所述第二存储属性更新交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述第二存储属性更新交易所在区块对应的第二存储属性。Optionally, in the process of recording the second storage attribute, the processor is prompted: after the blockchain node receives the periodically sent second storage attribute record transaction, executes the second storage attribute record transaction to call The second storage attribute recording logic in the smart contract determines the non-empty block closest to the block height of the block where the second storage attribute update transaction is located, and records the second storage attribute update based on the non-empty block The second storage attribute corresponding to the block where the transaction is located.
可选的,所述第一存储属性表征本区块的前一区块是否为空块,在基于所述第一存储属性确定各个区块是否为非空块时,所述处理器被促使:针对所述最新区块,基于所述第一存储属性确定所述最新区块的前一区块是否为非空块;若所述前一区块为非空块,则基于所述前一区块对应的第一存储属性判断所述前一区块的前一区块是否为非空块;若所述前一区块为空块,则确定与所述前一区块的区块高度最接近的非空块,并基于所述非空块对应的第一存储属性判断所述非空块的前一区块是否为空块。Optionally, the first storage attribute indicates whether the previous block of the current block is an empty block, and when determining whether each block is a non-empty block based on the first storage attribute, the processor is prompted to: For the latest block, determine whether the previous block of the latest block is a non-empty block based on the first storage attribute; if the previous block is a non-empty block, then based on the previous block The first storage attribute corresponding to the block judges whether the previous block of the previous block is a non-empty block; if the previous block is an empty block, then determine the block height closest to the previous block a non-empty block that is close to it, and judge whether the previous block of the non-empty block is an empty block based on the first storage attribute corresponding to the non-empty block.
可选的,所述第一存储属性的记录过程,所述处理器被促使:区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第三存储属性记录逻辑判断所述第一存储属性记录交易所在区块的前一区块是否 存储有业务交易,并基于判断结果生成所述第一存储属性记录交易所在区块对应的第一存储属性。Optionally, in the recording process of the first storage attribute, the processor is prompted: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call The third storage attribute record logic in the smart contract judges whether the previous block of the first storage attribute record transaction stores business transactions, and generates the first storage attribute record transaction area based on the judgment result The first storage attribute corresponding to the block.
可选的,数据同步的触发条件,包括:接收到数据同步请求后;和/或达到数据同步周期。Optionally, the trigger condition for data synchronization includes: after receiving a data synchronization request; and/or reaching a data synchronization period.
与前述基于区块链的数据同步方法的实施例相对应,本说明书还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,该程序被处理器执行时实现以下步骤:一种基于区块链的数据同步方法,应用于数据同步系统,所述数据同步系统与区块链节点对接,所述方法包括:达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;将同步队列内的业务交易同步至业务系统。Corresponding to the aforementioned embodiments of the blockchain-based data synchronization method, this specification also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the following is achieved: Steps: a blockchain-based data synchronization method applied to a data synchronization system, the data synchronization system is connected to a blockchain node, and the method includes: when a trigger condition for data synchronization is reached, the data is obtained from the blockchain node The first storage attribute of each block on the block chain; determine whether each block is a non-empty block based on the first storage attribute, and add the business transaction in the block determined to be a non-empty block to the synchronization queue, the Non-empty blocks are blocks that store business transactions; synchronize the business transactions in the synchronization queue to the business system.
可选的,所述第一存储属性表征本区块是否为非空块,所述基于所述第一存储属性确定各个区块是否为非空块,包括:从最新区块开始,按照区块高度从高到底的顺序,基于各个区块的第一存储属性依次判断各个区块是否为非空块。Optionally, the first storage attribute indicates whether the block is a non-empty block, and determining whether each block is a non-empty block based on the first storage attribute includes: starting from the latest block, according to the block In order of height from high to low, it is determined whether each block is a non-empty block based on the first storage attribute of each block.
可选的,所述第一存储属性表征本区块是否为非空块,所述基于所述第一存储属性确定各个区块是否为非空块,包括:基于最新区块对应的第一存储属性判断所述最新区块是否为非空块;若所述最新区块为非空块,则判断所述最新区块的前一区块是否为非空块;若所述最新区块为空块,则确定与所述最新区块的区块高度最接近的非空块,并判断所述非空块的前一区块是否为非空块。Optionally, the first storage attribute indicates whether the current block is a non-empty block, and determining whether each block is a non-empty block based on the first storage attribute includes: based on the first storage corresponding to the latest block attribute to determine whether the latest block is a non-empty block; if the latest block is a non-empty block, then judge whether the previous block of the latest block is a non-empty block; if the latest block is empty block, then determine the non-empty block closest to the block height of the latest block, and judge whether the previous block of the non-empty block is a non-empty block.
可选的,所述第一存储属性的记录过程,包括:区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第一存储属性记录逻辑记录表征所述业务交易所在区块为非空块的第一存储属性。Optionally, the recording process of the first storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the first storage attribute record logic record in the smart contract to represent the business exchange The block is the first storage attribute of a non-empty block.
可选的,所述第一存储属性的记录过程,包括:区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第一存储属性记录逻辑判断所述第一存储属性记录交易所在区块上是否存储有业务交易,并基于判断结果记录所述第一存储属性记录交易所在区块对应的第一存储属性。Optionally, the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract A storage attribute record logic judges whether a business transaction is stored on the block of the first storage attribute record transaction, and records the first storage attribute corresponding to the block where the first storage attribute record transaction is located based on the judgment result.
可选的,所述区块链节点上存储有各区块对应的第二存储属性,所述第二存储属性表征与本区块的区块高度最接近的非空块,所述确定与所述最新区块的区块高度最接近的非空块,包括:从区块链节点上获取所述最新区块对应的第二存储属性;基于所述第 二存储属性确定与所述最新区块的区块高度最接近的非空块。Optionally, the second storage attribute corresponding to each block is stored on the block chain node, the second storage attribute represents the non-empty block closest to the block height of the block, and the determination is related to the The non-empty block whose block height is closest to the latest block includes: obtaining the second storage attribute corresponding to the latest block from the blockchain node; determining the relationship between the latest block and the latest block based on the second storage attribute The closest non-empty block to the block height.
可选的,所述第二存储属性的记录过程,包括:区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第二存储属性记录逻辑确定与所述业务交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述业务交易所在区块对应的第二存储属性。Optionally, the recording process of the second storage attribute includes: after the blockchain node receives the business transaction, executes the business transaction to call the second storage attribute recording logic in the smart contract to determine the business transaction In the non-empty block closest to the block height of the block, and based on the non-empty block, record the second storage attribute corresponding to the block where the business transaction is located.
可选的,所述第二存储属性的记录过程,包括:区块链节点接收到周期性发送的第二存储属性记录交易后,执行所述第二存储属性记录交易以调用智能合约中的第二存储属性记录逻辑确定与所述第二存储属性更新交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述第二存储属性更新交易所在区块对应的第二存储属性。Optionally, the recording process of the second storage attribute includes: after the block chain node receives the second storage attribute record transaction sent periodically, execute the second storage attribute record transaction to call the first storage attribute record transaction in the smart contract The second storage attribute recording logic determines the non-empty block closest to the block height of the block where the second storage attribute update transaction is located, and records the block where the second storage attribute update transaction resides based on the non-empty block The corresponding second storage attribute.
可选的,所述第一存储属性表征本区块的前一区块是否为空块,所述基于所述第一存储属性确定各个区块是否为非空块,包括:针对所述最新区块,基于所述第一存储属性确定所述最新区块的前一区块是否为非空块;若所述前一区块为非空块,则基于所述前一区块对应的第一存储属性判断所述前一区块的前一区块是否为非空块;若所述前一区块为空块,则确定与所述前一区块的区块高度最接近的非空块,并基于所述非空块对应的第一存储属性判断所述非空块的前一区块是否为空块。Optionally, the first storage attribute indicates whether the previous block of this block is an empty block, and the determining whether each block is a non-empty block based on the first storage attribute includes: for the latest block block, based on the first storage attribute to determine whether the previous block of the latest block is a non-empty block; if the previous block is a non-empty block, based on the first block corresponding to the previous block The storage attribute judges whether the previous block of the previous block is a non-empty block; if the previous block is an empty block, then determine the non-empty block closest to the block height of the previous block , and judge whether the previous block of the non-empty block is an empty block based on the first storage attribute corresponding to the non-empty block.
可选的,所述第一存储属性的记录过程,包括:区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第三存储属性记录逻辑判断所述第一存储属性记录交易所在区块的前一区块是否存储有业务交易,并基于判断结果生成所述第一存储属性记录交易所在区块对应的第一存储属性。Optionally, the recording process of the first storage attribute includes: after the blockchain node receives the first storage attribute record transaction sent periodically, executes the first storage attribute record transaction to call the first storage attribute record transaction in the smart contract Three storage attribute record logic judges whether the previous block of the first storage attribute record transaction stores business transactions, and generates the first storage attribute record transaction corresponding to the first block based on the judgment result. store attributes.
可选的,数据同步的触发条件,包括:接收到数据同步请求后;和/或达到数据同步周期。Optionally, the trigger condition for data synchronization includes: after receiving a data synchronization request; and/or reaching a data synchronization period.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other implementations are within the scope of the following 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. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. Multitasking and parallel processing are also possible or may be advantageous in certain embodiments.
以上所述仅为本说明书的较佳实施例而已,并不用以限制本说明书,凡在本说明书的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书保护的范围之内。The above descriptions are only preferred embodiments of this specification, and are not intended to limit this specification. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this specification shall be included in this specification. within the scope of protection.

Claims (23)

  1. 一种基于区块链的数据同步方法,应用于数据同步系统,所述数据同步系统与区块链节点对接,所述方法包括:A block chain-based data synchronization method applied to a data synchronization system, the data synchronization system docking with a block chain node, the method comprising:
    达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;When the trigger condition of data synchronization is reached, the first storage attribute of each block on the blockchain is obtained from the blockchain node;
    基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;Determine whether each block is a non-empty block based on the first storage attribute, and add the business transaction in the block determined to be a non-empty block to the synchronization queue, and the non-empty block is a block storing a business transaction;
    将同步队列内的业务交易同步至业务系统。Synchronize the business transactions in the synchronization queue to the business system.
  2. 根据权利要求1所述方法,所述第一存储属性表征本区块是否为非空块,所述基于所述第一存储属性确定各个区块是否为非空块,包括:According to the method according to claim 1, the first storage attribute indicates whether the block is a non-empty block, and determining whether each block is a non-empty block based on the first storage attribute includes:
    从最新区块开始,按照区块高度从高到底的顺序,基于各个区块的第一存储属性依次判断各个区块是否为非空块。Starting from the latest block, according to the sequence of block height from high to low, it is judged whether each block is a non-empty block based on the first storage attribute of each block.
  3. 根据权利要求1所述方法,所述第一存储属性表征本区块是否为非空块,所述基于所述第一存储属性确定各个区块是否为非空块,包括:According to the method according to claim 1, the first storage attribute indicates whether the block is a non-empty block, and determining whether each block is a non-empty block based on the first storage attribute includes:
    基于最新区块对应的第一存储属性判断所述最新区块是否为非空块;judging whether the latest block is a non-empty block based on the first storage attribute corresponding to the latest block;
    若所述最新区块为非空块,则判断所述最新区块的前一区块是否为非空块;If the latest block is a non-empty block, then judging whether the previous block of the latest block is a non-empty block;
    若所述最新区块为空块,则确定与所述最新区块的区块高度最接近的非空块,并判断所述非空块的前一区块是否为非空块。If the latest block is an empty block, determine the non-empty block closest to the block height of the latest block, and determine whether the previous block of the non-empty block is a non-empty block.
  4. 根据权利要求2或3所述方法,所述第一存储属性的记录过程,包括:According to the method according to claim 2 or 3, the recording process of the first storage attribute comprises:
    区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第一存储属性记录逻辑记录表征所述业务交易所在区块为非空块的第一存储属性。After the blockchain node receives the business transaction, it executes the business transaction to call the first storage attribute record logic in the smart contract to record the first storage attribute that indicates that the block in which the business transaction is located is a non-empty block.
  5. 根据权利要求2或3所述方法,所述第一存储属性的记录过程,包括:According to the method according to claim 2 or 3, the recording process of the first storage attribute comprises:
    区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第一存储属性记录逻辑判断所述第一存储属性记录交易所在区块上是否存储有业务交易,并基于判断结果记录所述第一存储属性记录交易所在区块对应的第一存储属性。After the block chain node receives the first storage attribute record transaction sent periodically, execute the first storage attribute record transaction to call the first storage attribute record logic in the smart contract to determine the location of the first storage attribute record transaction Whether there is a business transaction stored in the block, and based on the judgment result, record the first storage attribute corresponding to the block where the transaction is located.
  6. 根据权利要求3所述方法,所述区块链节点上存储有各区块对应的第二存储属性,所述第二存储属性表征与本区块的区块高度最接近的非空块,所述确定与所述最新区块的区块高度最接近的非空块,包括:According to the method according to claim 3, the second storage attribute corresponding to each block is stored on the block chain node, and the second storage attribute represents the non-empty block closest to the block height of this block, and the Determine the non-empty block closest to the block height of the latest block, including:
    从区块链节点上获取所述最新区块对应的第二存储属性;Obtaining the second storage attribute corresponding to the latest block from the blockchain node;
    基于所述第二存储属性确定与所述最新区块的区块高度最接近的非空块。Determine a non-empty block closest to the block height of the latest block based on the second storage attribute.
  7. 根据权利要求6所述方法,所述第二存储属性的记录过程,包括:According to the method according to claim 6, the recording process of the second storage attribute comprises:
    区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第二存储属性记录逻辑确定与所述业务交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述业务交易所在区块对应的第二存储属性。After the blockchain node receives the business transaction, it executes the business transaction to call the second storage attribute recording logic in the smart contract to determine the non-empty block closest to the block height of the block where the business transaction is located, and based on The non-empty block records the second storage attribute corresponding to the block where the business transaction is located.
  8. 根据权利要求6所述方法,所述第二存储属性的记录过程,包括:According to the method according to claim 6, the recording process of the second storage attribute comprises:
    区块链节点接收到周期性发送的第二存储属性记录交易后,执行所述第二存储属性记录交易以调用智能合约中的第二存储属性记录逻辑确定与所述第二存储属性更新交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述第二存储属性更新交易所在区块对应的第二存储属性。After receiving the periodically sent second storage attribute record transaction, the block chain node executes the second storage attribute record transaction to call the second storage attribute record logic in the smart contract to determine the exchange with the second storage attribute update In the non-empty block closest to the block height of the block, and based on the second storage attribute recorded in the non-empty block, the second storage attribute corresponding to the block where the transaction is located is updated.
  9. 根据权利要求1所述方法,所述第一存储属性表征本区块的前一区块是否为空块,所述基于所述第一存储属性确定各个区块是否为非空块,包括:According to the method according to claim 1, the first storage attribute indicates whether the previous block of the current block is an empty block, and determining whether each block is a non-empty block based on the first storage attribute includes:
    针对最新区块,基于所述第一存储属性确定所述最新区块的前一区块是否为非空块;For the latest block, determine whether the previous block of the latest block is a non-empty block based on the first storage attribute;
    若所述前一区块为非空块,则基于所述前一区块对应的第一存储属性判断所述前一区块的前一区块是否为非空块;If the previous block is a non-empty block, then judging whether the previous block of the previous block is a non-empty block based on the first storage attribute corresponding to the previous block;
    若所述前一区块为空块,则确定与所述前一区块的区块高度最接近的非空块,并基于所述非空块对应的第一存储属性判断所述非空块的前一区块是否为空块。If the previous block is an empty block, determine the non-empty block closest to the block height of the previous block, and judge the non-empty block based on the first storage attribute corresponding to the non-empty block Whether the previous block of is an empty block.
  10. 根据权利要求9所述方法,所述第一存储属性的记录过程,包括:According to the method according to claim 9, the recording process of the first storage attribute comprises:
    区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第三存储属性记录逻辑判断所述第一存储属性记录交易所在区块的前一区块是否存储有业务交易,并基于判断结果生成所述第一存储属性记录交易所在区块对应的第一存储属性。After receiving the periodically sent first storage attribute record transaction, the blockchain node executes the first storage attribute record transaction to call the third storage attribute record logic in the smart contract to determine the location of the first storage attribute record transaction. Whether the previous block of the block stores business transactions, and based on the judgment result, generate the first storage attribute corresponding to the block where the first storage attribute records the transaction.
  11. 根据权利要求1所述方法,数据同步的触发条件,包括:According to the method according to claim 1, the triggering conditions for data synchronization include:
    接收到数据同步请求后;和/或达到数据同步周期。After a data synchronization request is received; and/or a data synchronization period is reached.
  12. 一种基于区块链的数据同步装置,包括:A data synchronization device based on blockchain, including:
    获取单元,达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;The acquisition unit, when the trigger condition of data synchronization is reached, acquires the first storage attribute of each block on the blockchain from the blockchain node;
    确定单元,基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;The determination unit determines whether each block is a non-empty block based on the first storage attribute, and adds the business transaction in the block determined to be a non-empty block to the synchronization queue, and the non-empty block is an area storing a business transaction piece;
    同步单元,将同步队列内的业务交易同步至业务系统。The synchronization unit synchronizes the business transactions in the synchronization queue to the business system.
  13. 根据权利要求12所述装置,所述第一存储属性表征本区块是否为非空块,所述确定单元在基于所述第一存储属性确定各个区块是否为非空块时:According to the device according to claim 12, the first storage attribute represents whether the block is a non-empty block, and when the determining unit determines whether each block is a non-empty block based on the first storage attribute:
    从最新区块开始,按照区块高度从高到底的顺序,基于各个区块的第一存储属性依 次判断各个区块是否为非空块。Starting from the latest block, according to the order of block height from high to low, judge whether each block is a non-empty block based on the first storage attribute of each block.
  14. 根据权利要求12所述装置,所述第一存储属性表征本区块是否为非空块,所述确定单元在基于所述第一存储属性确定各个区块是否为非空块时:According to the device according to claim 12, the first storage attribute represents whether the block is a non-empty block, and when the determining unit determines whether each block is a non-empty block based on the first storage attribute:
    基于最新区块对应的第一存储属性判断所述最新区块是否为非空块;judging whether the latest block is a non-empty block based on the first storage attribute corresponding to the latest block;
    若所述最新区块为非空块,则判断所述最新区块的前一区块是否为非空块;If the latest block is a non-empty block, then judging whether the previous block of the latest block is a non-empty block;
    若所述最新区块为空块,则确定与所述最新区块的区块高度最接近的非空块,并判断所述非空块的前一区块是否为非空块。If the latest block is an empty block, determine the non-empty block closest to the block height of the latest block, and determine whether the previous block of the non-empty block is a non-empty block.
  15. 根据权利要求13或14所述装置,所述第一存储属性的记录过程,包括:According to the device according to claim 13 or 14, the recording process of the first stored attribute comprises:
    区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第一存储属性记录逻辑记录表征所述业务交易所在区块为非空块的第一存储属性。After the blockchain node receives the business transaction, it executes the business transaction to call the first storage attribute record logic in the smart contract to record the first storage attribute that indicates that the block in which the business transaction is located is a non-empty block.
  16. 根据权利要求13或14所述装置,所述第一存储属性的记录过程,包括:According to the device according to claim 13 or 14, the recording process of the first stored attribute comprises:
    区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第一存储属性记录逻辑判断所述第一存储属性记录交易所在区块上是否存储有业务交易,并基于判断结果记录所述第一存储属性记录交易所在区块对应的第一存储属性。After the block chain node receives the first storage attribute record transaction sent periodically, execute the first storage attribute record transaction to call the first storage attribute record logic in the smart contract to determine the location of the first storage attribute record transaction Whether there is a business transaction stored in the block, and based on the judgment result, record the first storage attribute corresponding to the block where the transaction is located.
  17. 根据权利要求14所述装置,所述区块链节点上存储有各区块对应的第二存储属性,所述第二存储属性表征与本区块的区块高度最接近的非空块,所述确定单元在确定与所述最新区块的区块高度最接近的非空块时:According to the device according to claim 14, the second storage attribute corresponding to each block is stored on the block chain node, and the second storage attribute represents the non-empty block closest to the block height of the block, and the When the determination unit determines the non-empty block closest to the block height of the latest block:
    从区块链节点上获取所述最新区块对应的第二存储属性;Obtaining the second storage attribute corresponding to the latest block from the blockchain node;
    基于所述第二存储属性确定与所述最新区块的区块高度最接近的非空块。Determine a non-empty block closest to the block height of the latest block based on the second storage attribute.
  18. 根据权利要求17所述装置,所述第二存储属性的记录过程,包括:According to the device according to claim 17, the recording process of the second storage attribute comprises:
    区块链节点接收到业务交易后,执行所述业务交易以调用智能合约中的第二存储属性记录逻辑确定与所述业务交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述业务交易所在区块对应的第二存储属性。After the blockchain node receives the business transaction, it executes the business transaction to call the second storage attribute recording logic in the smart contract to determine the non-empty block closest to the block height of the block where the business transaction is located, and based on The non-empty block records the second storage attribute corresponding to the block where the business transaction is located.
  19. 根据权利要求17所述装置,所述第二存储属性的记录过程,包括:According to the device according to claim 17, the recording process of the second storage attribute comprises:
    区块链节点接收到周期性发送的第二存储属性记录交易后,执行所述第二存储属性记录交易以调用智能合约中的第二存储属性记录逻辑确定与所述第二存储属性更新交易所在区块的区块高度最接近的非空块,并基于所述非空块记录所述第二存储属性更新交易所在区块对应的第二存储属性。After receiving the periodically sent second storage attribute record transaction, the block chain node executes the second storage attribute record transaction to call the second storage attribute record logic in the smart contract to determine the exchange with the second storage attribute update In the non-empty block closest to the block height of the block, and based on the second storage attribute recorded in the non-empty block, the second storage attribute corresponding to the block where the transaction is located is updated.
  20. 根据权利要求12所述装置,所述第一存储属性表征本区块的前一区块是否为空块,所述确定单元在基于所述第一存储属性确定各个区块是否为非空块时:According to the device according to claim 12, the first storage attribute indicates whether the previous block of the current block is an empty block, and the determination unit determines whether each block is a non-empty block based on the first storage attribute :
    针对最新区块,基于所述第一存储属性确定所述最新区块的前一区块是否为非空块;For the latest block, determine whether the previous block of the latest block is a non-empty block based on the first storage attribute;
    若所述前一区块为非空块,则基于所述前一区块对应的第一存储属性判断所述前一区块的前一区块是否为非空块;If the previous block is a non-empty block, then judging whether the previous block of the previous block is a non-empty block based on the first storage attribute corresponding to the previous block;
    若所述前一区块为空块,则确定与所述前一区块的区块高度最接近的非空块,并基于所述非空块对应的第一存储属性判断所述非空块的前一区块是否为空块。If the previous block is an empty block, determine the non-empty block closest to the block height of the previous block, and judge the non-empty block based on the first storage attribute corresponding to the non-empty block Whether the previous block of is an empty block.
  21. 根据权利要求20所述装置,所述第一存储属性的记录过程,包括:According to the device according to claim 20, the recording process of the first stored attribute comprises:
    区块链节点接收到周期性发送的第一存储属性记录交易后,执行所述第一存储属性记录交易以调用智能合约中的第三存储属性记录逻辑判断所述第一存储属性记录交易所在区块的前一区块是否存储有业务交易,并基于判断结果生成所述第一存储属性记录交易所在区块对应的第一存储属性。After receiving the periodically sent first storage attribute record transaction, the blockchain node executes the first storage attribute record transaction to call the third storage attribute record logic in the smart contract to determine the location of the first storage attribute record transaction. Whether the previous block of the block stores business transactions, and based on the judgment result, generate the first storage attribute corresponding to the block where the first storage attribute records the transaction.
  22. 根据权利要求12所述装置,数据同步的触发条件,包括:According to the device according to claim 12, the triggering conditions for data synchronization include:
    接收到数据同步请求后;和/或达到数据同步周期。After a data synchronization request is received; and/or a data synchronization period is reached.
  23. 一种基于区块链的数据同步装置,包括:A data synchronization device based on blockchain, including:
    处理器;processor;
    用于存储机器可执行指令的存储器;memory for storing machine-executable instructions;
    其中,通过读取并执行所述存储器存储的与基于区块链的数据同步逻辑对应的机器可执行指令,所述处理器被促使:Wherein, by reading and executing the machine-executable instructions stored in the memory and corresponding to the blockchain-based data synchronization logic, the processor is caused to:
    达到数据同步的触发条件时,从区块链节点获取区块链上各个区块的第一存储属性;When the trigger condition of data synchronization is reached, the first storage attribute of each block on the blockchain is obtained from the blockchain node;
    基于所述第一存储属性确定各个区块是否为非空块,并将确定为非空块的区块中的业务交易加入同步队列,所述非空块为存储有业务交易的区块;Determine whether each block is a non-empty block based on the first storage attribute, and add the business transaction in the block determined to be a non-empty block to the synchronization queue, and the non-empty block is a block storing a business transaction;
    将同步队列内的业务交易同步至业务系统。Synchronize the business transactions in the synchronization queue to the business system.
PCT/CN2022/100606 2021-07-07 2022-06-23 Blockchain-based data synchronization method and apparatus WO2023279970A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110767447.1 2021-07-07
CN202110767447.1A CN113596107A (en) 2021-07-07 2021-07-07 Data synchronization method and device based on block chain

Publications (1)

Publication Number Publication Date
WO2023279970A1 true WO2023279970A1 (en) 2023-01-12

Family

ID=78246592

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/100606 WO2023279970A1 (en) 2021-07-07 2022-06-23 Blockchain-based data synchronization method and apparatus

Country Status (2)

Country Link
CN (1) CN113596107A (en)
WO (1) WO2023279970A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113596107A (en) * 2021-07-07 2021-11-02 支付宝(杭州)信息技术有限公司 Data synchronization method and device based on block chain
CN115186035B (en) * 2022-09-13 2022-11-22 腾讯科技(深圳)有限公司 Block processing method, related system, storage medium and server

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106874393A (en) * 2017-01-13 2017-06-20 北京众享比特科技有限公司 Synchronizing traffic data method and system, Database Systems based on block chain
CN108596588A (en) * 2018-04-28 2018-09-28 百度在线网络技术(北京)有限公司 A kind of processing method of block data, device, computing device and storage medium
CN109255057A (en) * 2018-09-18 2019-01-22 百度在线网络技术(北京)有限公司 Block generation method, device, equipment and storage medium
CN110298657A (en) * 2018-03-21 2019-10-01 中思博安科技(北京)有限公司 A kind of block chain common recognition method, relevant apparatus and system
US20200167779A1 (en) * 2018-11-27 2020-05-28 Akamai Technologies, Inc. High performance distributed system of record with confidence-based consensus
CN111444512A (en) * 2019-01-17 2020-07-24 杨税令 Mobile terminal blocking method and system for block chain
CN111737265A (en) * 2020-07-24 2020-10-02 支付宝(杭州)信息技术有限公司 Block data access method, block data storage method and device
CN112069169A (en) * 2020-07-30 2020-12-11 北京奇艺世纪科技有限公司 Block data storage method and device, electronic equipment and readable storage medium
US20200403777A1 (en) * 2018-08-31 2020-12-24 Simplecredit Micro-Lending Co., Ltd. Blockchain System, Information Sharing Method and Related Equipment
CN112199716A (en) * 2020-09-30 2021-01-08 卓望数码技术(深圳)有限公司 Block output method, device, equipment and storage medium of block chain
CN113596107A (en) * 2021-07-07 2021-11-02 支付宝(杭州)信息技术有限公司 Data synchronization method and device based on block chain

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109446273B (en) * 2018-12-04 2022-07-22 深圳前海环融联易信息科技服务有限公司 Data synchronization method and device of block chain, computer equipment and storage medium
US11876910B2 (en) * 2019-01-31 2024-01-16 Salesforce, Inc. Systems, methods, and apparatuses for implementing a multi tenant blockchain platform for managing Einstein platform decisions using distributed ledger technology (DLT)
CN110493148B (en) * 2019-08-12 2022-04-01 深圳前海微众银行股份有限公司 Block processing, block consensus and block synchronization method and device
CN110392121B (en) * 2019-09-02 2021-10-01 杭州复杂美科技有限公司 Parallel chain block generation method, device and storage medium
CN111078700A (en) * 2019-12-13 2020-04-28 山东众阳健康科技集团有限公司 Data synchronization method and system based on block chain
CN111339191B (en) * 2020-02-20 2023-05-26 百度在线网络技术(北京)有限公司 Data storage method, device, equipment and medium of block chain
CN111813866B (en) * 2020-07-30 2021-03-16 河南中盾云安信息科技有限公司 Improved block chain account book synchronization method

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106874393A (en) * 2017-01-13 2017-06-20 北京众享比特科技有限公司 Synchronizing traffic data method and system, Database Systems based on block chain
CN110298657A (en) * 2018-03-21 2019-10-01 中思博安科技(北京)有限公司 A kind of block chain common recognition method, relevant apparatus and system
CN108596588A (en) * 2018-04-28 2018-09-28 百度在线网络技术(北京)有限公司 A kind of processing method of block data, device, computing device and storage medium
US20200403777A1 (en) * 2018-08-31 2020-12-24 Simplecredit Micro-Lending Co., Ltd. Blockchain System, Information Sharing Method and Related Equipment
CN109255057A (en) * 2018-09-18 2019-01-22 百度在线网络技术(北京)有限公司 Block generation method, device, equipment and storage medium
US20200167779A1 (en) * 2018-11-27 2020-05-28 Akamai Technologies, Inc. High performance distributed system of record with confidence-based consensus
CN111444512A (en) * 2019-01-17 2020-07-24 杨税令 Mobile terminal blocking method and system for block chain
CN111737265A (en) * 2020-07-24 2020-10-02 支付宝(杭州)信息技术有限公司 Block data access method, block data storage method and device
CN112069169A (en) * 2020-07-30 2020-12-11 北京奇艺世纪科技有限公司 Block data storage method and device, electronic equipment and readable storage medium
CN112199716A (en) * 2020-09-30 2021-01-08 卓望数码技术(深圳)有限公司 Block output method, device, equipment and storage medium of block chain
CN113596107A (en) * 2021-07-07 2021-11-02 支付宝(杭州)信息技术有限公司 Data synchronization method and device based on block chain

Also Published As

Publication number Publication date
CN113596107A (en) 2021-11-02

Similar Documents

Publication Publication Date Title
WO2023279970A1 (en) Blockchain-based data synchronization method and apparatus
EP2490104B1 (en) Method and mobile terminal for controlling application in the mobile terminal
CN111506580B (en) Transaction storage method based on centralized block chain type account book
CN112613964A (en) Account checking method, account checking device, account checking equipment and storage medium
CN110363663A (en) Block chain-based data batch processing method, device, equipment and storage medium
CN110928489B (en) Data writing method and device and storage node
CN110458681B (en) Data reconciliation decision method, device, server and storage medium
CN111625592A (en) Load balancing method and device for distributed database
WO2019179252A1 (en) Sample playback data access method and device
CN111459948B (en) Transaction integrity verification method based on centralized block chain type account book
WO2020088072A1 (en) Failover data processing method, apparatus, and system
US9563366B2 (en) Using queues corresponding to attribute values associated with units of work and sub-units of the unit of work to select the units of work and their sub-units to process
WO2018077092A1 (en) Saving method applied to distributed file system, apparatus and distributed file system
CN111913807A (en) Event processing method, system and device based on multiple storage areas
CN110928565A (en) Hotspot account data update method, device, server and storage medium
CN113329078A (en) Data storage method and device
WO2024104295A1 (en) Thermal migration control method and apparatus for virtual machine, and medium and computer device
US20220343192A1 (en) Management apparatus and management method
WO2024119930A1 (en) Scheduling method and apparatus, and computer device and storage medium
CN116896763A (en) Delay test method, device, computer equipment and storage medium
CN110046172A (en) In line computation data processing method and system
WO2021218626A1 (en) Data storage method and apparatus, device, and storage medium
CN109656901A (en) Data processing method and device, electronic equipment
US11301442B2 (en) Method and system for using array level time buckets to efficiently calculate top contributors using relevant performance metric
CN109039695A (en) Business fault treatment method, device and equipment

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

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

Country of ref document: EP

Kind code of ref document: A1