Skip to content

Commit 1cef660

Browse files
consolidate wasm32
1 parent c2fb88b commit 1cef660

1 file changed

Lines changed: 47 additions & 56 deletions

File tree

consensus/src/simplex/mod.rs

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -314,80 +314,71 @@
314314
//! Before sending a message, the `Journal` sync is invoked to prevent inadvertent Byzantine behavior
315315
//! on restart (especially in the case of unclean shutdown).
316316
317-
#[cfg(not(target_arch = "wasm32"))]
318-
use crate::types::Round;
319-
#[cfg(not(target_arch = "wasm32"))]
320-
use commonware_cryptography::PublicKey;
321-
#[cfg(not(target_arch = "wasm32"))]
322-
use commonware_p2p::Recipients;
323-
324317
pub mod elector;
325318
pub mod scheme;
326319
pub mod types;
327320

328321
cfg_if::cfg_if! {
329322
if #[cfg(not(target_arch = "wasm32"))] {
323+
use crate::types::{Round, View, ViewDelta};
324+
use commonware_cryptography::PublicKey;
325+
use commonware_p2p::Recipients;
326+
330327
mod actors;
331328
pub mod config;
332329
pub use config::{Config, ForwardingPolicy};
333330
mod engine;
334331
pub use engine::Engine;
335332
mod metrics;
336-
}
337-
}
338333

339-
#[cfg(any(test, feature = "mocks"))]
340-
pub mod mocks;
341-
342-
#[cfg(not(target_arch = "wasm32"))]
343-
use crate::types::{View, ViewDelta};
334+
/// The minimum view we are tracking both in-memory and on-disk.
335+
pub(crate) const fn min_active(activity_timeout: ViewDelta, last_finalized: View) -> View {
336+
last_finalized.saturating_sub(activity_timeout)
337+
}
344338

345-
/// The minimum view we are tracking both in-memory and on-disk.
346-
#[cfg(not(target_arch = "wasm32"))]
347-
pub(crate) const fn min_active(activity_timeout: ViewDelta, last_finalized: View) -> View {
348-
last_finalized.saturating_sub(activity_timeout)
349-
}
339+
/// Whether or not a view is interesting to us. This is a function
340+
/// of both `min_active` and whether or not the view is too far
341+
/// in the future (based on the view we are currently in).
342+
pub(crate) fn interesting(
343+
activity_timeout: ViewDelta,
344+
last_finalized: View,
345+
current: View,
346+
pending: View,
347+
allow_future: bool,
348+
) -> bool {
349+
// If the view is genesis, skip it, genesis doesn't have votes
350+
if pending.is_zero() {
351+
return false;
352+
}
353+
if pending < min_active(activity_timeout, last_finalized) {
354+
return false;
355+
}
356+
if !allow_future && pending > current.next() {
357+
return false;
358+
}
359+
true
360+
}
350361

351-
/// Whether or not a view is interesting to us. This is a function
352-
/// of both `min_active` and whether or not the view is too far
353-
/// in the future (based on the view we are currently in).
354-
#[cfg(not(target_arch = "wasm32"))]
355-
pub(crate) fn interesting(
356-
activity_timeout: ViewDelta,
357-
last_finalized: View,
358-
current: View,
359-
pending: View,
360-
allow_future: bool,
361-
) -> bool {
362-
// If the view is genesis, skip it, genesis doesn't have votes
363-
if pending.is_zero() {
364-
return false;
365-
}
366-
if pending < min_active(activity_timeout, last_finalized) {
367-
return false;
368-
}
369-
if !allow_future && pending > current.next() {
370-
return false;
362+
/// Describes how a payload should be broadcast to the network.
363+
pub enum Plan<P: PublicKey> {
364+
/// Initial broadcast of a newly proposed block to all participants.
365+
Propose {
366+
/// The round in which the block was proposed.
367+
round: Round,
368+
},
369+
/// Forward a block to a specific set of peers.
370+
Forward {
371+
/// The round in which the forwarded block was proposed.
372+
round: Round,
373+
/// The recipients to forward the block to.
374+
recipients: Recipients<P>,
375+
},
376+
}
371377
}
372-
true
373378
}
374379

375-
/// Describes how a payload should be broadcast to the network.
376-
#[cfg(not(target_arch = "wasm32"))]
377-
pub enum Plan<P: PublicKey> {
378-
/// Initial broadcast of a newly proposed block to all participants.
379-
Propose {
380-
/// The round in which the block was proposed.
381-
round: Round,
382-
},
383-
/// Forward a block to a specific set of peers.
384-
Forward {
385-
/// The round in which the forwarded block was proposed.
386-
round: Round,
387-
/// The recipients to forward the block to.
388-
recipients: Recipients<P>,
389-
},
390-
}
380+
#[cfg(any(test, feature = "mocks"))]
381+
pub mod mocks;
391382

392383
/// Convenience alias for [`N3f1::quorum`].
393384
#[cfg(test)]

0 commit comments

Comments
 (0)