Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use low default estimated execution time for unknown entry points #21423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions crates/sui-core/src/authority/execution_time_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ impl ExecutionTimeObserver {
}
}

// Default duration estimate used for transations containing a command without any
// available observations.
// TODO: Make this a protocol config.
const DEFAULT_TRANSACTION_DURATION: Duration = Duration::from_millis(1_500);

// Key used to save StoredExecutionTimeObservations in the Sui system state object's
// `extra_fields` Bag.
pub const EXTRA_FIELD_EXECUTION_TIME_ESTIMATES_KEY: u64 = 0;
Expand Down Expand Up @@ -336,19 +331,19 @@ impl ExecutionTimeEstimator {
debug_fatal!("get_estimate called on non-ProgrammableTransaction");
return Duration::ZERO;
};
let mut estimate = Duration::ZERO;
for command in &tx.commands {
let key = ExecutionTimeObservationKey::from_command(command);
let Some(command_estimate) = self.consensus_observations.get(&key).map(|obs| {
obs.stake_weighted_median
tx.commands
.iter()
.map(|command| {
let key = ExecutionTimeObservationKey::from_command(command);
self.consensus_observations
.get(&key)
.map(|obs| obs.stake_weighted_median)
.unwrap_or_else(|| key.default_duration())
// For native commands, adjust duration by length of command's inputs/outputs.
// This is sort of arbitrary, but hopefully works okay as a heuristic.
.mul_f64(command_length(command).get() as f64)
}) else {
estimate = DEFAULT_TRANSACTION_DURATION;
break;
};
estimate += command_estimate;
}
estimate
})
.sum()
}

pub fn take_observations(&mut self) -> StoredExecutionTimeObservations {
Expand Down
12 changes: 12 additions & 0 deletions crates/sui-types/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ impl ExecutionTimeObservationKey {
Command::Upgrade(_, _, _, _) => ExecutionTimeObservationKey::Upgrade,
}
}

pub fn default_duration(&self) -> Duration {
match self {
ExecutionTimeObservationKey::MoveEntryPoint { .. } => Duration::from_millis(1),
ExecutionTimeObservationKey::TransferObjects => Duration::from_millis(1),
ExecutionTimeObservationKey::SplitCoins => Duration::from_millis(1),
ExecutionTimeObservationKey::MergeCoins => Duration::from_millis(1),
ExecutionTimeObservationKey::Publish => Duration::from_millis(3),
ExecutionTimeObservationKey::MakeMoveVec => Duration::from_millis(1),
ExecutionTimeObservationKey::Upgrade => Duration::from_millis(3),
}
}
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
Expand Down
Loading