Skip to content

Commit

Permalink
Merge pull request #493 from hirosystems/develop
Browse files Browse the repository at this point in the history
chore(release): publish v1.3.0
  • Loading branch information
MicaiahReid authored Feb 8, 2024
2 parents 6db3018 + 489b014 commit 21e4b1b
Show file tree
Hide file tree
Showing 32 changed files with 1,284 additions and 510 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[alias]
chainhook-install = "install --path components/chainhook-cli --locked --force"
chainhook-install = "install --path components/chainhook-cli --locked --force --features cli --features debug --no-default-features"
24 changes: 23 additions & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions components/chainhook-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainhook"
version = "1.1.1"
version = "1.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down Expand Up @@ -59,8 +59,8 @@ serial_test = "2.0.0"


[features]
default = ["cli"]
cli = ["clap", "clap_generate", "toml", "ctrlc", "release"]
default = ["cli", "release"]
cli = ["clap", "clap_generate", "toml", "ctrlc"]
debug = ["chainhook-sdk/debug"]
release = ["chainhook-sdk/release"]
redis_tests = []
Expand Down
9 changes: 8 additions & 1 deletion components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ struct StartCommand {
/// Start REST API for managing predicates
#[clap(long = "start-http-api")]
pub start_http_api: bool,
/// If provided, serves Prometheus metrics at localhost:{port}/metrics. If not specified, does not start Prometheus server.
#[clap(long = "prometheus-port")]
pub prometheus_monitoring_port: Option<u16>,
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -291,9 +294,13 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
match opts.command {
Command::Service(subcmd) => match subcmd {
ServiceCommand::Start(cmd) => {
let config =
let mut config =
Config::default(cmd.devnet, cmd.testnet, cmd.mainnet, &cmd.config_path)?;

if cmd.prometheus_monitoring_port.is_some() {
config.monitoring.prometheus_monitoring_port = cmd.prometheus_monitoring_port;
}

let predicates = cmd
.predicates_paths
.iter()
Expand Down
6 changes: 6 additions & 0 deletions components/chainhook-cli/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct ConfigFile {
pub event_source: Option<Vec<EventSourceConfigFile>>,
pub limits: LimitsConfigFile,
pub network: NetworkConfigFile,
pub monitoring: Option<MonitoringConfigFile>,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -81,3 +82,8 @@ impl NetworkConfigMode {
}
}
}

#[derive(Deserialize, Debug, Clone)]
pub struct MonitoringConfigFile {
pub prometheus_monitoring_port: Option<u16>,
}
5 changes: 5 additions & 0 deletions components/chainhook-cli/src/config/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ max_caching_memory_size_mb = 32000
# If this is not a requirement, you can comment out the `tsv_file_url` line.
[[event_source]]
tsv_file_url = "https://archive.hiro.so/{network}/stacks-blockchain-api/{network}-stacks-blockchain-api-latest"
# Enables a server that provides metrics that can be scraped by Prometheus.
# This is disabled by default.
# [monitoring]
# prometheus_monitoring_port = 20457
"#,
mode = mode.as_str(),
network = network.to_lowercase(),
Expand Down
26 changes: 24 additions & 2 deletions components/chainhook-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Config {
pub event_sources: Vec<EventSourceConfig>,
pub limits: LimitsConfig,
pub network: IndexerConfig,
pub monitoring: MonitoringConfig,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -80,6 +81,10 @@ pub struct LimitsConfig {
pub max_caching_memory_size_mb: usize,
}

#[derive(Clone, Debug, PartialEq)]
pub struct MonitoringConfig {
pub prometheus_monitoring_port: Option<u16>,
}
impl Config {
pub fn from_file_path(file_path: &str) -> Result<Config, String> {
let file = File::open(file_path)
Expand Down Expand Up @@ -120,6 +125,7 @@ impl Config {
bitcoin_network: self.network.bitcoin_network.clone(),
stacks_network: self.network.stacks_network.clone(),
data_handler_tx: None,
prometheus_monitoring_port: self.monitoring.prometheus_monitoring_port,
}
}

Expand All @@ -144,15 +150,19 @@ impl Config {
continue;
}
}

let prometheus_monitoring_port = if let Some(monitoring) = config_file.monitoring {
monitoring.prometheus_monitoring_port
} else {
None
};
let config = Config {
storage: StorageConfig {
working_dir: config_file.storage.working_dir.unwrap_or("cache".into()),
},
http_api: match config_file.http_api {
None => PredicatesApi::Off,
Some(http_api) => match http_api.disabled {
Some(false) => PredicatesApi::Off,
Some(true) => PredicatesApi::Off,
_ => PredicatesApi::On(PredicatesApiConfig {
http_port: http_api.http_port.unwrap_or(DEFAULT_CONTROL_PORT),
display_logs: http_api.display_logs.unwrap_or(true),
Expand Down Expand Up @@ -209,6 +219,9 @@ impl Config {
stacks_network,
bitcoin_network,
},
monitoring: MonitoringConfig {
prometheus_monitoring_port,
},
};
Ok(config)
}
Expand Down Expand Up @@ -340,6 +353,9 @@ impl Config {
stacks_network: StacksNetwork::Devnet,
bitcoin_network: BitcoinNetwork::Regtest,
},
monitoring: MonitoringConfig {
prometheus_monitoring_port: None,
},
}
}

Expand Down Expand Up @@ -371,6 +387,9 @@ impl Config {
stacks_network: StacksNetwork::Testnet,
bitcoin_network: BitcoinNetwork::Testnet,
},
monitoring: MonitoringConfig {
prometheus_monitoring_port: None,
},
}
}

Expand Down Expand Up @@ -402,6 +421,9 @@ impl Config {
stacks_network: StacksNetwork::Mainnet,
bitcoin_network: BitcoinNetwork::Mainnet,
},
monitoring: MonitoringConfig {
prometheus_monitoring_port: None,
},
}
}
}
Expand Down
34 changes: 31 additions & 3 deletions components/chainhook-cli/src/config/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use std::path::PathBuf;

