Skip to content

Commit

Permalink
feat: move thread pool size to config
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Jun 5, 2023
1 parent 1b58ccd commit bc313fa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/chainhook-cli/src/block/mod.rs
Expand Up @@ -15,7 +15,7 @@ pub struct Record {
pub id: u64,
pub created_at: String,
pub kind: RecordKind,
pub raw_log: String,
pub blob: Option<String>,
}

#[derive(Debug, Deserialize)]
Expand Down
6 changes: 4 additions & 2 deletions components/chainhook-cli/src/config/file.rs
Expand Up @@ -25,8 +25,10 @@ pub struct EventSourceConfigFile {

#[derive(Deserialize, Debug, Clone)]
pub struct ChainhooksConfigFile {
pub max_stacks_registrations: Option<u16>,
pub max_bitcoin_registrations: Option<u16>,
pub max_stacks_registrations: Option<usize>,
pub max_bitcoin_registrations: Option<usize>,
pub max_stacks_concurrent_scans: Option<usize>,
pub max_bitcoin_concurrent_scans: Option<usize>,
}

#[derive(Deserialize, Debug, Clone)]
Expand Down
8 changes: 5 additions & 3 deletions components/chainhook-cli/src/config/generator.rs
Expand Up @@ -6,8 +6,10 @@ redis_uri = "redis://localhost:6379/"
cache_path = "cache"
[chainhooks]
max_stacks_registrations = 500
max_bitcoin_registrations = 500
max_stacks_registrations = 100
max_bitcoin_registrations = 100
max_stacks_concurrent_scans = 10
max_bitcoin_concurrent_scans = 10
[network]
mode = "mainnet"
Expand All @@ -17,7 +19,7 @@ bitcoind_rpc_password = "devnet"
stacks_node_rpc_url = "http://localhost:20443"
[[event_source]]
tsv_file_url = "https://archive.hiro.so/mainnet/stacks-blockchain-api/mainnet-stacks-blockchain-api-latest.gz"
tsv_file_url = "https://archive.hiro.so/mainnet/stacks-blockchain-api/mainnet-stacks-blockchain-api-latest"
"#
);
return conf;
Expand Down
46 changes: 34 additions & 12 deletions components/chainhook-cli/src/config/mod.rs
Expand Up @@ -10,15 +10,20 @@ use std::fs::File;
use std::io::{BufReader, Read};
use std::path::PathBuf;

use crate::service::{DEFAULT_CONTROL_PORT, DEFAULT_INGESTION_PORT};

const DEFAULT_MAINNET_STACKS_TSV_ARCHIVE: &str =
"https://archive.hiro.so/mainnet/stacks-blockchain-api/mainnet-stacks-blockchain-api-latest";
const DEFAULT_TESTNET_STACKS_TSV_ARCHIVE: &str =
"https://archive.hiro.so/testnet/stacks-blockchain-api/testnet-stacks-blockchain-api-latest";
const DEFAULT_MAINNET_ORDINALS_SQLITE_ARCHIVE: &str =
"https://archive.hiro.so/mainnet/chainhooks/hord-latest.sqlite";

pub const DEFAULT_INGESTION_PORT: u16 = 20455;
pub const DEFAULT_CONTROL_PORT: u16 = 20456;
pub const STACKS_SCAN_THREAD_POOL_SIZE: usize = 10;
pub const BITCOIN_SCAN_THREAD_POOL_SIZE: usize = 10;
pub const STACKS_MAX_PREDICATE_REGISTRATION: usize = 50;
pub const BITCOIN_MAX_PREDICATE_REGISTRATION: usize = 50;

#[derive(Clone, Debug)]
pub struct Config {
pub storage: StorageConfig,
Expand Down Expand Up @@ -70,8 +75,10 @@ pub struct UrlConfig {

#[derive(Clone, Debug)]
pub struct ChainhooksConfig {
pub max_stacks_registrations: u16,
pub max_bitcoin_registrations: u16,
pub max_stacks_registrations: usize,
pub max_bitcoin_registrations: usize,
pub max_stacks_concurrent_scans: usize,
pub max_bitcoin_concurrent_scans: usize,
pub enable_http_api: bool,
}

Expand Down Expand Up @@ -151,11 +158,20 @@ impl Config {
max_stacks_registrations: config_file
.chainhooks
.max_stacks_registrations
.unwrap_or(100),
.unwrap_or(STACKS_MAX_PREDICATE_REGISTRATION),
max_bitcoin_registrations: config_file
.chainhooks
.max_bitcoin_registrations
.unwrap_or(100),
.unwrap_or(BITCOIN_MAX_PREDICATE_REGISTRATION),
max_stacks_concurrent_scans: config_file
.chainhooks
.max_stacks_registrations
.unwrap_or(STACKS_SCAN_THREAD_POOL_SIZE),
max_bitcoin_concurrent_scans: config_file
.chainhooks
.max_bitcoin_registrations
.unwrap_or(BITCOIN_SCAN_THREAD_POOL_SIZE),

enable_http_api: true,
},
network: IndexerConfig {
Expand Down Expand Up @@ -344,8 +360,10 @@ impl Config {
},
event_sources: vec![],
chainhooks: ChainhooksConfig {
max_stacks_registrations: 50,
max_bitcoin_registrations: 50,
max_stacks_registrations: STACKS_MAX_PREDICATE_REGISTRATION,
max_bitcoin_registrations: BITCOIN_MAX_PREDICATE_REGISTRATION,
max_stacks_concurrent_scans: STACKS_SCAN_THREAD_POOL_SIZE,
max_bitcoin_concurrent_scans: BITCOIN_SCAN_THREAD_POOL_SIZE,
enable_http_api: true,
},
network: IndexerConfig {
Expand Down Expand Up @@ -374,8 +392,10 @@ impl Config {
file_url: DEFAULT_TESTNET_STACKS_TSV_ARCHIVE.into(),
})],
chainhooks: ChainhooksConfig {
max_stacks_registrations: 10,
max_bitcoin_registrations: 10,
max_stacks_registrations: STACKS_MAX_PREDICATE_REGISTRATION,
max_bitcoin_registrations: BITCOIN_MAX_PREDICATE_REGISTRATION,
max_stacks_concurrent_scans: STACKS_SCAN_THREAD_POOL_SIZE,
max_bitcoin_concurrent_scans: BITCOIN_SCAN_THREAD_POOL_SIZE,
enable_http_api: true,
},
network: IndexerConfig {
Expand Down Expand Up @@ -409,8 +429,10 @@ impl Config {
}),
],
chainhooks: ChainhooksConfig {
max_stacks_registrations: 10,
max_bitcoin_registrations: 10,
max_stacks_registrations: STACKS_MAX_PREDICATE_REGISTRATION,
max_bitcoin_registrations: BITCOIN_MAX_PREDICATE_REGISTRATION,
max_stacks_concurrent_scans: STACKS_SCAN_THREAD_POOL_SIZE,
max_bitcoin_concurrent_scans: BITCOIN_SCAN_THREAD_POOL_SIZE,
enable_http_api: true,
},
network: IndexerConfig {
Expand Down

0 comments on commit bc313fa

Please sign in to comment.