-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: ingress-egress tracking for DOT (#4121)
* refactor: extract dot witnessing procedures into reusable functions * feat: add dot ingress-egress tracking * chore: silence clippy type complexity * chore: address minor review comments
- Loading branch information
Showing
8 changed files
with
239 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
api/bin/chainflip-ingress-egress-tracker/src/witnessing/dot.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use std::sync::Arc; | ||
|
||
use cf_primitives::EpochIndex; | ||
use chainflip_engine::{ | ||
dot::retry_rpc::DotRetryRpcClient, | ||
settings::NodeContainer, | ||
state_chain_observer::client::{ | ||
storage_api::StorageApi, StateChainClient, StateChainStreamApi, | ||
}, | ||
witness::{ | ||
common::{ | ||
chain_source::extension::ChainSourceExt, epoch_source::EpochSourceBuilder, | ||
STATE_CHAIN_CONNECTION, | ||
}, | ||
dot::{filter_map_events, process_egress, proxy_added_witnessing, DotUnfinalisedSource}, | ||
}, | ||
}; | ||
use futures::Future; | ||
use utilities::task_scope::Scope; | ||
|
||
use crate::DepositTrackerSettings; | ||
|
||
use super::EnvironmentParameters; | ||
|
||
pub(super) async fn start<ProcessCall, ProcessingFut>( | ||
scope: &Scope<'_, anyhow::Error>, | ||
witness_call: ProcessCall, | ||
settings: DepositTrackerSettings, | ||
env_params: EnvironmentParameters, | ||
state_chain_client: Arc<StateChainClient<()>>, | ||
state_chain_stream: impl StateChainStreamApi + Clone, | ||
epoch_source: EpochSourceBuilder<'_, '_, StateChainClient<()>, (), ()>, | ||
) -> anyhow::Result<()> | ||
where | ||
ProcessCall: Fn(state_chain_runtime::RuntimeCall, EpochIndex) -> ProcessingFut | ||
+ Send | ||
+ Sync | ||
+ Clone | ||
+ 'static, | ||
ProcessingFut: Future<Output = ()> + Send + 'static, | ||
{ | ||
let dot_client = DotRetryRpcClient::new( | ||
scope, | ||
NodeContainer { primary: settings.dot_node, backup: None }, | ||
env_params.dot_genesis_hash, | ||
)?; | ||
|
||
let epoch_source = epoch_source | ||
.filter_map( | ||
|state_chain_client, _epoch_index, hash, _info| async move { | ||
state_chain_client | ||
.storage_value::<pallet_cf_environment::PolkadotVaultAccountId<state_chain_runtime::Runtime>>( | ||
hash, | ||
) | ||
.await | ||
.expect(STATE_CHAIN_CONNECTION) | ||
}, | ||
|_state_chain_client, _epoch, _block_hash, historic_info| async move { historic_info }, | ||
) | ||
.await; | ||
|
||
let vaults = epoch_source.vaults().await; | ||
|
||
DotUnfinalisedSource::new(dot_client.clone()) | ||
.shared(scope) | ||
.then(|header| async move { header.data.iter().filter_map(filter_map_events).collect() }) | ||
.strictly_monotonic() | ||
.shared(scope) | ||
.chunk_by_vault(vaults.clone()) | ||
.deposit_addresses(scope, state_chain_stream.clone(), state_chain_client.clone()) | ||
.await | ||
// Deposit witnessing | ||
.dot_deposits(witness_call.clone()) | ||
// Proxy added witnessing | ||
.then({ | ||
let witness_call = witness_call.clone(); | ||
move |epoch, header| proxy_added_witnessing(epoch, header, witness_call.clone()) | ||
}) | ||
// Broadcast success | ||
.egress_items(scope, state_chain_stream.clone(), state_chain_client.clone()) | ||
.await | ||
.then({ | ||
let witness_call = witness_call.clone(); | ||
let dot_client = dot_client.clone(); | ||
move |epoch, header| { | ||
process_egress(epoch, header, witness_call.clone(), dot_client.clone()) | ||
} | ||
}) | ||
.logging("witnessing") | ||
.spawn(scope); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod btc; | ||
pub mod common; | ||
mod dot; | ||
pub mod dot; | ||
pub mod eth; | ||
pub mod start; |
Oops, something went wrong.