Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stabilize observer management #222

Merged
merged 4 commits into from
Dec 6, 2023
Merged
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
73 changes: 18 additions & 55 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ $ ordhook scan blocks --interval 767430:767753 --post-to=http://localhost:3000/a
$ ordhook service start --post-to=http://localhost:3000/api/events --config-path=./Ordhook.toml
```

New `http-post` endpoints can also be added dynamically by spinning up a redis server and adding the following section in the `Ordhook.toml` configuration file:
New `http-post` endpoints can also be added dynamically by adding the following section in the `Ordhook.toml` configuration file:

```toml
[http_api]
http_port = 20456
database_uri = "redis://localhost:6379/"
```

Running `ordhook` with the command
Expand Down
51 changes: 22 additions & 29 deletions components/ordhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use crate::config::generator::generate_config;
use clap::{Parser, Subcommand};
use hiro_system_kit;
use ordhook::chainhook_sdk::bitcoincore_rpc::{Auth, Client, RpcApi};
use ordhook::chainhook_sdk::chainhooks::types::HttpHook;
use ordhook::chainhook_sdk::chainhooks::types::{BitcoinChainhookSpecification, HttpHook};
use ordhook::chainhook_sdk::chainhooks::types::{
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType,
ChainhookFullSpecification, HookAction, OrdinalOperations,
BitcoinPredicateType, ChainhookFullSpecification, HookAction, OrdinalOperations,
};
use ordhook::chainhook_sdk::indexer::bitcoin::{
build_http_client, download_and_parse_block_with_retry, retrieve_block_hash_with_retry,
Expand Down Expand Up @@ -34,7 +33,6 @@ use ordhook::download::download_ordinals_dataset_if_required;
use ordhook::scan::bitcoin::scan_bitcoin_chainstate_via_rpc_using_predicate;
use ordhook::service::{start_observer_forwarding, Service};
use reqwest::Client as HttpClient;
use std::collections::BTreeMap;
use std::io::{BufReader, Read};
use std::path::PathBuf;
use std::process;
Expand Down Expand Up @@ -555,8 +553,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
Some(&block_heights),
None,
cmd.auth_token,
)?
.into_selected_network_specification(&config.network.bitcoin_network)?;
)?;
scan_bitcoin_chainstate_via_rpc_using_predicate(
&predicate_spec,
&config,
Expand Down Expand Up @@ -734,7 +731,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
Some(start_block),
cmd.auth_token.clone(),
)?;
predicates.push(ChainhookFullSpecification::Bitcoin(predicate));
predicates.push(predicate);
}

let mut service = Service::new(config, ctx.clone());
Expand Down Expand Up @@ -939,39 +936,35 @@ pub fn build_predicate_from_cli(
block_heights: Option<&BlockHeights>,
start_block: Option<u64>,
auth_token: Option<String>,
) -> Result<BitcoinChainhookFullSpecification, String> {
let mut networks = BTreeMap::new();
) -> Result<BitcoinChainhookSpecification, String> {
// Retrieve last block height known, and display it
let (start_block, end_block, blocks) = match (start_block, block_heights) {
(None, Some(BlockHeights::BlockRange(start, end))) => (Some(*start), Some(*end), None),
(None, Some(BlockHeights::Blocks(blocks))) => (None, None, Some(blocks.clone())),
(Some(start), None) => (Some(start), None, None),
_ => unreachable!(),
};
networks.insert(
config.network.bitcoin_network.clone(),
BitcoinChainhookNetworkSpecification {
start_block,
end_block,
blocks,
expire_after_occurrence: None,
include_proof: None,
include_inputs: None,
include_outputs: None,
include_witness: None,
predicate: BitcoinPredicateType::OrdinalsProtocol(OrdinalOperations::InscriptionFeed),
action: HookAction::HttpPost(HttpHook {
url: post_to.to_string(),
authorization_header: format!("Bearer {}", auth_token.unwrap_or("".to_string())),
}),
},
);
let predicate = BitcoinChainhookFullSpecification {
let predicate = BitcoinChainhookSpecification {
network: config.network.bitcoin_network.clone(),
uuid: post_to.to_string(),
owner_uuid: None,
name: post_to.to_string(),
version: 1,
networks,
start_block,
end_block,
blocks,
expire_after_occurrence: None,
include_proof: false,
include_inputs: false,
include_outputs: false,
include_witness: false,
expired_at: None,
enabled: true,
predicate: BitcoinPredicateType::OrdinalsProtocol(OrdinalOperations::InscriptionFeed),
action: HookAction::HttpPost(HttpHook {
url: post_to.to_string(),
authorization_header: format!("Bearer {}", auth_token.unwrap_or("".to_string())),
}),
};

Ok(predicate)
Expand Down
5 changes: 0 additions & 5 deletions components/ordhook-cli/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use ordhook::config::{
use std::fs::File;
use std::io::{BufReader, Read};

const DEFAULT_REDIS_URI: &str = "redis://localhost:6379/";

pub const DEFAULT_INGESTION_PORT: u16 = 20455;
pub const DEFAULT_CONTROL_PORT: u16 = 20456;
pub const STACKS_SCAN_THREAD_POOL_SIZE: usize = 10;
Expand Down Expand Up @@ -74,9 +72,6 @@ impl ConfigFile {
_ => PredicatesApi::On(PredicatesApiConfig {
http_port: http_api.http_port.unwrap_or(DEFAULT_CONTROL_PORT),
display_logs: http_api.display_logs.unwrap_or(true),
database_uri: http_api
.database_uri
.unwrap_or(DEFAULT_REDIS_URI.to_string()),
}),
},
},
Expand Down
1 change: 0 additions & 1 deletion components/ordhook-cli/src/config/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ working_dir = "ordhook"
#
# [http_api]
# http_port = 20456
# database_uri = "redis://localhost:6379/"

[network]
mode = "{network}"
Expand Down
10 changes: 2 additions & 8 deletions components/ordhook-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ num_cpus = "1.16.0"
serde = "1"
serde_json = "1"
serde_derive = "1"
redis = "0.21.5"
serde-redis = "0.12.0"
hex = "0.4.3"
rand = "0.8.5"
chainhook-sdk = { version = "0.11.0", features = ["zeromq"] }
Expand All @@ -33,14 +31,10 @@ fxhash = "0.2.1"
rusqlite = { version = "0.27.0", features = ["bundled"] }
anyhow = { version = "1.0.56", features = ["backtrace"] }
schemars = { version = "0.8.10", git = "https://github.com/hirosystems/schemars.git", branch = "feat-chainhook-fixes" }
pprof = { version = "0.13.0", features = ["flamegraph"], optional = true }
progressing = '3'
futures = "0.3.28"

[dependencies.rocksdb]
version = "0.20.1"
default-features = false
features = ["lz4", "snappy"]
rocksdb = { version = "0.21.0", default-features = false, features = ["snappy"] }
pprof = { version = "0.13.0", features = ["flamegraph"], optional = true }

# [profile.release]
# debug = true
Expand Down
5 changes: 0 additions & 5 deletions components/ordhook-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub enum PredicatesApi {
#[derive(Clone, Debug)]
pub struct PredicatesApiConfig {
pub http_port: u16,
pub database_uri: String,
pub display_logs: bool,
}

Expand Down Expand Up @@ -126,10 +125,6 @@ impl Config {
}
}

pub fn expected_api_database_uri(&self) -> &str {
&self.expected_api_config().database_uri
}

pub fn expected_api_config(&self) -> &PredicatesApiConfig {
match self.http_api {
PredicatesApi::On(ref config) => config,
Expand Down
Loading
Loading