Skip to content
Closed
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tower = "0.5.2"
strum_macros = "0.24.3"
strum = "0.24.1"
toml = "0.5.9"
indoc = "2.0.6"

hiro-system-kit = { version = "0.1.0", features = ["log"] }
clarinet-files = "3"
Expand Down
134 changes: 131 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use clarinet_files::{compute_addresses, StacksNetwork};
use std::{collections::BTreeMap, str::FromStr, time::Duration};
use std::{env, thread::sleep};

use clarinet_files::{compute_addresses, DevnetConfig, StacksNetwork};
use futures::future::try_join3;
use hiro_system_kit::{slog, Logger};
use hyper::{
body::{Bytes, HttpBody},
Body, Client as HttpClient, Request, Response, Uri,
};
use indoc::formatdoc;
use k8s_openapi::{
api::{
apps::v1::{Deployment, StatefulSet},
Expand All @@ -25,9 +29,8 @@ use resources::{
StacksDevnetResource,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{collections::BTreeMap, str::FromStr, time::Duration};
use std::{env, thread::sleep};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
use tower::BoxError;

pub mod config;
Expand All @@ -44,6 +47,28 @@ use crate::resources::configmap::StacksDevnetConfigmap;
use crate::resources::pod::StacksDevnetPod;
use crate::resources::service::{get_service_url, StacksDevnetService};

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy, Eq, PartialOrd, Ord, EnumIter)]
pub enum EpochSpec {
#[serde(rename = "2.0")]
Epoch2_0,
#[serde(rename = "2.05")]
Epoch2_05,
#[serde(rename = "2.1")]
Epoch2_1,
#[serde(rename = "2.2")]
Epoch2_2,
#[serde(rename = "2.3")]
Epoch2_3,
#[serde(rename = "2.4")]
Epoch2_4,
#[serde(rename = "2.5")]
Epoch2_5,
#[serde(rename = "3.0")]
Epoch3_0,
#[serde(rename = "3.1")]
Epoch3_1,
}

const COMPONENT_SELECTOR: &str = "app.kubernetes.io/component";
const USER_SELECTOR: &str = "app.kubernetes.io/instance";
const NAME_SELECTOR: &str = "app.kubernetes.io/name";
Expand Down Expand Up @@ -103,6 +128,7 @@ struct StacksV2InfoResponse {
burn_block_height: u64,
stacks_tip_height: u64,
}

#[derive(Clone)]
pub struct StacksDevnetApiK8sManager {
client: Client,
Expand Down Expand Up @@ -1358,6 +1384,9 @@ impl StacksDevnetApiK8sManager {
get_service_port(StacksDevnetService::BitcoindNode, ServicePort::P2P).unwrap()
));

let epoch_conf = build_stacks_epoch_config(devnet_config);
stacks_conf.push_str(&epoch_conf);

stacks_conf.push_str(&format!(
r#"
[[burnchain.epochs]]
Expand Down Expand Up @@ -1395,6 +1424,10 @@ impl StacksDevnetApiK8sManager {
[[burnchain.epochs]]
epoch_name = "3.0"
start_height = {}

[[burnchain.epochs]]
epoch_name = "3.1"
start_height = {}
"#,
devnet_config.epoch_2_0,
devnet_config.epoch_2_05,
Expand All @@ -1404,6 +1437,7 @@ impl StacksDevnetApiK8sManager {
devnet_config.epoch_2_4,
devnet_config.epoch_2_5,
devnet_config.epoch_3_0,
devnet_config.epoch_3_1,
));
stacks_conf
};
Expand Down Expand Up @@ -1713,3 +1747,97 @@ impl StacksDevnetApiK8sManager {
}
}
}

fn build_stacks_epoch_config(config: &DevnetConfig) -> String {
EpochSpec::iter()
.map(|epoch| {
let start_height = match epoch {
EpochSpec::Epoch2_0 => config.epoch_2_0,
EpochSpec::Epoch2_05 => config.epoch_2_05,
EpochSpec::Epoch2_1 => config.epoch_2_1,
EpochSpec::Epoch2_2 => config.epoch_2_2,
EpochSpec::Epoch2_3 => config.epoch_2_3,
EpochSpec::Epoch2_4 => config.epoch_2_4,
EpochSpec::Epoch2_5 => config.epoch_2_5,
EpochSpec::Epoch3_0 => config.epoch_3_0,
EpochSpec::Epoch3_1 => config.epoch_3_1,
};
let epoch_toml = toml::to_string(&epoch).unwrap();
formatdoc!(
r#"
[[burnchain.epochs]]
epoch_name = {epoch_toml}
start_height = {start_height}
"#,
)
})
.collect::<Vec<String>>()
.join("\n")
}

#[cfg(test)]
mod tests {
use indoc::indoc;
use pretty_assertions::assert_eq;

use super::*;

#[test]
fn test_epoch_conf() {
let devnet_config = DevnetConfig {
epoch_2_0: 0,
epoch_2_05: 1,
epoch_2_1: 2,
epoch_2_2: 3,
epoch_2_3: 4,
epoch_2_4: 5,
epoch_2_5: 6,
epoch_3_0: 7,
epoch_3_1: 8,
..Default::default()
};

let epoch_config = build_stacks_epoch_config(&devnet_config);

assert_eq!(
epoch_config.trim_end(),
indoc! { r#"
[[burnchain.epochs]]
epoch_name = "2.0"
start_height = 0

[[burnchain.epochs]]
epoch_name = "2.05"
start_height = 1

[[burnchain.epochs]]
epoch_name = "2.1"
start_height = 2

[[burnchain.epochs]]
epoch_name = "2.2"
start_height = 3

[[burnchain.epochs]]
epoch_name = "2.3"
start_height = 4

[[burnchain.epochs]]
epoch_name = "2.4"
start_height = 5

[[burnchain.epochs]]
epoch_name = "2.5"
start_height = 6

[[burnchain.epochs]]
epoch_name = "3.0"
start_height = 7

[[burnchain.epochs]]
epoch_name = "3.1"
start_height = 8"#
}
);
}
}
Loading