cleans up previous downloader implementation
This commit is contained in:
parent
4847155646
commit
571d01c82d
|
@ -24,7 +24,6 @@ import pkg/stew/shims/net as stewnet
|
|||
import pkg/datastore
|
||||
import pkg/ethers except Rng
|
||||
import pkg/stew/io2
|
||||
import pkg/questionable
|
||||
import pkg/taskpools
|
||||
|
||||
import ./node
|
||||
|
@ -72,7 +71,7 @@ proc waitForSync(provider: Provider): Future[void] {.async.} =
|
|||
trace "Ethereum provider is synced."
|
||||
|
||||
proc bootstrapInteractions(
|
||||
s: CodexServer): Future[?string] {.async.} =
|
||||
s: CodexServer): Future[void] {.async.} =
|
||||
## bootstrap interactions and return contracts
|
||||
## using clients, hosts, validators pairings
|
||||
##
|
||||
|
@ -145,7 +144,6 @@ proc bootstrapInteractions(
|
|||
validator = some ValidatorInteractions.new(clock, validation)
|
||||
|
||||
s.codexNode.contracts = (client, host, validator)
|
||||
return await market.getZkeyHash()
|
||||
|
||||
proc start*(s: CodexServer) {.async.} =
|
||||
trace "Starting codex node", config = $s.config
|
||||
|
@ -180,10 +178,10 @@ proc start*(s: CodexServer) {.async.} =
|
|||
s.codexNode.discovery.updateAnnounceRecord(announceAddrs)
|
||||
s.codexNode.discovery.updateDhtRecord(s.config.nat, s.config.discoveryPort)
|
||||
|
||||
let proofCeremonyUrl = await s.bootstrapInteractions()
|
||||
await s.bootstrapInteractions()
|
||||
|
||||
if prover =? s.codexNode.prover:
|
||||
if err =? (await prover.start(s.config, proofCeremonyUrl)).errorOption:
|
||||
if err =? (await prover.start(s.config)).errorOption:
|
||||
error "Failed to start prover", msg = err.msg
|
||||
return # should we abort start-up this way?
|
||||
|
||||
|
|
|
@ -39,10 +39,7 @@ proc wasmFilePath(config: CodexConf): string =
|
|||
proc zkeyFilePath(config: CodexConf): string =
|
||||
config.circuitDir / "proof_main.zkey"
|
||||
|
||||
proc zipFilePath(config: CodexConf): string =
|
||||
config.circuitDir / "circuit.zip"
|
||||
|
||||
proc initializeFromCeremonyFiles(
|
||||
proc initializeFromCircuitDirFiles(
|
||||
config: CodexConf,
|
||||
utils: BackendUtils): ?!AnyBackend =
|
||||
if fileExists(config.r1csFilePath) and
|
||||
|
@ -56,54 +53,21 @@ proc initializeFromCeremonyFiles(
|
|||
|
||||
failure("Ceremony files not found")
|
||||
|
||||
proc downloadCeremony(
|
||||
config: CodexConf,
|
||||
ceremonyHash: string,
|
||||
utils: BackendUtils
|
||||
): ?!void =
|
||||
# TODO:
|
||||
# In the future, the zip file will be stored in the Codex network
|
||||
# instead of a url + ceremonyHash, we'll get a CID from the marketplace contract.
|
||||
|
||||
let url = "https://circuit.codex.storage/proving-key/" & ceremonyHash
|
||||
trace "Downloading ceremony file", url, filepath = config.zipFilePath
|
||||
return utils.downloadFile(url, config.zipFilePath)
|
||||
|
||||
proc unzipCeremonyFile(
|
||||
config: CodexConf,
|
||||
utils: BackendUtils): ?!void =
|
||||
trace "Unzipping..."
|
||||
return utils.unzipFile(config.zipFilePath, $config.circuitDir)
|
||||
|
||||
proc initializeFromCeremonyHash(
|
||||
config: CodexConf,
|
||||
ceremonyHash: ?string,
|
||||
utils: BackendUtils): Future[?!AnyBackend] {.async.} =
|
||||
|
||||
if hash =? ceremonyHash:
|
||||
if dlErr =? downloadCeremony(config, hash, utils).errorOption:
|
||||
return failure(dlErr)
|
||||
if err =? unzipCeremonyFile(config, utils).errorOption:
|
||||
return failure(err)
|
||||
without backend =? initializeFromCeremonyFiles(config, utils), err:
|
||||
return failure(err)
|
||||
return success(backend)
|
||||
else:
|
||||
return failure("Ceremony URL not found")
|
||||
proc suggestDownloadTool() =
|
||||
error "TODO: We need to tell the user how to run the download tool. " &
|
||||
"So probably say './cirdl [circuitDir] [rpcEndpoint] [marketplaceAddress]' " &
|
||||
"but with the correct values already filled in."
|
||||
|
||||
proc initializeBackend*(
|
||||
config: CodexConf,
|
||||
ceremonyHash: ?string,
|
||||
utils: BackendUtils = BackendUtils()): Future[?!AnyBackend] {.async.} =
|
||||
|
||||
without backend =? initializeFromConfig(config, utils), cliErr:
|
||||
info "Could not initialize prover backend from CLI options...", msg = cliErr.msg
|
||||
without backend =? initializeFromCeremonyFiles(config, utils), localErr:
|
||||
info "Could not initialize prover backend from local files...", msg = localErr.msg
|
||||
without backend =? (await initializeFromCeremonyHash(config, ceremonyHash, utils)), urlErr:
|
||||
warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg
|
||||
return failure(urlErr)
|
||||
# Unexpected: value of backend does not survive leaving each scope. (definition does though...)
|
||||
return success(backend)
|
||||
without backend =? initializeFromCircuitDirFiles(config, utils), localErr:
|
||||
info "Could not initialize prover backend from circuit dir files...", msg = localErr.msg
|
||||
suggestDownloadTool()
|
||||
return failure("CircuitFilesNotFound")
|
||||
# Unexpected: value of backend does not survive leaving each scope. (definition does though...)
|
||||
return success(backend)
|
||||
return success(backend)
|
||||
|
|
|
@ -1,10 +1,3 @@
|
|||
import os
|
||||
import zip/zipfiles
|
||||
import pkg/chronos
|
||||
import pkg/chronicles
|
||||
import pkg/questionable
|
||||
import pkg/questionable/results
|
||||
|
||||
import ./backends
|
||||
|
||||
type
|
||||
|
@ -17,29 +10,3 @@ method initializeCircomBackend*(
|
|||
zKeyFile: string
|
||||
): AnyBackend {.base.} =
|
||||
CircomCompat.init(r1csFile, wasmFile, zKeyFile)
|
||||
|
||||
method downloadFile*(
|
||||
self: BackendUtils,
|
||||
url: string,
|
||||
filepath: string
|
||||
): ?!void {.base.} =
|
||||
try:
|
||||
# Nim's default webclient does not support SSL on all platforms.
|
||||
# Not without shipping additional binaries and cert-files... :(
|
||||
# So we're using curl for now.
|
||||
var rc = execShellCmd("curl -o " & filepath & " " & url)
|
||||
if not rc == 0:
|
||||
return failure("Download of '" & url & "' failed with return code: " & $rc)
|
||||
except Exception as exc:
|
||||
return failure(exc.msg)
|
||||
success()
|
||||
|
||||
method unzipFile*(
|
||||
self: BackendUtils,
|
||||
zipFile: string,
|
||||
outputDir: string): ?!void {.base.} =
|
||||
var z: ZipArchive
|
||||
if not z.open(zipFile):
|
||||
return failure("Unable to open zip file: " & zipFile)
|
||||
z.extractAll(outputDir)
|
||||
success()
|
||||
|
|
|
@ -98,10 +98,9 @@ proc verify*(
|
|||
|
||||
proc start*(
|
||||
self: Prover,
|
||||
config: CodexConf,
|
||||
ceremonyHash: ?string): Future[?!void] {.async.} =
|
||||
config: CodexConf): Future[?!void] {.async.} =
|
||||
|
||||
without backend =? (await initializeBackend(config, ceremonyHash)), err:
|
||||
without backend =? (await initializeBackend(config)), err:
|
||||
error "Failed to initialize backend", msg = err.msg
|
||||
return failure(err)
|
||||
|
||||
|
|
Loading…
Reference in New Issue