Skip to content

Commit e870ed1

Browse files
authored
[Storage] make Blob type an associated type of Storage instead of generic param (#729)
1 parent 5d3d8a2 commit e870ed1

15 files changed

Lines changed: 127 additions & 139 deletions

File tree

consensus/src/ordered_broadcast/engine.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use commonware_runtime::{
2626
histogram,
2727
status::{CounterExt, Status},
2828
},
29-
Blob, Clock, Handle, Metrics, Spawner, Storage,
29+
Clock, Handle, Metrics, Spawner, Storage,
3030
};
3131
use commonware_storage::journal::{self, variable::Journal};
3232
use commonware_utils::futures::Pool as FuturesPool;
@@ -53,8 +53,7 @@ struct Verify<C: Scheme, D: Digest, E: Clock> {
5353

5454
/// Instance of the engine.
5555
pub struct Engine<
56-
B: Blob,
57-
E: Clock + Spawner + Storage<B> + Metrics,
56+
E: Clock + Spawner + Storage + Metrics,
5857
C: Scheme,
5958
D: Digest,
6059
A: Automaton<Context = Context<C::PublicKey>, Digest = D> + Clone,
@@ -149,7 +148,7 @@ pub struct Engine<
149148
journal_name_prefix: String,
150149

151150
// A map of sequencer public keys to their journals.
152-
journals: BTreeMap<C::PublicKey, Journal<B, E>>,
151+
journals: BTreeMap<C::PublicKey, Journal<E>>,
153152

154153
////////////////////////////////////////
155154
// State
@@ -193,8 +192,7 @@ pub struct Engine<
193192
}
194193

