Skip to content

Commit ffbf604

Browse files
committed
[FAB-3344] Fix CSCC error messages
This commit fixes the error messages of the CSCC: 1. JoinChannel call provided with genesis block, hence args[1] is a block and not channel it as expected in error message, hence to prevent putting entire block into error message, channel id is extracted instead. 2. GetChannel doesn't get any parameters and therefore in order to avoid panic on accessing non existing args[1], this part of error message is removed. Change-Id: Ifcfc543afa5d694c963a65d688056e4d072b9379 Signed-off-by: Artem Barger <[email protected]>
1 parent 88ac3ba commit ffbf604

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

core/scc/cscc/configure.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ func (e *PeerConfiger) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
107107
case JoinChain:
108108
// 2. check local MSP Admins policy
109109
if err = e.policyChecker.CheckPolicyNoChannel(mgmt.Admins, sp); err != nil {
110-
return shim.Error(fmt.Sprintf("\"JoinChain\" request failed authorization check for channel [%s]: [%s]", args[1], err))
110+
cid, e := utils.GetChainIDFromBlockBytes(args[1])
111+
errorString := fmt.Sprintf("\"JoinChain\" request failed authorization check "+
112+
"for channel [%s]: [%s]", cid, err)
113+
if e != nil {
114+
errorString = fmt.Sprintf("\"JoinChain\" request failed authorization [%s] and unable "+
115+
"to extract channel id from the block due to [%s]", err, e)
116+
}
117+
return shim.Error(errorString)
111118
}
112119

113120
return joinChain(args[1])
@@ -127,7 +134,7 @@ func (e *PeerConfiger) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
127134
case GetChannels:
128135
// 2. check local MSP Members policy
129136
if err = e.policyChecker.CheckPolicyNoChannel(mgmt.Members, sp); err != nil {
130-
return shim.Error(fmt.Sprintf("\"GetChannels\" request failed authorization check for channel [%s]: [%s]", args[1], err))
137+
return shim.Error(fmt.Sprintf("\"GetChannels\" request failed authorization check: [%s]", err))
131138
}
132139

133140
return getChannels()

protos/utils/blockutils.go

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ import (
2323
cb "github.com/hyperledger/fabric/protos/common"
2424
)
2525

26+
// GetChainIDFromBlockBytes returns chain ID given byte array which represents the block
27+
func GetChainIDFromBlockBytes(bytes []byte) (string, error) {
28+
block, err := GetBlockFromBlockBytes(bytes)
29+
if err != nil {
30+
return "", err
31+
}
32+
33+
return GetChainIDFromBlock(block)
34+
}
35+
2636
// GetChainIDFromBlock returns chain ID in the block
2737
func GetChainIDFromBlock(block *cb.Block) (string, error) {
2838
if block.Data == nil || block.Data.Data == nil || len(block.Data.Data) == 0 {

0 commit comments

Comments
 (0)