diff --git a/.sqlx/query-4fbeeaff4eb307089f65b1ce032f9f597ecbfe44b2d76ddca04125f64bf65b11.json b/.sqlx/query-4fbeeaff4eb307089f65b1ce032f9f597ecbfe44b2d76ddca04125f64bf65b11.json new file mode 100644 index 000000000..b3d4f55a2 --- /dev/null +++ b/.sqlx/query-4fbeeaff4eb307089f65b1ce032f9f597ecbfe44b2d76ddca04125f64bf65b11.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT value\nFROM account_slots\nWHERE account_address = $1\nAND idx = $2\n", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "value", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Bytea", + "Bytea" + ] + }, + "nullable": [ + false + ] + }, + "hash": "4fbeeaff4eb307089f65b1ce032f9f597ecbfe44b2d76ddca04125f64bf65b11" +} diff --git a/.sqlx/query-a5ab4b2493cbf61ac57667946e32272f13c0a3ba35629517c157835e24c27ad7.json b/.sqlx/query-a5ab4b2493cbf61ac57667946e32272f13c0a3ba35629517c157835e24c27ad7.json new file mode 100644 index 000000000..cd3616c17 --- /dev/null +++ b/.sqlx/query-a5ab4b2493cbf61ac57667946e32272f13c0a3ba35629517c157835e24c27ad7.json @@ -0,0 +1,24 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT value\nFROM historical_slots\nWHERE account_address = $1\nAND idx = $2\nAND block_number = (SELECT MAX(block_number)\n FROM historical_slots\n WHERE account_address = $1\n AND idx = $2\n AND block_number <= $3)\n", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "value", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Bytea", + "Bytea", + "Numeric" + ] + }, + "nullable": [ + false + ] + }, + "hash": "a5ab4b2493cbf61ac57667946e32272f13c0a3ba35629517c157835e24c27ad7" +} diff --git a/.sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json b/.sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json deleted file mode 100644 index 13b6eaac5..000000000 --- a/.sqlx/query-e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT\n idx as \"index: _\",\n value as \"value: _\"\nFROM account_slots\nWHERE account_address = $1\nAND idx = $2\n", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "index: _", - "type_info": "Bytea" - }, - { - "ordinal": 1, - "name": "value: _", - "type_info": "Bytea" - } - ], - "parameters": { - "Left": [ - "Bytea", - "Bytea" - ] - }, - "nullable": [ - false, - false - ] - }, - "hash": "e2bbf70bff8147a1955a2b65838419cab2f276ed2817e2278f8166bd8c2bdc41" -} diff --git a/.sqlx/query-f21480f34d6d71a9a5c02ebad283b26cbeee229572ee97d0930ddb95253115f2.json b/.sqlx/query-f21480f34d6d71a9a5c02ebad283b26cbeee229572ee97d0930ddb95253115f2.json deleted file mode 100644 index 02ff320cf..000000000 --- a/.sqlx/query-f21480f34d6d71a9a5c02ebad283b26cbeee229572ee97d0930ddb95253115f2.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT\n idx as \"index: _\",\n value as \"value: _\"\nFROM historical_slots\nWHERE account_address = $1\nAND idx = $2\nAND block_number = (SELECT MAX(block_number)\n FROM historical_slots\n WHERE account_address = $1\n AND idx = $2\n AND block_number <= $3)\n", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "index: _", - "type_info": "Bytea" - }, - { - "ordinal": 1, - "name": "value: _", - "type_info": "Bytea" - } - ], - "parameters": { - "Left": [ - "Bytea", - "Bytea", - "Numeric" - ] - }, - "nullable": [ - false, - false - ] - }, - "hash": "f21480f34d6d71a9a5c02ebad283b26cbeee229572ee97d0930ddb95253115f2" -} diff --git a/src/eth/storage/postgres_permanent/postgres_permanent.rs b/src/eth/storage/postgres_permanent/postgres_permanent.rs index 978cfc2e5..b7e0091e6 100644 --- a/src/eth/storage/postgres_permanent/postgres_permanent.rs +++ b/src/eth/storage/postgres_permanent/postgres_permanent.rs @@ -34,6 +34,7 @@ use crate::eth::primitives::LogTopic; use crate::eth::primitives::Slot; use crate::eth::primitives::SlotIndex; use crate::eth::primitives::SlotSample; +use crate::eth::primitives::SlotValue; use crate::eth::primitives::StoragePointInTime; use crate::eth::primitives::TransactionMined; use crate::eth::storage::postgres_permanent::types::AccountBatch; @@ -164,10 +165,9 @@ impl PermanentStorage for PostgresPermanentStorage { let slot_index_u8: [u8; 32] = slot_index.clone().into(); let mut conn = PoolOrThreadConnection::take(&self.pool).await?; - let slot = match point_in_time { + let slot_value_vec: Option> = match point_in_time { StoragePointInTime::Present => - sqlx::query_file_as!( - Slot, + sqlx::query_file_scalar!( "src/eth/storage/postgres_permanent/sql/select_slot.sql", address.as_ref(), slot_index_u8.as_ref(), @@ -176,8 +176,7 @@ impl PermanentStorage for PostgresPermanentStorage { .await?, StoragePointInTime::Past(number) => { let block_number: i64 = (*number).try_into()?; - sqlx::query_file_as!( - Slot, + sqlx::query_file_scalar!( "src/eth/storage/postgres_permanent/sql/select_slot_at_block.sql", address.as_ref(), slot_index_u8.as_ref(), @@ -190,8 +189,13 @@ impl PermanentStorage for PostgresPermanentStorage { // If there is no slot, we return // an "empty slot" - match slot { - Some(slot) => { + match slot_value_vec { + Some(slot_value_vec) => { + let slot_value = SlotValue::from(slot_value_vec); + let slot = Slot { + index: slot_index.clone(), + value: slot_value, + }; tracing::trace!(?address, ?slot_index, %slot, "slot found"); Ok(Some(slot)) } diff --git a/src/eth/storage/postgres_permanent/sql/select_slot.sql b/src/eth/storage/postgres_permanent/sql/select_slot.sql index 95a210561..09b1028a7 100644 --- a/src/eth/storage/postgres_permanent/sql/select_slot.sql +++ b/src/eth/storage/postgres_permanent/sql/select_slot.sql @@ -1,6 +1,4 @@ -SELECT - idx as "index: _", - value as "value: _" +SELECT value FROM account_slots WHERE account_address = $1 AND idx = $2 diff --git a/src/eth/storage/postgres_permanent/sql/select_slot_at_block.sql b/src/eth/storage/postgres_permanent/sql/select_slot_at_block.sql index c446b1b05..392273036 100644 --- a/src/eth/storage/postgres_permanent/sql/select_slot_at_block.sql +++ b/src/eth/storage/postgres_permanent/sql/select_slot_at_block.sql @@ -1,6 +1,4 @@ -SELECT - idx as "index: _", - value as "value: _" +SELECT value FROM historical_slots WHERE account_address = $1 AND idx = $2 diff --git a/tests/test_import_offline_snapshot.rs b/tests/test_import_offline_snapshot.rs index c72da2733..db7150206 100644 --- a/tests/test_import_offline_snapshot.rs +++ b/tests/test_import_offline_snapshot.rs @@ -25,40 +25,50 @@ mod m { } #[cfg(feature = "metrics")] -const METRIC_QUERIES: [&str; 30] = [ +const METRIC_QUERIES: [&str; 43] = [ // EVM - "", + "* EVM", m::formatcp!("{}_count", m::METRIC_EVM_EXECUTION), m::formatcp!("{}_sum", m::METRIC_EVM_EXECUTION), m::formatcp!("{}{{quantile='1'}}", m::METRIC_EVM_EXECUTION), - // STORAGE ACCOUNTS - "", + m::formatcp!("{}{{quantile='0.95'}}", m::METRIC_EVM_EXECUTION), + "* ACCOUNTS (count)", m::formatcp!("sum({}_count)", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}_count{{found_at='temporary'}}", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}_count{{found_at='permanent'}}", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}_count{{found_at='default'}}", m::METRIC_STORAGE_READ_ACCOUNT), + "* ACCOUNTS (cumulative)", m::formatcp!("sum({}_sum)", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}_sum{{found_at='temporary'}}", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}_sum{{found_at='permanent'}}", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}_sum{{found_at='default'}}", m::METRIC_STORAGE_READ_ACCOUNT), + "* ACCOUNTS (P100)", m::formatcp!("{}{{found_at='temporary', quantile='1'}}", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}{{found_at='permanent', quantile='1'}}", m::METRIC_STORAGE_READ_ACCOUNT), m::formatcp!("{}{{found_at='default', quantile='1'}}", m::METRIC_STORAGE_READ_ACCOUNT), - // STORAGE SLOTS - "", + "* ACCOUNTS (P95)", + m::formatcp!("{}{{found_at='temporary', quantile='0.95'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}{{found_at='permanent', quantile='0.95'}}", m::METRIC_STORAGE_READ_ACCOUNT), + m::formatcp!("{}{{found_at='default', quantile='0.95'}}", m::METRIC_STORAGE_READ_ACCOUNT), + "* STORAGE SLOTS (count)", m::formatcp!("sum({}_count)", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}_count{{found_at='temporary'}}", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}_count{{found_at='permanent'}}", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}_count{{found_at='default'}}", m::METRIC_STORAGE_READ_SLOT), + "* STORAGE SLOTS (cumulative)", m::formatcp!("sum({}_sum)", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}_sum{{found_at='temporary'}}", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}_sum{{found_at='permanent'}}", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}_sum{{found_at='default'}}", m::METRIC_STORAGE_READ_SLOT), + "* STORAGE SLOTS (P100)", m::formatcp!("{}{{found_at='temporary', quantile='1'}}", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}{{found_at='permanent', quantile='1'}}", m::METRIC_STORAGE_READ_SLOT), m::formatcp!("{}{{found_at='default', quantile='1'}}", m::METRIC_STORAGE_READ_SLOT), - // STORAGE COMMIT - "", + "* STORAGE SLOTS (P95)", + m::formatcp!("{}{{found_at='temporary', quantile='0.95'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}{{found_at='permanent', quantile='0.95'}}", m::METRIC_STORAGE_READ_SLOT), + m::formatcp!("{}{{found_at='default', quantile='0.95'}}", m::METRIC_STORAGE_READ_SLOT), + "* COMMIT", m::formatcp!("{}{{quantile='1'}}", m::METRIC_STORAGE_COMMIT), ]; @@ -106,8 +116,8 @@ async fn test_import_offline_snapshot() { for query in METRIC_QUERIES { // formatting between query groups - if query.is_empty() { - println!("\n--------------------"); + if query.starts_with('*') { + println!("\n{}\n--------------------", query.replace("* ", "")); continue; } @@ -124,10 +134,10 @@ async fn test_import_offline_snapshot() { let value: f64 = value.parse().unwrap(); if query.contains("_count") { - println!("{:<64} = {}", query, value); + println!("{:<70} = {}", query, value); } else { let secs = Duration::from_secs_f64(value); - println!("{:<64} = {}", query, secs.fancy_duration().truncate(2)); + println!("{:<70} = {}", query, secs.fancy_duration().truncate(2)); } } }