mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 12:35:51 +00:00
b3e57a37e2
* wire prover into node * stricter case object checks * return correct proof * misc renames * adding usefull traces * fix nodes and tolerance to match expected params * format challenges in logs * add circom compat to solidity groth16 convertion * update * bump time to give nodes time to load with all circom artifacts * misc * misc * use correct dataset geometry in erasure * make errors more searchable * use parens around `=? (await...)` calls * styling * styling * use push raises * fix to match constructor arguments * merge master * merge master * integration: fix proof parameters for a test Increased times due to ZK proof generation. Increased storage requirement because we're now hosting 5 slots instead of 1. * sales: calculate initial proof at start of period reason: this ensures that the period (and therefore the challenge) doesn't change while we're calculating the proof * integration: fix proof parameters for tests Increased times due to waiting on next period. Fixed data to be of right size. Updated expected payout due to hosting 5 slots. * sales: wait for stable proof challenge When the block pointer is nearing the wrap-around point, we wait another period before calculating a proof. * fix merge conflict --------- Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
92 lines
2.3 KiB
Nim
92 lines
2.3 KiB
Nim
import std/osproc
|
|
import std/os
|
|
import std/streams
|
|
import std/strutils
|
|
import pkg/codex/conf
|
|
import pkg/codex/logutils
|
|
import pkg/confutils
|
|
import pkg/libp2p
|
|
import pkg/questionable
|
|
import ./codexclient
|
|
|
|
export codexclient
|
|
|
|
const workingDir = currentSourcePath() / ".." / ".." / ".."
|
|
const executable = "build" / "codex"
|
|
|
|
type
|
|
NodeProcess* = ref object
|
|
process: Process
|
|
arguments: seq[string]
|
|
debug: bool
|
|
client: ?CodexClient
|
|
|
|
proc start(node: NodeProcess) =
|
|
if node.debug:
|
|
node.process = osproc.startProcess(
|
|
executable,
|
|
workingDir,
|
|
node.arguments,
|
|
options={poParentStreams}
|
|
)
|
|
else:
|
|
node.process = osproc.startProcess(
|
|
executable,
|
|
workingDir,
|
|
node.arguments
|
|
)
|
|
|
|
proc waitUntilOutput*(node: NodeProcess, output: string) =
|
|
if node.debug:
|
|
raiseAssert "cannot read node output when in debug mode"
|
|
for line in node.process.outputStream.lines:
|
|
if line.contains(output):
|
|
return
|
|
raiseAssert "node did not output '" & output & "'"
|
|
|
|
proc waitUntilStarted*(node: NodeProcess) =
|
|
if node.debug:
|
|
sleep(10_000)
|
|
else:
|
|
node.waitUntilOutput("Started codex node")
|
|
|
|
proc startNode*(args: openArray[string], debug: string | bool = false): NodeProcess =
|
|
## Starts a Codex Node with the specified arguments.
|
|
## Set debug to 'true' to see output of the node.
|
|
let node = NodeProcess(arguments: @args, debug: ($debug != "false"))
|
|
node.start()
|
|
node
|
|
|
|
proc dataDir(node: NodeProcess): string =
|
|
let config = CodexConf.load(cmdLine = node.arguments, quitOnFailure = false)
|
|
config.dataDir.string
|
|
|
|
proc apiUrl(node: NodeProcess): string =
|
|
let config = CodexConf.load(cmdLine = node.arguments, quitOnFailure = false)
|
|
"http://" & config.apiBindAddress & ":" & $config.apiPort & "/api/codex/v1"
|
|
|
|
proc client*(node: NodeProcess): CodexClient =
|
|
if client =? node.client:
|
|
return client
|
|
let client = CodexClient.new(node.apiUrl)
|
|
node.client = some client
|
|
client
|
|
|
|
proc stop*(node: NodeProcess) =
|
|
if node.process != nil:
|
|
node.process.terminate()
|
|
discard node.process.waitForExit(timeout=5_000)
|
|
node.process.close()
|
|
node.process = nil
|
|
if client =? node.client:
|
|
node.client = none CodexClient
|
|
client.close()
|
|
|
|
proc restart*(node: NodeProcess) =
|
|
node.stop()
|
|
node.start()
|
|
node.waitUntilStarted()
|
|
|
|
proc removeDataDir*(node: NodeProcess) =
|
|
removeDir(node.dataDir)
|