From d1c00e716bea88b8ee3d9931498e3b6b971423e1 Mon Sep 17 00:00:00 2001 From: Hussein Ait Lahcen Date: Wed, 18 Oct 2023 11:17:34 +0200 Subject: [PATCH] feat(galois): allow only one proof to be generated concurrently --- galoisd/grpc/api/v1/server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/galoisd/grpc/api/v1/server.go b/galoisd/grpc/api/v1/server.go index 2e0645bf1d..4c3f8cb239 100644 --- a/galoisd/grpc/api/v1/server.go +++ b/galoisd/grpc/api/v1/server.go @@ -13,6 +13,8 @@ import ( "math/big" "os" "runtime" + "sync/atomic" + "time" cometbft_bn254 "github.com/cometbft/cometbft/crypto/bn254" ce "github.com/cometbft/cometbft/crypto/encoding" @@ -39,6 +41,7 @@ type proverServer struct { pk backend.ProvingKey vk backend.VerifyingKey commitment constraint.Commitment + proving atomic.Bool } func (*proverServer) mustEmbedUnimplementedUnionProverAPIServer() {} @@ -177,6 +180,15 @@ func (p *proverServer) QueryStats(ctx context.Context, req *QueryStatsRequest) ( func (p *proverServer) Prove(ctx context.Context, req *ProveRequest) (*ProveResponse, error) { log.Println("Proving...") + for true { + swapped := p.proving.CompareAndSwap(false, true) + if swapped { + break + } else { + time.Sleep(1000) + } + } + reqJson, err := json.MarshalIndent(req, "", " ") if err != nil { return nil, err @@ -321,6 +333,8 @@ func (p *proverServer) Prove(ctx context.Context, req *ProveRequest) (*ProveResp // Run GC to avoid high residency, a single prove call is very expensive in term of memory. runtime.GC() + p.proving.Store(false) + // F_r element var commitmentHash []byte // G1 uncompressed