Skip to content

Commit

Permalink
Add network mode for dkg services on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Jul 10, 2023
1 parent ac3b936 commit 4a4ab39
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion services/oracle/scripts/dev.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'os'
import { fetchRetry, run } from '@casimir/helpers'

const resourcePath = 'scripts/resources'
Expand All @@ -20,7 +21,11 @@ void async function () {
const cli = await run(`which ${process.env.CLI_PATH}`)
if (!cli) throw new Error('DKG CLI not found')

await run(`docker compose -f ${resourcePath}/rockx-dkg-cli/docker-compose.yaml -f ${resourcePath}/../docker-compose.override.yaml up -d`)
if (os.platform() === 'linux') {
await run(`docker compose -f ${resourcePath}/rockx-dkg-cli/docker-compose.yaml -f ${resourcePath}/../docker-compose.override.yaml up -d`)
} else {
await run(`docker compose -f ${resourcePath}/rockx-dkg-cli/docker-compose.yaml up -d`)
}
console.log('🔑 DKG service started')

const ping = await fetchRetry(`${process.env.MESSENGER_SRV_ADDR}/ping`)
Expand Down
9 changes: 9 additions & 0 deletions services/oracle/scripts/docker-compose.override.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
version: "3.7"
services:
messenger:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-1:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-2:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-3:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-4:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-5:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-6:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-7:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
operator-8:
network_mode: "host"
extra_hosts:
- "host.docker.internal:host-gateway"
19 changes: 6 additions & 13 deletions services/oracle/scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os from 'os'
import fs from 'fs'
import { ethers } from 'ethers'
import { fetchRetry, run } from '@casimir/helpers'
Expand All @@ -22,11 +23,9 @@ void async function () {
throw new Error('No VIEWS_ADDRESS set')
}

/** Get the oracle wallet address */
const wallet = ethers.Wallet.fromMnemonic(process.env.BIP39_SEED, 'm/44\'/60\'/0\'/0/6')
const oracleAddress = wallet.address

/** Create mock validators output path if it doesn't exist */
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath)
}
Expand All @@ -35,33 +34,29 @@ void async function () {
fs.writeFileSync(`${outputPath}/validators.json`, JSON.stringify({}))
}

/** Get the number of validators required */
const validatorCount = parseInt(process.env.VALIDATOR_COUNT as string) || 4

/** Read current mock validators file */
const validators = JSON.parse(fs.readFileSync(`${outputPath}/validators.json`, 'utf8') || '{}')

/** Check if the oracle has enough validators */
if (!validators[oracleAddress] || Object.keys(validators[oracleAddress]).length < validatorCount) {

/** Build and check if the CLI is available */
await run(`make -C ${resourcePath}/rockx-dkg-cli build`)
const cli = await run(`which ${process.env.CLI_PATH}`)
if (!cli) throw new Error('DKG CLI not found')

/** Start the DKG service */
await run(`docker compose -f ${resourcePath}/rockx-dkg-cli/docker-compose.yaml -f ${resourcePath}/../docker-compose.override.yaml up -d`)
if (os.platform() === 'linux') {
await run(`docker compose -f ${resourcePath}/rockx-dkg-cli/docker-compose.yaml -f ${resourcePath}/../docker-compose.override.yaml up -d`)
} else {
await run(`docker compose -f ${resourcePath}/rockx-dkg-cli/docker-compose.yaml up -d`)
}
console.log('🔑 DKG service started')

/** Ping the DGK service for a pong */
const ping = await fetchRetry(`${process.env.MESSENGER_SRV_ADDR}/ping`)
const { message } = await ping.json()
if (message !== 'pong') throw new Error('DKG service is not running')

/** Manager nonce for first validator starts at 3 after registry and upkeep */
let nonce = 3

/** Create requested count of validators */
const newValidators: Validator[] = []

for (let i = 0; i < validatorCount; i++) {
Expand All @@ -86,10 +81,8 @@ void async function () {

validators[oracleAddress] = newValidators

/** Write new validators to file */
fs.writeFileSync(`${outputPath}/validators.json`, JSON.stringify(validators, null, 4))

/** Stop the DKG service */
await run('npm run clean --workspace @casimir/oracle')
}
}()

0 comments on commit 4a4ab39

Please sign in to comment.