Skip to content

Commit f4b7350

Browse files
authored
Aligning Benchmarks with FSC Changes (#1952)
Signed-off-by: Effi-S <effi.szt@gmail.com>
1 parent b964f08 commit f4b7350

6 files changed

Lines changed: 100 additions & 47 deletions

File tree

cmd/token_validation_service/api_bench_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ func BenchmarkAPI(b *testing.B) {
1818
testdataPath := b.TempDir()
1919
nodeConfPath := path.Join(testdataPath, "fsc", "nodes", "test-node.0")
2020

21-
err := node.GenerateConfig(testdataPath)
21+
err := GenerateConfigWS(testdataPath)
2222
require.NoError(b, err)
2323

24-
n, err := node.SetupNode(nodeConfPath, node.NamedFactory{
24+
n, err := SetupNodeP2P(nodeConfPath, node.NamedFactory{
2525
Name: "token-validation-service",
2626
Factory: &TokenValidationServiceViewFactory{},
2727
})
28+
2829
require.NoError(b, err)
30+
2931
defer n.Stop()
3032

3133
vm, err := viewregistry.GetManager(n)

cmd/token_validation_service/api_grpc_bench_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ func BenchmarkAPIGRPC(b *testing.B) {
2525
nodeConfPath := path.Join(testdataPath, "fsc", "nodes", "test-node.0")
2626
clientConfPath := path.Join(nodeConfPath, "client-config.yaml")
2727

28-
err := node.GenerateConfig(testdataPath)
28+
err := GenerateConfigWS(testdataPath)
2929
require.NoError(b, err)
3030

31-
n, err := node.SetupNode(nodeConfPath, node.NamedFactory{
31+
n, err := SetupNodeP2P(nodeConfPath, node.NamedFactory{
3232
Name: "token-validation-service",
3333
Factory: &TokenValidationServiceViewFactory{},
3434
})
3535

3636
require.NoError(b, err)
37+
3738
defer n.Stop()
3839

3940
paramsSlice, err := NewTokenValidationParamsSlice(DefaultTestRoot)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright IBM Corp All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package bench
8+
9+
import (
10+
"github.com/hyperledger-labs/fabric-smart-client/integration"
11+
"github.com/hyperledger-labs/fabric-smart-client/integration/benchmark/node"
12+
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
13+
fscnode "github.com/hyperledger-labs/fabric-smart-client/node"
14+
viewsdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
15+
viewregistry "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
16+
)
17+
18+
// GenerateConfigWS mirrors node.GenerateConfig but uses websocket transport.
19+
// (node.GenerateConfig uses default LibP2P)
20+
func GenerateConfigWS(testdataDir string) error {
21+
fscTopology := fsc.NewTopology()
22+
fscTopology.P2PCommunicationType = fsc.WebSocket
23+
fscTopology.SetLogging("error", "")
24+
fscTopology.AddNodeByName("test-node")
25+
26+
_, err := integration.GenerateAt(8099, testdataDir, false, fscTopology)
27+
28+
return err
29+
}
30+
31+
// SetupNodeP2P mirrors node.SetupNode and uses the default websocket transport.
32+
func SetupNodeP2P(confPath string, factories ...node.NamedFactory) (*fscnode.Node, error) {
33+
n := fscnode.NewWithConfPath(confPath)
34+
35+
if err := n.InstallSDK(viewsdk.NewSDK(n)); err != nil {
36+
return nil, err
37+
}
38+
39+
if err := n.Start(); err != nil {
40+
return nil, err
41+
}
42+
43+
reg := viewregistry.GetRegistry(n)
44+
for _, f := range factories {
45+
if err := reg.RegisterFactory(f.Name, f.Factory); err != nil {
46+
return nil, err
47+
}
48+
}
49+
50+
return n, nil
51+
}

cmd/token_validation_service/server/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"path"
1414

1515
bench "github.com/LFDT-Panurus/panurus/cmd/token_validation_service"
16+
1617
"github.com/hyperledger-labs/fabric-smart-client/integration/benchmark/node"
1718
)
1819

@@ -21,14 +22,14 @@ func main() {
2122
nodeConfPath := path.Join(testdataPath, "fsc", "nodes", "test-node.0")
2223

2324
// we generate our testdata
24-
err := node.GenerateConfig(testdataPath)
25+
err := bench.GenerateConfigWS(testdataPath)
2526
if err != nil {
2627
fmt.Fprintf(os.Stderr, "Failed to generate config: %v\n", err)
2728
os.Exit(1)
2829
}
2930

3031
// create server
31-
n, err := node.SetupNode(nodeConfPath, node.NamedFactory{
32+
n, err := bench.SetupNodeP2P(nodeConfPath, node.NamedFactory{
3233
Name: "token-validation-service",
3334
Factory: &bench.TokenValidationServiceViewFactory{},
3435
})

cmd/token_validation_service/token_validation_service_bench.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os"
1616
"path/filepath"
1717
"regexp"
18+
"sort"
1819
"strconv"
1920
"strings"
2021
"sync"
@@ -31,7 +32,8 @@ import (
3132

3233
const (
3334
// DefaultTestRoot is the default path to test data for token transfer verification
34-
DefaultTestRoot = "../../token/core/zkatdlog/nogh/v1/validator/regression/testdata/32-BLS12_381_BBS_GURVY/transfers_i2_o2"
35+
DefaultTestRoot = "../../token/core/zkatdlog/nogh/v1/regression/testdata/zero/32-BLS12_381_BBS_GURVY"
36+
defaultCasePrefix = "transfers_i2_o2_"
3537
)
3638

3739
var (
@@ -102,55 +104,51 @@ func NewTokenValidationParamsSlice(TestRootPath string) ([]*transferServiceParam
102104
if TestRootPath == "" {
103105
return nil, errors.New("TestRootPath cannot be empty")
104106
}
105-
paramsTxt := filepath.Join(filepath.Dir(TestRootPath), "params.txt")
106107

107-
paramsRaw, err := os.ReadFile(paramsTxt)
108+
testdataPath := filepath.Join(TestRootPath, "testdata.json")
109+
testdataRaw, err := os.ReadFile(testdataPath)
108110
if err != nil {
109-
return nil, fmt.Errorf("failed to read params file %s: %w", paramsTxt, err)
111+
return nil, fmt.Errorf("failed to read testdata file %s: %w", testdataPath, err)
110112
}
111113

112-
ppRaw, err := base64.StdEncoding.DecodeString(strings.TrimSpace(string(paramsRaw)))
113-
if err != nil {
114-
return nil, fmt.Errorf("failed to base64-decode params.txt: %w", err)
114+
var allCases map[string]struct {
115+
ReqRaw string `json:"req_raw"`
116+
TXID string `json:"txid"`
115117
}
116-
117-
outPaths, err := os.ReadDir(TestRootPath)
118-
if err != nil {
119-
return nil, fmt.Errorf("failed to read directory %s: %w", TestRootPath, err)
118+
if err := json.Unmarshal(testdataRaw, &allCases); err != nil {
119+
return nil, fmt.Errorf("failed to unmarshal testdata file: %w", err)
120120
}
121-
ret := make([]*transferServiceParams, len(outPaths))
122-
for i, outPath := range outPaths {
123-
params, err := newTokenValidationParams(filepath.Join(TestRootPath, outPath.Name()), ppRaw)
124-
if err != nil {
125-
return nil, fmt.Errorf("failed to create params for %s: %w", outPath.Name(), err)
121+
122+
keys := make([]string, 0, len(allCases))
123+
for key := range allCases {
124+
if strings.HasPrefix(key, defaultCasePrefix) {
125+
keys = append(keys, key)
126126
}
127-
ret[i] = params
128127
}
129-
130-
return ret, nil
131-
}
132-
133-
func newTokenValidationParams(outputPath string, ppRaw []byte) (*transferServiceParams, error) {
134-
outputRaw, err := os.ReadFile(outputPath)
135-
if err != nil {
136-
return nil, fmt.Errorf("failed to read %s: %w", outputPath, err)
128+
if len(keys) == 0 {
129+
return nil, fmt.Errorf("no test cases with prefix %q found in %s", defaultCasePrefix, testdataPath)
137130
}
131+
sort.Strings(keys)
138132

139-
var tokenData struct {
140-
ReqRaw []byte `json:"req_raw"`
141-
TXID string `json:"txid"`
142-
}
143-
if err := json.Unmarshal(outputRaw, &tokenData); err != nil {
144-
return nil, fmt.Errorf("failed to unmarshal output file: %w", err)
133+
caseFamily := strings.TrimSuffix(defaultCasePrefix, "_")
134+
ret := make([]*transferServiceParams, 0, len(keys))
135+
for _, key := range keys {
136+
tokenCase := allCases[key]
137+
reqRaw, err := base64.StdEncoding.DecodeString(tokenCase.ReqRaw)
138+
if err != nil {
139+
return nil, fmt.Errorf("failed to base64-decode req_raw for %s: %w", key, err)
140+
}
141+
ret = append(ret, &transferServiceParams{
142+
// Synthetic path: <configDir>/<caseFamily>/<idx> for path-based helpers.
143+
OutputPath: filepath.Join(TestRootPath, caseFamily, strings.TrimPrefix(key, defaultCasePrefix)),
144+
TokenData: &TokenData{
145+
TokenRequestRaw: reqRaw,
146+
TxID: tokenCase.TXID,
147+
},
148+
})
145149
}
146150

147-
return &transferServiceParams{
148-
OutputPath: outputPath,
149-
TokenData: &TokenData{
150-
TokenRequestRaw: tokenData.ReqRaw,
151-
TxID: tokenData.TXID,
152-
},
153-
}, nil
151+
return ret, nil
154152
}
155153

156154
type fakeLedger struct{}

docs/drivers/benchmark/token_validation_service_benchmark.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ The Token Validation Service benchmarks serve several critical purposes:
3838
Panurus comes pre-equipped with test data containing cryptographic parameters and sample token transfers located at:
3939

4040
```
41-
token/core/zkatdlog/nogh/v1/validator/regression/testdata/
41+
token/core/zkatdlog/nogh/v1/validator/regression/testdata/zero
4242
```
4343

4444
This directory includes:
4545
- Public parameters for zero-knowledge proofs (e.g., `32-BLS12_381_BBS_GURVY/params.txt`)
46-
- Pre-generated token transfer test cases in subdirectories like `transfers_i2_o2/`
46+
- Pre-generated token transfer test cases in `testdata/`
4747

4848
**Note**: The test data is already included in the repository. You only need to regenerate it if you want to create custom test cases with different parameters or token configurations. To regenerate test data on demand:
4949

5050
```bash
51-
cd token/core/zkatdlog/nogh/v1/validator
51+
cd token/core/zkatdlog/nogh/v1/regression
5252
go test -run TestRegression -v
5353
```
5454
- Sample token commitments and metadata

0 commit comments

Comments
 (0)