Skip to content

Commit 1e5d803

Browse files
committed
Return Commitment from executors' execute_block
In MonzaExecutor and SuzukaExecutor, return the Commitment value from execute_block. The underlying opt-executor is changed to produce the commitment from proof data.
1 parent edc750f commit 1e5d803

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol-units/execution/maptos/opt-executor/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ tokio = { workspace = true }
3333
rand = { workspace = true }
3434
rand_core = { workspace = true }
3535
bcs = { workspace = true}
36+
futures = { workspace = true }
37+
async-channel = { workspace = true }
3638

3739
aptos-vm = { workspace = true }
3840
aptos-config = { workspace = true }
@@ -58,9 +60,8 @@ aptos-mempool = { workspace = true }
5860
aptos-temppath = { workspace = true }
5961
aptos-faucet-core = { workspace = true }
6062
aptos-cached-packages = { workspace = true }
61-
futures = { workspace = true }
62-
async-channel = { workspace = true }
6363
maptos-execution-util = { workspace = true }
64+
movement-types = { workspace = true }
6465

6566
dirs = { workspace = true }
6667
tempfile = { workspace = true }

protocol-units/execution/maptos/opt-executor/src/executor.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use aptos_vm::AptosVM;
3535
use aptos_vm_genesis::{
3636
default_gas_schedule, encode_genesis_change_set, GenesisConfiguration, TestValidator, Validator,
3737
};
38+
use movement_types::Commitment;
3839

