Skip to content

Commit a497171

Browse files
authored
feat(raiko): config redis ttl from cmdline & default 1 hour (#406)
* feat(raiko): config redis ttl from cmdline Signed-off-by: smtmfft <[email protected]> * fix CI Signed-off-by: smtmfft <[email protected]> --------- Signed-off-by: smtmfft <[email protected]>
1 parent 831efbe commit a497171

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ mod tests {
373373
height - 100
374374
}
375375

376+
#[ignore = "public node does not support long distance MPT proof query."]
376377
#[tokio::test(flavor = "multi_thread")]
377378
async fn test_prove_block_ethereum() {
378379
let proof_type = get_proof_type_from_env();

docker/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ services:
167167
- SKIP_SIMULATION=true
168168
- SP1_VERIFIER_RPC_URL=${SP1_VERIFIER_RPC_URL}
169169
- SP1_VERIFIER_ADDRESS=${SP1_VERIFIER_ADDRESS}
170+
- PROVER_NETWORK_RPC=${PROVER_NETWORK_RPC}
170171
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
171172
depends_on:
172173
- redis

host/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub struct Opts {
8484

8585
#[arg(long, require_equals = true, default_value = "redis://localhost:6379")]
8686
pub redis_url: String,
87+
88+
#[arg(long, require_equals = true, default_value = "3600")]
89+
pub redis_ttl: u64,
8790
}
8891

8992
impl Opts {
@@ -132,6 +135,7 @@ impl From<Opts> for TaskManagerOpts {
132135
sqlite_file: val.sqlite_file,
133136
max_db_size: val.max_db_size,
134137
redis_url: val.redis_url.to_string(),
138+
redis_ttl: val.redis_ttl,
135139
}
136140
}
137141
}
@@ -142,6 +146,7 @@ impl From<&Opts> for TaskManagerOpts {
142146
sqlite_file: val.sqlite_file.clone(),
143147
max_db_size: val.max_db_size,
144148
redis_url: val.redis_url.to_string(),
149+
redis_ttl: val.redis_ttl,
145150
}
146151
}
147152
}

taskdb/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub struct TaskManagerOpts {
233233
pub sqlite_file: PathBuf,
234234
pub max_db_size: usize,
235235
pub redis_url: String,
236+
pub redis_ttl: u64,
236237
}
237238

238239
#[async_trait::async_trait]
@@ -445,6 +446,7 @@ mod test {
445446
sqlite_file: sqlite_file.to_path_buf(),
446447
max_db_size: 1024 * 1024,
447448
redis_url: "redis://localhost:6379".to_string(),
449+
redis_ttl: 3600,
448450
};
449451
let mut task_manager = get_task_manager(&opts);
450452

taskdb/src/redis_db.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::{
2828

2929
pub struct RedisTaskDb {
3030
conn: Connection,
31+
config: RedisConfig,
3132
}
3233

3334
pub struct RedisTaskManager {
@@ -129,14 +130,18 @@ impl ToRedisArgs for TaskIdDescriptor {
129130
}
130131
}
131132

132-
// redis key ttl
133-
const TTL_SECS: u64 = 2 * 24 * 3600; // 2 days
133+
#[derive(Debug, Clone, Default)]
134+
pub struct RedisConfig {
135+
url: String,
136+
ttl: u64,
137+
}
134138

135139
impl RedisTaskDb {
136-
fn new(url: &str) -> RedisDbResult<Self> {
140+
fn new(config: RedisConfig) -> RedisDbResult<Self> {
141+
let url = config.url.clone();
137142
let client = Client::open(url).map_err(RedisDbError::RedisDb)?;
138143
let conn = client.get_connection().map_err(RedisDbError::RedisDb)?;
139-
Ok(RedisTaskDb { conn })
144+
Ok(RedisTaskDb { conn, config })
140145
}
141146

142147
fn insert_proof_task(
@@ -161,7 +166,7 @@ impl RedisTaskDb {
161166
V: ToRedisArgs,
162167
{
163168
self.conn
164-
.set_ex(key, value, TTL_SECS)
169+
.set_ex(key, value, self.config.ttl)
165170
.map_err(RedisDbError::RedisDb)?;
166171
Ok(())
167172
}
@@ -272,7 +277,7 @@ impl RedisTaskDb {
272277
}
273278

274279
fn update_status_redis(&mut self, k: &String, v: &String) -> RedisDbResult<()> {
275-
self.conn.set_ex(k, v, TTL_SECS)?;
280+
self.conn.set_ex(k, v, self.config.ttl)?;
276281
Ok(())
277282
}
278283
}
@@ -553,7 +558,11 @@ impl TaskManager for RedisTaskManager {
553558
INIT.call_once(|| {
554559
unsafe {
555560
CONN = Some(Arc::new(Mutex::new({
556-
let db = RedisTaskDb::new(&opts.redis_url).unwrap();
561+
let db = RedisTaskDb::new(RedisConfig {
562+
url: opts.redis_url.clone(),
563+
ttl: opts.redis_ttl.clone(),
564+
})
565+
.unwrap();
557566
db
558567
})))
559568
};

taskdb/tests/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod tests {
6868
sqlite_file: file,
6969
max_db_size: 1_000_000,
7070
redis_url: env::var("REDIS_URL").unwrap_or_default(),
71+
redis_ttl: 3600,
7172
});
7273

7374
let (chain_id, blockhash, request) =
@@ -106,6 +107,7 @@ mod tests {
106107
sqlite_file: file,
107108
max_db_size: 1_000_000,
108109
redis_url: env::var("REDIS_URL").unwrap_or_default(),
110+
redis_ttl: 3600,
109111
});
110112

111113
let mut rng = ChaCha8Rng::seed_from_u64(123);

0 commit comments

Comments
 (0)