Skip to content

Commit 67ea104

Browse files
committed
use struct's context
Signed-off-by: Angelo De Caro <[email protected]>
1 parent c69666f commit 67ea104

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Diff for: platform/fabric/chaincode.go

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func (i *ChaincodeDiscover) WithFilterByMSPIDs(mspIDs ...string) *ChaincodeDisco
146146
return i
147147
}
148148

149+
func (i *ChaincodeDiscover) WithContext(context context.Context) *ChaincodeDiscover {
150+
i.ChaincodeDiscover.WithContext(context)
151+
return i
152+
}
153+
149154
type ChaincodeInvocation struct {
150155
driver.ChaincodeInvocation
151156
}

Diff for: platform/fabric/core/generic/chaincode/discovery.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ type Discovery struct {
2929
QueryForPeers bool
3030

3131
DefaultTTL time.Duration
32+
Context context.Context
3233
}
3334

3435
func NewDiscovery(chaincode *Chaincode) *Discovery {
3536
// set key to the concatenation of chaincode name and version
3637
return &Discovery{
3738
chaincode: chaincode,
3839
DefaultTTL: chaincode.ChannelConfig.DiscoveryDefaultTTLS(),
40+
Context: context.Background(),
3941
}
4042
}
4143

@@ -230,7 +232,7 @@ func (d *Discovery) query(req *discovery.Request) (discovery.Response, error) {
230232
ClientIdentity: signerRaw,
231233
ClientTlsCertHash: ClientTLSCertHash,
232234
}
233-
timeout, cancel := context.WithTimeout(context.Background(), d.chaincode.ChannelConfig.DiscoveryTimeout())
235+
timeout, cancel := context.WithTimeout(d.Context, d.chaincode.ChannelConfig.DiscoveryTimeout())
234236
defer cancel()
235237
cl, err := pc.DiscoveryClient()
236238
if err != nil {
@@ -318,6 +320,10 @@ func (d *Discovery) ChaincodeVersion() (string, error) {
318320
return "", errors.Errorf("chaincode [%s] not found", d.chaincode.name)
319321
}
320322

323+
func (d *Discovery) WithContext(context context.Context) {
324+
d.Context = context
325+
}
326+
321327
func ccCall(ccNames ...string) []*peer.ChaincodeCall {
322328
var call []*peer.ChaincodeCall
323329
for _, ccName := range ccNames {

Diff for: platform/fabric/core/generic/chaincode/invoke.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func NewInvoke(chaincode *Chaincode, newChaincodeDiscover NewChaincodeDiscoverFu
6363
NumRetries: int(chaincode.NumRetries),
6464
RetrySleep: chaincode.RetrySleep,
6565
NewChaincodeDiscover: newChaincodeDiscover,
66+
Context: context.Background(),
6667
}
6768
}
6869

@@ -316,6 +317,8 @@ func (i *Invoke) prepare(query bool) (string, *pb.Proposal, []*pb.ProposalRespon
316317
i.EndorsersMSPIDs...,
317318
).WithImplicitCollections(
318319
i.ImplicitCollectionMSPIDs...,
320+
).WithContext(
321+
i.Context,
319322
)
320323
if query {
321324
discovery.WithForQuery()
@@ -473,7 +476,8 @@ func (i *Invoke) collectResponses(endorserClients []pb.EndorserClient, signedPro
473476
for _, endorser := range endorserClients {
474477
go func(endorser pb.EndorserClient) {
475478
defer wg.Done()
476-
proposalResp, err := endorser.ProcessProposal(context.Background(), signedProposal)
479+
// TODO: we could evaluate the policy already here after we get a result to see if still need more answers
480+
proposalResp, err := endorser.ProcessProposal(i.Context, signedProposal)
477481
if err != nil {
478482
errorCh <- err
479483
return
@@ -553,7 +557,7 @@ func (i *Invoke) broadcast(txID string, env *common.Envelope) error {
553557
if err := i.Chaincode.Broadcaster.Broadcast(i.Context, env); err != nil {
554558
return err
555559
}
556-
return i.Chaincode.Finality.IsFinal(context.Background(), txID)
560+
return i.Chaincode.Finality.IsFinal(i.Context, txID)
557561
}
558562

559563
func (i *Invoke) checkQueryPolicy(errs []error, successes int, n int) error {

Diff for: platform/fabric/driver/chaincode.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type ChaincodeDiscover interface {
9292
WithImplicitCollections(mspIDs ...string) ChaincodeDiscover
9393
WithForQuery() ChaincodeDiscover
9494
ChaincodeVersion() (string, error)
95+
WithContext(ctx context.Context)
9596
}
9697

9798
// Chaincode exposes chaincode-related functions

0 commit comments

Comments
 (0)