Skip to content

Commit

Permalink
Merge branch 'stacks-signers' into feat/stacks-signers
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Oct 16, 2024
2 parents df0f72d + 0a722b3 commit 552b317
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[alias]
chainhook-install = "install --path components/chainhook-cli --locked --force --features cli --features debug --no-default-features"

[env]
RUST_TEST_THREADS = "1"
20 changes: 15 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ jobs:
rustup toolchain install stable --profile minimal
echo "RUST_VERSION_HASH=$(rustc --version | sha256sum | awk '{print $1}')" >> $GITHUB_ENV
- name: Install redis
if: matrix.suite == 'cli'
run: |
sudo apt-get install -y redis-server
- name: Cache cargo
uses: actions/cache@v4
with:
Expand All @@ -62,6 +57,13 @@ jobs:
run: |
cargo install cargo-tarpaulin
- name: Setup integration environment
run: |
sudo ufw disable
docker compose -f ../../dockerfiles/docker-compose.dev.yml up -d
docker compose -f ../../dockerfiles/docker-compose.dev.yml logs -t -f --no-color &> docker-compose-logs.txt &
if: matrix.suite == 'cli'

- name: Run tests
run: |
cargo tarpaulin --skip-clean --out lcov --features ${{ matrix.features }} -- --test-threads=1
Expand All @@ -72,6 +74,14 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
codecov_yml_path: .github/codecov.yml

- name: Print integration environment logs
run: cat docker-compose-logs.txt
if: matrix.suite == 'cli' && failure()

- name: Teardown integration environment
run: docker compose -f ../../dockerfiles/docker-compose.dev.yml down -v -t 0
if: matrix.suite == 'cli' && always()

distributions:
runs-on: ${{ matrix.os }}

Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ components/chainhook-types-js/dist
*.redb
cache/
Chainhook.toml

