Skip to content

Commit

Permalink
Koios v1.1.1rc (#269)
Browse files Browse the repository at this point in the history
## Description
<!--- Describe your changes -->
Todo:
- [x] Update active_stake_cache, no longer requires maintaining account
active stake lookup, remove log scan references
- [x] Perf improvement for address_txs for 90% of addresses (postgres
filtering nuance)
- [x] Update cip67_strip_label
- [x] Reduce asset info cache rollback to 250
- [x] Update specs (view updates already covered in previous commits,
didnt see much to do beyond bumping version)
- [x] Retire stake_distribution_new_accounts_update (current query is
overkill)
- [x] Adapt as per 13.2.0.1 schema
  - [x] Replace consumed_by_tx_in_id
  - [x] Replace pool_offline_data
- [x] Update epoch references (no longer need 2 epoch wait time) for
cache
  - [x] Remove leftover tx_in references
- [x] MIRs (both extract from reserves as well as treasury) are no
longer in rewards table, but moved to it's own `instant_rewards` table -
update endpoints impacted (I think that's primarily SDC only)
- [x] Update `reserve_withdrawals` and `treasury_withdrawals` to include
`earned` and `spendable` epochs
- [x] Add an endpoint for asset/policy mint history
- [x] Retire asset_address_list and asset_policy_info (was deprecated 3
versions ago, and usage-wise had only a single hit in past 48 hours on
mainnet)
- [x] Fix script_utxos ->> asset_list
- [x] New endpoint + cron job to get current protocol parameters
- [x] Add is_dangling_delegation check
- [x] Specs Testing on guildnet
- [x] Update changelog

Bugs from testing:
- [x] Fix script_utxos, asset_list was not being returned as array ,
closes #272
- [x] Include burn asset transactions in asset_txs , closes #276 
- [x] tx_info: Fix spend_redeemers CTE Join condition, closes #275

- [x] Update Changelog/specs post testing results

---------

Co-authored-by: KoT_B_KocMoce <[email protected]>
Co-authored-by: XRAY | Robot <[email protected]>
Co-authored-by: Scitz0 <[email protected]>
Co-authored-by: Greg Beresnev <[email protected]>
  • Loading branch information
5 people authored May 4, 2024
1 parent d6ce49a commit b68c894
Show file tree
Hide file tree
Showing 73 changed files with 1,376 additions and 1,293 deletions.
34 changes: 8 additions & 26 deletions files/grest/cron/jobs/active-stake-cache-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ DB_NAME=cexplorer

tip=$(psql ${DB_NAME} -qbt -c "select extract(epoch from time)::integer from block order by id desc limit 1;" | xargs)

if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
echo "$(date +%F_%H:%M:%S) Skipping as database has not received a new block in past 300 seconds!" && exit 1
fi
[[ $(( $(date +%s) - tip )) -gt 300 ]] &&
echo "$(date +%F_%H:%M:%S) Skipping as database has not received a new block in past 300 seconds!" &&
exit 1

echo "$(date +%F_%H:%M:%S) Running active stake cache update..."

Expand All @@ -14,30 +14,12 @@ echo "$(date +%F_%H:%M:%S) Running active stake cache update..."
echo "No update needed, exiting..." &&
exit 0

# This could break due to upstream changes on db-sync (based on log format)
last_epoch_stakes_log=$(grep -r 'Inserted.*.EpochStake for EpochNo ' "$(dirname "$0")"/../../logs/dbsync-*.json "$(dirname "$0")"/../../logs/archive/dbsync-*.json 2>/dev/null | sed -e 's#.*.Inserted ##' -e 's#EpochStake for EpochNo##' -e 's#\"}.*.$##' | sort -k2 -n | tail -1)
[[ -z ${last_epoch_stakes_log} ]] &&
echo "Could not find any 'Handling stakes' log entries, exiting..." &&
exit 1

logs_last_epoch_stakes_count=$(echo "${last_epoch_stakes_log}" | cut -d\ -f1)
logs_last_epoch_no=$(echo "${last_epoch_stakes_log}" | cut -d\ -f3)
db_next_epoch_no=$(psql ${DB_NAME} -qbt -c "SELECT MAX(NO)+1 from EPOCH;" | tr -cd '[:alnum:]')
db_epoch_stakes_no=$(psql ${DB_NAME} -qbt -c "SELECT MAX(epoch_no) FROM EPOCH_STAKE;" | tr -cd '[:alnum:]')

db_last_epoch_no=$(psql ${DB_NAME} -qbt -c "SELECT MAX(NO) from EPOCH;" | tr -cd '[:alnum:]')
[[ "${db_last_epoch_no}" != "${logs_last_epoch_no}" ]] &&
echo "Mismatch between last epoch in logs and database, exiting..." &&
[[ ${db_next_epoch_no} -gt ${db_epoch_stakes_no} ]] &&
echo "Epoch Stake is not populated for epoch ${db_next_epoch_no}, exiting..." &&
exit 1

# Count current epoch entries processed by db-sync
db_epoch_stakes_count=$(psql ${DB_NAME} -qbt -c "SELECT COUNT(1) FROM EPOCH_STAKE WHERE epoch_no = ${db_last_epoch_no};" | tr -cd '[:alnum:]')

# Check if db-sync completed handling stakes
[[ "${db_epoch_stakes_count}" != "${logs_last_epoch_stakes_count}" ]] &&
echo "Logs last epoch stakes count: ${logs_last_epoch_stakes_count}" &&
echo "DB last epoch stakes count: ${db_epoch_stakes_count}" &&
echo "db-sync stakes handling still incomplete, exiting..." &&
exit 0

# Stakes have been validated, run the cache update
psql ${DB_NAME} -qbt -c "SELECT GREST.active_stake_cache_update(${db_last_epoch_no});" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT GREST.active_stake_cache_update(${db_epoch_stakes_no});" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
6 changes: 5 additions & 1 deletion files/grest/cron/jobs/asset-info-cache-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
echo "$(date +%F_%H:%M:%S) Skipping as database has not received a new block in past 300 seconds!" && exit 1
fi

asset_registry_exists=$(psql ${DB_NAME} -qbt -c "select last_value from grest.control_table where key='asset_registry_commit';" | xargs)

[[ -z "${asset_registry_exists}" ]] && echo "$(date +%F_%H:%M:%S) Skipping as asset registry cache does not seem to be populated!" && exit 1

echo "$(date +%F_%H:%M:%S) Running asset info cache update..."
psql ${DB_NAME} -qbt -c "SELECT grest.asset_info_cache_update();" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT grest.asset_info_cache_update();" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
2 changes: 1 addition & 1 deletion files/grest/cron/jobs/asset-txo-cache-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
fi

echo "$(date +%F_%H:%M:%S) Running asset txo cache update..."
psql ${DB_NAME} -qbt -c "SELECT grest.asset_txo_cache_update();" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT grest.asset_txo_cache_update();" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
33 changes: 33 additions & 0 deletions files/grest/cron/jobs/cli-protocol-params-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
DB_NAME=cexplorer
CCLI="${HOME}"/.local/bin/cardano-cli
SOCKET="$(dirname "$0")"/../../sockets/node.socket

echo "$(date +%F_%H:%M:%S) - START - CLI Protocol Parameters Update"
nwmagic=$(psql ${DB_NAME} -qbt -c "SELECT networkmagic FROM grest.genesis()" | xargs)
last_epoch=$(psql ${DB_NAME} -qbt -c "SELECT last_value FROM grest.control_table WHERE key='cli_protocol_params'" | xargs)
current_epoch=$(psql ${DB_NAME} -qbt -c "SELECT epoch_no FROM grest.tip()" | xargs)

if [[ -z ${current_epoch} ]] || ! [[ ${current_epoch} =~ ^[0-9]+$ ]]; then
echo "$(date +%F_%H:%M:%S) - Unable to fetch epoch_no from grest.tip"
echo "$(date +%F_%H:%M:%S) - Error message: ${current_epoch}"
exit 1
fi

[[ -n ${last_epoch} && ${last_epoch} -eq ${current_epoch} ]] && echo "$(date +%F_%H:%M:%S) - END - CLI Protocol Parameters Update, no update necessary." && exit 0

prot_params="$(${CCLI} query protocol-parameters --testnet-magic "${nwmagic}" --socket-path "${SOCKET}" 2>&1)"

if grep -q "Network.Socket.connect" <<< "${prot_params}"; then
echo "$(date +%F_%H:%M:%S) - Node socket path wrongly configured or node not running, please verify that socket set in env file match what is used to run the node"
echo "$(date +%F_%H:%M:%S) - Error message: ${prot_params}"
exit 1
elif [[ -z "${prot_params}" ]] || ! jq -er . <<< "${prot_params}" &>/dev/null; then
echo "$(date +%F_%H:%M:%S) - Failed to query protocol parameters, ensure your node is running with correct genesis (the node needs to be in sync to 1 epoch after the hardfork)"
echo "$(date +%F_%H:%M:%S) - Error message: ${prot_params}"
exit 1
fi

psql ${DB_NAME} -qb -c "INSERT INTO grest.control_table (key, last_value, artifacts) VALUES ('cli_protocol_params','${current_epoch}','${prot_params}') ON CONFLICT(key) DO UPDATE SET last_value='${current_epoch}', artifacts='${prot_params}'"

echo "$(date +%F_%H:%M:%S) - END - CLI Protocol Parameters Update, updated for epoch ${current_epoch}."
2 changes: 1 addition & 1 deletion files/grest/cron/jobs/epoch-info-cache-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
fi

echo "$(date +%F_%H:%M:%S) Running epoch info cache update..."
psql ${DB_NAME} -qbt -c "SELECT grest.epoch_info_cache_update();" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT grest.epoch_info_cache_update();" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
2 changes: 1 addition & 1 deletion files/grest/cron/jobs/epoch-summary-corrections-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
fi

echo "$(date +%F_%H:%M:%S) Running epoch summary corrections update..."
psql ${DB_NAME} -qbt -c "SELECT GREST.EPOCH_SUMMARY_CORRECTIONS_UPDATE();" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT GREST.EPOCH_SUMMARY_CORRECTIONS_UPDATE();" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
2 changes: 1 addition & 1 deletion files/grest/cron/jobs/pool-history-cache-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
fi

echo "$(date +%F_%H:%M:%S) Running pool history cache update..."
psql ${DB_NAME} -qbt -c "SELECT GREST.pool_history_cache_update();" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT GREST.pool_history_cache_update();" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
12 changes: 0 additions & 12 deletions files/grest/cron/jobs/stake-distribution-new-accounts-update.sh

This file was deleted.

2 changes: 1 addition & 1 deletion files/grest/cron/jobs/stake-distribution-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [[ $(( $(date +%s) - tip )) -gt 300 ]]; then
fi

echo "$(date +%F_%H:%M:%S) Running stake distribution update..."
psql ${DB_NAME} -qbt -c "SELECT GREST.STAKE_DISTRIBUTION_CACHE_UPDATE_CHECK();" 1>/dev/null 2>&1
psql ${DB_NAME} -qbt -c "SELECT GREST.STAKE_DISTRIBUTION_CACHE_UPDATE_CHECK();" 1>/dev/null
echo "$(date +%F_%H:%M:%S) Job done!"
12 changes: 0 additions & 12 deletions files/grest/cron/jobs/stake-snapshot-cache.sh

This file was deleted.

13 changes: 10 additions & 3 deletions files/grest/rpc/00_blockchain/reserve_withdrawals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ RETURNS TABLE (
block_hash text,
block_height word31type,
amount text,
stake_address text
stake_address text,
earned_epoch bigint,
spendable_epoch bigint
)
LANGUAGE sql STABLE
AS $$
Expand All @@ -17,11 +19,16 @@ AS $$
ENCODE(b.hash,'hex'),
b.block_no,
r.amount::text,
sa.view
sa.view,
earned_epoch,
spendable_epoch
FROM reserve AS r
LEFT JOIN tx ON r.tx_id = tx.id
INNER JOIN block AS b ON tx.block_id = b.id
LEFT JOIN stake_address AS sa ON sa.id = r.addr_id;
LEFT JOIN stake_address AS sa ON sa.id = r.addr_id
LEFT JOIN instant_reward AS ir ON ir.addr_id = r.addr_id AND ir.earned_epoch = b.epoch_no AND ir.type = 'reserves'
ORDER BY b.block_no DESC
;
$$;

COMMENT ON FUNCTION grest.reserve_withdrawals IS 'A list of withdrawals made from reserves (MIRs)'; --noqa: LT01
2 changes: 1 addition & 1 deletion files/grest/rpc/00_blockchain/tip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ AS $$
b.epoch_slot_no AS epoch_slot,
b.block_no,
EXTRACT(EPOCH FROM b.time)::integer
FROM block b
FROM block AS b
ORDER BY b.id DESC
LIMIT 1;
$$;
Expand Down
13 changes: 10 additions & 3 deletions files/grest/rpc/00_blockchain/treasury_withdrawals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ RETURNS TABLE (
block_hash text,
block_height word31type,
amount text,
stake_address text
stake_address text,
earned_epoch bigint,
spendable_epoch bigint
)
LANGUAGE sql STABLE
AS $$
Expand All @@ -17,11 +19,16 @@ AS $$
ENCODE(b.hash,'hex'),
b.block_no,
t.amount::text,
sa.view
sa.view,
earned_epoch,
spendable_epoch
FROM treasury AS t
LEFT JOIN tx ON t.tx_id = tx.id
INNER JOIN block AS b ON tx.block_id = b.id
LEFT JOIN stake_address AS sa ON sa.id = t.addr_id;
LEFT JOIN stake_address AS sa ON sa.id = t.addr_id
LEFT JOIN instant_reward AS ir ON ir.addr_id = t.addr_id AND ir.earned_epoch = b.epoch_no AND ir.type = 'treasury'
ORDER BY b.block_no DESC
;
$$;

COMMENT ON FUNCTION grest.treasury_withdrawals IS 'A list of withdrawals made from treasury'; --noqa: LT01
46 changes: 9 additions & 37 deletions files/grest/rpc/01_cached_tables/active_stake_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ CREATE TABLE IF NOT EXISTS grest.epoch_active_stake_cache (
PRIMARY KEY (epoch_no)
);

CREATE TABLE IF NOT EXISTS grest.account_active_stake_cache (
stake_address varchar NOT NULL,
pool_id varchar NOT NULL,
epoch_no bigint NOT NULL,
amount lovelace NOT NULL,
PRIMARY KEY (stake_address, pool_id, epoch_no)
);

CREATE OR REPLACE FUNCTION grest.active_stake_cache_update_check()
RETURNS boolean
LANGUAGE plpgsql
Expand All @@ -34,11 +26,18 @@ BEGIN
-- Get Current Epoch
SELECT MAX(no) INTO _current_epoch_no
FROM epoch;
RAISE NOTICE 'Current epoch: %', _current_epoch_no;
RAISE NOTICE 'Last active stake validated epoch: %', _last_active_stake_validated_epoch;
RAISE NOTICE 'Next epoch: %', _current_epoch_no+1;
RAISE NOTICE 'Latest epoch in active stake cache: %', _last_active_stake_validated_epoch;
IF _current_epoch_no > COALESCE(_last_active_stake_validated_epoch::integer, 0) THEN
RETURN TRUE;
ELSE
-- If last active stake cache is same as current epoch_no, check if we're beyond 60% within epoch to populate next epoch stake, only valid as of dbsync 13.2.0.0
IF _current_epoch_no = _last_active_stake_validated_epoch::integer
AND (SELECT MAX(epoch_no) FROM epoch_stake_progress WHERE completed='t')::integer > _last_active_stake_validated_epoch::integer THEN
RETURN TRUE;
END IF;
END IF;
RAISE NOTICE 'Active Stake cache is up to date with DB!';
RETURN FALSE;
END;
$$;
Expand All @@ -51,7 +50,6 @@ LANGUAGE plpgsql
AS $$
DECLARE
_last_active_stake_validated_epoch integer;
_last_account_active_stake_cache_epoch_no integer;
BEGIN
-- CHECK PREVIOUS QUERY FINISHED RUNNING
IF (
Expand Down Expand Up @@ -100,33 +98,7 @@ BEGIN
ON CONFLICT (epoch_no) DO UPDATE
SET amount = excluded.amount
WHERE epoch_active_stake_cache.amount IS DISTINCT FROM excluded.amount;
-- ACCOUNT ACTIVE STAKE CACHE
SELECT COALESCE(MAX(epoch_no), (_epoch_no - 4)) INTO _last_account_active_stake_cache_epoch_no
FROM grest.account_active_stake_cache;

INSERT INTO grest.account_active_stake_cache
SELECT
stake_address.view AS stake_address,
pool_hash.view AS pool_id,
epoch_stake.epoch_no AS epoch_no,
SUM(epoch_stake.amount) AS amount
FROM public.epoch_stake
INNER JOIN public.pool_hash ON pool_hash.id = epoch_stake.pool_id
INNER JOIN public.stake_address ON stake_address.id = epoch_stake.addr_id
WHERE epoch_stake.epoch_no > _last_account_active_stake_cache_epoch_no
AND epoch_stake.epoch_no <= _epoch_no
GROUP BY
stake_address.id,
pool_hash.id,
epoch_stake.epoch_no
ON CONFLICT (
stake_address,
pool_id,
epoch_no
) DO UPDATE
SET amount = excluded.amount;
DELETE FROM grest.account_active_stake_cache
WHERE epoch_no <= (_epoch_no - 4);
-- CONTROL TABLE ENTRY
PERFORM grest.update_control_table(
'last_active_stake_validated_epoch',
Expand Down
40 changes: 20 additions & 20 deletions files/grest/rpc/01_cached_tables/asset_cache_control.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ CREATE INDEX IF NOT EXISTS idx_atoc_txoid ON grest.asset_tx_out_cache USING btre
CREATE INDEX IF NOT EXISTS idx_atoc_maid ON grest.asset_tx_out_cache USING btree (ma_id) INCLUDE (txo_id, quantity);

DELETE FROM grest.asset_cache_control;
INSERT INTO grest.asset_cache_control VALUES (DECODE('a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235', 'hex')); -- HOSKY
INSERT INTO grest.asset_cache_control VALUES (DECODE('af2e27f580f7f08e93190a81f72462f153026d06450924726645891b', 'hex')); -- DRIP
INSERT INTO grest.asset_cache_control VALUES (DECODE('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6', 'hex')); -- MIN
INSERT INTO grest.asset_cache_control VALUES (DECODE('9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77', 'hex')); -- SUNDAE
INSERT INTO grest.asset_cache_control VALUES (DECODE('13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f', 'hex')); -- MINSWAP
INSERT INTO grest.asset_cache_control VALUES (DECODE('c0ee29a85b13209423b10447d3c2e6a50641a15c57770e27cb9d5073', 'hex')); -- WINGRIDERS
INSERT INTO grest.asset_cache_control VALUES (DECODE('1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e', 'hex')); -- worldmobiletoken
INSERT INTO grest.asset_cache_control VALUES (DECODE('682fe60c9918842b3323c43b5144bc3d52a23bd2fb81345560d73f63', 'hex')); -- NEWM
INSERT INTO grest.asset_cache_control VALUES (DECODE('6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d10', 'hex')); -- MELD
INSERT INTO grest.asset_cache_control VALUES (DECODE('884892bcdc360bcef87d6b3f806e7f9cd5ac30d999d49970e7a903ae', 'hex')); -- PAVIA
INSERT INTO grest.asset_cache_control VALUES (DECODE('279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f', 'hex')); -- SNEK
INSERT INTO grest.asset_cache_control VALUES (DECODE('f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535', 'hex')); -- AGIX
INSERT INTO grest.asset_cache_control VALUES (DECODE('92292852e3820cfbe99874b284fdf2befbddb38e070cf3512009a60a', 'hex')); -- *Pearl
INSERT INTO grest.asset_cache_control VALUES (DECODE('de9b756719341e79785aa13c164e7fe68c189ed04d61c9876b2fe53f', 'hex')); -- MuesliSwap_AMM
INSERT INTO grest.asset_cache_control VALUES (DECODE('10a49b996e2402269af553a8a96fb8eb90d79e9eca79e2b4223057b6', 'hex')); -- GERO
INSERT INTO grest.asset_cache_control VALUES (DECODE('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', 'hex')); -- BOOK
INSERT INTO grest.asset_cache_control VALUES (DECODE('e38748c08c510a4a5d712922a0f91269b8446ac565068f653c517475', 'hex')); -- preprod KUt1
INSERT INTO grest.asset_cache_control VALUES (DECODE('602866d30452bf3ea0af2d6b4007389eed5542d2572808cba3eb991f', 'hex')); -- preprod tokenA
INSERT INTO grest.asset_cache_control VALUES (DECODE('af6c50cb85c8df17f539437c01b405ab9b62b03140d872e787d7a279', 'hex')); -- preprod tokenB
INSERT INTO grest.asset_cache_control VALUES (DECODE('c462512684cf5a5ee0b176326c724d5879a37a4977d3bf1e4edc39f6', 'hex')); -- preview mTOSI BLUE/GREEN/PURPLE/RAINBOW/RED/YELLOW
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235', 'hex')); -- HOSKY
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('af2e27f580f7f08e93190a81f72462f153026d06450924726645891b', 'hex')); -- DRIP
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6', 'hex')); -- MIN
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77', 'hex')); -- SUNDAE
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f', 'hex')); -- MINSWAP
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('c0ee29a85b13209423b10447d3c2e6a50641a15c57770e27cb9d5073', 'hex')); -- WINGRIDERS
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e', 'hex')); -- worldmobiletoken
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('682fe60c9918842b3323c43b5144bc3d52a23bd2fb81345560d73f63', 'hex')); -- NEWM
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d10', 'hex')); -- MELD
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('884892bcdc360bcef87d6b3f806e7f9cd5ac30d999d49970e7a903ae', 'hex')); -- PAVIA
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f', 'hex')); -- SNEK
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535', 'hex')); -- AGIX
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('92292852e3820cfbe99874b284fdf2befbddb38e070cf3512009a60a', 'hex')); -- *Pearl
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('de9b756719341e79785aa13c164e7fe68c189ed04d61c9876b2fe53f', 'hex')); -- MuesliSwap_AMM
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('10a49b996e2402269af553a8a96fb8eb90d79e9eca79e2b4223057b6', 'hex')); -- GERO
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', 'hex')); -- BOOK
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('e38748c08c510a4a5d712922a0f91269b8446ac565068f653c517475', 'hex')); -- preprod KUt1
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('602866d30452bf3ea0af2d6b4007389eed5542d2572808cba3eb991f', 'hex')); -- preprod tokenA
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('af6c50cb85c8df17f539437c01b405ab9b62b03140d872e787d7a279', 'hex')); -- preprod tokenB
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('c462512684cf5a5ee0b176326c724d5879a37a4977d3bf1e4edc39f6', 'hex')); -- preview mTOSI BLUE/GREEN/PURPLE/RAINBOW/RED/YELLOW
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('', 'hex')); --
4 changes: 3 additions & 1 deletion files/grest/rpc/01_cached_tables/asset_info_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS grest.asset_info_cache (

CREATE INDEX IF NOT EXISTS idx_first_mint_tx_id ON grest.asset_info_cache (first_mint_tx_id);
CREATE INDEX IF NOT EXISTS idx_last_mint_tx_id ON grest.asset_info_cache (last_mint_tx_id);
CREATE INDEX IF NOT EXISTS idx_creation_time ON grest.asset_info_cache (creation_time DESC);

CREATE OR REPLACE FUNCTION grest.asset_info_cache_update()
RETURNS void
Expand All @@ -37,7 +38,8 @@ BEGIN
SELECT MAX(id) INTO _lastest_tx_id
FROM public.tx;

SELECT COALESCE(last_value::bigint,1000) - 1000 INTO _asset_info_cache_last_tx_id
-- assumption rollback to cater for - 15 blocks (16 tx each) , accordingly - rounding off to 250
SELECT COALESCE(last_value::bigint,250) - 250 INTO _asset_info_cache_last_tx_id
FROM grest.control_table
WHERE key = 'asset_info_cache_last_tx_id';

Expand Down
Loading

0 comments on commit b68c894

Please sign in to comment.