[storage] Persist hot state KV insertions/evictions to DB
What Changed
This PR introduces a new persistence path for hot state KV changes, which are now written to a dedicated RocksDB column family during transaction pre-commit. The AptosDB struct has been updated to include a hot_state_kv_db field, and the pre_commit_ledger method now writes hot state updates to this database in parallel with cold state commits.
The specific files modified include execution/executor-types/src/state_compute_result.rs, storage/aptosdb/src/db/aptosdb_internal.rs, storage/aptosdb/src/db/aptosdb_testonly.rs, storage/aptosdb/src/db/aptosdb_writer.rs, storage/aptosdb/src/db/mod.rs, storage/aptosdb/src/db_options.rs, and storage/aptosdb/src/schema/hot_state_value_by_key_hash/mod.rs. The core structs and functions touched include AptosDB, pre_commit_ledger, hot_state_kv_db, and HotStateEntry.
Where This Fits in Aptos
This change applies to the storage subsystem, specifically the AptosDB component. The transaction lifecycle pipeline is as follows:
Client -> Mempool -> Quorum Store -> Consensus -> Execution -> StorageThe storage subsystem is responsible for persisting the state of the blockchain, and this change improves the system's ability to handle hot state data.
How It Works (Step by Step)
When a transaction is committed, the pre_commit_ledger method is called, which writes the hot state updates to the hot_state_kv_db in parallel with the cold state commits. The hot_state_kv_db is a dedicated RocksDB column family that stores the hot state KV changes.
The HotStateEntry enum is used to represent the hot state value, which can be either Occupied or Vacant. The None value represents the eviction of a key from the hot state.
let hot_state_kv_db = self.hot_state_kv_db.as_ref().expect("hot_state_kv_db must exist on the write path");The put_hot_state_updates method is used to write the hot state updates to the hot_state_kv_db.
self.state_store.put_hot_state_updates(chunk.hot_state_updates, &mut sharded_hot_state_kv_batches)?;Why This Matters
This change improves the system's ability to handle hot state data, which is critical for the performance and scalability of the blockchain. By writing the hot state updates to a dedicated RocksDB column family, the system can reduce the latency and improve the throughput of the storage subsystem.
Architectural Connections
This change is related to the storage-sharding feature, which aims to improve the scalability and performance of the storage subsystem. The hot_state_kv_db is a key component of the storage-sharding architecture, and this change lays the groundwork for future improvements to the storage subsystem.
ELI5 — Explain Like I'm 5
The Big Picture: Imagine a library where books are stored on shelves. The library has a special section for frequently accessed books, which are stored on a separate shelf. When a book is checked out, the librarian updates the catalog to reflect the new location of the book. In this analogy, the library represents the blockchain, the books represent the data, and the special section represents the hot state.
What Changed: The librarian has introduced a new way of updating the catalog for the hot state books. Instead of updating the main catalog, the librarian now updates a separate catalog specifically for the hot state books. This change improves the efficiency of the library and allows for faster access to the hot state books.
Why It Matters: This change is important because it improves the performance and scalability of the library. By updating the catalog for the hot state books separately, the librarian can reduce the time it takes to access the books and improve the overall efficiency of the library.
What You Learned: You just learned about the hot state and how it is used to improve the performance and scalability of the blockchain. The hot state is a critical component of the blockchain architecture, and understanding how it works is essential for building scalable and efficient blockchain applications.
Related Systems
Other Deep Dives
View this report interactively with Advanced / ELI5 tabs at https://aptos-intelligence.vercel.app/#3368033534. Plain-text version: /reports/3368033534.txt.