Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[commonware-utils] move Array to utils #513

Merged
merged 4 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion broadcast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Disseminate data over a wide-area network.

use bytes::Bytes;
use commonware_cryptography::Array;
use commonware_utils::Array;
use futures::channel::oneshot;
use std::future::Future;

Expand Down
2 changes: 1 addition & 1 deletion broadcast/src/linked/mocks/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
linked::{signer, Context},
Application as A, Broadcaster,
};
use commonware_cryptography::Array;
use commonware_utils::Array;
use futures::{
channel::{mpsc, oneshot},
SinkExt, StreamExt,
Expand Down
3 changes: 2 additions & 1 deletion broadcast/src/linked/mocks/collector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{linked::prover::Prover, Collector as Z, Proof};
use commonware_cryptography::{bls12381::primitives::group, Array, Scheme};
use commonware_cryptography::{bls12381::primitives::group, Scheme};
use commonware_utils::Array;
use futures::{
channel::{mpsc, oneshot},
SinkExt, StreamExt,
Expand Down
10 changes: 4 additions & 6 deletions broadcast/src/linked/mocks/coordinator.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::{linked::Epoch, Coordinator as S, ThresholdCoordinator as T};
use commonware_cryptography::{
bls12381::primitives::{
group::{Public, Share},
poly::Poly,
},
Array,
use commonware_cryptography::bls12381::primitives::{
group::{Public, Share},
poly::Poly,
};
use commonware_utils::Array;
use std::collections::HashMap;

/// Implementation of `commonware-consensus::Coordinator`.
Expand Down
3 changes: 1 addition & 2 deletions broadcast/src/linked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
//! [Autobahn](https://arxiv.org/abs/2401.10369) provided the insight that a succinct
//! proof-of-availability could be produced by linking sequencer broadcasts.

use commonware_cryptography::Array;

use commonware_utils::Array;
mod namespace;
mod parsed;
mod serializer;
Expand Down
19 changes: 12 additions & 7 deletions broadcast/src/linked/parsed.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Parsed wrappers around wire types.

use crate::linked::{wire, Epoch};
use commonware_cryptography::Array;
use commonware_cryptography::{
bls12381::primitives::{
group::{Element, Signature as ThresholdSignature},
poly::PartialSignature,
},
Scheme,
};
use commonware_utils::Array;
use prost::Message;

#[derive(Debug, thiserror::Error)]
Expand All @@ -25,8 +25,12 @@ pub enum Error {
InvalidPartial,
#[error("Invalid threshold")]
InvalidThreshold,
#[error("Cryptographic error: {0}")]
Crypto(#[from] commonware_cryptography::Error),
#[error("Sequencer parse error: {0}")]
Sequencer(String),
#[error("Payload parse error: {0}")]
Payload(String),
#[error("Signature parse error: {0}")]
Signature(String),
}

/// Parsed version of a `Chunk`.
Expand All @@ -41,9 +45,9 @@ impl<D: Array, P: Array> Chunk<D, P> {
/// Returns a `Chunk` from a `wire::Chunk`.
pub fn from_wire(chunk: wire::Chunk) -> Result<Self, Error> {
Ok(Self {
sequencer: P::try_from(chunk.sequencer).map_err(Error::Crypto)?,
sequencer: P::try_from(chunk.sequencer).map_err(|e| Error::Sequencer(e.to_string()))?,
height: chunk.height,
payload: D::try_from(chunk.payload).map_err(Error::Crypto)?,
payload: D::try_from(chunk.payload).map_err(|e| Error::Payload(e.to_string()))?,
})
}

Expand All @@ -69,7 +73,7 @@ impl<D: Array> Parent<D> {
/// Returns a `Parent` from a `wire::Parent`.
pub fn from_wire(parent: wire::Parent) -> Result<Self, Error> {
Ok(Self {
payload: D::try_from(parent.payload).map_err(Error::Crypto)?,
payload: D::try_from(parent.payload).map_err(|e| Error::Payload(e.to_string()))?,
epoch: parent.epoch,
threshold: ThresholdSignature::deserialize(&parent.threshold)
.ok_or(Error::InvalidThreshold)?,
Expand Down Expand Up @@ -106,7 +110,8 @@ impl<C: Scheme, D: Array> Node<C, D> {
} else if chunk.height > 0 && parent.is_none() {
return Err(Error::ParentMissing);
}
let signature = C::Signature::try_from(node.signature).map_err(Error::Crypto)?;
let signature =
C::Signature::try_from(node.signature).map_err(|e| Error::Signature(e.to_string()))?;
Ok(Self {
chunk,
signature,
Expand Down
4 changes: 2 additions & 2 deletions broadcast/src/linked/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use commonware_cryptography::{
group::{self, Element},
ops,
},
Array, Scheme,
Scheme,
};
use commonware_utils::SizedSerialize;
use commonware_utils::{Array, SizedSerialize};
use std::marker::PhantomData;

/// Encode and decode proofs of broadcast.
Expand Down
3 changes: 1 addition & 2 deletions broadcast/src/linked/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use super::{parsed, Epoch};
use bytes::BufMut;
use commonware_cryptography::Array;
use commonware_utils::SizedSerialize;
use commonware_utils::{Array, SizedSerialize};

/// Serializes an Ack message into a byte array.
pub fn ack<D: Array, P: Array>(chunk: &parsed::Chunk<D, P>, epoch: Epoch) -> Vec<u8> {
Expand Down
6 changes: 2 additions & 4 deletions broadcast/src/linked/signer/ack_manager.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::linked::{parsed, Epoch};
use commonware_cryptography::{
bls12381::primitives::{group, ops, poly::PartialSignature},
Array,
};
use commonware_cryptography::bls12381::primitives::{group, ops, poly::PartialSignature};
use commonware_utils::Array;
use std::collections::{BTreeMap, HashMap, HashSet};

/// A struct representing a set of partial signatures for a payload digest.
Expand Down
3 changes: 2 additions & 1 deletion broadcast/src/linked/signer/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ use commonware_cryptography::{
ops,
poly::{self},
},
Array, Scheme,
Scheme,
};
use commonware_macros::select;
use commonware_p2p::{Receiver, Recipients, Sender};
use commonware_runtime::{Blob, Clock, Spawner, Storage};
use commonware_storage::journal::{self, variable::Journal};
use commonware_utils::Array;
use futures::{
channel::{mpsc, oneshot},
future::{self, Either},
Expand Down
3 changes: 2 additions & 1 deletion broadcast/src/linked/signer/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
linked::{Context, Epoch},
Application, Collector, ThresholdCoordinator,
};
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_utils::Array;
use std::time::Duration;

/// Configuration when creating an `Actor`.
Expand Down
2 changes: 1 addition & 1 deletion broadcast/src/linked/signer/ingress.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Broadcaster;
use commonware_cryptography::Array;
use commonware_utils::Array;
use futures::{
channel::{mpsc, oneshot},
SinkExt,
Expand Down
5 changes: 3 additions & 2 deletions broadcast/src/linked/signer/tip_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::linked::parsed;
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_utils::Array;
use std::collections::{hash_map::Entry, HashMap};

/// Manages the highest-height chunk for each sequencer.
Expand Down Expand Up @@ -61,8 +62,8 @@ mod tests {
use commonware_cryptography::{
ed25519::{self, Ed25519, PublicKey, Signature},
sha256::{self, Digest},
Array,
};
use commonware_utils::Array;
use commonware_utils::SizedSerialize;
use rand::SeedableRng;

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! expect breaking changes and occasional instability.
use bytes::Bytes;
use commonware_cryptography::Array;
use commonware_utils::Array;

pub mod simplex;
pub mod threshold_simplex;
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/actors/resolver/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use crate::{
},
Parsed, Supervisor,
};
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_macros::select;
use commonware_p2p::{utils::requester, Receiver, Recipients, Sender};
use commonware_runtime::Clock;
use commonware_utils::Array;
use futures::{channel::mpsc, future::Either, StreamExt};
use governor::clock::Clock as GClock;
use prometheus_client::metrics::{counter::Counter, gauge::Gauge};
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/simplex/actors/voter/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use crate::{
},
Automaton, Committer, Parsed, Relay, Supervisor,
};
use commonware_cryptography::{sha256::hash, sha256::Digest as Sha256Digest, Array, Scheme};
use commonware_cryptography::{sha256::hash, sha256::Digest as Sha256Digest, Scheme};
use commonware_macros::select;
use commonware_p2p::{Receiver, Recipients, Sender};
use commonware_runtime::{Blob, Clock, Spawner, Storage};
use commonware_storage::journal::variable::Journal;
use commonware_utils::quorum;
use commonware_utils::{quorum, Array};
use futures::{
channel::{mpsc, oneshot},
future::Either,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/simplex/actors/voter/ingress.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{simplex::wire, Parsed};
use commonware_cryptography::Array;
use commonware_utils::Array;
use futures::{channel::mpsc, SinkExt};

// If either of these requests fails, it will not send a reply.
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/actors/voter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::simplex::Context;
use crate::{simplex::View, Automaton, Supervisor};
use crate::{Committer, Relay};
pub use actor::Actor;
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_utils::Array;
pub use ingress::{Mailbox, Message};
use prometheus_client::registry::Registry;
use std::sync::{Arc, Mutex};
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Context, View};
use crate::{Automaton, Committer, Relay, Supervisor};
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_utils::Array;
use governor::Quota;
use prometheus_client::registry::Registry;
use std::{
Expand Down
3 changes: 1 addition & 2 deletions consensus/src/simplex/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::View;
use bytes::BufMut;
use commonware_cryptography::Array;
use commonware_utils::{union, SizedSerialize};
use commonware_utils::{union, Array, SizedSerialize};

pub const NOTARIZE_SUFFIX: &[u8] = b"_NOTARIZE";
pub const NULLIFY_SUFFIX: &[u8] = b"_NULLIFY";
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use super::{
Context, View,
};
use crate::{Automaton, Committer, Relay, Supervisor};
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_macros::select;
use commonware_p2p::{Receiver, Sender};
use commonware_runtime::{Blob, Clock, Spawner, Storage};
use commonware_storage::journal::variable::Journal;
use commonware_utils::Array;
use governor::clock::Clock as GClock;
use rand::{CryptoRng, Rng};
use tracing::debug;
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/simplex/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use commonware_cryptography::Array;
use commonware_utils::Array;
use prometheus_client::encoding::EncodeLabelSet;

const NOTARIZE_TYPE: i32 = 1;
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/mocks/application.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::relay::Relay;
use crate::{simplex::Context, Automaton as Au, Committer as Co, Proof, Relay as Re};
use bytes::{Buf, BufMut, Bytes};
use commonware_cryptography::{Array, Hasher};
use commonware_cryptography::Hasher;
use commonware_macros::select;
use commonware_runtime::Clock;
use commonware_utils::Array;
use commonware_utils::SizedSerialize;
use futures::{
channel::{mpsc, oneshot},
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/simplex/mocks/relay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytes::Bytes;
use commonware_cryptography::Array;
use commonware_utils::Array;
use futures::{channel::mpsc, SinkExt};
use std::{collections::BTreeMap, sync::Mutex};

Expand Down
3 changes: 2 additions & 1 deletion consensus/src/simplex/mocks/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{
},
Activity, Proof, Supervisor as Su,
};
use commonware_cryptography::{Array, Scheme};
use commonware_cryptography::Scheme;
use commonware_utils::Array;
use std::{
collections::{BTreeMap, HashMap, HashSet},
sync::{Arc, Mutex},
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/simplex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
//! * Introduce message rebroadcast to continue making progress if messages from a given view are dropped (only way
//! to ensure messages are reliably delivered is with a heavyweight reliable broadcast protocol).

use commonware_cryptography::Array;
use commonware_utils::Array;

mod encoder;
mod prover;
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/simplex/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use super::{
};
use crate::Proof;
use bytes::{Buf, BufMut};
use commonware_cryptography::{Array, Scheme};
use commonware_utils::SizedSerialize;
use commonware_cryptography::Scheme;
use commonware_utils::{Array, SizedSerialize};
use std::{collections::HashSet, marker::PhantomData};

/// Encode and decode proofs of activity.
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/simplex/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::{
simplex::encoder::{nullify_message, proposal_message},
Supervisor,
};
use commonware_cryptography::{Array, Scheme};
use commonware_utils::quorum;
use commonware_cryptography::Scheme;
use commonware_utils::{quorum, Array};
use std::collections::HashSet;
use tracing::debug;

Expand Down
3 changes: 2 additions & 1 deletion consensus/src/threshold_simplex/actors/resolver/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use crate::{
},
Parsed, ThresholdSupervisor,
};
use commonware_cryptography::{bls12381::primitives::poly, Array, Scheme};
use commonware_cryptography::{bls12381::primitives::poly, Scheme};
use commonware_macros::select;
use commonware_p2p::{utils::requester, Receiver, Recipients, Sender};
use commonware_runtime::Clock;
use commonware_utils::Array;
use futures::{channel::mpsc, future::Either, StreamExt};
use governor::clock::Clock as GClock;
use prometheus_client::metrics::{counter::Counter, gauge::Gauge};
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/threshold_simplex/actors/voter/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use commonware_cryptography::{
},
hash,
sha256::Digest as Sha256Digest,
Array, Scheme,
Scheme,
};
use commonware_macros::select;
use commonware_p2p::{Receiver, Recipients, Sender};
use commonware_runtime::{Blob, Clock, Spawner, Storage};
use commonware_storage::journal::variable::Journal;
use commonware_utils::quorum;
use commonware_utils::{quorum, Array};
use futures::{
channel::{mpsc, oneshot},
future::Either,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/threshold_simplex/actors/voter/ingress.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{threshold_simplex::wire, Parsed};
use commonware_cryptography::Array;
use commonware_utils::Array;
use futures::{channel::mpsc, SinkExt};

// If either of these requests fails, it will not send a reply.
Expand Down
Loading