Skip to content

Commit 8f28fe4

Browse files
authored
feat(fortuna): better parallization for revealing requests (#1636)
1 parent 90740e4 commit 8f28fe4

File tree

5 files changed

+188
-255
lines changed

5 files changed

+188
-255
lines changed

apps/fortuna/Cargo.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "6.1.0"
3+
version = "6.2.0"
44
edition = "2021"
55

66
[dependencies]
@@ -35,6 +35,7 @@ once_cell = "1.18.0"
3535
lazy_static = "1.4.0"
3636
url = "2.5.0"
3737
chrono = { version = "0.4.38", features = ["clock", "std"] , default-features = false}
38+
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
3839

3940

4041
[dev-dependencies]

apps/fortuna/src/chain/ethereum.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl EntropyReader for PythContract {
270270
sequence_number: u64,
271271
user_random_number: [u8; 32],
272272
provider_revelation: [u8; 32],
273-
) -> Result<Option<U256>> {
273+
) -> Result<U256> {
274274
let result: Result<U256, ContractError<Provider<Http>>> = self
275275
.reveal_with_callback(
276276
provider,
@@ -281,19 +281,6 @@ impl EntropyReader for PythContract {
281281
.estimate_gas()
282282
.await;
283283

284-
match result {
285-
Ok(gas) => Ok(Some(gas)),
286-
Err(e) => match e {
287-
ContractError::ProviderError { e } => Err(anyhow!(e)),
288-
_ => {
289-
tracing::info!(
290-
sequence_number = sequence_number,
291-
"Gas estimation failed. error: {:?}",
292-
e
293-
);
294-
Ok(None)
295-
}
296-
},
297-
}
284+
result.map_err(|e| e.into())
298285
}
299286
}

apps/fortuna/src/chain/reader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ pub trait EntropyReader: Send + Sync {
5757
to_block: BlockNumber,
5858
) -> Result<Vec<RequestedWithCallbackEvent>>;
5959

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

7170
/// An in-flight request stored in the contract.
@@ -189,8 +188,8 @@ pub mod mock {
189188
sequence_number: u64,
190189
user_random_number: [u8; 32],
191190
provider_revelation: [u8; 32],
192-
) -> Result<Option<U256>> {
193-
Ok(Some(U256::from(5)))
191+
) -> Result<U256> {
192+
Ok(U256::from(5))
194193
}
195194
}
196195
}

0 commit comments

Comments
 (0)