Skip to content

Commit 4408b1e

Browse files
author
Ludo Galabru
committed
feat: migrate stacks scans to rocksdb
1 parent bc313fa commit 4408b1e

File tree

6 files changed

+357
-178
lines changed

6 files changed

+357
-178
lines changed

Cargo.lock

+19-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/chainhook-cli/src/archive/mod.rs

+28-22
Original file line numberDiff line numberDiff line change
@@ -195,35 +195,41 @@ pub async fn download_stacks_dataset_if_required(config: &mut Config, ctx: &Cont
195195
Ok(response) => response.bytes().await,
196196
Err(e) => Err(e),
197197
};
198-
match (local_sha_file, remote_sha_file) {
198+
let should_download = match (local_sha_file, remote_sha_file) {
199199
(Ok(local), Ok(remote_response)) => {
200-
println!("{:?}", local);
201-
println!("{:?}", remote_response);
202-
}
203-
(Ok(local), _) => {
204-
// println!("Local: {:?}", local)
200+
let cache_invalidated = remote_response.starts_with(&local[0..32]) == false;
201+
if cache_invalidated {
202+
info!(
203+
ctx.expect_logger(),
204+
"More recent Stacks archive file detected"
205+
);
206+
}
207+
cache_invalidated
205208
}
206209
(_, _) => {
207-
// We will download the latest file
208-
println!("error reading local / remote");
210+
info!(
211+
ctx.expect_logger(),
212+
"Unable to retrieve Stacks archive file locally"
213+
);
214+
true
209215
}
210-
}
211-
212-
if !tsv_file_path.exists() {
213-
info!(ctx.expect_logger(), "Downloading {}", url);
214-
match download_tsv_file(&config).await {
215-
Ok(_) => {}
216-
Err(e) => {
217-
error!(ctx.expect_logger(), "{}", e);
218-
std::process::exit(1);
219-
}
220-
}
221-
} else {
216+
};
217+
if !should_download {
222218
info!(
223219
ctx.expect_logger(),
224-
"Building in-memory chainstate from file {}",
225-
tsv_file_path.display()
220+
"Stacks archive file already up to date"
226221
);
222+
config.add_local_stacks_tsv_source(&tsv_file_path);
223+
return false;
224+
}
225+
226+
info!(ctx.expect_logger(), "Downloading {}", url);
227+
match download_tsv_file(&config).await {
228+
Ok(_) => {}
229+
Err(e) => {
230+
error!(ctx.expect_logger(), "{}", e);
231+
std::process::exit(1);
232+
}
227233
}
228234
config.add_local_stacks_tsv_source(&tsv_file_path);
229235
}

0 commit comments

Comments
 (0)