Skip to content

Commit

Permalink
Merge branch '256-ethereum-health-check' into 'dev'
Browse files Browse the repository at this point in the history
Add ethereum health params

Closes #256

See merge request ergo/rosen-bridge/watcher!303
  • Loading branch information
vorujack committed Sep 27, 2024
2 parents d02303c + d7078ff commit 99c280c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-ants-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': minor
---

Add ethereum health check parameters
3 changes: 3 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ healthCheck:
bitcoinScanner:
warnDifference: 2 # warning difference between existing and scanned blocks height
criticalDifference: 10 # critical difference between existing and scanned blocks height
ethereumScanner:
warnDifference: 40 # warning difference between existing and scanned blocks height
criticalDifference: 160 # critical difference between existing and scanned blocks height
permit:
warnCommitmentCount: 4 # warning remaining permits for creating commitment
criticalCommitmentCount: 0 # critical remaining permits for creating commitment
Expand Down
8 changes: 8 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ class HealthCheckConfig {
cardanoScannerCriticalDiff: number;
bitcoinScannerWarnDiff: number;
bitcoinScannerCriticalDiff: number;
ethereumScannerWarnDiff: number;
ethereumScannerCriticalDiff: number;
ergoNodeMaxHeightDiff: number;
ergoNodeMaxBlockTime: number;
ergoNodeMinPeerCount: number;
Expand Down Expand Up @@ -564,6 +566,12 @@ class HealthCheckConfig {
this.bitcoinScannerCriticalDiff = getRequiredNumber(
'healthCheck.bitcoinScanner.criticalDifference'
);
this.ethereumScannerWarnDiff = getRequiredNumber(
'healthCheck.ethereumScanner.warnDifference'
);
this.ethereumScannerCriticalDiff = getRequiredNumber(
'healthCheck.ethereumScanner.criticalDifference'
);
this.permitWarnCommitmentCount = getRequiredNumber(
'healthCheck.permit.warnCommitmentCount'
);
Expand Down
21 changes: 21 additions & 0 deletions src/utils/healthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ErgoNodeScannerHealthCheck,
BitcoinEsploraScannerHealthCheck,
BitcoinRPCScannerHealthCheck,
EthereumRPCScannerHealthCheck,
} from '@rosen-bridge/scanner-sync-check';
import {
ExplorerWidHealthCheckParam,
Expand All @@ -35,6 +36,7 @@ import {
ERGO_DECIMALS,
ERGO_NATIVE_ASSET,
ESPLORA_TYPE,
ETHEREUM_CHAIN_NAME,
EXPLORER_TYPE,
KOIOS_TYPE,
NODE_TYPE,
Expand Down Expand Up @@ -108,6 +110,9 @@ class HealthCheckSingleton {
if (getConfig().general.networkWatcher === BITCOIN_CHAIN_NAME) {
this.registerBitcoinHealthCheckParams();
}
if (getConfig().general.networkWatcher === ETHEREUM_CHAIN_NAME) {
this.registerEthereumHealthCheckParams();
}
}

private observingNetworkLastBlock = (scanner: string) => {
Expand Down Expand Up @@ -250,6 +255,22 @@ class HealthCheckSingleton {
this.healthCheck.register(bitcoinScannerSyncCheck);
};

/**
* Registers all ethereum check params
*/
registerEthereumHealthCheckParams = () => {
const ethereumRpcScannerSyncCheck = new EthereumRPCScannerHealthCheck(
this.observingNetworkLastBlock(scanner.observationScanner.name()),
scanner.observationScanner.name(),
getConfig().healthCheck.ethereumScannerWarnDiff,
getConfig().healthCheck.ethereumScannerCriticalDiff,
getConfig().ethereum.rpc!.url,
getConfig().ethereum.rpc!.authToken,
getConfig().ethereum.rpc!.timeout
);
this.healthCheck.register(ethereumRpcScannerSyncCheck);
};

/**
* Registers permit check if watcher wid exists
*/
Expand Down

0 comments on commit 99c280c

Please sign in to comment.