Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/silver-suns-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': minor
---

Integrate Handshake watcher
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/config/*.json
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚫 Required Change

Please revert this change.

config/local*.yaml
config/contracts*.json
config/tokens*.json
Expand Down
13 changes: 13 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ firo:
timeout: 10 # rpc request timeout (in seconds)
# username: '' # rpc username for authentication required instances
# password: '' # rpc password for authentication required instances
handshake:
type: 'rpc' # options: rpc
initial:
height: -1 # initial height of scanning
interval: 180 # scanning interval (in seconds)
rpc:
url: '' # rpc url
timeout: 10 # rpc request timeout (in seconds)
# username: '' # rpc username for authentication required instances
# password: '' # rpc password for authentication required instances
ergo:
network: 'Mainnet' # ergo network type. testnet or mainnet
type: 'node' # ergo scanner type. options: node, explorer
Expand Down Expand Up @@ -147,6 +157,9 @@ healthCheck:
scanner:
warnDifference: 5 # warning difference between existing and scanned blocks height
criticalDifference: 20 # critical difference between existing and scanned blocks height
handshakeScanner:
warnDifference: 2 # warning difference between existing and scanned blocks height
criticalDifference: 10 # critical difference between existing and scanned blocks height
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚫 Required Change

Please remove these configs.

permit:
warnCommitmentCount: 4 # warning remaining permits for creating commitment
criticalCommitmentCount: 0 # critical remaining permits for creating commitment
Expand Down
4 changes: 4 additions & 0 deletions docker/custom-environment-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ firo:
rpc:
username: 'FIRO_RPC_USERNAME'
password: 'FIRO_RPC_PASSWORD'
handshake:
rpc:
username: 'HANDSHAKE_RPC_USERNAME'
password: 'HANDSHAKE_RPC_PASSWORD'
overrideLokiBasicAuth: 'OVERRIDE_LOKI_BASIC_AUTH'
80 changes: 64 additions & 16 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ErgoNetworkType } from '@rosen-bridge/scanner-interfaces';
import { TransportOptions } from '@rosen-bridge/winston-logger';
import { RateLimitedAxiosConfig } from '@rosen-clients/rate-limited-axios';
import { generateMnemonic } from 'bip39';
import config from 'config';
import * as wasm from 'ergo-lib-wasm-nodejs';
import { SecretError } from '../errors/errors';
import * as Constants from './constants';
import { RosenConfig } from './rosenConfig';
import { cloneDeep } from 'lodash-es';
import { SecretError } from '../errors/errors';
import { NetworkType } from '../types';
import { generateMnemonic } from 'bip39';
import { convertMnemonicToSecretKey } from '../utils/utils';
import { ErgoNetworkType } from '@rosen-bridge/scanner-interfaces';
import { TransportOptions } from '@rosen-bridge/winston-logger';
import { RateLimitedAxiosConfig } from '@rosen-clients/rate-limited-axios';
import * as Constants from './constants';
import { RosenConfig } from './rosenConfig';

const supportedNetworks: Array<NetworkType> = [
Constants.ERGO_CHAIN_NAME,
Expand All @@ -19,6 +19,7 @@ const supportedNetworks: Array<NetworkType> = [
Constants.DOGE_CHAIN_NAME,
Constants.ETHEREUM_CHAIN_NAME,
Constants.BINANCE_CHAIN_NAME,
Constants.HANDSHAKE_CHAIN_NAME,
Constants.FIRO_CHAIN_NAME,
];

Expand All @@ -31,6 +32,7 @@ interface ConfigType {
binance: BinanceConfig;
firo: FiroConfig;
doge: DogeConfig;
handshake: HandshakeConfig;
general: Config;
rosen: RosenConfig;
database: DatabaseConfig;
Expand Down Expand Up @@ -230,7 +232,7 @@ class Config {
this.observationConfirmation = getRequiredNumber(
'observation.confirmation'
);
const blockTime = {
const blockTimeByNetwork: Record<NetworkType, number> = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚫 Required Change

Revert this change (please avoid unnecessary changes). Adding the new record is sufficient here.

[Constants.ERGO_CHAIN_NAME]: Constants.ERGO_BLOCK_TIME,
[Constants.BITCOIN_CHAIN_NAME]: Constants.BITCOIN_BLOCK_TIME,
[Constants.BITCOIN_RUNES_CHAIN_NAME]: Constants.BITCOIN_BLOCK_TIME,
Expand All @@ -239,9 +241,11 @@ class Config {
[Constants.ETHEREUM_CHAIN_NAME]: Constants.ETHEREUM_BLOCK_TIME,
[Constants.DOGE_CHAIN_NAME]: Constants.DOGE_BLOCK_TIME,
[Constants.FIRO_CHAIN_NAME]: Constants.FIRO_BLOCK_TIME,
}[this.networkWatcher];
[Constants.HANDSHAKE_CHAIN_NAME]: Constants.HANDSHAKE_BLOCK_TIME,
};
this.observationValidThreshold = Math.floor(
getRequiredNumber('observation.validThreshold') / blockTime
getRequiredNumber('observation.validThreshold') /
blockTimeByNetwork[this.networkWatcher]
);
this.observationStoreRawData = config.get<boolean>(
'observation.storeRawData'
Expand Down Expand Up @@ -639,6 +643,37 @@ class FiroConfig {
}
}

class HandshakeConfig {
type: string;
initialHeight: number;
interval: number;
rpc?: {
url: string;
timeout: number;
username?: string;
password?: string;
};

constructor(network: string) {
this.type = config.get<string>('handshake.type');
if (network === Constants.HANDSHAKE_CHAIN_NAME) {
this.initialHeight = getRequiredNumber('handshake.initial.height');
this.interval = getRequiredNumber('handshake.interval');
if (this.type == Constants.RPC_TYPE) {
const url = getRequiredString('handshake.rpc.url');
const timeout = getRequiredNumber('handshake.rpc.timeout');
const username = getOptionalString('handshake.rpc.username', undefined);
const password = getOptionalString('handshake.rpc.password', undefined);
this.rpc = { url, timeout, username, password };
} else {
throw new Error(
`Improperly configured. handshake configuration type is invalid available choices are '${Constants.RPC_TYPE}'`
);
}
}
}
}

class DatabaseConfig {
type: string;
path = '';
Expand Down Expand Up @@ -699,6 +734,8 @@ class HealthCheckConfig {
ergCriticalThreshold: bigint;
scannerWarnDiff: number;
scannerCriticalDiff: number;
handshakeScannerWarnDiff: number;
handshakeScannerCriticalDiff: number;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚫 Required Change

Please remove these 2 variables.

permitWarnCommitmentCount: number;
permitCriticalCommitmentCount: number;
permitDefaultCommitmentRWT: number;
Expand All @@ -720,6 +757,14 @@ class HealthCheckConfig {
this.scannerCriticalDiff = getRequiredNumber(
'healthCheck.scanner.criticalDifference'
);
this.handshakeScannerWarnDiff = getOptionalNumber(
'healthCheck.handshakeScanner.warnDifference',
this.scannerWarnDiff
);
this.handshakeScannerCriticalDiff = getOptionalNumber(
'healthCheck.handshakeScanner.criticalDifference',
this.scannerCriticalDiff
);
this.permitWarnCommitmentCount = getRequiredNumber(
'healthCheck.permit.warnCommitmentCount'
);
Expand Down Expand Up @@ -749,6 +794,7 @@ const getConfig = (): ConfigType => {
const doge = new DogeConfig(general.networkWatcher);
const ethereum = new EthereumConfig(general.networkWatcher);
const binance = new BinanceConfig(general.networkWatcher);
const handshake = new HandshakeConfig(general.networkWatcher);
const firo = new FiroConfig(general.networkWatcher);
const rosen = new RosenConfig(
general.networkWatcher,
Expand All @@ -764,6 +810,7 @@ const getConfig = (): ConfigType => {
doge,
ethereum,
binance,
handshake,
firo,
logger,
general,
Expand All @@ -777,14 +824,15 @@ const getConfig = (): ConfigType => {
};

export {
getConfig,
Config,
RosenConfig,
CardanoConfig,
BinanceConfig,
BitcoinConfig,
BitcoinRunesConfig,
CardanoConfig,
Config,
DogeConfig,
EthereumConfig,
BinanceConfig,
FiroConfig,
DogeConfig,
getConfig,
HandshakeConfig,
RosenConfig,
};
2 changes: 2 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const BITCOIN_RUNES_CHAIN_NAME = 'bitcoin-runes';
export const DOGE_CHAIN_NAME = 'doge';
export const ETHEREUM_CHAIN_NAME = 'ethereum';
export const BINANCE_CHAIN_NAME = 'binance';
export const HANDSHAKE_CHAIN_NAME = 'handshake';
export const FIRO_CHAIN_NAME = 'firo';
export const ERGO_NATIVE_ASSET = 'erg';
export const ERGO_DECIMALS = 9;
Expand All @@ -34,6 +35,7 @@ export const CARDANO_BLOCK_TIME = 20;
export const ERGO_BLOCK_TIME = 120;
export const ETHEREUM_BLOCK_TIME = 12;
export const DOGE_BLOCK_TIME = 60;
export const HANDSHAKE_BLOCK_TIME = 600;
export const FIRO_BLOCK_TIME = 150;
export const UNISAT_TYPE = 'unisat';
export const ORDISCAN_TYPE = 'ordiscan';
13 changes: 10 additions & 3 deletions src/jobs/initScanner.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DefaultLogger } from '@rosen-bridge/abstract-logger';
import { GeneralScanner } from '@rosen-bridge/abstract-scanner';
import { CardanoOgmiosScanner } from '@rosen-bridge/cardano-scanner';
import * as Constants from '../config/constants';
import { getConfig } from '../config/config';
import { DefaultLogger } from '@rosen-bridge/abstract-logger';
import { EvmRpcScanner } from '@rosen-bridge/evm-scanner';
import { getConfig } from '../config/config';
import * as Constants from '../config/constants';
import { CreateScanner } from '../utils/scanner';

const allConfig = getConfig();
Expand All @@ -15,6 +15,7 @@ const {
doge: dogeConfig,
ethereum: ethereumConfig,
binance: binanceConfig,
handshake: handshakeConfig,
firo: firoConfig,
} = allConfig;

Expand Down Expand Up @@ -87,6 +88,12 @@ export const scannerInit = () => {
scanner.getObservationScanner() as GeneralScanner<unknown>
).then(() => null);
break;
case Constants.HANDSHAKE_CHAIN_NAME:
scanningJob(
handshakeConfig.interval,
scanner.getObservationScanner() as GeneralScanner<unknown>
).then(() => null);
break;
case Constants.ERGO_CHAIN_NAME:
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type NetworkType =
| typeof Constants.DOGE_CHAIN_NAME
| typeof Constants.ETHEREUM_CHAIN_NAME
| typeof Constants.BINANCE_CHAIN_NAME
| typeof Constants.FIRO_CHAIN_NAME;
| typeof Constants.FIRO_CHAIN_NAME
| typeof Constants.HANDSHAKE_CHAIN_NAME;

export { NetworkType };
Loading