Skip to content

Commit

Permalink
Merge pull request #2998 from blockstack/fix/cost-dir
Browse files Browse the repository at this point in the history
fix: Create a separate directory for `estimates` tables
  • Loading branch information
gregorycoppola authored Jan 13, 2022
2 parents 7011f32 + 90e6a88 commit c61a7da
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,17 @@ impl Config {
path
}

/// Returns the path `{get_chainstate_path()}/estimates`, and ensures it exists.
pub fn get_estimates_path(&self) -> PathBuf {
let mut path = self.get_chainstate_path();
path.push("estimates");
fs::create_dir_all(&path).expect(&format!(
"Failed to create `estimates` directory at {}",
path.to_string_lossy()
));
path
}

pub fn get_chainstate_path_str(&self) -> String {
self.get_chainstate_path()
.to_str()
Expand Down Expand Up @@ -1175,7 +1186,7 @@ impl Config {
match self.estimation.cost_estimator.as_ref()? {
CostEstimatorName::NaivePessimistic => Box::new(
self.estimation
.make_pessimistic_cost_estimator(self.get_chainstate_path()),
.make_pessimistic_cost_estimator(self.get_estimates_path()),
),
};

Expand All @@ -1197,10 +1208,10 @@ impl Config {
let fee_estimator: Box<dyn FeeEstimator> = match self.estimation.fee_estimator.as_ref()? {
FeeEstimatorName::ScalarFeeRate => self
.estimation
.make_scalar_fee_estimator(self.get_chainstate_path(), metric),
.make_scalar_fee_estimator(self.get_estimates_path(), metric),
FeeEstimatorName::FuzzedWeightedMedianFeeRate => self
.estimation
.make_fuzzed_weighted_median_fee_estimator(self.get_chainstate_path(), metric),
.make_fuzzed_weighted_median_fee_estimator(self.get_estimates_path(), metric),
};

Some(fee_estimator)
Expand All @@ -1210,11 +1221,11 @@ impl Config {
impl FeeEstimationConfig {
pub fn make_pessimistic_cost_estimator(
&self,
mut chainstate_path: PathBuf,
mut estimates_path: PathBuf,
) -> PessimisticEstimator {
if let Some(CostEstimatorName::NaivePessimistic) = self.cost_estimator.as_ref() {
chainstate_path.push("cost_estimator_pessimistic.sqlite");
PessimisticEstimator::open(&chainstate_path, self.log_error)
estimates_path.push("cost_estimator_pessimistic.sqlite");
PessimisticEstimator::open(&estimates_path, self.log_error)
.expect("Error opening cost estimator")
} else {
panic!("BUG: Expected to configure a naive pessimistic cost estimator");
Expand All @@ -1223,13 +1234,13 @@ impl FeeEstimationConfig {

pub fn make_scalar_fee_estimator<CM: 'static + CostMetric>(
&self,
mut chainstate_path: PathBuf,
mut estimates_path: PathBuf,
metric: CM,
) -> Box<dyn FeeEstimator> {
if let Some(FeeEstimatorName::ScalarFeeRate) = self.fee_estimator.as_ref() {
chainstate_path.push("fee_estimator_scalar_rate.sqlite");
estimates_path.push("fee_estimator_scalar_rate.sqlite");
Box::new(
ScalarFeeRateEstimator::open(&chainstate_path, metric)
ScalarFeeRateEstimator::open(&estimates_path, metric)
.expect("Error opening fee estimator"),
)
} else {
Expand All @@ -1241,13 +1252,13 @@ impl FeeEstimationConfig {
// is uniform with bounds [+/- 0.5].
pub fn make_fuzzed_weighted_median_fee_estimator<CM: 'static + CostMetric>(
&self,
mut chainstate_path: PathBuf,
mut estimates_path: PathBuf,
metric: CM,
) -> Box<dyn FeeEstimator> {
if let Some(FeeEstimatorName::FuzzedWeightedMedianFeeRate) = self.fee_estimator.as_ref() {
chainstate_path.push("fee_fuzzed_weighted_median.sqlite");
estimates_path.push("fee_fuzzed_weighted_median.sqlite");
let underlying_estimator = WeightedMedianFeeRateEstimator::open(
&chainstate_path,
&estimates_path,
metric,
self.fee_rate_window_size
.try_into()
Expand Down

0 comments on commit c61a7da

Please sign in to comment.