3940
use anyhow::Context as _;
4041
use futures::channel::mpsc as futures_mpsc;
@@ -256,7 +257,7 @@ impl Executor {
256257
pub async fn execute_block(
257258
&self,
258259
block: ExecutableBlock,
259-
) -> Result<(), anyhow::Error> {
260+
) -> Result<Commitment, anyhow::Error> {
260261

261262
let block_id = block.block_id.clone();
262263
let parent_block_id = {
@@ -285,14 +286,14 @@ impl Executor {
285286
)?;
286287
}
287288

288-
{
289+
let proof = {
289290
let reader = self.db.read().await.reader.clone();
290-
let proof = reader.get_state_proof(
291+
reader.get_state_proof(
291292
state_compute.version(),
292-
)?;
293-
}
293+
)?
294+
};
294295

295-
Ok(())
296+
Ok(Commitment::digest_state_proof(&proof))
296297
}
297298

298299
pub async fn try_get_context(&self) -> Result<Arc<Context>, anyhow::Error> {
@@ -582,7 +583,9 @@ mod tests {
582583

583584
// Create and execute the block.
584585
let block = ExecutableBlock::new(block_id.clone(), transactions);
585-
executor.execute_block(block).await?;
586+
let commitment = executor.execute_block(block).await?;
587+
588+
// TODO: verify commitment against the state.
586589

587590
// Access the database reader to verify state after execution.
588591
let db_reader = executor.db.read().await.reader.clone();

protocol-units/execution/monza/executor/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ aptos-proptest-helpers = { workspace = true }
6363

6464
maptos-opt-executor = { workspace = true }
6565
maptos-execution-util = { workspace = true }
66+
movement-types = { workspace = true }
6667

6768
dirs = "5.0.1"
6869
tempfile = "3.10.1"

protocol-units/execution/monza/executor/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ pub use aptos_types::{
77
transaction::{SignedTransaction, Transaction}
88
};
99
pub use aptos_crypto::hash::HashValue;
10-
use async_channel::Sender;
1110
use aptos_api::runtime::Apis;
11+
1212
pub use maptos_execution_util::FinalityMode;
13+
use movement_types::Commitment;
1314

15+
use async_channel::Sender;
1416

1517
#[tonic::async_trait]
1618
pub trait MonzaExecutor {
@@ -26,7 +28,7 @@ pub trait MonzaExecutor {
2628
&self,
2729
mode : &FinalityMode,
2830
block: ExecutableBlock,
29-
) -> Result<(), anyhow::Error>;
31+
) -> Result<Commitment, anyhow::Error>;
3032

3133
/// Sets the transaction channel.
3234
async fn set_tx_channel(&mut self, tx_channel: Sender<SignedTransaction>) -> Result<(), anyhow::Error>;

protocol-units/execution/monza/executor/src/v1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::*;
22
use aptos_types::transaction::SignedTransaction;
33
use async_channel::Sender;
44
use maptos_opt_executor::Executor;
5+
use movement_types::Commitment;
56

67
#[derive(Clone)]
78
pub struct MonzaExecutorV1 {
@@ -45,7 +46,7 @@ impl MonzaExecutor for MonzaExecutorV1 {
4546
&self,
4647
mode: &FinalityMode,
4748
block: ExecutableBlock,
48-
) -> Result<(), anyhow::Error> {
49+
) -> Result<Commitment, anyhow::Error> {
4950
match mode {
5051
FinalityMode::Dyn => unimplemented!(),
5152
FinalityMode::Opt => {

protocol-units/execution/suzuka/executor/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ aptos-temppath = { workspace = true }
6262

6363
maptos-opt-executor = { workspace = true }
6464
maptos-execution-util = { workspace = true }
65+
movement-types = { workspace = true }
6566

6667
dirs = "5.0.1"
6768
tempfile = "3.10.1"

protocol-units/execution/suzuka/executor/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ pub use aptos_types::{
77
transaction::{SignedTransaction, Transaction}
88
};
99
pub use aptos_crypto::hash::HashValue;
10-
use async_channel::Sender;
1110
use aptos_api::runtime::Apis;
11+
1212
pub use maptos_execution_util::FinalityMode;
13+
use movement_types::Commitment;
1314

15+
use async_channel::Sender;
1416

1517
#[tonic::async_trait]
1618
pub trait SuzukaExecutor {
@@ -26,7 +28,7 @@ pub trait SuzukaExecutor {
2628
&self,
2729
mode : &FinalityMode,
2830
block: ExecutableBlock,
29-
) -> Result<(), anyhow::Error>;
31+
) -> Result<Commitment, anyhow::Error>;
3032

3133
/// Sets the transaction channel.
3234
async fn set_tx_channel(&mut self, tx_channel: Sender<SignedTransaction>) -> Result<(), anyhow::Error>;

protocol-units/execution/suzuka/executor/src/v1.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::*;
22
use maptos_opt_executor::Executor;
33
use async_channel::Sender;
44
use aptos_types::transaction::SignedTransaction;
5+
use movement_types::Commitment;
56

67
#[derive(Clone)]
78
pub struct SuzukaExecutorV1 {
@@ -50,7 +51,7 @@ impl SuzukaExecutor for SuzukaExecutorV1 {
5051
&self,
5152
mode : &FinalityMode,
5253
block: ExecutableBlock,
53-
) -> Result<(), anyhow::Error> {
54+
) -> Result<Commitment, anyhow::Error> {
5455

5556
match mode {
5657
FinalityMode::Dyn => unimplemented!(),
@@ -138,7 +139,7 @@ mod opt_tests {
138139
#[tokio::test]
139140
async fn test_execute_opt_block() -> Result<(), anyhow::Error> {
140141
let (tx, rx) = async_channel::unbounded();
141-
let mut executor = SuzukaExecutorV1::try_from_env(tx).await?;
142+
let executor = SuzukaExecutorV1::try_from_env(tx).await?;
142143
let block_id = HashValue::random();
143144
let tx = SignatureVerifiedTransaction::Valid(Transaction::UserTransaction(
144145
create_signed_transaction(0),
@@ -228,7 +229,11 @@ mod opt_tests {
228229
));
229230
let txs = ExecutableTransactions::Unsharded(vec![tx]);
230231
let block = ExecutableBlock::new(block_id.clone(), txs);
231-
executor.execute_block(&FinalityMode::Opt, block).await?;
232+
let commitment = executor.execute_block(&FinalityMode::Opt, block).await?;
233+
234+
println!("Commitment: {:?}", commitment);
235+
236+
// TODO: test the commitment
232237

233238
services_handle.abort();
234239
background_handle.abort();

0 commit comments

Comments
 (0)