Skip to content

Commit

Permalink
[Execution] Return transactions when committing a chunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind authored and bors-libra committed Dec 22, 2021
1 parent 9eede8d commit 74bc0cf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions execution/executor-types/src/executed_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ impl ExecutedChunk {
.collect()
}

pub fn transactions(&self) -> Vec<Transaction> {
self.to_commit.iter().map(|(txn, _)| txn).cloned().collect()
}

pub fn events_to_commit(&self) -> Vec<ContractEvent> {
self.to_commit
.iter()
Expand Down
9 changes: 5 additions & 4 deletions execution/executor-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,23 @@ pub trait ChunkExecutorTrait: Send + Sync {
epoch_change_li: Option<&LedgerInfoWithSignatures>,
) -> anyhow::Result<()>;

/// Commit a previously executed chunks, returns a vector of reconfiguration events in the chunk.
fn commit_chunk(&self) -> Result<Vec<ContractEvent>>;
/// Commit a previously executed chunk. Returns a vector of reconfiguration
/// events in the chunk and the transactions that were committed.
fn commit_chunk(&self) -> Result<(Vec<ContractEvent>, Vec<Transaction>)>;

fn execute_and_commit_chunk(
&self,
txn_list_with_proof: TransactionListWithProof,
verified_target_li: &LedgerInfoWithSignatures,
epoch_change_li: Option<&LedgerInfoWithSignatures>,
) -> Result<Vec<ContractEvent>>;
) -> Result<(Vec<ContractEvent>, Vec<Transaction>)>;

fn apply_and_commit_chunk(
&self,
txn_output_list_with_proof: TransactionOutputListWithProof,
verified_target_li: &LedgerInfoWithSignatures,
epoch_change_li: Option<&LedgerInfoWithSignatures>,
) -> Result<Vec<ContractEvent>>;
) -> Result<(Vec<ContractEvent>, Vec<Transaction>)>;
}

pub trait BlockExecutorTrait: Send + Sync {
Expand Down
13 changes: 8 additions & 5 deletions execution/executor/src/chunk_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,21 @@ impl<V: VMExecutor> ChunkExecutorTrait for ChunkExecutor<V> {
Ok(())
}

fn commit_chunk(&self) -> Result<Vec<ContractEvent>> {
fn commit_chunk(&self) -> Result<(Vec<ContractEvent>, Vec<Transaction>)> {
let _timer = DIEM_EXECUTOR_COMMIT_CHUNK_SECONDS.start_timer();

Ok(self.commit_chunk_impl()?.events_to_commit())
let executed_chunk = self.commit_chunk_impl()?;
Ok((
executed_chunk.events_to_commit(),
executed_chunk.transactions(),
))
}

fn execute_and_commit_chunk(
&self,
txn_list_with_proof: TransactionListWithProof,
verified_target_li: &LedgerInfoWithSignatures,
epoch_change_li: Option<&LedgerInfoWithSignatures>,
) -> Result<Vec<ContractEvent>> {
) -> Result<(Vec<ContractEvent>, Vec<Transaction>)> {
// Re-sync with DB, make sure the queue is empty.
self.reset()?;

Expand All @@ -247,7 +250,7 @@ impl<V: VMExecutor> ChunkExecutorTrait for ChunkExecutor<V> {
txn_output_list_with_proof: TransactionOutputListWithProof,
verified_target_li: &LedgerInfoWithSignatures,
epoch_change_li: Option<&LedgerInfoWithSignatures>,
) -> Result<Vec<ContractEvent>> {
) -> Result<(Vec<ContractEvent>, Vec<Transaction>)> {
// Re-sync with DB, make sure the queue is empty.
self.reset()?;

Expand Down
2 changes: 1 addition & 1 deletion state-sync/state-sync-v1/src/executor_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<C: ChunkExecutorTrait> ExecutorProxyTrait for ExecutorProxy<C> {
) -> Result<(), Error> {
// track chunk execution time
let timer = counters::EXECUTE_CHUNK_DURATION.start_timer();
let events = self
let (events, _) = self
.chunk_executor
.execute_and_commit_chunk(
txn_list_with_proof,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<ChunkExecutor: ChunkExecutorTrait> StorageSynchronizerInterface
target_ledger_info: LedgerInfoWithSignatures,
end_of_epoch_ledger_info: Option<LedgerInfoWithSignatures>,
) -> Result<Vec<ContractEvent>, Error> {
let committed_events = self
let (committed_events, _) = self
.chunk_executor
.apply_and_commit_chunk(
output_list_with_proof,
Expand All @@ -151,7 +151,7 @@ impl<ChunkExecutor: ChunkExecutorTrait> StorageSynchronizerInterface
target_ledger_info: LedgerInfoWithSignatures,
end_of_epoch_ledger_info: Option<LedgerInfoWithSignatures>,
) -> Result<Vec<ContractEvent>, Error> {
let committed_events = self
let (committed_events, _) = self
.chunk_executor
.execute_and_commit_chunk(
transaction_list_with_proof,
Expand Down

0 comments on commit 74bc0cf

Please sign in to comment.