Skip to content

Commit

Permalink
Merge pull request #1990 from radixdlt/feature/adjust-nullification-cost
Browse files Browse the repository at this point in the history
Add cost for transaction intent hash status
  • Loading branch information
iamyulong authored Oct 31, 2024
2 parents e56a2ce + 5c2fc87 commit d7070aa
Show file tree
Hide file tree
Showing 258 changed files with 4,049 additions and 3,916 deletions.
2 changes: 1 addition & 1 deletion radix-engine-tests/tests/application/execution_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ fn test_execution_trace_for_transaction_v2() {
"58d39b18c2cb0885ab8e1da7b25b973ed5489f64e0765696956941aa1cf5",
),
resource_address: ResourceAddress(5da66318c6318c61f5a61b4c6318c6318cf794aa8d295f14e6318c6318c6),
amount: -0.33513389042,
amount: -0.34813389042,
},
],
1: [
Expand Down
6 changes: 2 additions & 4 deletions radix-engine/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'h, S: SubstateDatabase> BootLoader<'h, S> {
kernel_boot.always_visible_global_nodes(),
);

let (mut system, call_frame_inits, num_of_intent_statuses) = match system_init_result {
let (mut system, call_frame_inits) = match system_init_result {
Ok(success) => success,
Err(receipt) => return receipt,
};
Expand Down Expand Up @@ -184,9 +184,7 @@ impl<'h, S: SubstateDatabase> BootLoader<'h, S> {

// Finalize state updates based on what has occurred
let commit_info = kernel.substate_io.store.get_commit_info();
kernel
.callback
.finalize(commit_info, num_of_intent_statuses)?;
kernel.callback.finalize(executable, commit_info)?;

Ok(output)
}()
Expand Down
4 changes: 2 additions & 2 deletions radix-engine/src/kernel/kernel_callback_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub trait KernelTransactionExecutor: KernelCallbackObject {
executable: &Self::Executable,
init: Self::Init,
always_visible_global_nodes: &'static IndexSet<NodeId>,
) -> Result<(Self, Vec<CallFrameInit<Self::CallFrameData>>, usize), Self::Receipt>;
) -> Result<(Self, Vec<CallFrameInit<Self::CallFrameData>>), Self::Receipt>;

/// Start execution
fn execute<Y: KernelApi<CallbackObject = Self>>(
Expand All @@ -177,8 +177,8 @@ pub trait KernelTransactionExecutor: KernelCallbackObject {
/// Finish execution
fn finalize(
&mut self,
executable: &Self::Executable,
store_commit_info: StoreCommitInfo,
num_of_intent_statuses: usize,
) -> Result<(), RuntimeError>;

/// Create final receipt
Expand Down
64 changes: 44 additions & 20 deletions radix-engine/src/system/system_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ impl SystemVersion {

true
}

pub fn should_charge_for_transaction_intent(&self) -> bool {
match self {
SystemVersion::V1 => false,
SystemVersion::V2 => true,
}
}
}

#[derive(Clone)]
Expand Down Expand Up @@ -1515,7 +1522,7 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
executable: &ExecutableTransaction,
init_input: Self::Init,
always_visible_global_nodes: &'static IndexSet<NodeId>,
) -> Result<(Self, Vec<CallFrameInit<Actor>>, usize), Self::Receipt> {
) -> Result<(Self, Vec<CallFrameInit<Actor>>), Self::Receipt> {
// Dump executable
#[cfg(not(feature = "alloc"))]
if init_input.self_init.enable_kernel_trace {
Expand Down Expand Up @@ -1553,7 +1560,6 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
}
}

let mut num_of_intent_statuses = 0;
for hash_nullification in executable.intent_hash_nullifications() {
let intent_hash_validation_result = match hash_nullification {
IntentHashNullification::TransactionIntent {
Expand Down Expand Up @@ -1582,27 +1588,26 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
}
}
.and_then(|_| {
match hash_nullification {
let charge_for_nullification_check = match hash_nullification {
IntentHashNullification::TransactionIntent { .. }
| IntentHashNullification::SimulatedTransactionIntent { .. } => {
// Transaction intent nullification is historically not costed.
// If this changes, it should be applied to both TransactionIntents and SimulatedTransactionIntents
logic_version.should_charge_for_transaction_intent()
}
IntentHashNullification::Subintent { .. }
| IntentHashNullification::SimulatedSubintent { .. } => {
num_of_intent_statuses += 1;

if let Some(costing) = modules.costing_mut() {
return costing
.apply_deferred_execution_cost(
ExecutionCostingEntry::CheckIntentValidity,
| IntentHashNullification::SimulatedSubintent { .. } => true,
};

if charge_for_nullification_check {
if let Some(costing) = modules.costing_mut() {
return costing
.apply_deferred_execution_cost(
ExecutionCostingEntry::CheckIntentValidity,
)
.map_err(|e| {
RejectionReason::BootloadingError(
BootloadingError::FailedToApplyDeferredCosts(e),
)
.map_err(|e| {
RejectionReason::BootloadingError(
BootloadingError::FailedToApplyDeferredCosts(e),
)
});
}
});
}
}

Expand Down Expand Up @@ -1696,7 +1701,7 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
},
);

Ok((system, call_frame_inits, num_of_intent_statuses))
Ok((system, call_frame_inits))
}

fn execute<Y: SystemBasedKernelApi>(
Expand Down Expand Up @@ -1730,8 +1735,8 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {

fn finalize(
&mut self,
executable: &ExecutableTransaction,
info: StoreCommitInfo,
num_of_intent_statuses: usize,
) -> Result<(), RuntimeError> {
self.modules.on_teardown()?;

Expand All @@ -1754,6 +1759,25 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
logs: &self.modules.logs().clone(),
})
.map_err(|e| RuntimeError::FinalizationCostingError(e))?;
let num_of_intent_statuses = executable
.intent_hash_nullifications()
.iter()
.map(|n| match n {
IntentHashNullification::TransactionIntent { .. }
| IntentHashNullification::SimulatedTransactionIntent { .. } => {
if self
.versioned_system_logic
.should_charge_for_transaction_intent()
{
1
} else {
0
}
}
IntentHashNullification::Subintent { .. }
| IntentHashNullification::SimulatedSubintent { .. } => 1,
})
.sum();
self.modules
.apply_finalization_cost(FinalizationCostingEntry::CommitIntentStatus {
num_of_intent_statuses,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Total Cost (XRD) , 0.94495298742, 100.0%
- Execution Cost (XRD) , 0.329885, 34.9%
- Finalization Cost (XRD) , 0.1960235, 20.7%
- Storage Cost (XRD) , 0.41904448742, 44.3%
Total Cost (XRD) , 0.95795298742, 100.0%
- Execution Cost (XRD) , 0.337885, 35.3%
- Finalization Cost (XRD) , 0.2010235, 21.0%
- Storage Cost (XRD) , 0.41904448742, 43.7%
- Tipping Cost (XRD) , 0, 0.0%
- Royalty Cost (XRD) , 0, 0.0%
Execution Cost Breakdown , 6597700, 100.0%
Execution Cost Breakdown , 6757700, 100.0%
- AfterInvoke , 846, 0.0%
- AllocateNodeId , 3201, 0.0%
- BeforeInvoke , 5962, 0.1%
- CheckIntentValidity , 160000, 2.4%
- CheckReference , 40011, 0.6%
- CloseSubstate , 45150, 0.7%
- CreateNode , 29642, 0.4%
Expand All @@ -18,23 +19,23 @@ Execution Cost Breakdown ,
- MarkSubstateAsTransient , 165, 0.0%
- MoveModule , 9520, 0.1%
- OpenSubstate::GlobalAccessController , 2227, 0.0%
- OpenSubstate::GlobalConsensusManager , 43783, 0.7%
- OpenSubstate::GlobalFungibleResourceManager , 171184, 2.6%
- OpenSubstate::GlobalConsensusManager , 43783, 0.6%
- OpenSubstate::GlobalFungibleResourceManager , 171184, 2.5%
- OpenSubstate::GlobalGenericComponent , 47373, 0.7%
- OpenSubstate::GlobalNonFungibleResourceManager , 93378, 1.4%
- OpenSubstate::GlobalPackage , 3379244, 51.2%
- OpenSubstate::GlobalPackage , 3379244, 50.0%
- OpenSubstate::InternalFungibleVault , 106652, 1.6%
- OpenSubstate::InternalGenericComponent , 57160, 0.9%
- OpenSubstate::InternalKeyValueStore , 202765, 3.1%
- OpenSubstate::InternalGenericComponent , 57160, 0.8%
- OpenSubstate::InternalKeyValueStore , 202765, 3.0%
- PinNode , 336, 0.0%
- PrepareWasmCode , 707732, 10.7%
- PrepareWasmCode , 707732, 10.5%
- QueryActor , 2500, 0.0%
- QueryTransactionHash , 500, 0.0%
- ReadSubstate , 927777, 14.1%
- ReadSubstate , 927777, 13.7%
- RunNativeCode::Worktop_drop , 17918, 0.3%
- RunNativeCode::Worktop_put , 29033, 0.4%
- RunNativeCode::Worktop_take_all , 14602, 0.2%
- RunNativeCode::create , 156297, 2.4%
- RunNativeCode::create , 156297, 2.3%
- RunNativeCode::create_NonFungibleResourceManager , 88856, 1.3%
- RunNativeCode::create_empty_vault_FungibleResourceManager , 35570, 0.5%
- RunNativeCode::create_with_data , 54942, 0.8%
Expand All @@ -44,20 +45,20 @@ Execution Cost Breakdown ,
- RunNativeCode::lock_fee , 45243, 0.7%
- RunNativeCode::put_FungibleVault , 24554, 0.4%
- RunNativeCode::take_FungibleVault , 42457, 0.6%
- RunWasmCode::Faucet_free , 36859, 0.6%
- RunWasmCode::Faucet_free , 36859, 0.5%
- RunWasmCode::Faucet_lock_fee , 25290, 0.4%
- SetCallFrameData , 606, 0.0%
- SetSubstate , 944, 0.0%
- SwitchStack , 1000, 0.0%
- ValidateTxPayload , 24600, 0.4%
- VerifyTxSignatures , 7000, 0.1%
- WriteSubstate , 12778, 0.2%
Finalization Cost Breakdown , 3920470, 100.0%
Finalization Cost Breakdown , 4020470, 100.0%
- CommitEvents , 20030, 0.5%
- CommitIntentStatus , 0, 0.0%
- CommitIntentStatus , 100000, 2.5%
- CommitLogs , 0, 0.0%
- CommitStateUpdates::GlobalAccessController , 700142, 17.9%
- CommitStateUpdates::GlobalGenericComponent , 100018, 2.6%
- CommitStateUpdates::GlobalNonFungibleResourceManager , 2700228, 68.9%
- CommitStateUpdates::InternalFungibleVault , 300047, 7.7%
- CommitStateUpdates::InternalKeyValueStore , 100005, 2.6%
- CommitStateUpdates::GlobalAccessController , 700142, 17.4%
- CommitStateUpdates::GlobalGenericComponent , 100018, 2.5%
- CommitStateUpdates::GlobalNonFungibleResourceManager , 2700228, 67.2%
- CommitStateUpdates::InternalFungibleVault , 300047, 7.5%
- CommitStateUpdates::InternalKeyValueStore , 100005, 2.5%
Loading

0 comments on commit d7070aa

Please sign in to comment.