Skip to content

Commit 95b2ef7

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 95b2ef7

File tree

8 files changed

+24
-52
lines changed

8 files changed

+24
-52
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/config.bootstrap-mtca.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"description": "Cloudflare bootstrap MTCA shard 1",
66
"log_id": "13335.1",
77
"submission_url": "https://bootstrap-mtca.cloudflareresearch.com/logs/shard1/",
8-
"monitoring_url": "https://bootstrap-mtca-shard1.cloudflareresearch.com",
9-
"enable_dedup": false
8+
"monitoring_url": "https://bootstrap-mtca-shard1.cloudflareresearch.com"
109
}
1110
}
1211
}

crates/mtc_worker/config.dev.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
"description": "MTCA Dev1",
66
"log_id": "13335.1",
77
"submission_url": "http://localhost:8787/logs/dev1/",
8-
"location_hint": "enam",
9-
"enable_dedup": false
8+
"location_hint": "enam"
109
},
1110
"dev2": {
1211
"description": "MTCA Dev2",
1312
"log_id": "13335.2",
1413
"submission_url": "http://localhost:8787/logs/dev2/",
1514
"location_hint": "enam",
16-
"enable_dedup": false,
1715
"max_certificate_lifetime_secs": 100,
1816
"landmark_interval_secs": 10
1917
}
2018
}
21-
}
19+
}

crates/mtc_worker/config.schema.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@
9090
"default": 256,
9191
"description": "The maximum number of entries per batch."
9292
},
93-
"enable_dedup": {
94-
"type": "boolean",
95-
"default": true,
96-
"description": "Enables checking the deduplication cache for add-(pre-)chain requests. Can be disabled for tests and benchmarks. If disabled, `kv_namespaces` can be omitted from `wrangler.jsonc`."
97-
},
9893
"clean_interval_secs": {
9994
"type": "integer",
10095
"minimum": 1,
@@ -113,4 +108,4 @@
113108
"required": [
114109
"logs"
115110
]
116-
}
111+
}

crates/mtc_worker/config/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ pub struct LogParams {
3434
pub batch_timeout_millis: u64,
3535
#[serde(default = "default_usize::<100>")]
3636
pub max_batch_entries: usize,
37-
#[serde(default = "default_bool::<true>")]
38-
pub enable_dedup: bool,
3937
#[serde(default = "default_u64::<60>")]
4038
pub clean_interval_secs: u64,
4139
}
4240

43-
fn default_bool<const V: bool>() -> bool {
44-
V
45-
}
4641
fn default_u8<const V: u8>() -> u8 {
4742
V
4843
}

crates/mtc_worker/src/batcher_do.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl DurableObject for Batcher {
2222
name: name.to_string(),
2323
max_batch_entries: params.max_batch_entries,
2424
batch_timeout_millis: params.batch_timeout_millis,
25-
enable_dedup: params.enable_dedup,
25+
enable_dedup: false, // deduplication is not currently supported
2626
location_hint: params.location_hint.clone(),
2727
};
2828
Batcher(GenericBatcher::new(env, config))

crates/mtc_worker/src/frontend_worker.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ 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,
16+
load_public_bucket,
1717
log_ops::{
1818
prove_subtree_consistency, prove_subtree_inclusion, read_leaf, ProofError, CHECKPOINT_KEY,
1919
},
20-
put_cache_entry_metadata, serialize,
20+
serialize,
2121
util::now_millis,
2222
ObjectBackend, ObjectBucket, ENTRY_ENDPOINT, METRICS_ENDPOINT,
2323
};
@@ -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,32 +345,18 @@ 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}");
352352
return Response::error("Bad request", 400);
353353
}
354354
};
355355

356-
// Retrieve the sequenced entry for this pending log entry by first checking the
357-
// deduplication cache and then sending a request to the DO to sequence the entry.
356+
// Retrieve the sequenced entry for this pending log entry by sending a request to the DO to
357+
// 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-
372-
// Entry is not cached, so we need to sequence it.
373-
374360
// First persist issuers. Use a block so memory is deallocated sooner.
375361
{
376362
let public_bucket = ObjectBucket::new(load_public_bucket(env, name)?);
@@ -425,19 +411,11 @@ async fn add_entry(mut req: Request, env: &Env, name: &str) -> Result<Response>
425411
return Ok(response);
426412
}
427413
let metadata = deserialize::<SequenceMetadata>(&response.bytes().await?)?;
428-
if params.num_batchers == 0 && params.enable_dedup {
429-
// Write sequenced entry to the long-term deduplication cache in Workers
430-
// KV as there are no batchers configured to do it for us.
431-
if put_cache_entry_metadata(&load_cache_kv(env, name)?, &pending_entry, metadata)
432-
.await
433-
.is_err()
434-
{
435-
log::warn!("{name}: Failed to write entry to deduplication cache");
436-
}
437-
}
438414
Response::from_json(&AddEntryResponse {
439415
leaf_index: metadata.0,
440416
timestamp: metadata.1,
417+
not_before: validity.not_before.to_unix_duration().as_secs(),
418+
not_after: validity.not_after.to_unix_duration().as_secs(),
441419
})
442420
}
443421

crates/mtc_worker/src/sequencer_do.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl DurableObject for Sequencer {
3535
checkpoint_extension: Box::new(|_| vec![]), // no checkpoint extension for MTC
3636
sequence_interval: Duration::from_millis(params.sequence_interval_millis),
3737
max_sequence_skips: params.max_sequence_skips,
38-
enable_dedup: params.enable_dedup,
38+
enable_dedup: false, // deduplication is not currently supported
3939
sequence_skip_threshold_millis: params.sequence_skip_threshold_millis,
4040
location_hint: params.location_hint.clone(),
4141
checkpoint_callback: checkpoint_callback(&env, name),

0 commit comments

Comments
 (0)