Skip to content

Commit

Permalink
feat: upgrade clarinet to 2.9.0, use default values for chaintip
Browse files Browse the repository at this point in the history
  • Loading branch information
leahjlou committed Oct 3, 2024
1 parent feb7429 commit 7670c63
Show file tree
Hide file tree
Showing 8 changed files with 1,190 additions and 948 deletions.
1,941 changes: 1,072 additions & 869 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ http-body = "0.4.5"
hiro-system-kit = {version = "0.1.0", features = ["log"]}
strum_macros = "0.24.3"
strum = "0.24.1"
time = "0.3.35"
# clarity-repl = "1.8.0"
# clarity-repl = {version = "2.2.0", path = "../clarinet/components/clarity-repl" }
clarity-repl = {version = "2.3.1", git = "https://github.com/hirosystems/clarinet.git", rev="f06d087c5762fa06f7080b5c38994e7437048222" }
clarity-repl = {version = "2.9.0", git = "https://github.com/hirosystems/clarinet.git", rev="7085b877cdb9d533ccbf24cd947c5b4ee04bcc5b" }
# clarinet-files = {version = "1.0.3" }
# clarinet-files = {version = "2.2.0", path = "../clarinet/components/clarinet-files" }
clarinet-files = {version = "2.3.1", git = "https://github.com/hirosystems/clarinet.git", rev="f06d087c5762fa06f7080b5c38994e7437048222" }
clarinet-files = {version = "2.9.0", git = "https://github.com/hirosystems/clarinet.git", rev="7085b877cdb9d533ccbf24cd947c5b4ee04bcc5b" }
# clarinet-deployments = {version = "1.0.3" }
# clarinet-deployments = {version = "2.2.0", path = "../clarinet/components/clarinet-deployments" }
clarinet-deployments = {version = "2.3.1", git = "https://github.com/hirosystems/clarinet.git", rev="f06d087c5762fa06f7080b5c38994e7437048222" }
clarinet-deployments = {version = "2.9.0", git = "https://github.com/hirosystems/clarinet.git", rev="7085b877cdb9d533ccbf24cd947c5b4ee04bcc5b" }
# chainhook-types = "1.0"
chainhook-types = { version = "1.3" }
toml = "0.5.9"
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ COPY . /src

RUN mkdir /out
RUN rustup component add rustfmt
RUN cargo update
RUN cargo build --release --manifest-path ./Cargo.toml
RUN cp target/release/stacks-devnet-api /out

Expand Down
110 changes: 59 additions & 51 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chainhook_types::StacksNetwork;
use clarinet_files::compute_addresses;
use futures::future::try_join4;
use futures::future::try_join3;
use hiro_system_kit::{slog, Logger};
use hyper::{body::Bytes, Body, Client as HttpClient, Request, Response, Uri};
use k8s_openapi::{
Expand Down Expand Up @@ -560,72 +560,67 @@ impl StacksDevnetApiK8sManager {
namespace: &str,
) -> Result<StacksV2InfoResponse, DevNetError> {
let client = HttpClient::new();

// Log the constructed service URL and port
let url = get_service_url(namespace, StacksDevnetService::StacksBlockchain);
let port =
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::RPC).unwrap();
let port = get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::RPC).unwrap();
let url = format!("http://{}:{}/v2/info", url, port);

let context = format!("NAMESPACE: {}", namespace);

self.ctx.try_log(|logger: &hiro_system_kit::Logger| {
slog::info!(
logger,
"requesting /v2/info route of stacks node {}",
context
)
slog::info!(logger, "Requesting URL: {}", url); // Log the full URL
});


self.ctx.try_log(|logger: &hiro_system_kit::Logger| {
slog::info!(logger, "requesting /v2/info route of stacks node {}", context);
});

