-
Notifications
You must be signed in to change notification settings - Fork 8
Initial Handshake Implementation #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 5 commits
d128cac
b2248f1
194b5e5
caea517
658b96f
b6be728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rosen-bridge/watcher': minor | ||
| --- | ||
|
|
||
| Integrate Handshake watcher |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| src/config/*.json | ||
| config/local*.yaml | ||
| config/contracts*.json | ||
| config/tokens*.json | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| 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, | ||
|
|
@@ -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, | ||
| ]; | ||
|
|
||
|
|
@@ -31,6 +32,7 @@ interface ConfigType { | |
| binance: BinanceConfig; | ||
| firo: FiroConfig; | ||
| doge: DogeConfig; | ||
| handshake: HandshakeConfig; | ||
| general: Config; | ||
| rosen: RosenConfig; | ||
| database: DatabaseConfig; | ||
|
|
@@ -230,7 +232,7 @@ class Config { | |
| this.observationConfirmation = getRequiredNumber( | ||
| 'observation.confirmation' | ||
| ); | ||
| const blockTime = { | ||
| const blockTimeByNetwork: Record<NetworkType, number> = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
@@ -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' | ||
|
|
@@ -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 = ''; | ||
|
|
@@ -699,6 +734,8 @@ class HealthCheckConfig { | |
| ergCriticalThreshold: bigint; | ||
| scannerWarnDiff: number; | ||
| scannerCriticalDiff: number; | ||
| handshakeScannerWarnDiff: number; | ||
| handshakeScannerCriticalDiff: number; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
@@ -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' | ||
| ); | ||
|
|
@@ -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, | ||
|
|
@@ -764,6 +810,7 @@ const getConfig = (): ConfigType => { | |
| doge, | ||
| ethereum, | ||
| binance, | ||
| handshake, | ||
| firo, | ||
| logger, | ||
| general, | ||
|
|
@@ -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, | ||
| }; | ||
There was a problem hiding this comment.
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.