From 87d317a047b96ecb7e4b0d56ad85b736350e2946 Mon Sep 17 00:00:00 2001 From: Maxime Beauchamp <15185355+baktun14@users.noreply.github.com> Date: Sat, 13 Jun 2026 19:17:26 -0400 Subject: [PATCH] fix(indexer): remove legacy monitored value monitors The Address/Deployment Balance Monitors are leftovers from the old Blockspy/Cloudmos system and are unused by the deploy tool. The DeploymentBalanceMonitor in particular has been throwing non-stop (5180+ events) whenever it can't fetch a deployment's escrow balance. Nothing in the monorepo reads the monitoredValue table, so this removes the two monitors, their scheduled tasks, the shared Sequelize model, and drops the table via migration 0009. Fixes CLOUDMOS-SYNCER-5C --- apps/indexer/README.md | 2 - .../drizzle/0009_drop_monitored_value.sql | 2 + apps/indexer/drizzle/meta/_journal.json | 7 +++ apps/indexer/drizzle/schema.ts | 14 ----- apps/indexer/src/db/buildDatabase.ts | 2 - apps/indexer/src/index.ts | 3 - .../src/monitors/addressBalanceMonitor.ts | 40 ------------- .../src/monitors/deploymentBalanceMonitor.ts | 58 ------------------- apps/indexer/src/monitors/index.ts | 5 -- packages/database/dbSchemas/base/index.ts | 1 - .../database/dbSchemas/base/monitoredValue.ts | 36 ------------ packages/database/dbSchemas/index.ts | 15 +---- 12 files changed, 11 insertions(+), 174 deletions(-) create mode 100644 apps/indexer/drizzle/0009_drop_monitored_value.sql delete mode 100644 apps/indexer/src/monitors/addressBalanceMonitor.ts delete mode 100644 apps/indexer/src/monitors/deploymentBalanceMonitor.ts delete mode 100644 apps/indexer/src/monitors/index.ts delete mode 100644 packages/database/dbSchemas/base/monitoredValue.ts diff --git a/apps/indexer/README.md b/apps/indexer/README.md index e5efbec945..775308d7fa 100644 --- a/apps/indexer/README.md +++ b/apps/indexer/README.md @@ -45,8 +45,6 @@ Tasks can be configured to report their execution to healthcheck endpoints autom |[Sync Providers Info](./src/providers/providerStatusProvider.ts#L11)|15 minutes| Responsible for querying the `/status` endpoint of every akash provider to track their uptime and available resources. |[Provider IP Lookup](./src/providers/ipLocationProvider.ts#25)|30 minutes|Responsible for updating the akash providers location based on the node's ip address. |[Sync Keybase Info](./src/db/keybaseProvider.ts#L5)|6 hours|Responsible for fetching validator names and picture from [keybase.io](https://keybase.io/).| -|[Address Balance Monitor](./src/monitors/addressBalanceMonitor.ts#L6)|10 minutes|Responsible for updating tracked address balances (**Blockspy Specific**) -|[Deployment Balance Monitor](./src/monitors/deploymentBalanceMonitor.ts#L7)|10 minutes|Responsible for updating tracked deployment balances. This is **blockspy specific** and not used in the deploy tool. [Sync Blocks](./src/chain/chainSync.ts#L77)|7 seconds|Responsible for downloading new blocks and passing them through the correct indexers. ## Data Flow diff --git a/apps/indexer/drizzle/0009_drop_monitored_value.sql b/apps/indexer/drizzle/0009_drop_monitored_value.sql new file mode 100644 index 0000000000..8505add1ac --- /dev/null +++ b/apps/indexer/drizzle/0009_drop_monitored_value.sql @@ -0,0 +1,2 @@ +-- Drop legacy Blockspy monitoredValue table (no longer used) +DROP TABLE IF EXISTS "monitoredValue"; diff --git a/apps/indexer/drizzle/meta/_journal.json b/apps/indexer/drizzle/meta/_journal.json index 031652a730..447e376f33 100644 --- a/apps/indexer/drizzle/meta/_journal.json +++ b/apps/indexer/drizzle/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1762900000000, "tag": "0008_add_deployment_group_deployment_id_index", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1763000000000, + "tag": "0009_drop_monitored_value", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/indexer/drizzle/schema.ts b/apps/indexer/drizzle/schema.ts index 38a466fdcd..ab6de98da7 100644 --- a/apps/indexer/drizzle/schema.ts +++ b/apps/indexer/drizzle/schema.ts @@ -317,20 +317,6 @@ export const deploymentGroupResource = pgTable( ] ); -export const monitoredValue = pgTable( - "monitoredValue", - { - id: uuid().primaryKey().notNull(), - tracker: varchar({ length: 255 }).notNull(), - target: varchar({ length: 255 }).notNull(), - value: varchar({ length: 255 }), - lastUpdateDate: timestamp({ withTimezone: true, mode: "string" }) - }, - table => [ - uniqueIndex("monitored_value_tracker_target").using("btree", table.tracker.asc().nullsLast().op("text_ops"), table.target.asc().nullsLast().op("text_ops")) - ] -); - export const providerAttribute = pgTable( "providerAttribute", { diff --git a/apps/indexer/src/db/buildDatabase.ts b/apps/indexer/src/db/buildDatabase.ts index feef3acca7..51a5fadac6 100644 --- a/apps/indexer/src/db/buildDatabase.ts +++ b/apps/indexer/src/db/buildDatabase.ts @@ -1,7 +1,6 @@ import { activeChain } from "@akashnetwork/database/chainDefinitions"; import { Block, Message } from "@akashnetwork/database/dbSchemas"; import { Day, Transaction, TransactionEvent, TransactionEventAttribute } from "@akashnetwork/database/dbSchemas/base"; -import { MonitoredValue } from "@akashnetwork/database/dbSchemas/base"; import { getGenesis } from "@src/chain/genesisImporter"; import { indexers } from "@src/indexers"; @@ -31,7 +30,6 @@ export const initDatabase = async () => { await TransactionEventAttribute.sync(); await Message.sync(); await Day.sync(); - await MonitoredValue.sync(); // Setting STATISTICS value here since it cannot be defined in the sequelize model await sequelize.query(`ALTER TABLE IF EXISTS public.transaction_event_attribute ALTER COLUMN transaction_event_id SET STATISTICS 1000;`); diff --git a/apps/indexer/src/index.ts b/apps/indexer/src/index.ts index 945cbc8947..36aa64d367 100644 --- a/apps/indexer/src/index.ts +++ b/apps/indexer/src/index.ts @@ -20,7 +20,6 @@ import { env } from "./shared/utils/env"; import { bytesToHumanReadableSize } from "./shared/utils/files"; import { updateProviderUptime } from "./tasks/providerUptimeTracker"; import { updateUsdSpending } from "./tasks/usdSpendingTracker"; -import { addressBalanceMonitor, deploymentBalanceMonitor } from "./monitors"; import { Scheduler } from "./scheduler"; const app = express(); @@ -92,7 +91,6 @@ function startScheduler() { id: env.HEALTHCHECKS_SYNC_AKT_PRICE_HISTORY, measureDuration: true }); - scheduler.registerTask("Address Balance Monitor", () => addressBalanceMonitor.run(), "10 minutes"); if (env.ACTIVE_CHAIN === "akash" || env.ACTIVE_CHAIN === "akashTestnet" || env.ACTIVE_CHAIN === "akashSandbox") { scheduler.registerTask("Sync Providers Info", syncProvidersInfo, "10 seconds", true, { @@ -100,7 +98,6 @@ function startScheduler() { measureDuration: true }); - scheduler.registerTask("Deployment Balance Monitor", () => deploymentBalanceMonitor.run(), "10 minutes"); scheduler.registerTask("Provider IP Lookup", () => updateProvidersLocation(), "30 minutes", true); scheduler.registerTask("USD Spending Tracker", () => updateUsdSpending(), "1 minute", true); scheduler.registerTask("Update provider uptime", () => updateProviderUptime(), "10 minutes", true); diff --git a/apps/indexer/src/monitors/addressBalanceMonitor.ts b/apps/indexer/src/monitors/addressBalanceMonitor.ts deleted file mode 100644 index 53849ddb5d..0000000000 --- a/apps/indexer/src/monitors/addressBalanceMonitor.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { activeChain } from "@akashnetwork/database/chainDefinitions"; -import { MonitoredValue } from "@akashnetwork/database/dbSchemas/base"; -import axios from "axios"; - -export class AddressBalanceMonitor { - async run() { - const monitoredValues = await MonitoredValue.findAll({ - where: { - tracker: "AddressBalanceMonitor" - } - }); - - await Promise.allSettled(monitoredValues.map(x => this.updateValue(x))); - - console.log("Refreshed balances for " + monitoredValues.length + " addresses."); - } - - async updateValue(monitoredValue: MonitoredValue) { - const [targetAddress, targetToken] = monitoredValue.target.split("|"); - const balance = await this.getBalance(targetAddress, targetToken); - - monitoredValue.value = balance.toString(); - monitoredValue.lastUpdateDate = new Date(); - await monitoredValue.save(); - } - - async getBalance(address: string, denom?: string): Promise { - const response = await axios.get(`https://rest.cosmos.directory/${activeChain.cosmosDirectoryId}/cosmos/bank/v1beta1/balances/${address}`, { - timeout: 15_000 - }); - - const balance = response.data.balances.find(x => x.denom === (denom || activeChain.udenom)); - - if (!balance) { - return 0; - } - - return parseInt(balance.amount); - } -} diff --git a/apps/indexer/src/monitors/deploymentBalanceMonitor.ts b/apps/indexer/src/monitors/deploymentBalanceMonitor.ts deleted file mode 100644 index 7f1f5a62a9..0000000000 --- a/apps/indexer/src/monitors/deploymentBalanceMonitor.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { activeChain } from "@akashnetwork/database/chainDefinitions"; -import { MonitoredValue } from "@akashnetwork/database/dbSchemas/base"; -import * as Sentry from "@sentry/node"; -import axios from "axios"; - -export class DeploymentBalanceMonitor { - async run() { - const monitoredValues = await MonitoredValue.findAll({ - where: { - tracker: "DeploymentBalanceMonitor" - } - }); - - await Promise.allSettled(monitoredValues.map(x => this.updateValue(x))); - - console.log("Refreshed balances for " + monitoredValues.length + " deployments."); - } - - async updateValue(monitoredValue: MonitoredValue) { - try { - const balance = await this.getDeploymentBalance(monitoredValue.target); - - if (balance === null) { - throw new Error("Unable to get balance for " + monitoredValue.target); - } - - monitoredValue.value = balance.toString(); - monitoredValue.lastUpdateDate = new Date(); - await monitoredValue.save(); - } catch (err) { - console.error(err); - - Sentry.captureException(err, { tags: { target: monitoredValue.target } }); - } - } - - async getDeploymentBalance(target: string): Promise { - const [owner, dseq] = target.split("/"); - const response = await axios.get(`https://rest.cosmos.directory/akash/akash/deployment/v1beta4/deployments/info?id.owner=${owner}&id.dseq=${dseq}`, { - timeout: 15_000 - }); - - const escrowState = response?.data?.escrow_account?.state; - if (!escrowState?.funds) { - return null; - } - - const funds = escrowState.funds.find((f: { denom: string; amount: string }) => f.denom === activeChain.denom || f.denom === activeChain.udenom); - - if (!funds) { - return null; - } - - const fundsAmount = funds.denom === activeChain.udenom ? parseInt(funds.amount) : parseInt(funds.amount) * 1_000_000; - - return fundsAmount; - } -} diff --git a/apps/indexer/src/monitors/index.ts b/apps/indexer/src/monitors/index.ts deleted file mode 100644 index 55ab68212c..0000000000 --- a/apps/indexer/src/monitors/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { AddressBalanceMonitor } from "./addressBalanceMonitor"; -import { DeploymentBalanceMonitor } from "./deploymentBalanceMonitor"; - -export const addressBalanceMonitor = new AddressBalanceMonitor(); -export const deploymentBalanceMonitor = new DeploymentBalanceMonitor(); diff --git a/packages/database/dbSchemas/base/index.ts b/packages/database/dbSchemas/base/index.ts index b2fb6f47fd..3512e4ba2c 100644 --- a/packages/database/dbSchemas/base/index.ts +++ b/packages/database/dbSchemas/base/index.ts @@ -6,4 +6,3 @@ export { TransactionEvent } from "./transactionEvent"; export { TransactionEventAttribute } from "./transactionEventAttribute"; export { Message } from "./message"; export { AddressReference } from "./addressReference"; -export { MonitoredValue } from "./monitoredValue"; diff --git a/packages/database/dbSchemas/base/monitoredValue.ts b/packages/database/dbSchemas/base/monitoredValue.ts deleted file mode 100644 index ef23026f04..0000000000 --- a/packages/database/dbSchemas/base/monitoredValue.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { DataTypes, UUIDV4 } from "sequelize"; -import { Column, Default, Model, PrimaryKey, Table } from "sequelize-typescript"; - -import { Required } from "../decorators/requiredDecorator"; - -/** - * MonitoredValue model for Akash - * - * This is used to store the monitored value data for notification process - */ -@Table({ - modelName: "monitoredValue", - indexes: [{ unique: true, fields: ["tracker", "target"] }] -}) -export class MonitoredValue extends Model { - /** - * The database ID of the monitored value - */ - @Required @PrimaryKey @Default(UUIDV4) @Column(DataTypes.UUID) id!: string; - /** - * The tracker of the monitored value - */ - @Required @Column tracker!: string; - /** - * The target of the monitored value - */ - @Required @Column target!: string; - /** - * The value of the monitored value - */ - @Column value?: string; - /** - * The last update date of the monitored value - */ - @Column lastUpdateDate?: Date; -} diff --git a/packages/database/dbSchemas/index.ts b/packages/database/dbSchemas/index.ts index 2c94ccadd3..53bd6a662b 100644 --- a/packages/database/dbSchemas/index.ts +++ b/packages/database/dbSchemas/index.ts @@ -1,17 +1,7 @@ import type { Model, ModelCtor } from "sequelize-typescript"; import { activeChain, chainDefinitions } from "../chainDefinitions"; -import { - AddressReference, - Block as BaseBlock, - Day, - Message as BaseMessage, - MonitoredValue, - Transaction, - TransactionEvent, - TransactionEventAttribute, - Validator -} from "./base"; +import { AddressReference, Block as BaseBlock, Day, Message as BaseMessage, Transaction, TransactionEvent, TransactionEventAttribute, Validator } from "./base"; function getFilteredBaseModel(): ModelCtor>[] { let models: ModelCtor>[] = baseModels; @@ -33,8 +23,7 @@ const baseModels: ModelCtor>[] = [ Transaction, TransactionEvent, TransactionEventAttribute, - Validator, - MonitoredValue + Validator ]; export function getChainModels(chainName: string) {