Skip to content

Commit

Permalink
Merge pull request #1986 from radixdlt/feature/split-error-code
Browse files Browse the repository at this point in the history
Add intent hash to the error code
  • Loading branch information
iamyulong authored Oct 30, 2024
2 parents 5673820 + 52b8e6b commit db8452f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions radix-engine-tests/tests/system/nullification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn v2_transaction_intent_gets_nullified_and_cannot_be_replayed() {
// Assert
assert_matches!(
duplicate_receipt.expect_rejection(),
&RejectionReason::IntentHashPreviouslyCommitted
&RejectionReason::IntentHashPreviouslyCommitted(IntentHash::Transaction(_))
);
}

Expand Down Expand Up @@ -106,6 +106,6 @@ fn v2_subintent_only_gets_nullified_on_success() {

assert_matches!(
receipt.expect_rejection(),
&RejectionReason::IntentHashPreviouslyCommitted
&RejectionReason::IntentHashPreviouslyCommitted(IntentHash::Subintent(_))
);
}
8 changes: 5 additions & 3 deletions radix-engine-tests/tests/system/transaction_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ fn test_transaction_replay_protection() {
executable.clone(),
ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
);
receipt.expect_specific_rejection(|e| match e {
RejectionReason::IntentHashPreviouslyCommitted => true,
_ => false,
receipt.expect_specific_rejection(|e| {
matches!(
e,
RejectionReason::IntentHashPreviouslyCommitted(IntentHash::Transaction(_))
)
});

// 4. Advance to the max epoch (which triggers epoch update)
Expand Down
5 changes: 3 additions & 2 deletions radix-engine/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::vm::ScryptoVmVersionError;
use radix_engine_interface::api::object_api::ModuleId;
use radix_engine_interface::api::{ActorStateHandle, AttachedModuleId};
use radix_engine_interface::blueprints::package::{BlueprintPartitionType, CanonicalBlueprintId};
use radix_transactions::model::IntentHash;

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
pub enum IdAllocationError {
Expand Down Expand Up @@ -65,8 +66,8 @@ pub enum RejectionReason {
valid_to_exclusive: Instant,
current_time: Instant,
},
IntentHashPreviouslyCommitted,
IntentHashPreviouslyCancelled,
IntentHashPreviouslyCommitted(IntentHash),
IntentHashPreviouslyCancelled(IntentHash),

BootloadingError(BootloadingError),

Expand Down
28 changes: 18 additions & 10 deletions radix-engine/src/system/system_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl<V: SystemCallbackObject> System<V> {

fn validate_intent_hash_uncosted<S: CommitableSubstateStore>(
store: &mut S,
intent_hash: &Hash,
intent_hash: IntentHash,
expiry_epoch: Epoch,
) -> Result<(), RejectionReason> {
let substate: FieldSubstate<TransactionTrackerSubstate> = store
Expand All @@ -562,7 +562,7 @@ impl<V: SystemCallbackObject> System<V> {
let substate = store.read_substate(
TRANSACTION_TRACKER.as_node_id(),
PartitionNumber(partition_number),
&SubstateKey::Map(scrypto_encode(&intent_hash).unwrap()),
&SubstateKey::Map(scrypto_encode(intent_hash.as_hash()).unwrap()),
);

match substate {
Expand All @@ -572,10 +572,14 @@ impl<V: SystemCallbackObject> System<V> {
Some(status) => match status.into_v1() {
TransactionStatusV1::CommittedSuccess
| TransactionStatusV1::CommittedFailure => {
return Err(RejectionReason::IntentHashPreviouslyCommitted);
return Err(RejectionReason::IntentHashPreviouslyCommitted(
intent_hash,
));
}
TransactionStatusV1::Cancelled => {
return Err(RejectionReason::IntentHashPreviouslyCancelled);
return Err(RejectionReason::IntentHashPreviouslyCancelled(
intent_hash,
));
}
},
None => {}
Expand Down Expand Up @@ -1555,19 +1559,23 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
IntentHashNullification::TransactionIntent {
intent_hash,
expiry_epoch,
} => {
Self::validate_intent_hash_uncosted(store, intent_hash.as_hash(), *expiry_epoch)
}
} => Self::validate_intent_hash_uncosted(
store,
IntentHash::Transaction(*intent_hash),
*expiry_epoch,
),
IntentHashNullification::SimulatedTransactionIntent { .. } => {
// No validation is done on a simulated transaction intent used during preview
Ok(())
}
IntentHashNullification::Subintent {
intent_hash,
expiry_epoch,
} => {
Self::validate_intent_hash_uncosted(store, intent_hash.as_hash(), *expiry_epoch)
}
} => Self::validate_intent_hash_uncosted(
store,
IntentHash::Subintent(*intent_hash),
*expiry_epoch,
),
IntentHashNullification::SimulatedSubintent { .. } => {
// No validation is done on a simulated subintent used during preview
Ok(())
Expand Down

0 comments on commit db8452f

Please sign in to comment.