fuel_core_relayer/
config.rs

1use ethers_contract::EthEvent;
2use ethers_core::types::H256;
3use fuel_core_types::{
4    blockchain::primitives::DaBlockHeight,
5    fuel_types::Bytes20,
6};
7use once_cell::sync::Lazy;
8use std::{
9    str::FromStr,
10    time::Duration,
11};
12
13pub(crate) static ETH_LOG_MESSAGE: Lazy<H256> =
14    Lazy::new(crate::abi::bridge::MessageSentFilter::signature);
15
16pub(crate) static ETH_FORCED_TX: Lazy<H256> =
17    Lazy::new(crate::abi::bridge::TransactionFilter::signature);
18
19// TODO: Move settlement fields into `ChainConfig` because it is part of the consensus.
20#[derive(Clone, Debug)]
21/// Configuration settings for the Relayer.
22pub struct Config {
23    /// The da block to which the contract was deployed.
24    pub da_deploy_height: DaBlockHeight,
25    /// Uri addresses to ethereum client.
26    pub relayer: Option<Vec<url::Url>>,
27    // TODO: Create `EthAddress` into `fuel_core_types`.
28    /// Ethereum contract address.
29    pub eth_v2_listening_contracts: Vec<Bytes20>,
30    /// Number of pages or blocks containing logs that
31    /// should be downloaded in a single call to the da layer
32    pub log_page_size: u64,
33    /// This throttles the background relayer loop to
34    /// at least this duration to prevent spamming the DA node.
35    pub sync_minimum_duration: Duration,
36    /// How often calls are made to the DA node when the DA node
37    /// is in the process of syncing.
38    pub syncing_call_frequency: Duration,
39    /// How often progress logs are printed when the DA node is
40    /// syncing.
41    pub syncing_log_frequency: Duration,
42
43    /// Enables metrics on this fuel service
44    pub metrics: bool,
45}
46
47#[allow(missing_docs)]
48impl Config {
49    pub const DEFAULT_LOG_PAGE_SIZE: u64 = 10_000;
50    pub const DEFAULT_DA_DEPLOY_HEIGHT: u64 = 0;
51    pub const DEFAULT_SYNC_MINIMUM_DURATION: Duration = Duration::from_secs(5);
52    pub const DEFAULT_SYNCING_CALL_FREQ: Duration = Duration::from_secs(5);
53    pub const DEFAULT_SYNCING_LOG_FREQ: Duration = Duration::from_secs(60);
54}
55
56impl Default for Config {
57    fn default() -> Self {
58        Self {
59            da_deploy_height: DaBlockHeight::from(Self::DEFAULT_DA_DEPLOY_HEIGHT),
60            relayer: None,
61            eth_v2_listening_contracts: vec![Bytes20::from_str(
62                "0x03E4538018285e1c03CCce2F92C9538c87606911",
63            )
64            .unwrap()],
65            log_page_size: Self::DEFAULT_LOG_PAGE_SIZE,
66            sync_minimum_duration: Self::DEFAULT_SYNC_MINIMUM_DURATION,
67            syncing_call_frequency: Self::DEFAULT_SYNCING_CALL_FREQ,
68            syncing_log_frequency: Self::DEFAULT_SYNCING_LOG_FREQ,
69            metrics: false,
70        }
71    }
72}
73
74mod tests {
75
76    #[test]
77    fn conversion_str_h160_bytes() {
78        use std::str::FromStr;
79
80        let bytes20 = fuel_core_types::fuel_types::Bytes20::from_str(
81            "0x03E4538018285e1c03CCce2F92C9538c87606911",
82        )
83        .unwrap();
84        let h160 = ethers_core::types::H160::from_str(
85            "0x03E4538018285e1c03CCce2F92C9538c87606911",
86        )
87        .unwrap();
88        assert_eq!(bytes20.as_slice(), h160.as_bytes());
89    }
90}