From fd8fa7fe050f2c95524066d8e8669e14d7b90591 Mon Sep 17 00:00:00 2001 From: Godmode Galactus Date: Sat, 21 Oct 2023 18:40:19 +0200 Subject: [PATCH] making proper types --- migration.sql | 36 ++++++++++++++++++++++++++++++------ src/block_info.rs | 2 +- src/postgres.rs | 13 +++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/migration.sql b/migration.sql index fdea41e..042d695 100644 --- a/migration.sql +++ b/migration.sql @@ -1,21 +1,37 @@ CREATE SCHEMA banking_stage_results; +CREATE TYPE error AS ( + error text, + slot BIGINT, + count BIGINT +); + +CREATE TYPE ACCOUNT_USED AS ( + account CHAR(44), + r_w CHAR +); + +CREATE TYPE ACCOUNT_USE_COUNT AS ( + account CHAR(44), + cu BIGINT +); + CREATE TABLE banking_stage_results.transaction_infos ( - signature CHAR(88) NOT NULL, + signature CHAR(88) PRIMARY KEY, message text, - errors text, + errors ERROR[], is_executed BOOL, is_confirmed BOOL, first_notification_slot BIGINT NOT NULL, cu_requested BIGINT, prioritization_fees BIGINT, utc_timestamp TIMESTAMP WITH TIME ZONE NOT NULL, - accounts_used text[] - processed_slot BIGINT, + accounts_used ACCOUNT_USED[], + processed_slot BIGINT ); CREATE TABLE banking_stage_results.blocks ( - block_hash CHAR(44) NOT NULL, + block_hash CHAR(44) PRIMARY KEY, slot BIGINT, leader_identity CHAR(44), successful_transactions BIGINT, @@ -23,7 +39,15 @@ CREATE TABLE banking_stage_results.blocks ( processed_transactions BIGINT, total_cu_used BIGINT, total_cu_requested BIGINT, - heavily_writelocked_accounts text[] + heavily_writelocked_accounts ACCOUNT_USE_COUNT[] +); + +CREATE TABLE banking_stage_results.accounts ( + account CHAR(44) PRIMARY KEY, + account_borrow_outstanding BIGINT, + account_in_use_write BIGINT, + account_in_use_read BIGINT, + would_exceed_maximum_account_cost_limit BIGINT ); diff --git a/src/block_info.rs b/src/block_info.rs index 62541af..c4def74 100644 --- a/src/block_info.rs +++ b/src/block_info.rs @@ -202,7 +202,7 @@ impl BlockInfo { heavily_writelocked_accounts.sort_by(|lhs, rhs| (*rhs.1).cmp(lhs.1)); let heavily_writelocked_accounts = heavily_writelocked_accounts .iter() - .map(|(pubkey, cu)| format!("{}:{}", **pubkey, **cu)) + .map(|(pubkey, cu)| format!("({}, {})", **pubkey, **cu)) .collect_vec(); BlockInfo { block_hash, diff --git a/src/postgres.rs b/src/postgres.rs index f94c7da..17a4554 100644 --- a/src/postgres.rs +++ b/src/postgres.rs @@ -200,7 +200,7 @@ impl Postgres { pub struct PostgresTransactionInfo { pub signature: String, pub transaction_message: Option, - pub errors: String, + pub errors: Vec, pub is_executed: bool, pub is_confirmed: bool, pub first_notification_slot: i64, @@ -213,14 +213,15 @@ pub struct PostgresTransactionInfo { impl From<&TransactionInfo> for PostgresTransactionInfo { fn from(value: &TransactionInfo) -> Self { - let errors = value.errors.iter().fold(String::new(), |is, x| { - let str = is + x.0.to_string().as_str() + ":" + x.1.to_string().as_str() + ";"; - str - }); + let errors = value + .errors + .iter() + .map(|(key, size)| format!("({}, {}, {})", key.error, key.slot, size)) + .collect_vec(); let accounts_used = value .account_used .iter() - .map(|x| format!("{}({})", x.0, x.1).to_string()) + .map(|x| format!("({}, {})", x.0, x.1)) .collect(); Self { signature: value.signature.clone(),