Skip to content

Commit cdf570e

Browse files
committed
Add option to disable deduplication checks
Add an option to the configuration to disable the deduplication cache, which is useful for running tests and benchmarks against a log.
1 parent e367275 commit cdf570e

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

crates/ct_worker/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
],
1414
"description": "Log verbosity."
1515
},
16+
"disable_dedup": {
17+
"type": "boolean",
18+
"default": false,
19+
"description": "Disable checking the deduplication cache for add-(pre-)chain requests (e.g., for tests or benchmarks)."
20+
},
1621
"logs": {
1722
"type": "object",
1823
"description": "Dictionary CT log shard names to configurations.",

crates/ct_worker/config/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub struct TemporalInterval {
1515
#[derive(Deserialize, Debug)]
1616
pub struct AppConfig {
1717
pub logging_level: Option<String>,
18+
#[serde(default)]
19+
pub disable_dedup: bool,
1820
pub logs: HashMap<String, LogParams>,
1921
}
2022

crates/ct_worker/src/ctlog.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use crate::{
2222
metrics::{millis_diff_as_secs, AsF64, Metrics},
2323
util::now_millis,
24-
CacheRead, CacheWrite, LockBackend, LookupKey, ObjectBackend, SequenceMetadata,
24+
CacheRead, CacheWrite, LockBackend, LookupKey, ObjectBackend, SequenceMetadata, CONFIG,
2525
};
2626
use anyhow::{anyhow, bail};
2727
use ed25519_dalek::SigningKey as Ed25519SigningKey;
@@ -444,7 +444,10 @@ pub(crate) fn add_leaf_to_pool(
444444
) -> AddLeafResult {
445445
let hash = entry.lookup_key();
446446

447-
if let Some(result) = state.check(&hash) {
447+
if CONFIG.disable_dedup {
448+
// Bypass deduplication and rate limit checks.
449+
state.add(hash, entry)
450+
} else if let Some(result) = state.check(&hash) {
448451
// Entry is already pending or being sequenced.
449452
result
450453
} else if let Some(v) = cache.get_entry(&hash) {

crates/ct_worker/src/frontend_worker.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,23 @@ async fn add_chain_or_pre_chain(
202202

203203
// Check if entry is cached and return right away if so.
204204
let kv = load_cache_kv(env, name)?;
205-
if let Some((leaf_index, timestamp)) = kv
206-
.get(&BASE64_STANDARD.encode(lookup_key))
207-
.bytes_with_metadata::<SequenceMetadata>()
208-
.await?
209-
.1
210-
{
211-
debug!("{name}: Entry is cached");
212-
let entry = LogEntry {
213-
inner: pending_entry,
214-
leaf_index,
215-
timestamp,
216-
};
217-
let sct = static_ct_api::signed_certificate_timestamp(signing_key, &entry)
218-
.map_err(|e| e.to_string())?;
219-
return Response::from_json(&sct);
205+
if !CONFIG.disable_dedup {
206+
if let Some((leaf_index, timestamp)) = kv
207+
.get(&BASE64_STANDARD.encode(lookup_key))
208+
.bytes_with_metadata::<SequenceMetadata>()
209+
.await?
210+
.1
211+
{
212+
debug!("{name}: Entry is cached");
213+
let entry = LogEntry {
214+
inner: pending_entry,
215+
leaf_index,
216+
timestamp,
217+
};
218+
let sct = static_ct_api::signed_certificate_timestamp(signing_key, &entry)
219+
.map_err(|e| e.to_string())?;
220+
return Response::from_json(&sct);
221+
}
220222
}
221223

222224
// Entry is not cached, so we need to sequence it.

0 commit comments

Comments
 (0)