Skip to content

Commit 8db7bf0

Browse files
committed
fix(kms-connector): add more logs
1 parent 62b63db commit 8db7bf0

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

  • kms-connector/simple-connector/src/gw_adapters/decryption

kms-connector/simple-connector/src/gw_adapters/decryption/adapter.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ impl<P: Provider + Clone> DecryptionAdapter<P> {
6565

6666
let contract = Decryption::new(self.decryption_address, self.provider.clone());
6767

68-
let mut call = contract
69-
.publicDecryptionResponse(id, result, signature.into())
70-
.into_transaction_request();
71-
call.gas = Some(INFINITE_GAS_LIMIT);
68+
let call_builder = contract.publicDecryptionResponse(id, result, signature.into());
69+
info!(decryption_id = ?id, "public decryption calldata length {}", call_builder.calldata().len());
70+
71+
let mut call = call_builder.into_transaction_request();
72+
self.estimate_gas(id, &mut call).await;
7273
let tx = self.send_tx_with_retry(call).await?;
7374

7475
// TODO: optimize for low latency
@@ -77,6 +78,7 @@ impl<P: Provider + Clone> DecryptionAdapter<P> {
7778
.await
7879
.map_err(|e| Error::Contract(e.to_string()))?;
7980
info!(decryption_id = ?id, "🎯 Public Decryption response sent with tx receipt: {:?}", receipt);
81+
info!(decryption_id = ?id, "⛽ Gas consumed for Public Decryption: {}", receipt.gas_used);
8082
Ok(())
8183
}
8284

@@ -110,10 +112,11 @@ impl<P: Provider + Clone> DecryptionAdapter<P> {
110112
let contract = Decryption::new(self.decryption_address, self.provider.clone());
111113

112114
// Create and send transaction
113-
let mut call = contract
114-
.userDecryptionResponse(id, result, signature.into())
115-
.into_transaction_request();
116-
call.gas = Some(INFINITE_GAS_LIMIT);
115+
let call_builder = contract.userDecryptionResponse(id, result, signature.into());
116+
info!(decryption_id = ?id, "user decryption calldata length {}", call_builder.calldata().len());
117+
118+
let mut call = call_builder.into_transaction_request();
119+
self.estimate_gas(id, &mut call).await;
117120
let tx = self.send_tx_with_retry(call).await?;
118121

119122
// TODO: optimize for low latency
@@ -122,9 +125,24 @@ impl<P: Provider + Clone> DecryptionAdapter<P> {
122125
.await
123126
.map_err(|e| Error::Contract(e.to_string()))?;
124127
info!(decryption_id = ?id, "🎯 User Decryption response sent with tx receipt: {:?}", receipt);
128+
info!(decryption_id = ?id, "⛽ Gas consumed for User Decryption: {}", receipt.gas_used);
125129
Ok(())
126130
}
127131

132+
/// Estimates the `gas_limit` for the upcoming transaction.
133+
async fn estimate_gas(&self, id: U256, call: &mut TransactionRequest) {
134+
match self.provider.estimate_gas(call.clone()).await {
135+
Ok(gas) => info!(decryption_id = ?id, "Initial gas estimation for the tx: {gas}"),
136+
Err(e) => warn!(decryption_id = ?id, "Failed to estimate gas for the tx: {e}"),
137+
}
138+
139+
// TODO: temporary workaround for out-of-gas errors
140+
// Our automatic estimation fails during gas pikes.
141+
// (see https://zama-ai.slack.com/archives/C0915Q59CKG/p1749843623276629?thread_ts=1749828466.079719&cid=C0915Q59CKG)
142+
info!(decryption_id = ?id, "Updating `gas_limit` to max value");
143+
call.gas = Some(INFINITE_GAS_LIMIT);
144+
}
145+
128146
/// Sends the requested transactions with one retry.
129147
async fn send_tx_with_retry(
130148
&self,

0 commit comments

Comments
 (0)