use crate::config::{file::NetworkConfigMode, PredicatesApi, PredicatesApiConfig};

use super::{generator::generate_config, Config, ConfigFile, EventSourceConfig, PathConfig};
use crate::config::{
file::{NetworkConfigMode, PredicatesApiConfigFile},
PredicatesApi, PredicatesApiConfig,
};

use super::{
file::MonitoringConfigFile, generator::generate_config, Config, ConfigFile, EventSourceConfig,
PathConfig,
};
use chainhook_sdk::types::{BitcoinNetwork, StacksNetwork};
use test_case::test_case;

Expand All @@ -24,6 +30,28 @@ fn config_from_file_matches_generator_for_all_networks(network: BitcoinNetwork)
assert_eq!(generated_config, from_path_config);
}

#[test]
fn config_from_file_allows_setting_disabled_fields() {
let generated_config_str = generate_config(&BitcoinNetwork::Regtest);
let mut generated_config_file: ConfigFile = toml::from_str(&generated_config_str).unwrap();
// http_api and monitoring are optional, so they are disabled in generated config file
generated_config_file.http_api = Some(PredicatesApiConfigFile {
http_port: Some(0),
database_uri: Some(format!("")),
display_logs: Some(false),
disabled: Some(false),
});
generated_config_file.monitoring = Some(MonitoringConfigFile {
prometheus_monitoring_port: Some(20457),
});
let generated_config = Config::from_config_file(generated_config_file).unwrap();
assert!(generated_config.is_http_api_enabled());
assert_eq!(
generated_config.monitoring.prometheus_monitoring_port,
Some(20457)
);
}

#[test]
fn config_from_file_allows_local_tsv_file() {
let path = format!(
Expand Down
Loading

0 comments on commit 21e4b1b

Please sign in to comment.