Skip to content

Commit dd9df3a

Browse files
committed
[Hot State] Compute root hash for hot state
1 parent bbdf3e8 commit dd9df3a

File tree

19 files changed

+564
-205
lines changed

19 files changed

+564
-205
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

execution/executor-types/src/execution_output.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use crate::{
1010
use aptos_config::config::HotStateConfig;
1111
use aptos_drop_helper::DropHelper;
1212
use aptos_storage_interface::state_store::{
13-
state::LedgerState, state_view::cached_state_view::ShardedStateCache,
13+
state::LedgerState, state_view::cached_state_view::ShardedStateCache, HotStateShardUpdates,
1414
};
1515
use aptos_types::{
1616
contract_event::ContractEvent,
1717
epoch_state::EpochState,
18+
state_store::NUM_STATE_SHARDS,
1819
transaction::{
1920
block_epilogue::BlockEndInfo, ExecutionStatus, Transaction, TransactionStatus, Version,
2021
},
@@ -41,6 +42,7 @@ impl ExecutionOutput {
4142
block_end_info: Option<BlockEndInfo>,
4243
next_epoch_state: Option<EpochState>,
4344
subscribable_events: Planned<Vec<ContractEvent>>,
45+
hot_state_updates: [Vec<HotStateShardUpdates>; NUM_STATE_SHARDS],
4446
) -> Self {
4547
let next_version = first_version + to_commit.len() as Version;
4648
assert_eq!(next_version, result_state.latest().next_version());
@@ -65,6 +67,7 @@ impl ExecutionOutput {
6567
block_end_info,
6668
next_epoch_state,
6769
subscribable_events,
70+
hot_state_updates,
6871
})
6972
}
7073

@@ -81,6 +84,7 @@ impl ExecutionOutput {
8184
block_end_info: None,
8285
next_epoch_state: None,
8386
subscribable_events: Planned::ready(vec![]),
87+
hot_state_updates: std::array::from_fn(|_| vec![]),
8488
})
8589
}
8690

@@ -99,6 +103,7 @@ impl ExecutionOutput {
99103
block_end_info: None,
100104
next_epoch_state: None,
101105
subscribable_events: Planned::ready(vec![]),
106+
hot_state_updates: std::array::from_fn(|_| vec![]),
102107
})
103108
}
104109

@@ -119,6 +124,7 @@ impl ExecutionOutput {
119124
block_end_info: None,
120125
next_epoch_state: self.next_epoch_state.clone(),
121126
subscribable_events: Planned::ready(vec![]),
127+
hot_state_updates: std::array::from_fn(|_| vec![]),
122128
})
123129
}
124130

@@ -166,6 +172,8 @@ pub struct Inner {
166172
/// state cache.
167173
pub next_epoch_state: Option<EpochState>,
168174
pub subscribable_events: Planned<Vec<ContractEvent>>,
175+
/// Per checkpoint and optionally a partial block.
176+
pub hot_state_updates: [Vec<HotStateShardUpdates>; NUM_STATE_SHARDS],
169177
}
170178

