Review comments by Dmitriy, part 1

This commit is contained in:
Ben 2024-08-26 10:39:29 +02:00
parent f08a28c101
commit bdb5eefa7e
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
6 changed files with 22 additions and 13 deletions

View File

@ -272,7 +272,10 @@ proc new*(
engine = BlockExcEngine.new(repoStore, wallet, network, blockDiscovery, peerStore, pendingBlocks) engine = BlockExcEngine.new(repoStore, wallet, network, blockDiscovery, peerStore, pendingBlocks)
store = NetworkStore.new(engine, repoStore) store = NetworkStore.new(engine, repoStore)
prover = if config.prover: prover = if config.prover:
some Prover.new(store, config).expect("Unable to create prover.") let
backendFactory = BackendFactory()
backend = backendFactory.initializeBackend(config).expect("Unable to create prover backend.")
some Prover.new(store, backend, config)
else: else:
none Prover none Prover

View File

@ -1,4 +1,5 @@
import ./proofs/backends import ./proofs/backends
import ./proofs/prover import ./proofs/prover
import ./proofs/backendfactory
export circomcompat, prover export circomcompat, prover, backendfactory

View File

@ -11,6 +11,9 @@ import ../../conf
import ./backends import ./backends
import ./backendutils import ./backendutils
type
BackendFactory* = object of RootObj
proc initializeFromConfig( proc initializeFromConfig(
config: CodexConf, config: CodexConf,
utils: BackendUtils): ?!AnyBackend = utils: BackendUtils): ?!AnyBackend =
@ -70,6 +73,7 @@ proc suggestDownloadTool(config: CodexConf) =
echo "'./" & tokens.join(" ") & "'" echo "'./" & tokens.join(" ") & "'"
proc initializeBackend*( proc initializeBackend*(
self: BackendFactory,
config: CodexConf, config: CodexConf,
utils: BackendUtils = BackendUtils()): ?!AnyBackend = utils: BackendUtils = BackendUtils()): ?!AnyBackend =

View File

@ -92,13 +92,10 @@ proc verify*(
proc new*( proc new*(
_: type Prover, _: type Prover,
store: BlockStore, store: BlockStore,
config: CodexConf): ?!Prover = backend: AnyBackend,
config: CodexConf): Prover =
without backend =? initializeBackend(config), err: Prover(
error "Failed to initialize backend", msg = err.msg
return failure(err)
success Prover(
store: store, store: store,
backend: backend, backend: backend,
nSamples: config.numProofSamples) nSamples: config.numProofSamples)

View File

@ -36,6 +36,7 @@ suite "Test BackendFactory":
let let
utilsMock = BackendUtilsMock() utilsMock = BackendUtilsMock()
circuitDir = "testecircuitdir" circuitDir = "testecircuitdir"
factory = BackendFactory()
setup: setup:
createDir(circuitDir) createDir(circuitDir)
@ -56,7 +57,7 @@ suite "Test BackendFactory":
circomWasm: InputFile("tests/circuits/fixtures/proof_main.wasm"), circomWasm: InputFile("tests/circuits/fixtures/proof_main.wasm"),
circomZkey: InputFile("tests/circuits/fixtures/proof_main.zkey") circomZkey: InputFile("tests/circuits/fixtures/proof_main.zkey")
) )
backend = initializeBackend(config, utilsMock).tryGet backend = factory.initializeBackend(config, utilsMock).tryGet
check: check:
backend.vkp != nil backend.vkp != nil
@ -78,7 +79,7 @@ suite "Test BackendFactory":
# will be picked up as local files: # will be picked up as local files:
circuitDir: OutDir("tests/circuits/fixtures") circuitDir: OutDir("tests/circuits/fixtures")
) )
backend = initializeBackend(config, utilsMock).tryGet backend = factory.initializeBackend(config, utilsMock).tryGet
check: check:
backend.vkp != nil backend.vkp != nil
@ -97,8 +98,7 @@ suite "Test BackendFactory":
marketplaceAddress: EthAddress.example.some, marketplaceAddress: EthAddress.example.some,
circuitDir: OutDir(circuitDir) circuitDir: OutDir(circuitDir)
) )
backendResult = factory.initializeBackend(config, utilsMock)
backendResult = initializeBackend(config, utilsMock)
check: check:
backendResult.isErr backendResult.isErr

View File

@ -53,8 +53,12 @@ suite "Test Prover":
numProofSamples: samples numProofSamples: samples
) )
let
backendFactory = BackendFactory()
backend = backendFactory.initializeBackend(config).tryGet()
store = RepoStore.new(repoDs, metaDs) store = RepoStore.new(repoDs, metaDs)
prover = Prover.new(store, config).tryGet() prover = Prover.new(store, backend, config)
teardown: teardown:
await repoTmp.destroyDb() await repoTmp.destroyDb()