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

propagate estimation errors #867

Merged
merged 3 commits into from
Oct 11, 2023
Merged
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
27 changes: 23 additions & 4 deletions crates/core/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod util;
use crate::ring::{Location, PeerKeyLocation};
use isotonic_estimator::{EstimatorType, IsotonicEstimator, IsotonicEvent};
use serde::Serialize;
use std::time::Duration;
use std::{fmt, time::Duration};
use util::{Mean, TransferSpeed};

#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -196,15 +196,24 @@ impl Router {
let time_to_response_start_estimate = self
.response_start_time_estimator
.estimate_retrieval_time(peer, contract_location)
.unwrap();
.map_err(|e| {
RoutingError::EstimationError(format!(
"Response Start Time Estimation failed: {}",
e
))
})?;
let failure_estimate = self
.failure_estimator
.estimate_retrieval_time(peer, contract_location)
.unwrap();
.map_err(|e| {
RoutingError::EstimationError(format!("Failure Estimation failed: {}", e))
})?;
let transfer_rate_estimate = self
.transfer_rate_estimator
.estimate_retrieval_time(peer, contract_location)
.unwrap();
.map_err(|e| {
RoutingError::EstimationError(format!("Transfer Rate Estimation failed: {}", e))
})?;

// This is a fairly naive approach, assuming that the cost of a failure is a multiple
// of the cost of success.
Expand Down Expand Up @@ -233,6 +242,16 @@ impl Router {
#[derive(Debug)]
pub(crate) enum RoutingError {
InsufficientDataError,
EstimationError(String),
}

impl fmt::Display for RoutingError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RoutingError::InsufficientDataError => write!(f, "Insufficient data provided"),
RoutingError::EstimationError(err_msg) => write!(f, "Estimation error: {}", err_msg),
}
}
}

#[derive(Debug, Clone, Copy, Serialize)]
Expand Down
10 changes: 9 additions & 1 deletion crates/core/src/router/isotonic_estimator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ring::{Distance, Location, PeerKeyLocation};
use pav_regression::pav::{IsotonicRegression, Point};
use serde::Serialize;
use std::collections::HashMap;
use std::{collections::HashMap, fmt};

const MIN_POINTS_FOR_REGRESSION: usize = 5;

Expand Down Expand Up @@ -160,6 +160,14 @@ pub(crate) enum EstimationError {
InsufficientData, // Error indicating that there is not enough data for estimation
}

impl fmt::Display for EstimationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EstimationError::InsufficientData => write!(f, "Insufficient data for estimation"),
}
}
}

/// A routing event is a single request to a peer for a contract, and some value indicating
/// the result of the request, such as the time it took to retrieve the contract.
#[derive(Debug, Clone)]
Expand Down