Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Sep 5, 2024
1 parent 580a9ea commit 83ef772
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions utils/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ alloy-sol-types.workspace = true
op-succinct-client-utils.workspace = true
rkyv.workspace = true
kona-host.workspace = true
kona-preimage.workspace = true
sp1-sdk.workspace = true
anyhow.workspace = true
cargo_metadata.workspace = true
Expand Down
8 changes: 7 additions & 1 deletion utils/host/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloy_primitives::hex;
use alloy_primitives::{hex, keccak256};
use op_succinct_client_utils::BytesHasherBuilder;
use std::{collections::HashMap, fs, io::Read, path::PathBuf};
use kona_preimage::{HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient};

pub fn load_kv_store(data_dir: &PathBuf) -> HashMap<[u8; 32], Vec<u8>, BytesHasherBuilder> {
let capacity = get_file_count(data_dir);
Expand All @@ -13,15 +14,20 @@ pub fn load_kv_store(data_dir: &PathBuf) -> HashMap<[u8; 32], Vec<u8>, BytesHash
if path.is_file() {
// Extract the file name
let file_name = path.file_stem().unwrap().to_str().unwrap();
println!("File name: {:?}", file_name);

// Convert the file name to PreimageKey
if let Ok(key) = hex::decode(file_name) {
// Hash the key with SHA256.
let key = PreimageKey::new(keccak256(&key).into(), PreimageKeyType::Keccak256);

// Read the file contents
let mut file = fs::File::open(path).expect("Failed to open file");
let mut contents = Vec::new();
file.read_to_end(&mut contents).expect("Failed to read file");

// Insert the key-value pair into the cache
println!("Inserting key: {:?}", key);
cache.insert(key.try_into().unwrap(), contents);
}
}
Expand Down

0 comments on commit 83ef772

Please sign in to comment.