diff --git a/Cargo.lock b/Cargo.lock index 21e95d5c..4287ad9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5289,8 +5289,8 @@ dependencies = [ [[package]] name = "seahorse" -version = "0.2.6" -source = "git+https://github.com/EspressoSystems/seahorse.git?tag=0.2.6#9c99d795e3d31a576fdb6b8d7cc07efd3ec0b4ba" +version = "0.2.7" +source = "git+https://github.com/EspressoSystems/seahorse.git?tag=0.2.7#ae981e4c4acc09ff455c16ab1d0839bdd24b3b30" dependencies = [ "arbitrary", "arbitrary-wrappers", diff --git a/contracts/rust/Cargo.toml b/contracts/rust/Cargo.toml index 04308c42..8986c28e 100644 --- a/contracts/rust/Cargo.toml +++ b/contracts/rust/Cargo.toml @@ -63,7 +63,7 @@ rand = "0.8.4" rand_chacha = "0.3.1" reef = { git = "https://github.com/EspressoSystems/reef.git", tag = "0.2.2" } regex = "1.5.5" -seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.6" } +seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.7" } serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.67" sha3 = "0.9.1" diff --git a/eqs/Cargo.toml b/eqs/Cargo.toml index 6b754463..1d601523 100644 --- a/eqs/Cargo.toml +++ b/eqs/Cargo.toml @@ -32,7 +32,7 @@ net = { git = "https://github.com/EspressoSystems/net.git", tag = "0.2.2" } rand = "0.8.4" rand_chacha = { version = "0.3.1", features = ["serde1"] } reef = { git = "https://github.com/EspressoSystems/reef.git", tag = "0.2.2" } -seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.6", features = ["testing"] } +seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.7", features = ["testing"] } serde = { version = "1.0.123", features = ["derive", "rc"] } serde_derive = "1.0.118" serde_json = "1.0.61" diff --git a/faucet/Cargo.toml b/faucet/Cargo.toml index 3ab6f74b..14d5a5d1 100644 --- a/faucet/Cargo.toml +++ b/faucet/Cargo.toml @@ -53,7 +53,7 @@ net = { git = "https://github.com/EspressoSystems/net.git", tag = "0.2.2" } rand = "0.8.5" rand_chacha = "0.3.1" reef = { git = "https://github.com/EspressoSystems/reef.git", tag = "0.2.2" } -seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.6" } +seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.7" } serde = "1.0.136" serde_json = "1.0.67" snafu = "0.7.0" diff --git a/faucet/src/faucet.rs b/faucet/src/faucet.rs index 1c886573..d7896d42 100644 --- a/faucet/src/faucet.rs +++ b/faucet/src/faucet.rs @@ -458,6 +458,10 @@ impl FaucetQueue { } async fn fail(&mut self, request: UserPubKey) { + // Sleep a second before retrying to avoid creating a busy loop + // in case of unforeseen errors. + async_std::task::sleep(Duration::from_secs(1)).await; + if let Err(err) = self.sender.send(request).await { tracing::error!( "error re-adding failed request; request will be dropped. {}", @@ -595,9 +599,23 @@ async fn worker(id: usize, mut state: FaucetState) { .await { tracing::error!("worker {}: failed to transfer: {}", id, err); - // If we failed, mark the request as failed in the queue so it can be retried - // later. - state.queue.fail(pub_key).await; + if let CapeWalletError::PubkeyNotFound { address } = err { + // If the address is missing in the address book we can't + // transfer. Drop the faucet grant. + tracing::warn!( + "worker {}: pubkey for {} not found, removing key from index", + id, + address + ); + { + let mut index = state.queue.index.lock().await; + index.remove(&pub_key).unwrap(); + } + } else { + // If we failed, mark the request as failed in the queue so it can be retried + // later. + state.queue.fail(pub_key).await; + } continue 'wait_for_requests; } diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index b2ec8fd9..38d6dc75 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -54,7 +54,7 @@ rand_chacha = "0.3.1" reef = { git = "https://github.com/EspressoSystems/reef.git", tag = "0.2.2" } regex = "1.5.4" relayer = { path = "../relayer", features = ["testing"] } -seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.6", features = ["testing"] } +seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", tag = "0.2.7", features = ["testing"] } serde = { version = "1.0.123", features = ["derive", "rc"] } serde_derive = "1.0.118" serde_json = "1.0.61" diff --git a/wallet/src/backend.rs b/wallet/src/backend.rs index cf5e8bfb..ff774532 100644 --- a/wallet/src/backend.rs +++ b/wallet/src/backend.rs @@ -425,18 +425,22 @@ impl<'a> WalletBackend<'a, CapeLedger> for CapeBackend<'a> { .map_err(|err| CapeWalletError::Failed { msg: format!("error requesting public key: {}", err), })?; - if response.status() == StatusCode::Ok { - let bytes = response - .body_bytes() - .await - .expect("failed deserializing response from address book"); - let pub_key: UserPubKey = bincode::deserialize(&bytes) - .expect("failed deserializing UserPubKey from address book."); - Ok(pub_key) - } else { - Err(CapeWalletError::Failed { + match response.status() { + StatusCode::Ok => { + let bytes = response + .body_bytes() + .await + .expect("failed deserializing response from address book"); + let pub_key: UserPubKey = bincode::deserialize(&bytes) + .expect("failed deserializing UserPubKey from address book."); + Ok(pub_key) + } + StatusCode::NotFound => Err(CapeWalletError::PubkeyNotFound { + address: address.clone(), + }), + _ => Err(CapeWalletError::Failed { msg: "Error response from address book".into(), - }) + }), } }