tangle-network / relayer

🕸️ The Webb Relayer Network
https://webb-tools.github.io/relayer/
Apache License 2.0
22 stars 13 forks source link

[SPEC] Minimizing Transaction Queue configuratioin #595

Closed salman01zp closed 10 months ago

salman01zp commented 10 months ago

Overview

The current tx-queue is designed around a relayer use case and requires a lot of additional configuration(RelayerCtxConfig) which is not required by the tx-queue.

In order to run a tx-queue we require the following things

We can introduce Config traits which can provide us with this information

/// Config trait for EVM tx queue.
#[async_trait::async_trait]
pub trait EvmTxQueueConfig {
    type EtherClient: Middleware;
    /// Maximum number of milliseconds to wait before dequeuing a transaction from
    /// the queue.
    fn max_sleep_interval(&self, chain_id: &U256) -> Result<u64>;
    /// Block confirmations
    fn block_confirmations(&self, chain_id: &U256) -> Result<u8>;
    /// Block Explorer for this chain.
    ///
    /// Optional, and only used for printing a clickable links
    /// for transactions and contracts.
    fn explorer(&self, chain_id: &U256) -> Result<Option<Url>>;
    /// Returns a new `EthereumProvider`.
    ///
    /// # Arguments
    ///
    /// * `chain_id` - A string representing the chain id.
    async fn get_evm_provider(
        &self,
        chain_id: &U256,
    ) -> Result<Arc<Self::EtherClient>>;
    /// Returns an EVM wallet.
    ///
    /// # Arguments
    ///
    /// * `chain_id` - A string representing the chain id.
    async fn get_evm_wallet(&self, chain_id: &U256) -> Result<LocalWallet>;
}

pub struct EvmTxQueue<S, C>
where
    S: QueueStore<TypedTransaction>,
    C: EvmTxQueueConfig
{
    tx_config: C,
    chain_id: types::U256,
    store: Arc<S>,
}

/// Config trait for Substrate tx queue.
#[async_trait::async_trait]
pub trait SubstrateTxQueueConfig {
    /// Maximum number of milliseconds to wait before dequeuing a transaction from
    /// the queue.
    fn max_sleep_interval(&self, chain_id: u32) -> Result<u64>;
    /// Returns a Substrate client.
    ///
    /// # Arguments
    ///
    /// * `chain_id` - A string representing the chain Id.
    async fn substrate_provider<C: subxt::Config>(
        &self,
        chain_id: u32,
    ) -> Result<OnlineClient<C>>;
    /// Returns a Substrate wallet.
    ///
    /// # Arguments
    ///
    /// * `chain_id` - A string representing the chain Id.
    async fn substrate_wallet(&self, chain_id: u32) -> Result<Sr25519Pair>;
}
pub struct SubstrateTxQueue<S, C>
where
    S: QueueStore<TypeErasedStaticTxPayload, Key = SledQueueKey>,
    C: SubstrateTxQueueConfig
{
    tx_config: C,
    chain_id: u32,
    store: Arc<S>,
}
shekohex commented 10 months ago

Looks good! We would implement this trait for RelayerContext too. I would recommend changing the trait functions to expect a ChainId as an argument instead of just returning the ethers client.

One comment also would be to ensure the Store/QueueStore does not depend on relayer specific things, more genaric over different keys/values.