195194
impl<
196-
B: Blob,
197-
E: Clock + Spawner + Storage<B> + Metrics,
195+
E: Clock + Spawner + Storage + Metrics,
198196
C: Scheme,
199197
D: Digest,
200198
A: Automaton<Context = Context<C::PublicKey>, Digest = D> + Clone,
@@ -210,7 +208,7 @@ impl<
210208
>,
211209
NetS: Sender<PublicKey = C::PublicKey>,
212210
NetR: Receiver<PublicKey = C::PublicKey>,
213-
> Engine<B, E, C, D, A, R, Z, M, Su, TSu, NetS, NetR>
211+
> Engine<E, C, D, A, R, Z, M, Su, TSu, NetS, NetR>
214212
{
215213
/// Creates a new engine with the given context and configuration.
216214
pub fn new(context: E, cfg: Config<C, D, A, R, Z, M, Su, TSu>) -> Self {

consensus/src/simplex/actors/voter/actor.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
use commonware_cryptography::{sha256::hash, sha256::Digest as Sha256Digest, Scheme};
1818
use commonware_macros::select;
1919
use commonware_p2p::{Receiver, Recipients, Sender};
20-
use commonware_runtime::{Blob, Clock, Handle, Metrics, Spawner, Storage};
20+
use commonware_runtime::{Clock, Handle, Metrics, Spawner, Storage};
2121
use commonware_storage::journal::variable::Journal;
2222
use commonware_utils::{quorum, Array};
2323
use futures::{
@@ -458,8 +458,7 @@ impl<C: Scheme, D: Array, S: Supervisor<Index = View, PublicKey = C::PublicKey>>
458458
}
459459

460460
pub struct Actor<
461-
B: Blob,
462-
E: Clock + Rng + Spawner + Storage<B> + Metrics,
461+
E: Clock + Rng + Spawner + Storage + Metrics,
463462
C: Scheme,
464463
D: Array,
465464
A: Automaton<Context = Context<D>, Digest = D>,
@@ -475,7 +474,7 @@ pub struct Actor<
475474
supervisor: S,
476475

477476
replay_concurrency: usize,
478-
journal: Option<Journal<B, E>>,
477+
journal: Option<Journal<E>>,
479478

480479
genesis: Option<D>,
481480

@@ -505,19 +504,18 @@ pub struct Actor<
505504
}
506505

507506
impl<
508-
B: Blob,
509-
E: Clock + Rng + Spawner + Storage<B> + Metrics,
507+
E: Clock + Rng + Spawner + Storage + Metrics,
510508
C: Scheme,
511509
D: Array,
512510
A: Automaton<Context = Context<D>, Digest = D>,
513511
R: Relay<Digest = D>,
514512
F: Committer<Digest = D>,
515513
S: Supervisor<Index = View, PublicKey = C::PublicKey>,
516-
> Actor<B, E, C, D, A, R, F, S>
514+
> Actor<E, C, D, A, R, F, S>
517515
{
518516
pub fn new(
519517
context: E,
520-
journal: Journal<B, E>,
518+
journal: Journal<E>,
521519
cfg: Config<C, D, A, R, F, S>,
522520
) -> (Self, Mailbox<D>) {
523521
// Assert correctness of timeouts

consensus/src/simplex/engine.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{Automaton, Committer, Relay, Supervisor};
77
use commonware_cryptography::Scheme;
88
use commonware_macros::select;
99
use commonware_p2p::{Receiver, Sender};
10-
use commonware_runtime::{Blob, Clock, Handle, Metrics, Spawner, Storage};
10+
use commonware_runtime::{Clock, Handle, Metrics, Spawner, Storage};
1111
use commonware_storage::journal::variable::Journal;
1212
use commonware_utils::Array;
1313
use governor::clock::Clock as GClock;
@@ -16,8 +16,7 @@ use tracing::debug;
1616

1717
/// Instance of `simplex` consensus engine.
1818
pub struct Engine<
19-
B: Blob,
20-
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage<B> + Metrics,
19+
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage + Metrics,
2120
C: Scheme,
2221
D: Array,
2322
A: Automaton<Context = Context<D>, Digest = D>,
@@ -27,25 +26,24 @@ pub struct Engine<
2726
> {
2827
context: E,
2928

30-
voter: voter::Actor<B, E, C, D, A, R, F, S>,
29+
voter: voter::Actor<E, C, D, A, R, F, S>,
3130
voter_mailbox: voter::Mailbox<D>,
3231
resolver: resolver::Actor<E, C, D, S>,
3332
resolver_mailbox: resolver::Mailbox,
3433
}
3534

3635
impl<
37-
B: Blob,
38-
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage<B> + Metrics,
36+
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage + Metrics,
3937
C: Scheme,
4038
D: Array,
4139
A: Automaton<Context = Context<D>, Digest = D>,
4240
R: Relay<Digest = D>,
4341
F: Committer<Digest = D>,
4442
S: Supervisor<Index = View, PublicKey = C::PublicKey>,
45-
> Engine<B, E, C, D, A, R, F, S>
43+
> Engine<E, C, D, A, R, F, S>
4644
{
4745
/// Create a new `simplex` consensus engine.
48-
pub fn new(context: E, journal: Journal<B, E>, cfg: Config<C, D, A, R, F, S>) -> Self {
46+
pub fn new(context: E, journal: Journal<E>, cfg: Config<C, D, A, R, F, S>) -> Self {
4947
// Ensure configuration is valid
5048
cfg.assert();
5149

consensus/src/threshold_simplex/actors/voter/actor.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use commonware_cryptography::{
2929
};
3030
use commonware_macros::select;
3131
use commonware_p2p::{Receiver, Recipients, Sender};
32-
use commonware_runtime::{Blob, Clock, Handle, Metrics, Spawner, Storage};
32+
use commonware_runtime::{Clock, Handle, Metrics, Spawner, Storage};
3333
use commonware_storage::journal::variable::Journal;
3434
use commonware_utils::quorum;
3535
use futures::{
@@ -675,8 +675,7 @@ impl<
675675
}
676676

677677
pub struct Actor<
678-
B: Blob,
679-
E: Clock + Rng + Spawner + Storage<B> + Metrics,
678+
E: Clock + Rng + Spawner + Storage + Metrics,
680679
C: Scheme,
681680
D: Digest,
682681
A: Automaton<Digest = D, Context = Context<D>>,
@@ -698,7 +697,7 @@ pub struct Actor<
698697
supervisor: S,
699698

700699
replay_concurrency: usize,
701-
journal: Option<Journal<B, E>>,
700+
journal: Option<Journal<E>>,
702701

703702
genesis: Option<D>,
704703

@@ -729,8 +728,7 @@ pub struct Actor<
729728
}
730729

731730
impl<
732-
B: Blob,
733-
E: Clock + Rng + Spawner + Storage<B> + Metrics,
731+
E: Clock + Rng + Spawner + Storage + Metrics,
734732
C: Scheme,
735733
D: Digest,
736734
A: Automaton<Digest = D, Context = Context<D>>,
@@ -743,11 +741,11 @@ impl<
743741
Share = group::Share,
744742
PublicKey = C::PublicKey,
745743
>,
746-
> Actor<B, E, C, D, A, R, F, S>
744+
> Actor<E, C, D, A, R, F, S>
747745
{
748746
pub fn new(
749747
context: E,
750-
journal: Journal<B, E>,
748+
journal: Journal<E>,
751749
cfg: Config<C, D, A, R, F, S>,
752750
) -> (Self, Mailbox<D>) {
753751
// Assert correctness of timeouts

consensus/src/threshold_simplex/engine.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ use commonware_cryptography::{
1010
};
1111
use commonware_macros::select;
1212
use commonware_p2p::{Receiver, Sender};
13-
use commonware_runtime::{Blob, Clock, Handle, Metrics, Spawner, Storage};
13+
use commonware_runtime::{Clock, Handle, Metrics, Spawner, Storage};
1414
use commonware_storage::journal::variable::Journal;
1515
use governor::clock::Clock as GClock;
1616
use rand::{CryptoRng, Rng};
1717
use tracing::debug;
1818

1919
/// Instance of `threshold-simplex` consensus engine.
2020
pub struct Engine<
21-
B: Blob,
22-
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage<B> + Metrics,
21+
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage + Metrics,
2322
C: Scheme,
2423
D: Digest,
2524
A: Automaton<Context = Context<D>, Digest = D>,
@@ -35,15 +34,14 @@ pub struct Engine<
3534
> {
3635
context: E,
3736

38-
voter: voter::Actor<B, E, C, D, A, R, F, S>,
37+
voter: voter::Actor<E, C, D, A, R, F, S>,
3938
voter_mailbox: voter::Mailbox<D>,
4039
resolver: resolver::Actor<E, C, D, S>,
4140
resolver_mailbox: resolver::Mailbox,
4241
}
4342

4443
impl<
45-
B: Blob,
46-
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage<B> + Metrics,
44+
E: Clock + GClock + Rng + CryptoRng + Spawner + Storage + Metrics,
4745
C: Scheme,
4846
D: Digest,
4947
A: Automaton<Context = Context<D>, Digest = D>,
@@ -56,10 +54,10 @@ impl<
5654
Identity = poly::Public,
5755
PublicKey = C::PublicKey,
5856
>,
59-
> Engine<B, E, C, D, A, R, F, S>
57+
> Engine<E, C, D, A, R, F, S>
6058
{
6159
/// Create a new `threshold-simplex` consensus engine.
62-
pub fn new(context: E, journal: Journal<B, E>, cfg: Config<C, D, A, R, F, S>) -> Self {
60+
pub fn new(context: E, journal: Journal<E>, cfg: Config<C, D, A, R, F, S>) -> Self {
6361
// Ensure configuration is valid
6462
cfg.assert();
6563

runtime/src/deterministic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,9 @@ impl Clone for Blob {
13241324
}
13251325
}
13261326

1327-
impl crate::Storage<Blob> for Context {
1327+
impl crate::Storage for Context {
1328+
type Blob = Blob;
1329+
13281330
async fn open(&self, partition: &str, name: &[u8]) -> Result<Blob, Error> {
13291331
self.executor.auditor.open(partition, name);
13301332
let mut partitions = self.executor.partitions.lock().unwrap();

runtime/src/lib.rs

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,19 @@ pub trait Stream: Sync + Send + 'static {
259259
/// writes, blobs are responsible for maintaining synchronization.
260260
///
261261
/// Storage can be backed by a local filesystem, cloud storage, etc.
262-
pub trait Storage<B>: Clone + Send + Sync + 'static
263-
where
264-
B: Blob,
265-
{
262+
pub trait Storage: Clone + Send + Sync + 'static {
263+
/// The readable/writeable storage buffer that can be opened by this Storage.
264+
type Blob: Blob;
265+
266266
/// Open an existing blob in a given partition or create a new one.
267267
///
268268
/// Multiple instances of the same blob can be opened concurrently, however,
269269
/// writing to the same blob concurrently may lead to undefined behavior.
270-
fn open(&self, partition: &str, name: &[u8]) -> impl Future<Output = Result<B, Error>> + Send;
270+
fn open(
271+
&self,
272+
partition: &str,
273+
name: &[u8],
274+
) -> impl Future<Output = Result<Self::Blob, Error>> + Send;
271275

272276
/// Remove a blob from a given partition.
273277
///
@@ -483,10 +487,7 @@ mod tests {
483487
});
484488
}
485489

486-
fn test_storage_operations<B>(runner: impl Runner, context: impl Spawner + Storage<B>)
487-
where
488-
B: Blob,
489-
{
490+
fn test_storage_operations(runner: impl Runner, context: impl Spawner + Storage) {
490491
runner.start(async move {
491492
let partition = "test_partition";
492493
let name = b"test_blob";
@@ -568,10 +569,7 @@ mod tests {
568569
});
569570
}
570571

571-
fn test_blob_read_write<B>(runner: impl Runner, context: impl Spawner + Storage<B>)
572-
where
573-
B: Blob,
574-
{
572+
fn test_blob_read_write(runner: impl Runner, context: impl Spawner + Storage) {
575573
runner.start(async move {
576574
let partition = "test_partition";
577575
let name = b"test_blob_rw";
@@ -632,10 +630,7 @@ mod tests {
632630
});
633631
}
634632

635-
fn test_many_partition_read_write<B>(runner: impl Runner, context: impl Spawner + Storage<B>)
636-
where
637-
B: Blob,
638-
{
633+
fn test_many_partition_read_write(runner: impl Runner, context: impl Spawner + Storage) {
639634
runner.start(async move {
640635
let partitions = ["partition1", "partition2", "partition3"];
641636
let name = b"test_blob_rw";
@@ -682,10 +677,7 @@ mod tests {
682677
});
683678
}
684679

685-
fn test_blob_read_past_length<B>(runner: impl Runner, context: impl Spawner + Storage<B>)
686-
where
687-
B: Blob,
688-
{
680+
fn test_blob_read_past_length(runner: impl Runner, context: impl Spawner + Storage) {
689681
runner.start(async move {
690682
let partition = "test_partition";
691683
let name = b"test_blob_rw";
@@ -714,12 +706,10 @@ mod tests {
714706
})
715707
}
716708

717-
fn test_blob_clone_and_concurrent_read<B>(
709+
fn test_blob_clone_and_concurrent_read(
718710
runner: impl Runner,
719-
context: impl Spawner + Storage<B> + Metrics,
720-
) where
721-
B: Blob,
722-
{
711+
context: impl Spawner + Storage + Metrics,
712+
) {
723713
runner.start(async move {
724714
let partition = "test_partition";
725715
let name = b"test_blob_rw";

runtime/src/tokio/runtime.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,9 @@ impl Clone for Blob {
695695
}
696696
}
697697

698-
impl crate::Storage<Blob> for Context {
698+
impl crate::Storage for Context {
699+
type Blob = Blob;
700+
699701
async fn open(&self, partition: &str, name: &[u8]) -> Result<Blob, Error> {
700702
// Acquire the filesystem lock
701703
let _guard = self.executor.fs.lock().await;

0 commit comments

Comments
 (0)