From 7c854c5fe950bee228a657ab49a20b1cc2ce47e6 Mon Sep 17 00:00:00 2001 From: Gui Iribarren Date: Mon, 2 Oct 2023 13:57:25 +0200 Subject: [PATCH] zkCircuits: fix BaseDir handling until now, voconed didn't put the files inside VOCONED_DIR now: * `go test ./...` uses ~/.cache/vocdoni/zkCircuits/ * `node` uses ~/.vocdoni/zkCircuits/ * `voconed` uses ~/.voconed/zkCircuits/ and both `node` and `voconed` use `/app/run/zkCircuits` when inside docker --- cmd/node/main.go | 2 +- cmd/voconed/voconed.go | 5 +++++ crypto/zk/circuit/circuit.go | 20 ++++++++------------ dockerfiles/vocone/.env | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/node/main.go b/cmd/node/main.go index 7d54089d6..3cd678d11 100644 --- a/cmd/node/main.go +++ b/cmd/node/main.go @@ -348,7 +348,7 @@ func main() { // Overwrite the default path to download the zksnarks circuits artifacts // using the global datadir as parent folder. - circuit.BaseDir = filepath.Join(globalCfg.DataDir, circuit.BaseDir) + circuit.BaseDir = filepath.Join(globalCfg.DataDir, "zkCircuits") // Ensure we can have at least 8k open files. This is necessary, since // many components like IPFS and Tendermint require keeping many active diff --git a/cmd/voconed/voconed.go b/cmd/voconed/voconed.go index f70e20115..33c478462 100644 --- a/cmd/voconed/voconed.go +++ b/cmd/voconed/voconed.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/viper" "go.vocdoni.io/dvote/api/faucet" "go.vocdoni.io/dvote/crypto/ethereum" + "go.vocdoni.io/dvote/crypto/zk/circuit" "go.vocdoni.io/dvote/internal" "go.vocdoni.io/dvote/log" "go.vocdoni.io/dvote/vochain/state" @@ -178,6 +179,10 @@ func main() { log.Infof("using data directory at %s", config.dir) + // Overwrite the default path to download the zksnarks circuits artifacts + // using the global datadir as parent folder. + circuit.BaseDir = filepath.Join(config.dir, "zkCircuits") + mngKey := ethereum.SignKeys{} if err := mngKey.AddHexKey(config.keymanager); err != nil { log.Fatal(err) diff --git a/crypto/zk/circuit/circuit.go b/crypto/zk/circuit/circuit.go index b2c732411..ad38448b7 100644 --- a/crypto/zk/circuit/circuit.go +++ b/crypto/zk/circuit/circuit.go @@ -19,21 +19,17 @@ var downloadCircuitsTimeout = time.Minute * 5 // BaseDir is where the artifact cache is expected to be found. // If the artifacts are not found there, they will be downloaded and stored. -// If unset ("") it will default to ~/.cache/vocdoni/zkCircuits/ +// +// Defaults to ~/.cache/vocdoni/zkCircuits/ // // In any case, the LocalDir path associated with the circuit config will be appended at the end -var BaseDir = "" - -func init() { - // if base dir is unset, default to ~/.cache/vocdoni/ - if BaseDir == "" { - home, err := os.UserHomeDir() - if err != nil { - panic(err) - } - BaseDir = home + "/.cache/vocdoni/zkCircuits" +var BaseDir = func() string { + home, err := os.UserHomeDir() + if err != nil { + panic(err) } -} + return filepath.Join(home, ".cache", "vocdoni", "zkCircuits") +}() // ZkCircuit struct wraps the circuit configuration and contains the file // content of the circuit artifacts (provingKey, verificationKey and wasm) diff --git a/dockerfiles/vocone/.env b/dockerfiles/vocone/.env index d47766ad2..a9a68f933 100644 --- a/dockerfiles/vocone/.env +++ b/dockerfiles/vocone/.env @@ -1,5 +1,6 @@ IMAGE_TAG=main # VOCONED_KEYMANAGER=571063b70545d01b8c130bb411b5f0220e06b8db236bb12e77ae478f7078b77b +VOCONED_DIR=/app/run VOCONED_PORT=9090 VOCONED_URLPATH=/v2 VOCONED_BLOCKPERIOD=5