input-output-hk / mithril

Stake-based threshold multi-signatures protocol
https://mithril.network
Apache License 2.0
129 stars 41 forks source link

Enhance Mithril/Cardano node communication #1315

Closed jpraynaud closed 8 months ago

jpraynaud commented 1 year ago

Why

Today, the Mithril signer and aggregator communicate with the Cardano node with the Cardano cli which acts as a proxy for providing some of the information essential to running a Mithril network. This communication is not optimal, and we could communicate directly with the Cardano node instead.

What

The Mithril signer and aggregator (will) rely on some information that are provided by the Cardano node :

The signer and aggregator rely on an a common ChainObserver trait:

pub trait ChainObserver: Sync + Send {
    /// Retrieve the datums associated to and address
    async fn get_current_datums(
        &self,
        address: &ChainAddress,
    ) -> Result<Vec<TxDatum>, ChainObserverError>;

    /// Retrieve the current epoch of the Cardano network
    async fn get_current_epoch(&self) -> Result<Option<Epoch>, ChainObserverError>;

    /// Retrieve the current stake distribution of the Cardano network
    async fn get_current_stake_distribution(
        &self,
    ) -> Result<Option<StakeDistribution>, ChainObserverError>;

    /// Retrieve the KES period of an operational certificate
    async fn get_current_kes_period(
        &self,
        _opcert: &OpCert,
    ) -> Result<Option<KESPeriod>, ChainObserverError> {
        Ok(None)
    }
}

That is currently implemented by the CliObserver.

We would like to have a new implementation CardanoObserver of this trait that:

A good candidate library to implement this is pallas and pallas-network that already has an implementation of the mini-protocols.

Note: The signer and aggregator nodes already have a defined configuration parameter with the path of the Cardano node socket cardano_node_socket_path:

How

Draft of how this could be implemented

Acceptance Criteria

jpraynaud commented 1 year ago

Ping @abailly-iohk, @scarmuega, @falcucci

jpraynaud commented 1 year ago

@scarmuega, @falcucci, following our discussion, here are some information on the way dependencies of the ChainObserver work.

In order to test the new PallasObserver, you will need to update the dependency injection in the aggregator and signer.

I'd suggest that you make the change in 2 phases:

robinboening commented 10 months ago

+1 for working on this issue. I am following this because once the switch is done it allows docker set ups to remove the cardano-cli dependency from the container. This dependency has been annoying me a bit as it currently means you either have to

  1. copy the cardano-cli (+libs) over to your mithril container
  2. or allow the mithril container to execute the cardano node container's cli

Both ways do work, but it'll be much more elegant when the cardano-cli isn't needed anymore.

Keep up the great work! 👏 ~Robin