Skip to content

Commit 1e4b663

Browse files
committed
refactor(mock-attestation): rename with_expiry -> with_expiry_capped_at
It caps (min of existing and provided), not sets, so the old name read as a pure setter and misled readers (netrome). Renamed the method, its two call sites (AcceptedAttestation::mock, the migration helper), and its tests.
1 parent ad85d0b commit 1e4b663

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

crates/contract/src/v3_13_0_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct MpcContract {
112112
/// [`mpc_attestation::attestation::MockAttestation::Valid`] entries pass
113113
/// re-verification forever and can therefore never be evicted by
114114
/// [`TeeState::clean_invalid_attestations`];
115-
/// [`mpc_attestation::attestation::MockAttestation::with_expiry`] rewrites them as
115+
/// [`mpc_attestation::attestation::MockAttestation::with_expiry_capped_at`] rewrites them as
116116
/// expiring mocks so the normal cleanup flow can remove stale entries once the
117117
/// window elapses. An entry whose expiry is longer than (or missing) the default
118118
/// window is capped at it; a shorter existing expiry is left as-is.
@@ -141,7 +141,7 @@ fn stamp_expiry_on_legacy_mocks(tee_state: &mut TeeState, current_timestamp_seco
141141
continue;
142142
};
143143
if let VerifiedAttestation::Mock(mock) = &node_attestation.verified_attestation {
144-
let stamped = mock.clone().with_expiry(expiry_timestamp_seconds);
144+
let stamped = mock.clone().with_expiry_capped_at(expiry_timestamp_seconds);
145145
node_attestation.verified_attestation = VerifiedAttestation::Mock(stamped);
146146
}
147147
}

crates/mpc-attestation/src/attestation.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl AcceptedAttestation {
8585
}
8686

8787
/// Assembles the acceptance for a verified `Mock` attestation. Stamps a
88-
/// [`DEFAULT_EXPIRATION_DURATION_SECONDS`] expiry (via [`MockAttestation::with_expiry`]),
88+
/// [`DEFAULT_EXPIRATION_DURATION_SECONDS`] expiry (via [`MockAttestation::with_expiry_capped_at`]),
8989
/// mirroring [`AcceptedAttestation::dstack`], so a [`MockAttestation::Valid`] mock
9090
/// does not pass re-verification forever and can be cleaned up.
9191
fn mock(mock_attestation: &MockAttestation, current_timestamp_seconds: u64) -> Self {
@@ -95,7 +95,7 @@ impl AcceptedAttestation {
9595
attestation: VerifiedAttestation::Mock(
9696
mock_attestation
9797
.clone()
98-
.with_expiry(expiry_timestamp_seconds),
98+
.with_expiry_capped_at(expiry_timestamp_seconds),
9999
),
100100
advisory_ids: Vec::new(),
101101
}
@@ -157,7 +157,7 @@ impl MockAttestation {
157157
// Full alignment — override the value, or split the submitted vs stored mock
158158
// types (`ValidatedMockAttestation`) — is tracked in #4005; revisit alongside
159159
// #1639 (certificate-derived expiry).
160-
pub fn with_expiry(self, expiry_timestamp_seconds: u64) -> Self {
160+
pub fn with_expiry_capped_at(self, expiry_timestamp_seconds: u64) -> Self {
161161
match self {
162162
MockAttestation::Valid => MockAttestation::WithConstraints {
163163
mpc_docker_image_hash: None,
@@ -548,9 +548,9 @@ mod tests {
548548
use super::*;
549549

550550
#[test]
551-
fn with_expiry__should_convert_valid_to_expiring_constraints() {
551+
fn with_expiry_capped_at__should_convert_valid_to_expiring_constraints() {
552552
// Given / When
553-
let stamped = MockAttestation::Valid.with_expiry(42);
553+
let stamped = MockAttestation::Valid.with_expiry_capped_at(42);
554554

555555
// Then
556556
assert_matches::assert_matches!(
@@ -565,7 +565,7 @@ mod tests {
565565
}
566566

567567
#[test]
568-
fn with_expiry__should_fill_missing_expiry_and_keep_other_constraints() {
568+
fn with_expiry_capped_at__should_fill_missing_expiry_and_keep_other_constraints() {
569569
// Given: a constrained mock with an image-hash constraint but no expiry.
570570
let image_hash = NodeImageHash::from([7; 32]);
571571
let mock = MockAttestation::WithConstraints {
@@ -576,7 +576,7 @@ mod tests {
576576
};
577577

578578
// When
579-
let stamped = mock.with_expiry(42);
579+
let stamped = mock.with_expiry_capped_at(42);
580580

581581
// Then: the expiry is filled in and the other constraints are preserved.
582582
assert_matches::assert_matches!(
@@ -590,7 +590,7 @@ mod tests {
590590
}
591591

592592
#[test]
593-
fn with_expiry__should_cap_existing_expiry_at_the_provided_value() {
593+
fn with_expiry_capped_at__should_cap_existing_expiry_at_the_provided_value() {
594594
// Given: a mock whose expiry is longer than the contract cap.
595595
let mock = MockAttestation::WithConstraints {
596596
mpc_docker_image_hash: None,
@@ -600,7 +600,7 @@ mod tests {
600600
};
601601

602602
// When
603-
let stamped = mock.with_expiry(42);
603+
let stamped = mock.with_expiry_capped_at(42);
604604

605605
// Then: it is capped at the contract-provided value (a caller cannot extend it).
606606
assert_matches::assert_matches!(
@@ -613,7 +613,7 @@ mod tests {
613613
}
614614

615615
#[test]
616-
fn with_expiry__should_keep_a_shorter_existing_expiry() {
616+
fn with_expiry_capped_at__should_keep_a_shorter_existing_expiry() {
617617
// Given: a mock whose expiry is already shorter than the cap.
618618
let mock = MockAttestation::WithConstraints {
619619
mpc_docker_image_hash: None,
@@ -623,7 +623,7 @@ mod tests {
623623
};
624624

625625
// When
626-
let stamped = mock.with_expiry(42);
626+
let stamped = mock.with_expiry_capped_at(42);
627627

628628
// Then: the shorter expiry is left as-is (capping only lowers, never raises).
629629
assert_matches::assert_matches!(
@@ -636,9 +636,9 @@ mod tests {
636636
}
637637

638638
#[test]
639-
fn with_expiry__should_leave_invalid_unchanged() {
639+
fn with_expiry_capped_at__should_leave_invalid_unchanged() {
640640
// Given / When
641-
let stamped = MockAttestation::Invalid.with_expiry(42);
641+
let stamped = MockAttestation::Invalid.with_expiry_capped_at(42);
642642

643643
// Then
644644
assert_matches::assert_matches!(stamped, MockAttestation::Invalid);

0 commit comments

Comments
 (0)