Skip to content

Commit c82903f

Browse files
committed
refactor(node): own the attestation resubmission interval in the tee module
run.rs built the interval and held ATTESTATION_RESUBMISSION_INTERVAL, leaving the cadence policy in the bootstrap file while every other attestation timing constant lived beside the submission code. run_periodic_attestation_submission now wraps that setup, so periodic_attestation_submission and Tick can be private and the ticker seam the tests drive stays unchanged.
1 parent 71e4834 commit c82903f

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

crates/node/src/run.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use std::{
3434
collections::BTreeMap,
3535
path::PathBuf,
3636
sync::{Arc, Mutex, OnceLock},
37-
time::Duration,
3837
};
3938
use tee_authority::tee_authority::TeeAuthority;
4039
use tokio::signal::unix::{SignalKind, signal};
@@ -45,12 +44,10 @@ use tracing::info;
4544
use crate::tee::{
4645
AllowedImageHashesFile, monitor_allowed_image_hashes,
4746
remote_attestation::{
48-
AttestationSubmitter, monitor_attestation_removal, periodic_attestation_submission,
47+
AttestationSubmitter, monitor_attestation_removal, run_periodic_attestation_submission,
4948
},
5049
};
5150

52-
pub const ATTESTATION_RESUBMISSION_INTERVAL: Duration = Duration::from_secs(60 * 60); // 1 hour
53-
5451
pub async fn run_mpc_node(config: StartConfig) -> anyhow::Result<()> {
5552
init_logging(&config.log);
5653

@@ -367,14 +364,7 @@ where
367364
allowed_launcher_compose_hashes: indexer_api.allowed_launcher_compose_receiver.clone(),
368365
attestation_reader: indexer_api.attestation_reader.clone(),
369366
};
370-
let mut attestation_interval = tokio::time::interval(ATTESTATION_RESUBMISSION_INTERVAL);
371-
// A failed submission can retry internally for longer than the interval; skip the missed
372-
// ticks instead of bursting stale submissions afterwards
373-
attestation_interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
374-
tokio::spawn(periodic_attestation_submission(
375-
submitter.clone(),
376-
attestation_interval,
377-
));
367+
tokio::spawn(run_periodic_attestation_submission(submitter.clone()));
378368
tokio::spawn(monitor_attestation_removal(
379369
submitter,
380370
config.my_near_account_id.clone(),

crates/node/src/tee/remote_attestation.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const MAX_BACKOFF_DURATION: Duration = Duration::from_secs(60);
3333
const MAX_RETRY_DURATION: Duration = Duration::from_secs(60 * 60 * 12); // 12 hours.
3434
const BACKOFF_FACTOR: f32 = 1.5;
3535
const RESUBMISSION_RETRY_DELAY: Duration = Duration::from_secs(60 * 10); // 10 minutes.
36+
const ATTESTATION_RESUBMISSION_INTERVAL: Duration = Duration::from_secs(60 * 60); // 1 hour.
3637

3738
/// Shared inputs for the attestation-submission background tasks
3839
/// ([`periodic_attestation_submission`] and [`monitor_attestation_removal`]).
@@ -224,10 +225,18 @@ fn outcome_label(succeeded: bool) -> &'static str {
224225
}
225226
}
226227

228+
pub async fn run_periodic_attestation_submission<T: TransactionSender + Clone>(
229+
submitter: AttestationSubmitter<T>,
230+
) {
231+
let mut interval = tokio::time::interval(ATTESTATION_RESUBMISSION_INTERVAL);
232+
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
233+
periodic_attestation_submission(submitter, interval).await
234+
}
235+
227236
/// Periodically regenerates and submits this node's attestation. Generation and submission
228237
/// failures are logged and retried on the next tick; this task never returns.
229238
#[tracing::instrument(skip_all)]
230-
pub async fn periodic_attestation_submission<T: TransactionSender + Clone, I: Tick>(
239+
async fn periodic_attestation_submission<T: TransactionSender + Clone, I: Tick>(
231240
submitter: AttestationSubmitter<T>,
232241
mut interval_ticker: I,
233242
) {
@@ -314,7 +323,7 @@ pub async fn monitor_attestation_removal<T: TransactionSender + Clone>(
314323
}
315324

316325
/// Allows repeatedly awaiting for something, like a [`tokio::time::Interval`].
317-
pub trait Tick {
326+
trait Tick {
318327
async fn tick(&mut self);
319328
}
320329

0 commit comments

Comments
 (0)