Skip to content

Commit d4e7ac4

Browse files
authored
feat(cat-gateway): RBAC updates (#3729)
* feat(cat-gateway): Remove `removed_addresses` from the `rbac_registration` table (#3724) * remove `removed_addresses` from the `rbac_registration` table * fix clippy * wip * feat(cat-gateway): Applying latest `rbac-registration` crate version (#3730) * apply latest `rbac-registration` crate * fix * cleanup * fix * fix spelling * wip * fix clippy * use the latest `rbac-registration`, updating RbacChainsState, renaming it to `RbacChainsProvider` (#3779)
1 parent 621e469 commit d4e7ac4

23 files changed

+608
-750
lines changed

catalyst-gateway/bin/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ repository.workspace = true
1515
workspace = true
1616

1717
[dependencies]
18-
cardano-chain-follower = { version = "0.0.18", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower/v0.0.18" }
19-
rbac-registration = { version = "0.0.14", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.14" }
18+
cardano-chain-follower = { version = "0.0.19", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "cardano-chain-follower/v0.0.19" }
19+
rbac-registration = { version = "0.0.15", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "rbac-registration/v0.0.15" }
2020
catalyst-signed-doc = { version = "0.0.10", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v0.0.10" }
2121
catalyst-signed-doc-v1 = { package = "catalyst-signed-doc", version = "0.0.4", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "catalyst-signed-doc/v.0.0.4" }
2222
c509-certificate = { version = "0.0.3", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "c509-certificate-v0.0.3" }

catalyst-gateway/bin/src/db/index/block/rbac509/cql/insert_rbac509.cql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ INSERT INTO rbac_registration (
55
txn_index,
66
txn_id,
77
prv_txn_id,
8-
removed_stake_addresses,
98
purpose
109
) VALUES (
1110
:catalyst_id,
1211
:slot_no,
1312
:txn_index,
1413
:txn_id,
1514
:prv_txn_id,
16-
:removed_stake_addresses,
1715
:purpose
1816
);

catalyst-gateway/bin/src/db/index/block/rbac509/insert_catalyst_id_for_public_key.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use tracing::error;
1010

1111
use crate::{
1212
db::{
13-
index::queries::{PreparedQueries, SizedBatch},
13+
index::{
14+
queries::{FallibleQueryResults, PreparedQueries, PreparedQuery, SizedBatch},
15+
session::CassandraSession,
16+
},
1417
types::{DbCatalystId, DbPublicKey, DbSlot},
1518
},
1619
settings::cassandra_db::EnvVars,
@@ -57,6 +60,16 @@ impl Params {
5760
}
5861
}
5962

63+
/// Executes prepared queries as a batch.
64+
pub(crate) async fn execute_batch(
65+
session: &Arc<CassandraSession>,
66+
queries: Vec<Self>,
67+
) -> FallibleQueryResults {
68+
session
69+
.execute_batch(PreparedQuery::CatalystIdForPublicKeyInsertQuery, queries)
70+
.await
71+
}
72+
6073
/// Prepares a batch of queries.
6174
pub(crate) async fn prepare_batch(
6275
session: &Arc<Session>,

catalyst-gateway/bin/src/db/index/block/rbac509/insert_catalyst_id_for_stake_address.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use tracing::error;
99

1010
use crate::{
1111
db::{
12-
index::queries::{PreparedQueries, SizedBatch},
12+
index::{
13+
queries::{FallibleQueryResults, PreparedQueries, PreparedQuery, SizedBatch},
14+
session::CassandraSession,
15+
},
1316
types::{DbCatalystId, DbSlot, DbStakeAddress, DbTxnIndex},
1417
},
1518
settings::cassandra_db::EnvVars,
@@ -61,6 +64,23 @@ impl Params {
6164
}
6265
}
6366

67+
/// Executes prepared queries as a batch.
68+
pub(crate) async fn execute_batch(
69+
session: &Arc<CassandraSession>,
70+
queries: Vec<Self>,
71+
) -> FallibleQueryResults {
72+
for q in &queries {
73+
session
74+
.caches()
75+
.rbac_stake_address()
76+
.insert(q.stake_address.clone().into(), q.catalyst_id.clone().into());
77+
}
78+
79+
session
80+
.execute_batch(PreparedQuery::CatalystIdForStakeAddressInsertQuery, queries)
81+
.await
82+
}
83+
6484
/// Prepare Batch of RBAC Registration Index Data Queries
6585
pub(crate) async fn prepare_batch(
6686
session: &Arc<Session>,

catalyst-gateway/bin/src/db/index/block/rbac509/insert_catalyst_id_for_txn_id.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use tracing::error;
99

1010
use crate::{
1111
db::{
12-
index::queries::{PreparedQueries, SizedBatch},
12+
index::{
13+
queries::{FallibleQueryResults, PreparedQueries, PreparedQuery, SizedBatch},
14+
session::CassandraSession,
15+
},
1316
types::{DbCatalystId, DbSlot, DbTransactionId},
1417
},
1518
settings::cassandra_db::EnvVars,
@@ -56,6 +59,16 @@ impl Params {
5659
}
5760
}
5861

62+
/// Executes prepared queries as a batch.
63+
pub(crate) async fn execute_batch(
64+
session: &Arc<CassandraSession>,
65+
queries: Vec<Self>,
66+
) -> FallibleQueryResults {
67+
session
68+
.execute_batch(PreparedQuery::CatalystIdForTxnIdInsertQuery, queries)
69+
.await
70+
}
71+
5972
/// Prepares a Batch of RBAC Registration Index Data Queries.
6073
pub(crate) async fn prepare_batch(
6174
session: &Arc<Session>,

catalyst-gateway/bin/src/db/index/block/rbac509/insert_rbac509.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
//! Insert RBAC 509 Registration Query.
22
3-
use std::{collections::HashSet, fmt::Debug, sync::Arc};
3+
use std::{fmt::Debug, sync::Arc};
44

5-
use cardano_chain_follower::{Slot, StakeAddress, TxnIndex, hashes::TransactionId};
5+
use cardano_chain_follower::{Slot, TxnIndex, hashes::TransactionId};
66
use catalyst_types::{catalyst_id::CatalystId, uuid::UuidV4};
77
use scylla::{SerializeRow, client::session::Session, value::MaybeUnset};
88
use tracing::error;
99

1010
use crate::{
1111
db::{
12-
index::queries::{PreparedQueries, SizedBatch},
13-
types::{DbCatalystId, DbSlot, DbStakeAddress, DbTransactionId, DbTxnIndex, DbUuidV4},
12+
index::{
13+
queries::{FallibleQueryResults, PreparedQueries, PreparedQuery, SizedBatch},
14+
session::CassandraSession,
15+
},
16+
types::{DbCatalystId, DbSlot, DbTransactionId, DbTxnIndex, DbUuidV4},
1417
},
1518
settings::cassandra_db::EnvVars,
1619
};
@@ -31,8 +34,6 @@ pub(crate) struct Params {
3134
txn_id: DbTransactionId,
3235
/// Hash of Previous Transaction. Is `None` for the first registration. 32 Bytes.
3336
prv_txn_id: MaybeUnset<DbTransactionId>,
34-
/// A set of removed stake addresses.
35-
removed_stake_addresses: HashSet<DbStakeAddress>,
3637
/// A registration purpose.
3738
///
3839
/// The value of purpose is `None` if the chain is modified by the registration
@@ -55,7 +56,6 @@ impl Debug for Params {
5556
.field("slot_no", &self.slot_no)
5657
.field("txn_index", &self.txn_index)
5758
.field("prv_txn_id", &prv_txn_id)
58-
.field("removed_stake_addresses", &self.removed_stake_addresses)
5959
.field("purpose", &self.purpose)
6060
.finish()
6161
}
@@ -69,14 +69,9 @@ impl Params {
6969
slot_no: Slot,
7070
txn_index: TxnIndex,
7171
prv_txn_id: Option<TransactionId>,
72-
removed_stake_addresses: HashSet<StakeAddress>,
7372
purpose: Option<UuidV4>,
7473
) -> Self {
7574
let prv_txn_id = prv_txn_id.map_or(MaybeUnset::Unset, |v| MaybeUnset::Set(v.into()));
76-
let removed_stake_addresses = removed_stake_addresses
77-
.into_iter()
78-
.map(Into::into)
79-
.collect();
8075
let purpose = purpose.map_or(MaybeUnset::Unset, |v| MaybeUnset::Set(v.into()));
8176

8277
Self {
@@ -85,11 +80,20 @@ impl Params {
8580
slot_no: slot_no.into(),
8681
txn_index: txn_index.into(),
8782
prv_txn_id,
88-
removed_stake_addresses,
8983
purpose,
9084
}
9185
}
9286

87+
/// Executes prepared queries as a batch.
88+
pub(crate) async fn execute_batch(
89+
session: &Arc<CassandraSession>,
90+
queries: Vec<Self>,
91+
) -> FallibleQueryResults {
92+
session
93+
.execute_batch(PreparedQuery::Rbac509InsertQuery, queries)
94+
.await
95+
}
96+
9397
/// Prepare Batch of RBAC Registration Index Data Queries
9498
pub(crate) async fn prepare_batch(
9599
session: &Arc<Session>,

catalyst-gateway/bin/src/db/index/block/rbac509/insert_rbac509_invalid.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use tracing::error;
1010

1111
use crate::{
1212
db::{
13-
index::queries::{PreparedQueries, SizedBatch},
13+
index::{
14+
queries::{FallibleQueryResults, PreparedQueries, PreparedQuery, SizedBatch},
15+
session::CassandraSession,
16+
},
1417
types::{DbCatalystId, DbSlot, DbTransactionId, DbTxnIndex, DbUuidV4},
1518
},
1619
service::common::objects::generic::problem_report::ProblemReport,
@@ -65,6 +68,16 @@ impl Params {
6568
}
6669
}
6770

71+
/// Executes prepared queries as a batch.
72+
pub(crate) async fn execute_batch(
73+
session: &Arc<CassandraSession>,
74+
queries: Vec<Self>,
75+
) -> FallibleQueryResults {
76+
session
77+
.execute_batch(PreparedQuery::Rbac509InvalidInsertQuery, queries)
78+
.await
79+
}
80+
6881
/// Prepare Batch of RBAC Registration Index Data Queries
6982
pub(crate) async fn prepare_batch(
7083
session: &Arc<Session>,

0 commit comments

Comments
 (0)