Skip to content

Commit 047d28d

Browse files
authored
perf: reduce memory usage by boxing large error variants in wallet operations (#11928)
* perf: box large AWS and GCP error variants in WalletSignerError * fix: update error handling for boxed AWS/GCP errors in wallet operations * fmt
1 parent 1cf23aa commit 047d28d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

crates/wallets/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pub enum WalletSignerError {
3232
Trezor(#[from] TrezorError),
3333
#[error(transparent)]
3434
#[cfg(feature = "aws-kms")]
35-
Aws(#[from] AwsSignerError),
35+
Aws(#[from] Box<AwsSignerError>),
3636
#[error(transparent)]
3737
#[cfg(feature = "gcp-kms")]
38-
Gcp(#[from] GcpSignerError),
38+
Gcp(#[from] Box<GcpSignerError>),
3939
#[error(transparent)]
4040
Io(#[from] std::io::Error),
4141
#[error(transparent)]

crates/wallets/src/wallet_signer.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ impl WalletSigner {
6060
alloy_signer_aws::aws_config::load_defaults(BehaviorVersion::latest()).await;
6161
let client = AwsClient::new(&config);
6262

63-
Ok(Self::Aws(AwsSigner::new(client, key_id, None).await?))
63+
Ok(Self::Aws(
64+
AwsSigner::new(client, key_id, None)
65+
.await
66+
.map_err(|e| WalletSignerError::Aws(Box::new(e)))?,
67+
))
6468
}
6569

6670
#[cfg(not(feature = "aws-kms"))]
@@ -88,12 +92,20 @@ impl WalletSigner {
8892
.await
8993
{
9094
Ok(c) => c,
91-
Err(e) => return Err(WalletSignerError::from(GcpSignerError::GoogleKmsError(e))),
95+
Err(e) => {
96+
return Err(WalletSignerError::Gcp(Box::new(GcpSignerError::GoogleKmsError(
97+
e,
98+
))));
99+
}
92100
};
93101

94102
let specifier = KeySpecifier::new(keyring, &key_name, key_version);
95103

96-
Ok(Self::Gcp(GcpSigner::new(client, specifier, None).await?))
104+
Ok(Self::Gcp(
105+
GcpSigner::new(client, specifier, None)
106+
.await
107+
.map_err(|e| WalletSignerError::Gcp(Box::new(e)))?,
108+
))
97109
}
98110

99111
#[cfg(not(feature = "gcp-kms"))]

0 commit comments

Comments
 (0)