Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gas] Fix potential data race in gas object check #4588

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crates/sui-core/src/transaction_input_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use crate::authority::SuiDataStore;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::fmt::Debug;
use sui_types::base_types::ObjectRef;
use sui_types::messages::TransactionKind;
use sui_types::{
base_types::{ObjectID, SequenceNumber, SuiAddress},
base_types::{SequenceNumber, SuiAddress},
error::{SuiError, SuiResult},
fp_ensure,
gas::{self, SuiGasStatus},
Expand All @@ -28,7 +29,7 @@ where
{
let mut gas_status = check_gas(
store,
transaction.gas_payment_object_ref().0,
transaction.gas_payment_object_ref(),
transaction.signed_data.data.gas_budget,
transaction.signed_data.data.gas_price,
&transaction.signed_data.data.kind,
Expand Down Expand Up @@ -90,7 +91,7 @@ where
#[instrument(level = "trace", skip_all)]
async fn check_gas<S>(
store: &SuiDataStore<S>,
gas_payment_id: ObjectID,
gas_payment: &ObjectRef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the digest isn't necessary and we can just pass the ID and version here.

gas_budget: u64,
computation_gas_price: u64,
tx_kind: &TransactionKind,
Expand All @@ -101,9 +102,11 @@ where
if tx_kind.is_system_tx() {
Ok(SuiGasStatus::new_unmetered())
} else {
let gas_object = store.get_object(&gas_payment_id)?;
let gas_object = gas_object.ok_or(SuiError::ObjectNotFound {
object_id: gas_payment_id,
let gas_object = store.get_object_by_key(&gas_payment.0, gas_payment.1)?;
let gas_object = gas_object.ok_or(SuiError::ObjectErrors {
errors: vec![SuiError::ObjectNotFound {
object_id: gas_payment.0,
}],
})?;

//TODO: cache this storage_gas_price in memory
Expand Down