Skip to content

Commit

Permalink
Allow building without 'parallel' feature (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolin committed Oct 12, 2022
1 parent c6f947a commit 9964c54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ utilities = [ "snarkvm-utilities" ]
parameters_no_std_out = [ "snarkvm-parameters/no_std_out" ]
parallel = [
"rayon",
"snarkvm-algorithms/parallel",
"snarkvm-compiler/parallel",
"snarkvm-fields/parallel",
"snarkvm-utilities/parallel"
Expand All @@ -123,6 +124,7 @@ noconfig = [ ]
path = "./algorithms"
version = "0.9.0"
optional = true
default-features = false

[dependencies.snarkvm-circuit]
path = "./circuit"
Expand Down Expand Up @@ -167,6 +169,7 @@ optional = true
[dependencies.snarkvm-compiler]
path = "./compiler"
version = "0.9.0"
default-features = false

[dependencies.anyhow]
version = "1.0.64"
Expand Down
14 changes: 11 additions & 3 deletions compiler/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ impl<N: Network, B: BlockStorage<N>, P: ProgramStorage<N>> Ledger<N, B, P> {
ledger.block_tree.append(&hashes)?;

// Safety check the existence of every block.
(0..=latest_height).into_par_iter().try_for_each(|height| {
#[cfg(feature = "parallel")]
let heights_iter = (0..=latest_height).into_par_iter();
#[cfg(not(feature = "parallel"))]
let mut heights_iter = (0..=latest_height).into_iter();
heights_iter.try_for_each(|height| {
ledger.get_block(height)?;
Ok::<_, Error>(())
})?;
Expand Down Expand Up @@ -517,8 +521,12 @@ impl<N: Network, B: BlockStorage<N>, P: ProgramStorage<N>> Ledger<N, B, P> {
bail!("Cannot validate a block with more than {} transactions", Transactions::<N>::MAX_TRANSACTIONS);
}

// Ensure each transaction is well-formed.
if !block.transactions().par_iter().all(|(_, transaction)| self.vm.verify(transaction)) {
// Ensure each transaction is well-formed and unique.
#[cfg(feature = "parallel")]
let transactions_iter = block.transactions().par_iter();
#[cfg(not(feature = "parallel"))]
let mut transactions_iter = block.transactions().iter();
if !transactions_iter.all(|(_, transaction)| self.vm.verify(transaction)) {
bail!("Invalid transaction found in the transactions list");
}

Expand Down

0 comments on commit 9964c54

Please sign in to comment.