Merge pull request #104 from ArtemKolodko/revert_config_update

Revert Add new config param INTERNAL_TXS_DELETE_PERIOD
pull/105/head
Diego Nava 2 years ago committed by GitHub
commit c11348062f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 59
      doc/ManualMigrations.md
  2. 1
      src/config.ts
  3. 7
      src/store/postgres/InternalTransaction.ts
  4. 16
      src/store/postgres/index.ts

@ -18,62 +18,3 @@ ADD COLUMN block_number bigint default 0;
ALTER TABLE erc1155_asset
ADD COLUMN block_number bigint default 0;
```
#### Date: 2022
```sql
create type transaction_extra_mark as enum (
'normal',
'hasInternalONETransfers'
);
alter table transactions add column extra_mark transaction_extra_mark default 'normal'
create table if not exists transactions_count
(
id serial primary key,
date timestamp default now(),
date_string varchar unique not null,
count bigint not null
);
create type metrics_type as enum (
'wallets_count',
'transactions_count',
'average_fee',
'block_size'
);
create table if not exists metrics_daily
(
id serial primary key,
type metrics_type,
date varchar not null,
value varchar not null,
created_at timestamp default now(),
unique (type, date)
);
create type metrics_top_type as enum (
'top_one_sender',
'top_one_receiver',
'top_txs_count_sent',
'top_txs_count_received'
);
create table if not exists metrics_top
(
type metrics_top_type,
period smallint not null,
address char(42) not null,
value numeric,
rank smallint not null,
share real default (0),
updated_at timestamp default now(),
unique (type, period, address)
);
```

@ -107,7 +107,6 @@ export const config = {
),
batchCount: +(process.env.INDEXER_BATCH_COUNT || 100),
blockIndexerBlockRange: +(process.env.BLOCK_INDEXER_BLOCK_RANGE || 10),
internalTxsDeletePeriod: +(process.env.INTERNAL_TXS_DELETE_PERIOD || 1000 * 60 * 60 * 24), // Delete all internal txs older than given period
rpc: {
transport: process.env.INDEXER_RPC_TRANSPORT || 'ws',
urls: [

@ -17,8 +17,11 @@ export class PostgresStorageInternalTransaction implements IStorageInternalTrans
this.query = query
}
removeInternalTxs = async (toBlockNumber: number) => {
await this.query(`delete from internal_transactions where block_number < $1`, [toBlockNumber])
// remove old transactions every day
removeInternalTransactionsOlder7Days = async (toBlockNumber: number) => {
const res = await this.query(`delete from internal_transactions where block_number < $1`, [
toBlockNumber,
])
}
addInternalTransaction = async (tx: InternalTransaction) => {

@ -28,6 +28,7 @@ import {config} from 'src/config'
const defaultRetries = 2
const sleep = (time = 1000) => new Promise((r) => setTimeout(r, time))
const removeOldInternalTransactionsTaskPeriod = 1000 * 60 * 60 * 24
const blockNumber7DayOld = (7 * 24 * 60 * 60) / 2
export class PostgresStorage implements IStorage {
@ -98,11 +99,12 @@ export class PostgresStorage implements IStorage {
this.isStarting = false
this.l.info('Done')
const {internalTxsDeletePeriod} = config.indexer
if (config.indexer.isEnabled && [0, 1].includes(this.shardID) && internalTxsDeletePeriod) {
this.l.info(`Start removing internal transactions task, period: ${internalTxsDeletePeriod}`)
if (config.indexer.isEnabled && [0, 1].includes(this.shardID)) {
this.l.info(
`Start removing internal transactions task, period: ${removeOldInternalTransactionsTaskPeriod}`
)
try {
await this.removeOldInternalTransactionsTask(internalTxsDeletePeriod)
await this.removeOldInternalTransactionsTask()
} catch (err) {
this.l.error(`Failed to start removing internal transactions task: ${JSON.stringify(err)}`)
}
@ -172,13 +174,13 @@ export class PostgresStorage implements IStorage {
return {count}
}
removeOldInternalTransactionsTask = async (period: number) => {
removeOldInternalTransactionsTask = async () => {
const lastBlockNumber = await this.block.getLatestBlockNumber()
const toBlock = lastBlockNumber - blockNumber7DayOld
this.l.info(`Removing internal transactions where block number < ${toBlock}`)
await this.internalTransaction.removeInternalTxs(lastBlockNumber)
setTimeout(this.removeOldInternalTransactionsTask, period)
await this.internalTransaction.removeInternalTransactionsOlder7Days(lastBlockNumber)
setTimeout(this.removeOldInternalTransactionsTask, removeOldInternalTransactionsTaskPeriod)
}
async stop() {

Loading…
Cancel
Save