Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Oct 7, 2023
1 parent 412f245 commit 3ff0f98
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/bin/dolos/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::path::Path;
use tracing::info;

use dolos::{
prelude::*,
Expand Down
3 changes: 2 additions & 1 deletion src/bin/dolos/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 5 additions & 2 deletions src/serve/grpc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ impl chain_sync_service_server::ChainSyncService for ChainSyncServiceImpl {
&self,
_request: Request<FollowTipRequest>,
) -> Result<Response<Self::FollowTipStream>, 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)))
}
Expand Down
4 changes: 2 additions & 2 deletions src/serve/ouroboros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)? {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/applydb/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<_>, _>>()?
Expand Down
41 changes: 14 additions & 27 deletions src/storage/rolldb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,21 @@ impl RollDB {
Ok(out)
}

pub fn crawl_wal_after(
&self,
seq: Option<u64>,
) -> impl Iterator<Item = Result<(wal::Seq, wal::Value), Error>> + '_ {
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<u64>) -> 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<wal::Seq, Error> {
Expand Down Expand Up @@ -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<bool, Error> {
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<Path>) -> Result<(), Error> {
DB::destroy(&Options::default(), path).map_err(|_| Error::IO)
}
Expand Down
6 changes: 3 additions & 3 deletions src/storage/rolldb/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ItemWithBlock = (super::wal::Value, RawBlock);
pub struct RollStream;

impl RollStream {
pub fn start_after_seq(db: RollDB, seq: Option<super::wal::Seq>) -> impl Stream<Item = Item> {
pub fn start_after(db: RollDB, seq: Option<super::wal::Seq>) -> impl Stream<Item = Item> {
async_stream::stream! {
let mut last_seq = seq;

Expand All @@ -33,7 +33,7 @@ impl RollStream {
}
}

pub fn start_after_block(
pub fn start_after_with_block(
db: RollDB,
seq: Option<super::wal::Seq>,
) -> impl Stream<Item = ItemWithBlock> {
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 12 additions & 2 deletions src/storage/rolldb/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,23 @@ impl KVTable<DBInt, DBSerde<Value>> for WalKV {
const CF_NAME: &'static str = "WalKV";
}

pub struct WalIterator<'a>(pub EntryIterator<'a, DBInt, DBSerde<Value>>);

impl Iterator for WalIterator<'_> {
type Item = Result<(u64, Value), Error>;

fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|v| v.map(|(seq, val)| (seq.0, val.0)))
}
}

impl WalKV {
pub fn initialize(db: &DB) -> Result<Seq, Error> {
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())
}
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 3ff0f98

Please sign in to comment.