Skip to content

Commit

Permalink
feat(fortuna-v2): implement a keeper service for entropy v2 (#1366)
Browse files Browse the repository at this point in the history
* extract code to run api

* save

* some changes

* add exit checks

* retry for sub threads and fetch events

* handle events

* remove unused

* compiling

* add logs to keeper

* add simulation and some fixed

* refactoring keeper

* backlog refactoring works

* extract handle event

* extract watch blocks in a method

* handle events extracted

* remove res block from backlog method

* remove res block from watch_blocks

* remove res block from process events

* load private key from file

* add gas limit to blockchain config

* remove unused imports

* remove a log

* gas param u256

* spell simulate

* rename keeper private keeper file

* wait for only api to exit

* remove exit check from keeper

* remove is valid request method as simulate will cover things

* remove some parameters

* remove exit check from keeper

* use saturating sub

* correct condition

* update logging statement

* combine logs

* use nonce manager to send transaction

* poll instead of stream and add nonce middleware

* remove unused

* fix tests

* add ws support to streaming

* Refactor and improve error handling

* replace simulation with gas estimation

* add polling support for when no wss url

* version update

* test check

* update comment

* update key comment

* rename chain_config to chain_state

* update version

* pad gas estimate

* add comments

---------

Co-authored-by: Amin Moghaddam <[email protected]>
  • Loading branch information
Dev Kalra and m30m authored Apr 3, 2024
1 parent 050b827 commit 6295674
Show file tree
Hide file tree
Showing 10 changed files with 710 additions and 75 deletions.
113 changes: 68 additions & 45 deletions fortuna/Cargo.lock

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

6 changes: 4 additions & 2 deletions fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "3.3.4"
version = "4.0.0"
edition = "2021"

[dependencies]
Expand All @@ -12,7 +12,8 @@ bincode = "1.3.3"
byteorder = "1.5.0"
clap = { version = "4.4.6", features = ["derive", "cargo", "env"] }
ethabi = "18.0.0"
ethers = "2.0.10"
ethers = { version = "2.0.14", features = ["ws"] }
futures = { version = "0.3.28" }
hex = "0.4.3"
prometheus-client = { version = "0.21.2" }
pythnet-sdk = { path = "../pythnet/pythnet_sdk", features = ["strum"] }
Expand All @@ -34,5 +35,6 @@ once_cell = "1.18.0"
lazy_static = "1.4.0"
url = "2.5.0"


[dev-dependencies]
axum-test = "13.1.1"
4 changes: 4 additions & 0 deletions fortuna/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ impl ApiState {
/// The state of the randomness service for a single blockchain.
#[derive(Clone)]
pub struct BlockchainState {
/// The chain id for this blockchain, useful for logging
pub id: ChainId,
/// The hash chain(s) required to serve random numbers for this blockchain
pub state: Arc<HashChainState>,
/// The contract that the server is fulfilling requests for.
Expand Down Expand Up @@ -245,6 +247,7 @@ mod test {
let eth_read = Arc::new(MockEntropyReader::with_requests(10, &[]));

let eth_state = BlockchainState {
id: "ethereum".into(),
state: ETH_CHAIN.clone(),
contract: eth_read.clone(),
provider_address: PROVIDER,
Expand All @@ -255,6 +258,7 @@ mod test {
let avax_read = Arc::new(MockEntropyReader::with_requests(10, &[]));

let avax_state = BlockchainState {
id: "avalanche".into(),
state: AVAX_CHAIN.clone(),
contract: avax_read.clone(),
provider_address: PROVIDER,
Expand Down
Loading

0 comments on commit 6295674

Please sign in to comment.