Skip to content

Commit 5a681d7

Browse files
authored
feat(argus): Delete hash chain logic (#2466)
* hash chain state * delete unused struct
1 parent 52d5086 commit 5a681d7

File tree

10 files changed

+12
-450
lines changed

10 files changed

+12
-450
lines changed

apps/argus/src/api.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use {
22
crate::{
33
chain::reader::{BlockNumber, BlockStatus, EntropyReader},
4-
state::HashChainState,
54
},
65
anyhow::Result,
76
axum::{
@@ -78,8 +77,6 @@ impl ApiState {
7877
pub struct BlockchainState {
7978
/// The chain id for this blockchain, useful for logging
8079
pub id: ChainId,
81-
/// The hash chain(s) required to serve random numbers for this blockchain
82-
pub state: Arc<HashChainState>,
8380
/// The contract that the server is fulfilling requests for.
8481
pub contract: Arc<dyn EntropyReader>,
8582
/// The address of the provider that this server is operating for.

apps/argus/src/command/register_provider.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use {
33
api::{get_register_uri, ChainId},
44
chain::ethereum::SignablePythContract,
55
config::{Config, EthereumConfig, ProviderConfig, RegisterProviderOptions},
6-
state::PebbleHashChain,
76
},
87
anyhow::{anyhow, Result},
98
ethers::{
109
abi::Bytes,
11-
signers::{LocalWallet, Signer},
1210
types::U256,
1311
},
1412
std::sync::Arc,
@@ -45,27 +43,13 @@ pub async fn register_provider_from_config(
4543
Arc::new(SignablePythContract::from_config(chain_config, &private_key_string).await?);
4644
// Create a new random hash chain.
4745
let random = rand::random::<[u8; 32]>();
48-
let secret = provider_config
49-
.secret
50-
.load()?
51-
.ok_or(anyhow!("Please specify a provider secret in the config"))?;
5246

53-
let commitment_length = provider_config.chain_length;
54-
tracing::info!("Generating hash chain");
55-
let chain = PebbleHashChain::from_config(
56-
&secret,
57-
chain_id,
58-
&private_key_string.parse::<LocalWallet>()?.address(),
59-
&chain_config.contract_addr,
60-
&random,
61-
commitment_length,
62-
provider_config.chain_sample_interval,
63-
)?;
64-
tracing::info!("Done generating hash chain");
47+
// FIXME: delete this
48+
let commitment_length = 1000;
6549

6650
// Arguments to the contract to register our new provider.
6751
let fee_in_wei = chain_config.fee;
68-
let commitment = chain.reveal_ith(0)?;
52+
let commitment = [0; 32];
6953
// Store the random seed and chain length in the metadata field so that we can regenerate the hash
7054
// chain at-will. (This is secure because you can't generate the chain unless you also have the secret)
7155
let commitment_metadata = CommitmentMetadata {

apps/argus/src/command/run.rs

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ use {
22
crate::{
33
api::{self, BlockchainState, ChainId},
44
chain::ethereum::InstrumentedPythContract,
5-
command::register_provider::CommitmentMetadata,
6-
config::{Commitment, Config, EthereumConfig, RunOptions},
5+
config::{Config, EthereumConfig, RunOptions},
76
keeper::{self, keeper_metrics::KeeperMetrics},
8-
state::{HashChainState, PebbleHashChain},
97
},
108
fortuna::eth_utils::traced_client::{RpcMetrics, TracedClient},
119
anyhow::{anyhow, Error, Result},
@@ -107,22 +105,16 @@ pub async fn run_keeper(
107105

108106
pub async fn run(opts: &RunOptions) -> Result<()> {
109107
let config = Config::load(&opts.config.config)?;
110-
let secret = config.provider.secret.load()?.ok_or(anyhow!(
111-
"Please specify a provider secret in the config file."
112-
))?;
113108
let (tx_exit, rx_exit) = watch::channel(false);
114109
let metrics_registry = Arc::new(RwLock::new(Registry::default()));
115110
let rpc_metrics = Arc::new(RpcMetrics::new(metrics_registry.clone()).await);
116111

117112
let mut tasks = Vec::new();
118113
for (chain_id, chain_config) in config.chains.clone() {
119-
let secret_copy = secret.clone();
120114
let rpc_metrics = rpc_metrics.clone();
121115
tasks.push(spawn(async move {
122116
let state = setup_chain_state(
123117
&config.provider.address,
124-
&secret_copy,
125-
config.provider.chain_sample_interval,
126118
&chain_id,
127119
&chain_config,
128120
rpc_metrics,
@@ -189,8 +181,6 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
189181

190182
async fn setup_chain_state(
191183
provider: &Address,
192-
secret: &str,
193-
chain_sample_interval: u64,
194184
chain_id: &ChainId,
195185
chain_config: &EthereumConfig,
196186
rpc_metrics: Arc<RpcMetrics>,
@@ -200,80 +190,9 @@ async fn setup_chain_state(
200190
chain_id.clone(),
201191
rpc_metrics,
202192
)?);
203-
let mut provider_commitments = chain_config.commitments.clone().unwrap_or_default();
204-
provider_commitments.sort_by(|c1, c2| {
205-
c1.original_commitment_sequence_number
206-
.cmp(&c2.original_commitment_sequence_number)
207-
});
208-
209-
let provider_info = contract.get_provider_info(*provider).call().await?;
210-
let latest_metadata = bincode::deserialize::<CommitmentMetadata>(
211-
&provider_info.commitment_metadata,
212-
)
213-
.map_err(|e| {
214-
anyhow!(
215-
"Chain: {} - Failed to deserialize commitment metadata: {}",
216-
&chain_id,
217-
e
218-
)
219-
})?;
220-
221-
let last_prior_commitment = provider_commitments.last();
222-
if last_prior_commitment.is_some()
223-
&& last_prior_commitment
224-
.unwrap()
225-
.original_commitment_sequence_number
226-
>= provider_info.original_commitment_sequence_number
227-
{
228-
return Err(anyhow!("The current hash chain for chain id {} has configured commitments for sequence numbers greater than the current on-chain sequence number. Are the commitments configured correctly?", &chain_id));
229-
}
230-
231-
provider_commitments.push(Commitment {
232-
seed: latest_metadata.seed,
233-
chain_length: latest_metadata.chain_length,
234-
original_commitment_sequence_number: provider_info.original_commitment_sequence_number,
235-
});
236-
237-
// TODO: we may want to load the hash chain in a lazy/fault-tolerant way. If there are many blockchains,
238-
// then it's more likely that some RPC fails. We should tolerate these faults and generate the hash chain
239-
// later when a user request comes in for that chain.
240-
241-
let mut offsets = Vec::<usize>::new();
242-
let mut hash_chains = Vec::<PebbleHashChain>::new();
243-
244-
for commitment in &provider_commitments {
245-
let offset = commitment.original_commitment_sequence_number.try_into()?;
246-
offsets.push(offset);
247-
248-
let pebble_hash_chain = PebbleHashChain::from_config(
249-
secret,
250-
chain_id,
251-
provider,
252-
&chain_config.contract_addr,
253-
&commitment.seed,
254-
commitment.chain_length,
255-
chain_sample_interval,
256-
)
257-
.map_err(|e| anyhow!("Failed to create hash chain: {}", e))?;
258-
hash_chains.push(pebble_hash_chain);
259-
}
260-
261-
let chain_state = HashChainState {
262-
offsets,
263-
hash_chains,
264-
};
265-
266-
if chain_state.reveal(provider_info.original_commitment_sequence_number)?
267-
!= provider_info.original_commitment
268-
{
269-
return Err(anyhow!("The root of the generated hash chain for chain id {} does not match the commitment. Are the secret and chain length configured correctly?", &chain_id));
270-
} else {
271-
tracing::info!("Root of chain id {} matches commitment", &chain_id);
272-
}
273193

274194
let state = BlockchainState {
275195
id: chain_id.clone(),
276-
state: Arc::new(chain_state),
277196
contract,
278197
provider_address: *provider,
279198
reveal_delay_blocks: chain_config.reveal_delay_blocks,

apps/argus/src/command/setup_provider.rs

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use {
22
crate::{
33
api::{get_register_uri, ChainId},
44
chain::ethereum::{ProviderInfo, SignablePythContract},
5-
command::register_provider::{register_provider_from_config, CommitmentMetadata},
5+
command::register_provider::register_provider_from_config,
66
config::{Config, EthereumConfig, SetupProviderOptions},
7-
state::{HashChainState, PebbleHashChain},
87
},
98
anyhow::{anyhow, Result},
109
ethers::{
@@ -56,8 +55,6 @@ pub async fn setup_provider(opts: &SetupProviderOptions) -> Result<()> {
5655

5756
/// Setup provider for a single chain.
5857
/// 1. Register if there was no previous registration.
59-
/// 2. Re-register if there are no more random numbers to request on the contract.
60-
/// 3. Re-register if there is a mismatch in generated hash chain.
6158
/// 4. Update provider fee if there is a mismatch with the fee set on contract.
6259
/// 5. Update provider uri if there is a mismatch with the uri set on contract.
6360
#[tracing::instrument(name = "setup_chain_provider", skip_all, fields(chain_id = chain_id))]
@@ -79,72 +76,11 @@ async fn setup_chain_provider(
7976
let provider_info = contract.get_provider_info(provider_address).call().await?;
8077
tracing::info!("Provider info: {:?}", provider_info);
8178

82-
let mut register = false;
83-
84-
// This condition satisfies for both when there is no registration and when there are no
85-
// more random numbers left to request
86-
if provider_info.end_sequence_number <= provider_info.sequence_number {
87-
tracing::info!(
88-
"endSequenceNumber <= sequenceNumber. endSequenceNumber={}, sequenceNumber={}",
89-
provider_info.end_sequence_number,
90-
provider_info.sequence_number
91-
);
92-
register = true;
93-
} else {
94-
let metadata =
95-
bincode::deserialize::<CommitmentMetadata>(&provider_info.commitment_metadata)
96-
.map_err(|e| {
97-
anyhow!(
98-
"Chain: {} - Failed to deserialize commitment metadata: {}",
99-
&chain_id,
100-
e
101-
)
102-
})?;
103-
104-
let secret = provider_config.secret.load()?.ok_or(anyhow!(
105-
"Please specify a provider secret in the config file."
106-
))?;
107-
if metadata.chain_length != provider_config.chain_length {
108-
tracing::info!(
109-
"Chain length mismatch. metadata.chain_length={}, provider_config.chain_length={}",
110-
metadata.chain_length,
111-
provider_config.chain_length
112-
);
113-
register = true;
114-
} else {
115-
let hash_chain = PebbleHashChain::from_config(
116-
&secret,
117-
chain_id,
118-
&provider_address,
119-
&chain_config.contract_addr,
120-
&metadata.seed,
121-
provider_config.chain_length,
122-
provider_config.chain_sample_interval,
123-
)?;
124-
let chain_state = HashChainState {
125-
offsets: vec![provider_info
126-
.original_commitment_sequence_number
127-
.try_into()?],
128-
hash_chains: vec![hash_chain],
129-
};
130-
131-
if chain_state.reveal(provider_info.original_commitment_sequence_number)?
132-
!= provider_info.original_commitment
133-
{
134-
tracing::info!(
135-
"The root of the generated hash chain does not match the commitment",
136-
);
137-
register = true;
138-
}
139-
}
140-
}
141-
if register {
142-
tracing::info!("Registering");
143-
register_provider_from_config(provider_config, chain_id, chain_config)
144-
.await
145-
.map_err(|e| anyhow!("Chain: {} - Failed to register provider: {}", &chain_id, e))?;
146-
tracing::info!("Registered");
147-
}
79+
tracing::info!("Registering");
80+
register_provider_from_config(provider_config, chain_id, chain_config)
81+
.await
82+
.map_err(|e| anyhow!("Chain: {} - Failed to register provider: {}", &chain_id, e))?;
83+
tracing::info!("Registered");
14884

14985
let provider_info = contract.get_provider_info(provider_address).call().await?;
15086

apps/argus/src/config.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ pub struct EthereumConfig {
172172
#[serde(default)]
173173
pub fee: u128,
174174

175-
/// Historical commitments made by the provider.
176-
pub commitments: Option<Vec<Commitment>>,
177-
178175
/// Maximum number of hashes to record in a request.
179176
/// This should be set according to the maximum gas limit the provider supports for callbacks.
180177
pub max_num_hashes: Option<u32>,
@@ -272,17 +269,6 @@ impl EscalationPolicyConfig {
272269
}
273270
}
274271

275-
/// A commitment that the provider used to generate random numbers at some point in the past.
276-
/// These historical commitments need to be stored in the configuration to support transition points where
277-
/// the commitment changes. In theory, this information is stored on the blockchain, but unfortunately it
278-
/// is hard to retrieve from there.
279-
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
280-
pub struct Commitment {
281-
pub seed: [u8; 32],
282-
pub chain_length: u64,
283-
pub original_commitment_sequence_number: u64,
284-
}
285-
286272
/// Configuration values that are common to a single provider (and shared across chains).
287273
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
288274
pub struct ProviderConfig {
@@ -298,27 +284,11 @@ pub struct ProviderConfig {
298284
/// the private key (e.g., running the server).
299285
pub private_key: SecretString,
300286

301-
/// The provider's secret which is a 64-char hex string.
302-
/// The secret is used for generating new hash chains
303-
pub secret: SecretString,
304-
305-
/// The length of the hash chain to generate.
306-
pub chain_length: u64,
307-
308-
/// How frequently the hash chain is sampled -- increase this value to tradeoff more
309-
/// compute per request for less RAM use.
310-
#[serde(default = "default_chain_sample_interval")]
311-
pub chain_sample_interval: u64,
312-
313287
/// The address of the fee manager for the provider. Set this value to the keeper wallet address to
314288
/// enable keeper balance top-ups.
315289
pub fee_manager: Option<Address>,
316290
}
317291

318-
fn default_chain_sample_interval() -> u64 {
319-
1
320-
}
321-
322292
/// Configuration values for the keeper service that are shared across chains.
323293
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
324294
pub struct KeeperConfig {

apps/argus/src/keeper.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use {
77
get_latest_safe_block, process_backlog, process_new_blocks, watch_blocks_wrapper,
88
BlockRange,
99
},
10-
keeper::commitment::update_commitments_loop,
1110
keeper::fee::adjust_fee_wrapper,
1211
keeper::fee::withdraw_fees_wrapper,
1312
keeper::track::track_accrued_pyth_fees,
@@ -27,7 +26,6 @@ use {
2726
};
2827

2928
pub(crate) mod block;
30-
pub(crate) mod commitment;
3129
pub(crate) mod fee;
3230
pub(crate) mod keeper_metrics;
3331
pub(crate) mod process_event;
@@ -166,8 +164,6 @@ pub async fn run_keeper_threads(
166164
.in_current_span(),
167165
);
168166

169-
spawn(update_commitments_loop(contract.clone(), chain_state.clone()).in_current_span());
170-
171167
// Spawn a thread to track the provider info and the balance of the keeper
172168
spawn(
173169
async move {

0 commit comments

Comments
 (0)