Skip to content

Commit

Permalink
fix: Preview with skip_epoch_check flag no longer requires correct ep…
Browse files Browse the repository at this point in the history
…ochs
  • Loading branch information
dhedey committed Oct 14, 2024
1 parent d0b1272 commit 3fc9cad
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 37 deletions.
38 changes: 16 additions & 22 deletions radix-engine/src/system/system_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ impl<V: SystemCallbackObject> System<V> {
expiry_epoch,
..
} => (intent_hash.into_hash(), expiry_epoch),
IntentHashNullification::SimulatedTransactionIntent { simulated } => {
let intent_hash = simulated.intent_hash();
let expiry_epoch =
simulated.expiry_epoch(Epoch::of(transaction_tracker.start_epoch));
(intent_hash.into_hash(), expiry_epoch)
}
IntentHashNullification::Subintent {
intent_hash,
expiry_epoch,
Expand All @@ -925,7 +931,7 @@ impl<V: SystemCallbackObject> System<V> {
};

let partition_number = transaction_tracker.partition_for_expiry_epoch(expiry_epoch)
.expect("Validation of the max expiry epoch window should ensure that the expiry epoch is in range for the transaction tracker");
.expect("Validation of the max expiry epoch window combined with the current epoch check on launch should ensure that the expiry epoch is in range for the transaction tracker");

// Update the status of the intent hash
track
Expand Down Expand Up @@ -1556,38 +1562,26 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
IntentHashNullification::TransactionIntent {
intent_hash,
expiry_epoch,
ignore_duplicate,
} => {
if *ignore_duplicate {
Ok(())
} else {
Self::validate_intent_hash_uncosted(
store,
intent_hash.as_hash(),
*expiry_epoch,
)
}
Self::validate_intent_hash_uncosted(store, intent_hash.as_hash(), *expiry_epoch)
}
IntentHashNullification::SimulatedTransactionIntent { .. } => {
// No validation is done on a simulated transaction intent used during preview
Ok(())
}
IntentHashNullification::Subintent {
intent_hash,
expiry_epoch,
ignore_duplicate,
} => {
if *ignore_duplicate {
Ok(())
} else {
Self::validate_intent_hash_uncosted(
store,
intent_hash.as_hash(),
*expiry_epoch,
)
}
Self::validate_intent_hash_uncosted(store, intent_hash.as_hash(), *expiry_epoch)
}
}
.and_then(|_| {
match hash_nullification {
IntentHashNullification::TransactionIntent { .. } => {
IntentHashNullification::TransactionIntent { .. }
| IntentHashNullification::SimulatedTransactionIntent { .. } => {
// Transaction intent nullification is historically not costed.
// If this changes, it should be applied to both TransactionIntents and SimulatedTransactionIntents
}
IntentHashNullification::Subintent { .. } => {
num_of_intent_statuses += 1;
Expand Down
2 changes: 0 additions & 2 deletions radix-transactions/src/model/concepts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ impl IntentHash {
IntentHash::Transaction(tx_intent_hash) => IntentHashNullification::TransactionIntent {
intent_hash: tx_intent_hash,
expiry_epoch,
ignore_duplicate: false,
},
IntentHash::Subintent(subintent_hash) => IntentHashNullification::Subintent {
intent_hash: subintent_hash,
expiry_epoch,
ignore_duplicate: false,
},
}
}
Expand Down
31 changes: 25 additions & 6 deletions radix-transactions/src/model/execution/executable_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,52 @@ impl From<(BlueprintId, GlobalAddress)> for PreAllocatedAddress {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IntentHashNullification {
/// Should be checked with transaction tracker.
/// Will be written
/// Assuming the transaction gets committed, this will be persisted/nullified regardless of success
TransactionIntent {
intent_hash: TransactionIntentHash,
expiry_epoch: Epoch,
ignore_duplicate: bool,
},
/// Used in preview. For realistic preview, should be billed as if it were a real transaction intent nullification.
/// But it shouldn't error or prevent the preview from running.
SimulatedTransactionIntent {
simulated: SimulatedTransactionIntentNullification,
},
/// Subintent - should only be written on failure
Subintent {
intent_hash: SubintentHash,
expiry_epoch: Epoch,
ignore_duplicate: bool,
},
}

impl IntentHashNullification {
pub fn intent_hash(&self) -> Option<IntentHash> {
pub fn intent_hash(&self) -> IntentHash {
match self {
IntentHashNullification::TransactionIntent { intent_hash, .. } => {
Some(IntentHash::Transaction(*intent_hash))
IntentHash::Transaction(*intent_hash)
}
IntentHashNullification::SimulatedTransactionIntent { simulated } => {
IntentHash::Transaction(simulated.intent_hash())
}
IntentHashNullification::Subintent { intent_hash, .. } => {
Some(IntentHash::Subintent(*intent_hash))
IntentHash::Subintent(*intent_hash)
}
}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SimulatedTransactionIntentNullification;

impl SimulatedTransactionIntentNullification {
pub fn intent_hash(&self) -> TransactionIntentHash {
TransactionIntentHash::from_hash(Hash([0; Hash::LENGTH]))
}

pub fn expiry_epoch(&self, current_epoch: Epoch) -> Epoch {
current_epoch.next().unwrap_or(Epoch::of(u64::MAX))
}
}

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor, ManifestSbor, Default)]
pub struct TransactionCostingParameters {
pub tip: TipSpecifier,
Expand Down
1 change: 0 additions & 1 deletion radix-transactions/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ Enum<3u8>(
intent_hash_nullifications: vec![IntentHashNullification::TransactionIntent {
intent_hash: expected_intent_hash,
expiry_epoch: Epoch::of(66),
ignore_duplicate: false,
}],
epoch_range: Some(EpochRange {
start_epoch_inclusive: Epoch::of(55),
Expand Down
17 changes: 12 additions & 5 deletions radix-transactions/src/model/v1/preview_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,25 @@ impl ValidatedPreviewIntent {

let intent_hash = intent.transaction_intent_hash();

let nullification = if flags.skip_epoch_check {
IntentHashNullification::SimulatedTransactionIntent {
simulated: SimulatedTransactionIntentNullification,
}
} else {
IntentHashNullification::TransactionIntent {
intent_hash,
expiry_epoch: intent.header.inner.end_epoch_exclusive,
}
};

ExecutableTransaction::new_v1(
self.encoded_instructions,
AuthZoneInit::new(initial_proofs, simulate_every_proof_under_resources),
intent.instructions.references,
intent.blobs.blobs_by_hash,
ExecutionContext {
unique_hash: intent_hash.0,
intent_hash_nullifications: vec![IntentHashNullification::TransactionIntent {
intent_hash,
expiry_epoch: intent.header.inner.end_epoch_exclusive,
ignore_duplicate: flags.skip_epoch_check,
}],
intent_hash_nullifications: vec![nullification],
epoch_range: if flags.skip_epoch_check {
None
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl ValidatedNotarizedTransactionV1 {
intent_hash_nullifications: vec![IntentHashNullification::TransactionIntent {
intent_hash,
expiry_epoch: header.end_epoch_exclusive,
ignore_duplicate: false,
}],
epoch_range: Some(EpochRange {
start_epoch_inclusive: header.start_epoch_inclusive,
Expand Down

0 comments on commit 3fc9cad

Please sign in to comment.