Skip to content

Commit

Permalink
chore: update chainhook-sdk
Browse files Browse the repository at this point in the history
* feat: split clarinet-sdk into web and node

* ci: add-clarinet sdk ci (#1496)

* docs: improve build and contributing steps in readmes

* fix: address review

* tests: add compilation in the pretest script

* address review

* fix renames, imports, and some function access

* fix chain_coordinator merge

* chore: fix chainhook-sdk dependency patching

---------

Co-authored-by: Hugo Caillard <911307+hugocaillard@users.noreply.github.com>
Co-authored-by: brady.ouren <bouren@hiro.sh>
  • Loading branch information
3 people authored Jul 15, 2024
1 parent b37d9f8 commit d1aec13
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ default-members = ["components/clarinet-cli"]
version = "2.7.0"

[patch.crates-io]
chainhook-sdk = { git = "https://github.com/hirosystems/chainhook.git", branch="develop" }
chainhook-types = { git = "https://github.com/hirosystems/chainhook.git", branch="develop" }

[patch.'https://github.com/hirosystems/clarinet.git']
chainhook-sdk = { git = "https://github.com/hirosystems/chainhook.git" }
chainhook-types = { git = "https://github.com/hirosystems/chainhook.git" }
stacks-codec = { path = "./components/stacks-codec" }
2 changes: 1 addition & 1 deletion components/stacks-codec/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,7 @@ pub const MAX_EPOCH_SIZE: u32 = 2 * 1024 * 1024;
// $MAX_EPOCH_SIZE bytes (so the average microblock size needs to be 4kb if there are 256 of them)
pub const MAX_MICROBLOCK_SIZE: u32 = 65536;

pub fn build_contrat_call_transaction(
pub fn build_contract_call_transaction(
contract_id: String,
function_name: String,
args: Vec<Value>,
Expand Down
18 changes: 9 additions & 9 deletions components/stacks-network/src/chainhooks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chainhook_sdk::chainhooks::types::{ChainhookConfig, ChainhookFullSpecification};
use chainhook_sdk::chainhooks::types::{ChainhookSpecificationNetworkMap, ChainhookStore};
use chainhook_sdk::types::{BitcoinNetwork, StacksNetwork};
use clarinet_files::FileLocation;
use std::fs::File;
Expand All @@ -9,7 +9,7 @@ use std::fs;

pub fn parse_chainhook_full_specification(
path: &PathBuf,
) -> Result<ChainhookFullSpecification, String> {
) -> Result<ChainhookSpecificationNetworkMap, String> {
let path = match File::open(path) {
Ok(path) => path,
Err(_e) => {
Expand All @@ -18,7 +18,7 @@ pub fn parse_chainhook_full_specification(
};

let mut hook_spec_file_reader = BufReader::new(path);
let specification: ChainhookFullSpecification =
let specification: ChainhookSpecificationNetworkMap =
serde_json::from_reader(&mut hook_spec_file_reader)
.map_err(|e| format!("unable to parse chainhook spec: {}", e))?;

Expand All @@ -28,28 +28,28 @@ pub fn parse_chainhook_full_specification(
pub fn load_chainhooks(
manifest_location: &FileLocation,
networks: &(BitcoinNetwork, StacksNetwork),
) -> Result<ChainhookConfig, String> {
) -> Result<ChainhookStore, String> {
let hook_files = get_chainhooks_files(manifest_location)?;
let mut stacks_chainhooks = vec![];
let mut bitcoin_chainhooks = vec![];
for (path, relative_path) in hook_files.into_iter() {
match parse_chainhook_full_specification(&path) {
Ok(hook) => match hook {
ChainhookFullSpecification::Bitcoin(predicate) => {
let mut spec = predicate.into_selected_network_specification(&networks.0)?;
ChainhookSpecificationNetworkMap::Bitcoin(predicate) => {
let mut spec = predicate.into_specification_for_network(&networks.0)?;
spec.enabled = true;
bitcoin_chainhooks.push(spec)
}
ChainhookFullSpecification::Stacks(predicate) => {
let mut spec = predicate.into_selected_network_specification(&networks.1)?;
ChainhookSpecificationNetworkMap::Stacks(predicate) => {
let mut spec = predicate.into_specification_for_network(&networks.1)?;
spec.enabled = true;
stacks_chainhooks.push(spec)
}
},
Err(msg) => return Err(format!("{} syntax incorrect: {}", relative_path, msg)),
};
}
Ok(ChainhookConfig {
Ok(ChainhookStore {
stacks_chainhooks,
bitcoin_chainhooks,
})
Expand Down
48 changes: 27 additions & 21 deletions components/stacks-network/src/chains_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use crate::event::Status;
use crate::orchestrator::ServicesMapHosts;

use base58::FromBase58;
use chainhook_sdk::chainhooks::types::ChainhookConfig;
use chainhook_sdk::chainhooks::types::ChainhookStore;
use chainhook_sdk::observer::{
start_event_observer, EventObserverConfig, ObserverCommand, ObserverEvent,
StacksChainMempoolEvent,
};
use chainhook_sdk::types::BitcoinBlockSignaling;
use chainhook_sdk::types::BitcoinChainEvent;
use chainhook_sdk::types::BitcoinNetwork;
use chainhook_sdk::types::StacksChainEvent;
use chainhook_sdk::types::StacksNetwork;
use chainhook_sdk::types::StacksNodeConfig;
use chainhook_sdk::types::{BitcoinNetwork, StacksNetwork};
use chainhook_sdk::utils::Context;
use clarinet_deployments::onchain::TransactionStatus;
use clarinet_deployments::onchain::{
Expand All @@ -35,7 +34,6 @@ use clarity_repl::clarity::PublicKey;
use hiro_system_kit;
use hiro_system_kit::slog;
use hiro_system_kit::yellow;
use stacks_codec::codec;
use stacks_rpc_client::rpc_client::PoxInfo;
use stacks_rpc_client::StacksRpc;
use stackslib::chainstate::stacks::address::PoxAddress;
Expand Down Expand Up @@ -106,7 +104,7 @@ impl DevnetEventObserverConfig {
manifest: ProjectManifest,
network_manifest: Option<NetworkManifest>,
deployment: DeploymentSpecification,
chainhooks: ChainhookConfig,
chainhooks: ChainhookStore,
ctx: &Context,
services_map_hosts: ServicesMapHosts,
) -> Self {
Expand All @@ -123,8 +121,7 @@ impl DevnetEventObserverConfig {
};
let event_observer_config = EventObserverConfig {
bitcoin_rpc_proxy_enabled: true,
chainhook_config: Some(chainhooks),
ingestion_port: devnet_config.orchestrator_ingestion_port,
registered_chainhooks: chainhooks,
bitcoind_rpc_username: devnet_config.bitcoin_node_username.clone(),
bitcoind_rpc_password: devnet_config.bitcoin_node_password.clone(),
bitcoind_rpc_url: format!("http://{}", services_map_hosts.bitcoin_node_host),
Expand All @@ -133,11 +130,9 @@ impl DevnetEventObserverConfig {
ingestion_port: devnet_config.orchestrator_ingestion_port,
}),

display_logs: true,
cache_path: devnet_config.working_dir.to_string(),
display_stacks_ingestion_logs: true,
bitcoin_network: BitcoinNetwork::Regtest,
stacks_network: StacksNetwork::Devnet,
data_handler_tx: None,
prometheus_monitoring_port: None,
};

Expand Down Expand Up @@ -199,15 +194,22 @@ pub async fn start_chains_coordinator(
&boot_completed,
);

if let Some(ref hooks) = config.event_observer_config.chainhook_config {
let chainhooks_count = hooks.bitcoin_chainhooks.len() + hooks.stacks_chainhooks.len();
if chainhooks_count > 0 {
devnet_event_tx
.send(DevnetEvent::info(format!(
"{chainhooks_count} chainhooks registered",
)))
.expect("Unable to terminate event observer");
}
let chainhooks_count = config
.event_observer_config
.registered_chainhooks
.stacks_chainhooks
.len()
+ config
.event_observer_config
.registered_chainhooks
.bitcoin_chainhooks
.len();
if chainhooks_count > 0 {
devnet_event_tx
.send(DevnetEvent::info(format!(
"{chainhooks_count} chainhooks registered",
)))
.expect("Unable to terminate event observer");
}

// Spawn event observer
Expand Down Expand Up @@ -282,6 +284,11 @@ pub async fn start_chains_coordinator(
.expect("Unable to terminate event observer");
// Terminate
}
ObserverEvent::PredicateInterrupted(_data) => {
devnet_event_tx
.send(DevnetEvent::error("predicate interrupt".to_string())) // need to use data for the message
.expect("Event observer received predicate interrupt");
}
ObserverEvent::Error(msg) => {
devnet_event_tx
.send(DevnetEvent::error(msg))
Expand Down Expand Up @@ -479,7 +486,6 @@ pub async fn start_chains_coordinator(
ObserverEvent::BitcoinPredicateTriggered(_) => {}
ObserverEvent::StacksPredicateTriggered(_) => {}
ObserverEvent::PredicateEnabled(_) => {}
ObserverEvent::PredicateInterrupted(_) => {}
}
}
Ok(())
Expand Down Expand Up @@ -739,7 +745,7 @@ pub async fn publish_stacking_orders(
i.try_into().unwrap(),
);

let tx = codec::build_contrat_call_transaction(
let tx = stacks_codec::codec::build_contract_call_transaction(
pox_contract_id_moved,
method,
arguments,
Expand Down
11 changes: 5 additions & 6 deletions components/stacks-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod orchestrator;
mod ui;

pub use chainhook_sdk::observer::MempoolAdmissionData;
use chainhook_sdk::observer::ObserverCommand;
pub use chainhook_sdk::{self, utils::Context};
use chainhook_sdk::{chainhooks::types::ChainhookStore, observer::ObserverCommand};
pub use chainhooks::{load_chainhooks, parse_chainhook_full_specification};
use chains_coordinator::BitcoinMiningCommand;
use clarinet_files::NetworkManifest;
Expand All @@ -26,7 +26,6 @@ use std::{
time::Duration,
};

use chainhook_sdk::chainhooks::types::ChainhookConfig;
use chains_coordinator::start_chains_coordinator;
use clarinet_deployments::types::DeploymentSpecification;
use hiro_system_kit::slog;
Expand All @@ -49,7 +48,7 @@ where
async fn do_run_devnet(
mut devnet: DevnetOrchestrator,
deployment: DeploymentSpecification,
chainhooks: &mut Option<ChainhookConfig>,
chainhooks: &mut Option<ChainhookStore>,
log_tx: Option<Sender<LogData>>,
display_dashboard: bool,
ctx: Context,
Expand Down Expand Up @@ -99,7 +98,7 @@ async fn do_run_devnet(
// and should be able to be terminated
let hooks = match chainhooks.take() {
Some(hooks) => hooks,
_ => ChainhookConfig::new(),
_ => ChainhookStore::new(),
};
let devnet_path = devnet_config.working_dir.clone();
let config = DevnetEventObserverConfig::new(
Expand Down Expand Up @@ -261,7 +260,7 @@ async fn do_run_devnet(
pub async fn do_run_chain_coordinator(
mut devnet: DevnetOrchestrator,
deployment: DeploymentSpecification,
chainhooks: &mut Option<ChainhookConfig>,
chainhooks: &mut Option<ChainhookStore>,
log_tx: Option<Sender<LogData>>,
ctx: Context,
orchestrator_terminated_tx: Sender<bool>,
Expand Down Expand Up @@ -295,7 +294,7 @@ pub async fn do_run_chain_coordinator(
pub async fn do_run_local_devnet(
mut devnet: DevnetOrchestrator,
deployment: DeploymentSpecification,
chainhooks: &mut Option<ChainhookConfig>,
chainhooks: &mut Option<ChainhookStore>,
log_tx: Option<Sender<LogData>>,
display_dashboard: bool,
ctx: Context,
Expand Down

0 comments on commit d1aec13

Please sign in to comment.