Skip to content

Commit

Permalink
fix(cat-gateway): bump scylla to v0.15.0 (#1316)
Browse files Browse the repository at this point in the history
* refactor: initial

* fix: arc type

* fix: query iter

* fix: functions

* fix: final

* chore: fmtfix

* chore: remove lints

* chore: remove lint from database object

* chore: remove result wrapper
  • Loading branch information
apskhem authored Dec 3, 2024
1 parent 6d5d1bc commit 46f7344
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 249 deletions.
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ anyhow = "1.0.92"
duration-string = "0.4.0"
build-info = "0.0.39"
ed25519-dalek = "2.1.1"
scylla = { version = "0.14.0", features = ["cloud", "full-serialization"] }
scylla = { version = "0.15.0", features = ["cloud", "full-serialization"] }
strum = { version = "0.26.3", features = ["derive"] }
strum_macros = "0.26.4"
openssl = { version = "0.10.66", features = ["vendored"] }
Expand Down
4 changes: 2 additions & 2 deletions catalyst-gateway/bin/src/db/index/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use registrations::{
};
use scylla::{
batch::Batch, prepared_statement::PreparedStatement, serialize::row::SerializeRow,
transport::iterator::RowIterator, QueryResult, Session,
transport::iterator::QueryPager, QueryResult, Session,
};
use staked_ada::{
get_assets_by_stake_address::GetAssetsByStakeAddressQuery,
Expand Down Expand Up @@ -311,7 +311,7 @@ impl PreparedQueries {
/// returns.
pub(crate) async fn execute_iter<P>(
&self, session: Arc<Session>, select_query: PreparedSelectQuery, params: P,
) -> anyhow::Result<RowIterator>
) -> anyhow::Result<QueryPager>
where P: SerializeRow {
let prepared_stmt = match select_query {
PreparedSelectQuery::TxoByStakeAddress => &self.txo_by_stake_address_query,
Expand Down
29 changes: 9 additions & 20 deletions catalyst-gateway/bin/src/db/index/queries/rbac/get_chain_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::sync::Arc;

use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow,
Session,
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;

Expand All @@ -22,23 +22,12 @@ pub(crate) struct GetChainRootQueryParams {
pub(crate) stake_address: Vec<u8>,
}

/// Get chain root by stake address query row result
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/828
// The macro uses expect to signal an error in deserializing values.
#[allow(clippy::expect_used)]
mod result {
use scylla::FromRow;

/// Get chain root query result.
#[derive(FromRow)]
pub(crate) struct GetChainRootQuery {
/// Chain root for the queries stake address.
pub(crate) chain_root: Vec<u8>,
}
}

/// Get chain root by stake address query.
pub(crate) struct GetChainRootQuery;
#[derive(DeserializeRow)]
pub(crate) struct GetChainRootQuery {
/// Chain root for the queries stake address.
pub(crate) chain_root: Vec<u8>,
}

impl GetChainRootQuery {
/// Prepares a get chain root by stake address query.
Expand All @@ -61,11 +50,11 @@ impl GetChainRootQuery {
/// Executes a get chain root by stake address query.
pub(crate) async fn execute(
session: &CassandraSession, params: GetChainRootQueryParams,
) -> anyhow::Result<TypedRowIterator<result::GetChainRootQuery>> {
) -> anyhow::Result<TypedRowStream<GetChainRootQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::ChainRootByStakeAddress, params)
.await?
.into_typed::<result::GetChainRootQuery>();
.rows_stream::<GetChainRootQuery>()?;

Ok(iter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::sync::Arc;

use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow,
Session,
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;

Expand All @@ -23,23 +23,12 @@ pub(crate) struct GetRegistrationsByChainRootQueryParams {
pub(crate) chain_root: Vec<u8>,
}

/// Get registrations by chain root query row result
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/828
// The macro uses expect to signal an error in deserializing values.
#[allow(clippy::expect_used)]
mod result {
use scylla::FromRow;

/// Get chain root query result.
#[derive(FromRow)]
pub(crate) struct GetRegistrationsByChainRootQuery {
/// Registration transaction id.
pub(crate) transaction_id: Vec<u8>,
}
}

/// Get chain root by stake address query.
pub(crate) struct GetRegistrationsByChainRootQuery;
#[derive(DeserializeRow)]
pub(crate) struct GetRegistrationsByChainRootQuery {
/// Registration transaction id.
pub(crate) transaction_id: Vec<u8>,
}

impl GetRegistrationsByChainRootQuery {
/// Prepares a get registrations by chain root query.
Expand All @@ -62,11 +51,11 @@ impl GetRegistrationsByChainRootQuery {
/// Executes a get registrations by chain root query.
pub(crate) async fn execute(
session: &CassandraSession, params: GetRegistrationsByChainRootQueryParams,
) -> anyhow::Result<TypedRowIterator<result::GetRegistrationsByChainRootQuery>> {
) -> anyhow::Result<TypedRowStream<GetRegistrationsByChainRootQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::RegistrationsByChainRoot, params)
.await?
.into_typed::<result::GetRegistrationsByChainRootQuery>();
.rows_stream::<GetRegistrationsByChainRootQuery>()?;

Ok(iter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::sync::Arc;

use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow,
Session,
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;

Expand All @@ -22,23 +22,12 @@ pub(crate) struct GetRole0ChainRootQueryParams {
pub(crate) role0_key: Vec<u8>,
}

/// Get chain root by role0 key query row result
// TODO: https://github.com/input-output-hk/catalyst-voices/issues/828
// The macro uses expect to signal an error in deserializing values.
#[allow(clippy::expect_used)]
mod result {
use scylla::FromRow;

/// Get role0 key chain root query result.
#[derive(FromRow)]
pub(crate) struct GetRole0ChainRootQuery {
/// Chain root.
pub(crate) chain_root: Vec<u8>,
}
}

/// Get chain root by role0 key query.
pub(crate) struct GetRole0ChainRootQuery;
#[derive(DeserializeRow)]
pub(crate) struct GetRole0ChainRootQuery {
/// Chain root.
pub(crate) chain_root: Vec<u8>,
}

impl GetRole0ChainRootQuery {
/// Prepares a get chain root by role0 key query.
Expand All @@ -61,11 +50,11 @@ impl GetRole0ChainRootQuery {
/// Executes a get chain root role0 key query.
pub(crate) async fn execute(
session: &CassandraSession, params: GetRole0ChainRootQueryParams,
) -> anyhow::Result<TypedRowIterator<result::GetRole0ChainRootQuery>> {
) -> anyhow::Result<TypedRowStream<GetRole0ChainRootQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::ChainRootByRole0Key, params)
.await?
.into_typed::<result::GetRole0ChainRootQuery>();
.rows_stream::<GetRole0ChainRootQuery>()?;

Ok(iter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::sync::Arc;

use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow,
Session,
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;

Expand Down Expand Up @@ -32,34 +32,26 @@ impl From<&ed25519_dalek::VerifyingKey> for GetRegistrationParams {
}
}

/// Get registration given stake addr or vote key
#[allow(clippy::expect_used)]
mod result {
use scylla::FromRow;

/// Get registration query result.
#[derive(FromRow)]
pub(crate) struct GetRegistrationQuery {
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
pub stake_address: Vec<u8>,
/// Nonce value after normalization.
pub nonce: num_bigint::BigInt,
/// Slot Number the cert is in.
pub slot_no: num_bigint::BigInt,
/// Transaction Index.
pub txn: i16,
/// Voting Public Key
pub vote_key: Vec<u8>,
/// Full Payment Address (not hashed, 32 byte ED25519 Public key).
pub payment_address: Vec<u8>,
/// Is the stake address a script or not.
pub is_payable: bool,
/// Is the Registration CIP36 format, or CIP15
pub cip36: bool,
}
}
/// Get registration query.
pub(crate) struct GetRegistrationQuery;
#[derive(DeserializeRow)]
pub(crate) struct GetRegistrationQuery {
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
pub stake_address: Vec<u8>,
/// Nonce value after normalization.
pub nonce: num_bigint::BigInt,
/// Slot Number the cert is in.
pub slot_no: num_bigint::BigInt,
/// Transaction Index.
pub txn: i16,
/// Voting Public Key
pub vote_key: Vec<u8>,
/// Full Payment Address (not hashed, 32 byte ED25519 Public key).
pub payment_address: Vec<u8>,
/// Is the stake address a script or not.
pub is_payable: bool,
/// Is the Registration CIP36 format, or CIP15
pub cip36: bool,
}

impl GetRegistrationQuery {
/// Prepares a get registration query.
Expand All @@ -82,11 +74,11 @@ impl GetRegistrationQuery {
/// Executes get registration info for given stake addr query.
pub(crate) async fn execute(
session: &CassandraSession, params: GetRegistrationParams,
) -> anyhow::Result<TypedRowIterator<result::GetRegistrationQuery>> {
) -> anyhow::Result<TypedRowStream<GetRegistrationQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::RegistrationFromStakeAddr, params)
.await?
.into_typed::<result::GetRegistrationQuery>();
.rows_stream::<GetRegistrationQuery>()?;

Ok(iter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::sync::Arc;

use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow,
Session,
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;

Expand All @@ -31,20 +31,12 @@ impl GetStakeAddrParams {
}
}

/// Get stake addr from stake hash query string.
#[allow(clippy::expect_used)]
mod result {
use scylla::FromRow;

/// Get stake addr from stake hash query result.
#[derive(FromRow)]
pub(crate) struct GetStakeAddrQuery {
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
pub stake_address: Vec<u8>,
}
/// Get stake addr from stake hash query.
#[derive(DeserializeRow)]
pub(crate) struct GetStakeAddrQuery {
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
pub stake_address: Vec<u8>,
}
/// Get registration query.
pub(crate) struct GetStakeAddrQuery;

impl GetStakeAddrQuery {
/// Prepares a get get stake addr from stake hash query.
Expand All @@ -67,11 +59,11 @@ impl GetStakeAddrQuery {
/// Executes a get txi by transaction hashes query.
pub(crate) async fn execute(
session: &CassandraSession, params: GetStakeAddrParams,
) -> anyhow::Result<TypedRowIterator<result::GetStakeAddrQuery>> {
) -> anyhow::Result<TypedRowStream<GetStakeAddrQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::StakeAddrFromStakeHash, params)
.await?
.into_typed::<result::GetStakeAddrQuery>();
.rows_stream::<GetStakeAddrQuery>()?;

Ok(iter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::sync::Arc;

use scylla::{
prepared_statement::PreparedStatement, transport::iterator::TypedRowIterator, SerializeRow,
Session,
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow,
SerializeRow, Session,
};
use tracing::error;

Expand All @@ -29,20 +29,12 @@ impl GetStakeAddrFromVoteKeyParams {
}
}

/// Get stake addr given vote key
#[allow(clippy::expect_used)]
mod result {
use scylla::FromRow;

/// Get stake addr from vote key query result.
#[derive(FromRow)]
pub(crate) struct GetStakeAddrFromVoteKeyQuery {
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
pub stake_address: Vec<u8>,
}
}
/// Get stake addr from vote key query.
pub(crate) struct GetStakeAddrFromVoteKeyQuery;
#[derive(DeserializeRow)]
pub(crate) struct GetStakeAddrFromVoteKeyQuery {
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
pub stake_address: Vec<u8>,
}

impl GetStakeAddrFromVoteKeyQuery {
/// Prepares a get stake addr from vote key query.
Expand All @@ -65,11 +57,11 @@ impl GetStakeAddrFromVoteKeyQuery {
/// Executes a get txi by transaction hashes query.
pub(crate) async fn execute(
session: &CassandraSession, params: GetStakeAddrFromVoteKeyParams,
) -> anyhow::Result<TypedRowIterator<result::GetStakeAddrFromVoteKeyQuery>> {
) -> anyhow::Result<TypedRowStream<GetStakeAddrFromVoteKeyQuery>> {
let iter = session
.execute_iter(PreparedSelectQuery::StakeAddrFromVoteKey, params)
.await?
.into_typed::<result::GetStakeAddrFromVoteKeyQuery>();
.rows_stream::<GetStakeAddrFromVoteKeyQuery>()?;

Ok(iter)
}
Expand Down
Loading

0 comments on commit 46f7344

Please sign in to comment.