Skip to content

Commit 15371cf

Browse files
committed
Reorg modules
1 parent fab5556 commit 15371cf

3 files changed

Lines changed: 43 additions & 38 deletions

File tree

crates/core/src/aggsigdb/memory.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
aggsigdb::{AggSigDB, Error},
2+
aggsigdb::types::{AggSigDB, Error},
33
deadline, types,
44
};
55
use std::collections::{HashMap, hash_map::Entry};
@@ -198,7 +198,10 @@ impl AggSigDB for MemoryDBHandle {
198198
#[cfg(test)]
199199
mod tests {
200200
use crate::{
201-
aggsigdb::{AggSigDB, Error, memory::MemoryDBHandle},
201+
aggsigdb::{
202+
memory::MemoryDBHandle,
203+
types::{AggSigDB, Error},
204+
},
202205
deadline,
203206
signeddata::SignedDataError,
204207
types::{Duty, PubKey, Signature, SignedData, SignedDataSet, SlotNumber},

crates/core/src/aggsigdb/mod.rs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
1-
use crate::types;
2-
3-
/// Errors for AggSigDB operations.
4-
#[derive(Debug, thiserror::Error)]
5-
pub enum Error {
6-
/// Data for the same duty and public key already exists but does not match
7-
/// the new data.
8-
#[error("Mismatching data")]
9-
MismatchingData,
10-
11-
/// The request cannot be processed because the instance has been
12-
/// terminated.
13-
#[error("The instance has been terminated")]
14-
Terminated,
15-
}
16-
17-
/// A persistent store for aggregated signed duty data.
18-
#[async_trait::async_trait]
19-
pub trait AggSigDB {
20-
/// Stores aggregated signed duty data set.
21-
async fn store(&self, duty: types::Duty, data: types::SignedDataSet) -> Result<(), Error>;
22-
23-
/// Blocks and returns the aggregated signed duty data when available.
24-
///
25-
/// Might block indefinitely if no data is ever stored for the given duty
26-
/// and public key.
27-
///
28-
/// To avoid blocking indefinitely, consider using a timeout,
29-
/// [`CancellationToken`] or racing using `tokio::select!` against other
30-
/// events.
31-
async fn wait_for(
32-
&self,
33-
duty: types::Duty,
34-
pub_key: types::PubKey,
35-
) -> Result<Box<dyn types::SignedData>, Error>;
36-
}
1+
/// Type definitions and traits for the AggSigDB.
2+
pub mod types;
373

384
/// Memory implementation of the AggSigDB.
395
pub mod memory;

crates/core/src/aggsigdb/types.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::types;
2+
3+
/// Errors for AggSigDB operations.
4+
#[derive(Debug, thiserror::Error)]
5+
pub enum Error {
6+
/// Data for the same duty and public key already exists but does not match
7+
/// the new data.
8+
#[error("Mismatching data")]
9+
MismatchingData,
10+
11+
/// The request cannot be processed because the instance has been
12+
/// terminated.
13+
#[error("The instance has been terminated")]
14+
Terminated,
15+
}
16+
17+
/// A persistent store for aggregated signed duty data.
18+
#[async_trait::async_trait]
19+
pub trait AggSigDB {
20+
/// Stores aggregated signed duty data set.
21+
async fn store(&self, duty: types::Duty, data: types::SignedDataSet) -> Result<(), Error>;
22+
23+
/// Blocks and returns the aggregated signed duty data when available.
24+
///
25+
/// Might block indefinitely if no data is ever stored for the given duty
26+
/// and public key.
27+
///
28+
/// To avoid blocking indefinitely, consider using a timeout,
29+
/// [`CancellationToken`] or racing using `tokio::select!` against other
30+
/// events.
31+
async fn wait_for(
32+
&self,
33+
duty: types::Duty,
34+
pub_key: types::PubKey,
35+
) -> Result<Box<dyn types::SignedData>, Error>;
36+
}

0 commit comments

Comments
 (0)