Skip to content

Commit 1764cfc

Browse files
RozerxshashankAkramBitar
authored andcommitted
perf(benchmark): add benchmarks and documentation for fabtoken
Signed-off-by: Shashank <yshashank959@gmail.com>
1 parent fad498f commit 1764cfc

7 files changed

Lines changed: 1315 additions & 12 deletions

File tree

docs/drivers/benchmark/benchmark.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
- [ZKAT DLog Testing Architecture](core/dlognogh/dlognogh_architecture.md) - Understanding the test layers
1616
- [ZKAT DLog Regression Tests](core/dlognogh/dlognogh_regression.md) - Backwards compatibility testing
1717

18+
- [Fabtoken Benchmarks](core/fabtoken/fabtoken.md) - How to run benchmarks
19+
- [Fabtoken Testing Architecture](core/fabtoken/fabtoken_architecture.md) - Understanding the test layers
20+
1821
### Services
1922

2023
- [Identity Service - Idemix](services/identity/idemix.md)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Fabtoken Benchmarks
2+
3+
This document provides an overview of the performance benchmarks for the Fabtoken driver in the Fabric Token SDK.
4+
5+
> **Related Documentation:**
6+
> - [Testing Architecture](./fabtoken_architecture.md) - Understanding the test layers
7+
8+
## Overview
9+
10+
The Fabtoken benchmarks measure the performance of token operations (Issue, Transfer, and Validation) at different abstraction layers. Unlike the ZKAT DLog driver, Fabtoken does not use complex zero-knowledge proofs, making its operations significantly faster and simpler.
11+
12+
## Benchmark Packages
13+
14+
The following packages contain benchmark tests for Fabtoken:
15+
16+
- `token/core/fabtoken/v1`:
17+
- **Layer 3 (Service)**: `BenchmarkTransferServiceTransfer`, `BenchmarkIssueServiceIssue`, `BenchmarkAuditorServiceCheck`
18+
- **Layer 2 (Action Generation)**: `BenchmarkSender`, `BenchmarkIssuer`
19+
- **Layer 2 (Action Verification)**: `BenchmarkVerificationSenderProof`, `BenchmarkProofVerificationIssuer`
20+
- **Layer 1 (Core)**: `BenchmarkTransferProofGeneration`
21+
- `token/core/fabtoken/v1/validator`:
22+
- **Layer 3 (Service)**: `BenchmarkValidatorTransfer`, `BenchmarkValidatorIssue`
23+
24+
## Parameters
25+
26+
Fabtoken benchmarks support the same programmatic parameter system as other drivers:
27+
28+
- **NumInputs**: Number of input tokens (for Transfer).
29+
- **NumOutputs**: Number of output tokens (for Issue and Transfer).
30+
31+
These are controlled via the `benchmark` package and can be customized in the test code or via flags if implemented in the future (currently using defaults from `GenerateCasesWithDefaults`).
32+
33+
## How to Run
34+
35+
### Run Service Layer Benchmarks
36+
```bash
37+
# Transfer Service
38+
go test ./token/core/fabtoken/v1 -bench=BenchmarkTransferServiceTransfer -benchmem -run=^$
39+
40+
# Issue Service
41+
go test ./token/core/fabtoken/v1 -bench=BenchmarkIssueServiceIssue -benchmem -run=^$
42+
43+
# Auditor Service
44+
go test ./token/core/fabtoken/v1 -bench=BenchmarkAuditorServiceCheck -benchmem -run=^$
45+
```
46+
47+
### Run Action Layer Benchmarks
48+
```bash
49+
# Transfer Action Generation
50+
go test ./token/core/fabtoken/v1 -bench=BenchmarkSender -benchmem -run=^$
51+
52+
# Issue Action Generation
53+
go test ./token/core/fabtoken/v1 -bench=BenchmarkIssuer -benchmem -run=^$
54+
```
55+
56+
### Run Validator Benchmarks
57+
```bash
58+
go test ./token/core/fabtoken/v1/validator -bench=BenchmarkValidatorTransfer -benchmem -run=^$
59+
go test ./token/core/fabtoken/v1/validator -bench=BenchmarkValidatorIssue -benchmem -run=^$
60+
```
61+
62+
## Parallel Benchmarking
63+
64+
Most benchmarks include parallel variants to measure performance under concurrent load:
65+
66+
- **Built-in Parallelism**: `BenchmarkParallelSender`, `BenchmarkVerificationParallelSenderProof`
67+
- **Custom Parallel Framework**: `TestParallelBenchmarkTransferServiceTransfer`, `TestParallelBenchmarkIssueServiceIssue`, `TestParallelBenchmarkAuditorServiceCheck`, `TestParallelBenchmarkValidatorTransfer`, etc.
68+
69+
To run the custom parallel benchmarks (using `*testing.T`):
70+
```bash
71+
go test ./token/core/fabtoken/v1 -run=TestParallelBenchmarkTransferServiceTransfer -v
72+
```
73+
74+
## Understanding Results
75+
76+
The benchmarks report:
77+
- `ns/op`: Time taken per operation.
78+
- `B/op`: Memory allocated per operation.
79+
- `allocs/op`: Number of memory allocations per operation.
80+
81+
Lower values indicate better performance. Since Fabtoken uses standard cryptographic signatures (like ECDSA or RSA) instead of ZK proofs, you should expect much lower `ns/op` compared to the DLog driver.
Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
# Fabtoken Testing Architecture
2+
3+
This document explains the testing architecture for the Fabtoken implementation in the Fabric Token SDK.
4+
5+
> **Related Documentation:**
6+
> - [Running Benchmarks](./fabtoken.md) - How to run performance benchmarks
7+
8+
## Overview
9+
10+
The Fabtoken tests are organized in a **layered architecture** that mirrors the **code abstraction levels**. Each layer represents a different level of the software stack - from core operations to high-level service APIs.
11+
12+
## Architecture Layers
13+
14+
Each layer represents a different **code abstraction level**.
15+
16+
```
17+
┌─────────────────────────────────────────────────────────────────┐
18+
│ Layer 3: Service Layer (Highest Abstraction) │
19+
├─────────────────────────────────────────────────────────────────┤
20+
│ Transfer Generation Service │
21+
│ Location: token/core/fabtoken/v1/ │
22+
│ Tests: - BenchmarkTransferServiceTransfer │
23+
│ - TestParallelBenchmarkTransferServiceTransfer │
24+
│ Purpose: End-to-end transfer operation generation with vault, │
25+
│ audit, and metadata handling │
26+
├─────────────────────────────────────────────────────────────────┤
27+
│ Issue Generation Service │
28+
│ Location: token/core/fabtoken/v1/ │
29+
│ Tests: - BenchmarkIssueServiceIssue │
30+
│ - TestParallelBenchmarkIssueServiceIssue │
31+
│ Purpose: End-to-end issue operation generation through high-level│
32+
│ service API │
33+
├─────────────────────────────────────────────────────────────────┤
34+
│ Auditor Check Service │
35+
│ Location: token/core/fabtoken/v1/ │
36+
│ Tests: - BenchmarkAuditorServiceCheck │
37+
│ - TestParallelBenchmarkAuditorServiceCheck │
38+
│ Purpose: End-to-end audit verification through high-level │
39+
│ service API │
40+
├─────────────────────────────────────────────────────────────────┤
41+
│ Transfer/Issue Validator Service │
42+
│ Location: token/core/fabtoken/v1/validator/ │
43+
│ Tests: - BenchmarkValidatorTransfer │
44+
│ - TestParallelBenchmarkValidatorTransfer │
45+
│ - BenchmarkValidatorIssue │
46+
│ - TestParallelBenchmarkValidatorIssue │
47+
│ Purpose: Token request validation with signatures, business │
48+
│ logic, and format verification │
49+
└─────────────────────────────────────────────────────────────────┘
50+
51+
┌─────────────────────────────────────────────────────────────────┐
52+
│ Layer 2: Action Operations │
53+
├─────────────────────────────────────────────────────────────────┤
54+
│ Transfer Generation (token/core/fabtoken/v1/) │
55+
│ Tests: - BenchmarkSender │
56+
│ - BenchmarkParallelSender │
57+
│ - TestParallelBenchmarkSender │
58+
│ Purpose: Transfer action generation and serialization │
59+
├─────────────────────────────────────────────────────────────────┤
60+
│ Transfer Verification (token/core/fabtoken/v1/) │
61+
│ Tests: - BenchmarkVerificationSenderProof │
62+
│ - BenchmarkVerificationParallelSenderProof │
63+
│ - TestParallelBenchmarkVerificationSenderProof │
64+
│ Purpose: Deserialization and format validation of transfer │
65+
│ actions │
66+
├─────────────────────────────────────────────────────────────────┤
67+
│ Issue Generation (token/core/fabtoken/v1/) │
68+
│ Tests: - BenchmarkIssuer │
69+
│ Purpose: Issue action generation and serialization │
70+
├─────────────────────────────────────────────────────────────────┤
71+
│ Issue Verification (token/core/fabtoken/v1/) │
72+
│ Tests: - BenchmarkProofVerificationIssuer │
73+
│ Purpose: Deserialization and verification of issue actions │
74+
└─────────────────────────────────────────────────────────────────┘
75+
76+
┌─────────────────────────────────────────────────────────────────┐
77+
│ Layer 1: Core Operations (Lowest Abstraction) │
78+
│ Location: token/core/fabtoken/v1/ │
79+
│ Tests: - BenchmarkTransferProofGeneration │
80+
│ - TestParallelBenchmarkTransferProofGeneration │
81+
│ Purpose: Pure transfer action structure generation and │
82+
│ serialization │
83+
└─────────────────────────────────────────────────────────────────┘
84+
```
85+
86+
---
87+
88+
## Layer 1: Core Operations
89+
90+
**Location:** `token/core/fabtoken/v1/`
91+
92+
### Tests
93+
- `BenchmarkTransferProofGeneration`
94+
- `TestParallelBenchmarkTransferProofGeneration`
95+
96+
### Purpose
97+
Pure transfer action generation and serialization. In Fabtoken, since there are no complex zero-knowledge proofs, this layer focuses on the core action structure creation.
98+
99+
### Example Commands
100+
```bash
101+
cd token/core/fabtoken/v1
102+
go test -bench=BenchmarkTransferProofGeneration -benchtime=10s
103+
go test -run=TestParallelBenchmarkTransferProofGeneration -v
104+
```
105+
106+
---
107+
108+
## Layer 2: Action Operations
109+
110+
### Transfer Action Generation
111+
112+
**Location:** `token/core/fabtoken/v1/`
113+
114+
#### Tests
115+
- `BenchmarkSender`
116+
- `BenchmarkParallelSender`
117+
- `TestParallelBenchmarkSender`
118+
119+
#### Purpose
120+
Complete transfer action creation from inputs to serialized output.
121+
122+
#### Example Commands
123+
```bash
124+
cd token/core/fabtoken/v1
125+
go test -bench=BenchmarkSender -benchtime=10s
126+
go test -bench=BenchmarkParallelSender -benchtime=10s
127+
go test -run=TestParallelBenchmarkSender -v
128+
```
129+
130+
### Transfer Action Verification
131+
132+
**Location:** `token/core/fabtoken/v1/`
133+
134+
#### Tests
135+
- `BenchmarkVerificationSenderProof`
136+
- `BenchmarkVerificationParallelSenderProof`
137+
- `TestParallelBenchmarkVerificationSenderProof`
138+
139+
#### Purpose
140+
Deserialization and verification of transfer actions.
141+
142+
#### Example Commands
143+
```bash
144+
cd token/core/fabtoken/v1
145+
go test -bench=BenchmarkVerificationSenderProof -benchtime=10s
146+
go test -bench=BenchmarkVerificationParallelSenderProof -benchtime=10s
147+
go test -run=TestParallelBenchmarkVerificationSenderProof -v
148+
```
149+
150+
### Issue Action Generation
151+
152+
**Location:** `token/core/fabtoken/v1/`
153+
154+
#### Tests
155+
- `BenchmarkIssuer`
156+
157+
#### Purpose
158+
Complete issue action creation from inputs to serialized output.
159+
160+
#### Example Commands
161+
```bash
162+
cd token/core/fabtoken/v1
163+
go test -bench=BenchmarkIssuer -benchtime=10s
164+
```
165+
166+
### Issue Action Verification
167+
168+
**Location:** `token/core/fabtoken/v1/`
169+
170+
#### Tests
171+
- `BenchmarkProofVerificationIssuer`
172+
173+
#### Purpose
174+
Deserialization and verification of issue actions.
175+
176+
#### Example Commands
177+
```bash
178+
cd token/core/fabtoken/v1
179+
go test -bench=BenchmarkProofVerificationIssuer -benchtime=10s
180+
```
181+
182+
---
183+
184+
## Layer 3: Service Layer
185+
186+
The Service Layer provides the highest level of abstraction for complete end-to-end operations through the Service APIs.
187+
188+
### Transfer Generation Service
189+
190+
**Location:** `token/core/fabtoken/v1/`
191+
192+
#### Tests
193+
- `BenchmarkTransferServiceTransfer`
194+
- `TestParallelBenchmarkTransferServiceTransfer`
195+
196+
#### Purpose
197+
Complete end-to-end transfer operation generation through the high-level Transfer Service API.
198+
199+
#### Includes
200+
- Token Loading from vault
201+
- Input Preparation
202+
- Sender Initialization
203+
- Output Processing
204+
- Action Generation and Serialization
205+
- Audit Information collection
206+
207+
#### Example Commands
208+
```bash
209+
cd token/core/fabtoken/v1
210+
go test -bench=BenchmarkTransferServiceTransfer -benchtime=10s
211+
go test -run=TestParallelBenchmarkTransferServiceTransfer -v
212+
```
213+
214+
### Issue Generation Service
215+
216+
**Location:** `token/core/fabtoken/v1/`
217+
218+
#### Tests
219+
- `BenchmarkIssueServiceIssue`
220+
- `TestParallelBenchmarkIssueServiceIssue`
221+
222+
#### Purpose
223+
End-to-end issue operation generation through the high-level Issue Service API.
224+
225+
#### Includes
226+
- Wallet lookup and signer resolution
227+
- Output token creation
228+
- Action and metadata serialization
229+
230+
#### Example Commands
231+
```bash
232+
cd token/core/fabtoken/v1
233+
go test -bench=BenchmarkIssueServiceIssue -benchtime=10s
234+
go test -run=TestParallelBenchmarkIssueServiceIssue -v
235+
```
236+
237+
### Auditor Check Service
238+
239+
**Location:** `token/core/fabtoken/v1/`
240+
241+
#### Tests
242+
- `BenchmarkAuditorServiceCheck`
243+
- `TestParallelBenchmarkAuditorServiceCheck`
244+
245+
#### Purpose
246+
End-to-end audit verification through the high-level Auditor Service API.
247+
248+
#### Includes
249+
- Action deserialization
250+
- Request verification
251+
- Identity matching via the driver deserializer
252+
253+
#### Example Commands
254+
```bash
255+
cd token/core/fabtoken/v1
256+
go test -bench=BenchmarkAuditorServiceCheck -benchtime=10s
257+
go test -run=TestParallelBenchmarkAuditorServiceCheck -v
258+
```
259+
260+
### Transfer/Issue Validator Service
261+
262+
**Location:** `token/core/fabtoken/v1/validator/`
263+
264+
#### Tests
265+
- `BenchmarkValidatorTransfer`
266+
- `TestParallelBenchmarkValidatorTransfer`
267+
- `BenchmarkValidatorIssue`
268+
- `TestParallelBenchmarkValidatorIssue`
269+
270+
#### Purpose
271+
Complete validation pipeline performance, including all signature and business logic checks.
272+
273+
#### Example Commands
274+
```bash
275+
cd token/core/fabtoken/v1/validator
276+
go test -bench=BenchmarkValidatorTransfer -benchtime=10s
277+
go test -run=TestParallelBenchmarkValidatorTransfer -v
278+
go test -bench=BenchmarkValidatorIssue -benchtime=10s
279+
go test -run=TestParallelBenchmarkValidatorIssue -v
280+
```
281+
282+
---
283+
284+
## Testing Strategy
285+
286+
### Understanding the Layers
287+
288+
Each layer tests a **different code abstraction level independently**:
289+
290+
- **Layer 1** tests the core action structure generation.
291+
- **Layer 2** tests the action creation/verification code.
292+
- **Layer 3** tests the service layer code:
293+
- **Transfer Generation Service**: end-to-end transfer generation
294+
- **Issue Generation Service**: end-to-end issue generation
295+
- **Auditor Check Service**: audit verification
296+
- **Transfer Validator Service**: validation logic
297+
298+
---
299+
300+
## Parallel Testing Variants
301+
302+
Most layers include parallel test variants that run benchmarks concurrently:
303+
- **`Benchmark*Parallel`**: Go's built-in parallel benchmarking (`*testing.B`)
304+
- **`TestParallelBenchmark*`**: Custom parallel benchmarking framework (`*testing.T`)
305+
306+
These help identify concurrency issues and measure performance under load.

0 commit comments

Comments
 (0)