Skip to content

Commit

Permalink
refactor(collator): use executor output type
Browse files Browse the repository at this point in the history
  • Loading branch information
Mododo committed Jun 13, 2024
1 parent 0e0f61e commit 4edd43b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 15 additions & 19 deletions collator/src/collator/do_collate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use everscale_types::num::Tokens;
use everscale_types::prelude::*;
use humantime::format_duration;
use sha2::Digest;
use ton_executor::blockchain_config::PreloadedBlockchainConfig;
use ton_executor::ExecuteParams;
use ton_executor::{ExecuteParams, ExecutorOutput, PreloadedBlockchainConfig};
use tycho_util::FastHashMap;

use super::types::{CachedMempoolAnchor, SpecialOrigin};
Expand Down Expand Up @@ -339,7 +338,7 @@ impl CollatorStdImpl {
let new_messages = new_transaction(
&mut collation_data,
&self.shard_id,
item.transaction,
item.executor_output,
item.in_message,
)?;

Expand Down Expand Up @@ -1081,12 +1080,12 @@ impl CollatorStdImpl {
.execute_ordinary_transaction(account_stuff, in_message)
.await?;

let (_total_fees, transaction) = executed.result?;
let executor_output = executed.result?;

new_transaction(
collation_data,
&self.shard_id,
transaction,
executor_output,
executed.in_message,
)?;

Expand Down Expand Up @@ -1142,7 +1141,7 @@ impl CollatorStdImpl {
return Ok(());
};

let (_async_message, _transaction) = exec_manager
let _executor_output = exec_manager
.execute_ticktock_transaction(account_stuff, tick_tock)
.await?;

Expand Down Expand Up @@ -1257,13 +1256,13 @@ impl CollatorStdImpl {
fn new_transaction(
collation_data: &mut BlockCollationData,
shard_id: &ShardIdent,
transaction: Lazy<Transaction>,
executor_output: ExecutorOutput,
in_msg: Box<AsyncMessage>,
) -> Result<Vec<Box<AsyncMessage>>> {
tracing::trace!(
target: tracing_targets::COLLATOR,
message_hash = %in_msg.cell.repr_hash(),
transaction_hash = %transaction.inner().repr_hash(),
transaction_hash = %executor_output.transaction.inner().repr_hash(),
"process new transaction from message",
);

Expand All @@ -1281,7 +1280,7 @@ fn new_transaction(
fwd_fee_remaining: Default::default(),
message: Lazy::from_raw(in_msg.cell),
})?,
transaction: transaction.clone(),
transaction: executor_output.transaction.clone(),
fwd_fee: Default::default(),
});

Expand All @@ -1295,7 +1294,7 @@ fn new_transaction(
import_fees = ImportFees::default();
Lazy::new(&InMsg::External(InMsgExternal {
in_msg: Lazy::from_raw(in_msg.cell),
transaction: transaction.clone(),
transaction: executor_output.transaction.clone(),
}))?
}
// Dequeued messages have a dedicated `InMsg` type
Expand All @@ -1318,7 +1317,7 @@ fn new_transaction(

let in_msg = InMsg::Final(InMsgFinal {
in_msg_envelope: envelope.clone(),
transaction: transaction.clone(),
transaction: executor_output.transaction.clone(),
fwd_fee,
});
import_fees = in_msg.compute_fees()?;
Expand Down Expand Up @@ -1354,7 +1353,7 @@ fn new_transaction(
};
let in_msg = InMsg::Immediate(InMsgFinal {
in_msg_envelope: Lazy::new(&msg_envelope)?,
transaction: transaction.clone(),
transaction: executor_output.transaction.clone(),
fwd_fee,
});

Expand Down Expand Up @@ -1400,10 +1399,7 @@ fn new_transaction(

let mut out_messages = vec![];

let binding = transaction.load()?;

// TODO: Get out messages from executor
for out_msg_cell in binding.out_msgs.values() {
for out_msg_cell in executor_output.out_msgs.values() {
let out_msg_cell = out_msg_cell?;
let out_msg_hash = *out_msg_cell.repr_hash();
let out_msg_info = out_msg_cell.parse::<MsgInfo>()?;
Expand Down Expand Up @@ -1434,15 +1430,15 @@ fn new_transaction(
fwd_fee_remaining: *fwd_fee,
message: Lazy::from_raw(out_msg_cell.clone()),
})?,
transaction: transaction.clone(),
transaction: executor_output.transaction.clone(),
});

collation_data
.out_msgs
.insert(out_msg_hash, PreparedOutMsg {
out_msg: Lazy::new(&out_msg)?,
exported_value: out_msg.compute_exported_value()?,
new_tx: Some(transaction.clone()),
new_tx: Some(executor_output.transaction.clone()),
});

out_messages.push(Box::new(AsyncMessage {
Expand All @@ -1455,7 +1451,7 @@ fn new_transaction(
MsgInfo::ExtOut(_) => {
let out_msg = OutMsg::External(OutMsgExternal {
out_msg: Lazy::from_raw(out_msg_cell),
transaction: transaction.clone(),
transaction: executor_output.transaction.clone(),
});

collation_data
Expand Down
29 changes: 14 additions & 15 deletions collator/src/collator/execution_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use everscale_types::models::*;
use everscale_types::prelude::*;
use futures_util::stream::FuturesUnordered;
use futures_util::{Future, StreamExt};
use ton_executor::blockchain_config::PreloadedBlockchainConfig;
use ton_executor::{
ExecuteParams, OrdinaryTransactionExecutor, TickTockTransactionExecutor, TransactionExecutor,
ExecuteParams, ExecutorOutput, OrdinaryTransactionExecutor, PreloadedBlockchainConfig,
TickTockTransactionExecutor, TransactionExecutor,
};
use tycho_util::metrics::HistogramGuard;
use tycho_util::sync::rayon_run;
Expand Down Expand Up @@ -141,13 +141,12 @@ impl ExecutionManager {
}
}

let (total_fees, transaction) = tx.result?;
let executor_output = tx.result?;

items.push(ExecutedTickItem {
account_addr: executed.account_state.account_addr,
in_message: tx.in_message,
total_fees,
transaction,
executor_output,
});
}

Expand Down Expand Up @@ -332,8 +331,7 @@ impl ExecutedTick {
pub struct ExecutedTickItem {
pub account_addr: AccountId,
pub in_message: Box<AsyncMessage>,
pub total_fees: CurrencyCollection,
pub transaction: Lazy<Transaction>,
pub executor_output: ExecutorOutput,
}

pub struct ExecutedTransactions {
Expand All @@ -346,8 +344,6 @@ pub struct ExecutedOrdinaryTransaction {
pub in_message: Box<AsyncMessage>,
}

pub type ExecutorOutput = (CurrencyCollection, Lazy<Transaction>);

fn execute_ordinary_transaction(
account_stuff: &mut ShardAccountStuff,
in_message: Box<AsyncMessage>,
Expand All @@ -373,13 +369,16 @@ fn execute_ordinary_transaction(
config,
);

if let Ok((total_fees, transaction)) = &result {
if let Ok((total_fees, executor_output)) = &result {
// TODO replace with batch set
let tx_lt = shard_account.last_trans_lt;
account_stuff.add_transaction(tx_lt, total_fees, transaction)?;
account_stuff.add_transaction(tx_lt, total_fees, &executor_output.transaction)?;
}

Ok(ExecutedOrdinaryTransaction { result, in_message })
Ok(ExecutedOrdinaryTransaction {
result: result.map(|(_, exec_out)| exec_out),
in_message,
})
}

fn execute_ticktock_transaction(
Expand All @@ -401,14 +400,14 @@ fn execute_ticktock_transaction(
let shard_account = &mut account_stuff.shard_account;

// NOTE: Failed (without tx) ticktock execution is considered as a fatal error
let (total_fees, transaction) = TickTockTransactionExecutor::new(tick_tock)
let (total_fees, executor_output) = TickTockTransactionExecutor::new(tick_tock)
.execute_with_libs_and_params(None, shard_account, min_lt, params, config)?;

// TODO replace with batch set
let tx_lt = shard_account.last_trans_lt;
account_stuff.add_transaction(tx_lt, &total_fees, &transaction)?;
account_stuff.add_transaction(tx_lt, &total_fees, &executor_output.transaction)?;

Ok((total_fees, transaction))
Ok(executor_output)
}

// TODO: Update
Expand Down

0 comments on commit 4edd43b

Please sign in to comment.