Skip to content

Commit cf38de6

Browse files
committed
mtc_worker: Return MTC validity window on add entry
Add the MTC validity window to `AddEntryResponse`. In case the entry was cached, it would be necessary to parse the validity window from the entry itself. However, for now we don't actually want to cache MTC entries, so remove caching for now.
1 parent c891f42 commit cf38de6

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

crates/mtc_api/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,15 @@ pub struct AddEntryRequest {
119119
#[serde_as]
120120
#[derive(Serialize)]
121121
pub struct AddEntryResponse {
122+
/// The index of the entry in the log.
122123
pub leaf_index: LeafIndex,
124+
125+
/// The time at which the entry was added to the log.
123126
pub timestamp: UnixTimestamp,
127+
128+
/// The validity period of the certificate.
129+
pub not_before: UnixTimestamp,
130+
pub not_after: UnixTimestamp,
124131
}
125132

126133
/// Get-roots response. This is in the same format as the RFC 6962 get-roots
@@ -684,7 +691,7 @@ pub fn validate_chain(
684691
raw_chain: &[Vec<u8>],
685692
roots: &CertPool,
686693
issuer: RdnSequence,
687-
mut validity: Validity,
694+
validity: &mut Validity,
688695
) -> Result<(BootstrapMtcPendingLogEntry, Option<usize>), MtcError> {
689696
// We will run the ordinary chain validation on our input, but we have some post-processing we
690697
// need to do too. Namely we need to adjust the validity period of the provided bootstrap cert,
@@ -741,7 +748,7 @@ pub fn validate_chain(
741748
data: MerkleTreeCertEntry::TbsCertEntry(tbs_cert_to_log_entry(
742749
leaf.tbs_certificate,
743750
issuer,
744-
validity,
751+
*validity,
745752
)?)
746753
.encode()?,
747754
},

crates/mtc_worker/src/batcher_do.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ impl DurableObject for Batcher {
1818
.map(|(name, params)| (name.as_str(), params.num_batchers)),
1919
);
2020
let params = &CONFIG.logs[name];
21+
if params.enable_dedup {
22+
log::warn!("ignored enable_dedup: this feature is not implemented by mtc_worker");
23+
}
2124
let config = BatcherConfig {
2225
name: name.to_string(),
2326
max_batch_entries: params.max_batch_entries,
2427
batch_timeout_millis: params.batch_timeout_millis,
25-
enable_dedup: params.enable_dedup,
28+
enable_dedup: false,
2629
location_hint: params.location_hint.clone(),
2730
};
2831
Batcher(GenericBatcher::new(env, config))

crates/mtc_worker/src/frontend_worker.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use der::{
1212
Any, Encode, Tag,
1313
};
1414
use generic_log_worker::{
15-
batcher_id_from_lookup_key, deserialize, get_cached_metadata, get_durable_object_stub,
16-
init_logging, load_cache_kv, load_public_bucket,
15+
batcher_id_from_lookup_key, deserialize, get_durable_object_stub, init_logging, load_cache_kv,
16+
load_public_bucket,
1717
log_ops::{
1818
prove_subtree_consistency, prove_subtree_inclusion, read_leaf, ProofError, CHECKPOINT_KEY,
1919
},
@@ -333,7 +333,7 @@ async fn add_entry(mut req: Request, env: &Env, name: &str) -> Result<Response>
333333
)]);
334334

335335
let now = Duration::from_millis(now_millis());
336-
let validity = Validity {
336+
let mut validity = Validity {
337337
not_before: Time::UtcTime(UtcTime::from_unix_duration(now).map_err(|e| e.to_string())?),
338338
not_after: Time::UtcTime(
339339
UtcTime::from_unix_duration(
@@ -345,7 +345,7 @@ async fn add_entry(mut req: Request, env: &Env, name: &str) -> Result<Response>
345345

346346
let roots = load_roots(env, name).await?;
347347
let (pending_entry, found_root_idx) =
348-
match mtc_api::validate_chain(&req.chain, roots, issuer, validity) {
348+
match mtc_api::validate_chain(&req.chain, roots, issuer, &mut validity) {
349349
Ok(v) => v,
350350
Err(e) => {
351351
log::warn!("{name}: Bad request: {e}");
@@ -357,18 +357,6 @@ async fn add_entry(mut req: Request, env: &Env, name: &str) -> Result<Response>
357357
// deduplication cache and then sending a request to the DO to sequence the entry.
358358
let lookup_key = pending_entry.lookup_key();
359359

360-
// Check if entry is cached and return right away if so.
361-
if params.enable_dedup {
362-
if let Some(metadata) = get_cached_metadata(&load_cache_kv(env, name)?, &lookup_key).await?
363-
{
364-
log::debug!("{name}: Entry is cached");
365-
return Response::from_json(&AddEntryResponse {
366-
leaf_index: metadata.0,
367-
timestamp: metadata.1,
368-
});
369-
}
370-
}
371-
372360
// Entry is not cached, so we need to sequence it.
373361

374362
// First persist issuers. Use a block so memory is deallocated sooner.
@@ -438,6 +426,8 @@ async fn add_entry(mut req: Request, env: &Env, name: &str) -> Result<Response>
438426
Response::from_json(&AddEntryResponse {
439427
leaf_index: metadata.0,
440428
timestamp: metadata.1,
429+
not_before: validity.not_before.to_unix_duration().as_secs(),
430+
not_after: validity.not_after.to_unix_duration().as_secs(),
441431
})
442432
}
443433

0 commit comments

Comments
 (0)