mirror of
https://github.com/vacp2p/status-rln-prover.git
synced 2026-01-08 05:03:54 -05:00
Print an error if too many users are registered (#40)
This commit is contained in:
@@ -139,7 +139,17 @@ impl RegistryListener {
|
||||
let id_commitment = self
|
||||
.user_db
|
||||
.on_new_user(&to_address)
|
||||
.map_err(HandleTransferError::Register)?;
|
||||
.map_err(HandleTransferError::Register);
|
||||
|
||||
// Don't stop the registry_listener if the user_db is full
|
||||
// Prover will still be functional
|
||||
if let Err(HandleTransferError::Register(RegisterError::TooManyUsers)) =
|
||||
id_commitment
|
||||
{
|
||||
error!("Cannot register a new user: {:?}", id_commitment);
|
||||
}
|
||||
|
||||
let id_commitment = id_commitment?;
|
||||
|
||||
let id_co =
|
||||
U256::from_le_slice(BigUint::from(id_commitment).to_bytes_le().as_slice());
|
||||
|
||||
@@ -17,6 +17,10 @@ use rocksdb::{
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::error;
|
||||
use zerokit_utils::{
|
||||
error::ZerokitMerkleTreeError,
|
||||
pmtree::{PmtreeErrorKind, TreeErrorKind},
|
||||
};
|
||||
// internal
|
||||
use crate::epoch_service::{Epoch, EpochSlice};
|
||||
use crate::error::GetMerkleTreeProofError;
|
||||
@@ -262,7 +266,19 @@ impl UserDb {
|
||||
self.merkle_tree
|
||||
.write()
|
||||
.set(new_index.into(), rate_commit)
|
||||
.map_err(|e| RegisterError::TreeError(e.to_string()))?;
|
||||
.map_err(|e| {
|
||||
// Check Zerokit issue: https://github.com/vacp2p/zerokit/issues/343
|
||||
if matches!(
|
||||
e,
|
||||
ZerokitMerkleTreeError::PmtreeErrorKind(PmtreeErrorKind::TreeError(
|
||||
TreeErrorKind::IndexOutOfBounds
|
||||
))
|
||||
) {
|
||||
RegisterError::TooManyUsers
|
||||
} else {
|
||||
RegisterError::TreeError(e.to_string())
|
||||
}
|
||||
})?;
|
||||
|
||||
// Add index for user
|
||||
merkle_index_serializer.serialize(&new_index, &mut buffer);
|
||||
@@ -805,7 +821,7 @@ mod tests {
|
||||
assert_eq!(tree.read().leaves_set(), 2);
|
||||
|
||||
let res = user_db.register(ADDR_2);
|
||||
assert_matches!(res, Err(RegisterError::TreeError(_)));
|
||||
assert_matches!(res, Err(RegisterError::TooManyUsers));
|
||||
assert_eq!(user_db.has_user(&ADDR_1), Ok(true));
|
||||
assert_eq!(user_db.has_user(&ADDR_2), Ok(false));
|
||||
assert_eq!(tree.read().leaves_set(), 2);
|
||||
|
||||
@@ -27,6 +27,8 @@ pub enum RegisterError {
|
||||
AlreadyRegistered(Address),
|
||||
#[error(transparent)]
|
||||
Db(#[from] rocksdb::Error),
|
||||
#[error("Too many users, exceeding merkle tree capacity...")]
|
||||
TooManyUsers,
|
||||
#[error("Merkle tree error: {0}")]
|
||||
TreeError(String),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user