Skip to content

Feat: Build & Lint CI #12

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

Merged
merged 5 commits into from
Mar 27, 2023
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
47 changes: 47 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Rust

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt, clippy
override: true

- name: cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check

- name: cargo clippy
uses: actions-rs/clippy-check@v1
with:
args: --all --all-features -- -D warnings
token: ${{ secrets.GITHUB_TOKEN }}

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ target/

.env

logs/
logs/

.DS_Store
2 changes: 1 addition & 1 deletion src/db/blob_db_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::types::{Blob, BlockData, IndexerMetadata, StdError, TransactionData};
pub trait DBManager {
type Options;

async fn new(connection_uri: &String, db_name: &String) -> Result<Self, StdError>
async fn new(connection_uri: &str, db_name: &str) -> Result<Self, StdError>
where
Self: Sized;

Expand Down
2 changes: 1 addition & 1 deletion src/db/mongodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const INDEXER_METADATA_ID: &str = "indexer_metadata";
impl DBManager for MongoDBManager {
type Options = MongoDBManagerOptions;

async fn new(connection_uri: &String, db_name: &String) -> Result<Self, StdError>
async fn new(connection_uri: &str, db_name: &str) -> Result<Self, StdError>
where
Self: Sized,
{
Expand Down
10 changes: 3 additions & 7 deletions src/db/mongodb/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ impl TryFrom<&BlockData<'_>> for BlockDocument {
number,
slot: block_data.slot,
timestamp: block.timestamp.as_u64(),
transactions: block_data
.tx_to_versioned_hashes
.keys()
.map(|hash| hash.clone())
.collect(),
transactions: block_data.tx_to_versioned_hashes.keys().copied().collect(),
})
}
}
Expand Down Expand Up @@ -90,8 +86,8 @@ impl TryFrom<&TransactionData<'_>> for TransactionDocument {
from: tx.from,
to,
value: tx.value,
block_hash: block_hash,
block_number: block_number,
block_hash,
block_number,
blob_versioned_hashes: tx_data.blob_versioned_hashes.clone(),
})
}
Expand Down
20 changes: 8 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,17 @@ async fn main() -> Result<(), StdError> {
};

loop {
match context.beacon_api.get_block(None).await? {
Some(latest_beacon_block) => {
let latest_slot: u32 = latest_beacon_block.slot.parse()?;
if let Some(latest_beacon_block) = context.beacon_api.get_block(None).await? {
let latest_slot: u32 = latest_beacon_block.slot.parse()?;

if current_slot < latest_slot {
slot_processor
.process_slots(current_slot, latest_slot)
.await;
if current_slot < latest_slot {
slot_processor
.process_slots(current_slot, latest_slot)
.await;

current_slot = latest_slot;
}
current_slot = latest_slot;
}
_ => (),
};

}
thread::sleep(Duration::from_secs(1));
}
}
6 changes: 3 additions & 3 deletions src/slot_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a> SlotProcessor<'a> {
panic!();
};

current_slot = current_slot + 1;
current_slot += 1;
}

self.save_slot(current_slot).await
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<'a> SlotProcessor<'a> {

let blobs = match beacon_api.get_blobs_sidecar(slot).await? {
Some(blobs_sidecar) => {
if blobs_sidecar.blobs.len() == 0 {
if blobs_sidecar.blobs.is_empty() {
info!("[Slot {}] Skipping as blobs sidecar is empty", slot);

return Ok(());
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'a> SlotProcessor<'a> {
commitment,
data: blob,
versioned_hash,
tx_hash: tx_hash.clone(),
tx_hash: *tx_hash,
},
Some(&mut self.db_options),
)
Expand Down
1 change: 1 addition & 0 deletions src/utils/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Environment {
#[serde(default = "default_beacon_node_rpc")]
pub beacon_node_rpc: String,
#[serde(default = "default_logger")]
#[allow(dead_code)] // Temporal until we move to tracing
logger: String,
#[serde(default = "default_mode")]
pub mode: String,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::types::StdError;
const BLOB_COMMITMENT_VERSION_KZG: u8 = 0x01;

pub fn sha256(value: &str) -> Result<H256, StdError> {
let value_without_prefix = if value.starts_with("0x") {
&value[2..]
let value_without_prefix = if let Some(value_without_prefix) = value.strip_prefix("0x") {
value_without_prefix
} else {
value
};
Expand All @@ -24,8 +24,8 @@ pub fn sha256(value: &str) -> Result<H256, StdError> {
Ok(H256::from_slice(&result))
}

pub fn calculate_versioned_hash(commitment: &String) -> Result<H256, StdError> {
let hashed_commitment = sha256(&commitment)?;
pub fn calculate_versioned_hash(commitment: &str) -> Result<H256, StdError> {
let hashed_commitment = sha256(commitment)?;

// Replace first byte with the blob commitment version byte
let hashed_commitment = &mut hashed_commitment.as_bytes()[1..].to_vec();
Expand Down