Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apps/indexer/drizzle/0009_drop_monitored_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Drop legacy Blockspy monitoredValue table (no longer used)
DROP TABLE IF EXISTS "monitoredValue";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a deprecation/data-retention gate before dropping the table.

Line 2 performs an immediate hard drop, which can irreversibly delete existing monitoredValue rows during rollout/rollback. Add an explicit guard (or two-phase deprecate-then-drop sequence) so the migration fails safely if data still exists.

Proposed migration hardening
 -- Drop legacy Blockspy monitoredValue table (no longer used)
-DROP TABLE IF EXISTS "monitoredValue";
+DO $$
+BEGIN
+  IF EXISTS (SELECT 1 FROM "monitoredValue" LIMIT 1) THEN
+    RAISE EXCEPTION 'monitoredValue is not empty; deprecate/archive before dropping';
+  END IF;
+END
+$$;
+
+DROP TABLE IF EXISTS "monitoredValue";

As per coding guidelines, raw SQL migrations should flag destructive DROP COLUMN/TABLE operations without prior deprecation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DROP TABLE IF EXISTS "monitoredValue";
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM "monitoredValue" LIMIT 1) THEN
RAISE EXCEPTION 'monitoredValue is not empty; deprecate/archive before dropping';
END IF;
END
$$;
DROP TABLE IF EXISTS "monitoredValue";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/indexer/drizzle/0009_drop_monitored_value.sql` at line 2, The DROP TABLE
IF EXISTS statement for "monitoredValue" on line 2 performs an irreversible hard
drop without any safeguard. Add a data-retention gate before dropping the table
by implementing a check that verifies the table is empty or has no dependent
data, causing the migration to fail explicitly if data still exists rather than
silently deleting rows. This can be done by adding a guard query (such as
checking row count) before the DROP TABLE statement, or implementing a two-phase
migration where the table is first marked for deprecation before being dropped
in a subsequent migration.

Source: Coding guidelines

7 changes: 7 additions & 0 deletions apps/indexer/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
14 changes: 0 additions & 14 deletions apps/indexer/drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
2 changes: 0 additions & 2 deletions apps/indexer/src/db/buildDatabase.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;`);
Expand Down
3 changes: 0 additions & 3 deletions apps/indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -92,15 +91,13 @@ 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, {
id: env.HEALTHCHECKS_SYNC_PROVIDER_INFO,
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);
Expand Down
40 changes: 0 additions & 40 deletions apps/indexer/src/monitors/addressBalanceMonitor.ts

This file was deleted.

58 changes: 0 additions & 58 deletions apps/indexer/src/monitors/deploymentBalanceMonitor.ts

This file was deleted.

5 changes: 0 additions & 5 deletions apps/indexer/src/monitors/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/database/dbSchemas/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export { TransactionEvent } from "./transactionEvent";
export { TransactionEventAttribute } from "./transactionEventAttribute";
export { Message } from "./message";
export { AddressReference } from "./addressReference";
export { MonitoredValue } from "./monitoredValue";
36 changes: 0 additions & 36 deletions packages/database/dbSchemas/base/monitoredValue.ts

This file was deleted.

15 changes: 2 additions & 13 deletions packages/database/dbSchemas/index.ts
Original file line number Diff line number Diff line change
@@ -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<Model<any, any>>[] {
let models: ModelCtor<Model<any, any>>[] = baseModels;
Expand All @@ -33,8 +23,7 @@ const baseModels: ModelCtor<Model<any, any>>[] = [
Transaction,
TransactionEvent,
TransactionEventAttribute,
Validator,
MonitoredValue
Validator
];

export function getChainModels(chainName: string) {
Expand Down