v0.5.3-pre.002
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: ks-store/src/postgres/query/replay_candidate_queries.rs
|
||||
// version: 4
|
||||
// version: 6
|
||||
|
||||
//! Read-only PostgreSQL queries for replay candidate discovery.
|
||||
|
||||
@@ -14,9 +14,9 @@ struct ReplayTransactionCandidateRow {
|
||||
ledger_status: std::string::String,
|
||||
processor_version: std::option::Option<std::string::String>,
|
||||
attempt_count: i32,
|
||||
outer_instruction_count: i64,
|
||||
top_level_instruction_count: i64,
|
||||
inner_instruction_count: i64,
|
||||
outer_program_count: i64,
|
||||
top_level_program_count: i64,
|
||||
inner_program_count: i64,
|
||||
updated_at: std::string::String,
|
||||
}
|
||||
@@ -25,7 +25,7 @@ struct ReplayTransactionCandidateRow {
|
||||
struct ReplayProgramSummaryRow {
|
||||
program_id: std::string::String,
|
||||
transaction_count: i64,
|
||||
outer_instruction_count: i64,
|
||||
top_level_instruction_count: i64,
|
||||
inner_instruction_count: i64,
|
||||
log_count: i64,
|
||||
min_slot: i64,
|
||||
@@ -42,10 +42,10 @@ struct ReplayEntitySummaryRow {
|
||||
max_slot: i64,
|
||||
}
|
||||
|
||||
pub(in crate::postgres) async fn list_replay_transaction_candidates(
|
||||
pub(crate) async fn list_replay_transaction_candidates(
|
||||
pool: &sqlx::PgPool,
|
||||
filter: &crate::PostgresReplayTransactionFilter,
|
||||
) -> ks_core::Result<std::vec::Vec<crate::PostgresReplayTransactionCandidate>> {
|
||||
filter: &crate::ReplayTransactionFilter,
|
||||
) -> ks_core::Result<std::vec::Vec<crate::ReplayTransactionCandidate>> {
|
||||
let min_slot_result =
|
||||
crate::postgres::query::replay_candidate_queries::optional_sql_bigint(filter.min_slot);
|
||||
let min_slot = match min_slot_result {
|
||||
@@ -93,7 +93,7 @@ pub(in crate::postgres) async fn list_replay_transaction_candidates(
|
||||
};
|
||||
let mut output = std::vec::Vec::with_capacity(rows.len());
|
||||
for row in rows {
|
||||
output.push(crate::PostgresReplayTransactionCandidate {
|
||||
output.push(crate::ReplayTransactionCandidate {
|
||||
signature: row.signature,
|
||||
slot: row.slot,
|
||||
raw_processing_state: row.raw_processing_state,
|
||||
@@ -103,9 +103,9 @@ pub(in crate::postgres) async fn list_replay_transaction_candidates(
|
||||
ledger_status: row.ledger_status,
|
||||
processor_version: row.processor_version,
|
||||
attempt_count: row.attempt_count,
|
||||
outer_instruction_count: row.outer_instruction_count,
|
||||
top_level_instruction_count: row.top_level_instruction_count,
|
||||
inner_instruction_count: row.inner_instruction_count,
|
||||
outer_program_count: row.outer_program_count,
|
||||
top_level_program_count: row.top_level_program_count,
|
||||
inner_program_count: row.inner_program_count,
|
||||
updated_at: row.updated_at,
|
||||
});
|
||||
@@ -113,13 +113,13 @@ pub(in crate::postgres) async fn list_replay_transaction_candidates(
|
||||
return std::result::Result::Ok(output);
|
||||
}
|
||||
|
||||
pub(in crate::postgres) async fn list_replay_program_summaries(
|
||||
pub(crate) async fn list_replay_program_summaries(
|
||||
pool: &sqlx::PgPool,
|
||||
filter: &crate::PostgresReplayProgramFilter,
|
||||
) -> ks_core::Result<std::vec::Vec<crate::PostgresReplayProgramSummary>> {
|
||||
filter: &crate::ReplayProgramFilter,
|
||||
) -> ks_core::Result<std::vec::Vec<crate::ReplayProgramSummary>> {
|
||||
let query_result = sqlx::query_as::<sqlx::Postgres, crate::postgres::query::replay_candidate_queries::ReplayProgramSummaryRow>(
|
||||
r#"WITH occurrences AS (
|
||||
SELECT program_id, signature, slot, 'outer'::TEXT AS scope FROM kb_sol_core_instructions
|
||||
SELECT program_id, signature, slot, 'top_level'::TEXT AS scope FROM kb_sol_core_instructions
|
||||
UNION ALL
|
||||
SELECT program_id, signature, slot, 'inner'::TEXT AS scope FROM kb_sol_core_inner_instructions
|
||||
UNION ALL
|
||||
@@ -127,7 +127,7 @@ pub(in crate::postgres) async fn list_replay_program_summaries(
|
||||
)
|
||||
SELECT program_id,
|
||||
COUNT(DISTINCT signature)::BIGINT AS transaction_count,
|
||||
COUNT(*) FILTER (WHERE scope = 'outer')::BIGINT AS outer_instruction_count,
|
||||
COUNT(*) FILTER (WHERE scope = 'top_level')::BIGINT AS top_level_instruction_count,
|
||||
COUNT(*) FILTER (WHERE scope = 'inner')::BIGINT AS inner_instruction_count,
|
||||
COUNT(*) FILTER (WHERE scope = 'logs')::BIGINT AS log_count,
|
||||
MIN(slot)::BIGINT AS min_slot,
|
||||
@@ -152,10 +152,10 @@ pub(in crate::postgres) async fn list_replay_program_summaries(
|
||||
};
|
||||
let mut output = std::vec::Vec::with_capacity(rows.len());
|
||||
for row in rows {
|
||||
output.push(crate::PostgresReplayProgramSummary {
|
||||
output.push(crate::ReplayProgramSummary {
|
||||
program_id: row.program_id,
|
||||
transaction_count: row.transaction_count,
|
||||
outer_instruction_count: row.outer_instruction_count,
|
||||
top_level_instruction_count: row.top_level_instruction_count,
|
||||
inner_instruction_count: row.inner_instruction_count,
|
||||
log_count: row.log_count,
|
||||
min_slot: row.min_slot,
|
||||
@@ -165,10 +165,10 @@ pub(in crate::postgres) async fn list_replay_program_summaries(
|
||||
return std::result::Result::Ok(output);
|
||||
}
|
||||
|
||||
pub(in crate::postgres) async fn list_replay_entity_summaries(
|
||||
pub(crate) async fn list_replay_entity_summaries(
|
||||
pool: &sqlx::PgPool,
|
||||
filter: &crate::PostgresReplayEntityFilter,
|
||||
) -> ks_core::Result<std::vec::Vec<crate::PostgresReplayEntitySummary>> {
|
||||
filter: &crate::ReplayEntityFilter,
|
||||
) -> ks_core::Result<std::vec::Vec<crate::ReplayEntitySummary>> {
|
||||
let entity_kind = filter.entity_kind.as_sql();
|
||||
let query_result = sqlx::query_as::<
|
||||
sqlx::Postgres,
|
||||
@@ -214,7 +214,7 @@ pub(in crate::postgres) async fn list_replay_entity_summaries(
|
||||
};
|
||||
let mut output = std::vec::Vec::with_capacity(rows.len());
|
||||
for row in rows {
|
||||
output.push(crate::PostgresReplayEntitySummary {
|
||||
output.push(crate::ReplayEntitySummary {
|
||||
entity_kind: row.entity_kind,
|
||||
entity_value: row.entity_value,
|
||||
transaction_count: row.transaction_count,
|
||||
@@ -245,9 +245,9 @@ fn transaction_candidate_sql(order: &str) -> &'static str {
|
||||
COALESCE(ledger.status, 'not_started') AS ledger_status,
|
||||
ledger.processor_version,
|
||||
COALESCE(ledger.attempt_count, 0)::INTEGER AS attempt_count,
|
||||
COALESCE(outer_stats.instruction_count, 0)::BIGINT AS outer_instruction_count,
|
||||
COALESCE(top_level_stats.instruction_count, 0)::BIGINT AS top_level_instruction_count,
|
||||
COALESCE(inner_stats.instruction_count, 0)::BIGINT AS inner_instruction_count,
|
||||
COALESCE(outer_stats.program_count, 0)::BIGINT AS outer_program_count,
|
||||
COALESCE(top_level_stats.program_count, 0)::BIGINT AS top_level_program_count,
|
||||
COALESCE(inner_stats.program_count, 0)::BIGINT AS inner_program_count,
|
||||
raw.updated_at::TEXT AS updated_at
|
||||
FROM kb_sol_raw_transactions raw
|
||||
@@ -265,7 +265,7 @@ fn transaction_candidate_sql(order: &str) -> &'static str {
|
||||
SELECT COUNT(*)::BIGINT AS instruction_count, COUNT(DISTINCT program_id)::BIGINT AS program_count
|
||||
FROM kb_sol_core_instructions
|
||||
WHERE signature = raw.signature
|
||||
) outer_stats ON TRUE
|
||||
) top_level_stats ON TRUE
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT COUNT(*)::BIGINT AS instruction_count, COUNT(DISTINCT program_id)::BIGINT AS program_count
|
||||
FROM kb_sol_core_inner_instructions
|
||||
@@ -278,11 +278,11 @@ fn transaction_candidate_sql(order: &str) -> &'static str {
|
||||
AND ($5::TEXT IS NULL OR ($5 = 'not_started' AND ledger.status IS NULL) OR ledger.status = $5)
|
||||
AND ($6::TEXT IS NULL OR
|
||||
($7 = 'any' AND (
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_outer WHERE candidate_outer.signature = raw.signature AND candidate_outer.program_id = $6) OR
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_top_level WHERE candidate_top_level.signature = raw.signature AND candidate_top_level.program_id = $6) OR
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_inner_instructions candidate_inner WHERE candidate_inner.signature = raw.signature AND candidate_inner.program_id = $6) OR
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_logs candidate_log WHERE candidate_log.signature = raw.signature AND candidate_log.program_id = $6)
|
||||
)) OR
|
||||
($7 = 'outer' AND EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_outer WHERE candidate_outer.signature = raw.signature AND candidate_outer.program_id = $6)) OR
|
||||
($7 = 'top_level' AND EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_top_level WHERE candidate_top_level.signature = raw.signature AND candidate_top_level.program_id = $6)) OR
|
||||
($7 = 'inner' AND EXISTS (SELECT 1 FROM kb_sol_core_inner_instructions candidate_inner WHERE candidate_inner.signature = raw.signature AND candidate_inner.program_id = $6)) OR
|
||||
($7 = 'logs' AND EXISTS (SELECT 1 FROM kb_sol_core_logs candidate_log WHERE candidate_log.signature = raw.signature AND candidate_log.program_id = $6)))
|
||||
AND ($8::TEXT IS NULL OR
|
||||
@@ -313,9 +313,9 @@ fn transaction_candidate_sql(order: &str) -> &'static str {
|
||||
COALESCE(ledger.status, 'not_started') AS ledger_status,
|
||||
ledger.processor_version,
|
||||
COALESCE(ledger.attempt_count, 0)::INTEGER AS attempt_count,
|
||||
COALESCE(outer_stats.instruction_count, 0)::BIGINT AS outer_instruction_count,
|
||||
COALESCE(top_level_stats.instruction_count, 0)::BIGINT AS top_level_instruction_count,
|
||||
COALESCE(inner_stats.instruction_count, 0)::BIGINT AS inner_instruction_count,
|
||||
COALESCE(outer_stats.program_count, 0)::BIGINT AS outer_program_count,
|
||||
COALESCE(top_level_stats.program_count, 0)::BIGINT AS top_level_program_count,
|
||||
COALESCE(inner_stats.program_count, 0)::BIGINT AS inner_program_count,
|
||||
raw.updated_at::TEXT AS updated_at
|
||||
FROM kb_sol_raw_transactions raw
|
||||
@@ -333,7 +333,7 @@ fn transaction_candidate_sql(order: &str) -> &'static str {
|
||||
SELECT COUNT(*)::BIGINT AS instruction_count, COUNT(DISTINCT program_id)::BIGINT AS program_count
|
||||
FROM kb_sol_core_instructions
|
||||
WHERE signature = raw.signature
|
||||
) outer_stats ON TRUE
|
||||
) top_level_stats ON TRUE
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT COUNT(*)::BIGINT AS instruction_count, COUNT(DISTINCT program_id)::BIGINT AS program_count
|
||||
FROM kb_sol_core_inner_instructions
|
||||
@@ -346,11 +346,11 @@ fn transaction_candidate_sql(order: &str) -> &'static str {
|
||||
AND ($5::TEXT IS NULL OR ($5 = 'not_started' AND ledger.status IS NULL) OR ledger.status = $5)
|
||||
AND ($6::TEXT IS NULL OR
|
||||
($7 = 'any' AND (
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_outer WHERE candidate_outer.signature = raw.signature AND candidate_outer.program_id = $6) OR
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_top_level WHERE candidate_top_level.signature = raw.signature AND candidate_top_level.program_id = $6) OR
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_inner_instructions candidate_inner WHERE candidate_inner.signature = raw.signature AND candidate_inner.program_id = $6) OR
|
||||
EXISTS (SELECT 1 FROM kb_sol_core_logs candidate_log WHERE candidate_log.signature = raw.signature AND candidate_log.program_id = $6)
|
||||
)) OR
|
||||
($7 = 'outer' AND EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_outer WHERE candidate_outer.signature = raw.signature AND candidate_outer.program_id = $6)) OR
|
||||
($7 = 'top_level' AND EXISTS (SELECT 1 FROM kb_sol_core_instructions candidate_top_level WHERE candidate_top_level.signature = raw.signature AND candidate_top_level.program_id = $6)) OR
|
||||
($7 = 'inner' AND EXISTS (SELECT 1 FROM kb_sol_core_inner_instructions candidate_inner WHERE candidate_inner.signature = raw.signature AND candidate_inner.program_id = $6)) OR
|
||||
($7 = 'logs' AND EXISTS (SELECT 1 FROM kb_sol_core_logs candidate_log WHERE candidate_log.signature = raw.signature AND candidate_log.program_id = $6)))
|
||||
AND ($8::TEXT IS NULL OR
|
||||
@@ -400,7 +400,7 @@ mod tests {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_error) => return,
|
||||
};
|
||||
let _postgres_guard = crate::postgres::test_serial::postgres_test_guard().await;
|
||||
let _postgres_guard = crate::postgres_test_guard().await;
|
||||
let options_result = crate::PostgresStoreOptions::new(database_url, 1, 5000, false);
|
||||
let options = match options_result {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -419,14 +419,14 @@ mod tests {
|
||||
if let std::result::Result::Err(error) = core_schema_result {
|
||||
panic!("unexpected core schema error: {error}");
|
||||
}
|
||||
let transaction_filter_result = crate::PostgresReplayTransactionFilter::new(
|
||||
let transaction_filter_result = crate::ReplayTransactionFilter::new(
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
crate::PostgresReplayProgramScope::Any,
|
||||
crate::ReplayProgramScope::Any,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
10,
|
||||
@@ -442,8 +442,7 @@ mod tests {
|
||||
if let std::result::Result::Err(error) = transaction_result {
|
||||
panic!("unexpected transaction candidate query error: {error}");
|
||||
}
|
||||
let program_filter_result =
|
||||
crate::PostgresReplayProgramFilter::new(std::option::Option::None, 10);
|
||||
let program_filter_result = crate::ReplayProgramFilter::new(std::option::Option::None, 10);
|
||||
let program_filter = match program_filter_result {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => panic!("unexpected program filter error: {error}"),
|
||||
@@ -453,12 +452,12 @@ mod tests {
|
||||
panic!("unexpected program summary query error: {error}");
|
||||
}
|
||||
for entity_kind in [
|
||||
crate::PostgresReplayEntityKind::Mint,
|
||||
crate::PostgresReplayEntityKind::Owner,
|
||||
crate::PostgresReplayEntityKind::AccountKey,
|
||||
crate::ReplayEntityKind::Mint,
|
||||
crate::ReplayEntityKind::Owner,
|
||||
crate::ReplayEntityKind::AccountKey,
|
||||
] {
|
||||
let entity_filter_result =
|
||||
crate::PostgresReplayEntityFilter::new(entity_kind, std::option::Option::None, 10);
|
||||
crate::ReplayEntityFilter::new(entity_kind, std::option::Option::None, 10);
|
||||
let entity_filter = match entity_filter_result {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
|
||||
Reference in New Issue
Block a user