Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions agents/updater/src/produce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) struct UpdateProducer {
home: Arc<CachingHome>,
db: NomadDB,
signer: Arc<Signers>,
update_pause_seconds: u64,
interval_seconds: u64,
signed_attestation_count: IntCounter,
}
Expand All @@ -22,13 +23,15 @@ impl UpdateProducer {
home: Arc<CachingHome>,
db: NomadDB,
signer: Arc<Signers>,
update_pause_seconds: u64,
interval_seconds: u64,
signed_attestation_count: IntCounter,
) -> Self {
Self {
home,
db,
signer,
update_pause_seconds,
interval_seconds,
signed_attestation_count,
}
Expand Down Expand Up @@ -109,6 +112,31 @@ impl UpdateProducer {
continue;
}

// Sleep for `update_pause` seconds so we can check for
// unwanted state changes afterwards
sleep(Duration::from_secs(self.update_pause_seconds)).await;

// If HomeIndexer found new root from that doesn't
// match our most current root, continue
if self.find_latest_root()? != current_root {
continue;
}

// Have home suggest an update again
if let Some(check_suggested) = self.home.produce_update().await? {
if check_suggested.previous_root != suggested.previous_root {
// If newly suggested update no longer builds on
// same previous root as original suggested, reorg
// occurred or home received new in flight update.
// Ignore and continue.
continue;
}
} else {
// If no longer a suggested update, reorg or new update
// was received during pause. Ignore and continue.
continue;
}

// If the suggested matches our local view, sign an update
// and store it as locally produced
let signed = suggested.sign_with(self.signer.as_ref()).await?;
Expand Down
2 changes: 2 additions & 0 deletions agents/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ impl NomadAgent for Updater {
let home = self.home();
let address = self.signer.address();
let db = NomadDB::new(self.home().name(), self.db());
let update_pause = self.as_ref().settings.home.block_time;

let produce = UpdateProducer::new(
self.home(),
db.clone(),
self.signer.clone(),
update_pause,
self.interval_seconds,
self.signed_attestation_count.clone(),
);
Expand Down
4 changes: 4 additions & 0 deletions nomad-base/src/settings/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct ChainSetup {
pub page_settings: PageSettings,
/// Network specific finality in blocks
pub finality: u8,
/// Network specific block time
pub block_time: u64,
/// The chain connection details
#[serde(flatten)]
pub chain: ChainConf,
Expand Down Expand Up @@ -82,6 +84,7 @@ impl ChainSetup {
.expect("!domain");
let domain_number = domain.domain;
let finality = domain.specs.finalization_blocks;
let block_time = domain.specs.block_time;
let core = config.core().get(&resident_network).expect("!core");
let (address, page_settings) = match core {
CoreContracts::Evm(core) => {
Expand Down Expand Up @@ -117,6 +120,7 @@ impl ChainSetup {
address,
page_settings,
finality,
block_time,
chain,
disabled: None,
}
Expand Down