Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
renan061 committed Aug 14, 2024
1 parent 0afc9d8 commit 15f40f0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
14 changes: 8 additions & 6 deletions offchain/authority-claimer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
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!)

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"`.
2 changes: 1 addition & 1 deletion offchain/authority-claimer/src/claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions offchain/authority-claimer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,7 +26,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {
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,
Expand All @@ -35,7 +35,7 @@ pub async fn run(config: Config) -> Result<(), Box<dyn Error>> {
.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,
Expand Down
23 changes: 13 additions & 10 deletions offchain/authority-claimer/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -96,7 +96,10 @@ impl MultidappBrokerListener {
broker_config: BrokerConfig,
chain_id: u64,
) -> Result<Self, BrokerError> {
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 {
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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()
);
}
Expand Down
2 changes: 1 addition & 1 deletion offchain/test-fixtures/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericImage>, BrokerEndpoint, Mutex<Broker>) {
Expand Down

0 comments on commit 15f40f0

Please sign in to comment.