Skip to content

Commit 596be48

Browse files
chore: remove fortuna-specific keeper code (#2534)
1 parent b3c4c05 commit 596be48

File tree

11 files changed

+20
-763
lines changed

11 files changed

+20
-763
lines changed

apps/argus/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/argus/config.sample.yaml

-25
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ chains:
33
geth_rpc_addr: https://replicator.pegasus.lightlink.io/rpc/v1
44
contract_addr: 0x8250f4aF4B972684F7b336503E2D6dFeDeB1487a
55

6-
# Keeper configuration for the chain
7-
reveal_delay_blocks: 0
8-
gas_limit: 500000
96

107
# Multiplier for the priority fee estimate, as a percentage (i.e., 100 = no change).
118
# Defaults to 100 if the field is omitted.
@@ -38,23 +35,7 @@ chains:
3835
min_profit_pct: 0
3936
target_profit_pct: 20
4037
max_profit_pct: 100
41-
42-
# A list of block delays for processing blocks multiple times. Each number represents
43-
# how many blocks to wait before processing. For example, [5, 10, 20] means process
44-
# blocks after 5 blocks, then again after 10 blocks, and finally after 20 blocks.
45-
block_delays: [5, 10, 20]
46-
47-
# Historical commitments -- delete this block for local development purposes
48-
commitments:
49-
# prettier-ignore
50-
- seed: [219,125,217,197,234,88,208,120,21,181,172,143,239,102,41,233,167,212,237,106,37,255,184,165,238,121,230,155,116,158,173,48]
51-
chain_length: 10000
52-
original_commitment_sequence_number: 104
5338
provider:
54-
uri: http://localhost:8080/
55-
chain_length: 100000
56-
chain_sample_interval: 10
57-
5839
# An ethereum wallet address and private key. Generate with `cast wallet new`
5940
address: 0xADDRESS
6041
private_key:
@@ -63,12 +44,6 @@ provider:
6344
# For production, you can store the private key in a file.
6445
# file: provider-key.txt
6546
# A 32 byte random value in hexadecimal
66-
# Generate with `openssl rand -hex 32`
67-
secret:
68-
# For local development, you can hardcode the value here
69-
value: abcd
70-
# For production, you can store the private key in a file.
71-
# file: secret.txt
7247

7348
# Set this to the address of your keeper wallet if you would like the keeper wallet to
7449
# be able to withdraw fees from the contract.

apps/argus/src/api.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use {
2-
crate::{
3-
chain::reader::{BlockNumber, BlockStatus},
4-
},
2+
crate::chain::reader::BlockStatus,
53
anyhow::Result,
64
axum::{
75
body::Body,
@@ -47,9 +45,7 @@ pub struct ApiState {
4745
}
4846

4947
impl ApiState {
50-
pub async fn new(
51-
metrics_registry: Arc<RwLock<Registry>>,
52-
) -> ApiState {
48+
pub async fn new(metrics_registry: Arc<RwLock<Registry>>) -> ApiState {
5349
let metrics = ApiMetrics {
5450
http_requests: Family::default(),
5551
};
@@ -68,16 +64,13 @@ impl ApiState {
6864
}
6965
}
7066

71-
/// The state of the randomness service for a single blockchain.
67+
/// The state of the service for a single blockchain.
7268
#[derive(Clone)]
7369
pub struct BlockchainState {
7470
/// The chain id for this blockchain, useful for logging
7571
pub id: ChainId,
7672
/// The address of the provider that this server is operating for.
7773
pub provider_address: Address,
78-
/// The server will wait for this many block confirmations of a request before revealing
79-
/// the random number.
80-
pub reveal_delay_blocks: BlockNumber,
8174
/// The BlockStatus of the block that is considered to be confirmed on the blockchain.
8275
/// For eg., Finalized, Safe
8376
pub confirmed_block_status: BlockStatus,

apps/argus/src/chain/reader.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use {
2-
ethers::types::{Address, BlockNumber as EthersBlockNumber},
3-
};
1+
use ethers::types::{Address, BlockNumber as EthersBlockNumber};
42

53
pub type BlockNumber = u64;
64

+4-38
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
use {
22
crate::{
3-
api::{get_register_uri, ChainId},
3+
api::ChainId,
44
chain::ethereum::SignablePythContract,
55
config::{Config, EthereumConfig, ProviderConfig, RegisterProviderOptions},
66
},
77
anyhow::{anyhow, Result},
8-
ethers::{
9-
abi::Bytes,
10-
types::U256,
11-
},
128
std::sync::Arc,
139
};
1410

@@ -31,48 +27,18 @@ pub async fn register_provider(opts: &RegisterProviderOptions) -> Result<()> {
3127

3228
pub async fn register_provider_from_config(
3329
provider_config: &ProviderConfig,
34-
chain_id: &ChainId,
30+
_chain_id: &ChainId,
3531
chain_config: &EthereumConfig,
3632
) -> Result<()> {
3733
let private_key_string = provider_config.private_key.load()?.ok_or(anyhow!(
3834
"Please specify a provider private key in the config"
3935
))?;
4036

4137
// Initialize a Provider to interface with the EVM contract.
42-
let contract =
38+
let _contract =
4339
Arc::new(SignablePythContract::from_config(chain_config, &private_key_string).await?);
44-
// Create a new random hash chain.
45-
let random = rand::random::<[u8; 32]>();
46-
47-
// FIXME: delete this
48-
let commitment_length = 1000;
4940

50-
// Arguments to the contract to register our new provider.
51-
let fee_in_wei = chain_config.fee;
52-
let commitment = [0; 32];
53-
// Store the random seed and chain length in the metadata field so that we can regenerate the hash
54-
// chain at-will. (This is secure because you can't generate the chain unless you also have the secret)
55-
let commitment_metadata = CommitmentMetadata {
56-
seed: random,
57-
chain_length: commitment_length,
58-
};
59-
let uri = get_register_uri(&provider_config.uri, chain_id)?;
60-
let call = contract.register(
61-
fee_in_wei,
62-
commitment,
63-
bincode::serialize(&commitment_metadata)?.into(),
64-
commitment_length,
65-
// Use Bytes to serialize the uri. Most users will be using JS/TS to deserialize this uri.
66-
// Bincode is a different encoding mechanisms, and I didn't find any JS/TS library to parse bincode.
67-
Bytes::from(uri.as_str()).into(),
68-
);
69-
let mut gas_estimate = call.estimate_gas().await?;
70-
let gas_multiplier = U256::from(2); //TODO: smarter gas estimation
71-
gas_estimate *= gas_multiplier;
72-
let call_with_gas = call.gas(gas_estimate);
73-
if let Some(r) = call_with_gas.send().await?.await? {
74-
tracing::info!("Registered provider: {:?}", r);
75-
}
41+
// TODO: implement registration for Pulse
7642

7743
Ok(())
7844
}

apps/argus/src/command/run.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use {
44
config::{Config, EthereumConfig, RunOptions},
55
keeper::{self, keeper_metrics::KeeperMetrics},
66
},
7-
fortuna::eth_utils::traced_client::{RpcMetrics, TracedClient},
87
anyhow::{anyhow, Error, Result},
98
axum::Router,
109
ethers::{
1110
middleware::Middleware,
1211
types::{Address, BlockNumber},
1312
},
13+
fortuna::eth_utils::traced_client::{RpcMetrics, TracedClient},
1414
futures::future::join_all,
1515
prometheus_client::{
1616
encoding::EncodeLabelSet,
@@ -110,12 +110,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
110110
let mut tasks = Vec::new();
111111
for (chain_id, chain_config) in config.chains.clone() {
112112
tasks.push(spawn(async move {
113-
let state = setup_chain_state(
114-
&config.provider.address,
115-
&chain_id,
116-
&chain_config,
117-
)
118-
.await;
113+
let state = setup_chain_state(&config.provider.address, &chain_id, &chain_config).await;
119114

120115
(chain_id, state)
121116
}));
@@ -183,7 +178,6 @@ async fn setup_chain_state(
183178
let state = BlockchainState {
184179
id: chain_id.clone(),
185180
provider_address: *provider,
186-
reveal_delay_blocks: chain_config.reveal_delay_blocks,
187181
confirmed_block_status: chain_config.confirmed_block_status,
188182
};
189183
Ok(state)

apps/argus/src/command/setup_provider.rs

+2-55
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use {
22
crate::{
3-
api::{get_register_uri, ChainId},
3+
api::ChainId,
44
chain::ethereum::{ProviderInfo, SignablePythContract},
55
command::register_provider::register_provider_from_config,
66
config::{Config, EthereumConfig, SetupProviderOptions},
77
},
88
anyhow::{anyhow, Result},
99
ethers::{
10-
abi::Bytes as AbiBytes,
1110
signers::{LocalWallet, Signer},
12-
types::{Address, Bytes},
11+
types::Address,
1312
},
1413
futures::future::join_all,
1514
std::sync::Arc,
@@ -88,11 +87,6 @@ async fn setup_chain_provider(
8887
.in_current_span()
8988
.await?;
9089

91-
let uri = get_register_uri(&provider_config.uri, chain_id)?;
92-
sync_uri(&contract, &provider_info, uri)
93-
.in_current_span()
94-
.await?;
95-
9690
sync_fee_manager(
9791
&contract,
9892
&provider_info,
@@ -101,34 +95,6 @@ async fn setup_chain_provider(
10195
.in_current_span()
10296
.await?;
10397

104-
sync_max_num_hashes(
105-
&contract,
106-
&provider_info,
107-
chain_config.max_num_hashes.unwrap_or(0),
108-
)
109-
.in_current_span()
110-
.await?;
111-
112-
Ok(())
113-
}
114-
115-
async fn sync_uri(
116-
contract: &Arc<SignablePythContract>,
117-
provider_info: &ProviderInfo,
118-
uri: String,
119-
) -> Result<()> {
120-
let uri_as_bytes: Bytes = AbiBytes::from(uri.as_str()).into();
121-
if provider_info.uri != uri_as_bytes {
122-
tracing::info!("Updating provider uri to {}", uri);
123-
if let Some(receipt) = contract
124-
.set_provider_uri(uri_as_bytes)
125-
.send()
126-
.await?
127-
.await?
128-
{
129-
tracing::info!("Updated provider uri: {:?}", receipt);
130-
}
131-
}
13298
Ok(())
13399
}
134100

@@ -164,22 +130,3 @@ async fn sync_fee_manager(
164130
}
165131
Ok(())
166132
}
167-
168-
async fn sync_max_num_hashes(
169-
contract: &Arc<SignablePythContract>,
170-
provider_info: &ProviderInfo,
171-
max_num_hashes: u32,
172-
) -> Result<()> {
173-
if provider_info.max_num_hashes != max_num_hashes {
174-
tracing::info!("Updating provider max num hashes to {:?}", max_num_hashes);
175-
if let Some(receipt) = contract
176-
.set_max_num_hashes(max_num_hashes)
177-
.send()
178-
.await?
179-
.await?
180-
{
181-
tracing::info!("Updated provider max num hashes to : {:?}", receipt);
182-
}
183-
}
184-
Ok(())
185-
}

apps/argus/src/config.rs

+3-35
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use {
2-
crate::{
3-
api::ChainId,
4-
chain::reader::{BlockNumber, BlockStatus},
5-
},
6-
fortuna::eth_utils::utils::EscalationPolicy,
2+
crate::{api::ChainId, chain::reader::BlockStatus},
73
anyhow::{anyhow, Result},
84
clap::{crate_authors, crate_description, crate_name, crate_version, Args, Parser},
95
ethers::types::Address,
6+
fortuna::eth_utils::utils::EscalationPolicy,
107
std::{collections::HashMap, fs},
118
};
129
pub use {
@@ -66,7 +63,7 @@ pub enum Options {
6663
pub struct ConfigOptions {
6764
/// Path to a configuration file containing the list of supported blockchains
6865
#[arg(long = "config")]
69-
#[arg(env = "FORTUNA_CONFIG")]
66+
#[arg(env = "ARGUS_CONFIG")]
7067
#[arg(default_value = "config.yaml")]
7168
pub config: String,
7269
}
@@ -117,12 +114,6 @@ pub struct EthereumConfig {
117114
/// Address of a Pyth Randomness contract to interact with.
118115
pub contract_addr: Address,
119116

120-
/// reveal_delay_blocks - The difference between the block number with the
121-
/// confirmed_block_status(see below) and the block number of a request to
122-
/// Entropy should be greater than `reveal_delay_blocks` for Fortuna to reveal
123-
/// its commitment.
124-
pub reveal_delay_blocks: BlockNumber,
125-
126117
/// The BlockStatus of the block that is considered confirmed.
127118
/// For example, Finalized, Safe, Latest
128119
#[serde(default)]
@@ -136,7 +127,6 @@ pub struct EthereumConfig {
136127
pub gas_limit: u64,
137128

138129
/// The percentage multiplier to apply to priority fee estimates (100 = no change, e.g. 150 = 150% of base fee)
139-
#[serde(default = "default_priority_fee_multiplier_pct")]
140130
pub priority_fee_multiplier_pct: u64,
141131

142132
/// The escalation policy governs how the gas limit and fee are increased during backoff retries.
@@ -171,24 +161,6 @@ pub struct EthereumConfig {
171161
/// How much the provider charges for a request on this chain.
172162
#[serde(default)]
173163
pub fee: u128,
174-
175-
/// Maximum number of hashes to record in a request.
176-
/// This should be set according to the maximum gas limit the provider supports for callbacks.
177-
pub max_num_hashes: Option<u32>,
178-
179-
/// A list of delays (in blocks) that indicates how many blocks should be delayed
180-
/// before we process a block. For retry logic, we can process blocks multiple times
181-
/// at each specified delay. For example: [5, 10, 20].
182-
#[serde(default = "default_block_delays")]
183-
pub block_delays: Vec<u64>,
184-
}
185-
186-
fn default_block_delays() -> Vec<u64> {
187-
vec![5]
188-
}
189-
190-
fn default_priority_fee_multiplier_pct() -> u64 {
191-
100
192164
}
193165

194166
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
@@ -272,10 +244,6 @@ impl EscalationPolicyConfig {
272244
/// Configuration values that are common to a single provider (and shared across chains).
273245
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
274246
pub struct ProviderConfig {
275-
/// The URI where clients can retrieve random values from this provider,
276-
/// i.e., wherever fortuna for this provider will be hosted.
277-
pub uri: String,
278-
279247
/// The public key of the provider whose requests the server will respond to.
280248
pub address: Address,
281249

0 commit comments

Comments
 (0)