Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(raiko): config redis ttl from cmdline & default 1 hour #406

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ mod tests {
height - 100
}

#[ignore = "public node does not support long distance MPT proof query."]
#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_ethereum() {
let proof_type = get_proof_type_from_env();
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ services:
- SKIP_SIMULATION=true
- SP1_VERIFIER_RPC_URL=${SP1_VERIFIER_RPC_URL}
- SP1_VERIFIER_ADDRESS=${SP1_VERIFIER_ADDRESS}
- PROVER_NETWORK_RPC=${PROVER_NETWORK_RPC}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
depends_on:
- redis
Expand Down
5 changes: 5 additions & 0 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ pub struct Opts {

#[arg(long, require_equals = true, default_value = "redis://localhost:6379")]
pub redis_url: String,

#[arg(long, require_equals = true, default_value = "3600")]
pub redis_ttl: u64,
}

impl Opts {
Expand Down Expand Up @@ -132,6 +135,7 @@ impl From<Opts> for TaskManagerOpts {
sqlite_file: val.sqlite_file,
max_db_size: val.max_db_size,
redis_url: val.redis_url.to_string(),
redis_ttl: val.redis_ttl,
}
}
}
Expand All @@ -142,6 +146,7 @@ impl From<&Opts> for TaskManagerOpts {
sqlite_file: val.sqlite_file.clone(),
max_db_size: val.max_db_size,
redis_url: val.redis_url.to_string(),
redis_ttl: val.redis_ttl,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions taskdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub struct TaskManagerOpts {
pub sqlite_file: PathBuf,
pub max_db_size: usize,
pub redis_url: String,
pub redis_ttl: u64,
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -445,6 +446,7 @@ mod test {
sqlite_file: sqlite_file.to_path_buf(),
max_db_size: 1024 * 1024,
redis_url: "redis://localhost:6379".to_string(),
redis_ttl: 3600,
};
let mut task_manager = get_task_manager(&opts);

Expand Down
23 changes: 16 additions & 7 deletions taskdb/src/redis_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{

pub struct RedisTaskDb {
conn: Connection,
config: RedisConfig,
}

pub struct RedisTaskManager {
Expand Down Expand Up @@ -129,14 +130,18 @@ impl ToRedisArgs for TaskIdDescriptor {
}
}

// redis key ttl
const TTL_SECS: u64 = 2 * 24 * 3600; // 2 days
#[derive(Debug, Clone, Default)]
pub struct RedisConfig {
url: String,
ttl: u64,
}

impl RedisTaskDb {
fn new(url: &str) -> RedisDbResult<Self> {
fn new(config: RedisConfig) -> RedisDbResult<Self> {
let url = config.url.clone();
let client = Client::open(url).map_err(RedisDbError::RedisDb)?;
let conn = client.get_connection().map_err(RedisDbError::RedisDb)?;
Ok(RedisTaskDb { conn })
Ok(RedisTaskDb { conn, config })
}

fn insert_proof_task(
Expand All @@ -161,7 +166,7 @@ impl RedisTaskDb {
V: ToRedisArgs,
{
self.conn
.set_ex(key, value, TTL_SECS)
.set_ex(key, value, self.config.ttl)
.map_err(RedisDbError::RedisDb)?;
Ok(())
}
Expand Down Expand Up @@ -272,7 +277,7 @@ impl RedisTaskDb {
}

fn update_status_redis(&mut self, k: &String, v: &String) -> RedisDbResult<()> {
self.conn.set_ex(k, v, TTL_SECS)?;
self.conn.set_ex(k, v, self.config.ttl)?;
Ok(())
}
}
Expand Down Expand Up @@ -553,7 +558,11 @@ impl TaskManager for RedisTaskManager {
INIT.call_once(|| {
unsafe {
CONN = Some(Arc::new(Mutex::new({
let db = RedisTaskDb::new(&opts.redis_url).unwrap();
let db = RedisTaskDb::new(RedisConfig {
url: opts.redis_url.clone(),
ttl: opts.redis_ttl.clone(),
})
.unwrap();
db
})))
};
Expand Down
2 changes: 2 additions & 0 deletions taskdb/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod tests {
sqlite_file: file,
max_db_size: 1_000_000,
redis_url: env::var("REDIS_URL").unwrap_or_default(),
redis_ttl: 3600,
});

let (chain_id, blockhash, request) =
Expand Down Expand Up @@ -106,6 +107,7 @@ mod tests {
sqlite_file: file,
max_db_size: 1_000_000,
redis_url: env::var("REDIS_URL").unwrap_or_default(),
redis_ttl: 3600,
});

let mut rng = ChaCha8Rng::seed_from_u64(123);
Expand Down
Loading