Skip to content

Commit c20ff68

Browse files
committed
Update active_stake_cache_update to directly check epoch_stake_progress in function instead of bash
1 parent e2c5f16 commit c20ff68

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

files/grest/cron/jobs/active-stake-cache-update.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ echo "$(date +%F_%H:%M:%S) Running active stake cache update..."
1414
echo "No update needed, exiting..." &&
1515
exit 0
1616

17-
next_epoch_no=$(psql ${DB_NAME} -qbt -c "SELECT MAX(epoch_no) FROM epoch_stake_progress WHERE completed='t'" | tr -cd '[:alnum:]')
18-
19-
psql ${DB_NAME} -qbt -c "SELECT GREST.active_stake_cache_update(${next_epoch_no});" 1>/dev/null
2017
echo "$(date +%F_%H:%M:%S) Job done!"

files/grest/rpc/01_cached_tables/active_stake_cache.sql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,29 @@ CREATE TABLE IF NOT EXISTS grest.epoch_active_stake_cache (
1212
);
1313

1414
CREATE OR REPLACE FUNCTION grest.active_stake_cache_update_check()
15-
RETURNS boolean
15+
RETURNS void
1616
LANGUAGE plpgsql
1717
AS $$
1818
DECLARE
19-
_current_epoch_no integer;
19+
_latest_epoch_stake integer;
2020
_last_active_stake_validated_epoch text;
2121
BEGIN
2222
-- Get Last Active Stake Validated Epoch
2323
SELECT last_value INTO _last_active_stake_validated_epoch
2424
FROM grest.control_table
2525
WHERE key = 'last_active_stake_validated_epoch';
2626
-- Get Current Epoch
27-
SELECT MAX(no) INTO _current_epoch_no
28-
FROM epoch;
29-
RAISE NOTICE 'Next epoch: %', _current_epoch_no+1;
27+
SELECT MAX(epoch_no) INTO _latest_epoch_stake
28+
FROM epoch_stake_progress
29+
WHERE completed='t';
30+
RAISE NOTICE 'Latest epoch in epoch_stake: %', _latest_epoch_stake;
3031
RAISE NOTICE 'Latest epoch in active stake cache: %', COALESCE(_last_active_stake_validated_epoch::integer, '0');
31-
IF (SELECT MAX(epoch_no) FROM epoch_stake_progress WHERE completed='t')::integer > COALESCE(_last_active_stake_validated_epoch,'0')::integer THEN
32-
RETURN TRUE;
32+
IF _latest_epoch_stake::integer > COALESCE(_last_active_stake_validated_epoch,'0')::integer THEN
33+
RAISE NOTICE 'Running update for epoch: %', _latest_epoch_stake;
34+
PERFORM grest.active_stake_cache_update(_latest_epoch_stake);
35+
ELSE
36+
RAISE NOTICE 'Skipping! Active Stake cache is already up to date with DB!';
3337
END IF;
34-
RAISE NOTICE 'Active Stake cache is up to date with DB!';
35-
RETURN FALSE;
3638
END;
3739
$$;
3840

0 commit comments

Comments
 (0)