refactor: chainhook_event_observer to chainhook_sdk

This commit is contained in:
Ludo Galabru
2023-06-08 06:57:12 -04:00
parent bcd2a45a86
commit 48ec25c523
57 changed files with 48 additions and 92 deletions

4
Cargo.lock generated
View File

@@ -466,7 +466,7 @@ version = "0.14.0"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
"chainhook-event-observer", "chainhook-sdk",
"chainhook-types 1.0.3", "chainhook-types 1.0.3",
"clap 3.2.23", "clap 3.2.23",
"clap_generate", "clap_generate",
@@ -499,7 +499,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "chainhook-event-observer" name = "chainhook-sdk"
version = "1.0.7" version = "1.0.7"
dependencies = [ dependencies = [
"anyhow", "anyhow",

View File

@@ -1,7 +1,7 @@
[workspace] [workspace]
members = [ members = [
"components/chainhook-event-observer", "components/chainhook-sdk",
"components/chainhook-cli", "components/chainhook-cli",
"components/chainhook-types-rs", "components/chainhook-types-rs",
] ]
default-members = ["components/chainhook-cli", "components/chainhook-event-observer"] default-members = ["components/chainhook-cli", "components/chainhook-sdk"]

View File

@@ -17,7 +17,7 @@ hex = "0.4.3"
rand = "0.8.5" rand = "0.8.5"
# tikv-client = { git = "https://github.com/tikv/client-rust.git", rev = "8f54e6114227718e256027df2577bbacdf425f86" } # tikv-client = { git = "https://github.com/tikv/client-rust.git", rev = "8f54e6114227718e256027df2577bbacdf425f86" }
# raft-proto = { git = "https://github.com/tikv/raft-rs", rev="f73766712a538c2f6eb135b455297ad6c03fc58d", version = "0.7.0"} # raft-proto = { git = "https://github.com/tikv/raft-rs", rev="f73766712a538c2f6eb135b455297ad6c03fc58d", version = "0.7.0"}
chainhook-event-observer = { version = "=1.0.7", default-features = false, features = ["ordinals", "zeromq"], path = "../chainhook-event-observer" } chainhook-sdk = { version = "=1.0.7", default-features = false, features = ["ordinals", "zeromq"], path = "../chainhook-sdk" }
chainhook-types = { version = "=1.0.3", path = "../chainhook-types-rs" } chainhook-types = { version = "=1.0.3", path = "../chainhook-types-rs" }
clarinet-files = "1" clarinet-files = "1"
hiro-system-kit = "0.1.0" hiro-system-kit = "0.1.0"

View File

@@ -1,6 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use chainhook_event_indexer::ingestion::start_ingesting; use chainhook_event_indexer::ingestion::start_ingesting;
use chainhook_event_observer::indexer::IndexerConfig; use chainhook_sdk::indexer::IndexerConfig;
fn criterion_benchmark(c: &mut Criterion) { fn criterion_benchmark(c: &mut Criterion) {

View File

@@ -1,5 +1,5 @@
use crate::config::Config; use crate::config::Config;
use chainhook_event_observer::utils::Context; use chainhook_sdk::utils::Context;
use chainhook_types::{BitcoinNetwork, StacksNetwork}; use chainhook_types::{BitcoinNetwork, StacksNetwork};
use clarinet_files::FileLocation; use clarinet_files::FileLocation;
use flate2::read::GzDecoder; use flate2::read::GzDecoder;

View File

@@ -1,8 +1,8 @@
use super::DigestingCommand; use super::DigestingCommand;
use crate::config::Config; use crate::config::Config;
use chainhook_event_observer::indexer; use chainhook_sdk::indexer;
use chainhook_event_observer::indexer::Indexer; use chainhook_sdk::indexer::Indexer;
use chainhook_event_observer::utils::Context; use chainhook_sdk::utils::Context;
use redis::Commands; use redis::Commands;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::{collections::BinaryHeap, process, sync::mpsc::Receiver}; use std::{collections::BinaryHeap, process, sync::mpsc::Receiver};

View File

@@ -1,6 +1,6 @@
use crate::config::Config; use crate::config::Config;
use chainhook_event_observer::indexer::{self, Indexer}; use chainhook_sdk::indexer::{self, Indexer};
use chainhook_event_observer::utils::Context; use chainhook_sdk::utils::Context;
use chainhook_types::BlockIdentifier; use chainhook_types::BlockIdentifier;
use redis::Commands; use redis::Commands;
use serde::Deserialize; use serde::Deserialize;

View File

@@ -5,29 +5,29 @@ use crate::scan::bitcoin::scan_bitcoin_chainstate_via_rpc_using_predicate;
use crate::scan::stacks::scan_stacks_chainstate_via_csv_using_predicate; use crate::scan::stacks::scan_stacks_chainstate_via_csv_using_predicate;
use crate::service::Service; use crate::service::Service;
use chainhook_event_observer::bitcoincore_rpc::{Auth, Client, RpcApi}; use chainhook_sdk::bitcoincore_rpc::{Auth, Client, RpcApi};
use chainhook_event_observer::chainhooks::types::{ use chainhook_sdk::chainhooks::types::{
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType, BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType,
ChainhookFullSpecification, FileHook, HookAction, OrdinalOperations, ChainhookFullSpecification, FileHook, HookAction, OrdinalOperations,
StacksChainhookFullSpecification, StacksChainhookNetworkSpecification, StacksPredicate, StacksChainhookFullSpecification, StacksChainhookNetworkSpecification, StacksPredicate,
StacksPrintEventBasedPredicate, StacksPrintEventBasedPredicate,
}; };
use chainhook_event_observer::hord::db::{ use chainhook_sdk::hord::db::{
delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db, find_last_block_inserted, delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db, find_last_block_inserted,
find_lazy_block_at_block_height, find_watched_satpoint_for_inscription, initialize_hord_db, find_lazy_block_at_block_height, find_watched_satpoint_for_inscription, initialize_hord_db,
open_readonly_hord_db_conn, open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn, open_readonly_hord_db_conn, open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn,
open_readwrite_hord_db_conn_rocks_db, retrieve_satoshi_point_using_lazy_storage, open_readwrite_hord_db_conn_rocks_db, retrieve_satoshi_point_using_lazy_storage,
}; };
use chainhook_event_observer::hord::{ use chainhook_sdk::hord::{
new_traversals_lazy_cache, retrieve_inscribed_satoshi_points_from_block, new_traversals_lazy_cache, retrieve_inscribed_satoshi_points_from_block,
update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, HordConfig, Storage, update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, HordConfig, Storage,
}; };
use chainhook_event_observer::indexer; use chainhook_sdk::indexer;
use chainhook_event_observer::indexer::bitcoin::{ use chainhook_sdk::indexer::bitcoin::{
download_and_parse_block_with_retry, retrieve_block_hash_with_retry, download_and_parse_block_with_retry, retrieve_block_hash_with_retry,
}; };
use chainhook_event_observer::observer::BitcoinConfig; use chainhook_sdk::observer::BitcoinConfig;
use chainhook_event_observer::utils::Context; use chainhook_sdk::utils::Context;
use chainhook_types::{ use chainhook_types::{
BitcoinBlockData, BitcoinNetwork, BlockIdentifier, StacksNetwork, TransactionIdentifier, BitcoinBlockData, BitcoinNetwork, BlockIdentifier, StacksNetwork, TransactionIdentifier,
}; };

View File

@@ -1,9 +1,9 @@
pub mod file; pub mod file;
pub mod generator; pub mod generator;
use chainhook_event_observer::hord::HordConfig; use chainhook_sdk::hord::HordConfig;
pub use chainhook_event_observer::indexer::IndexerConfig; pub use chainhook_sdk::indexer::IndexerConfig;
use chainhook_event_observer::observer::EventObserverConfig; use chainhook_sdk::observer::EventObserverConfig;
use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork, StacksNetwork}; use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork, StacksNetwork};
pub use file::ConfigFile; pub use file::ConfigFile;
use std::fs::File; use std::fs::File;

View File

@@ -1,31 +1,29 @@
use crate::archive::download_ordinals_dataset_if_required; use crate::archive::download_ordinals_dataset_if_required;
use crate::config::Config; use crate::config::Config;
use chainhook_event_observer::bitcoincore_rpc::RpcApi; use chainhook_sdk::bitcoincore_rpc::RpcApi;
use chainhook_event_observer::bitcoincore_rpc::{Auth, Client}; use chainhook_sdk::bitcoincore_rpc::{Auth, Client};
use chainhook_event_observer::chainhooks::bitcoin::{ use chainhook_sdk::chainhooks::bitcoin::{
evaluate_bitcoin_chainhooks_on_chain_event, handle_bitcoin_hook_action, evaluate_bitcoin_chainhooks_on_chain_event, handle_bitcoin_hook_action,
BitcoinChainhookOccurrence, BitcoinTriggerChainhook, BitcoinChainhookOccurrence, BitcoinTriggerChainhook,
}; };
use chainhook_event_observer::chainhooks::types::{ use chainhook_sdk::chainhooks::types::{BitcoinChainhookSpecification, BitcoinPredicateType};
BitcoinChainhookSpecification, BitcoinPredicateType, use chainhook_sdk::hord::db::{
};
use chainhook_event_observer::hord::db::{
fetch_and_cache_blocks_in_hord_db, find_all_inscriptions, find_last_block_inserted, fetch_and_cache_blocks_in_hord_db, find_all_inscriptions, find_last_block_inserted,
find_lazy_block_at_block_height, open_readonly_hord_db_conn, find_lazy_block_at_block_height, open_readonly_hord_db_conn,
open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn, open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn,
open_readwrite_hord_db_conn_rocks_db, open_readwrite_hord_db_conn_rocks_db,
}; };
use chainhook_event_observer::hord::{ use chainhook_sdk::hord::{
get_inscriptions_revealed_in_block, get_inscriptions_revealed_in_block,
update_storage_and_augment_bitcoin_block_with_inscription_reveal_data, update_storage_and_augment_bitcoin_block_with_inscription_reveal_data,
update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, Storage, update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, Storage,
}; };
use chainhook_event_observer::indexer; use chainhook_sdk::indexer;
use chainhook_event_observer::indexer::bitcoin::{ use chainhook_sdk::indexer::bitcoin::{
download_and_parse_block_with_retry, retrieve_block_hash_with_retry, download_and_parse_block_with_retry, retrieve_block_hash_with_retry,
}; };
use chainhook_event_observer::observer::{gather_proofs, EventObserverConfig}; use chainhook_sdk::observer::{gather_proofs, EventObserverConfig};
use chainhook_event_observer::utils::{file_append, send_request, Context}; use chainhook_sdk::utils::{file_append, send_request, Context};
use chainhook_types::{BitcoinChainEvent, BitcoinChainUpdatedWithBlocksData}; use chainhook_types::{BitcoinChainEvent, BitcoinChainUpdatedWithBlocksData};
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};

View File

@@ -14,13 +14,13 @@ use crate::{
open_readwrite_stacks_db_conn, open_readwrite_stacks_db_conn,
}, },
}; };
use chainhook_event_observer::{ use chainhook_sdk::{
chainhooks::stacks::evaluate_stacks_chainhook_on_blocks, chainhooks::stacks::evaluate_stacks_chainhook_on_blocks,
indexer::{self, stacks::standardize_stacks_serialized_block_header, Indexer}, indexer::{self, stacks::standardize_stacks_serialized_block_header, Indexer},
rocksdb::DB, rocksdb::DB,
utils::Context, utils::Context,
}; };
use chainhook_event_observer::{ use chainhook_sdk::{
chainhooks::{ chainhooks::{
stacks::{handle_stacks_hook_action, StacksChainhookOccurrence, StacksTriggerChainhook}, stacks::{handle_stacks_hook_action, StacksChainhookOccurrence, StacksTriggerChainhook},
types::StacksChainhookSpecification, types::StacksChainhookSpecification,

View File

@@ -4,7 +4,7 @@ use std::{
sync::{mpsc::Sender, Arc, Mutex}, sync::{mpsc::Sender, Arc, Mutex},
}; };
use chainhook_event_observer::{ use chainhook_sdk::{
chainhooks::types::{ChainhookFullSpecification, ChainhookSpecification}, chainhooks::types::{ChainhookFullSpecification, ChainhookSpecification},
observer::ObserverCommand, observer::ObserverCommand,
utils::Context, utils::Context,

View File

@@ -9,11 +9,11 @@ use crate::storage::{
confirm_entries_in_stacks_blocks, draft_entries_in_stacks_blocks, open_readwrite_stacks_db_conn, confirm_entries_in_stacks_blocks, draft_entries_in_stacks_blocks, open_readwrite_stacks_db_conn,
}; };
use chainhook_event_observer::chainhooks::types::{ChainhookConfig, ChainhookFullSpecification}; use chainhook_sdk::chainhooks::types::{ChainhookConfig, ChainhookFullSpecification};
use chainhook_event_observer::chainhooks::types::ChainhookSpecification; use chainhook_sdk::chainhooks::types::ChainhookSpecification;
use chainhook_event_observer::observer::{start_event_observer, ObserverEvent}; use chainhook_sdk::observer::{start_event_observer, ObserverEvent};
use chainhook_event_observer::utils::Context; use chainhook_sdk::utils::Context;
use chainhook_types::{BitcoinBlockSignaling, StacksChainEvent}; use chainhook_types::{BitcoinBlockSignaling, StacksChainEvent};
use redis::{Commands, Connection}; use redis::{Commands, Connection};

View File

@@ -1,6 +1,6 @@
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use chainhook_event_observer::{ use chainhook_sdk::{
chainhooks::types::{ chainhooks::types::{
BitcoinChainhookSpecification, ChainhookSpecification, StacksChainhookSpecification, BitcoinChainhookSpecification, ChainhookSpecification, StacksChainhookSpecification,
}, },

View File

@@ -1,6 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use chainhook_event_observer::{rocksdb::Options, rocksdb::DB, utils::Context}; use chainhook_sdk::{rocksdb::Options, rocksdb::DB, utils::Context};
use chainhook_types::{BlockIdentifier, StacksBlockData, StacksBlockUpdate}; use chainhook_types::{BlockIdentifier, StacksBlockData, StacksBlockUpdate};
fn get_db_default_options() -> Options { fn get_db_default_options() -> Options {

View File

@@ -1,14 +0,0 @@
normalization_enabled = true
bitcoin_rpc_proxy_enabled = false
grpc_server_enabled = true
hooks_enabled = true
webhooks = []
control_port = 20446
ingestion_port = 20445
bitcoind_rpc_username = "devnet"
bitcoind_rpc_password = "devnet"
bitcoind_rpc_host = "localhost"
bitcoind_rpc_port = 18443
stacks_node_rpc_host = "localhost"
stacks_node_rpc_port = 20443
operators = ["74738ff5-5367-5958-9aee-98fffdcd1876"]

View File

@@ -365,7 +365,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "chainhook-event-observer" name = "chainhook-sdk"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"base58", "base58",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "chainhook-event-observer" name = "chainhook-sdk"
version = "1.0.7" version = "0.1.0"
description = "Stateless Transaction Indexing Engine for Stacks and Bitcoin" description = "Stateless Transaction Indexing Engine for Stacks and Bitcoin"
license = "GPL-3.0" license = "GPL-3.0"
edition = "2021" edition = "2021"
@@ -48,7 +48,7 @@ threadpool = "1.8.1"
rand = "0.8.5" rand = "0.8.5"
hex-simd = "0.8.0" hex-simd = "0.8.0"
serde_cbor = "0.11.2" serde_cbor = "0.11.2"
zeromq = { version = "*", default-features = false, features = ["tokio-runtime", "tcp-transport"], optional = true } zeromq = { version = "0.3.3", default-features = false, features = ["tokio-runtime", "tcp-transport"], optional = true }
dashmap = "5.4.0" dashmap = "5.4.0"
fxhash = "0.2.1" fxhash = "0.2.1"

View File

@@ -677,6 +677,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
}; };
let _ = block_data_tx.send(res); let _ = block_data_tx.send(res);
}); });
// TODO: remove this join?
if block_height >= ordinal_computing_height { if block_height >= ordinal_computing_height {
let _ = retrieve_block_data_pool.join(); let _ = retrieve_block_data_pool.join();
} }

View File

@@ -1,29 +0,0 @@
FROM rust:bullseye as build
WORKDIR /src
RUN apt update && apt install -y ca-certificates pkg-config libssl-dev libclang-11-dev
RUN rustup update 1.67.0 && rustup default 1.67.0
COPY ./components/chainhook-types-rs /src/components/chainhook-types-rs
COPY ./components/chainhook-event-observer /src/components/chainhook-event-observer
WORKDIR /src/components/chainhook-event-observer
RUN mkdir /out
RUN cargo build --release
RUN cp target/release/chainhook-event-observer /out
FROM debian:bullseye-slim
RUN apt update && apt install -y ca-certificates libssl-dev
COPY --from=build /out/ /bin/
WORKDIR /workspace
ENTRYPOINT ["chainhook-event-observer"]

View File

@@ -10,7 +10,7 @@ COPY ./components/chainhook-cli /src/components/chainhook-cli
COPY ./components/chainhook-types-rs /src/components/chainhook-types-rs COPY ./components/chainhook-types-rs /src/components/chainhook-types-rs
COPY ./components/chainhook-event-observer /src/components/chainhook-event-observer COPY ./components/chainhook-sdk /src/components/chainhook-sdk
WORKDIR /src/components/chainhook-cli WORKDIR /src/components/chainhook-cli