Skip to content

Commit 9baed47

Browse files
authored
chore: Add fmt and tests, add rustfmt config (#71)
1 parent 62ccfa9 commit 9baed47

312 files changed

Lines changed: 5946 additions & 8315 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/tests.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,29 @@ jobs:
2626
- uses: dsherret/rust-toolchain-file@v1
2727
- uses: Swatinem/rust-cache@v2
2828
- run: cargo clippy --all-targets --all-features -- -D clippy::correctness
29+
30+
fmt:
31+
name: rustfmt
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
# rustfmt.toml uses nightly-only options (imports_granularity), so check with nightly.
36+
- uses: dtolnay/rust-toolchain@nightly
37+
with:
38+
components: rustfmt
39+
- run: cargo +nightly fmt --all -- --check
40+
41+
test:
42+
name: Test
43+
runs-on: ubuntu-latest
44+
if: github.event_name == 'push' || !github.event.pull_request.draft
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
lfs: true
49+
- uses: dsherret/rust-toolchain-file@v1
50+
- uses: Swatinem/rust-cache@v2
51+
- name: Fetch LFS files
52+
run: git lfs fetch --all && git lfs checkout
53+
- name: Run tests
54+
run: cargo test --all-features --jobs 2

crates/archive/src/archive.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
use crate::cli::{Cli, NetworkKind};
2-
use crate::fs::create_fs;
3-
use crate::ingest::ingest_from_service;
4-
use crate::layout::Layout;
5-
use crate::metrics;
6-
use crate::proc::Proc;
7-
use crate::server::run_server;
8-
use crate::writer::Writer;
1+
use std::time::Duration;
2+
93
use anyhow::{ensure, Context};
104
use prometheus_client::registry::Registry;
11-
use sqd_data::bitcoin::tables::BitcoinChunkBuilder;
12-
use sqd_data::evm::tables::EvmChunkBuilder;
13-
use sqd_data::hyperliquid_fills::tables::HyperliquidFillsChunkBuilder;
14-
use sqd_data::hyperliquid_replica_cmds::tables::HyperliquidReplicaCmdsChunkBuilder;
15-
use sqd_data::solana::tables::SolanaChunkBuilder;
16-
use sqd_data::tron::tables::TronChunkBuilder;
5+
use sqd_data::{
6+
bitcoin::tables::BitcoinChunkBuilder, evm::tables::EvmChunkBuilder,
7+
hyperliquid_fills::tables::HyperliquidFillsChunkBuilder,
8+
hyperliquid_replica_cmds::tables::HyperliquidReplicaCmdsChunkBuilder, solana::tables::SolanaChunkBuilder,
9+
tron::tables::TronChunkBuilder
10+
};
1711
use sqd_primitives::BlockNumber;
18-
use std::time::Duration;
1912

13+
use crate::{
14+
cli::{Cli, NetworkKind},
15+
fs::create_fs,
16+
ingest::ingest_from_service,
17+
layout::Layout,
18+
metrics,
19+
proc::Proc,
20+
server::run_server,
21+
writer::Writer
22+
};
2023

2124
pub async fn run(args: Cli) -> anyhow::Result<()> {
2225
ensure!(
@@ -27,12 +30,9 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
2730
let fs = create_fs(&args.dest).await?;
2831
let layout = Layout::new(fs.clone());
2932

30-
let chunk_tracker = layout.create_chunk_tracker(
31-
&chunk_check,
32-
args.top_dir_size,
33-
args.first_block,
34-
args.last_block
35-
).await?;
33+
let chunk_tracker = layout
34+
.create_chunk_tracker(&chunk_check, args.top_dir_size, args.first_block, args.last_block)
35+
.await?;
3636

3737
if let Some(last_block) = args.last_block {
3838
if chunk_tracker.next_block() > last_block {
@@ -78,32 +78,31 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
7878
let attach_idx_field = args.attach_idx_field;
7979
let write_task = tokio::spawn(async move {
8080
let mut writer = Writer::new(fs, chunk_receiver, attach_idx_field);
81-
writer.start().await
81+
writer.start().await
8282
});
83-
83+
8484
match write_task.await.context("write task panicked") {
8585
Ok(Ok(_)) => {
8686
proc_task.await.context("processing task panicked")??;
87-
},
87+
}
8888
Ok(Err(err)) => {
8989
proc_task.abort();
90-
return Err(err)
91-
},
90+
return Err(err);
91+
}
9292
Err(err) => {
9393
proc_task.abort();
94-
return Err(err)
94+
return Err(err);
9595
}
9696
}
9797

9898
Ok(())
9999
}
100100

101-
102101
fn chunk_check(filelist: &[String]) -> bool {
103102
for file in filelist {
104103
if file.starts_with("blocks.parquet") {
105104
return true;
106105
}
107106
}
108107
false
109-
}
108+
}

crates/archive/src/chunk_writer.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
use sqd_data_core::{BlockChunkBuilder, ChunkProcessor, PreparedChunk};
22
use sqd_dataset::DatasetDescriptionRef;
33

4-
54
pub struct ChunkWriter<B> {
65
chunk_builder: B,
76
processor: ChunkProcessor,
8-
memory_threshold: usize,
7+
memory_threshold: usize
98
}
109

11-
1210
impl<B: BlockChunkBuilder> ChunkWriter<B> {
1311
pub fn new(chunk_builder: B) -> anyhow::Result<Self> {
1412
Ok(Self {
1513
processor: chunk_builder.new_chunk_processor()?,
1614
chunk_builder,
17-
memory_threshold: 40 * 1024 * 1024,
15+
memory_threshold: 40 * 1024 * 1024
1816
})
1917
}
2018

@@ -52,4 +50,4 @@ impl<B: BlockChunkBuilder> ChunkWriter<B> {
5250
let new_processor = self.chunk_builder.new_chunk_processor()?;
5351
std::mem::replace(&mut self.processor, new_processor).finish()
5452
}
55-
}
53+
}

