Skip to content

Commit

Permalink
lmdb: remove thiserror and tracing deps
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Dec 6, 2024
1 parent 096e7b2 commit 6076d2c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

* sdk: remove `nwc` dep ([Yuki Kishimoto])
* database: remove `lru`, `thiserror` and `tracing` deps ([Yuki Kishimoto])
* lmdb: remove `thiserror` and `tracing` deps ([Yuki Kishimoto])
* zapper: remove `thiserror` dep ([Yuki Kishimoto])
* nwc: remove `thiserror` dep and unnecessary `Error::Zapper` variant ([Yuki Kishimoto])
* ffi: drop support for `i686-linux-android` target ([Yuki Kishimoto])
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/nostr-lmdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ async-utility.workspace = true
heed = { version = "0.20", default-features = false, features = ["read-txn-no-tls"] }
nostr = { workspace = true, features = ["std"] }
nostr-database = { workspace = true, features = ["flatbuf"] }
thiserror.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "sync"] }
tracing = { workspace = true, features = ["std", "attributes"] }
tokio = { workspace = true, features = ["sync"] }

[dev-dependencies]
tempfile = "3"
tokio = { workspace = true, features = ["macros"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
2 changes: 0 additions & 2 deletions crates/nostr-lmdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl NostrDatabase for NostrLMDB {
#[async_trait]
impl NostrEventsDatabase for NostrLMDB {
#[inline]
#[tracing::instrument(skip_all, level = "trace")]
async fn save_event(&self, event: &Event) -> Result<bool, DatabaseError> {
self.db
.save_event(event)
Expand Down Expand Up @@ -138,7 +137,6 @@ impl NostrEventsDatabase for NostrLMDB {
}

#[inline]
#[tracing::instrument(skip_all, level = "trace")]
async fn query(&self, filters: Vec<Filter>) -> Result<Events, DatabaseError> {
self.db.query(filters).await.map_err(DatabaseError::backend)
}
Expand Down
81 changes: 64 additions & 17 deletions crates/nostr-lmdb/src/store/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

use std::{fmt, io};

use nostr::{key, secp256k1};
use nostr_database::flatbuffers;
use thiserror::Error;
use tokio::task::JoinError;

#[derive(Debug, Error)]
#[derive(Debug)]
pub enum Error {
/// An upstream I/O error
#[error(transparent)]
Io(#[from] std::io::Error),
/// An error from LMDB, our upstream storage crate
#[error(transparent)]
Lmdb(#[from] heed::Error),
Io(io::Error),
/// An error from LMDB
Heed(heed::Error),
/// Flatbuffers error
#[error(transparent)]
FlatBuffers(#[from] flatbuffers::Error),
#[error(transparent)]
Thread(#[from] JoinError),
#[error(transparent)]
Key(#[from] key::Error),
#[error(transparent)]
Secp256k1(#[from] secp256k1::Error),
FlatBuffers(flatbuffers::Error),
Thread(JoinError),
Key(key::Error),
Secp256k1(secp256k1::Error),
// /// The event has already been deleted
// #[error("Event was previously deleted")]
// Deleted,
Expand All @@ -38,8 +33,60 @@ pub enum Error {
// #[error("Event was previously replaced")]
// Replaced,
/// The event kind is wrong
#[error("Wrong event kind")]
WrongEventKind,
#[error("Not found")]
/// Not found
NotFound,
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => write!(f, "{e}"),
Self::Heed(e) => write!(f, "{e}"),
Self::FlatBuffers(e) => write!(f, "{e}"),
Self::Thread(e) => write!(f, "{e}"),
Self::Key(e) => write!(f, "{e}"),
Self::Secp256k1(e) => write!(f, "{e}"),
Self::NotFound => write!(f, "Not found"),
Self::WrongEventKind => write!(f, "Wrong event kind"),
}
}
}

impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Self::Io(e)
}
}

impl From<heed::Error> for Error {
fn from(e: heed::Error) -> Self {
Self::Heed(e)
}
}

impl From<flatbuffers::Error> for Error {
fn from(e: flatbuffers::Error) -> Self {
Self::FlatBuffers(e)
}
}

impl From<JoinError> for Error {
fn from(e: JoinError) -> Self {
Self::Thread(e)
}
}

impl From<key::Error> for Error {
fn from(e: key::Error) -> Self {
Self::Key(e)
}
}

impl From<secp256k1::Error> for Error {
fn from(e: secp256k1::Error) -> Self {
Self::Secp256k1(e)
}
}
2 changes: 2 additions & 0 deletions crates/nostr-lmdb/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ impl Store {
})
}

// TODO: spawn an ingester and remove the `fbb` field (use it in the ingester without mutex)?

#[inline]
async fn interact<F, R>(&self, f: F) -> Result<R, Error>
where
Expand Down

0 comments on commit 6076d2c

Please sign in to comment.