Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
faucet: remove key if pubkey can't be looked up (#1201)
Browse files Browse the repository at this point in the history
* faucet: remove key if pubkey can't be looked up
* Seahorse 0.2.6 -> 0.2.7
  • Loading branch information
sveitser authored Jul 18, 2022
1 parent fe37d0c commit ef77622
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion eqs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 21 additions & 3 deletions faucet/src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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. {}",
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 15 additions & 11 deletions wallet/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}),
}
}

Expand Down

0 comments on commit ef77622

Please sign in to comment.