Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion apps/fortuna/src/command/register_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ pub async fn register_provider_from_config(
&random,
commitment_length,
provider_config.chain_sample_interval,
)?;
)
.await?;
tracing::info!("Done generating hash chain");

// Arguments to the contract to register our new provider.
Expand Down
1 change: 1 addition & 0 deletions apps/fortuna/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async fn setup_chain_state(
commitment.chain_length,
chain_sample_interval,
)
.await
.map_err(|e| anyhow!("Failed to create hash chain: {}", e))?;
hash_chains.push(pebble_hash_chain);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/fortuna/src/command/setup_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ async fn setup_chain_provider(
&metadata.seed,
provider_config.chain_length,
provider_config.chain_sample_interval,
)?;
)
.await?;
let chain_state = HashChainState {
offsets: vec![provider_info
.original_commitment_sequence_number
Expand Down
16 changes: 10 additions & 6 deletions apps/fortuna/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
anyhow::{ensure, Result},
ethers::types::Address,
sha3::{Digest, Keccak256},
tokio::task::spawn_blocking,
};

/// A hash chain of a specific length. The hash chain has the property that
Expand Down Expand Up @@ -42,7 +43,7 @@ impl PebbleHashChain {
}
}

pub fn from_config(
pub async fn from_config(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can i suggest making a separate constructor method that spawns the original from_config in a blocking thread? like from_config_async

secret: &str,
chain_id: &ChainId,
provider_address: &Address,
Expand All @@ -59,11 +60,14 @@ impl PebbleHashChain {
input.extend_from_slice(random);

let secret: [u8; 32] = Keccak256::digest(input).into();
Ok(Self::new(
secret,
chain_length.try_into()?,
sample_interval.try_into()?,
))

let chain_length: usize = chain_length.try_into()?;
let sample_interval: usize = sample_interval.try_into()?;
let hash_chain = spawn_blocking(move || Self::new(secret, chain_length, sample_interval))
.await
.expect("Failed to make hash chain");

Ok(hash_chain)
}

pub fn reveal_ith(&self, i: usize) -> Result<[u8; 32]> {
Expand Down