-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into data-test-haproxy
- Loading branch information
Showing
148 changed files
with
22,074 additions
and
2,876 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Update Repository | ||
|
||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
sync: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.GIT_CC }} | ||
- name: Clone repository | ||
run: | | ||
git clone https://github.com/cardano-community/koios-artifacts.git | ||
cd koios-artifacts | ||
git config --global user.name 'cardano-bot' | ||
git config --global user.email '${{ secrets.GIT_EMAIL }}' | ||
- name: Sync repositories | ||
run: | | ||
git remote add new https://github.com/koios-official/koios-artifacts.git | ||
git fetch --unshallow origin | ||
git fetch --all | ||
git remote set-url --add --push new https://github.com/koios-official/koios-artifacts.git | ||
git push -f --all new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
tests/**/__pycache__ | ||
tests/**/.* | ||
.vscode | ||
.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[sqlfluff] | ||
dialect = postgres | ||
exclude_rules = structure.column_order, references.keywords | ||
max_line_length=260 | ||
recurse = 0 | ||
capitalisation_policy = upper | ||
extended_capitalisation_policy = upper | ||
idented_joins = True | ||
indented_using_on = False | ||
tab_space_size = 2 | ||
large_file_skip_byte_limit=35000 | ||
|
||
[sqlfluff:indentation] | ||
tab_space_size = 2 | ||
allow_implicit_indents = True | ||
|
||
[sqlfluff:rules:convention.count_rows] | ||
prefer_count_1 = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
echo "$(date +%F_%H:%M:%S) Running active stake cache update..." | ||
|
||
# High level check in db to see if update needed at all (should be updated only once on epoch transition) | ||
[[ $(psql ${DB_NAME} -qbt -c "SELECT grest.active_stake_cache_update_check();" | tail -2 | tr -cd '[:alnum:]') != 't' ]] && | ||
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_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..." && | ||
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 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
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 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
CNODE_VNAME=cnode | ||
DB_NAME=cexplorer | ||
TR_URL=https://github.com/cardano-foundation/cardano-token-registry | ||
TR_SUBDIR=mappings | ||
TR_DIR=${HOME}/git | ||
TR_NAME=${CNODE_VNAME}-token-registry | ||
|
||
echo "$(date +%F_%H:%M:%S) - START - Asset Registry Update" | ||
|
||
if [[ ! -d "${TR_DIR}/${TR_NAME}" ]]; then | ||
[[ -z ${HOME} ]] && echo "HOME variable not set, aborting..." && exit 1 | ||
mkdir -p "${TR_DIR}" | ||
cd "${TR_DIR}" >/dev/null || exit 1 | ||
git clone ${TR_URL} ${TR_NAME} >/dev/null || exit 1 | ||
fi | ||
pushd "${TR_DIR}/${TR_NAME}" >/dev/null || exit 1 | ||
git pull >/dev/null || exit 1 | ||
|
||
last_commit="$(psql ${DB_NAME} -c "select last_value from grest.control_table where key='asset_registry_commit'" -t | xargs)" | ||
[[ -z "${last_commit}" ]] && last_commit="$(git rev-list HEAD | tail -n 1)" | ||
latest_commit="$(git rev-list HEAD | head -n 1)" | ||
|
||
[[ "${last_commit}" == "${latest_commit}" ]] && echo "$(date +%F_%H:%M:%S) - END - Asset Registry Update, no updates necessary." && exit 0 | ||
|
||
asset_cnt=0 | ||
|
||
[[ -f '.assetregistry.csv' ]] && rm -f .assetregistry.csv | ||
while IFS= read -re assetfile; do | ||
if ! asset_data_csv=$(jq -er '[ | ||
.subject[0:56], | ||
.subject[56:], | ||
.name.value, | ||
.description.value // "", | ||
.ticker.value // "", | ||
.url.value // "", | ||
.logo.value // "", | ||
.decimals.value // 0 | ||
] | @csv' "${assetfile}"); then | ||
echo "Failure parsing '${assetfile}', skipping..." | ||
continue | ||
fi | ||
echo "${asset_data_csv}" >> .assetregistry.csv | ||
((asset_cnt++)) | ||
done < <(git diff --name-only "${last_commit}" "${latest_commit}" | grep ^${TR_SUBDIR}) | ||
cat << EOF > .assetregistry.sql | ||
CREATE TEMP TABLE tmparc (like grest.asset_registry_cache); | ||
\COPY tmparc FROM '.assetregistry.csv' DELIMITER ',' CSV; | ||
INSERT INTO grest.asset_registry_cache SELECT DISTINCT ON (asset_policy,asset_name) * FROM tmparc ON CONFLICT(asset_policy,asset_name) DO UPDATE SET asset_policy=excluded.asset_policy, asset_name=excluded.asset_name, name=excluded.name, description=excluded.description, ticker=excluded.ticker, url=excluded.url, logo=excluded.logo,decimals=excluded.decimals; | ||
UPDATE grest.asset_info_cache SET decimals=x.decimals FROM | ||
(SELECT ma.id, t.decimals FROM tmparc t LEFT JOIN multi_asset ma ON decode(t.asset_name,'hex')=ma.name AND decode(t.asset_policy,'hex')=ma.policy WHERE t.decimals != 0) as x | ||
WHERE asset_id = x.id; | ||
EOF | ||
|
||
psql ${DB_NAME} -qb -f .assetregistry.sql >/dev/null && rm -f .assetregistry.sql | ||
psql ${DB_NAME} -qb -c "INSERT INTO grest.control_table (key, last_value) VALUES ('asset_registry_commit','${latest_commit}') ON CONFLICT(key) DO UPDATE SET last_value='${latest_commit}'" | ||
echo "$(date +%F_%H:%M:%S) - END - Asset Registry Update, ${asset_cnt} assets added/updated for commits ${last_commit} to ${latest_commit}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
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 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
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 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
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 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
DB_NAME=cexplorer | ||
NWMAGIC= | ||
EPOCH_LENGTH= | ||
PROM_URL= | ||
CCLI= | ||
export CARDANO_NODE_SOCKET_PATH= | ||
|
||
echo "$(date +%F_%H:%M:%S) Running next epoch nonce calculation..." | ||
|
||
min_slot=$((EPOCH_LENGTH * 7 / 10)) | ||
current_epoch=$(curl -s "${PROM_URL}" | grep epoch | awk '{print $2}') | ||
current_slot_in_epoch=$(curl -s "${PROM_URL}" | grep slotInEpoch | awk '{print $2}') | ||
next_epoch=$((current_epoch + 1)) | ||
|
||
[[ ${current_slot_in_epoch} -ge ${min_slot} ]] && | ||
next_epoch_nonce=$(echo "$(${CCLI} query protocol-state --testnet-magic "${NWMAGIC}" | jq -r .candidateNonce.contents)$(${CCLI} query protocol-state --testnet-magic "${NWMAGIC}" | jq -r .lastEpochBlockNonce.contents)" | xxd -r -p | b2sum -b -l 256 | awk '{print $1}') && | ||
psql ${DB_NAME} -c "INSERT INTO grest.epoch_info_cache (epoch_no, p_nonce) VALUES (${next_epoch}, '${next_epoch_nonce}') ON CONFLICT DO NOTHING;" | ||
|
||
echo "$(date +%F_%H:%M:%S) Job done!" |
12 changes: 12 additions & 0 deletions
12
files/grest/cron/jobs/stake-distribution-new-accounts-update.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
echo "$(date +%F_%H:%M:%S) Running stake distribution update for new accounts..." | ||
psql ${DB_NAME} -qbt -c "CALL GREST.UPDATE_NEWLY_REGISTERED_ACCOUNTS_STAKE_DISTRIBUTION_CACHE();" 1>/dev/null 2>&1 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
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 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
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 | ||
|
||
echo "$(date +%F_%H:%M:%S) Capturing last epochs' snapshot..." | ||
psql ${DB_NAME} -qbt -c "CALL GREST.CAPTURE_LAST_EPOCH_SNAPSHOT();" 1>/dev/null 2>&1 | ||
echo "$(date +%F_%H:%M:%S) Job done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CREATE OR REPLACE FUNCTION grest.genesis() | ||
RETURNS TABLE ( | ||
networkmagic varchar, | ||
networkid varchar, | ||
activeslotcoeff varchar, | ||
updatequorum varchar, | ||
maxlovelacesupply varchar, | ||
epochlength varchar, | ||
systemstart integer, | ||
slotsperkesperiod varchar, | ||
slotlength varchar, | ||
maxkesrevolutions varchar, | ||
securityparam varchar, | ||
alonzogenesis varchar | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT | ||
g.networkmagic, | ||
g.networkid, | ||
g.activeslotcoeff, | ||
g.updatequorum, | ||
g.maxlovelacesupply, | ||
g.epochlength, | ||
EXTRACT(EPOCH FROM g.systemstart::timestamp)::integer, | ||
g.slotsperkesperiod, | ||
g.slotlength, | ||
g.maxkesrevolutions, | ||
g.securityparam, | ||
g.alonzogenesis | ||
FROM | ||
grest.genesis AS g; | ||
END; | ||
$$; |
Oops, something went wrong.