Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kms): do not require distributed locking when only using one kms key #475

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions crates/builder/src/signer/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::monitor_account_balance;
#[derive(Debug)]
pub(crate) struct KmsSigner {
pub(crate) signer: AwsSigner,
_kms_guard: SpawnGuard,
_kms_guard: Option<SpawnGuard>,
_monitor_guard: SpawnGuard,
}

Expand All @@ -41,15 +41,27 @@ impl KmsSigner {
redis_uri: String,
ttl_millis: u64,
) -> anyhow::Result<Self> {
let (tx, rx) = oneshot::channel::<String>();
let kms_guard = SpawnGuard::spawn_with_guard(Self::lock_manager_loop(
redis_uri, key_ids, chain_id, ttl_millis, tx,
));
let key_id = rx.await.context("should lock key_id")?;
let client = KmsClient::new(region);
let mut kms_guard = None;
let key_id;

if key_ids.len() > 1 {
let (tx, rx) = oneshot::channel::<String>();
kms_guard = Some(SpawnGuard::spawn_with_guard(Self::lock_manager_loop(
redis_uri, key_ids, chain_id, ttl_millis, tx,
)));
key_id = rx.await.context("should lock key_id")?;
} else {
key_id = key_ids
.first()
.expect("There should be at least one kms key")
.to_owned();
};

let signer = AwsSigner::new(client, key_id, chain_id)
.await
.context("should create signer")?;

let monitor_guard = SpawnGuard::spawn_with_guard(monitor_account_balance(
signer.address(),
provider.clone(),
Expand Down
Loading