From 3ff0f986e2d1a097c14741247dc59c0f9ee75ac6 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Sat, 7 Oct 2023 07:50:52 -0300 Subject: [PATCH] fix lint --- src/bin/dolos/daemon.rs | 1 - src/bin/dolos/main.rs | 3 ++- src/serve/grpc/sync.rs | 7 ++++-- src/serve/ouroboros/mod.rs | 4 ++-- src/storage/applydb/genesis.rs | 2 +- src/storage/rolldb/mod.rs | 41 ++++++++++++---------------------- src/storage/rolldb/stream.rs | 6 ++--- src/storage/rolldb/wal.rs | 14 ++++++++++-- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/bin/dolos/daemon.rs b/src/bin/dolos/daemon.rs index 4c1fc65e..90bd6f4a 100644 --- a/src/bin/dolos/daemon.rs +++ b/src/bin/dolos/daemon.rs @@ -1,5 +1,4 @@ use std::path::Path; -use tracing::info; use dolos::{ prelude::*, diff --git a/src/bin/dolos/main.rs b/src/bin/dolos/main.rs index d1440988..542c9409 100644 --- a/src/bin/dolos/main.rs +++ b/src/bin/dolos/main.rs @@ -42,7 +42,8 @@ pub struct ApplydbConfig { #[derive(Deserialize)] pub struct GenesisFileRef { path: PathBuf, - hash: String, + // TODO: add hash of genesis for runtime verification + // hash: String, } #[derive(Deserialize)] diff --git a/src/serve/grpc/sync.rs b/src/serve/grpc/sync.rs index 255c96af..db9445f7 100644 --- a/src/serve/grpc/sync.rs +++ b/src/serve/grpc/sync.rs @@ -126,8 +126,11 @@ impl chain_sync_service_server::ChainSyncService for ChainSyncServiceImpl { &self, _request: Request, ) -> Result, tonic::Status> { - let s = crate::storage::rolldb::stream::RollStream::start_after_block(self.0.clone(), None) - .map(|(evt, block)| Ok(roll_to_tip_response(evt, &block))); + let s = crate::storage::rolldb::stream::RollStream::start_after_with_block( + self.0.clone(), + None, + ) + .map(|(evt, block)| Ok(roll_to_tip_response(evt, &block))); Ok(Response::new(Box::pin(s))) } diff --git a/src/serve/ouroboros/mod.rs b/src/serve/ouroboros/mod.rs index b3b4c6e7..3a364aad 100644 --- a/src/serve/ouroboros/mod.rs +++ b/src/serve/ouroboros/mod.rs @@ -70,10 +70,10 @@ async fn handle_blockfetch(db: RollDB, mut peer: PeerServer) -> Result<(), Error } }; - if let Some(mut iter) = db.read_chain_range(from, to).map_err(Error::storage)? { + if let Some(iter) = db.read_chain_range(from, to).map_err(Error::storage)? { blockfetch.send_start_batch().await.map_err(Error::server)?; - while let Some(point) = iter.next() { + for point in iter { let (_, hash) = point.map_err(Error::storage)?; let block_bytes = match db.get_block(hash).map_err(Error::storage)? { diff --git a/src/storage/applydb/genesis.rs b/src/storage/applydb/genesis.rs index 5a8521a2..22d87a1f 100644 --- a/src/storage/applydb/genesis.rs +++ b/src/storage/applydb/genesis.rs @@ -38,7 +38,7 @@ impl ApplyDB { &self, byron: &pallas::ledger::configs::byron::GenesisFile, ) -> Result<(), Error> { - let batch = pallas::ledger::configs::byron::genesis_utxos(&byron) + let batch = pallas::ledger::configs::byron::genesis_utxos(byron) .into_iter() .map(genesis_utxo_to_kv) .collect::, _>>()? diff --git a/src/storage/rolldb/mod.rs b/src/storage/rolldb/mod.rs index 2f6b58e9..9f2fd753 100644 --- a/src/storage/rolldb/mod.rs +++ b/src/storage/rolldb/mod.rs @@ -175,23 +175,21 @@ impl RollDB { Ok(out) } - pub fn crawl_wal_after( - &self, - seq: Option, - ) -> impl Iterator> + '_ { - let iter = match seq { - Some(seq) => { - let seq = Box::<[u8]>::from(DBInt(seq)); - let from = rocksdb::IteratorMode::From(&seq, rocksdb::Direction::Forward); - wal::WalKV::iter_entries(&self.db, from).skip(1) - } - None => { - let from = rocksdb::IteratorMode::Start; - wal::WalKV::iter_entries(&self.db, from).skip(0) - } - }; + pub fn crawl_wal_after(&self, seq: Option) -> wal::WalIterator { + if let Some(seq) = seq { + let seq = Box::<[u8]>::from(DBInt(seq)); + let from = rocksdb::IteratorMode::From(&seq, rocksdb::Direction::Forward); + let mut iter = wal::WalKV::iter_entries(&self.db, from); + + // skip current + iter.next(); - iter.map(|v| v.map(|(seq, val)| (seq.0, val.0))) + wal::WalIterator(iter) + } else { + let from = rocksdb::IteratorMode::Start; + let iter = wal::WalKV::iter_entries(&self.db, from); + wal::WalIterator(iter) + } } pub fn find_wal_seq(&self, block: Option<(BlockSlot, BlockHash)>) -> Result { @@ -348,17 +346,6 @@ impl RollDB { Ok(false) } - /// Check if a point (pair of slot and block hash) exists in the WalKV - pub fn wal_contains(&self, slot: BlockSlot, hash: &BlockHash) -> Result { - if let Some(_) = WalKV::scan_until(&self.db, rocksdb::IteratorMode::End, |v| { - v.slot() == slot && v.hash().eq(hash) - })? { - Ok(true) - } else { - Ok(false) - } - } - pub fn destroy(path: impl AsRef) -> Result<(), Error> { DB::destroy(&Options::default(), path).map_err(|_| Error::IO) } diff --git a/src/storage/rolldb/stream.rs b/src/storage/rolldb/stream.rs index d698bdd1..76c2b436 100644 --- a/src/storage/rolldb/stream.rs +++ b/src/storage/rolldb/stream.rs @@ -10,7 +10,7 @@ type ItemWithBlock = (super::wal::Value, RawBlock); pub struct RollStream; impl RollStream { - pub fn start_after_seq(db: RollDB, seq: Option) -> impl Stream { + pub fn start_after(db: RollDB, seq: Option) -> impl Stream { async_stream::stream! { let mut last_seq = seq; @@ -33,7 +33,7 @@ impl RollStream { } } - pub fn start_after_block( + pub fn start_after_with_block( db: RollDB, seq: Option, ) -> impl Stream { @@ -104,7 +104,7 @@ mod tests { } }); - let s = super::RollStream::start_after_seq(db.clone(), None); + let s = super::RollStream::start_after(db.clone(), None); pin_mut!(s); diff --git a/src/storage/rolldb/wal.rs b/src/storage/rolldb/wal.rs index 0d4f9bb9..58becf35 100644 --- a/src/storage/rolldb/wal.rs +++ b/src/storage/rolldb/wal.rs @@ -82,13 +82,23 @@ impl KVTable> for WalKV { const CF_NAME: &'static str = "WalKV"; } +pub struct WalIterator<'a>(pub EntryIterator<'a, DBInt, DBSerde>); + +impl Iterator for WalIterator<'_> { + type Item = Result<(u64, Value), Error>; + + fn next(&mut self) -> Option { + self.0.next().map(|v| v.map(|(seq, val)| (seq.0, val.0))) + } +} + impl WalKV { pub fn initialize(db: &DB) -> Result { if Self::is_empty(db) { Self::write_seed(db)?; Ok(0) } else { - let last = Self::last_key(&db)?.map(|x| x.0); + let last = Self::last_key(db)?.map(|x| x.0); Ok(last.unwrap()) } } @@ -97,7 +107,7 @@ impl WalKV { let mut batch = WriteBatch::default(); let k = DBInt(0); let v = DBSerde(Value::origin()); - Self::stage_upsert(&db, k, v, &mut batch); + Self::stage_upsert(db, k, v, &mut batch); db.write(batch).map_err(|_| Error::IO) }