cat_gateway/rbac/
validation_result.rs

1//! Types related to validation of new RBAC registrations.
2
3use std::collections::HashSet;
4
5use cardano_chain_follower::StakeAddress;
6use catalyst_types::{catalyst_id::CatalystId, problem_report::ProblemReport, uuid::UuidV4};
7use ed25519_dalek::VerifyingKey;
8
9/// A return value of the `validate_rbac_registration` method.
10pub type RbacValidationResult = Result<RbacValidationSuccess, RbacValidationError>;
11
12/// A value returned from the `validate_rbac_registration` on happy path.
13///
14/// It contains information for updating `rbac_registration`,
15/// `catalyst_id_for_public_key`, `catalyst_id_for_stake_address` and
16/// `catalyst_id_for_txn_id` tables.
17pub struct RbacValidationSuccess {
18    /// A Catalyst ID of the chain this registration belongs to.
19    pub catalyst_id: CatalystId,
20    /// A list of stake addresses that were added to the chain.
21    pub stake_addresses: HashSet<StakeAddress>,
22    /// A list of role public keys used in this registration.
23    pub public_keys: HashSet<VerifyingKey>,
24    /// A list of updates to other chains containing Catalyst IDs and removed stake
25    /// addresses.
26    ///
27    /// A new RBAC registration can take ownership of stake addresses of other chains.
28    pub modified_chains: Vec<(CatalystId, HashSet<StakeAddress>)>,
29    /// A registration purpose.
30    pub purpose: Option<UuidV4>,
31}
32
33/// An error returned from the `validate_rbac_registration` method.
34#[allow(clippy::large_enum_variant)]
35pub enum RbacValidationError {
36    /// A registration is invalid (`report.is_problematic()` returns `true`).
37    ///
38    /// This variant is inserted to the `rbac_invalid_registration` table.
39    InvalidRegistration {
40        /// A Catalyst ID.
41        catalyst_id: CatalystId,
42        /// A registration purpose.
43        purpose: Option<UuidV4>,
44        /// A problem report.
45        report: ProblemReport,
46    },
47    /// Unable to determine a Catalyst ID of the registration.
48    ///
49    /// This can happen if a previous transaction ID in the registration is incorrect.
50    UnknownCatalystId,
51    /// A "fatal" error occurred during validation.
52    ///
53    /// This means that the validation wasn't performed properly (usually because of a
54    /// database failure) and we cannot process the given registration. This error is
55    /// propagated on a higher level, so there will be another attempt to index that
56    /// block.
57    Fatal(anyhow::Error),
58}
59
60impl From<anyhow::Error> for RbacValidationError {
61    fn from(e: anyhow::Error) -> Self {
62        RbacValidationError::Fatal(e)
63    }
64}