Skip to content

Commit d38beaa

Browse files
Fix high-throughput sample
Build failures because the startFabric.sh script specified that the chaincode required initialization, which is both logacy behavior and is unnecessary. The chaincode is updated to use the Contract API instead of the legacy / low-level chaincode API. The client application is also simplified. Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
1 parent ad19505 commit d38beaa

10 files changed

Lines changed: 236 additions & 350 deletions

File tree

high-throughput/application-go/app.go

Lines changed: 98 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ package main
99
import (
1010
"log"
1111
"os"
12+
"sync"
1213
"time"
1314

1415
"github.com/hyperledger/fabric-gateway/pkg/client"
1516
"github.com/hyperledger/fabric-gateway/pkg/hash"
16-
f "github.com/hyperledger/fabric-samples/high-throughput/application-go/functions"
17+
gatewaypb "github.com/hyperledger/fabric-protos-go-apiv2/gateway"
18+
"google.golang.org/grpc/status"
1719
)
1820

1921
func main() {
@@ -56,38 +58,102 @@ func main() {
5658
contract := gateway.GetNetwork("mychannel").GetContract("bigdatacc")
5759

5860
// Handle different functions
59-
if function == "update" {
60-
result, err := f.Update(contract, function, variableName, change, sign)
61-
if err != nil {
62-
log.Fatalf("error: %v", err)
63-
}
64-
log.Println("Value of variable", string(variableName), ": ", string(result))
61+
switch function {
62+
case "update":
63+
update(contract, variableName, change, sign)
64+
case "delete":
65+
delete(contract, variableName)
66+
case "prune":
67+
prune(contract, variableName)
68+
case "delstandard":
69+
delStandard(contract, variableName)
70+
case "get":
71+
get(contract, variableName)
72+
case "getstandard":
73+
getStandard(contract, variableName)
74+
case "manyUpdates":
75+
manyUpdates(contract, "Update", variableName, change, sign)
76+
case "manyUpdatesTraditional":
77+
manyUpdates(contract, "PutStandard", variableName, change, sign)
78+
}
79+
}
6580

66-
} else if function == "delete" || function == "prune" || function == "delstandard" {
67-
result, err := f.DeletePrune(contract, function, variableName)
68-
if err != nil {
69-
log.Fatalf("error: %v", err)
70-
}
71-
log.Println(string(result))
72-
} else if function == "get" || function == "getstandard" {
73-
result, err := f.Query(contract, function, variableName)
74-
if err != nil {
75-
log.Fatalf("error: %v", err)
76-
}
77-
log.Println("Value of variable", string(variableName), ": ", string(result))
78-
} else if function == "manyUpdates" {
79-
log.Println("submitting 1000 concurrent updates...")
80-
result, err := f.ManyUpdates(contract, "update", variableName, change, sign)
81-
if err != nil {
82-
log.Fatalf("error: %v", err)
83-
}
84-
log.Println("Final value of variable", string(variableName), ": ", string(result))
85-
} else if function == "manyUpdatesTraditional" {
86-
log.Println("submitting 1000 concurrent updates...")
87-
result, err := f.ManyUpdates(contract, "putstandard", variableName, change, sign)
88-
if err != nil {
89-
log.Fatalf("error: %v", err)
81+
func update(contract *client.Contract, variableName, change, sign string) {
82+
_, err := contract.SubmitTransaction("Update", variableName, change, sign)
83+
failOnError(err)
84+
85+
result, err := contract.EvaluateTransaction("Get", variableName)
86+
failOnError(err)
87+
log.Println("Value of variable", variableName, ": ", string(result))
88+
}
89+
90+
func delete(contract *client.Contract, variableName string) {
91+
result, err := contract.SubmitTransaction("Delete", variableName)
92+
failOnError(err)
93+
log.Println(string(result))
94+
}
95+
96+
func prune(contract *client.Contract, variableName string) {
97+
result, err := contract.SubmitTransaction("Prune", variableName)
98+
failOnError(err)
99+
log.Println(string(result))
100+
}
101+
102+
func delStandard(contract *client.Contract, variableName string) {
103+
result, err := contract.SubmitTransaction("DelStandard", variableName)
104+
failOnError(err)
105+
log.Println(string(result))
106+
}
107+
108+
func get(contract *client.Contract, variableName string) {
109+
result, err := contract.EvaluateTransaction("Get", variableName)
110+
failOnError(err)
111+
log.Println("Value of variable", string(variableName), ": ", string(result))
112+
}
113+
114+
func getStandard(contract *client.Contract, variableName string) {
115+
result, err := contract.EvaluateTransaction("GetStandard", variableName)
116+
failOnError(err)
117+
log.Println("Value of variable", string(variableName), ": ", string(result))
118+
}
119+
120+
func manyUpdates(contract *client.Contract, function, variableName, change, sign string) {
121+
log.Println("submitting 1000 concurrent updates...")
122+
123+
var wg sync.WaitGroup
124+
for range 1000 {
125+
wg.Add(1)
126+
go func() {
127+
defer wg.Done()
128+
contract.SubmitTransaction(function, variableName, change, sign)
129+
}()
130+
}
131+
132+
wg.Wait()
133+
134+
result, err := contract.EvaluateTransaction("Get", variableName)
135+
failOnError(err)
136+
log.Println("Final value of variable", string(variableName), ": ", string(result))
137+
}
138+
139+
func failOnError(err error) {
140+
if err == nil {
141+
return
142+
}
143+
144+
details := status.Convert(err).Details()
145+
if len(details) > 0 {
146+
log.Println("Error Details:")
147+
148+
for _, detail := range details {
149+
switch detail := detail.(type) {
150+
case *gatewaypb.ErrorDetail:
151+
log.Printf("- address: %s\n mspId: %s\n message: %s\n", detail.Address, detail.MspId, detail.Message)
152+
default:
153+
log.Printf("- %s", detail)
154+
}
90155
}
91-
log.Println("Final value of variable", string(variableName), ": ", string(result))
92156
}
157+
158+
log.Fatalf("error: %v", err)
93159
}

high-throughput/application-go/functions/deletePrune.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

high-throughput/application-go/functions/manyUpdates.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

high-throughput/application-go/functions/query.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

high-throughput/application-go/functions/update.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

high-throughput/application-go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ go 1.23.0
44

55
require (
66
github.com/hyperledger/fabric-gateway v1.8.0
7+
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7
78
google.golang.org/grpc v1.73.0
89
)
910

1011
require (
11-
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7 // indirect
1212
github.com/miekg/pkcs11 v1.1.1 // indirect
1313
golang.org/x/crypto v0.40.0 // indirect
1414
golang.org/x/net v0.42.0 // indirect

high-throughput/chaincode-go/go.mod

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@ module github.com/hyperledger/fabric-samples/high-throughput/chaincode
22

33
go 1.23.0
44

5-
require (
6-
github.com/hyperledger/fabric-chaincode-go v0.0.0-20230228194215-b84622ba6a7a
7-
github.com/hyperledger/fabric-protos-go v0.3.0
8-
)
5+
require github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0
96

107
require (
11-
github.com/golang/protobuf v1.5.3 // indirect
8+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
9+
github.com/go-openapi/jsonreference v0.21.0 // indirect
10+
github.com/go-openapi/spec v0.21.0 // indirect
11+
github.com/go-openapi/swag v0.23.0 // indirect
12+
github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0 // indirect
13+
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.4 // indirect
14+
github.com/josharian/intern v1.0.0 // indirect
15+
github.com/mailru/easyjson v0.7.7 // indirect
16+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
17+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
18+
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
1219
golang.org/x/net v0.42.0 // indirect
1320
golang.org/x/sys v0.34.0 // indirect
1421
golang.org/x/text v0.27.0 // indirect
1522
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
16-
google.golang.org/grpc v1.56.3 // indirect
23+
google.golang.org/grpc v1.67.0 // indirect
1724
google.golang.org/protobuf v1.36.6 // indirect
25+
gopkg.in/yaml.v3 v3.0.1 // indirect
1826
)
Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,61 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
23
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
4-
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
5-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
6-
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
8-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9-
github.com/hyperledger/fabric-chaincode-go v0.0.0-20230228194215-b84622ba6a7a h1:HwSCxEeiBthwcazcAykGATQ36oG9M+HEQvGLvB7aLvA=
10-
github.com/hyperledger/fabric-chaincode-go v0.0.0-20230228194215-b84622ba6a7a/go.mod h1:TDSu9gxURldEnaGSFbH1eMlfSQBWQcMQfnDBcpQv5lU=
11-
github.com/hyperledger/fabric-protos-go v0.3.0 h1:MXxy44WTMENOh5TI8+PCK2x6pMj47Go2vFRKDHB2PZs=
12-
github.com/hyperledger/fabric-protos-go v0.3.0/go.mod h1:WWnyWP40P2roPmmvxsUXSvVI/CF6vwY1K1UFidnKBys=
4+
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
5+
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
6+
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
7+
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
8+
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
9+
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
10+
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
11+
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
12+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
13+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
14+
github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0 h1:IhkHfrl5X/fVnmB6pWeCYCdIJRi9bxj+WTnVN8DtW3c=
15+
github.com/hyperledger/fabric-chaincode-go/v2 v2.0.0/go.mod h1:PHHaFffjw7p7n9bmCfcm7RqDqYdivNEsJdiNIKZo5Lk=
16+
github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0 h1:rmUoBmciB0GL/miqcbJmJbgp5QTWoJUrZo+CNxrNLF4=
17+
github.com/hyperledger/fabric-contract-api-go/v2 v2.2.0/go.mod h1:FeWeO/jwGjiME7ak3GufqKIcwkejtzrDG4QxbfKydWs=
18+
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.4 h1:YJrd+gMaeY0/vsN0aS0QkEKTivGoUnSRIXxGJ7KI+Pc=
19+
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.4/go.mod h1:bau/6AJhvEcu9GKKYHlDXAxXKzYNfhP6xu2GXuxEcFk=
20+
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
21+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
22+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
23+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
24+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
25+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
26+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
27+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
1328
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1429
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
16-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
30+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
31+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
32+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
33+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
34+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
35+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
36+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
37+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
38+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
39+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
40+
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
41+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
42+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
43+
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
44+
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
1745
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
1846
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
1947
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
2048
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
2149
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
2250
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
23-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2451
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
2552
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
26-
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
27-
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
28-
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
29-
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
53+
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=
54+
google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
3055
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
3156
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
57+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
58+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
59+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
3260
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3361
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)