Skip to content

Commit 68747d3

Browse files
authored
Block epilogue refactor / optimize / prep for V2 support (#17094)
1 parent a9d8afa commit 68747d3

18 files changed

+949
-638
lines changed

Cargo.lock

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

aptos-move/aptos-vm/src/block_executor/mod.rs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ impl BeforeMaterializationOutput<SignatureVerifiedTransaction> for BeforeMateria
225225
.collect()
226226
}
227227

228-
fn for_each_resource_group_key_and_tags<F>(&self, mut callback: F) -> Result<(), PanicError>
229-
where
230-
F: FnMut(&StateKey, HashSet<&StructTag>) -> Result<(), PanicError>,
231-
{
228+
fn for_each_resource_group_key_and_tags(
229+
&self,
230+
callback: &mut dyn FnMut(&StateKey, HashSet<&StructTag>) -> Result<(), PanicError>,
231+
) -> Result<(), PanicError> {
232232
for (key, tags) in self
233233
.guard
234234
.resource_write_set()
@@ -401,29 +401,52 @@ impl BlockExecutorTransactionOutput for AptosTransactionOutput {
401401
false
402402
}
403403

404+
fn check_materialization(&self) -> Result<bool, PanicError> {
405+
if let Some(output) = self.committed_output.get() {
406+
if output.status().is_retry() {
407+
return Err(code_invariant_error(
408+
"Committed output must not have is_retry set.",
409+
));
410+
}
411+
Ok(true)
412+
} else {
413+
if !self
414+
.vm_output
415+
.read()
416+
.as_ref()
417+
.map_or(false, |output| output.status().is_retry())
418+
{
419+
return Err(code_invariant_error(
420+
"Non-committed output must exist with is_retry set.",
421+
));
422+
}
423+
Ok(false)
424+
}
425+
}
426+
404427
fn incorporate_materialized_txn_output(
405428
&self,
406429
aggregator_v1_writes: Vec<(StateKey, WriteOp)>,
407430
materialized_resource_write_set: Vec<(StateKey, WriteOp)>,
408431
materialized_events: Vec<ContractEvent>,
409432
) -> Result<(), PanicError> {
410-
assert!(
411-
self.committed_output
412-
.set(
413-
self.vm_output
414-
.write()
415-
.take()
416-
.expect("Output must be set to incorporate materialized data")
417-
.into_transaction_output_with_materialized_write_set(
418-
aggregator_v1_writes,
419-
materialized_resource_write_set,
420-
materialized_events,
421-
)?,
433+
self.committed_output
434+
.set(
435+
self.vm_output
436+
.write()
437+
.take()
438+
.expect("Output must be set to incorporate materialized data")
439+
.into_transaction_output_with_materialized_write_set(
440+
aggregator_v1_writes,
441+
materialized_resource_write_set,
442+
materialized_events,
443+
)?,
444+
)
445+
.map_err(|_| {
446+
code_invariant_error(
447+
"Could not combine VMOutput with the materialized resource and event data",
422448
)
423-
.is_ok(),
424-
"Could not combine VMOutput with the materialized resource and event data"
425-
);
426-
Ok(())
449+
})
427450
}
428451

429452
fn set_txn_output_for_non_dynamic_change_set(&self) {

aptos-move/block-executor/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ proptest = { workspace = true, optional = true }
4949
proptest-derive = { workspace = true, optional = true }
5050
rand = { workspace = true }
5151
rayon = { workspace = true }
52-
scopeguard = { workspace = true }
5352

5453
[dev-dependencies]
5554
aptos-aggregator = { workspace = true, features = ["testing"] }

aptos-move/block-executor/src/combinatorial_tests/mock_executor.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ where
730730
Ok(self)
731731
}
732732

733+
fn check_materialization(&self) -> Result<bool, PanicError> {
734+
Ok(!self.skipped)
735+
}
736+
733737
fn legacy_sequential_materialize_agg_v1(&self, _view: &impl TAggregatorV1View<Identifier = K>) {
734738
// TODO[agg_v2](tests): implement this method and compare
735739
// against sequential execution results v. aggregator v1.
@@ -849,18 +853,18 @@ where
849853
.collect()
850854
}
851855

852-
fn for_each_resource_group_key_and_tags<F>(&self, mut callback: F) -> Result<(), PanicError>
853-
where
854-
F: FnMut(&K, HashSet<&u32>) -> Result<(), PanicError>,
855-
{
856+
fn for_each_resource_group_key_and_tags(
857+
&self,
858+
callback: &mut dyn FnMut(&K, HashSet<&u32>) -> Result<(), PanicError>,
859+
) -> Result<(), PanicError> {
856860
for (key, _, _, ops) in self.group_writes.iter() {
857861
callback(key, ops.iter().map(|(tag, _)| tag).collect())?;
858862
}
859863
Ok(())
860864
}
861865

862866
fn output_approx_size(&self) -> u64 {
863-
// TODO add block output limit testing
867+
// TODO: add block output limit testing
864868
0
865869
}
866870

aptos-move/block-executor/src/combinatorial_tests/resource_tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ where
129129
>::new(config, executor_thread_pool, None);
130130

131131
if block_stm_v2 {
132-
block_executor.execute_transactions_parallel_v2(txn_provider, data_view, &mut guard)
132+
block_executor.execute_transactions_parallel_v2(
133+
txn_provider,
134+
data_view,
135+
&TransactionSliceMetadata::unknown(),
136+
&mut guard,
137+
)
133138
} else {
134139
block_executor.execute_transactions_parallel(
135140
txn_provider,

aptos-move/block-executor/src/counters.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ pub static RAYON_EXECUTION_SECONDS: Lazy<Histogram> = Lazy::new(|| {
121121
.unwrap()
122122
});
123123

124+
pub static PARALLEL_FINALIZE_SECONDS: Lazy<Histogram> = Lazy::new(|| {
125+
register_histogram!(
126+
// metric name
127+
"aptos_finalize_parallel_execution_seconds",
128+
// metric description
129+
"The time spent in seconds in finalizing parallel execution",
130+
time_buckets(),
131+
)
132+
.unwrap()
133+
});
134+
124135
pub static VM_INIT_SECONDS: Lazy<Histogram> = Lazy::new(|| {
125136
register_histogram!(
126137
// metric name

0 commit comments

Comments
 (0)