-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cat-gateway): incorporate chain root for stake addr and txn id re…
…gistration queries
- Loading branch information
1 parent
bc87c9b
commit 6e2ae43
Showing
10 changed files
with
339 additions
and
62 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
catalyst-gateway/bin/src/db/index/queries/purge/chain_root_for_stake_address.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
//! Chain Root For Role0 Key (RBAC 509 registrations) Queries used in purging data. | ||
use std::{fmt::Debug, sync::Arc}; | ||
|
||
use scylla::{ | ||
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow, | ||
Session, | ||
}; | ||
use tracing::error; | ||
|
||
use crate::{ | ||
db::index::{ | ||
queries::{ | ||
purge::{PreparedDeleteQuery, PreparedQueries, PreparedSelectQuery}, | ||
FallibleQueryResults, SizedBatch, | ||
}, | ||
session::CassandraSession, | ||
}, | ||
settings::cassandra_db, | ||
}; | ||
|
||
pub(crate) mod result { | ||
//! Return values for Chain Root For Role0 Key registration purge queries. | ||
|
||
/// Primary Key Row | ||
pub(crate) type PrimaryKey = (Vec<u8>, num_bigint::BigInt, i16); | ||
} | ||
|
||
/// Select primary keys for Chain Root For Role0 Key registration. | ||
const SELECT_QUERY: &str = include_str!("./cql/get_chain_root_for_role0_key.cql"); | ||
|
||
/// Primary Key Value. | ||
#[derive(SerializeRow)] | ||
pub(crate) struct Params { | ||
/// Role0 Key - Binary 16 bytes. | ||
pub(crate) role0_key: Vec<u8>, | ||
/// Block Slot Number | ||
pub(crate) slot_no: num_bigint::BigInt, | ||
/// Transaction Offset inside the block. | ||
pub(crate) txn: i16, | ||
} | ||
|
||
impl Debug for Params { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Params") | ||
.field("role0_key", &self.role0_key) | ||
.field("slot_no", &self.slot_no) | ||
.field("txn", &self.txn) | ||
.finish() | ||
} | ||
} | ||
|
||
impl From<result::PrimaryKey> for Params { | ||
fn from(value: result::PrimaryKey) -> Self { | ||
Self { | ||
role0_key: value.0, | ||
slot_no: value.1, | ||
txn: value.2, | ||
} | ||
} | ||
} | ||
/// Get primary key for Chain Root For Role0 Key registration query. | ||
pub(crate) struct PrimaryKeyQuery; | ||
|
||
impl PrimaryKeyQuery { | ||
/// Prepares a query to get all Chain Root For Role0 Key registration primary keys. | ||
pub(crate) async fn prepare(session: &Arc<Session>) -> anyhow::Result<PreparedStatement> { | ||
let select_primary_key = PreparedQueries::prepare( | ||
session.clone(), | ||
SELECT_QUERY, | ||
scylla::statement::Consistency::All, | ||
true, | ||
) | ||
.await; | ||
|
||
if let Err(ref error) = select_primary_key { | ||
error!(error=%error, "Failed to prepare get Chain Root For Role0 Key registration primary key query"); | ||
}; | ||
|
||
select_primary_key | ||
} | ||
|
||
/// Executes a query to get all Chain Root For Role0 Key registration primary keys. | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, | ||
) -> anyhow::Result<TypedRowIterator<result::PrimaryKey>> { | ||
let iter = session | ||
.purge_execute_iter(PreparedSelectQuery::ChainRootForRole0Key) | ||
.await? | ||
.into_typed::<result::PrimaryKey>(); | ||
|
||
Ok(iter) | ||
} | ||
} | ||
|
||
/// Delete Chain Root For Role0 Key registration | ||
const DELETE_QUERY: &str = include_str!("./cql/delete_chain_root_for_role0_key.cql"); | ||
|
||
/// Delete Chain Root For Role0 Key registration Query | ||
pub(crate) struct DeleteQuery; | ||
|
||
impl DeleteQuery { | ||
/// Prepare Batch of Delete Queries | ||
pub(crate) async fn prepare_batch( | ||
session: &Arc<Session>, cfg: &cassandra_db::EnvVars, | ||
) -> anyhow::Result<SizedBatch> { | ||
let delete_queries = PreparedQueries::prepare_batch( | ||
session.clone(), | ||
DELETE_QUERY, | ||
cfg, | ||
scylla::statement::Consistency::Any, | ||
true, | ||
false, | ||
) | ||
.await?; | ||
Ok(delete_queries) | ||
} | ||
|
||
/// Executes a DELETE Query | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, params: Vec<Params>, | ||
) -> FallibleQueryResults { | ||
let results = session | ||
.purge_execute_batch(PreparedDeleteQuery::ChainRootForRole0Key, params) | ||
.await?; | ||
|
||
Ok(results) | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
catalyst-gateway/bin/src/db/index/queries/purge/chain_root_for_txn_id.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
//! Chain Root For Role0 Key (RBAC 509 registrations) Queries used in purging data. | ||
use std::{fmt::Debug, sync::Arc}; | ||
|
||
use scylla::{ | ||
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow, | ||
Session, | ||
}; | ||
use tracing::error; | ||
|
||
use crate::{ | ||
db::index::{ | ||
queries::{ | ||
purge::{PreparedDeleteQuery, PreparedQueries, PreparedSelectQuery}, | ||
FallibleQueryResults, SizedBatch, | ||
}, | ||
session::CassandraSession, | ||
}, | ||
settings::cassandra_db, | ||
}; | ||
|
||
pub(crate) mod result { | ||
//! Return values for Chain Root For Role0 Key registration purge queries. | ||
|
||
/// Primary Key Row | ||
pub(crate) type PrimaryKey = (Vec<u8>, num_bigint::BigInt, i16); | ||
} | ||
|
||
/// Select primary keys for Chain Root For Role0 Key registration. | ||
const SELECT_QUERY: &str = include_str!("./cql/get_chain_root_for_role0_key.cql"); | ||
|
||
/// Primary Key Value. | ||
#[derive(SerializeRow)] | ||
pub(crate) struct Params { | ||
/// Role0 Key - Binary 16 bytes. | ||
pub(crate) role0_key: Vec<u8>, | ||
/// Block Slot Number | ||
pub(crate) slot_no: num_bigint::BigInt, | ||
/// Transaction Offset inside the block. | ||
pub(crate) txn: i16, | ||
} | ||
|
||
impl Debug for Params { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Params") | ||
.field("role0_key", &self.role0_key) | ||
.field("slot_no", &self.slot_no) | ||
.field("txn", &self.txn) | ||
.finish() | ||
} | ||
} | ||
|
||
impl From<result::PrimaryKey> for Params { | ||
fn from(value: result::PrimaryKey) -> Self { | ||
Self { | ||
role0_key: value.0, | ||
slot_no: value.1, | ||
txn: value.2, | ||
} | ||
} | ||
} | ||
/// Get primary key for Chain Root For Role0 Key registration query. | ||
pub(crate) struct PrimaryKeyQuery; | ||
|
||
impl PrimaryKeyQuery { | ||
/// Prepares a query to get all Chain Root For Role0 Key registration primary keys. | ||
pub(crate) async fn prepare(session: &Arc<Session>) -> anyhow::Result<PreparedStatement> { | ||
let select_primary_key = PreparedQueries::prepare( | ||
session.clone(), | ||
SELECT_QUERY, | ||
scylla::statement::Consistency::All, | ||
true, | ||
) | ||
.await; | ||
|
||
if let Err(ref error) = select_primary_key { | ||
error!(error=%error, "Failed to prepare get Chain Root For Role0 Key registration primary key query"); | ||
}; | ||
|
||
select_primary_key | ||
} | ||
|
||
/// Executes a query to get all Chain Root For Role0 Key registration primary keys. | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, | ||
) -> anyhow::Result<TypedRowIterator<result::PrimaryKey>> { | ||
let iter = session | ||
.purge_execute_iter(PreparedSelectQuery::ChainRootForRole0Key) | ||
.await? | ||
.into_typed::<result::PrimaryKey>(); | ||
|
||
Ok(iter) | ||
} | ||
} | ||
|
||
/// Delete Chain Root For Role0 Key registration | ||
const DELETE_QUERY: &str = include_str!("./cql/delete_chain_root_for_role0_key.cql"); | ||
|
||
/// Delete Chain Root For Role0 Key registration Query | ||
pub(crate) struct DeleteQuery; | ||
|
||
impl DeleteQuery { | ||
/// Prepare Batch of Delete Queries | ||
pub(crate) async fn prepare_batch( | ||
session: &Arc<Session>, cfg: &cassandra_db::EnvVars, | ||
) -> anyhow::Result<SizedBatch> { | ||
let delete_queries = PreparedQueries::prepare_batch( | ||
session.clone(), | ||
DELETE_QUERY, | ||
cfg, | ||
scylla::statement::Consistency::Any, | ||
true, | ||
false, | ||
) | ||
.await?; | ||
Ok(delete_queries) | ||
} | ||
|
||
/// Executes a DELETE Query | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, params: Vec<Params>, | ||
) -> FallibleQueryResults { | ||
let results = session | ||
.purge_execute_batch(PreparedDeleteQuery::ChainRootForRole0Key, params) | ||
.await?; | ||
|
||
Ok(results) | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
catalyst-gateway/bin/src/db/index/queries/purge/cql/delete_chain_root_for_stake_addr.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
-- Delete Chain Root For TX ID. RBAC 509 registrations. | ||
DELETE FROM chain_root_for_txn_id | ||
WHERE transaction_id = :transaction_id | ||
-- Delete Chain Root For Stake Address (RBAC 509 registrations). | ||
DELETE FROM chain_root_for_stake_addr | ||
WHERE stake_addr = :stake_addr | ||
AND slot_no = :slot_no | ||
AND txn = :txn |
8 changes: 3 additions & 5 deletions
8
catalyst-gateway/bin/src/db/index/queries/purge/cql/delete_chain_root_for_txn_id.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
-- Delete all the chain roots for a stake address | ||
DELETE FROM chain_root_for_stake_addr | ||
WHERE stake_addr = :stake_addr | ||
AND slot_no = :slot_no | ||
AND txn = :txn | ||
-- Delete Chain Root For TX ID (RBAC 509 registrations). | ||
DELETE FROM chain_root_for_txn_id | ||
WHERE transaction_id = :transaction_id |
9 changes: 6 additions & 3 deletions
9
catalyst-gateway/bin/src/db/index/queries/purge/cql/get_chain_root_for_stake_addr.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
-- Get all primary keys from Chain Root For TX ID. RBAC 509 Registrations. | ||
SELECT transaction_id | ||
FROM chain_root_for_txn_id | ||
-- Get all primary keys from Chain Root For Stake Address (RBAC 509 registrations). | ||
SELECT | ||
role0_key, | ||
slot_no, | ||
txn | ||
FROM chain_root_for_role0_key |
9 changes: 3 additions & 6 deletions
9
catalyst-gateway/bin/src/db/index/queries/purge/cql/get_chain_root_for_txn_id.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
-- Get all primary keys from Chain Roots for a Role0 Key. | ||
SELECT | ||
role0_key, | ||
slot_no, | ||
txn | ||
FROM chain_root_for_role0_key | ||
-- Get all primary keys from Chain Root For TX ID (RBAC 509 Registrations). | ||
SELECT transaction_id | ||
FROM chain_root_for_txn_id |
Oops, something went wrong.