From b6063483b53737348ab11e4179b7b35e23471ee3 Mon Sep 17 00:00:00 2001 From: rdlrt <3169068+rdlrt@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:53:54 +1100 Subject: [PATCH] Account Info and SDC to avoid edge case of listing retired pool in delegated status --- .../stake_distribution_cache.sql | 6 +++++ files/grest/rpc/account/account_info.sql | 27 ++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql b/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql index d446c6ce..7ccc7135 100644 --- a/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql +++ b/files/grest/rpc/01_cached_tables/stake_distribution_cache.sql @@ -46,6 +46,12 @@ BEGIN WHERE stake_deregistration.addr_id = delegation.addr_id AND stake_deregistration.tx_id > delegation.tx_id ) + AND NOT EXISTS ( + SELECT TRUE + FROM pool_retire AS pr + WHERE pr.hash_id = delegation.pool_hash_id + AND pr.retiring_epoch > delegation.active_epoch_no + ) -- Account must be present in epoch_stake table for the last validated epoch AND EXISTS ( SELECT TRUE diff --git a/files/grest/rpc/account/account_info.sql b/files/grest/rpc/account/account_info.sql index 89bf291f..a351da72 100644 --- a/files/grest/rpc/account/account_info.sql +++ b/files/grest/rpc/account/account_info.sql @@ -66,12 +66,12 @@ BEGIN FROM ( SELECT - sas.id, - sas.view, + sa.id, + sa.view, EXISTS ( SELECT TRUE FROM stake_registration WHERE - stake_registration.addr_id = sas.id + stake_registration.addr_id = sa.id AND NOT EXISTS ( SELECT TRUE FROM stake_deregistration @@ -80,30 +80,33 @@ BEGIN AND stake_deregistration.tx_id > stake_registration.tx_id ) ) AS registered - FROM public.stake_address sas - WHERE sas.id = ANY(sa_id_list) + FROM public.stake_address sa + WHERE sa.id = ANY(sa_id_list) ) AS status_t LEFT JOIN ( SELECT delegation.addr_id, pool_hash.view AS delegated_pool - FROM - delegation + FROM delegation INNER JOIN pool_hash ON pool_hash.id = delegation.pool_hash_id WHERE - delegation.addr_id = ANY(sa_id_list) + delegation.addr_id = ANY(_sa_id_list) AND NOT EXISTS ( SELECT TRUE FROM delegation AS d - WHERE - d.addr_id = delegation.addr_id + WHERE d.addr_id = delegation.addr_id AND d.id > delegation.id) AND NOT EXISTS ( SELECT TRUE FROM stake_deregistration - WHERE - stake_deregistration.addr_id = delegation.addr_id + WHERE stake_deregistration.addr_id = delegation.addr_id AND stake_deregistration.tx_id > delegation.tx_id) + AND NOT EXISTS ( + SELECT TRUE + FROM pool_retire AS pr + WHERE pr.hash_id = delegation.pool_hash_id + AND pr.retiring_epoch > delegation.active_epoch_no + ) ) AS pool_t ON pool_t.addr_id = status_t.id LEFT JOIN ( SELECT