1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#![recursion_limit = "256"]
#![feature(array_zip)]

mod cancellation;
mod cli;
mod connection_manager;
pub mod delay;
mod error;
mod execution;
mod faucet;
mod issue;
pub mod metrics;
pub mod process;
mod redeem;
pub mod relay;
mod replace;
mod system;
mod trace;
mod types;

pub mod service {
    pub use crate::{
        cancellation::{CancellationScheduler, IssueCanceller, ReplaceCanceller},
        connection_manager::{
            init_subscriber, spawn_cancelable, wait_or_shutdown, warp, warp::Filter, ConnectionManager,
            DynBitcoinCoreApi, MonitoringConfig, Service, ServiceConfig, ShutdownSender,
        },
        execution::execute_open_requests,
        issue::{
            listen_for_issue_cancels, listen_for_issue_executes, listen_for_issue_requests, process_issue_requests,
        },
        metrics::monitor_bridge_metrics,
        redeem::listen_for_redeem_requests,
        relay::{Config, Runner},
        replace::{listen_for_accept_replace, listen_for_execute_replace, listen_for_replace_requests},
    };
}
use governor::Quota;
use nonzero_ext::*;
use std::time::Duration;
pub use system::{VaultService, VaultServiceConfig, ABOUT, AUTHORS, NAME, VERSION};

use runtime::{InterBtcParachain, VaultId, VaultRegistryPallet};

pub use crate::{cancellation::Event, error::Error, types::IssueRequests};
pub use delay::{OrderedVaultsDelay, RandomDelay, ZeroDelay};
pub use system::VaultIdManager;

pub(crate) async fn deposit_collateral(api: &InterBtcParachain, vault_id: &VaultId, amount: u128) -> Result<(), Error> {
    let result = api.deposit_collateral(vault_id, amount).await;
    tracing::info!("Locking additional collateral; amount {}: {:?}", amount, result);
    Ok(result?)
}

/// At startup we wait until a new block has arrived before we start event listeners.
/// This constant defines the rate at which we check whether the chain height has increased.
pub const CHAIN_HEIGHT_POLLING_INTERVAL: Duration = Duration::from_millis(500);

/// explicitly yield at most once per second
pub const YIELD_RATE: Quota = Quota::per_second(nonzero!(1u32));