match Uri::from_str(&url) {
Ok(uri) => match client.get(uri).await {
Ok(response) => match hyper::body::to_bytes(response.into_body()).await {
Ok(body) => match serde_json::from_slice::<StacksV2InfoResponse>(&body) {
Ok(config) => {
Ok(response) => {
match hyper::body::to_bytes(response.into_body()).await {
Ok(body) => {
let body_str = String::from_utf8_lossy(&body);

Check warning on line 584 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L581-L584

Added lines #L581 - L584 were not covered by tests
self.ctx.try_log(|logger: &hiro_system_kit::Logger| {
slog::info!(
logger,
"successfully requested /v2/info route of stacks node {}",
context
)
slog::info!(logger, "Raw response body: {}", body_str);

Check warning on line 586 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L586

Added line #L586 was not covered by tests
});
Ok(config)

match serde_json::from_slice::<StacksV2InfoResponse>(&body) {

Check warning on line 589 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L589

Added line #L589 was not covered by tests
Ok(config) => {
self.ctx.try_log(|logger: &hiro_system_kit::Logger| {
slog::info!(logger, "Successfully requested /v2/info route of stacks node {}", context);
});
Ok(config)

Check warning on line 594 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L594

Added line #L594 was not covered by tests
}
Err(e) => {
let msg = format!("failed to parse JSON response: {}, ERROR: {}, Raw body: {}", context, e.to_string(), body_str);
self.ctx.try_log(|logger| slog::error!(logger, "{}", msg));

Check warning on line 598 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L596-L598

Added lines #L596 - L598 were not covered by tests
Err(DevNetError {
message: msg,
code: 500,

Check warning on line 601 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L600-L601

Added lines #L600 - L601 were not covered by tests
})
}
}
}
Err(e) => {
let msg = format!(
"failed to parse response: {}, ERROR: {}",
context,
e.to_string()
);
let msg = format!("failed to parse response bytes: {}, ERROR: {}", context, e.to_string());
self.ctx.try_log(|logger| slog::error!(logger, "{}", msg));
Err(DevNetError {
message: msg,
code: 500,
})
}
},
Err(e) => {
let msg = format!(
"failed to parse response: {}, ERROR: {}",
context,
e.to_string()
);
self.ctx.try_log(|logger| slog::error!(logger, "{}", msg));
Err(DevNetError {
message: msg,
code: 500,
})
}
},
}
Err(e) => {
let msg = format!(
"failed to query stacks node: {}, ERROR: {}",
context,
e.to_string()
);
let msg = format!("failed to query stacks node: {}, ERROR: {}", context, e.to_string());
self.ctx.try_log(|logger| slog::warn!(logger, "{}", msg));
Ok(StacksV2InfoResponse::default())
Ok(StacksV2InfoResponse::default()) // Return default response on error
}
},
Err(e) => {
let msg = format!("failed to parse url: {} ERROR: {}", context, e.to_string());
let msg = format!("failed to parse url: {} ERROR: {}", url, e.to_string());

Check warning on line 623 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L623

Added line #L623 was not covered by tests
self.ctx.try_log(|logger| slog::error!(logger, "{}", msg));
Err(DevNetError {
message: msg,
Expand All @@ -641,7 +636,7 @@ impl StacksDevnetApiK8sManager {
user_id: &str,
) -> Result<StacksDevnetInfoResponse, DevNetError> {
let context = format!("NAMESPACE: {}", namespace);

match self.check_all_devnet_assets_exist(&namespace).await? {
false => {
let msg = format!("not all devnet assets exist {}", context);
Expand All @@ -656,7 +651,8 @@ impl StacksDevnetApiK8sManager {
self.ctx.try_log(|logger: &hiro_system_kit::Logger| {
slog::info!(logger, "getting devnet info {}", context)
});


// Fetch the pod status information
let (
PodStatusResponse {
status: bitcoind_node_status,
Expand All @@ -669,9 +665,8 @@ impl StacksDevnetApiK8sManager {
PodStatusResponse {
status: stacks_api_status,
start_time: stacks_api_started_at,
},
chain_info,
) = try_join4(
}
) = try_join3(
self.get_pod_status_info(&namespace, user_id, StacksDevnetPod::BitcoindNode),
self.get_pod_status_info(
&namespace,
Expand All @@ -683,10 +678,23 @@ impl StacksDevnetApiK8sManager {
user_id,
StacksDevnetPod::StacksBlockchainApi,
),
self.get_stacks_v2_info(&namespace),
)
.await?;


// Try to fetch chain info, but handle errors by using default values for the chain tips
let chain_info = match self.get_stacks_v2_info(&namespace).await {
Ok(info) => info,
Err(e) => {

Check warning on line 687 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L687

Added line #L687 was not covered by tests
self.ctx.try_log(|logger: &hiro_system_kit::Logger| {
slog::warn!(logger, "Failed to get chain info: {}", e.message);

Check warning on line 689 in src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/lib.rs#L689

Added line #L689 was not covered by tests
});
StacksV2InfoResponse {
stacks_tip_height: 0,
burn_block_height: 0,
}
}
};

Ok(StacksDevnetInfoResponse {
bitcoind_node_status,
stacks_node_status,
Expand Down
11 changes: 10 additions & 1 deletion src/tests/fixtures/network-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,16 @@ devnet_settings:
stacks_node_events_observers:
- "host.docker.internal:20455"
stacks_node_env_vars: []
stacks_node_next_initiative_delay: 4000
stacks_api_port: 3999
stacks_api_events_port: 3700
stacks_api_env_vars: []
stacks_signers_keys:
- key: 7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c178
compress_public: true
- key: 530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc2091
compress_public: true
stacks_signers_env_vars: []
stacks_explorer_port: 8000
stacks_explorer_env_vars: []
bitcoin_explorer_port: 8001
Expand All @@ -113,6 +120,7 @@ devnet_settings:
faucet_btc_address: mjSrB3wS4xab3kYqFktwBzfTdPg367ZJ2d
faucet_mnemonic: shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform
faucet_derivation_path: "m/44'/5757'/0'/0/0"
pre_nakamoto_mock_signing: false
working_dir: /Users/micaiahreid/work/stx-px/tmp
postgres_port: 5432
postgres_username: postgres
Expand Down Expand Up @@ -141,14 +149,15 @@ devnet_settings:
execute_script: []
bitcoin_node_image_url: "quay.io/hirosystems/bitcoind:devnet-v3"
stacks_node_image_url: "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0"
stacks_signer_image_url: "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0"
stacks_signers_image_url: "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0"
stacks_api_image_url: "hirosystems/stacks-blockchain-api:latest"
stacks_explorer_image_url: "hirosystems/explorer:latest"
postgres_image_url: "postgres:14"
bitcoin_explorer_image_url: "quay.io/hirosystems/bitcoin-explorer:devnet"
disable_bitcoin_explorer: true
disable_stacks_explorer: true
disable_stacks_api: false
disable_postgres: false
bind_containers_volumes: false
enable_subnet_node: false
subnet_node_image_url: "hirosystems/stacks-subnets:0.8.1"
Expand Down
16 changes: 15 additions & 1 deletion src/tests/fixtures/stacks-devnet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,21 @@
"stacks_node_subsequent_attempt_time_ms": 1000,
"stacks_node_events_observers": ["host.docker.internal:20455"],
"stacks_node_env_vars": [],
"stacks_node_next_initiative_delay": 4000,
"stacks_api_port": 3999,
"stacks_api_events_port": 3700,
"stacks_api_env_vars": [],
"stacks_signers_keys": [
{
"key": "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c178",
"compress_public": true
},
{
"key": "530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc2091",
"compress_public": true
}
],
"stacks_signers_env_vars": [],
"stacks_explorer_port": 8000,
"stacks_explorer_env_vars": [],
"bitcoin_explorer_port": 8001,
Expand All @@ -264,6 +276,7 @@
"faucet_btc_address": "mjSrB3wS4xab3kYqFktwBzfTdPg367ZJ2d",
"faucet_mnemonic": "shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform",
"faucet_derivation_path": "m/44'/5757'/0'/0/0",
"pre_nakamoto_mock_signing": false,
"working_dir": "/Users/micaiahreid/work/stx-px/tmp",
"postgres_port": 5432,
"postgres_username": "postgres",
Expand Down Expand Up @@ -296,14 +309,15 @@
"execute_script": [],
"bitcoin_node_image_url": "quay.io/hirosystems/bitcoind:devnet-v3",
"stacks_node_image_url": "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0",
"stacks_signer_image_url": "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0",
"stacks_signers_image_url": "quay.io/hirosystems/stacks-node:devnet-2.4.0.0.0",
"stacks_api_image_url": "hirosystems/stacks-blockchain-api:latest",
"stacks_explorer_image_url": "hirosystems/explorer:latest",
"postgres_image_url": "postgres:14",
"bitcoin_explorer_image_url": "quay.io/hirosystems/bitcoin-explorer:devnet",
"disable_bitcoin_explorer": true,
"disable_stacks_explorer": true,
"disable_stacks_api": false,
"disable_postgres": false,
"bind_containers_volumes": false,
"enable_subnet_node": false,
"subnet_node_image_url": "hirosystems/stacks-subnets:0.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
image: hirosystems/stacks-network-orchestrator:clarinet-2.6.0
image: hirosystems/stacks-network-orchestrator:clarinet-2.9.0
imagePullPolicy: IfNotPresent
name: chain-coordinator
ports:
Expand Down Expand Up @@ -111,4 +111,4 @@ spec:
name: deployment-plan
- configMap:
name: project-dir
name: project-dir
name: project-dir
48 changes: 27 additions & 21 deletions templates/stacks-devnet-api.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ metadata:
name: stacks-devnet-api
rules:
- apiGroups: [""]
resources: ["pods", "pods/status", "services", "configmaps", "persistentvolumeclaims"]
resources:
[
"pods",
"pods/status",
"services",
"configmaps",
"persistentvolumeclaims",
]
verbs: ["get", "delete", "create", "list", "deletecollection"]
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets"]
verbs: ["get", "delete", "create", "list"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get"]


---
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -35,8 +41,7 @@ roleRef:
name: stacks-devnet-api
apiGroup: rbac.authorization.k8s.io

---

---
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -47,17 +52,19 @@ metadata:
spec:
serviceAccountName: stacks-devnet-api
containers:
- command: ["stacks-devnet-api"]
name: stacks-devnet-api
image: hirosystems/stacks-devnet-api:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8477
name: api
protocol: TCP
volumeMounts:
- name: config-volume
mountPath: /etc/config
- command: ["stacks-devnet-api"]
name: stacks-devnet-api
# image: hirosystems/stacks-devnet-api:latest
# imagePullPolicy: IfNotPresent
image: stacks-devnet-api:latest
imagePullPolicy: Never
ports:
- containerPort: 8477
name: api
protocol: TCP
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
Expand All @@ -71,12 +78,11 @@ metadata:
namespace: devnet
spec:
ports:
- name: api
port: 8477
protocol: TCP
targetPort: 8477
nodePort: 30000
- name: api
port: 8477
protocol: TCP
targetPort: 8477
nodePort: 30000
selector:
name: stacks-devnet-api
type: NodePort

0 comments on commit 7670c63

Please sign in to comment.