Skip to content

Commit c932232

Browse files
authored
EOA diagnostics and improvements (#29)
* clippy * add EOA executor admin routes * always update cached transaction count * read counts correctly * fix endpoints * propagate password * clippy * pagination fixes * run clippy * update optimistic nonce if behind * review comments * add health to diagnostics
1 parent 693a7e7 commit c932232

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+844
-278
lines changed

aa-core/src/signer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<C: Chain + Clone> SmartAccountSignerBuilder<C> {
8585
.to_determined_smart_account()
8686
.await
8787
.map_err(|e| EngineError::ValidationError {
88-
message: format!("Failed to determine smart account: {}", e),
88+
message: format!("Failed to determine smart account: {e}"),
8989
})?,
9090
};
9191

core/src/chain.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl ThirdwebChainConfig<'_> {
131131
// For local anvil, use localhost URLs
132132
let local_rpc_url = "http://127.0.0.1:8545";
133133
let rpc_url = Url::parse(local_rpc_url).map_err(|e| EngineError::RpcConfigError {
134-
message: format!("Failed to parse local anvil RPC URL: {}", e),
134+
message: format!("Failed to parse local anvil RPC URL: {e}"),
135135
})?;
136136

137137
// For bundler and paymaster, use the same local RPC URL
@@ -149,7 +149,7 @@ impl ThirdwebChainConfig<'_> {
149149
client_id = self.client_id,
150150
))
151151
.map_err(|e| EngineError::RpcConfigError {
152-
message: format!("Failed to parse RPC URL: {}", e),
152+
message: format!("Failed to parse RPC URL: {e}"),
153153
})?;
154154

155155
let bundler_url = Url::parse(&format!(
@@ -158,7 +158,7 @@ impl ThirdwebChainConfig<'_> {
158158
base_url = self.bundler_base_url,
159159
))
160160
.map_err(|e| EngineError::RpcConfigError {
161-
message: format!("Failed to parse Bundler URL: {}", e),
161+
message: format!("Failed to parse Bundler URL: {e}"),
162162
})?;
163163

164164
let paymaster_url = Url::parse(&format!(
@@ -167,7 +167,7 @@ impl ThirdwebChainConfig<'_> {
167167
base_url = self.paymaster_base_url,
168168
))
169169
.map_err(|e| EngineError::RpcConfigError {
170-
message: format!("Failed to parse Paymaster URL: {}", e),
170+
message: format!("Failed to parse Paymaster URL: {e}"),
171171
})?;
172172

173173
(rpc_url, bundler_url, paymaster_url)

