Skip to content

Commit

Permalink
Merge branch 'fix-ogmios-connection' into 'dev'
Browse files Browse the repository at this point in the history
update scanner packages

See merge request ergo/rosen-bridge/watcher!285
  • Loading branch information
vorujack committed Aug 7, 2024
2 parents 216a438 + 1c0d8df commit e6c7b60
Show file tree
Hide file tree
Showing 11 changed files with 551 additions and 101 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-ducks-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': patch
---

Stabalize ogmios connection by adding connection close handler
1 change: 1 addition & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cardano:
ogmios:
host: '' # ogmios node host address
port: 1337 # ogmios port
connectionRetrialInterval: 30 # ogmios connection retrial interval (in seconds)
useTls: false # connect to ogmios using https or not
blockfrost:
url: '' # url to connect to blockfrost
Expand Down
186 changes: 93 additions & 93 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@
},
"dependencies": {
"@emurgo/cip14-js": "^3.0.1",
"@rosen-bridge/address-extractor": "^5.0.5",
"@rosen-bridge/address-extractor": "^5.0.6",
"@rosen-bridge/asset-check": "^0.2.1",
"@rosen-bridge/bitcoin-esplora-scanner": "^0.1.10",
"@rosen-bridge/bitcoin-observation-extractor": "^4.0.1",
"@rosen-bridge/bitcoin-rpc-scanner": "^0.2.4",
"@rosen-bridge/bitcoin-esplora-scanner": "^0.1.12",
"@rosen-bridge/bitcoin-observation-extractor": "^4.0.4",
"@rosen-bridge/bitcoin-rpc-scanner": "^0.2.6",
"@rosen-bridge/health-check": "^5.0.0",
"@rosen-bridge/log-level-check": "^0.1.1",
"@rosen-bridge/minimum-fee": "^2.1.0",
"@rosen-bridge/node-sync-check": "^0.1.1",
"@rosen-bridge/observation-extractor": "^5.0.2",
"@rosen-bridge/observation-extractor": "^5.0.4",
"@rosen-bridge/permit-check": "^0.1.1",
"@rosen-bridge/scanner": "^4.0.5",
"@rosen-bridge/scanner": "^4.1.1",
"@rosen-bridge/scanner-sync-check": "^0.3.0",
"@rosen-bridge/tokens": "^1.2.1",
"@rosen-bridge/watcher-data-extractor": "^7.0.0",
"@rosen-bridge/watcher-data-extractor": "^7.0.2",
"@rosen-bridge/wid-check": "^0.1.1",
"@rosen-bridge/winston-logger": "0.2.1",
"@rosen-clients/cardano-koios": "^2.0.3",
Expand Down
13 changes: 12 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class CardanoConfig {
port: number;
initialSlot: number;
initialHash: string;
connectionRetrialInterval: number;
useTls?: boolean;
};
koios?: {
Expand All @@ -324,9 +325,19 @@ class CardanoConfig {
const host = getRequiredString('cardano.ogmios.host');
const port = getRequiredNumber('cardano.ogmios.port');
const initialSlot = getRequiredNumber('cardano.initial.slot');
const connectionRetrialInterval = getRequiredNumber(
'cardano.ogmios.connectionRetrialInterval'
);
const initialHash = getRequiredString('cardano.initial.hash');
const useTls = config.get<boolean>('cardano.ogmios.useTls');
this.ogmios = { host, port, initialHash, initialSlot, useTls };
this.ogmios = {
host,
port,
initialHash,
initialSlot,
connectionRetrialInterval,
useTls,
};
} else if (this.type === Constants.KOIOS_TYPE) {
const url = getRequiredString('cardano.koios.url');
const interval = getRequiredNumber('cardano.koios.interval');
Expand Down
8 changes: 8 additions & 0 deletions src/database/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { WatcherMigration1700710099334 } from './postgres/1700710099334-watcherM
import { WatcherMigration1703244656364 } from './postgres/1703244656364-watcherMigration';
import { WatcherMigration1704105342269 } from './postgres/1704105342269-watcherMigration';
import { WatcherMigration1720424860524 } from './postgres/1720424860524-watcherMigration';
import { WatcherMigration1722549850233 } from './postgres/1722549850233-watcherMigration';
import { WatcherMigration1722867363628 } from './postgres/1722867363628-watcherMigration';
import { WatcherMigration1700641198429 } from './sqlite/1700641198429-watcherMigration';
import { WatcherMigration1703244614956 } from './sqlite/1703244614956-watcherMigration';
import { WatcherMigration1704105040303 } from './sqlite/1704105040303-watcherMigration';
import { WatcherMigration1706610773175 } from './sqlite/1706610773175-watcherMigration';
import { WatcherMigration1706610773177 } from './sqlite/1706610773177-watcherMigration';
import { WatcherMigration1720425345411 } from './sqlite/1720425345411-watcherMigration';
import { WatcherMigration1722597111974 } from './sqlite/1722597111974-watcherMigration';
import { WatcherMigration1722866480590 } from './sqlite/1722866480590-watcherMigration';

export default {
sqlite: [
Expand All @@ -17,11 +21,15 @@ export default {
WatcherMigration1706610773175,
WatcherMigration1706610773177,
WatcherMigration1720425345411,
WatcherMigration1722597111974,
WatcherMigration1722866480590,
],
postgres: [
WatcherMigration1700710099334,
WatcherMigration1703244656364,
WatcherMigration1704105342269,
WatcherMigration1720424860524,
WatcherMigration1722549850233,
WatcherMigration1722867363628,
],
};
108 changes: 108 additions & 0 deletions src/database/migrations/postgres/1722549850233-watcherMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class WatcherMigration1722549850233 implements MigrationInterface {
name = 'WatcherMigration1722549850233';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`
DELETE FROM "typeorm_metadata"
WHERE "type" = $1
AND "name" = $2
AND "schema" = $3
`,
['VIEW', 'revenue_view', 'public']
);
await queryRunner.query(`
DROP VIEW "revenue_view"
`);
await queryRunner.query(
`
DELETE FROM "typeorm_metadata"
WHERE "type" = $1
AND "name" = $2
AND "schema" = $3
`,
['VIEW', 'revenue_chart_data', 'public']
);
await queryRunner.query(`
DROP VIEW "revenue_chart_data"
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE VIEW "revenue_chart_data" AS
SELECT "pe"."WID" AS "wid",
"be"."year" AS "year",
"be"."month" AS "month",
"be"."day" AS "day",
re."tokenId" AS "tokenId",
re."amount" AS "amount",
be."timestamp" AS "timestamp"
FROM "revenue_entity" "re"
INNER JOIN "permit_entity" "pe" ON re."permitId" = "pe"."id"
INNER JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"
`);
await queryRunner.query(
`
INSERT INTO "typeorm_metadata"(
"database",
"schema",
"table",
"type",
"name",
"value"
)
VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)
`,
[
'public',
'VIEW',
'revenue_chart_data',
'SELECT "pe"."WID" AS "wid", "be"."year" AS "year", "be"."month" AS "month", "be"."day" AS "day", re."tokenId" AS "tokenId", re."amount" AS "amount", be."timestamp" AS "timestamp" FROM "revenue_entity" "re" INNER JOIN "permit_entity" "pe" ON re."permitId" = "pe"."id" INNER JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"',
]
);
await queryRunner.query(`
CREATE VIEW "revenue_view" AS
SELECT "pe"."id" AS "id",
"pe"."WID" AS "wid",
"ete"."sourceChainHeight" AS "lockHeight",
"be"."height" AS "height",
"be"."timestamp" AS "timestamp",
pe."txId" AS "permitTxId",
ete."eventId" AS "eventId",
ete."fromChain" AS "fromChain",
ete."toChain" AS "toChain",
ete."fromAddress" AS "fromAddress",
ete."toAddress" AS "toAddress",
ete."amount" AS "amount",
ete."bridgeFee" AS "bridgeFee",
ete."networkFee" AS "networkFee",
ete."sourceChainTokenId" AS "tokenId",
ete."sourceTxId" AS "lockTxId"
FROM "permit_entity" "pe"
INNER JOIN "event_trigger_entity" "ete" ON pe."txId" = ete."spendTxId"
LEFT JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"
`);
await queryRunner.query(
`
INSERT INTO "typeorm_metadata"(
"database",
"schema",
"table",
"type",
"name",
"value"
)
VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)
`,
[
'public',
'VIEW',
'revenue_view',
'SELECT "pe"."id" AS "id", "pe"."WID" AS "wid", "ete"."sourceChainHeight" AS "lockHeight", "be"."height" AS "height", "be"."timestamp" AS "timestamp", pe."txId" AS "permitTxId", ete."eventId" AS "eventId", ete."fromChain" AS "fromChain", ete."toChain" AS "toChain", ete."fromAddress" AS "fromAddress", ete."toAddress" AS "toAddress", ete."amount" AS "amount", ete."bridgeFee" AS "bridgeFee", ete."networkFee" AS "networkFee", ete."sourceChainTokenId" AS "tokenId", ete."sourceTxId" AS "lockTxId" FROM "permit_entity" "pe" INNER JOIN "event_trigger_entity" "ete" ON pe."txId" = ete."spendTxId" LEFT JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"',
]
);
}
}
108 changes: 108 additions & 0 deletions src/database/migrations/postgres/1722867363628-watcherMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class WatcherMigration1722867363628 implements MigrationInterface {
name = 'WatcherMigration1722867363628';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE VIEW "revenue_chart_data" AS
SELECT "pe"."WID" AS "wid",
"be"."year" AS "year",
"be"."month" AS "month",
"be"."day" AS "day",
re."tokenId" AS "tokenId",
re."amount" AS "amount",
be."timestamp" AS "timestamp"
FROM "revenue_entity" "re"
INNER JOIN "permit_entity" "pe" ON re."permitId" = "pe"."id"
INNER JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"
`);
await queryRunner.query(
`
INSERT INTO "typeorm_metadata"(
"database",
"schema",
"table",
"type",
"name",
"value"
)
VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)
`,
[
'public',
'VIEW',
'revenue_chart_data',
'SELECT "pe"."WID" AS "wid", "be"."year" AS "year", "be"."month" AS "month", "be"."day" AS "day", re."tokenId" AS "tokenId", re."amount" AS "amount", be."timestamp" AS "timestamp" FROM "revenue_entity" "re" INNER JOIN "permit_entity" "pe" ON re."permitId" = "pe"."id" INNER JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"',
]
);
await queryRunner.query(`
CREATE VIEW "revenue_view" AS
SELECT "pe"."id" AS "id",
"pe"."WID" AS "wid",
"ete"."sourceChainHeight" AS "lockHeight",
"be"."height" AS "height",
"be"."timestamp" AS "timestamp",
pe."txId" AS "permitTxId",
ete."eventId" AS "eventId",
ete."fromChain" AS "fromChain",
ete."toChain" AS "toChain",
ete."fromAddress" AS "fromAddress",
ete."toAddress" AS "toAddress",
ete."amount" AS "amount",
ete."bridgeFee" AS "bridgeFee",
ete."networkFee" AS "networkFee",
ete."sourceChainTokenId" AS "tokenId",
ete."sourceTxId" AS "lockTxId"
FROM "permit_entity" "pe"
INNER JOIN "event_trigger_entity" "ete" ON pe."txId" = ete."spendTxId"
LEFT JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"
`);
await queryRunner.query(
`
INSERT INTO "typeorm_metadata"(
"database",
"schema",
"table",
"type",
"name",
"value"
)
VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)
`,
[
'public',
'VIEW',
'revenue_view',
'SELECT "pe"."id" AS "id", "pe"."WID" AS "wid", "ete"."sourceChainHeight" AS "lockHeight", "be"."height" AS "height", "be"."timestamp" AS "timestamp", pe."txId" AS "permitTxId", ete."eventId" AS "eventId", ete."fromChain" AS "fromChain", ete."toChain" AS "toChain", ete."fromAddress" AS "fromAddress", ete."toAddress" AS "toAddress", ete."amount" AS "amount", ete."bridgeFee" AS "bridgeFee", ete."networkFee" AS "networkFee", ete."sourceChainTokenId" AS "tokenId", ete."sourceTxId" AS "lockTxId" FROM "permit_entity" "pe" INNER JOIN "event_trigger_entity" "ete" ON pe."txId" = ete."spendTxId" LEFT JOIN "block_entity" "be" ON "pe"."block" = "be"."hash"',
]
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`
DELETE FROM "typeorm_metadata"
WHERE "type" = $1
AND "name" = $2
AND "schema" = $3
`,
['VIEW', 'revenue_view', 'public']
);
await queryRunner.query(`
DROP VIEW "revenue_view"
`);
await queryRunner.query(
`
DELETE FROM "typeorm_metadata"
WHERE "type" = $1
AND "name" = $2
AND "schema" = $3
`,
['VIEW', 'revenue_chart_data', 'public']
);
await queryRunner.query(`
DROP VIEW "revenue_chart_data"
`);
}
}
Loading

0 comments on commit e6c7b60

Please sign in to comment.