Skip to content

Commit

Permalink
fixup! feat: add the MultidappClaimer as an experimental feature for …
Browse files Browse the repository at this point in the history
…sunodo
  • Loading branch information
renan061 committed Aug 16, 2024
1 parent 4237b7e commit 691d5ed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
13 changes: 6 additions & 7 deletions offchain/authority-claimer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ 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 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 `authority-claimer`.
This key holds a Redis Set value.
You must use commands such as SADD and SREM to manipulate the list of addresses.
Addresses are encoded as hex strings without the leading `"0x"`.
Example address value: `"0202020202020202020202020202020202020202"`.

You may rewrite the list of addresses at any time,
The claimer will adjust accordingly.
You must set `experimental-dapp-addresses-config` **before** starting the `authority-claimer`.
The `authority-claimer` stops with an error if the list is empty.

Example key value: `"0202020202020202020202020202020202020202, 0505050505050505050505050505050505050505"`.
You may rewrite the list of addresses at any time, the claimer will adjust accordingly.
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 {
info!("It was a duplicated claim");
info!("Duplicate claim detected: {:?}", rollups_claim);
continue;
}

Expand Down
4 changes: 1 addition & 3 deletions offchain/authority-claimer/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,6 @@ mod tests {
assert_eq_vec(fourth_batch_dapps, dapps);
println!("--- All good with the fourth batch!");
}

assert!(false);
}

#[tokio::test]
Expand All @@ -605,7 +603,7 @@ mod tests {
.await;

let result = listener.listen().await;
assert!(result.is_ok());
assert!(result.is_ok(), "{:?}", result);

let expected_dapp = dapps.get(index).unwrap().clone();
let actual_dapp = result.unwrap().dapp_address;
Expand Down
34 changes: 15 additions & 19 deletions offchain/rollups-events/src/broker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub mod indexer;

pub const INITIAL_ID: &str = "0";
const DAPPS_KEY: &str = "experimental-dapp-addresses-config";
const DAPPS_DIVIDER: &str = ", ";

/// The `BrokerConnection` enum implements the `ConnectionLike` trait
/// to satisfy the `AsyncCommands` trait bounds.
Expand Down Expand Up @@ -368,14 +367,13 @@ impl Broker {
pub async fn get_dapps(&mut self) -> Result<Vec<Address>, BrokerError> {
retry(self.backoff.clone(), || async {
tracing::trace!(key = DAPPS_KEY, "getting key");
let reply: String = self.connection.clone().get(DAPPS_KEY).await?;
if reply.is_empty() {
return Ok(vec![]);
}
Ok(reply
.split(DAPPS_DIVIDER)
let reply: Vec<String> =
self.connection.clone().smembers(DAPPS_KEY).await?;
let dapp_addresses: Vec<Address> = reply
.iter()
.map(|s| Address::from_str(s).unwrap())
.collect::<Vec<_>>())
.collect();
Ok(dapp_addresses)
})
.await
.context(ConnectionSnafu)
Expand All @@ -388,17 +386,15 @@ impl Broker {
dapp_addresses: Vec<Address>,
) -> Result<(), BrokerError> {
tracing::trace!(key = DAPPS_KEY, "setting key");
let dapp_addresses: Vec<_> = dapp_addresses
.iter()
.map(|address| address.to_string())
.collect();
let dapp_addresses = dapp_addresses.join(DAPPS_DIVIDER);
let _: () = self
.connection
.clone()
.set(DAPPS_KEY, dapp_addresses)
.await
.unwrap();
let _: () = self.connection.clone().del(DAPPS_KEY).await.unwrap();
for dapp_address in dapp_addresses {
let _: () = self
.connection
.clone()
.sadd(DAPPS_KEY, dapp_address.to_string())
.await
.unwrap();
}
Ok(())
}
}
Expand Down

0 comments on commit 691d5ed

Please sign in to comment.