Computer implementation method for synchronizing blockchain status data
It mainly describes how to optimize the synchronization process of blockchain status data by organizing the account status information in the blockchain into a Merkle status tree. The following are the core points of the document:
Background and purpose of the invention:
Technical characteristics of blockchain: Blockchain technology has the characteristics of decentralization, openness, transparency and fast data synchronization, and is widely used in many fields.
Data synchronization problem: In the prior art, when node devices synchronize blockchain status data, there are problems such as large amount of synchronized data and slow synchronization rate.
Purpose of the invention: Propose an efficient blockchain status data synchronization method, which improves the synchronization rate by instantly obtaining the current Merkle status tree of the latest block.
Design of Merkle status tree:
Current Merkle status tree: It is organized by the latest account status of each blockchain account and is used to store the latest status of each account.
Historical Merkle status tree: It is organized by the historical account status of each blockchain account and is used to store the historical status of the account.
Data structure difference: The current Merkle status tree mainly maintains the latest status and has a small amount of data; the historical Merkle status tree contains historical status and has a large amount of data.
Synchronization method:
Synchronization instruction reception: The blockchain node device receives the data synchronization instruction for the Merkle state tree.
Instant acquisition: Instantly obtain the current Merkle state tree of the latest block stored in the database of other node devices in the blockchain.
Storage and synchronization: Store the current Merkle state tree obtained to the local database to complete instant data synchronization.
Synchronization optimization:
Offline acquisition of historical state tree: Obtain the historical Merkle state tree of each block of other node devices offline in the background and store it in the local database.
Block lag processing: Determine whether the latest block stored by other node devices lags behind the latest block of the blockchain. If it lags, re-execute the transaction between the lagging blocks and update the state tree in the local database.
Data organization and storage:
Data structure selection: The current Merkle state tree adopts the data structure of B+ tree, and the historical Merkle state tree adopts the data structure of LSM tree to adapt to different read and write requirements.
Database type: Use Key-Value database, such as LevelDB or Rocksdb database based on LevelDB architecture, for data storage.
Key-value pair storage: The data nodes on the Merkle state tree are stored in the form of Key-Value pairs. The key of the current Merkle state tree is the node ID, and the key of the historical Merkle state tree is the hash value of the data content.
Application scenarios and devices:
Application scenarios: Applicable to the state data synchronization of blockchain node devices when they recover from a crash or join a new blockchain.
Implementation devices: Specific implementation devices include personal computers, laptops, smart phones, etc., and synchronization operations are performed through devices such as processors, memory and storage media.
Technical effects and advantages:
Improve synchronization rate: By instantly obtaining the current Merkle state tree of the latest block, the amount of synchronization data is reduced and the synchronization rate is improved.
Save storage space: Through multitasking technology, the storage space in the historical Merkle state tree is effectively saved.
Distributed consistency: By re-executing transactions between delayed blocks, ensure that the state tree in the local database is distributedly consistent with other nodes in the blockchain network.
These key points comprehensively summarize the core content of the document, including the background of the invention, the design of the Merkle state tree, synchronization methods, synchronization optimization, data organization and storage, application scenarios and equipment, as well as technical effects and advantages.