IX. Storage Module
The storage module of the Mova payment public blockchain is responsible for the persistent storage of event data, transaction data, ledger state data, and historical read-write sets. It serves as the core guarantee for system-wide data consistency and traceability. This module not only provides high-performance write capabilities but also supports flexible data recovery and efficient query mechanisms, ensuring high real-time responsiveness and reliability required in payment scenarios.
9.1 Ledger Storage Processing Flow
9.1.1 Event Submission and Storage Process
Once an event enters consensus, it goes through the following storage procedures:
Write-Ahead Logging (WAL)
- All serialized event data, read-write set lists, and the latest event height are first written to the EventBinaryLog (the write-ahead log), enabling rapid recovery in the event of system exceptions.
- The same data is also written into an in-memory cache area to improve overall performance.
Event and Transaction Data Storage
- The EventDB records the basic information of the event and the list of associated transaction IDs, while individual transaction data is stored using the TxID as the key.
- A mapping index is created between EventHash and EventHeight.
- The latest event height is used as a checkpoint for batch write operations to ensure atomicity.
State Database Update
- The StateDB stores the on-chain state modified by each transaction, with keys composed of contract name + object primary key.
- Like other modules, the database synchronizes at batch intervals using EventHeight as the synchronization checkpoint.
Read-Write Set Recording
- Historical read-write set data is written into HistoryDB, using TxID as the primary key.
- These records are used for subsequent queries, auditing, and verification of transaction validity.
9.1.2 Ledger Recovery Process
If database writes are interrupted due to node failure, the system will enter an automatic recovery procedure during restart:
- Independently obtain the latest EventHeight from EventBinaryLog, EventDB, StateDB, and HistoryDB.
- Use the EventHeight recorded in the WAL as the baseline checkpoint to determine whether any databases are in a βlagged state.β
- If discrepancies exist, replay the missing events and read-write sets from the WAL and write them into the lagging databases.
- Once all database modules have been restored to a consistent height, the system fully starts up and resumes consensus operations.
9.1.3 Query Process
- Query requests first check the in-memory cache; if the requested data is not found, it is retrieved from the database.
- For logically deleted data, the cache layer provides deletion markers.
- Range queries merge results from memory and disk and deduplicate them to ensure accuracy.
9.2 Supported Database Types
To meet different deployment needs and business environments, Mova supports multiple underlying databases:
- LevelDB: Suitable for lightweight nodes.
- RocksDB: Supports high-concurrency writes, suitable for high-performance nodes.
PostgreSQL / Distributed Relational Databases: Used for high-security, enterprise-grade environments requiring horizontal scalability and disaster recovery. Also used for storing chain tables and synchronizing contract events into relational database structures.