* 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 <amin@pyth.network> |
||
---|---|---|
.. | ||
src | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
Dockerfile | ||
README.md | ||
config.sample.yaml |
README.md
Fortuna
Fortuna is a webservice that serves random numbers according to the Entropy protocol. The webservice generates a hash chain of random numbers and reveals them to callers when permitted by the protocol. The hash chain is generated from a secret key that is provided to the server on startup.
A single instance of this webservice can simultaneously serve random numbers for several different blockchains.
Each blockchain is configured in config.yaml
.
Build & Test
Fortuna uses Cargo for building and dependency management.
Simply run cargo build
and cargo test
to build and test the project.
Command-Line Interface
The Fortuna binary has a command-line interface to perform useful operations on the contract, such as
registering a new randomness provider, or drawing a random value. To see the available commands, simply run cargo run
.
Local Development
To start an instance of the webserver for local testing, you first need to perform a few setup steps:
- Create
config.yaml
file to point to the desired blockchains and Entropy contracts. Copy the content inconfig.sample.yaml
to start with. - Generate a secret key. The secret key is a 32-byte random value used to construct the hash chains.
You can generate this value using the
openssl
command:openssl rand -hex 32
- Generate an ethereum wallet for the provider. You can do this in foundry using
cast wallet new
. Note both the private key and the address; you will need both for subsequent steps. - Register a randomness provider for this service:
cargo run -- register-provider --chain-id <chain id> --secret <secret> --private-key <private-key>
. The chain id is the key of the blockchain inconfig.yaml
, the secret is from step (2), and the private key is from step (3). Note that you need to run this command once per blockchain configured inconfig.yaml
.
Once you've completed the setup, simply run the following command, using the secret from step (2) and the wallet address from step (3) as the provider:
cargo run -- run --secret <secret> --provider <provider>
This command will start the webservice on localhost:34000
.