Skip to content

Commit dde3788

Browse files
committed
address review feedback: type alias, flush_metrics, tx-senders signature
- Add `type CiphertextDigest = FixedBytes<32>` to avoid literal 32 - Document implicit upper bound on open_handles - Remove redundant early-return guard in flush_metrics - fetch_expected_coprocessor_tx_senders now requires gateway_config_address parameter; caller decides whether to call based on config
1 parent b88641d commit dde3788

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ pub(crate) struct EventContext {
2121
pub(crate) log_index: Option<u64>,
2222
}
2323

24+
type CiphertextDigest = FixedBytes<32>;
25+
2426
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
2527
struct DigestPair {
26-
ciphertext_digest: FixedBytes<32>,
27-
ciphertext128_digest: FixedBytes<32>,
28+
ciphertext_digest: CiphertextDigest,
29+
ciphertext128_digest: CiphertextDigest,
2830
}
2931

3032
#[derive(Clone, Copy, Debug)]
@@ -77,7 +79,11 @@ enum HandleDisposition {
7779

7880
pub(crate) struct DriftDetector {
7981
current_expected_senders: Vec<Address>,
80-
open_handles: HashMap<FixedBytes<32>, HandleState>,
82+
/// Handles waiting for consensus or post-consensus grace. Bounded implicitly:
83+
/// `evict_stale` removes entries after `no_consensus_timeout_blocks` (no consensus)
84+
/// or `post_consensus_grace_blocks` (consensus reached). Steady-state size is
85+
/// proportional to handle throughput * max(timeout, grace) in blocks.
86+
open_handles: HashMap<CiphertextDigest, HandleState>,
8187
host_chain_id: ChainId,
8288
local_node_id: String,
8389
no_consensus_timeout_blocks: u64,
@@ -250,7 +256,7 @@ impl DriftDetector {
250256

251257
async fn try_check_local_consensus(
252258
&mut self,
253-
handle: FixedBytes<32>,
259+
handle: CiphertextDigest,
254260
db_pool: &Pool<Postgres>,
255261
) -> anyhow::Result<()> {
256262
if self.replaying {
@@ -437,13 +443,6 @@ impl DriftDetector {
437443
}
438444

439445
pub(crate) fn flush_metrics(&mut self) {
440-
if self.deferred_drift_detected == 0
441-
&& self.deferred_consensus_timeout == 0
442-
&& self.deferred_missing_submission == 0
443-
{
444-
return;
445-
}
446-
447446
DRIFT_DETECTED_COUNTER.inc_by(self.deferred_drift_detected);
448447
CONSENSUS_TIMEOUT_COUNTER.inc_by(self.deferred_consensus_timeout);
449448
MISSING_SUBMISSION_COUNTER.inc_by(self.deferred_missing_submission);
@@ -545,7 +544,7 @@ impl DriftDetector {
545544
}
546545
}
547546

548-
fn finish_if_complete(&mut self, handle: FixedBytes<32>) {
547+
fn finish_if_complete(&mut self, handle: CiphertextDigest) {
549548
let Some(state) = self.open_handles.get(&handle) else {
550549
return;
551550
};
@@ -742,9 +741,9 @@ mod tests {
742741
}
743742

744743
fn make_submission_event(
745-
handle: FixedBytes<32>,
746-
ciphertext_digest: FixedBytes<32>,
747-
ciphertext128_digest: FixedBytes<32>,
744+
handle: CiphertextDigest,
745+
ciphertext_digest: CiphertextDigest,
746+
ciphertext128_digest: CiphertextDigest,
748747
sender: Address,
749748
) -> CiphertextCommits::AddCiphertextMaterial {
750749
CiphertextCommits::AddCiphertextMaterial {
@@ -757,9 +756,9 @@ mod tests {
757756
}
758757

759758
fn make_consensus_event(
760-
handle: FixedBytes<32>,
761-
ciphertext_digest: FixedBytes<32>,
762-
ciphertext128_digest: FixedBytes<32>,
759+
handle: CiphertextDigest,
760+
ciphertext_digest: CiphertextDigest,
761+
ciphertext128_digest: CiphertextDigest,
763762
senders: Vec<Address>,
764763
) -> CiphertextCommits::AddCiphertextMaterialConsensus {
765764
CiphertextCommits::AddCiphertextMaterialConsensus {
@@ -782,9 +781,9 @@ mod tests {
782781

783782
fn submit_digest_event_and_drift_check(
784783
d: &mut DriftDetector,
785-
handle: FixedBytes<32>,
786-
ct: impl Into<FixedBytes<32>>,
787-
ct128: impl Into<FixedBytes<32>>,
784+
handle: CiphertextDigest,
785+
ct: impl Into<CiphertextDigest>,
786+
ct128: impl Into<CiphertextDigest>,
788787
sender: Address,
789788
block: u64,
790789
) {
@@ -808,8 +807,8 @@ mod tests {
808807

809808
fn make_consensus_state(
810809
block_number: u64,
811-
ciphertext_digest: FixedBytes<32>,
812-
ciphertext128_digest: FixedBytes<32>,
810+
ciphertext_digest: CiphertextDigest,
811+
ciphertext128_digest: CiphertextDigest,
813812
senders: Vec<Address>,
814813
) -> ConsensusState {
815814
ConsensusState {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ impl<P: Provider<Ethereum> + Clone + 'static, A: AwsS3Interface + Clone + 'stati
155155
let sender_seed_block = replay_start_block
156156
.map(|block| block.saturating_sub(1))
157157
.or(last_processed_block_num);
158-
let expected_coprocessor_tx_senders = self
159-
.fetch_expected_coprocessor_tx_senders(sender_seed_block)
160-
.await?;
158+
let expected_coprocessor_tx_senders =
159+
if let Some(gw_config_addr) = self.conf.gateway_config_address {
160+
self.fetch_expected_coprocessor_tx_senders(gw_config_addr, sender_seed_block)
161+
.await?
162+
} else {
163+
Vec::new()
164+
};
161165
let mut drift_detector = DriftDetector::new(
162166
expected_coprocessor_tx_senders,
163167
self.conf.host_chain_id,
@@ -371,12 +375,9 @@ impl<P: Provider<Ethereum> + Clone + 'static, A: AwsS3Interface + Clone + 'stati
371375

372376
async fn fetch_expected_coprocessor_tx_senders(
373377
&self,
378+
gateway_config_address: Address,
374379
at_block: Option<u64>,
375380
) -> anyhow::Result<Vec<Address>> {
376-
let Some(gateway_config_address) = self.conf.gateway_config_address else {
377-
return Ok(Vec::new());
378-
};
379-
380381
let gateway_config = GatewayConfig::new(gateway_config_address, self.provider.clone());
381382
let call = gateway_config.getCoprocessorTxSenders();
382383
let expected_coprocessor_tx_senders = match at_block {

0 commit comments

Comments
 (0)