crates/archive/src/cli.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use clap::{value_parser, Parser, ValueEnum};
22
use sqd_primitives::BlockNumber;
33
use url::Url;
44

5-
65
#[derive(ValueEnum, Clone, Debug)]
76
pub enum NetworkKind {
87
Bitcoin,
@@ -13,7 +12,6 @@ pub enum NetworkKind {
1312
Tron
1413
}
1514

16-
1715
#[derive(Parser, Debug)]
1816
#[command(version, about, long_about = None)]
1917
pub struct Cli {
@@ -67,5 +65,5 @@ pub struct Cli {
6765

6866
/// Whether to attach an index field to each record
6967
#[arg(long)]
70-
pub attach_idx_field: bool,
68+
pub attach_idx_field: bool
7169
}

crates/archive/src/fs/local.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
use crate::fs::{FSRef, Fs};
1+
use std::{
2+
path::{Path, PathBuf},
3+
sync::Arc
4+
};
5+
26
use async_trait::async_trait;
3-
use std::path::{Path, PathBuf};
4-
use std::sync::Arc;
57

8+
use crate::fs::{FSRef, Fs};
69

710
pub struct LocalFs {
8-
root: PathBuf,
11+
root: PathBuf
912
}
1013

11-
1214
impl LocalFs {
1315
pub fn new(root: impl Into<PathBuf>) -> LocalFs {
1416
Self { root: root.into() }
1517
}
1618
}
1719

18-
1920
#[async_trait]
2021
impl Fs for LocalFs {
2122
fn cd(&self, path: &str) -> FSRef {
22-
Arc::new(Self::new(
23-
self.root.join(path)
24-
))
23+
Arc::new(Self::new(self.root.join(path)))
2524
}
2625

2726
async fn ls(&self) -> anyhow::Result<Vec<String>> {
@@ -57,4 +56,4 @@ impl Fs for LocalFs {
5756
}
5857
Ok(())
5958
}
60-
}
59+
}

crates/archive/src/fs/mod.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
1-
use crate::fs::local::LocalFs;
2-
use crate::fs::s3::S3Fs;
1+
use std::{path::Path, sync::Arc};
2+
33
use anyhow::{anyhow, bail, ensure};
44
use async_trait::async_trait;
5-
use std::path::Path;
6-
use std::sync::Arc;
75
use url::Url;
86

7+
use crate::fs::{local::LocalFs, s3::S3Fs};
98

109
pub mod local;
1110
pub mod s3;
1211

13-
1412
pub type FSRef = Arc<dyn Fs + Sync + Send>;
1513

16-
1714
#[async_trait]
1815
pub trait Fs {
1916
fn cd(&self, path: &str) -> FSRef;
20-
17+
2118
async fn ls(&self) -> anyhow::Result<Vec<String>>;
2219

2320
async fn move_local(&self, local_src: &Path, dest: &str) -> anyhow::Result<()>;
24-
21+
2522
async fn delete(&self, path: &str) -> anyhow::Result<()>;
2623
}
2724

28-
2925
pub async fn create_fs(url: &str) -> anyhow::Result<FSRef> {
3026
match Url::parse(url) {
3127
Ok(u) => {
3228
if u.scheme() == "s3" {
3329
ensure!(!u.cannot_be_a_base(), "invalid s3 url - {}", url);
3430

35-
let bucket = u.host_str().ok_or_else(|| {
36-
anyhow!("bucket is missing in {}", url)
37-
})?;
31+
let bucket = u.host_str().ok_or_else(|| anyhow!("bucket is missing in {}", url))?;
3832

3933
let mut config_loader = aws_config::from_env();
4034
if let Ok(s3_endpoint) = std::env::var("AWS_S3_ENDPOINT") {
4135
config_loader = config_loader.endpoint_url(s3_endpoint);
4236
}
4337
let config = config_loader.load().await;
4438
let s3_client = aws_sdk_s3::Client::new(&config);
45-
39+
4640
let fs = S3Fs::new(s3_client, bucket.to_string()).cd(u.path());
4741
Ok(fs)
4842
} else {

0 commit comments

Comments
 (0)