Skip to content

Commit

Permalink
Expose GasData through executor
Browse files Browse the repository at this point in the history
  • Loading branch information
dariorussi committed Feb 17, 2025
1 parent 0eaa8f7 commit d5539ba
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 90 deletions.
4 changes: 2 additions & 2 deletions crates/simulacrum/src/epoch_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl EpochState {
)?;

let transaction_data = transaction.data().transaction_data();
let (kind, signer, gas) = transaction_data.execution_parts();
let (kind, signer, gas_data) = transaction_data.execution_parts();
let (inner_temp_store, gas_status, effects, _timings, result) =
self.executor.execute_transaction_to_effects(
store.backing_store(),
Expand All @@ -145,7 +145,7 @@ impl EpochState {
&self.epoch_start_state.epoch(),
self.epoch_start_state.epoch_start_timestamp_ms(),
checked_input_objects,
gas,
gas_data,
gas_status,
kind,
signer,
Expand Down
50 changes: 26 additions & 24 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ impl AuthorityState {
let tx_digest = *certificate.digest();
let protocol_config = epoch_store.protocol_config();
let transaction_data = &certificate.data().intent_message().value;
let (kind, signer, gas) = transaction_data.execution_parts();
let (kind, signer, gas_data) = transaction_data.execution_parts();

#[allow(unused_mut)]
let (inner_temp_store, _, mut effects, timings, execution_error_opt) =
Expand All @@ -1682,7 +1682,7 @@ impl AuthorityState {
.epoch_data()
.epoch_start_timestamp(),
input_objects,
gas,
gas_data,
gas_status,
kind,
signer,
Expand Down Expand Up @@ -1811,7 +1811,7 @@ impl AuthorityState {
)?;

// make a gas object if one was not provided
let mut gas_object_refs = transaction.gas().to_vec();
let mut gas_data = transaction.gas_data().clone();
let ((gas_status, checked_input_objects), mock_gas) = if transaction.gas().is_empty() {
let sender = transaction.sender();
// use a 1B sui coin
Expand All @@ -1825,7 +1825,7 @@ impl AuthorityState {
TransactionDigest::genesis_marker(),
);
let gas_object_ref = gas_object.compute_object_reference();
gas_object_refs = vec![gas_object_ref];
gas_data.payment = vec![gas_object_ref];
(
sui_transaction_checks::check_transaction_input_with_given_gas(
epoch_store.protocol_config(),
Expand Down Expand Up @@ -1875,7 +1875,7 @@ impl AuthorityState {
.epoch_data()
.epoch_start_timestamp(),
checked_input_objects,
gas_object_refs,
gas_data,
gas_status,
kind,
signer,
Expand Down Expand Up @@ -2002,7 +2002,7 @@ impl AuthorityState {
)?;

// make a gas object if one was not provided
let mut gas_object_refs = transaction.gas().to_vec();
let mut gas_data = transaction.gas_data().clone();
let ((gas_status, checked_input_objects), mock_gas) = if transaction.gas().is_empty() {
let sender = transaction.sender();
// use a 1B sui coin
Expand All @@ -2016,7 +2016,7 @@ impl AuthorityState {
TransactionDigest::genesis_marker(),
);
let gas_object_ref = gas_object.compute_object_reference();
gas_object_refs = vec![gas_object_ref];
gas_data.payment = vec![gas_object_ref];
(
sui_transaction_checks::check_transaction_input_with_given_gas(
epoch_store.protocol_config(),
Expand Down Expand Up @@ -2066,7 +2066,7 @@ impl AuthorityState {
.epoch_data()
.epoch_start_timestamp(),
checked_input_objects,
gas_object_refs,
gas_data,
gas_status,
kind,
signer,
Expand Down Expand Up @@ -2122,7 +2122,7 @@ impl AuthorityState {
let owner = gas_sponsor.unwrap_or(sender);
// Payment might be empty here, but it's fine we'll have to deal with it later after reading all the input objects.
let payment = gas_objects.unwrap_or_default();
let transaction = TransactionData::V1(TransactionDataV1 {
let mut transaction = TransactionData::V1(TransactionDataV1 {
kind: transaction_kind.clone(),
sender,
gas_data: GasData {
Expand Down Expand Up @@ -2168,26 +2168,20 @@ impl AuthorityState {
.unwrap_or(false),
)?;

// Create and use a dummy gas object if there is no gas object provided.
let dummy_gas_object = Object::new_gas_with_balance_and_owner_for_testing(
DEV_INSPECT_GAS_COIN_VALUE,
transaction.gas_owner(),
);

let gas_objects = if transaction.gas().is_empty() {
let gas_object_ref = dummy_gas_object.compute_object_reference();
vec![gas_object_ref]
} else {
transaction.gas().to_vec()
};

let (gas_status, checked_input_objects) = if skip_checks {
// If we are skipping checks, then we call the check_dev_inspect_input function which will perform
// only lightweight checks on the transaction input. And if the gas field is empty, that means we will
// use the dummy gas object so we need to add it to the input objects vector.
if transaction.gas().is_empty() {
// Create and use a dummy gas object if there is no gas object provided.
let dummy_gas_object = Object::new_gas_with_balance_and_owner_for_testing(
DEV_INSPECT_GAS_COIN_VALUE,
transaction.gas_owner(),
);
let gas_object_ref = dummy_gas_object.compute_object_reference();
transaction.gas_data_mut().payment = vec![gas_object_ref];
input_objects.push(ObjectReadResult::new(
InputObjectKind::ImmOrOwnedMoveObject(gas_objects[0]),
InputObjectKind::ImmOrOwnedMoveObject(gas_object_ref),
dummy_gas_object.into(),
));
}
Expand All @@ -2209,6 +2203,13 @@ impl AuthorityState {
// If we are not skipping checks, then we call the check_transaction_input function and its dummy gas
// variant which will perform full fledged checks just like a real transaction execution.
if transaction.gas().is_empty() {
// Create and use a dummy gas object if there is no gas object provided.
let dummy_gas_object = Object::new_gas_with_balance_and_owner_for_testing(
DEV_INSPECT_GAS_COIN_VALUE,
transaction.gas_owner(),
);
let gas_object_ref = dummy_gas_object.compute_object_reference();
transaction.gas_data_mut().payment = vec![gas_object_ref];
sui_transaction_checks::check_transaction_input_with_given_gas(
epoch_store.protocol_config(),
epoch_store.reference_gas_price(),
Expand All @@ -2234,6 +2235,7 @@ impl AuthorityState {

let executor = sui_execution::executor(protocol_config, /* silent */ true, None)
.expect("Creating an executor should not fail here");
let gas_data = transaction.gas_data().clone();
let intent_msg = IntentMessage::new(
Intent {
version: IntentVersion::V0,
Expand All @@ -2255,7 +2257,7 @@ impl AuthorityState {
.epoch_data()
.epoch_start_timestamp(),
checked_input_objects,
gas_objects,
gas_data,
gas_status,
transaction_kind,
sender,
Expand Down
20 changes: 16 additions & 4 deletions crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,14 @@ async fn test_publish_dependent_module_ok() {
);
let transaction = to_sender_signed_transaction(data, &sender_key);

let dependent_module_id =
TxContext::new(&sender, transaction.digest(), &EpochData::new_test()).fresh_id();
let dependent_module_id = TxContext::new(
&sender,
transaction.digest(),
&EpochData::new_test(),
rgp,
None,
)
.fresh_id();

// Object does not exist
assert!(authority.get_object(&dependent_module_id).await.is_none());
Expand Down Expand Up @@ -1739,8 +1745,14 @@ async fn test_publish_module_no_dependencies_ok() {
rgp,
);
let transaction = to_sender_signed_transaction(data, &sender_key);
let _module_object_id =
TxContext::new(&sender, transaction.digest(), &EpochData::new_test()).fresh_id();
let _module_object_id = TxContext::new(
&sender,
transaction.digest(),
&EpochData::new_test(),
rgp,
None,
)
.fresh_id();
let signed_effects = send_and_confirm_transaction(&authority, transaction)
.await
.unwrap()
Expand Down
5 changes: 3 additions & 2 deletions crates/sui-genesis-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,8 @@ fn create_genesis_transaction(
let expensive_checks = false;
let certificate_deny_set = HashSet::new();
let transaction_data = &genesis_transaction.data().intent_message().value;
let (kind, signer, _) = transaction_data.execution_parts();
let (kind, signer, mut gas_data) = transaction_data.execution_parts();
gas_data.payment = vec![];
let input_objects = CheckedInputObjects::new_for_genesis(vec![]);
let (inner_temp_store, _, effects, _timings, _execution_error) = executor
.execute_transaction_to_effects(
Expand All @@ -926,7 +927,7 @@ fn create_genesis_transaction(
&epoch_data.epoch_id(),
epoch_data.epoch_start_timestamp(),
input_objects,
vec![],
gas_data,
SuiGasStatus::new_unmetered(),
kind,
signer,
Expand Down
31 changes: 17 additions & 14 deletions crates/sui-replay/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use sui_sdk::{SuiClient, SuiClientBuilder};
use sui_types::in_memory_storage::InMemoryStorage;
use sui_types::message_envelope::Message;
use sui_types::storage::{get_module, PackageObject};
use sui_types::transaction::GasData;
use sui_types::transaction::TransactionKind::ProgrammableTransaction;
use sui_types::SUI_DENY_LIST_OBJECT_ID;
use sui_types::{
Expand Down Expand Up @@ -757,8 +758,8 @@ impl LocalExec {
SuiGasStatus::new_unmetered()
} else {
SuiGasStatus::new(
tx_info.gas_budget,
tx_info.gas_price,
tx_info.gas.budget,
tx_info.gas.price,
tx_info.reference_gas_price,
protocol_config,
)
Expand Down Expand Up @@ -843,8 +844,8 @@ impl LocalExec {
CheckedInputObjects::new_for_replay(input_objects),
tx_info.gas.clone(),
SuiGasStatus::new(
tx_info.gas_budget,
tx_info.gas_price,
tx_info.gas.budget,
tx_info.gas.price,
tx_info.reference_gas_price,
protocol_config,
)?,
Expand Down Expand Up @@ -924,7 +925,7 @@ impl LocalExec {
reference_gas_price,
)
.unwrap();
let (kind, signer, gas) = executable.transaction_data().execution_parts();
let (kind, signer, gas_data) = executable.transaction_data().execution_parts();
let executor = sui_execution::executor(&protocol_config, true, None).unwrap();
let (_, _, effects, _timings, exec_res) = executor.execute_transaction_to_effects(
&store,
Expand All @@ -935,7 +936,7 @@ impl LocalExec {
&executed_epoch,
epoch_start_timestamp,
input_objects,
gas,
gas_data,
gas_status,
kind,
signer,
Expand Down Expand Up @@ -1508,6 +1509,12 @@ impl LocalExec {
.iter()
.map(|obj_ref| obj_ref.to_object_ref())
.collect();
let gas_data = GasData {
payment: gas_object_refs,
owner: gas_data.owner,
price: gas_data.price,
budget: gas_data.budget,
};
let receiving_objs = orig_tx
.transaction_data()
.receiving_objects()
Expand All @@ -1529,9 +1536,7 @@ impl LocalExec {
modified_at_versions,
input_objects: input_objs,
shared_object_refs,
gas: gas_object_refs,
gas_budget: gas_data.budget,
gas_price: gas_data.price,
gas: gas_data,
executed_epoch: epoch_id,
dependencies: effects.dependencies().to_vec(),
effects: SuiTransactionBlockEffects::V1(effects),
Expand Down Expand Up @@ -1592,8 +1597,7 @@ impl LocalExec {
}
})
.collect();
let gas_data = orig_tx.transaction_data().gas_data();
let gas_object_refs: Vec<_> = gas_data.clone().payment.into_iter().collect();
let gas_data = orig_tx.transaction_data().gas_data().clone();
let receiving_objs = orig_tx
.transaction_data()
.receiving_objects()
Expand All @@ -1618,9 +1622,7 @@ impl LocalExec {
modified_at_versions,
input_objects: input_objs,
shared_object_refs,
gas: gas_object_refs,
gas_budget: gas_data.budget,
gas_price: gas_data.price,
gas: gas_data,
executed_epoch: epoch_id,
dependencies: effects.dependencies().to_vec(),
effects,
Expand Down Expand Up @@ -1799,6 +1801,7 @@ impl LocalExec {
// Download gas (although this should already be in cache from modified at versions?)
let gas_refs: Vec<_> = tx_info
.gas
.payment
.iter()
.filter_map(|w| (w.0 != ObjectID::ZERO).then_some((w.0, w.1)))
.collect();
Expand Down
6 changes: 2 additions & 4 deletions crates/sui-replay/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sui_types::base_types::{ObjectID, ObjectRef, SequenceNumber, SuiAddress, Ver
use sui_types::digests::{ObjectDigest, TransactionDigest};
use sui_types::error::{SuiError, SuiObjectResponseError, SuiResult, UserInputError};
use sui_types::object::Object;
use sui_types::transaction::{InputObjectKind, SenderSignedData, TransactionKind};
use sui_types::transaction::{GasData, InputObjectKind, SenderSignedData, TransactionKind};
use thiserror::Error;
use tokio::time::Duration;
use tracing::{error, warn};
Expand All @@ -43,9 +43,7 @@ pub struct OnChainTransactionInfo {
pub kind: TransactionKind,
pub modified_at_versions: Vec<(ObjectID, SequenceNumber)>,
pub shared_object_refs: Vec<ObjectRef>,
pub gas: Vec<(ObjectID, SequenceNumber, ObjectDigest)>,
pub gas_budget: u64,
pub gas_price: u64,
pub gas: GasData,
pub executed_epoch: u64,
pub dependencies: Vec<TransactionDigest>,
#[serde(skip)]
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-single-node-benchmark/src/single_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl SingleValidator {
self.epoch_store.reference_gas_price(),
)
.unwrap();
let (kind, signer, gas) = executable.transaction_data().execution_parts();
let (kind, signer, gas_data) = executable.transaction_data().execution_parts();
let (inner_temp_store, _, effects, _timings, _) =
self.epoch_store.executor().execute_transaction_to_effects(
&store,
Expand All @@ -215,7 +215,7 @@ impl SingleValidator {
&self.epoch_store.epoch(),
0,
input_objects,
gas,
gas_data,
gas_status,
kind,
signer,
Expand Down
5 changes: 3 additions & 2 deletions crates/sui-swarm-config/src/network_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ mod test {
let certificate_deny_set = HashSet::new();
let epoch = EpochData::new_test();
let transaction_data = &genesis_transaction.data().intent_message().value;
let (kind, signer, _) = transaction_data.execution_parts();
let (kind, signer, mut gas_data) = transaction_data.execution_parts();
gas_data.payment = vec![];
let input_objects = CheckedInputObjects::new_for_genesis(vec![]);

let (_inner_temp_store, _, effects, _timings, _execution_error) = executor
Expand All @@ -612,7 +613,7 @@ mod test {
&epoch.epoch_id(),
epoch.epoch_start_timestamp(),
input_objects,
vec![],
gas_data,
SuiGasStatus::new_unmetered(),
kind,
signer,
Expand Down
Loading

0 comments on commit d5539ba

Please sign in to comment.