Skip to content

Commit

Permalink
feat(okp4 devnet): passes test
Browse files Browse the repository at this point in the history
- weirdness around string replacements:
  - work with shelling out to perl
  - node's readFileSync can't find the same file
  - log filter eats useful output?
  • Loading branch information
egasimus committed Oct 12, 2023
1 parent 0194fc8 commit 43206f8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
45 changes: 37 additions & 8 deletions devnets/devnet.init.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from 'node:process'
import { env, getuid } from 'node:process'
import { spawn, exec, execSync } from 'node:child_process'
import { existsSync, writeFileSync, chmodSync } from 'node:fs'
import { existsSync, readFileSync, writeFileSync, chmodSync } from 'node:fs'

const {
VERBOSE = false,
Expand Down Expand Up @@ -40,8 +40,15 @@ function start () {

function spawnLcp () {
console.info('Configuring the node to support lcp (CORS proxy)...')
run(`perl -i -pe 's;address = "tcp://0.0.0.0:1317";address = "tcp://0.0.0.0:1316";' ${appToml}`)
run(`perl -i -pe 's/enable-unsafe-cors = false/enable-unsafe-cors = true/' ${appToml}`)
if (DAEMON === 'secretd') {
//let appTomlData = readFileSync(appToml)
run(`perl -i -pe 's;address = "tcp://0.0.0.0:1317";address = "tcp://0.0.0.0:1316";' ${appToml}`)
run(`perl -i -pe 's/enable-unsafe-cors = false/enable-unsafe-cors = true/' ${appToml}`)
}
//let appTomlData = readFileSync(appToml)
//appTomlData = appTomlData.replace('address = "tcp://0.0.0.0:1317"', 'address = "tcp://0.0.0.0:1316')
//appTomlData = appTomlData.replace('enable-unsafe-cors = false', 'enable-unsafe-cors = false')
//writeFileSync(appToml, appTomlData)
const lcpArgs = [
`--proxyUrl`, 'http://localhost:1316',
`--port`, LCP_PORT,
Expand All @@ -54,12 +61,26 @@ function spawnLcp () {

function launchNode () {
console.info('Launching the node...')
const command = `source /opt/sgxsdk/environment && RUST_BACKTRACE=1 ${DAEMON} start --bootstrap`
let command
if (DAEMON === 'secretd') {
command = `source /opt/sgxsdk/environment && RUST_BACKTRACE=1 ${DAEMON} start --bootstrap`
+ ` --rpc.laddr ${RPC_ADDR}`
+ ` --grpc.address ${GRPC_ADDR}`
+ ` --grpc-web.address ${GRPC_WEB_ADDR}`
} else {
command = `${DAEMON} start`
}
command += ''
+ ` --rpc.laddr ${RPC_ADDR}`
+ ` --grpc.address ${GRPC_ADDR}`
+ ` --grpc-web.address ${GRPC_WEB_ADDR}`
console.info(`$`, command)
execSync(command, { shell: '/bin/bash', stdio: 'inherit' })
try {
execSync(command, { shell: '/bin/bash', stdio: 'inherit' })
} catch (e) {
console.log('ERROR:', e.message)
process.exit(1)
}
}

function performGenesis () {
Expand All @@ -78,7 +99,10 @@ function performGenesis () {

function preGenesisCleanup () {
console.info('\nEnsuring a clean slate...')
run(`rm -rf ${daemonDir} ~/.secretcli /opt/secret/.sgx-secrets`)
run(`rm -rf ${daemonDir}`)
if (DAEMON === 'secretd') {
run(`~/.secretcli /opt/secret/.sgx-secrets`)
}
}

function preGenesisConfig () {
Expand All @@ -91,6 +115,7 @@ function preGenesisConfig () {
if (DAEMON === 'secretd') {
run(`cp ~/node_key.json ${nodeKey}`)
}
console.log('Patching', genesis)
run(`perl -i -pe 's/"stake"/ "${TOKEN}"/g' ${genesis}`)
}

Expand All @@ -116,7 +141,11 @@ function bootstrapChain () {
console.info('\nBootstrapping chain...')
daemon(`collect-gentxs`)
daemon(`validate-genesis`)
daemon(`init-bootstrap`)
if (DAEMON === 'secretd') {
daemon(`init-bootstrap`)
}/* else {
daemon(`init ${CHAIN_ID}`)
}*/
daemon(`validate-genesis`)
}

Expand Down
2 changes: 1 addition & 1 deletion devnets/okp4_5_0.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM okp4/okp4d:5.0.0@sha256:b197462e61c068ea094ec9b5693c88c2850606f9eaf53fcbe08a0aa4f6ff90b9
#RUN okp4d init fadroma-devnet --chain-id fadroma-devnet-okp4-v5.0
RUN apk add nodejs
RUN apk add nodejs perl bash
ENTRYPOINT [ "/usr/bin/node" ]
ADD devnet.init.mjs /
CMD [ "/devnet.init.mjs" ]
2 changes: 1 addition & 1 deletion fadroma-devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class Devnet implements DevnetHandle {
'scrt_1.7': 'indexed block',
'scrt_1.8': 'Done verifying block height',
'scrt_1.9': 'Validating proposal',
'okp4_5.0': 'NOT KNOWN YET',
'okp4_5.0': 'indexed block',
}

static daemonBinary: Record<DevnetPlatform, string> = {
Expand Down

0 comments on commit 43206f8

Please sign in to comment.