Extracts backend initialization to backend-factory
This commit is contained in:
parent
63ab4c5064
commit
83e1347038
|
@ -0,0 +1,44 @@
|
|||
import pkg/chronos
|
||||
import pkg/questionable
|
||||
import pkg/confutils/defs
|
||||
|
||||
import ../../conf
|
||||
import ./backends
|
||||
|
||||
proc initializeFromConfig(
|
||||
config: CodexConf): ?!AnyBackend =
|
||||
|
||||
# check provided files exist
|
||||
# initialize backend with files
|
||||
# or failure
|
||||
|
||||
success(CircomCompat.init($config.circomR1cs, $config.circomWasm, $config.circomZkey))
|
||||
|
||||
proc initializeFromCeremonyFiles(): ?!AnyBackend =
|
||||
|
||||
# initialize from previously-downloaded files if they exist
|
||||
echo "todo"
|
||||
failure("todo")
|
||||
|
||||
proc initializeFromCeremonyUrl(
|
||||
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
|
||||
|
||||
# download the ceremony url
|
||||
# unzip it
|
||||
|
||||
without backend =? initializeFromCeremonyFiles(), err:
|
||||
return failure(err)
|
||||
return success(backend)
|
||||
|
||||
proc initializeBackend*(
|
||||
config: CodexConf,
|
||||
proofCeremonyUrl: ?string): Future[?!AnyBackend] {.async.} =
|
||||
|
||||
without backend =? initializeFromConfig(config), cliErr:
|
||||
info "Could not initialize prover backend from CLI options...", msg = cliErr.msg
|
||||
without backend =? initializeFromCeremonyFiles(), localErr:
|
||||
info "Could not initialize prover backend from local files...", msg = localErr.msg
|
||||
without backend =? (await initializeFromCeremonyUrl(proofCeremonyUrl)), urlErr:
|
||||
warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg
|
||||
return failure(urlErr)
|
||||
return success(backend)
|
|
@ -1,3 +1,6 @@
|
|||
import ./backends/circomcompat
|
||||
|
||||
export circomcompat
|
||||
|
||||
type
|
||||
AnyBackend* = CircomCompat
|
||||
|
|
|
@ -13,7 +13,6 @@ import pkg/chronicles
|
|||
import pkg/circomcompat
|
||||
import pkg/poseidon2
|
||||
import pkg/questionable/results
|
||||
import pkg/confutils/defs
|
||||
|
||||
import pkg/libp2p/cid
|
||||
|
||||
|
@ -28,6 +27,7 @@ import ../builder
|
|||
import ../sampler
|
||||
|
||||
import ./backends
|
||||
import ./backendfactory
|
||||
import ../types
|
||||
|
||||
export backends
|
||||
|
@ -36,7 +36,6 @@ logScope:
|
|||
topics = "codex prover"
|
||||
|
||||
type
|
||||
AnyBackend* = CircomCompat
|
||||
AnyProof* = CircomProof
|
||||
|
||||
AnySampler* = Poseidon2Sampler
|
||||
|
@ -97,43 +96,16 @@ proc verify*(
|
|||
else:
|
||||
return failure("Prover was not started")
|
||||
|
||||
proc initializeFromConfig(
|
||||
self: Prover,
|
||||
config: CodexConf): ?!void =
|
||||
|
||||
# check provided files exist
|
||||
# initialize backend with files
|
||||
# or failure
|
||||
|
||||
self.backend = some CircomCompat.init($config.circomR1cs, $config.circomWasm, $config.circomZkey)
|
||||
success()
|
||||
|
||||
proc initializeFromCeremonyFiles(
|
||||
self: Prover): ?!void =
|
||||
|
||||
# initialize from previously-downloaded files if they exist
|
||||
echo "todo"
|
||||
success()
|
||||
|
||||
proc initializeFromCeremonyUrl(
|
||||
self: Prover,
|
||||
proofCeremonyUrl: ?string): Future[?!void] {.async.} =
|
||||
|
||||
# download the ceremony url
|
||||
# unzip it
|
||||
return self.initializeFromCeremonyFiles()
|
||||
|
||||
proc start*(
|
||||
self: Prover,
|
||||
config: CodexConf,
|
||||
proofCeremonyUrl: ?string): Future[?!void] {.async.} =
|
||||
if cliErr =? self.initializeFromConfig(config).errorOption:
|
||||
info "Could not initialize prover backend from CLI options...", msg = cliErr.msg
|
||||
if localErr =? self.initializeFromCeremonyFiles().errorOption:
|
||||
info "Could not initialize prover backend from local files...", msg = localErr.msg
|
||||
if urlErr =? (await self.initializeFromCeremonyUrl(proofCeremonyUrl)).errorOption:
|
||||
warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg
|
||||
return failure(urlErr)
|
||||
|
||||
without backend =? (await initializeBackend(config, proofCeremonyUrl)), err:
|
||||
error "Failed to initialize backend", msg = err.msg
|
||||
return failure(err)
|
||||
|
||||
self.backend = some backend
|
||||
return success()
|
||||
|
||||
proc new*(
|
||||
|
|
Loading…
Reference in New Issue