Skip to content

Commit 4d6e8a1

Browse files
committed
refactor(coprocessor): fetch expected senders from gateway config
1 parent 8cd6781 commit 4d6e8a1

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

coprocessor/fhevm-engine/gw-listener/src/bin/gw_listener.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ struct Conf {
9494
ciphertext_commits_address: Option<Address>,
9595

9696
#[arg(
97-
long = "expected-coprocessor-tx-sender",
97+
long,
9898
requires = "ciphertext_commits_address",
99-
help = "Expected coprocessor tx-sender address. Repeat once per coprocessor."
99+
help = "GatewayConfig contract address used to fetch coprocessor tx-senders"
100100
)]
101-
expected_coprocessor_tx_senders: Vec<Address>,
101+
gateway_config_address: Option<Address>,
102102

103103
#[arg(
104104
long,
@@ -182,10 +182,9 @@ async fn main() -> anyhow::Result<()> {
182182
else {
183183
anyhow::bail!("--host-chain-id or CHAIN_ID env var is missing.")
184184
};
185-
if conf.ciphertext_commits_address.is_some() && conf.expected_coprocessor_tx_senders.is_empty()
186-
{
185+
if conf.ciphertext_commits_address.is_some() && conf.gateway_config_address.is_none() {
187186
anyhow::bail!(
188-
"--expected-coprocessor-tx-sender is required when --ciphertext-commits-address is set."
187+
"--gateway-config-address is required when --ciphertext-commits-address is set."
189188
);
190189
}
191190
let config = ConfigSettings {
@@ -204,7 +203,7 @@ async fn main() -> anyhow::Result<()> {
204203
replay_skip_verify_proof: conf.replay_skip_verify_proof,
205204
log_last_processed_every_number_of_updates: conf.log_last_processed_every_number_of_updates,
206205
ciphertext_commits_address: conf.ciphertext_commits_address,
207-
expected_coprocessor_tx_senders: conf.expected_coprocessor_tx_senders,
206+
gateway_config_address: conf.gateway_config_address,
208207
drift_no_consensus_timeout_blocks: conf.drift_no_consensus_timeout_blocks,
209208
drift_post_consensus_grace_blocks: conf.drift_post_consensus_grace_blocks,
210209
};

coprocessor/fhevm-engine/gw-listener/src/gw_listener.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::KeyType;
2929
use fhevm_engine_common::chain_id::ChainId;
3030

3131
use fhevm_gateway_bindings::ciphertext_commits::CiphertextCommits;
32+
use fhevm_gateway_bindings::gateway_config::GatewayConfig;
3233
use fhevm_gateway_bindings::input_verification::InputVerification;
3334
use fhevm_gateway_bindings::kms_generation::KMSGeneration;
3435

@@ -129,8 +130,9 @@ impl<P: Provider<Ethereum> + Clone + 'static, A: AwsS3Interface + Clone + 'stati
129130
let mut ticker = tokio::time::interval(self.conf.get_logs_poll_interval);
130131
let mut last_processed_block_num = self.get_last_processed_block_num(db_pool).await?;
131132
let mut number_of_last_processed_updates: u64 = 0;
133+
let expected_coprocessor_tx_senders = self.fetch_expected_coprocessor_tx_senders().await?;
132134
let mut drift_detector = DriftDetector::new(
133-
self.conf.expected_coprocessor_tx_senders.clone(),
135+
expected_coprocessor_tx_senders,
134136
self.conf.host_chain_id,
135137
self.conf.drift_no_consensus_timeout_blocks,
136138
self.conf.drift_post_consensus_grace_blocks,
@@ -334,6 +336,24 @@ impl<P: Provider<Ethereum> + Clone + 'static, A: AwsS3Interface + Clone + 'stati
334336
Ok(())
335337
}
336338

339+
async fn fetch_expected_coprocessor_tx_senders(&self) -> anyhow::Result<Vec<Address>> {
340+
let Some(gateway_config_address) = self.conf.gateway_config_address else {
341+
return Ok(Vec::new());
342+
};
343+
344+
let expected_coprocessor_tx_senders =
345+
GatewayConfig::new(gateway_config_address, self.provider.clone())
346+
.getCoprocessorTxSenders()
347+
.call()
348+
.await?;
349+
350+
if expected_coprocessor_tx_senders.is_empty() {
351+
anyhow::bail!("GatewayConfig returned no coprocessor tx-senders");
352+
}
353+
354+
Ok(expected_coprocessor_tx_senders)
355+
}
356+
337357
async fn verify_proof_request(
338358
&self,
339359
db_pool: &Pool<Postgres>,

coprocessor/fhevm-engine/gw-listener/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct ConfigSettings {
5858
pub log_last_processed_every_number_of_updates: u64,
5959

6060
pub ciphertext_commits_address: Option<Address>,
61-
pub expected_coprocessor_tx_senders: Vec<Address>,
61+
pub gateway_config_address: Option<Address>,
6262
pub drift_no_consensus_timeout_blocks: u64,
6363
pub drift_post_consensus_grace_blocks: u64,
6464
}
@@ -96,7 +96,7 @@ impl Default for ConfigSettings {
9696
replay_skip_verify_proof: false,
9797
log_last_processed_every_number_of_updates: 50,
9898
ciphertext_commits_address: None,
99-
expected_coprocessor_tx_senders: Vec::new(),
99+
gateway_config_address: None,
100100
drift_no_consensus_timeout_blocks: 50,
101101
drift_post_consensus_grace_blocks: 10,
102102
}

0 commit comments

Comments
 (0)