Skip to content

Commit

Permalink
feat(fortuna): better parallization for revealing requests (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m authored May 31, 2024
1 parent 90740e4 commit 8f28fe4
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 255 deletions.
17 changes: 16 additions & 1 deletion apps/fortuna/Cargo.lock

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

3 changes: 2 additions & 1 deletion apps/fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "6.1.0"
version = "6.2.0"
edition = "2021"

[dependencies]
Expand Down Expand Up @@ -35,6 +35,7 @@ once_cell = "1.18.0"
lazy_static = "1.4.0"
url = "2.5.0"
chrono = { version = "0.4.38", features = ["clock", "std"] , default-features = false}
backoff = { version = "0.4.0", features = ["futures", "tokio"] }


[dev-dependencies]
Expand Down
17 changes: 2 additions & 15 deletions apps/fortuna/src/chain/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl EntropyReader for PythContract {
sequence_number: u64,
user_random_number: [u8; 32],
provider_revelation: [u8; 32],
) -> Result<Option<U256>> {
) -> Result<U256> {
let result: Result<U256, ContractError<Provider<Http>>> = self
.reveal_with_callback(
provider,
Expand All @@ -281,19 +281,6 @@ impl EntropyReader for PythContract {
.estimate_gas()
.await;

match result {
Ok(gas) => Ok(Some(gas)),
Err(e) => match e {
ContractError::ProviderError { e } => Err(anyhow!(e)),
_ => {
tracing::info!(
sequence_number = sequence_number,
"Gas estimation failed. error: {:?}",
e
);
Ok(None)
}
},
}
result.map_err(|e| e.into())
}
}
9 changes: 4 additions & 5 deletions apps/fortuna/src/chain/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ pub trait EntropyReader: Send + Sync {
to_block: BlockNumber,
) -> Result<Vec<RequestedWithCallbackEvent>>;

/// Simulate a reveal with callback. Returns Some(gas) if the estimation was successful.
/// Returns None otherwise. Returns an error if the gas could not be estimated.
/// Estimate the gas required to reveal a random number with a callback.
async fn estimate_reveal_with_callback_gas(
&self,
provider: Address,
sequence_number: u64,
user_random_number: [u8; 32],
provider_revelation: [u8; 32],
) -> Result<Option<U256>>;
) -> Result<U256>;
}

/// An in-flight request stored in the contract.
Expand Down Expand Up @@ -189,8 +188,8 @@ pub mod mock {
sequence_number: u64,
user_random_number: [u8; 32],
provider_revelation: [u8; 32],
) -> Result<Option<U256>> {
Ok(Some(U256::from(5)))
) -> Result<U256> {
Ok(U256::from(5))
}
}
}
Loading

0 comments on commit 8f28fe4

Please sign in to comment.