diff --git a/.github/workflows/deploy-libre-testnet.yaml b/.github/workflows/deploy-libre-testnet.yaml index 944aab05..245dc769 100644 --- a/.github/workflows/deploy-libre-testnet.yaml +++ b/.github/workflows/deploy-libre-testnet.yaml @@ -56,7 +56,7 @@ jobs: REACT_APP_SYNC_TOLERANCE_INTERVAL: 180000 REACT_APP_TOKEN_SYMBOL: 'LIBRE' REACT_APP_NETWORK_URL: '[{"label":"EOS","value":"https://eos.antelope.tools","mainnet":true,"pair":"eos","icon":"eos","order":1},{"label":"Proton","value":"https://proton.antelope.tools","mainnet":true,"pair":"proton","icon":"proton","order":2},{"label":"WAX","value":"https://wax.antelope.tools","mainnet":true,"pair":"wax","icon":"wax","order":3},{"label":"Telos","value":"https://telos.antelope.tools","mainnet":true,"pair":"telos","icon":"telos","order":4},{"label":"Libre","value":"https://libre.antelope.tools","mainnet":true,"pair":"libre","icon":"libre","order":5},{"label":"LACChain EOSIO","value":"https://lacchain.antelope.tools","mainnet":true,"pair":null,"icon":"lacchain","order":6},{"label":"Jungle4 Testnet","value":"https://jungle.antelope.tools","mainnet":false,"pair":"eos","icon":"jungle","order":1},{"label":"Proton Testnet","value":"https://proton-testnet.antelope.tools","mainnet":false,"pair":"proton","icon":"proton","order":2},{"label":"WAX Testnet","value":"https://wax-testnet.antelope.tools","mainnet":false,"pair":"wax","icon":"wax","order":3},{"label":"Telos Testnet","value":"https://telos-testnet.antelope.tools","mainnet":false,"pair":"telos","icon":"telos","order":4},{"label":"Libre Testnet","value":"https://libre-testnet.antelope.tools","mainnet":false,"pair":"libre","icon":"libre","order":5},{"label":"Ultra Testnet","value":"https://ultra-testnet.antelope.tools","mainnet":false,"pair":"ultra","icon":"ultra","order":6}]' - REACT_APP_DISABLED_MENU_ITEMS: '["/missed-blocks","/block-distribution"]' + REACT_APP_DISABLED_MENU_ITEMS: '["/missed-blocks"]' REACT_APP_BLOCK_EXPLORER_URL: 'https://libre-testnet-explorer.edenia.cloud/transaction/(transaction)' REACT_APP_STATE_HISTORY_ENABLED: 'false' REACT_APP_GOOGLE_ANALITIC_PAGE_ID: 'G-E6Y0EC9FT8' @@ -82,7 +82,8 @@ jobs: # hapi HAPI_EOS_API_NETWORK_NAME: libre HAPI_EOS_API_ENDPOINTS: '["https://libre-testnet.edenia.cloud","https://api.testnet.libre.cryptobloks.io","https://libre-testnet.eosphere.io"]' - HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT: '' + HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT: 'ws://api-node.libre-testnet:8080' + HAPI_EOS_BLOCK_HISTORY_DAYS: 90 HAPI_EOS_API_CHAIN_ID: b64646740308df2ee06c6b72f34c0f7fa066d940e831f752db2006fcc2b78dee HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }} HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }} diff --git a/docker-compose.yaml b/docker-compose.yaml index 5cb0b0af..1cf4677d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -68,6 +68,7 @@ services: HAPI_EOSRATE_GET_STATS_URL: '${HAPI_EOSRATE_GET_STATS_URL}' HAPI_EOSRATE_GET_STATS_USER: '${HAPI_EOSRATE_GET_STATS_USER}' HAPI_EOSRATE_GET_STATS_PASSWORD: '${HAPI_EOSRATE_GET_STATS_PASSWORD}' + HAPI_EOS_BLOCK_HISTORY_DAYS: '${HAPI_EOS_BLOCK_HISTORY_DAYS}' hasura: container_name: '${STAGE}-${APP_NAME}-hasura' image: hasura/graphql-engine:v2.16.0.cli-migrations-v3 diff --git a/hapi/src/config/eos.config.js b/hapi/src/config/eos.config.js index 26fc45cf..b4484bed 100644 --- a/hapi/src/config/eos.config.js +++ b/hapi/src/config/eos.config.js @@ -8,6 +8,8 @@ module.exports = { : '', stateHistoryPluginEndpoint: process.env.HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT, + keepBlockHistoryForDays: + parseInt(process.env.HAPI_EOS_BLOCK_HISTORY_DAYS) || 0, chainId: process.env.HAPI_EOS_API_CHAIN_ID, eosChainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', diff --git a/hapi/src/services/state-history-plugin.service.js b/hapi/src/services/state-history-plugin.service.js index fe4b6917..6e5912bb 100644 --- a/hapi/src/services/state-history-plugin.service.js +++ b/hapi/src/services/state-history-plugin.service.js @@ -132,6 +132,23 @@ const handleBlocksResult = async data => { } } +const cleanOldBlocks = async () => { + const date = new Date() + const days = eosConfig.keepBlockHistoryForDays + + date.setSeconds(date.getSeconds() - 60 * 60 * 24 * days) + + const mutation = ` + mutation ($date: timestamptz) { + delete_block_history (where: {timestamp: {_lt: $date}}) { + affected_rows + } + } + ` + + await hasuraUtil.request(mutation, { date }) +} + const init = async () => { if (!eosConfig.stateHistoryPluginEndpoint) { return @@ -177,5 +194,6 @@ const init = async () => { } module.exports = { + cleanOldBlocks, init } diff --git a/hapi/src/services/transactions.service.js b/hapi/src/services/transactions.service.js index 5bc8c8ae..d83057cf 100644 --- a/hapi/src/services/transactions.service.js +++ b/hapi/src/services/transactions.service.js @@ -17,7 +17,8 @@ const getTransactions = async (range = '3 Hours') => { FROM interval LEFT JOIN - block_history ON date_trunc('${granularity}', block_history.timestamp) = interval.value + ( SELECT * FROM block_history WHERE transactions_length > 0 ) + AS block_history ON date_trunc('${granularity}', block_history.timestamp) = interval.value GROUP BY 1 ORDER BY diff --git a/hapi/src/workers/producers.worker.js b/hapi/src/workers/producers.worker.js index 36863f46..c2e61c75 100644 --- a/hapi/src/workers/producers.worker.js +++ b/hapi/src/workers/producers.worker.js @@ -64,14 +64,14 @@ const start = async () => { run('CPU WORKER', cpuService.worker, workersConfig.cpuWorkerInterval) run('CPU WORKER CLEANUP', cpuService.cleanOldBenchmarks, 86400) } - + if (eosConfig.stateHistoryPluginEndpoint) { + run('BLOCK HISTORY CLEANUP', stateHistoryPluginService.cleanOldBlocks, 43200) run('SYNC BLOCK HISTORY', stateHistoryPluginService.init) run('SYNC MISSED BLOCKS', missedBlocksService.syncMissedBlocks) run('SYNC MISSED BLOCKS PER PRODUCER', statsService.getCurrentMissedBlock) run('SYNC SCHEDULE HISTORY', demuxService.init) run('SYNC TPS', statsService.syncTPSAllTimeHigh) - run('SYNC TRX BY INTERVALS', statsService.formatTransactionHistory, 10800) run( 'SYNC TRANSACTIONS INFO', statsService.syncTransactionsInfo, diff --git a/kubernetes/configmap-dashboard.yaml b/kubernetes/configmap-dashboard.yaml index 5553fb71..6b8385af 100644 --- a/kubernetes/configmap-dashboard.yaml +++ b/kubernetes/configmap-dashboard.yaml @@ -96,6 +96,7 @@ data: HAPI_EOSRATE_GET_STATS_URL: '${HAPI_EOSRATE_GET_STATS_URL}' HAPI_EOSRATE_GET_STATS_USER: '${HAPI_EOSRATE_GET_STATS_USER}' HAPI_EOSRATE_GET_STATS_PASSWORD: '${HAPI_EOSRATE_GET_STATS_PASSWORD}' + HAPI_EOS_BLOCK_HISTORY_DAYS: '${HAPI_EOS_BLOCK_HISTORY_DAYS}' --- apiVersion: v1 kind: ConfigMap