@@ -41,7 +41,11 @@ use aptos_db_indexer_schemas::{
4141 schema:: indexer_metadata:: InternalIndexerMetadataSchema ,
4242} ;
4343use aptos_infallible:: Mutex ;
44- use aptos_jellyfish_merkle:: iterator:: JellyfishMerkleIterator ;
44+ use aptos_jellyfish_merkle:: {
45+ iterator:: JellyfishMerkleIterator ,
46+ node_type:: { Node , NodeKey } ,
47+ TreeWriter ,
48+ } ;
4549use aptos_logger:: info;
4650use aptos_metrics_core:: TimerHelper ;
4751use aptos_schemadb:: batch:: { NativeBatch , SchemaBatch , WriteBatch } ;
@@ -58,6 +62,7 @@ use aptos_storage_interface::{
5862 } ,
5963 state_with_summary:: { LedgerStateWithSummary , StateWithSummary } ,
6064 versioned_state_value:: StateUpdateRef ,
65+ HotStateShardUpdates ,
6166 } ,
6267 AptosDbError , DbReader , Result , StateSnapshotReceiver ,
6368} ;
@@ -79,6 +84,7 @@ use claims::{assert_ge, assert_le};
7984use itertools:: Itertools ;
8085use rayon:: prelude:: * ;
8186use std:: {
87+ collections:: HashMap ,
8288 ops:: Deref ,
8389 sync:: { Arc , MutexGuard } ,
8490} ;
@@ -554,6 +560,7 @@ impl StateStore {
554560 latest_snapshot_version = latest_snapshot_version,
555561 "Initializing BufferedState."
556562 ) ;
563+ // TODO(HotState): read hot root hash from DB.
557564 let latest_snapshot_root_hash = if let Some ( version) = latest_snapshot_version {
558565 state_db
559566 . state_merkle_db
@@ -595,6 +602,18 @@ impl StateStore {
595602 ) ;
596603 }
597604
605+ if snapshot_next_version > 0 {
606+ let prev_version = snapshot_next_version - 1 ;
607+ let node_key = NodeKey :: new_empty_path ( prev_version) ;
608+ let node = Node :: Null ;
609+ let mut node_batch = HashMap :: new ( ) ;
610+ node_batch. insert ( node_key, node) ;
611+ if let Some ( db) = & state_db. hot_state_merkle_db {
612+ db. write_node_batch ( & node_batch) ?;
613+ }
614+ info ! ( "Wrote null node for hot state at version {prev_version}" ) ;
615+ }
616+
598617 // Replaying the committed write sets after the latest snapshot.
599618 if snapshot_next_version < num_transactions {
600619 if check_max_versions_after_snapshot {
@@ -605,6 +624,8 @@ impl StateStore {
605624 num_transactions,
606625 ) ;
607626 }
627+ info ! ( "Replaying writesets from {snapshot_next_version} to {num_transactions} to let state Merkle DB catch up." ) ;
628+
608629 let write_sets = state_db
609630 . ledger_db
610631 . write_set_db ( )
@@ -628,17 +649,28 @@ impl StateStore {
628649 ) ;
629650 let current_state = out_current_state. lock ( ) . clone ( ) ;
630651 let ( hot_state, state) = out_persisted_state. get_state ( ) ;
631- let ( new_state, _state_reads) = current_state. ledger_state ( ) . update_with_db_reader (
632- & state,
633- hot_state,
634- & state_update_refs,
635- state_db. clone ( ) ,
636- ) ?;
652+ let ( new_state, _state_reads, hot_state_updates) = current_state
653+ . ledger_state ( )
654+ . update_with_db_reader ( & state, hot_state, & state_update_refs, state_db. clone ( ) ) ?;
637655 let state_summary = out_persisted_state. get_state_summary ( ) ;
638656 let new_state_summary = current_state. ledger_state_summary ( ) . update (
639- & ProvableStateSummary :: new ( state_summary, state_db. as_ref ( ) ) ,
657+ & ProvableStateSummary :: new (
658+ state_summary. clone ( ) ,
659+ state_db. as_ref ( ) ,
660+ /* is_hot = */ true ,
661+ ) ,
662+ & hot_state_updates,
663+ & ProvableStateSummary :: new (
664+ state_summary,
665+ state_db. as_ref ( ) ,
666+ /* is_hot = */ false ,
667+ ) ,
640668 & state_update_refs,
641669 ) ?;
670+ info ! (
671+ "new hot state summary root hash: {}" ,
672+ new_state_summary. hot_root_hash( )
673+ ) ;
642674 let updated =
643675 LedgerStateWithSummary :: from_state_and_summary ( new_state, new_state_summary) ;
644676
@@ -720,7 +752,7 @@ impl StateStore {
720752 ) -> Result < LedgerState > {
721753 let current = self . current_state_locked ( ) . ledger_state ( ) ;
722754 let ( hot_state, persisted) = self . get_persisted_state ( ) ?;
723- let ( new_state, reads) = current. update_with_db_reader (
755+ let ( new_state, reads, _hot_state_updates ) = current. update_with_db_reader (
724756 & persisted,
725757 hot_state,
726758 state_update_refs,
@@ -1403,27 +1435,29 @@ mod test_only {
14031435 let current = self . current_state_locked ( ) . ledger_state_summary ( ) ;
14041436 let persisted = self . persisted_state . get_state_summary ( ) ;
14051437
1406- let new_state_summary = current
1407- . update (
1408- & ProvableStateSummary :: new ( persisted, self . state_db . as_ref ( ) ) ,
1409- & state_update_refs,
1410- )
1411- . unwrap ( ) ;
1412- let root_hash = new_state_summary. root_hash ( ) ;
1413-
1414- self . buffered_state
1415- . lock ( )
1416- . update (
1417- LedgerStateWithSummary :: from_state_and_summary (
1418- new_ledger_state,
1419- new_state_summary,
1420- ) ,
1421- 0 , /* estimated_items, doesn't matter since we sync-commit */
1422- true , /* sync_commit */
1423- )
1424- . unwrap ( ) ;
1425-
1426- root_hash
1438+ unimplemented ! ( ) ;
1439+
1440+ // let new_state_summary = current
1441+ // .update(
1442+ // &ProvableStateSummary::new(persisted, self.state_db.as_ref()),
1443+ // &state_update_refs,
1444+ // )
1445+ // .unwrap();
1446+ // let root_hash = new_state_summary.root_hash();
1447+
1448+ // self.buffered_state
1449+ // .lock()
1450+ // .update(
1451+ // LedgerStateWithSummary::from_state_and_summary(
1452+ // new_ledger_state,
1453+ // new_state_summary,
1454+ // ),
1455+ // 0, /* estimated_items, doesn't matter since we sync-commit */
1456+ // true, /* sync_commit */
1457+ // )
1458+ // .unwrap();
1459+
1460+ // root_hash
14271461 }
14281462 }
14291463}
0 commit comments