Skip to content

Commit

Permalink
[gas] Do not charge for loading Sui Framework or Move stdlib
Browse files Browse the repository at this point in the history
- The code for the Sui Framework and Move stdlib will live directly in the validator binary, so using these won't actually trigger an on-chain read. No need to charge users for this.
- For Sui Framework developers, it's quite cumbersome to change the gas snapshot tests every time code in the Sui Framework changes (since it tweaks the loading cost). This is a pain for us today, but in the future it will also be a pain for third-party devs--a change in the size of the Sui Framework due to a framework upgrade will change the gas cost for a dependent package `P` even if the actual functions called by `P` are unchanged by the upgrade.
  • Loading branch information
sblackshear committed Dec 19, 2022
1 parent 0e50053 commit faab3b6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
10 changes: 7 additions & 3 deletions crates/sui-core/src/execution_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use sui_types::storage::{ChildObjectResolver, DeleteKind, ParentSync, WriteKind}
#[cfg(test)]
use sui_types::temporary_store;
use sui_types::temporary_store::InnerTemporaryStore;
use sui_types::SUI_SYSTEM_STATE_OBJECT_SHARED_VERSION;
use sui_types::{
base_types::{ObjectID, ObjectRef, SuiAddress, TransactionDigest, TxContext},
gas::SuiGasStatus,
Expand All @@ -41,6 +40,9 @@ use sui_types::{
sui_system_state::{ADVANCE_EPOCH_FUNCTION_NAME, SUI_SYSTEM_MODULE_NAME},
SUI_FRAMEWORK_ADDRESS, SUI_SYSTEM_STATE_OBJECT_ID,
};
use sui_types::{
MOVE_STDLIB_OBJECT_ID, SUI_FRAMEWORK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_SHARED_VERSION,
};

use crate::authority::TemporaryStore;

Expand Down Expand Up @@ -118,8 +120,10 @@ fn charge_gas_for_object_read<S>(
// fetching only unique objects.
let total_size = temporary_store
.objects()
.values()
.map(|obj| obj.object_size_for_gas_metering())
.iter()
// don't charge for loading Sui Framework or Move stdlib
.filter(|(id, _)| *id != &SUI_FRAMEWORK_OBJECT_ID && *id != &MOVE_STDLIB_OBJECT_ID)
.map(|(_, obj)| obj.object_size_for_gas_metering())
.sum();
gas_status.charge_storage_read(total_size)
}
Expand Down
10 changes: 9 additions & 1 deletion crates/sui-core/src/unit_tests/gas_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use sui_types::{
crypto::get_key_pair,
gas::{SuiGasStatus, MAX_GAS_BUDGET, MIN_GAS_BUDGET},
};
use sui_types::{MOVE_STDLIB_OBJECT_ID, SUI_FRAMEWORK_OBJECT_ID};

#[tokio::test]
async fn test_tx_less_than_minimum_gas_budget() {
Expand Down Expand Up @@ -298,7 +299,14 @@ async fn test_publish_gas() -> anyhow::Result<()> {
gas_status.charge_storage_read(
genesis_objects
.iter()
.map(|o| o.object_size_for_gas_metering())
// do not charge for loads of the Sui Framework
.filter_map(|o| {
if o.id() != SUI_FRAMEWORK_OBJECT_ID && o.id() != MOVE_STDLIB_OBJECT_ID {
Some(o.object_size_for_gas_metering())
} else {
None
}
})
.sum(),
)?;
gas_status.charge_storage_read(gas_object.object_size_for_gas_metering())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ expression: common_costs_actual
---
{
"MergeCoin": {
"computation_cost": 733,
"computation_cost": 63,
"storage_cost": 32,
"storage_rebate": 0
},
"Publish": {
"computation_cost": 984,
"computation_cost": 226,
"storage_cost": 119,
"storage_rebate": 0
},
Expand All @@ -29,7 +29,7 @@ expression: common_costs_actual
"storage_rebate": 15
},
"SplitCoin": {
"computation_cost": 844,
"computation_cost": 173,
"storage_cost": 80,
"storage_rebate": 0
},
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod utils;
/// 0x1-- account address where Move stdlib modules are stored
/// Same as the ObjectID
pub const MOVE_STDLIB_ADDRESS: AccountAddress = AccountAddress::ONE;
pub const MOVE_STDLIB_OBJECT_ID: ObjectID = ObjectID::from_single_byte(1);

/// 0x2-- account address where sui framework modules are stored
/// Same as the ObjectID
Expand Down

0 comments on commit faab3b6

Please sign in to comment.