From 055344f05fbe65c59d1e732bc6a1e31fd33bc619 Mon Sep 17 00:00:00 2001 From: RdLrT <3169068+rdlrt@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:05:34 +1100 Subject: [PATCH] Apply Fixes from testing on non-mainnet networks: (#173) - Fix Asset Info Cache to not rely on being able to decode policy ID (bad data on IO repo) - Handle Pool_list to check metadata entries that have not been populated in pool_offline_data (closes #109 from Koios point of view) - Fix pool_updates to use pmr_id instead of pool_offline_data.id (wasnt reported earlier, but the endpoint was showing wrong data) - Update account_info_cached description to clarify it is effective for registered accounts --- .../rpc/01_cached_tables/asset_info_cache.sql | 6 ++--- files/grest/rpc/pool/pool_list.sql | 25 +++++++++++++------ files/grest/rpc/pool/pool_updates.sql | 2 +- specs/results/koiosapi-guild.yaml | 2 +- specs/results/koiosapi-mainnet.yaml | 2 +- specs/results/koiosapi-preprod.yaml | 2 +- specs/results/koiosapi-preview.yaml | 2 +- specs/templates/api-main.yaml | 2 +- 8 files changed, 27 insertions(+), 16 deletions(-) diff --git a/files/grest/rpc/01_cached_tables/asset_info_cache.sql b/files/grest/rpc/01_cached_tables/asset_info_cache.sql index 7cba903d..849eff68 100644 --- a/files/grest/rpc/01_cached_tables/asset_info_cache.sql +++ b/files/grest/rpc/01_cached_tables/asset_info_cache.sql @@ -94,7 +94,7 @@ BEGIN WHERE CASE WHEN _asset_info_cache_last_tx_id IS NOT NULL AND _asset_id_list IS NOT NULL THEN - mtm.id = any(_asset_id_list) + mtm.ident = any(_asset_id_list) AND mtm.tx_id > _asset_info_cache_last_tx_id ELSE TRUE END @@ -145,11 +145,11 @@ BEGIN INNER JOIN tx ON tx.id = mtm.tx_id INNER JOIN block b ON b.id = tx.block_id INNER JOIN tx_meta tm ON tm.ident = ma.id - LEFT JOIN grest.asset_registry_cache arc ON DECODE(arc.asset_policy, 'hex') = ma.policy AND DECODE(arc.asset_name, 'hex') = ma.name + LEFT JOIN grest.asset_registry_cache arc ON arc.asset_policy = ENCODE(ma.policy,'hex') AND arc.asset_name = encode(ma.name,'hex') WHERE CASE WHEN _asset_info_cache_last_tx_id IS NOT NULL AND _asset_id_list IS NOT NULL THEN - mtm.id = any(_asset_id_list) + mtm.ident = any(_asset_id_list) ELSE TRUE END GROUP BY ma.id, arc.decimals, tm.first_mint_tx_id, tm.first_mint_keys, tm.last_mint_tx_id, tm.last_mint_keys diff --git a/files/grest/rpc/pool/pool_list.sql b/files/grest/rpc/pool/pool_list.sql index ad4d7987..3bb9ddbd 100644 --- a/files/grest/rpc/pool/pool_list.sql +++ b/files/grest/rpc/pool/pool_list.sql @@ -1,4 +1,4 @@ -CREATE FUNCTION grest.pool_list () +CREATE OR REPLACE FUNCTION grest.pool_list () RETURNS TABLE ( pool_id_bech32 character varying, ticker character varying) @@ -10,24 +10,35 @@ BEGIN RETURN QUERY ( WITH -- Get last pool update for each pool - _pool_updates AS ( + _pool_list AS ( SELECT DISTINCT ON (pic.pool_id_bech32) pool_id_bech32, - pod.ticker_name, - pic.pool_status + pool_status + FROM + grest.pool_info_cache AS pic + ORDER BY + pic.pool_id_bech32, + pic.tx_id DESC + ), + _pool_meta AS ( + SELECT + DISTINCT ON (pic.pool_id_bech32) pool_id_bech32, + pod.ticker_name FROM grest.pool_info_cache AS pic LEFT JOIN public.pool_offline_data AS pod ON pod.pmr_id = pic.meta_id + WHERE pod.ticker_name IS NOT NULL ORDER BY pic.pool_id_bech32, pic.tx_id DESC ) SELECT - pool_id_bech32, - ticker_name + pl.pool_id_bech32, + pm.ticker_name FROM - _pool_updates + _pool_list AS pl + LEFT JOIN _pool_meta AS pm ON pl.pool_id_bech32 = pm.pool_id_bech32 WHERE pool_status != 'retired' diff --git a/files/grest/rpc/pool/pool_updates.sql b/files/grest/rpc/pool/pool_updates.sql index 1170b2c4..52960bd1 100644 --- a/files/grest/rpc/pool/pool_updates.sql +++ b/files/grest/rpc/pool/pool_updates.sql @@ -43,7 +43,7 @@ BEGIN retiring_epoch FROM grest.pool_info_cache pic - LEFT JOIN public.pool_offline_data pod ON pod.id = pic.meta_id + LEFT JOIN public.pool_offline_data pod ON pod.pmr_id = pic.meta_id WHERE _pool_bech32 IS NULL OR diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index a4f5fd43..4e672276 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -728,7 +728,7 @@ paths: "404": $ref: "#/components/responses/NotFound" summary: Account Information (Cached) - description: Get the cached account information for given stake addresses + description: Get the cached account information for given stake addresses, effective for registered accounts /account_rewards: #RPC post: tags: diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index 6a463c21..1b3b3d1e 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -728,7 +728,7 @@ paths: "404": $ref: "#/components/responses/NotFound" summary: Account Information (Cached) - description: Get the cached account information for given stake addresses + description: Get the cached account information for given stake addresses, effective for registered accounts /account_rewards: #RPC post: tags: diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index e249246b..175c1731 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -728,7 +728,7 @@ paths: "404": $ref: "#/components/responses/NotFound" summary: Account Information (Cached) - description: Get the cached account information for given stake addresses + description: Get the cached account information for given stake addresses, effective for registered accounts /account_rewards: #RPC post: tags: diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index 203495a5..16cfb18c 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -728,7 +728,7 @@ paths: "404": $ref: "#/components/responses/NotFound" summary: Account Information (Cached) - description: Get the cached account information for given stake addresses + description: Get the cached account information for given stake addresses, effective for registered accounts /account_rewards: #RPC post: tags: diff --git a/specs/templates/api-main.yaml b/specs/templates/api-main.yaml index 1f9215eb..717cfda6 100644 --- a/specs/templates/api-main.yaml +++ b/specs/templates/api-main.yaml @@ -533,7 +533,7 @@ paths: "404": $ref: "#/components/responses/NotFound" summary: Account Information (Cached) - description: Get the cached account information for given stake addresses + description: Get the cached account information for given stake addresses, effective for registered accounts /account_rewards: #RPC post: tags: