From d72446888b82a8cbeeed8c519b6a9081e11e38da Mon Sep 17 00:00:00 2001 From: rdlrt <3169068+rdlrt@users.noreply.github.com> Date: Fri, 27 Sep 2024 13:21:09 +1000 Subject: [PATCH] Update active_stake_cache_update to directly check epoch_stake_progress in function instead of bash --- .../cron/jobs/active-stake-cache-update.sh | 3 --- .../01_cached_tables/active_stake_cache.sql | 20 +++++++------- specs/results/koiosapi-guild.yaml | 4 ++- specs/results/koiosapi-mainnet.yaml | 4 ++- specs/results/koiosapi-preprod.yaml | 26 ++++++++++--------- specs/results/koiosapi-preview.yaml | 4 ++- specs/templates/4-api-schemas.yaml | 4 ++- specs/templates/example-map.json | 16 ++++++------ 8 files changed, 45 insertions(+), 36 deletions(-) diff --git a/files/grest/cron/jobs/active-stake-cache-update.sh b/files/grest/cron/jobs/active-stake-cache-update.sh index 0ef14b1c..258b26c6 100755 --- a/files/grest/cron/jobs/active-stake-cache-update.sh +++ b/files/grest/cron/jobs/active-stake-cache-update.sh @@ -14,7 +14,4 @@ echo "$(date +%F_%H:%M:%S) Running active stake cache update..." echo "No update needed, exiting..." && exit 0 -next_epoch_no=$(psql ${DB_NAME} -qbt -c "SELECT MAX(epoch_no) FROM epoch_stake_progress WHERE completed='t'" | tr -cd '[:alnum:]') - -psql ${DB_NAME} -qbt -c "SELECT GREST.active_stake_cache_update(${next_epoch_no});" 1>/dev/null echo "$(date +%F_%H:%M:%S) Job done!" diff --git a/files/grest/rpc/01_cached_tables/active_stake_cache.sql b/files/grest/rpc/01_cached_tables/active_stake_cache.sql index ba56d7d5..92a1245e 100644 --- a/files/grest/rpc/01_cached_tables/active_stake_cache.sql +++ b/files/grest/rpc/01_cached_tables/active_stake_cache.sql @@ -12,11 +12,11 @@ CREATE TABLE IF NOT EXISTS grest.epoch_active_stake_cache ( ); CREATE OR REPLACE FUNCTION grest.active_stake_cache_update_check() -RETURNS boolean +RETURNS void LANGUAGE plpgsql AS $$ DECLARE - _current_epoch_no integer; + _latest_epoch_stake integer; _last_active_stake_validated_epoch text; BEGIN -- Get Last Active Stake Validated Epoch @@ -24,15 +24,17 @@ BEGIN FROM grest.control_table WHERE key = 'last_active_stake_validated_epoch'; -- Get Current Epoch - SELECT MAX(no) INTO _current_epoch_no - FROM epoch; - RAISE NOTICE 'Next epoch: %', _current_epoch_no+1; + SELECT MAX(epoch_no) INTO _latest_epoch_stake + FROM epoch_stake_progress + WHERE completed='t'; + RAISE NOTICE 'Latest epoch in epoch_stake: %', _latest_epoch_stake; RAISE NOTICE 'Latest epoch in active stake cache: %', COALESCE(_last_active_stake_validated_epoch::integer, '0'); - IF (SELECT MAX(epoch_no) FROM epoch_stake_progress WHERE completed='t')::integer > COALESCE(_last_active_stake_validated_epoch,'0')::integer THEN - RETURN TRUE; + IF _latest_epoch_stake::integer > COALESCE(_last_active_stake_validated_epoch,'0')::integer THEN + RAISE NOTICE 'Running update for epoch: %', _latest_epoch_stake; + PERFORM grest.active_stake_cache_update(_latest_epoch_stake); + ELSE + RAISE NOTICE 'Skipping! Active Stake cache is already up to date with DB!'; END IF; - RAISE NOTICE 'Active Stake cache is up to date with DB!'; - RETURN FALSE; END; $$; diff --git a/specs/results/koiosapi-guild.yaml b/specs/results/koiosapi-guild.yaml index d79c3b61..c790af65 100644 --- a/specs/results/koiosapi-guild.yaml +++ b/specs/results/koiosapi-guild.yaml @@ -5291,7 +5291,9 @@ components: - string description: Comment attached to the metadata is_valid: - type: boolean + type: + - 'null' + - boolean description: Indicate whether data is invalid example: true drep_updates: diff --git a/specs/results/koiosapi-mainnet.yaml b/specs/results/koiosapi-mainnet.yaml index 3fad91d1..48081aae 100644 --- a/specs/results/koiosapi-mainnet.yaml +++ b/specs/results/koiosapi-mainnet.yaml @@ -5291,7 +5291,9 @@ components: - string description: Comment attached to the metadata is_valid: - type: boolean + type: + - 'null' + - boolean description: Indicate whether data is invalid example: true drep_updates: diff --git a/specs/results/koiosapi-preprod.yaml b/specs/results/koiosapi-preprod.yaml index 6ac8bc40..d1a95430 100644 --- a/specs/results/koiosapi-preprod.yaml +++ b/specs/results/koiosapi-preprod.yaml @@ -2047,7 +2047,7 @@ components: description: Epoch Number to fetch details for schema: type: string - example: "31" + example: "166" in: query required: false allowEmptyValue: true @@ -2117,7 +2117,7 @@ components: description: Voter ID (Drep, SPO, Committee Member) in Bech32 format (CIP-5 | CIP-129) schema: type: string - example: "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd" + example: "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z" in: query required: true allowEmptyValue: false @@ -2127,7 +2127,7 @@ components: description: DRep ID in bech32 format schema: type: string - example: "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd" + example: "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z" in: query required: true allowEmptyValue: false @@ -2137,7 +2137,7 @@ components: description: DRep ID in bech32 format schema: type: string - example: "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd" + example: "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z" in: query required: false allowEmptyValue: true @@ -2187,7 +2187,7 @@ components: description: Pool ID in bech32 format schema: type: string - example: "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9" + example: "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv" in: query required: true allowEmptyValue: false @@ -2197,7 +2197,7 @@ components: description: Pool ID in bech32 format (optional) schema: type: string - example: "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9" + example: "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv" in: query required: false allowEmptyValue: true @@ -2225,7 +2225,7 @@ components: deprecated: false name: _proposal_id description: Government proposal ID in CIP-129 Bech32 format - example: "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf" + example: "gov_action14lefp8upwhhq92xph7t075txshf9huxxh9d2ey05ml2n5hqgvlxqqp92kfl" schema: type: string in: query @@ -2618,7 +2618,7 @@ components: example: _pool_bech32_ids: - pool1ext7qrwjzaxcdfhdnkq5mth59ukuu2atcg6tgqpmevpt7ratkta - - pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9 + - pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv - pool1ws42l6rawqjv58crs5l32v0eem3qnngpnjfd7epwd4lmjccc5cg description: Array of Cardano pool IDs (bech32 format) pool_ids_optional: @@ -2636,7 +2636,7 @@ components: example: _pool_bech32_ids: - pool1ext7qrwjzaxcdfhdnkq5mth59ukuu2atcg6tgqpmevpt7ratkta - - pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9 + - pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv - pool1ws42l6rawqjv58crs5l32v0eem3qnngpnjfd7epwd4lmjccc5cg description: Array of Cardano pool IDs (bech32 format) [Optional] script_hashes: @@ -2736,8 +2736,8 @@ components: type: string example: _drep_ids: - - drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd - - drep14x62vyme8l8dkhvxg6rauc6vpcd2va9fquz8k3jstsqczwlvqqh + - drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z + - drep1y25j98kvqf7t3tj4pvxwrjr2728dsrfekptgg3kxqrr56qqcny8sn utxo_refs_with_extended: content: application/json: @@ -5291,7 +5291,9 @@ components: - string description: Comment attached to the metadata is_valid: - type: boolean + type: + - 'null' + - boolean description: Indicate whether data is invalid example: true drep_updates: diff --git a/specs/results/koiosapi-preview.yaml b/specs/results/koiosapi-preview.yaml index 0c0ed67d..b4680797 100644 --- a/specs/results/koiosapi-preview.yaml +++ b/specs/results/koiosapi-preview.yaml @@ -5291,7 +5291,9 @@ components: - string description: Comment attached to the metadata is_valid: - type: boolean + type: + - 'null' + - boolean description: Indicate whether data is invalid example: true drep_updates: diff --git a/specs/templates/4-api-schemas.yaml b/specs/templates/4-api-schemas.yaml index 8fbd7947..f09faa8d 100644 --- a/specs/templates/4-api-schemas.yaml +++ b/specs/templates/4-api-schemas.yaml @@ -2456,7 +2456,9 @@ schemas: - string description: Comment attached to the metadata is_valid: - type: boolean + type: + - 'null' + - boolean description: Indicate whether data is invalid example: true drep_updates: diff --git a/specs/templates/example-map.json b/specs/templates/example-map.json index 0f2291d2..5697d3ef 100644 --- a/specs/templates/example-map.json +++ b/specs/templates/example-map.json @@ -10,7 +10,7 @@ "m": "320", "g": "6219", "pv": "675", - "pp": "31" + "pp": "166" }, "_earned_epoch_no": { "m": "320", @@ -76,7 +76,7 @@ "m": "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3", "g": "drep1s9qaseg7qyum807fcv0hdky9gv0c89tn98t4urjn5ewz57dml0r", "pv": "drep17rksqsgqx8ej3rtc3x4gjm8a44u6w3qcshfm46yc9tq4zeffuzj", - "pp": "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd" + "pp": "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z" }, "_cc_hot_id": { "m": "cc_hot1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvcdjk7", @@ -88,7 +88,7 @@ "m": "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf", "g": "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf", "pv": "gov_action17m93skslaxyd45gpr6ernkdzs852h564wsterr8l6lheu7hu7kvsqecyqdh", - "pp": "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf" + "pp": "gov_action14lefp8upwhhq92xph7t075txshf9huxxh9d2ey05ml2n5hqgvlxqqp92kfl" }, "_voter_id": { "m": "['pool1w83ux7vrwafrsuz044knxl9xxtr38q5jj2l3p28fl3g26faqqwg', 'drep1yt76he02dprm2af6x26vg76mhs2vajlg43cr9jh9dq3f2qs68ts3s']", @@ -100,13 +100,13 @@ "m": "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", "g": "pool1xc9eywck4e20tydz4yvh5vfe0ep8whawvwz8wqkc9k046a2ypp4", "pv": "pool1leml52hm4fcp3hhe4zye08qz27llhj7d339p3gs0tl85cstx59q", - "pp": "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9" + "pp": "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv" }, "_pool_bech32_optional": { "m": "pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", "g": "pool1xc9eywck4e20tydz4yvh5vfe0ep8whawvwz8wqkc9k046a2ypp4", "pv": "pool1leml52hm4fcp3hhe4zye08qz27llhj7d339p3gs0tl85cstx59q", - "pp": "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9" + "pp": "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv" }, "_pool_epoch_no": { "m": "320", @@ -204,13 +204,13 @@ "m": "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3", "g": "drep1s9qaseg7qyum807fcv0hdky9gv0c89tn98t4urjn5ewz57dml0r", "pv": "drep1yt76he02dprm2af6x26vg76mhs2vajlg43cr9jh9dq3f2qs68ts3s", - "pp": "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd" + "pp": "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z" }, "drep_ids2": { "m": "drep1s9q5uyddsvza4uk2n9wswy90n8wx9d2jmrq4zgcvlyv055007av", "g": "drep13p45vxysc2s6vp6ez2ng7lynlsheh64zxexpcennn68cuc05yps", "pv": "drep1g5vl99xcpv8uce5hhh50xe3fh68tl9f8hcprleekw0c6jhhr45f", - "pp": "drep14x62vyme8l8dkhvxg6rauc6vpcd2va9fquz8k3jstsqczwlvqqh" + "pp": "drep1y25j98kvqf7t3tj4pvxwrjr2728dsrfekptgg3kxqrr56qqcny8sn" }, "tx_ids_tx_hashes1": { "m": "f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", @@ -252,7 +252,7 @@ "m": "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m", "g": "pool1uul8pytp2p0xq4ckjn3l294km0m7fuef46teehvh3x5tk46sfx3", "pv": "pool1wwh3k3ldzujdvgxllfwlnnkxyheafkacqlufnvpr77n5q72f9hw", - "pp": "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9" + "pp": "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv" }, "pool_ids_pool_bech32_ids3": { "m": "pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm",