Skip to content

Commit a5714ce

Browse files
Srinivasan MuralidharanGerrit Code Review
authored andcommitted
Merge "Change default visibility"
2 parents bcc43d6 + 7d59fd7 commit a5714ce

File tree

5 files changed

+34
-32
lines changed

5 files changed

+34
-32
lines changed

core/common/validation/msgvalidation.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,16 @@ func validateChaincodeProposalMessage(prop *pb.Proposal, hdr *common.Header) (*p
4646
// TODO: should we even do this? If so, using which interface?
4747

4848
// - ensure that the visibility field has some value we understand
49-
// TODO: we need to define visibility fields first
50-
51-
// TODO: should we check the payload as well?
49+
// currently the fabric only supports full visibility: this means that
50+
// there are no restrictions on which parts of the proposal payload will
51+
// be visible in the final transaction; this default approach requires
52+
// no additional instructions in the PayloadVisibility field which is
53+
// therefore expected to be nil; however the fabric may be extended to
54+
// encode more elaborate visibility mechanisms that shall be encoded in
55+
// this field (and handled appropriately by the peer)
56+
if chaincodeHdrExt.PayloadVisibility != nil {
57+
return nil, fmt.Errorf("Invalid payload visibility field")
58+
}
5259

5360
return chaincodeHdrExt, nil
5461
}

core/endorser/endorser.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,7 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
271271
// ProcessProposal process the Proposal
272272
func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedProposal) (*pb.ProposalResponse, error) {
273273
// at first, we check whether the message is valid
274-
prop, _, hdrExt, err := validation.ValidateProposalMessage(signedProp)
275-
if err != nil {
276-
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
277-
}
278-
279-
hdr, err := putils.GetHeader(prop.Header)
274+
prop, hdr, hdrExt, err := validation.ValidateProposalMessage(signedProp)
280275
if err != nil {
281276
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
282277
}
@@ -325,8 +320,6 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
325320
// to validate the supplied action before endorsing it
326321

327322
//1 -- simulate
328-
//TODO what do we do with response ? We need it for Invoke responses for sure
329-
//Which field in PayloadResponse will carry return value ?
330323
cd, res, simulationResult, ccevent, err := e.simulateProposal(ctx, chainID, txid, prop, hdrExt.ChaincodeId, txsim)
331324
if err != nil {
332325
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
@@ -346,7 +339,6 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
346339
}
347340
}
348341

349-
//TODO what do we do with response ? We need it for Invoke responses for sure
350342
// Set the proposal response payload - it
351343
// contains the "return value" from the
352344
// chaincode invocation

core/scc/escc/endorser_onevalidsignature.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ func (e *EndorserOneValidSignature) Init(stub shim.ChaincodeStubInterface) pb.Re
5252
// args[0] - function name (not used now)
5353
// args[1] - serialized Header object
5454
// args[2] - serialized ChaincodeProposalPayload object
55-
// args[3] - binary blob of simulation results
56-
// args[4] - serialized events (optional)
57-
// args[5] - payloadVisibility (optional)
55+
// args[3] - result of executing chaincode
56+
// args[4] - binary blob of simulation results
57+
// args[5] - serialized events
58+
// args[6] - payloadVisibility
5859
//
5960
// NOTE: this chaincode is meant to sign another chaincode's simulation
6061
// results. It should not manipulate state as any state change will be
@@ -119,11 +120,15 @@ func (e *EndorserOneValidSignature) Invoke(stub shim.ChaincodeStubInterface) pb.
119120
}
120121

121122
// Handle payload visibility (it's an optional argument)
122-
visibility := []byte("") // TODO: when visibility is properly defined, replace with the default
123+
// currently the fabric only supports full visibility: this means that
124+
// there are no restrictions on which parts of the proposal payload will
125+
// be visible in the final transaction; this default approach requires
126+
// no additional instructions in the PayloadVisibility field; however
127+
// the fabric may be extended to encode more elaborate visibility
128+
// mechanisms that shall be encoded in this field (and handled
129+
// appropriately by the peer)
130+
var visibility []byte
123131
if len(args) > 6 {
124-
if args[6] == nil {
125-
return shim.Error("serialized events are null")
126-
}
127132
visibility = args[6]
128133
}
129134

core/scc/escc/endorser_onevalidsignature_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,15 @@ func TestInvoke(t *testing.T) {
186186
}
187187

188188
// success test 3: invocation with mandatory args + events and visibility
189-
visibility := []byte("visibility")
190-
191-
args = [][]byte{[]byte(""), proposal.Header, proposal.Payload, successRes, simRes, events, visibility}
189+
args = [][]byte{[]byte(""), proposal.Header, proposal.Payload, successRes, simRes, events, nil}
192190
res = stub.MockInvoke("1", args)
193191
if res.Status != shim.OK {
194192
t.Fail()
195193
t.Fatalf("escc invoke failed with: %s", res.Message)
196194
return
197195
}
198196

199-
err = validateProposalResponse(res.Payload, proposal, visibility, successResponse, simRes, events)
197+
err = validateProposalResponse(res.Payload, proposal, []byte{}, successResponse, simRes, events)
200198
if err != nil {
201199
t.Fail()
202200
t.Fatalf("%s", err)

protos/utils/txutils.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ func GetBytesProposalPayloadForTx(payload *peer.ChaincodeProposalPayload, visibi
253253
return nil, errors.New("Failure while marshalling the ChaincodeProposalPayload!")
254254
}
255255

256-
// TODO: handle payload visibility - it needs to be defined first!
257-
// here, as an example, I'll code the visibility policy that allows the
258-
// full header but only the hash of the payload
259-
260-
digest, err := factory.GetDefaultOrPanic().Hash(cppBytes, &bccsp.SHAOpts{})
261-
if err != nil {
262-
return nil, fmt.Errorf("Failed computing digest [%s]", err)
263-
}
264-
return digest, nil
256+
// currently the fabric only supports full visibility: this means that
257+
// there are no restrictions on which parts of the proposal payload will
258+
// be visible in the final transaction; this default approach requires
259+
// no additional instructions in the PayloadVisibility field; however
260+
// the fabric may be extended to encode more elaborate visibility
261+
// mechanisms that shall be encoded in this field (and handled
262+
// appropriately by the peer)
263+
264+
return cppBytes, nil
265265
}
266266

267267
// GetProposalHash2 gets the proposal hash - this version

0 commit comments

Comments
 (0)