@@ -12,27 +12,29 @@ CREATE TABLE IF NOT EXISTS grest.epoch_active_stake_cache (
1212);
1313
1414CREATE OR REPLACE FUNCTION grest .active_stake_cache_update_check()
15- RETURNS boolean
15+ RETURNS void
1616LANGUAGE plpgsql
1717AS $$
1818DECLARE
19- _current_epoch_no integer ;
19+ _latest_epoch_stake integer ;
2020 _last_active_stake_validated_epoch text ;
2121BEGIN
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;
3638END;
3739$$;
3840
0 commit comments