Skip to content

Commit

Permalink
add action plan ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed May 4, 2024
1 parent 4595ae8 commit 395e725
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crates/core/transaction/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ pub struct TransactionPlan {

impl TransactionPlan {
/// Sort the actions by type, using the protobuf field number in the [`Action`].
pub fn sort_actions(mut actions: Vec<Action>) -> Vec<Action> {
pub fn sort_actions(&self, mut actions: Vec<Action>) -> Vec<Action> {
actions.sort_by_key(|action: &Action| action.variant_index());

actions
}

/// Sort the action plans by type, using the protobuf field number in the [`ActionPlan`].
pub fn sort_action_plans(&self, mut actions_plans: Vec<ActionPlan>) -> Vec<ActionPlan> {
actions_plans.sort_by_key(|action: &ActionPlan| action.variant_index());

actions_plans
}

/// Computes the [`EffectHash`] for the [`Transaction`] described by this
/// [`TransactionPlan`].
///
Expand Down
2 changes: 1 addition & 1 deletion crates/core/transaction/src/plan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl TransactionPlan {
let detection_data = self.detection_data.as_ref().map(|x| x.detection_data());

// Implement canonical ordering to the actions to reduce client distinguishability.
actions = TransactionPlan::sort_actions(actions);
actions = self.sort_actions(actions);

let transaction_body = TransactionBody {
actions,
Expand Down

0 comments on commit 395e725

Please sign in to comment.