Skip to content

Commit

Permalink
Always expect concurrency level to be passed to NewDlnProofVerifier
Browse files Browse the repository at this point in the history
The concurrency level is now available in all rounds constructing the
verifier and the optional concurrency feature is never used.
  • Loading branch information
pdyraga committed Aug 25, 2022
1 parent 4db8a49 commit 4ba50f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
14 changes: 1 addition & 13 deletions ecdsa/keygen/dln_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
package keygen

import (
"errors"
"math/big"
"runtime"

"github.com/bnb-chain/tss-lib/crypto/dlnproof"
)
Expand All @@ -23,17 +21,7 @@ type message interface {
UnmarshalDLNProof2() (*dlnproof.Proof, error)
}

func NewDlnProofVerifier(optionalConcurrency ...int) *DlnProofVerifier {
var concurrency int
if 0 < len(optionalConcurrency) {
if 1 < len(optionalConcurrency) {
panic(errors.New("NewDlnProofVerifier: expected 0 or 1 item in `optionalConcurrency`"))
}
concurrency = optionalConcurrency[0]
} else {
concurrency = runtime.NumCPU()
}

func NewDlnProofVerifier(concurrency int) *DlnProofVerifier {
semaphore := make(chan interface{}, concurrency)

return &DlnProofVerifier{
Expand Down
29 changes: 9 additions & 20 deletions ecdsa/keygen/dln_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package keygen

import (
"math/big"
"runtime"
"testing"

"github.com/bnb-chain/tss-lib/crypto/dlnproof"
Expand Down Expand Up @@ -42,7 +43,7 @@ func BenchmarkDlnVerifier_VerifyProof1(b *testing.B) {
Dlnproof_1: proof,
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

b.ResetTimer()
for n := 0; n < b.N; n++ {
Expand All @@ -60,7 +61,7 @@ func BenchmarkDlnVerifier_VerifyProof2(b *testing.B) {
Dlnproof_2: proof,
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

b.ResetTimer()
for n := 0; n < b.N; n++ {
Expand All @@ -78,7 +79,7 @@ func TestVerifyDLNProof1_Success(t *testing.T) {
Dlnproof_1: proof,
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

resultChan := make(chan bool)

Expand All @@ -98,7 +99,7 @@ func TestVerifyDLNProof1_MalformedMessage(t *testing.T) {
Dlnproof_1: proof[:len(proof)-1], // truncate
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

resultChan := make(chan bool)

Expand All @@ -118,7 +119,7 @@ func TestVerifyDLNProof1_IncorrectProof(t *testing.T) {
Dlnproof_1: proof,
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

resultChan := make(chan bool)

Expand All @@ -139,7 +140,7 @@ func TestVerifyDLNProof2_Success(t *testing.T) {
Dlnproof_2: proof,
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

resultChan := make(chan bool)

Expand All @@ -159,7 +160,7 @@ func TestVerifyDLNProof2_MalformedMessage(t *testing.T) {
Dlnproof_2: proof[:len(proof)-1], // truncate
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

resultChan := make(chan bool)

Expand All @@ -179,7 +180,7 @@ func TestVerifyDLNProof2_IncorrectProof(t *testing.T) {
Dlnproof_2: proof,
}

verifier := NewDlnProofVerifier()
verifier := NewDlnProofVerifier(runtime.GOMAXPROCS(0))

resultChan := make(chan bool)

Expand All @@ -194,18 +195,6 @@ func TestVerifyDLNProof2_IncorrectProof(t *testing.T) {
}
}

// TestOptionalConcurrency check that if the concurrency level optional flag
// is set, it is taken into account.
func TestOptionalConcurrency(t *testing.T) {
concurrency := 7161

verifier := NewDlnProofVerifier(concurrency)

if cap(verifier.semaphore) != concurrency {
t.Fatal("unexpected concurrency level")
}
}

func prepareProofT(t *testing.T) (*LocalPreParams, [][]byte) {
preParams, serialized, err := prepareProof()
if err != nil {
Expand Down

0 comments on commit 4ba50f5

Please sign in to comment.