Skip to content

Commit 38a7952

Browse files
committed
refactor: simplify coprocessor config terminal errors
1 parent b471693 commit 38a7952

File tree

10 files changed

+61
-70
lines changed

10 files changed

+61
-70
lines changed

coprocessor/fhevm-engine/transaction-sender/src/ops/add_ciphertext.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ where
7575
return Ok(());
7676
}
7777
Err(e) => {
78-
if let Some(terminal_error) = try_extract_terminal_config_error(&e) {
78+
if let Some(terminal_config_error) = try_extract_terminal_config_error(&e) {
7979
ADD_CIPHERTEXT_MATERIAL_FAIL_COUNTER.inc();
8080
error!(
81-
error = %terminal_error.config_error,
81+
error = %terminal_config_error,
8282
handle = h,
8383
"Detected non-retryable gateway coprocessor config error while adding ciphertext"
8484
);
8585
self.mark_add_ciphertext_terminal_config_error(
8686
handle,
87-
&terminal_error.db_error,
87+
&terminal_config_error.to_string(),
8888
)
8989
.await?;
9090
return Ok(());
@@ -154,16 +154,16 @@ where
154154
)
155155
.await
156156
{
157-
Ok(terminal_error) => {
157+
Ok(terminal_config_error) => {
158158
error!(
159-
error = %terminal_error.config_error,
159+
error = %terminal_config_error,
160160
transaction_hash = %receipt.transaction_hash,
161161
handle = h,
162162
"Terminalizing addCiphertext due to gateway coprocessor config error from debug trace"
163163
);
164164
self.mark_add_ciphertext_terminal_config_error(
165165
handle,
166-
&terminal_error.db_error,
166+
&terminal_config_error.to_string(),
167167
)
168168
.await?;
169169
return Ok(());

coprocessor/fhevm-engine/transaction-sender/src/ops/allow_handle.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,18 @@ where
100100
return Ok(());
101101
}
102102
Err(e) => {
103-
if let Some(terminal_error) = try_extract_terminal_config_error(&e) {
103+
if let Some(terminal_config_error) = try_extract_terminal_config_error(&e) {
104104
ALLOW_HANDLE_FAIL_COUNTER.inc();
105105
error!(
106-
error = %terminal_error.config_error,
106+
error = %terminal_config_error,
107107
key = %key,
108108
"Detected non-retryable gateway coprocessor config error while allowing handle"
109109
);
110-
self.mark_allow_handle_terminal_config_error(key, &terminal_error.db_error)
111-
.await?;
110+
self.mark_allow_handle_terminal_config_error(
111+
key,
112+
&terminal_config_error.to_string(),
113+
)
114+
.await?;
112115
return Ok(());
113116
}
114117
// Consider transport retryable errors, BackendGone and local usage errors as something that must be retried infinitely.
@@ -177,15 +180,18 @@ where
177180
)
178181
.await
179182
{
180-
Ok(terminal_error) => {
183+
Ok(terminal_config_error) => {
181184
error!(
182-
error = %terminal_error.config_error,
185+
error = %terminal_config_error,
183186
transaction_hash = %receipt.transaction_hash,
184187
key = %key,
185188
"Terminalizing allow_handle due to gateway coprocessor config error from debug trace"
186189
);
187-
self.mark_allow_handle_terminal_config_error(key, &terminal_error.db_error)
188-
.await?;
190+
self.mark_allow_handle_terminal_config_error(
191+
key,
192+
&terminal_config_error.to_string(),
193+
)
194+
.await?;
189195
return Ok(());
190196
}
191197
Err(reason) => {

coprocessor/fhevm-engine/transaction-sender/src/ops/common.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,13 @@ pub(crate) fn try_into_array<const SIZE: usize>(vec: Vec<u8>) -> Result<[u8; SIZ
2828
.map_err(|_| anyhow!("Failed to convert Vec to array"))
2929
}
3030

31-
#[derive(Clone, Debug, PartialEq, Eq)]
32-
pub(crate) struct TerminalConfigError {
33-
pub(crate) config_error: CoprocessorConfigError,
34-
pub(crate) db_error: String,
35-
}
36-
3731
#[derive(Clone, Debug, PartialEq, Eq)]
3832
pub(crate) enum CoprocessorConfigError {
3933
NotCoprocessorSigner(Address),
4034
NotCoprocessorTxSender(Address),
4135
CoprocessorSignerDoesNotMatchTxSender { signer: Address, tx_sender: Address },
4236
}
4337

44-
impl CoprocessorConfigError {
45-
pub(crate) fn to_db_error_string(&self) -> String {
46-
format!("gw: {self}")
47-
}
48-
}
49-
50-
impl From<CoprocessorConfigError> for TerminalConfigError {
51-
fn from(config_error: CoprocessorConfigError) -> Self {
52-
Self {
53-
db_error: config_error.to_db_error_string(),
54-
config_error,
55-
}
56-
}
57-
}
58-
5938
impl Display for CoprocessorConfigError {
6039
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6140
match self {
@@ -108,15 +87,15 @@ fn try_decode_coprocessor_config_error(
10887

10988
pub(crate) fn try_extract_terminal_config_error(
11089
err: &RpcError<TransportErrorKind>,
111-
) -> Option<TerminalConfigError> {
112-
try_decode_coprocessor_config_error(err).map(Into::into)
90+
) -> Option<CoprocessorConfigError> {
91+
try_decode_coprocessor_config_error(err)
11392
}
11493

11594
pub(crate) async fn classify_failed_receipt<P>(
11695
provider: &NonceManagedProvider<P>,
11796
receipt: &TransactionReceipt,
11897
trace_timeout: Duration,
119-
) -> std::result::Result<TerminalConfigError, String>
98+
) -> std::result::Result<CoprocessorConfigError, String>
12099
where
121100
P: Provider<Ethereum> + Clone + 'static,
122101
{
@@ -150,7 +129,7 @@ where
150129
};
151130

152131
if let Some(config_error) = find_config_error_in_trace(&call_frame) {
153-
return Ok(config_error.into());
132+
return Ok(config_error);
154133
}
155134

156135
Err(

coprocessor/fhevm-engine/transaction-sender/src/ops/delegate_user_decrypt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ impl<P: Provider<Ethereum> + Clone + 'static> DelegateUserDecryptOperation<P> {
150150
return TxResult::IdemPotentError;
151151
}
152152
Err(error) => {
153-
if let Some(terminal_error) = try_extract_terminal_config_error(&error) {
153+
if let Some(terminal_config_error) = try_extract_terminal_config_error(&error) {
154154
error!(
155-
error = %terminal_error.config_error,
155+
error = %terminal_config_error,
156156
?delegation,
157157
"{operation} failed with non-retryable gateway coprocessor config error"
158158
);
159-
return TxResult::NonRetryableError(terminal_error.db_error);
159+
return TxResult::NonRetryableError(terminal_config_error.to_string());
160160
}
161161
if is_transient_error(&error) {
162162
warn!(
@@ -198,14 +198,14 @@ impl<P: Provider<Ethereum> + Clone + 'static> DelegateUserDecryptOperation<P> {
198198
)
199199
.await
200200
{
201-
Ok(terminal_error) => {
201+
Ok(terminal_config_error) => {
202202
error!(
203-
error = %terminal_error.config_error,
203+
error = %terminal_config_error,
204204
?delegation,
205205
transaction_hash = %receipt.transaction_hash,
206206
"{operation} terminalized after debug trace matched gateway coprocessor config error"
207207
);
208-
TxResult::NonRetryableError(terminal_error.db_error)
208+
TxResult::NonRetryableError(terminal_config_error.to_string())
209209
}
210210
Err(reason) => TxResult::OtherError(reason),
211211
}

coprocessor/fhevm-engine/transaction-sender/src/ops/verify_proof.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ where
160160
);
161161
self.remove_proof_by_id(txn_request.0).await?;
162162
return Ok(());
163-
} else if let Some(terminal_error) = try_extract_terminal_config_error(&e) {
163+
} else if let Some(terminal_config_error) = try_extract_terminal_config_error(&e) {
164164
VERIFY_PROOF_FAIL_COUNTER.inc();
165165
error!(
166166
zk_proof_id = txn_request.0,
167-
error = %terminal_error.config_error,
167+
error = %terminal_config_error,
168168
"Detected non-retryable gateway coprocessor config error while sending verify_proof transaction"
169169
);
170170
self.mark_verify_proof_terminal_config_error(
171171
txn_request.0,
172-
&terminal_error.db_error,
172+
&terminal_config_error.to_string(),
173173
)
174174
.await?;
175175
return Ok(());
@@ -220,16 +220,16 @@ where
220220
)
221221
.await
222222
{
223-
Ok(terminal_error) => {
223+
Ok(terminal_config_error) => {
224224
error!(
225225
zk_proof_id = txn_request.0,
226226
transaction_hash = %receipt.transaction_hash,
227-
error = %terminal_error.config_error,
227+
error = %terminal_config_error,
228228
"Terminalizing verify_proof due to gateway coprocessor config error from debug trace"
229229
);
230230
self.mark_verify_proof_terminal_config_error(
231231
txn_request.0,
232-
&terminal_error.db_error,
232+
&terminal_config_error.to_string(),
233233
)
234234
.await?;
235235
return Ok(());

coprocessor/fhevm-engine/transaction-sender/tests/add_ciphertext_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy::network::TxSigner;
44
use alloy::primitives::{FixedBytes, U256};
55
use alloy::providers::{Provider, ProviderBuilder, WsConnect};
66
use alloy::signers::local::PrivateKeySigner;
7-
use common::{CiphertextCommits, TestEnvironment};
7+
use common::{is_coprocessor_config_error, CiphertextCommits, TestEnvironment};
88

99
use common::SignerType;
1010
use rand::{random, Rng};
@@ -709,7 +709,7 @@ async fn add_ciphertext_terminal_on_gw_config_error(
709709
&& txn_limited_retries_count == conf.add_ciphertexts_max_retries
710710
&& txn_last_error
711711
.as_deref()
712-
.is_some_and(|err| err.starts_with("gw: "))
712+
.is_some_and(is_coprocessor_config_error)
713713
{
714714
break;
715715
}
@@ -732,8 +732,8 @@ async fn add_ciphertext_terminal_on_gw_config_error(
732732
assert!(
733733
txn_last_error
734734
.as_deref()
735-
.is_some_and(|err| err.starts_with("gw: ")),
736-
"Expected gw-prefixed terminal error, got {:?}",
735+
.is_some_and(is_coprocessor_config_error),
736+
"Expected terminal gateway config error, got {:?}",
737737
txn_last_error
738738
);
739739

@@ -861,7 +861,7 @@ async fn add_ciphertext_terminal_on_gw_config_error_after_mined_revert(
861861
&& txn_limited_retries_count == conf.add_ciphertexts_max_retries
862862
&& txn_last_error
863863
.as_deref()
864-
.is_some_and(|err| err.starts_with("gw: "))
864+
.is_some_and(is_coprocessor_config_error)
865865
{
866866
break;
867867
}
@@ -884,8 +884,8 @@ async fn add_ciphertext_terminal_on_gw_config_error_after_mined_revert(
884884
assert!(
885885
txn_last_error
886886
.as_deref()
887-
.is_some_and(|err| err.starts_with("gw: ")),
888-
"Expected gw-prefixed terminal error from trace classification, got {:?}",
887+
.is_some_and(is_coprocessor_config_error),
888+
"Expected terminal gateway config error from trace classification, got {:?}",
889889
txn_last_error
890890
);
891891

coprocessor/fhevm-engine/transaction-sender/tests/allow_handle_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloy::network::TxSigner;
22
use alloy::providers::{Provider, ProviderBuilder};
33
use alloy::signers::local::PrivateKeySigner;
44
use alloy::{primitives::Address, providers::WsConnect};
5-
use common::{MultichainACL, SignerType, TestEnvironment};
5+
use common::{is_coprocessor_config_error, MultichainACL, SignerType, TestEnvironment};
66

77
use fhevm_engine_common::types::AllowEvents;
88
use rand::random;
@@ -476,7 +476,7 @@ async fn allow_handle_terminal_on_gw_config_error(
476476
&& txn_limited_retries_count == conf.allow_handle_max_retries
477477
&& txn_last_error
478478
.as_deref()
479-
.is_some_and(|err| err.starts_with("gw: "))
479+
.is_some_and(is_coprocessor_config_error)
480480
{
481481
break;
482482
}
@@ -499,8 +499,8 @@ async fn allow_handle_terminal_on_gw_config_error(
499499
assert!(
500500
txn_last_error
501501
.as_deref()
502-
.is_some_and(|err| err.starts_with("gw: ")),
503-
"Expected gw-prefixed terminal error, got {:?}",
502+
.is_some_and(is_coprocessor_config_error),
503+
"Expected terminal gateway config error, got {:?}",
504504
txn_last_error
505505
);
506506

coprocessor/fhevm-engine/transaction-sender/tests/common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub enum SignerType {
4444
AwsKms,
4545
}
4646

47+
pub fn is_coprocessor_config_error(err: &str) -> bool {
48+
err.starts_with("NotCoprocessorSigner(")
49+
|| err.starts_with("NotCoprocessorTxSender(")
50+
|| err.starts_with("CoprocessorSignerDoesNotMatchTxSender(")
51+
}
52+
4753
pub struct TestEnvironment {
4854
pub signer: AbstractSigner,
4955
pub conf: ConfigSettings,

coprocessor/fhevm-engine/transaction-sender/tests/delegate_user_decrypt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alloy::network::TxSigner;
33
use alloy::providers::{Provider, ProviderBuilder};
44
use alloy::signers::local::PrivateKeySigner;
55
use alloy::{primitives::Address, providers::WsConnect};
6-
use common::{MultichainACL, SignerType, TestEnvironment};
6+
use common::{is_coprocessor_config_error, MultichainACL, SignerType, TestEnvironment};
77

88
use rstest::*;
99
use serial_test::serial;
@@ -480,7 +480,7 @@ async fn delegate_user_decrypt_terminal_on_gw_config_error(
480480
&& gateway_nb_attempts == (config.delegation_max_retry + 1) as i64
481481
&& gateway_last_error
482482
.as_deref()
483-
.is_some_and(|err| err.starts_with("gw: "))
483+
.is_some_and(is_coprocessor_config_error)
484484
{
485485
break;
486486
}
@@ -506,8 +506,8 @@ async fn delegate_user_decrypt_terminal_on_gw_config_error(
506506
assert!(
507507
gateway_last_error
508508
.as_deref()
509-
.is_some_and(|err| err.starts_with("gw: ")),
510-
"Expected gw-prefixed terminal error, got {:?}",
509+
.is_some_and(is_coprocessor_config_error),
510+
"Expected terminal gateway config error, got {:?}",
511511
gateway_last_error
512512
);
513513

coprocessor/fhevm-engine/transaction-sender/tests/verify_proof_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use alloy::providers::{Provider, WsConnect};
55
use alloy::signers::local::PrivateKeySigner;
66
use alloy::{providers::ProviderBuilder, sol};
77
use common::SignerType;
8-
use common::{CiphertextCommits, InputVerification, TestEnvironment};
8+
use common::{is_coprocessor_config_error, CiphertextCommits, InputVerification, TestEnvironment};
99
use futures_util::StreamExt;
1010
use futures_util::TryStreamExt;
1111
use rand::random;
@@ -1404,7 +1404,7 @@ async fn verify_proof_terminal_on_gw_config_error(
14041404
&& retry_count == Some(conf.verify_proof_resp_max_retries as i32)
14051405
&& last_error
14061406
.as_deref()
1407-
.is_some_and(|err| err.starts_with("gw: "))
1407+
.is_some_and(is_coprocessor_config_error)
14081408
{
14091409
break;
14101410
}
@@ -1426,8 +1426,8 @@ async fn verify_proof_terminal_on_gw_config_error(
14261426
assert!(
14271427
last_error
14281428
.as_deref()
1429-
.is_some_and(|err| err.starts_with("gw: ")),
1430-
"Expected gw-prefixed terminal error, got {:?}",
1429+
.is_some_and(is_coprocessor_config_error),
1430+
"Expected terminal gateway config error, got {:?}",
14311431
last_error
14321432
);
14331433

0 commit comments

Comments
 (0)