171179
impl Inner {

execution/executor/src/block_executor/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,14 @@ where
315315
output.set_state_checkpoint_output(DoStateCheckpoint::run(
316316
&output.execution_output,
317317
parent_block.output.ensure_result_state_summary()?,
318-
&ProvableStateSummary::new_persisted(self.db.reader.as_ref())?,
318+
&ProvableStateSummary::new_persisted(
319+
self.db.reader.as_ref(),
320+
/* is_hot = */ true,
321+
)?,
322+
&ProvableStateSummary::new_persisted(
323+
self.db.reader.as_ref(),
324+
/* is_hot = */ false,
325+
)?,
319326
None,
320327
)?);
321328
output.set_ledger_update_output(DoLedgerUpdate::run(

execution/executor/src/chunk_executor/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,14 @@ impl<V: VMBlockExecutor> ChunkExecutorInner<V> {
346346
let state_checkpoint_output = DoStateCheckpoint::run(
347347
&output.execution_output,
348348
&parent_state_summary,
349-
&ProvableStateSummary::new_persisted(self.db.reader.as_ref())?,
349+
&ProvableStateSummary::new_persisted(
350+
self.db.reader.as_ref(),
351+
/* is_hot = */ true,
352+
)?,
353+
&ProvableStateSummary::new_persisted(
354+
self.db.reader.as_ref(),
355+
/* is_hot = */ false,
356+
)?,
350357
Some(
351358
chunk_verifier
352359
.transaction_infos()

execution/executor/src/workflow/do_get_execution_output.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl Parser {
417417
},
418418
)?;
419419

420-
let result_state = parent_state.update_with_memorized_reads(
420+
let (result_state, hot_state_updates) = parent_state.update_with_memorized_reads(
421421
base_state_view.persisted_hot_state(),
422422
base_state_view.persisted_state(),
423423
to_commit.state_update_refs(),
@@ -437,6 +437,7 @@ impl Parser {
437437
block_end_info,
438438
next_epoch_state,
439439
Planned::place_holder(),
440+
hot_state_updates,
440441
);
441442
let ret = out.clone();
442443
ret.subscribable_events

execution/executor/src/workflow/do_state_checkpoint.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ impl DoStateCheckpoint {
1818
pub fn run(
1919
execution_output: &ExecutionOutput,
2020
parent_state_summary: &LedgerStateSummary,
21-
persisted_state_summary: &ProvableStateSummary,
21+
hot_persisted_state_summary: &ProvableStateSummary,
22+
cold_persisted_state_summary: &ProvableStateSummary,
2223
known_state_checkpoints: Option<Vec<Option<HashValue>>>,
2324
) -> Result<StateCheckpointOutput> {
2425
let _timer = OTHER_TIMERS.timer_with(&["do_state_checkpoint"]);
2526

2627
let state_summary = parent_state_summary.update(
27-
persisted_state_summary,
28+
hot_persisted_state_summary,
29+
&execution_output.hot_state_updates,
30+
cold_persisted_state_summary,
2831
execution_output.to_commit.state_update_refs(),
2932
)?;
3033

execution/executor/src/workflow/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ impl ApplyExecutionOutput {
2727
let state_checkpoint_output = DoStateCheckpoint::run(
2828
&execution_output,
2929
&base_view.state_summary,
30-
&ProvableStateSummary::new_persisted(reader)?,
30+
&ProvableStateSummary::new_persisted(reader, /* is_hot = */ true)?,
31+
&ProvableStateSummary::new_persisted(reader, /* is_hot = */ false)?,
3132
None,
3233
)?;
3334
let ledger_update_output = DoLedgerUpdate::run(

storage/aptosdb/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ aptos-crypto = { workspace = true }
2020
aptos-db-indexer = { workspace = true }
2121
aptos-db-indexer-schemas = { workspace = true, features = ["fuzzing"] }
2222
aptos-executor-types = { workspace = true }
23+
aptos-experimental-layered-map = { workspace = true }
2324
aptos-experimental-runtimes = { workspace = true }
2425
aptos-infallible = { workspace = true }
2526
aptos-jellyfish-merkle = { workspace = true }

storage/aptosdb/src/backup/restore_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub(crate) fn save_transactions_impl(
267267
}
268268

269269
if kv_replay && first_version > 0 && state_store.get_usage(Some(first_version - 1)).is_ok() {
270-
let ledger_state = state_store.calculate_state_and_put_updates(
270+
let (ledger_state, _hot_state_updates) = state_store.calculate_state_and_put_updates(
271271
&StateUpdateRefs::index_write_sets(first_version, write_sets, write_sets.len(), vec![]),
272272
&mut ledger_db_batch.ledger_metadata_db_batches, // used for storing the storage usage
273273
state_kv_batches,

storage/aptosdb/src/db/aptosdb_testonly.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,17 @@ impl AptosDB {
166166

167167
let current = self.state_store.current_state_locked().clone();
168168
let (hot_state, persisted_state) = self.state_store.get_persisted_state()?;
169-
let (new_state, reads) = current.ledger_state().update_with_db_reader(
169+
let (new_state, reads, hot_state_updates) = current.ledger_state().update_with_db_reader(
170170
&persisted_state,
171171
hot_state,
172172
transactions_to_keep.state_update_refs(),
173173
self.state_store.clone(),
174174
)?;
175175
let persisted_summary = self.state_store.get_persisted_state_summary()?;
176176
let new_state_summary = current.ledger_state_summary().update(
177-
&ProvableStateSummary::new(persisted_summary, self),
177+
&ProvableStateSummary::new(persisted_summary.clone(), self, /* is_hot = */ true),
178+
&hot_state_updates,
179+
&ProvableStateSummary::new(persisted_summary, self, /* is_hot = */ false),
178180
transactions_to_keep.state_update_refs(),
179181
)?;
180182

0 commit comments

Comments
 (0)