Skip to content

fix(cat-gateway): Fix cip36 endpoint #2124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions catalyst-gateway/bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ prometheus = "0.13.4"
rust-embed = "8.5.0"
num-traits = "0.2.19"
base64 = "0.22.1"
dashmap = { version = "6.1.0", features = ["rayon"] }
jsonschema = "0.26.1"
bech32 = "0.11.0"
const_format = "0.2.33"
Expand All @@ -96,7 +95,6 @@ mime = "0.3.17"
stats_alloc = "0.1.10"
memory-stats = "1.0.0"
derive_more = { version = "2.0.1", default-features = false, features = ["from", "into"] }
rayon = "1.10"

# Its a transitive dependency of the "poem-openapi" crate,
# but its breaks API after version "5.1.8".
Expand Down
22 changes: 11 additions & 11 deletions catalyst-gateway/bin/src/cardano/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,23 @@ impl SyncParams {
}

/// Convert Params into the result of the sync.
fn done(
pub(crate) fn done(
&self, first: Option<Point>, first_immutable: bool, last: Option<Point>,
last_immutable: bool, synced: u64, result: anyhow::Result<()>,
) -> Self {
if result.is_ok() && first_immutable && last_immutable {
if result.is_ok() && self.end != Point::TIP {
// Update sync status in the Immutable DB.
// Can fire and forget, because failure to update DB will simply cause the chunk to be
// re-indexed, on recovery.
update_sync_status(self.end.slot_or_default(), self.start.slot_or_default());
}

let mut done = self.clone();
done.first_indexed_block = first;
done.first_is_immutable = first_immutable;
done.last_indexed_block = last;
done.last_is_immutable = last_immutable;
done.total_blocks_synced = done.total_blocks_synced.saturating_add(synced);
done.last_blocks_synced = synced;

done.result = Arc::new(Some(result));

done
Expand Down Expand Up @@ -265,7 +263,7 @@ fn sync_subchain(
// What we need to do here is tell the primary follower to start a new sync
// for the new immutable data, and then purge the volatile database of the
// old data (after the immutable data has synced).
info!(chain=%params.chain, "Immutable chain rolled forward.");
info!(chain=%params.chain, point=?chain_update.block_data().point(), "Immutable chain rolled forward.");
let mut result = params.done(
first_indexed_block,
first_immutable,
Expand All @@ -275,9 +273,10 @@ fn sync_subchain(
Ok(()),
);
// Signal the point the immutable chain rolled forward to.
// If this is live chain immediately stops to later run immutable sync tasks
result.follower_roll_forward = Some(chain_update.block_data().point());
return result;
};
}
},
cardano_chain_follower::Kind::Block => {
let block = chain_update.block_data();
Expand Down Expand Up @@ -311,8 +310,9 @@ fn sync_subchain(

let purge_condition = PurgeCondition::PurgeForwards(rollback_slot);
if let Err(error) = roll_forward::purge_live_index(purge_condition).await {
error!(chain=%params.chain, error=%error, "Chain follower
rollback, purging volatile data task failed.");
error!(chain=%params.chain, error=%error,
"Chain follower rollback, purging volatile data task failed."
);
} else {
// How many slots are purged
#[allow(clippy::arithmetic_side_effects)]
Expand Down Expand Up @@ -364,7 +364,7 @@ fn sync_subchain(
Ok(()),
);

info!(chain = %params.chain, result=%result, "Indexing Blockchain Completed: OK");
info!(chain = %result.chain, result=%result, "Indexing Blockchain Completed: OK");

result
})
Expand Down Expand Up @@ -539,7 +539,7 @@ impl SyncTask {
},
Err(error) => {
error!(chain=%self.cfg.chain, report=%finished, error=%error,
"An Immutable follower failed, restarting it.");
"An Immutable follower failed, restarting it.");
// Restart the Immutable Chain sync task again from where it left
// off.
self.sync_tasks.push(sync_subchain(
Expand All @@ -550,7 +550,7 @@ impl SyncTask {
}
} else {
error!(chain=%self.cfg.chain, report=%finished,
"BUG: The Immutable follower completed, but without a proper result.");
"BUG: The Immutable follower completed, but without a proper result.");
}
},
Err(error) => {
Expand Down
62 changes: 36 additions & 26 deletions catalyst-gateway/bin/src/db/index/block/certs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
settings::cassandra_db,
};

/// Insert TXI Query and Parameters
/// Insert stake registration query
#[derive(SerializeRow)]
pub(crate) struct StakeRegistrationInsertQuery {
/// Stake address (29 bytes).
Expand All @@ -29,23 +29,22 @@ pub(crate) struct StakeRegistrationInsertQuery {
/// Transaction Index.
txn_index: DbTxnIndex,
/// Full Stake Public Key (32 byte Ed25519 Public key, not hashed).
stake_public_key: MaybeUnset<DbPublicKey>,
stake_public_key: DbPublicKey,
/// Is the stake address a script or not.
script: bool,
/// Is the Certificate Registered?
/// Is the Cardano Certificate Registered
register: MaybeUnset<bool>,
/// Is the Certificate Deregistered?
/// Is the Cardano Certificate Deregistered
deregister: MaybeUnset<bool>,
/// Is the stake address contains CIP36 registration?
cip36: MaybeUnset<bool>,
/// Pool Delegation Address
pool_delegation: MaybeUnset<Vec<u8>>,
}

impl Debug for StakeRegistrationInsertQuery {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
let stake_public_key = match self.stake_public_key {
MaybeUnset::Unset => "UNSET",
MaybeUnset::Set(ref v) => &hex::encode(v.as_ref()),
};
let stake_public_key = hex::encode(self.stake_public_key.as_ref());
let register = match self.register {
MaybeUnset::Unset => "UNSET",
MaybeUnset::Set(v) => &format!("{v:?}"),
Expand All @@ -54,6 +53,10 @@ impl Debug for StakeRegistrationInsertQuery {
MaybeUnset::Unset => "UNSET",
MaybeUnset::Set(v) => &format!("{v:?}"),
};
let cip36 = match self.cip36 {
MaybeUnset::Unset => "UNSET",
MaybeUnset::Set(v) => &format!("{v:?}"),
};
let pool_delegation = match self.pool_delegation {
MaybeUnset::Unset => "UNSET",
MaybeUnset::Set(ref v) => &hex::encode(v),
Expand All @@ -67,29 +70,28 @@ impl Debug for StakeRegistrationInsertQuery {
.field("script", &self.script)
.field("register", &register)
.field("deregister", &deregister)
.field("cip36", &cip36)
.field("pool_delegation", &pool_delegation)
.finish()
}
}

/// TXI by Txn hash Index
/// Insert stake registration
const INSERT_STAKE_REGISTRATION_QUERY: &str = include_str!("./cql/insert_stake_registration.cql");

impl StakeRegistrationInsertQuery {
/// Create a new Insert Query.
#[allow(clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
pub fn new(
stake_address: StakeAddress, slot_no: Slot, txn_index: TxnIndex,
stake_public_key: Option<VerifyingKey>, script: bool, register: bool, deregister: bool,
pool_delegation: Option<Vec<u8>>,
stake_public_key: VerifyingKey, script: bool, register: bool, deregister: bool,
cip36: bool, pool_delegation: Option<Vec<u8>>,
) -> Self {
let stake_public_key =
stake_public_key.map_or(MaybeUnset::Unset, |a| MaybeUnset::Set(a.into()));
StakeRegistrationInsertQuery {
stake_address: stake_address.into(),
slot_no: slot_no.into(),
txn_index: txn_index.into(),
stake_public_key,
stake_public_key: stake_public_key.into(),
script,
register: if register {
MaybeUnset::Set(true)
Expand All @@ -101,6 +103,11 @@ impl StakeRegistrationInsertQuery {
} else {
MaybeUnset::Unset
},
cip36: if cip36 {
MaybeUnset::Set(true)
} else {
MaybeUnset::Unset
},
pool_delegation: if let Some(pool_delegation) = pool_delegation {
MaybeUnset::Set(pool_delegation)
} else {
Expand All @@ -109,7 +116,7 @@ impl StakeRegistrationInsertQuery {
}
}

/// Prepare Batch of Insert TXI Index Data Queries
/// Prepare Batch of Insert stake registration.
pub(crate) async fn prepare_batch(
session: &Arc<Session>, cfg: &cassandra_db::EnvVars,
) -> anyhow::Result<SizedBatch> {
Expand Down Expand Up @@ -184,16 +191,19 @@ impl CertInsertQuery {
}

// This may not be witnessed, its normal but disappointing.
self.stake_reg_data.push(StakeRegistrationInsertQuery::new(
stake_address,
slot_no,
txn,
pubkey,
script,
register,
deregister,
delegation,
));
if let Some(pubkey) = pubkey {
self.stake_reg_data.push(StakeRegistrationInsertQuery::new(
stake_address,
slot_no,
txn,
pubkey,
script,
register,
deregister,
false,
delegation,
));
}
}

/// Index an Alonzo Era certificate into the database.
Expand Down
Loading
Loading