From 15f40f027b89471e4104b27f562deb15aad6a99c Mon Sep 17 00:00:00 2001 From: Renan Santos Date: Wed, 14 Aug 2024 19:01:22 -0300 Subject: [PATCH] wip --- offchain/authority-claimer/README.md | 14 +++++++------ offchain/authority-claimer/src/claimer.rs | 2 +- offchain/authority-claimer/src/lib.rs | 6 +++--- offchain/authority-claimer/src/listener.rs | 23 ++++++++++++---------- offchain/test-fixtures/src/broker.rs | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/offchain/authority-claimer/README.md b/offchain/authority-claimer/README.md index 2e094aa1..71d934e4 100644 --- a/offchain/authority-claimer/README.md +++ b/offchain/authority-claimer/README.md @@ -3,7 +3,7 @@ This service submits rollups claims consumed from the broker to the blockchain using the [tx-manager crate](https://github.com/cartesi/tx-manager). It runs at the end of every epoch, when new claims are inserted on the broker. -### Multidapp Mode +### Multi-dapp Mode (This is an **experimental** feature! Don't try it unless you know exactly what you are doing!) @@ -11,16 +11,18 @@ The `authority-claimer` can be configured to run in "multidapp mode". To do so, the `DAPP_CONTRACT_ADDRESS` environment variable must be left unset. This will force the claimer to instantiate a `MultidappBrokerListener` instead of a `DefaultBrokerListener`. -In multidapp mode, the claimer reads claims from the broker for multiple dapps. +In multidapp mode, the claimer reads claims from the broker for multiple applications. All dapps must share the same History contract and the same chain ID. Instead of using evironment variables, - the claimer will get the list of dapp addresses from Redis, + the claimer will get the list of application addresses from Redis, through the `experimental-dapp-addresses-config` key. You must set this key with a string of comma separated (`", "`) hex encoded addresses (without `"0x"`) - **before** starting the claimer. -You may rewrite this key at any time, and the claimer will adjust accordingly to the new list of addresses. -The claimer stops with an error if the list is empty. + **before** starting the `authority-claimer`. + +You may rewrite the list of addresses at any time, +The claimer will adjust accordingly. +The `authority-claimer` stops with an error if the list is empty. Example key value: `"0202020202020202020202020202020202020202, 0505050505050505050505050505050505050505"`. diff --git a/offchain/authority-claimer/src/claimer.rs b/offchain/authority-claimer/src/claimer.rs index 203603ce..c21a4ed9 100644 --- a/offchain/authority-claimer/src/claimer.rs +++ b/offchain/authority-claimer/src/claimer.rs @@ -104,7 +104,7 @@ where .await .context(DuplicatedClaimSnafu)?; if is_duplicated_rollups_claim { - debug!("It was a duplicated claim"); + info!("It was a duplicated claim"); continue; } diff --git a/offchain/authority-claimer/src/lib.rs b/offchain/authority-claimer/src/lib.rs index 2c8a7e45..3e657151 100644 --- a/offchain/authority-claimer/src/lib.rs +++ b/offchain/authority-claimer/src/lib.rs @@ -12,7 +12,7 @@ pub mod signer; use config::Config; use listener::{BrokerListener, MultidappBrokerListener}; use snafu::Error; -use tracing::trace; +use tracing::{info, trace}; use crate::{ checker::DefaultDuplicateChecker, @@ -26,7 +26,7 @@ pub async fn run(config: Config) -> Result<(), Box> { let metrics = AuthorityClaimerMetrics::new(); let dapp_address = config.authority_claimer_config.dapp_address.clone(); if let Some(dapp_address) = dapp_address { - trace!("Creating the default broker listener"); + info!("Creating the default broker listener"); let broker_listener = DefaultBrokerListener::new( config.authority_claimer_config.broker_config.clone(), config.authority_claimer_config.tx_manager_config.chain_id, @@ -35,7 +35,7 @@ pub async fn run(config: Config) -> Result<(), Box> { .await?; _run(metrics, config, broker_listener).await } else { - trace!("Creating the multidapp broker listener"); + info!("Creating the multidapp broker listener"); let broker_listener = MultidappBrokerListener::new( config.authority_claimer_config.broker_config.clone(), config.authority_claimer_config.tx_manager_config.chain_id, diff --git a/offchain/authority-claimer/src/listener.rs b/offchain/authority-claimer/src/listener.rs index 57124ceb..09f297b5 100644 --- a/offchain/authority-claimer/src/listener.rs +++ b/offchain/authority-claimer/src/listener.rs @@ -22,8 +22,8 @@ pub enum BrokerListenerError { #[snafu(display("broker error"))] BrokerError { source: BrokerError }, - #[snafu(display("no dapps"))] - NoDapps, + #[snafu(display("no applications configured"))] + NoApplicationsConfigured, } // ------------------------------------------------------------------------------------------------ @@ -96,7 +96,10 @@ impl MultidappBrokerListener { broker_config: BrokerConfig, chain_id: u64, ) -> Result { - tracing::trace!("Connecting to the broker ({:?})", broker_config); + tracing::trace!( + "Connecting to the broker ({:?}) on multidapp mode", + broker_config + ); let broker = Broker::new(broker_config).await?; let streams = HashMap::new(); Ok(Self { @@ -113,11 +116,11 @@ impl MultidappBrokerListener { async fn update_streams(&mut self) -> Result<(), BrokerListenerError> { let initial_id = INITIAL_ID.to_string(); - let streams: Vec<_> = self - .broker - .get_dapps() - .await - .context(BrokerSnafu)? + let streams: Vec<_> = + self.broker.get_dapps().await.context(BrokerSnafu)?; + tracing::info!("Got the following dapps: {:?}", self.streams); + + let streams: Vec<_> = streams .into_iter() .map(|dapp_address| { let dapp_metadata = &DAppMetadata { @@ -130,7 +133,7 @@ impl MultidappBrokerListener { }) .collect(); if streams.is_empty() { - return Err(BrokerListenerError::NoDapps); + return Err(BrokerListenerError::NoApplicationsConfigured); } self.streams = HashMap::from_iter(streams); @@ -438,7 +441,7 @@ mod tests { let result = listener.listen().await; assert!(result.is_err()); assert_eq!( - BrokerListenerError::NoDapps.to_string(), + BrokerListenerError::NoApplicationsConfigured.to_string(), result.unwrap_err().to_string() ); } diff --git a/offchain/test-fixtures/src/broker.rs b/offchain/test-fixtures/src/broker.rs index 3ab8d1d0..b2d43547 100644 --- a/offchain/test-fixtures/src/broker.rs +++ b/offchain/test-fixtures/src/broker.rs @@ -18,7 +18,7 @@ use tokio::sync::Mutex; const CHAIN_ID: u64 = 0; const DAPP_ADDRESS: Address = Address::new([0xfa; ADDRESS_SIZE]); const CONSUME_TIMEOUT: usize = 10_000; // ms - // + async fn start_redis( docker: &Cli, ) -> (Container, BrokerEndpoint, Mutex) {