components/chainhook-cli/src/service/tests/fixtures/tmp
components/chainhook-cli/src/archive/tests/fixtures/tmp
**/src/service/tests/fixtures/tmp
**/src/archive/tests/fixtures/tmp
47 changes: 47 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "test: chainhook-sdk",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=chainhook-sdk"],
"filter": {
"name": "chainhook_sdk",
"kind": "lib"
}
},
"args": [],
"env": {
"RUST_TEST_THREADS": "1"
},
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "test: chainhook-cli",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=chainhook",
"--package=chainhook",
"--features=redis_tests"
],
"filter": {
"name": "chainhook",
"kind": "bin"
}
},
"args": [],
"env": {
"RUST_TEST_THREADS": "1"
},
"cwd": "${workspaceFolder}",
"preLaunchTask": "redis:start",
"postDebugTask": "redis:stop"
}
]
}
47 changes: 47 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "redis:start",
"type": "shell",
"command": "docker compose -f dockerfiles/docker-compose.dev.yml up --force-recreate -V",
"isBackground": true,
"problemMatcher": {
"pattern": { "regexp": ".", "file": 1, "location": 2, "message": 3 },
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "."
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"clear": false
}
},
{
"label": "redis:stop",
"type": "shell",
"command": "docker compose -f dockerfiles/docker-compose.dev.yml down -v -t 0",
"isBackground": true,
"problemMatcher": {
"pattern": { "regexp": ".", "file": 1, "location": 2, "message": 3 },
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "."
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"clear": false
}
}
]
}
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 @@ -5,6 +5,7 @@ pub struct ConfigFile {
pub storage: StorageConfigFile,
pub pox_config: Option<PoxConfigFile>,
pub http_api: Option<PredicatesApiConfigFile>,
pub predicates: Option<PredicatesConfigFile>,
pub event_source: Option<Vec<EventSourceConfigFile>>,
pub limits: LimitsConfigFile,
pub network: NetworkConfigFile,
Expand Down Expand Up @@ -64,6 +65,11 @@ pub struct NetworkConfigFile {
pub stacks_events_ingestion_port: Option<u16>,
}

#[derive(Deserialize, Debug, Clone)]
pub struct PredicatesConfigFile {
pub payload_http_request_timeout_ms: Option<u64>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum NetworkConfigMode {
Expand Down
23 changes: 22 additions & 1 deletion components/chainhook-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod generator;

use chainhook_sdk::chainhooks::types::{ChainhookStore, PoxConfig};
pub use chainhook_sdk::indexer::IndexerConfig;
use chainhook_sdk::observer::EventObserverConfig;
use chainhook_sdk::observer::{EventObserverConfig, PredicatesConfig};
use chainhook_sdk::types::{
BitcoinBlockSignaling, BitcoinNetwork, StacksNetwork, StacksNodeConfig,
};
Expand All @@ -30,6 +30,7 @@ pub struct Config {
pub storage: StorageConfig,
pub pox_config: PoxConfig,
pub http_api: PredicatesApi,
pub predicates: PredicatesConfig,
pub event_sources: Vec<EventSourceConfig>,
pub limits: LimitsConfig,
pub network: IndexerConfig,
Expand Down Expand Up @@ -117,6 +118,9 @@ impl Config {
EventObserverConfig {
bitcoin_rpc_proxy_enabled: true,
registered_chainhooks: ChainhookStore::new(),
predicates_config: PredicatesConfig {
payload_http_request_timeout_ms: self.predicates.payload_http_request_timeout_ms,
},
bitcoind_rpc_username: self.network.bitcoind_rpc_username.clone(),
bitcoind_rpc_password: self.network.bitcoind_rpc_password.clone(),
bitcoind_rpc_url: self.network.bitcoind_rpc_url.clone(),
Expand Down Expand Up @@ -193,6 +197,14 @@ impl Config {
}),
},
},
predicates: match config_file.predicates {
None => PredicatesConfig {
payload_http_request_timeout_ms: None,
},
Some(predicates) => PredicatesConfig {
payload_http_request_timeout_ms: predicates.payload_http_request_timeout_ms,
},
},
event_sources,
limits: LimitsConfig {
max_number_of_stacks_predicates: config_file
Expand Down Expand Up @@ -357,6 +369,9 @@ impl Config {
},
pox_config: PoxConfig::devnet_default(),
http_api: PredicatesApi::Off,
predicates: PredicatesConfig {
payload_http_request_timeout_ms: None,
},
event_sources: vec![],
limits: LimitsConfig {
max_number_of_bitcoin_predicates: BITCOIN_MAX_PREDICATE_REGISTRATION,
Expand Down Expand Up @@ -390,6 +405,9 @@ impl Config {
},
pox_config: PoxConfig::testnet_default(),
http_api: PredicatesApi::Off,
predicates: PredicatesConfig {
payload_http_request_timeout_ms: None,
},
event_sources: vec![EventSourceConfig::StacksTsvUrl(UrlConfig {
file_url: DEFAULT_TESTNET_STACKS_TSV_ARCHIVE.into(),
})],
Expand Down Expand Up @@ -425,6 +443,9 @@ impl Config {
},
pox_config: PoxConfig::mainnet_default(),
http_api: PredicatesApi::Off,
predicates: PredicatesConfig {
payload_http_request_timeout_ms: None,
},
event_sources: vec![EventSourceConfig::StacksTsvUrl(UrlConfig {
file_url: DEFAULT_MAINNET_STACKS_TSV_ARCHIVE.into(),
})],
Expand Down
2 changes: 1 addition & 1 deletion components/chainhook-cli/src/scan/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub async fn execute_predicates_action<'a>(
gather_proofs(&trigger, &mut proofs, config, ctx);
}
let predicate_uuid = &trigger.chainhook.uuid;
match handle_bitcoin_hook_action(trigger, &proofs) {
match handle_bitcoin_hook_action(trigger, &proofs, &config) {
Err(e) => {
warn!(
ctx.expect_logger(),
Expand Down
26 changes: 19 additions & 7 deletions components/chainhook-cli/src/scan/stacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ pub async fn get_canonical_fork_from_tsv(
for result in reader_builder.deserialize() {
line += 1;
let record: Record = result.unwrap();
if let RecordKind::StacksBlockReceived = &record.kind { if let Err(_e) = record_tx.send(Some((record, line))) {
break;
} };
if let RecordKind::StacksBlockReceived = &record.kind {
if let Err(_e) = record_tx.send(Some((record, line))) {
break;
}
};
}
let _ = record_tx.send(None);
})
Expand Down Expand Up @@ -338,7 +340,12 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
apply: hits_per_blocks,
rollback: vec![],
};
let res = match handle_stacks_hook_action(trigger, &proofs, ctx) {
let res = match handle_stacks_hook_action(
trigger,
&proofs,
&config.get_event_observer_config(),
ctx,
) {
Err(e) => {
warn!(
ctx.expect_logger(),
Expand Down Expand Up @@ -487,7 +494,9 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
let mut tsv_line = String::new();
while tsv_current_line < tsv_line_number {
tsv_line.clear();
let bytes_read = tsv_reader.read_line(&mut tsv_line).map_err(|e| e.to_string())?;
let bytes_read = tsv_reader
.read_line(&mut tsv_line)
.map_err(|e| e.to_string())?;
if bytes_read == 0 {
return Err("Unexpected EOF when reading TSV".to_string());
}
Expand Down Expand Up @@ -525,7 +534,8 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
apply: hits_per_blocks,
rollback: vec![],
};
match handle_stacks_hook_action(trigger, &proofs, ctx) {
match handle_stacks_hook_action(trigger, &proofs, &config.get_event_observer_config(), ctx)
{
Err(e) => {
error!(ctx.expect_logger(), "unable to handle action {}", e);
}
Expand Down Expand Up @@ -604,7 +614,9 @@ pub async fn consolidate_local_stacks_chainstate_using_csv(
let mut tsv_line = String::new();
while tsv_current_line < tsv_line_number {
tsv_line.clear();
let bytes_read = tsv_reader.read_line(&mut tsv_line).map_err(|e| e.to_string())?;
let bytes_read = tsv_reader
.read_line(&mut tsv_line)
.map_err(|e| e.to_string())?;
if bytes_read == 0 {
return Err("Unexpected EOF when reading TSV".to_string());
}
Expand Down
Loading

0 comments on commit 552b317

Please sign in to comment.