Skip to content

Commit

Permalink
Update active_stake_cache_update to directly check epoch_stake_progre…
Browse files Browse the repository at this point in the history
…ss in function instead of bash
  • Loading branch information
rdlrt committed Sep 30, 2024
1 parent e2c5f16 commit d724468
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 36 deletions.
3 changes: 0 additions & 3 deletions files/grest/cron/jobs/active-stake-cache-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
20 changes: 11 additions & 9 deletions files/grest/rpc/01_cached_tables/active_stake_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@ 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
SELECT last_value INTO _last_active_stake_validated_epoch
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;
$$;

Expand Down
4 changes: 3 additions & 1 deletion specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 14 additions & 12 deletions specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -2127,7 +2127,7 @@ components:
description: DRep ID in bech32 format
schema:
type: string
example: "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd"
example: "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z"
in: query
required: true
allowEmptyValue: false
Expand All @@ -2137,7 +2137,7 @@ components:
description: DRep ID in bech32 format
schema:
type: string
example: "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd"
example: "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z"
in: query
required: false
allowEmptyValue: true
Expand Down Expand Up @@ -2187,7 +2187,7 @@ components:
description: Pool ID in bech32 format
schema:
type: string
example: "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9"
example: "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv"
in: query
required: true
allowEmptyValue: false
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2618,7 +2618,7 @@ components:
example:
_pool_bech32_ids:
- pool1ext7qrwjzaxcdfhdnkq5mth59ukuu2atcg6tgqpmevpt7ratkta
- pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9
- pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv
- pool1ws42l6rawqjv58crs5l32v0eem3qnngpnjfd7epwd4lmjccc5cg
description: Array of Cardano pool IDs (bech32 format)
pool_ids_optional:
Expand All @@ -2636,7 +2636,7 @@ components:
example:
_pool_bech32_ids:
- pool1ext7qrwjzaxcdfhdnkq5mth59ukuu2atcg6tgqpmevpt7ratkta
- pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9
- pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv
- pool1ws42l6rawqjv58crs5l32v0eem3qnngpnjfd7epwd4lmjccc5cg
description: Array of Cardano pool IDs (bech32 format) [Optional]
script_hashes:
Expand Down Expand Up @@ -2736,8 +2736,8 @@ components:
type: string
example:
_drep_ids:
- drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd
- drep14x62vyme8l8dkhvxg6rauc6vpcd2va9fquz8k3jstsqczwlvqqh
- drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z
- drep1y25j98kvqf7t3tj4pvxwrjr2728dsrfekptgg3kxqrr56qqcny8sn
utxo_refs_with_extended:
content:
application/json:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions specs/templates/example-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"m": "320",
"g": "6219",
"pv": "675",
"pp": "31"
"pp": "166"
},
"_earned_epoch_no": {
"m": "320",
Expand Down Expand Up @@ -76,7 +76,7 @@
"m": "drep17l6sywnwqu9aedd6aumev42w39ln5zfl9nw7j4ak6u8swyrwvz3",
"g": "drep1s9qaseg7qyum807fcv0hdky9gv0c89tn98t4urjn5ewz57dml0r",
"pv": "drep17rksqsgqx8ej3rtc3x4gjm8a44u6w3qcshfm46yc9tq4zeffuzj",
"pp": "drep1kxtwaqtayj6vklc57u93xayjvkwgvefh8drscqp5a5y6jz7m6rd"
"pp": "drep1ydmraa6kv8cvmry059v608tehl50nfmg0z764lmsqkvwurs40sw2z"
},
"_cc_hot_id": {
"m": "cc_hot1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvcdjk7",
Expand All @@ -88,7 +88,7 @@
"m": "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf",
"g": "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf",
"pv": "gov_action17m93skslaxyd45gpr6ernkdzs852h564wsterr8l6lheu7hu7kvsqecyqdh",
"pp": "gov_action1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpzklpgpf"
"pp": "gov_action14lefp8upwhhq92xph7t075txshf9huxxh9d2ey05ml2n5hqgvlxqqp92kfl"
},
"_voter_id": {
"m": "['pool1w83ux7vrwafrsuz044knxl9xxtr38q5jj2l3p28fl3g26faqqwg', 'drep1yt76he02dprm2af6x26vg76mhs2vajlg43cr9jh9dq3f2qs68ts3s']",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -252,7 +252,7 @@
"m": "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m",
"g": "pool1uul8pytp2p0xq4ckjn3l294km0m7fuef46teehvh3x5tk46sfx3",
"pv": "pool1wwh3k3ldzujdvgxllfwlnnkxyheafkacqlufnvpr77n5q72f9hw",
"pp": "pool1x4p3cwemsm356vpxnjwuud7w76jz64hyss729zp7xa6wuey6yr9"
"pp": "pool1vw6fr9agt58djrp3w0t0lsn6t329t6eusqxz5ugd9w7ecyedsdv"
},
"pool_ids_pool_bech32_ids3": {
"m": "pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm",
Expand Down

0 comments on commit d724468

Please sign in to comment.