core/src/error.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,22 @@ impl<T: Debug> From<SdkError<T>> for SerialisableAwsSdkError {
331331
fn from(err: SdkError<T>) -> Self {
332332
match err {
333333
SdkError::ConstructionFailure(err) => SerialisableAwsSdkError::ConstructionFailure {
334-
message: format!("{:?}", err),
334+
message: format!("{err:?}"),
335335
},
336336
SdkError::TimeoutError(err) => SerialisableAwsSdkError::TimeoutError {
337-
message: format!("{:?}", err),
337+
message: format!("{err:?}"),
338338
},
339339
SdkError::DispatchFailure(err) => SerialisableAwsSdkError::DispatchFailure {
340-
message: format!("{:?}", err),
340+
message: format!("{err:?}"),
341341
},
342342
SdkError::ResponseError(err) => SerialisableAwsSdkError::ResponseError {
343-
message: format!("{:?}", err),
343+
message: format!("{err:?}"),
344344
},
345345
SdkError::ServiceError(err) => SerialisableAwsSdkError::ServiceError {
346-
message: format!("{:?}", err),
346+
message: format!("{err:?}"),
347347
},
348348
_ => SerialisableAwsSdkError::Other {
349-
message: format!("{:?}", err),
349+
message: format!("{err:?}"),
350350
},
351351
}
352352
}
@@ -398,11 +398,8 @@ impl From<vault_sdk::error::VaultError> for EngineError {
398398
message,
399399
details,
400400
} => match details {
401-
Some(details) => format!(
402-
"Enclave error: {} - {} - details: {}",
403-
code, message, details
404-
),
405-
None => format!("Enclave error: {} - {}", code, message),
401+
Some(details) => format!("Enclave error: {code} - {message} - details: {details}"),
402+
None => format!("Enclave error: {code} - {message}"),
406403
},
407404
_ => err.to_string(),
408405
};
@@ -536,15 +533,15 @@ impl ContractErrorToEngineError for alloy::contract::Error {
536533
fn to_engine_error(self, chain_id: u64, contract_address: Option<Address>) -> EngineError {
537534
let (message, kind) = match self {
538535
alloy::contract::Error::UnknownFunction(name) => (
539-
format!("Unknown function: {}", name),
536+
format!("Unknown function: {name}"),
540537
ContractInteractionErrorKind::UnknownFunction {
541538
function_name: name,
542539
},
543540
),
544541
alloy::contract::Error::UnknownSelector(selector) => (
545-
format!("Unknown selector: {:?}", selector),
542+
format!("Unknown selector: {selector:?}"),
546543
ContractInteractionErrorKind::UnknownSelector {
547-
function_selector: format!("{:?}", selector),
544+
function_selector: format!("{selector:?}"),
548545
},
549546
),
550547
alloy::contract::Error::NotADeploymentTransaction => (
@@ -556,26 +553,26 @@ impl ContractErrorToEngineError for alloy::contract::Error {
556553
ContractInteractionErrorKind::ContractNotDeployed,
557554
),
558555
alloy::contract::Error::ZeroData(function, err) => (
559-
format!("Zero data returned from contract call to {}", function),
556+
format!("Zero data returned from contract call to {function}"),
560557
ContractInteractionErrorKind::ZeroData {
561558
function,
562559
message: err.to_string(),
563560
},
564561
),
565562
alloy::contract::Error::AbiError(err) => (
566-
format!("ABI error: {}", err),
563+
format!("ABI error: {err}"),
567564
ContractInteractionErrorKind::AbiError {
568565
message: err.to_string(),
569566
},
570567
),
571568
alloy::contract::Error::TransportError(err) => (
572-
format!("Transport error: {}", err),
569+
format!("Transport error: {err}"),
573570
ContractInteractionErrorKind::TransportError {
574571
message: err.to_string(),
575572
},
576573
),
577574
alloy::contract::Error::PendingTransactionError(err) => (
578-
format!("Pending transaction error: {}", err),
575+
format!("Pending transaction error: {err}"),
579576
ContractInteractionErrorKind::PendingTransactionError {
580577
message: err.to_string(),
581578
},

core/src/execution_options/aa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ impl Erc4337ExecutionOptions {
9191
pub fn get_salt_data(&self) -> Result<Bytes, EngineError> {
9292
if self.account_salt.starts_with("0x") {
9393
Bytes::from_hex(&self.account_salt).map_err(|e| EngineError::ValidationError {
94-
message: format!("Failed to parse hex salt: {}", e),
94+
message: format!("Failed to parse hex salt: {e}"),
9595
})
9696
} else {
9797
let hex_string = alloy::hex::encode(&self.account_salt);
9898
Bytes::from_hex(hex_string).map_err(|e| EngineError::ValidationError {
99-
message: format!("Failed to encode salt as hex: {}", e),
99+
message: format!("Failed to encode salt as hex: {e}"),
100100
})
101101
}
102102
}

core/src/execution_options/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,8 @@ mod tests {
211211
r#"{{
212212
"url": "https://example.com/webhook",
213213
"secret": "test_secret",
214-
"userMetadata": "{}"
215-
}}"#,
216-
large_metadata
214+
"userMetadata": "{large_metadata}"
215+
}}"#
217216
);
218217

219218
let webhook_options: Result<WebhookOptions, _> = serde_json::from_str(&invalid_json);

core/src/signer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ impl Erc4337SigningOptions {
102102
pub fn get_salt_data(&self) -> Result<Bytes, EngineError> {
103103
if self.account_salt.starts_with("0x") {
104104
Bytes::from_hex(&self.account_salt).map_err(|e| EngineError::ValidationError {
105-
message: format!("Failed to parse hex salt: {}", e),
105+
message: format!("Failed to parse hex salt: {e}"),
106106
})
107107
} else {
108108
let hex_string = alloy::hex::encode(&self.account_salt);
109109
Bytes::from_hex(hex_string).map_err(|e| EngineError::ValidationError {
110-
message: format!("Failed to encode salt as hex: {}", e),
110+
message: format!("Failed to encode salt as hex: {e}"),
111111
})
112112
}
113113
}
@@ -308,7 +308,7 @@ impl AccountSigner for EoaSigner {
308308
let signature = signer.sign_message(&message_bytes).await.map_err(|e| {
309309
tracing::error!("Error signing message with EOA (PrivateKey): {:?}", e);
310310
EngineError::ValidationError {
311-
message: format!("Failed to sign message: {}", e),
311+
message: format!("Failed to sign message: {e}"),
312312
}
313313
})?;
314314
Ok(signature.to_string())
@@ -377,7 +377,7 @@ impl AccountSigner for EoaSigner {
377377
.map_err(|e| {
378378
tracing::error!("Error signing typed data with EOA (PrivateKey): {:?}", e);
379379
EngineError::ValidationError {
380-
message: format!("Failed to sign typed data: {}", e),
380+
message: format!("Failed to sign typed data: {e}"),
381381
}
382382
})?;
383383
Ok(signature.to_string())
@@ -447,7 +447,7 @@ impl AccountSigner for EoaSigner {
447447
.map_err(|e| {
448448
tracing::error!("Error signing transaction with EOA (PrivateKey): {:?}", e);
449449
EngineError::ValidationError {
450-
message: format!("Failed to sign transaction: {}", e),
450+
message: format!("Failed to sign transaction: {e}"),
451451
}
452452
})?;
453453
Ok(signature.to_string())
@@ -521,7 +521,7 @@ impl AccountSigner for EoaSigner {
521521
let signature = signer.sign_hash_sync(&authorization_hash).map_err(|e| {
522522
tracing::error!("Error signing authorization with EOA (PrivateKey): {:?}", e);
523523
EngineError::ValidationError {
524-
message: format!("Failed to sign authorization: {}", e),
524+
message: format!("Failed to sign authorization: {e}"),
525525
}
526526
})?;
527527

core/src/userop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl UserOpSigner {
115115
)
116116
.await
117117
.map_err(|e| EngineError::ValidationError {
118-
message: format!("Failed to sign userop: {}", e),
118+
message: format!("Failed to sign userop: {e}"),
119119
})?;
120120

121121
Ok(Bytes::from_hex(&result.signature).map_err(|_| {
@@ -128,7 +128,7 @@ impl UserOpSigner {
128128
let signer = creds.get_signer(Some(params.chain_id)).await?;
129129
let userophash = params.userop.hash(params.chain_id).map_err(|e| {
130130
EngineError::ValidationError {
131-
message: format!("Failed to hash userop: {}", e),
131+
message: format!("Failed to hash userop: {e}"),
132132
}
133133
})?;
134134

@@ -147,13 +147,13 @@ impl UserOpSigner {
147147
SigningCredential::PrivateKey(signer) => {
148148
let userophash = params.userop.hash(params.chain_id).map_err(|e| {
149149
EngineError::ValidationError {
150-
message: format!("Failed to hash userop: {}", e),
150+
message: format!("Failed to hash userop: {e}"),
151151
}
152152
})?;
153153

154154
let signature = signer.sign_hash(&userophash).await.map_err(|e| {
155155
EngineError::ValidationError {
156-
message: format!("Failed to sign userop: {}", e),
156+
message: format!("Failed to sign userop: {e}"),
157157
}
158158
})?;
159159

eip7702-core/src/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<C: Chain> MinimalAccountTransaction<C> {
214214
// Serialize wrapped calls to JSON
215215
let wrapped_calls_json = serde_json::to_value(&self.wrapped_calls).map_err(|e| {
216216
EngineError::ValidationError {
217-
message: format!("Failed to serialize wrapped calls: {}", e),
217+
message: format!("Failed to serialize wrapped calls: {e}"),
218218
}
219219
})?;
220220

eip7702-core/tests/integration_tests.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ use std::time::Duration;
22

33
use alloy::{
44
consensus::{SignableTransaction, TypedTransaction},
5-
eips::{BlockNumberOrTag, eip7702::SignedAuthorization},
6-
hex,
5+
eips::eip7702::SignedAuthorization,
76
network::{EthereumWallet, TransactionBuilder, TransactionBuilder7702, TxSigner},
8-
node_bindings::{Anvil, AnvilInstance},
9-
primitives::{Address, BlockNumber, Bytes, TxHash, U256},
7+
primitives::{Address, Bytes, U256},
108
providers::{
119
DynProvider, Identity, Provider, ProviderBuilder, RootProvider,
1210
ext::AnvilApi,
@@ -25,7 +23,7 @@ use engine_core::{
2523
chain::Chain,
2624
credentials::SigningCredential,
2725
error::EngineError,
28-
signer::{AccountSigner, EoaSigner, EoaSigningOptions},
26+
signer::{AccountSigner, EoaSigningOptions},
2927
transaction::InnerTransaction,
3028
};
3129
use engine_eip7702_core::{
@@ -36,8 +34,6 @@ use engine_eip7702_core::{
3634
use serde_json::Value;
3735
use tokio::time::sleep;
3836

39-
use crate::MockERC20::{MockERC20Calls, MockERC20Instance};
40-
4137
// Mock ERC20 contract
4238
sol! {
4339
#[allow(missing_docs)]
@@ -185,7 +181,7 @@ impl AccountSigner for MockEoaSigner {
185181
let message_bytes = _message.as_bytes();
186182
let signature = signer.sign_message(message_bytes).await.map_err(|e| {
187183
EngineError::ValidationError {
188-
message: format!("Failed to sign message: {}", e),
184+
message: format!("Failed to sign message: {e}"),
189185
}
190186
})?;
191187
Ok(signature.to_string())
@@ -208,7 +204,7 @@ impl AccountSigner for MockEoaSigner {
208204
.sign_dynamic_typed_data(typed_data)
209205
.await
210206
.map_err(|e| EngineError::ValidationError {
211-
message: format!("Failed to sign typed data: {}", e),
207+
message: format!("Failed to sign typed data: {e}"),
212208
})?;
213209
Ok(signature.to_string())
214210
}
@@ -229,7 +225,7 @@ impl AccountSigner for MockEoaSigner {
229225
let mut tx = transaction.clone();
230226
let signature = signer.sign_transaction(&mut tx).await.map_err(|e| {
231227
EngineError::ValidationError {
232-
message: format!("Failed to sign transaction: {}", e),
228+
message: format!("Failed to sign transaction: {e}"),
233229
}
234230
})?;
235231
Ok(signature.to_string())
@@ -258,7 +254,7 @@ impl AccountSigner for MockEoaSigner {
258254
let authorization_hash = authorization.signature_hash();
259255
let signature = signer.sign_hash(&authorization_hash).await.map_err(|e| {
260256
EngineError::ValidationError {
261-
message: format!("Failed to sign authorization: {}", e),
257+
message: format!("Failed to sign authorization: {e}"),
262258
}
263259
})?;
264260
Ok(authorization.into_signed(signature))
@@ -374,7 +370,7 @@ impl TestSetup {
374370
let _: () = chain
375371
.provider()
376372
.client()
377-
.request("anvil_setBalance", (address, format!("0x{:x}", balance)))
373+
.request("anvil_setBalance", (address, format!("0x{balance:x}")))
378374
.await?;
379375

380376
Ok(())
@@ -395,8 +391,7 @@ impl TestSetup {
395391
.await?;
396392

397393
println!(
398-
"Set bytecode for minimal account implementation at {}",
399-
MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS
394+
"Set bytecode for minimal account implementation at {MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS}"
400395
);
401396

402397
Ok(())

executors/src/eip7702_executor/confirm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy::primitives::{Address, TxHash};
1+
use alloy::primitives::TxHash;
22
use alloy::providers::Provider;
33
use alloy::rpc::types::TransactionReceipt;
44
use engine_core::error::{AlloyRpcErrorToEngineError, EngineError};
@@ -107,7 +107,7 @@ pub enum Eip7702ConfirmationError {
107107
impl From<TwmqError> for Eip7702ConfirmationError {
108108
fn from(error: TwmqError) -> Self {
109109
Eip7702ConfirmationError::InternalError {
110-
message: format!("Deserialization error for job data: {}", error),
110+
message: format!("Deserialization error for job data: {error}"),
111111
}
112112
}
113113
}
@@ -171,7 +171,7 @@ where
171171
.get_chain(job_data.chain_id)
172172
.map_err(|e| Eip7702ConfirmationError::ChainServiceError {
173173
chain_id: job_data.chain_id,
174-
message: format!("Failed to get chain instance: {}", e),
174+
message: format!("Failed to get chain instance: {e}"),
175175
})
176176
.map_err_fail()?;
177177

@@ -199,7 +199,7 @@ where
199199
TwGetTransactionHashResponse::Success { transaction_hash } => {
200200
transaction_hash.parse::<TxHash>().map_err(|e| {
201201
Eip7702ConfirmationError::TransactionHashError {
202-
message: format!("Invalid transaction hash format: {}", e),
202+
message: format!("Invalid transaction hash format: {e}"),
203203
}
204204
.fail()
205205
})?
@@ -227,7 +227,7 @@ where
227227
.map_err(|e| {
228228
// If transaction not found, nack and retry
229229
Eip7702ConfirmationError::ConfirmationError {
230-
message: format!("Failed to get transaction receipt: {}", e),
230+
message: format!("Failed to get transaction receipt: {e}"),
231231
inner_error: Some(e.to_engine_error(&chain)),
232232
}
233233
.nack(Some(Duration::from_secs(5)), RequeuePosition::Last)

0 commit comments

Comments
 (0)