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

faucet: remove key if pubkey can't be looked up #1201

Merged
merged 5 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
65 changes: 61 additions & 4 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ 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" }
# TODO switch to seahorse release
seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", rev = "c6d3ce4f0f87f92ee18eb3f3e06af7299feb7dcb" }
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
3 changes: 2 additions & 1 deletion wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ 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"] }
# TODO switch to seahorse release
seahorse = { git = "https://github.com/EspressoSystems/seahorse.git", rev = "c6d3ce4f0f87f92ee18eb3f3e06af7299feb7dcb", 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