Skip to content

Commit

Permalink
Feat: btc ingress egress tracking (#4133)
Browse files Browse the repository at this point in the history
* refactor: extract btc egress processing

* refactor: rename btc mempool witnessing

* feat: add btc ingress-egress tracking

* refactor: btc mempool tracker uses shared settings

* chore: fix clippy

* chore: address review comments

* chore: remove redundant shared adapter
  • Loading branch information
msgmaxim authored Oct 19, 2023
1 parent 8c7d520 commit 2768d3c
Show file tree
Hide file tree
Showing 8 changed files with 684 additions and 576 deletions.
12 changes: 10 additions & 2 deletions api/bin/chainflip-ingress-egress-tracker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chainflip_engine::settings::WsHttpEndpoints;
use chainflip_engine::settings::{HttpBasicAuthEndpoint, WsHttpEndpoints};
use futures::FutureExt;
use jsonrpsee::{core::Error, server::ServerBuilder, RpcModule};
use std::{env, io::Write, net::SocketAddr, path::PathBuf};
Expand All @@ -14,6 +14,7 @@ pub struct DepositTrackerSettings {
eth_key_path: PathBuf,
dot_node: WsHttpEndpoints,
state_chain_ws_endpoint: String,
btc: HttpBasicAuthEndpoint,
}

async fn start(
Expand All @@ -26,7 +27,7 @@ async fn start(
.expect("setting default subscriber failed");
let mut module = RpcModule::new(());

let btc_tracker = witnessing::btc::start(scope).await;
let btc_tracker = witnessing::btc_mempool::start(scope, settings.btc.clone()).await;

module.register_async_method("status", move |arguments, _context| {
let btc_tracker = btc_tracker.clone();
Expand Down Expand Up @@ -109,6 +110,13 @@ async fn main() -> anyhow::Result<()> {
},
state_chain_ws_endpoint: env::var("SC_WS_ENDPOINT")
.unwrap_or("ws://localhost:9944".to_string()),
btc: HttpBasicAuthEndpoint {
http_endpoint: env::var("BTC_ENDPOINT")
.unwrap_or("http://127.0.0.1:8332".to_string())
.into(),
basic_auth_user: env::var("BTC_USERNAME").unwrap_or("flip".to_string()),
basic_auth_password: env::var("BTC_PASSWORD").unwrap_or("flip".to_string()),
},
};

task_scope::task_scope(|scope| async move { start(scope, settings).await }.boxed()).await
Expand Down
38 changes: 29 additions & 9 deletions api/bin/chainflip-ingress-egress-tracker/src/witnessing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod btc;
mod btc;
pub mod btc_mempool;
mod dot;
mod eth;

Expand Down Expand Up @@ -27,6 +28,7 @@ struct EnvironmentParameters {
usdc_contract_address: H160,
supported_erc20_tokens: HashMap<H160, cf_primitives::Asset>,
dot_genesis_hash: PolkadotHash,
btc_network: cf_chains::btc::BitcoinNetwork,
}

async fn get_env_parameters(state_chain_client: &StateChainClient<()>) -> EnvironmentParameters {
Expand Down Expand Up @@ -66,14 +68,20 @@ async fn get_env_parameters(state_chain_client: &StateChainClient<()>) -> Enviro
.map(|(asset, address)| (address, asset.into()))
.collect();

let dot_genesis_hash = PolkadotHash::from(
state_chain_client
.storage_value::<pallet_cf_environment::PolkadotGenesisHash<state_chain_runtime::Runtime>>(
state_chain_client.latest_finalized_hash(),
)
.await
.expect(STATE_CHAIN_CONNECTION),
);
let dot_genesis_hash = state_chain_client
.storage_value::<pallet_cf_environment::PolkadotGenesisHash<state_chain_runtime::Runtime>>(
state_chain_client.latest_finalized_hash(),
)
.await
.expect(STATE_CHAIN_CONNECTION);

let btc_network = state_chain_client
.storage_value::<pallet_cf_environment::ChainflipNetworkEnvironment<state_chain_runtime::Runtime>>(
state_chain_client.latest_finalized_hash(),
)
.await
.expect(STATE_CHAIN_CONNECTION)
.into();

EnvironmentParameters {
eth_chain_id,
Expand All @@ -83,6 +91,7 @@ async fn get_env_parameters(state_chain_client: &StateChainClient<()>) -> Enviro
eth_address_checker_address,
supported_erc20_tokens,
dot_genesis_hash,
btc_network,
}
}

Expand Down Expand Up @@ -129,6 +138,17 @@ pub(super) async fn start(
)
.await?;

btc::start(
scope,
witness_call.clone(),
settings.clone(),
env_params.clone(),
state_chain_client.clone(),
state_chain_stream.clone(),
epoch_source.clone(),
)
.await?;

dot::start(
scope,
witness_call,
Expand Down
Loading

0 comments on commit 2768d3c

Please sign in to comment.