Skip to content

Commit

Permalink
feat(relayer): add check for replica updater addresses (#219)
Browse files Browse the repository at this point in the history
* feat(relayer): add check for replica addresses

* chore(changelog): add comment

* fix(relayer): hex format addrs
  • Loading branch information
luketchang authored Jul 20, 2022
1 parent 185cbfe commit f883290
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions agents/relayer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Unreleased

- relayer checks replica updater addresses match, errors channel if otherwise
- add bootup-only tracing subscriber
- add environment variable overrides for agent configuration
- add tests for agent environment variable overrides
Expand Down
23 changes: 20 additions & 3 deletions agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use color_eyre::Result;
use color_eyre::{eyre::ensure, Result};
use std::{sync::Arc, time::Duration};
use tokio::{sync::Mutex, task::JoinHandle, time::sleep};
use tracing::{info, instrument::Instrumented, Instrument};
Expand Down Expand Up @@ -169,6 +169,16 @@ impl NomadAgent for Relayer {
#[tracing::instrument]
fn run(channel: Self::Channel) -> Instrumented<JoinHandle<Result<()>>> {
tokio::spawn(async move {
let home_updater = channel.home().updater().await?;
let replica_updater = channel.replica().updater().await?;

ensure!(
home_updater == replica_updater,
"Home and replica updaters do not match. Home: {:x}. Replica: {:x}.",
home_updater,
replica_updater
);

let update_poller = UpdatePoller::new(
channel.home(),
channel.replica(),
Expand All @@ -183,8 +193,7 @@ impl NomadAgent for Relayer {

#[cfg(test)]
mod test {

use ethers::prelude::ProviderError;
use ethers::prelude::{ProviderError, H256};
use nomad_base::{
chains::PageSettings, CommonIndexers, ContractSync, ContractSyncMetrics, CoreMetrics,
HomeIndexers, IndexSettings, NomadDB,
Expand Down Expand Up @@ -233,13 +242,21 @@ mod test {

{
home_mock.expect__name().return_const("home_1".to_owned());
home_mock
.expect__updater()
.times(..)
.returning(|| Ok(H256::zero()));
}

let home = CachingHome::new(home_mock.into(), home_sync, home_db.clone()).into();

// Setting replica
let mut replica_mock = MockReplicaContract::new();
{
replica_mock
.expect__updater()
.times(..)
.returning(|| Ok(H256::zero()));
replica_mock
.expect__committed_root()
.times(..)
Expand Down

0 comments on commit f883290

Please sign in to comment.