Skip to content

Commit

Permalink
feat(galois): allow only one proof to be generated concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Oct 18, 2023
1 parent b904df8 commit d1c00e7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions galoisd/grpc/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,6 +41,7 @@ type proverServer struct {
pk backend.ProvingKey
vk backend.VerifyingKey
commitment constraint.Commitment
proving atomic.Bool
}

func (*proverServer) mustEmbedUnimplementedUnionProverAPIServer() {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d1c00e7

Please sign in to comment.