Skip to content

Commit bd2bb73

Browse files
committed
Revert [FAB-6230] pCLI support for cfg lifecycle
This reverts commit 2263248a220b2fb9762c3b28e8572ffb9a23927a. Change-Id: I0feb9d3c1ac6a8d89fb2da4b3f2e568ae26fa55a Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 525d214 commit bd2bb73

File tree

8 files changed

+122
-428
lines changed

8 files changed

+122
-428
lines changed

peer/chaincode/chaincode.go

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,24 @@ func Cmd(cf *ChaincodeCmdFactory) *cobra.Command {
5050

5151
// Chaincode-related variables.
5252
var (
53-
chaincodeLang string
54-
chaincodeCtorJSON string
55-
chaincodePath string
56-
chaincodeName string
57-
chaincodeUsr string // Not used
58-
chaincodeQueryRaw bool
59-
chaincodeQueryHex bool
60-
customIDGenAlg string
61-
channelID string
62-
chaincodeVersion string
63-
policy string
64-
escc string
65-
vscc string
66-
policyMarshalled []byte
67-
orderingEndpoint string
68-
tls bool
69-
caFile string
70-
transient string
71-
resourceEnvelopeSavePath string
72-
resourceEnvelopeLoadPath string
53+
chaincodeLang string
54+
chaincodeCtorJSON string
55+
chaincodePath string
56+
chaincodeName string
57+
chaincodeUsr string // Not used
58+
chaincodeQueryRaw bool
59+
chaincodeQueryHex bool
60+
customIDGenAlg string
61+
channelID string
62+
chaincodeVersion string
63+
policy string
64+
escc string
65+
vscc string
66+
policyMarshalled []byte
67+
orderingEndpoint string
68+
tls bool
69+
caFile string
70+
transient string
7371
)
7472

7573
var chaincodeCmd = &cobra.Command{
@@ -110,10 +108,6 @@ func resetFlags() {
110108
fmt.Sprint("The name of the endorsement system chaincode to be used for this chaincode"))
111109
flags.StringVarP(&vscc, "vscc", "V", common.UndefinedParamValue,
112110
fmt.Sprint("The name of the verification system chaincode to be used for this chaincode"))
113-
flags.StringVarP(&resourceEnvelopeSavePath, "resourceEnvelopeSavePath", "S", common.UndefinedParamValue,
114-
fmt.Sprint("Specifies the file to save the resource config update to. If not specified, sends config update"))
115-
flags.StringVarP(&resourceEnvelopeLoadPath, "resourceEnvelopeLoadPath", "L", common.UndefinedParamValue,
116-
fmt.Sprint("Specifies the file to load the resource config update from. If not specified, creates a new config update"))
117111
flags.BoolVarP(&getInstalledChaincodes, "installed", "", false,
118112
"Get the installed chaincodes on a peer")
119113
flags.BoolVarP(&getInstantiatedChaincodes, "instantiated", "", false,
@@ -126,7 +120,7 @@ func attachFlags(cmd *cobra.Command, names []string) {
126120
if flag := flags.Lookup(name); flag != nil {
127121
cmdFlags.AddFlag(flag)
128122
} else {
129-
logger.Fatalf("Could not find flag '%s' to attach to command '%s'", name, cmd.Name())
123+
logger.Fatalf("Could not find flag '%s' to attach to commond '%s'", name, cmd.Name())
130124
}
131125
}
132126
}

peer/chaincode/instantiate.go

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717
package chaincode
1818

1919
import (
20+
"errors"
2021
"fmt"
2122

22-
"github.com/hyperledger/fabric/protos/common"
23+
protcommon "github.com/hyperledger/fabric/protos/common"
2324
pb "github.com/hyperledger/fabric/protos/peer"
2425
"github.com/hyperledger/fabric/protos/utils"
25-
"github.com/pkg/errors"
2626
"github.com/spf13/cobra"
2727
"golang.org/x/net/context"
2828
)
@@ -41,17 +41,7 @@ func instantiateCmd(cf *ChaincodeCmdFactory) *cobra.Command {
4141
Long: fmt.Sprint(instantiateDesc),
4242
ValidArgs: []string{"1"},
4343
RunE: func(cmd *cobra.Command, args []string) error {
44-
cf1 := cf
45-
if cf1 == nil {
46-
var err error
47-
cf1, err = InitCmdFactory(true, true)
48-
if err != nil {
49-
return err
50-
}
51-
}
52-
return chaincodeDeploy(cf1, func() error {
53-
return lsccInstantiate(cmd, cf1)
54-
})
44+
return chaincodeDeploy(cmd, args, cf)
5545
},
5646
}
5747
flagList := []string{
@@ -63,15 +53,14 @@ func instantiateCmd(cf *ChaincodeCmdFactory) *cobra.Command {
6353
"policy",
6454
"escc",
6555
"vscc",
66-
"resourceEnvelopeSavePath",
67-
"resourceEnvelopeLoadPath",
6856
}
6957
attachFlags(chaincodeInstantiateCmd, flagList)
58+
7059
return chaincodeInstantiateCmd
7160
}
7261

7362
//instantiate the command via Endorser
74-
func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*common.Envelope, error) {
63+
func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*protcommon.Envelope, error) {
7564
spec, err := getChaincodeSpec(cmd)
7665
if err != nil {
7766
return nil, err
@@ -119,29 +108,26 @@ func instantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) (*common.Envelope,
119108
// chaincodeDeploy instantiates the chaincode. On success, the chaincode name
120109
// (hash) is printed to STDOUT for use by subsequent chaincode-related CLI
121110
// commands.
122-
func chaincodeDeploy(cf *ChaincodeCmdFactory, sendInit sendInitTransaction) error {
111+
func chaincodeDeploy(cmd *cobra.Command, args []string, cf *ChaincodeCmdFactory) error {
123112
if channelID == "" {
124113
return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag")
125114
}
126115
var err error
127-
128-
defer cf.BroadcastClient.Close()
129-
130-
ss := &sigSupport{cf.Signer}
131-
version, config, err := fetchResourceConfig(cf.EndorserClient, ss, channelID)
132-
if err != nil {
133-
return errors.Wrap(err, "failed probing channel version")
134-
}
135-
if version == v11 {
136-
return configBasedLifecycleUpdate(ss, cf, config, sendInit)
116+
if cf == nil {
117+
cf, err = InitCmdFactory(true, true)
118+
if err != nil {
119+
return err
120+
}
137121
}
138-
return sendInit()
139-
}
140-
141-
func lsccInstantiate(cmd *cobra.Command, cf *ChaincodeCmdFactory) error {
122+
defer cf.BroadcastClient.Close()
142123
env, err := instantiate(cmd, cf)
143124
if err != nil {
144125
return err
145126
}
146-
return cf.BroadcastClient.Send(env)
127+
128+
if env != nil {
129+
err = cf.BroadcastClient.Send(env)
130+
}
131+
132+
return err
147133
}

peer/chaincode/instantiate_test.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,16 @@
1717
package chaincode
1818

1919
import (
20-
"errors"
2120
"testing"
2221

23-
"github.com/hyperledger/fabric/peer/common"
24-
"github.com/hyperledger/fabric/protos/peer"
2522
"github.com/stretchr/testify/assert"
2623
)
2724

2825
func TestInstantiateCmd(t *testing.T) {
2926
InitMSP()
3027

31-
newMockCF := func() *ChaincodeCmdFactory {
32-
mockCF, err := getMockChaincodeCmdFactoryWithEnorserResponses(common.MockResponse{Error: errors.New("chaincode error")}, common.MockResponse{
33-
Response: &peer.ProposalResponse{
34-
Response: &peer.Response{Status: 200},
35-
Endorsement: &peer.Endorsement{},
36-
},
37-
})
38-
assert.NoError(t, err, "Error getting mock chaincode command factory")
39-
return mockCF
40-
}
28+
mockCF, err := getMockChaincodeCmdFactory()
29+
assert.NoError(t, err, "Error getting mock chaincode command factory")
4130

4231
// basic function tests
4332
var tests = []struct {
@@ -86,10 +75,10 @@ func TestInstantiateCmd(t *testing.T) {
8675
for _, test := range tests {
8776
t.Run(test.name, func(t *testing.T) {
8877
resetFlags()
89-
cmd := instantiateCmd(newMockCF())
78+
cmd := instantiateCmd(mockCF)
9079
addFlags(cmd)
9180
cmd.SetArgs(test.args)
92-
err := cmd.Execute()
81+
err = cmd.Execute()
9382
checkError(t, err, test.errorExpected, test.errMsg)
9483
})
9584
}

peer/chaincode/invoke_test.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,31 +179,38 @@ func TestInvokeCmdEndorsementFailure(t *testing.T) {
179179

180180
// Returns mock chaincode command factory
181181
func getMockChaincodeCmdFactory() (*ChaincodeCmdFactory, error) {
182-
return getMockChaincodeCmdFactoryWithEnorserResponses(common.MockResponse{
183-
Response: &pb.ProposalResponse{
184-
Response: &pb.Response{Status: 200},
185-
Endorsement: &pb.Endorsement{},
186-
},
187-
})
182+
signer, err := common.GetDefaultSigner()
183+
if err != nil {
184+
return nil, err
185+
}
186+
mockResponse := &pb.ProposalResponse{
187+
Response: &pb.Response{Status: 200},
188+
Endorsement: &pb.Endorsement{},
189+
}
190+
mockEndorserClient := common.GetMockEndorserClient(mockResponse, nil)
191+
mockBroadcastClient := common.GetMockBroadcastClient(nil)
192+
mockCF := &ChaincodeCmdFactory{
193+
EndorserClient: mockEndorserClient,
194+
Signer: signer,
195+
BroadcastClient: mockBroadcastClient,
196+
}
197+
return mockCF, nil
188198
}
189199

190200
// Returns mock chaincode command factory that is constructed with an endorser
191201
// client that returns an error for proposal request
192202
func getMockChaincodeCmdFactoryWithErr() (*ChaincodeCmdFactory, error) {
193-
return getMockChaincodeCmdFactoryWithEnorserResponses(common.MockResponse{
194-
Error: errors.New("invoke error"),
195-
})
196-
}
197-
198-
func getMockChaincodeCmdFactoryWithEnorserResponses(responses ...common.MockResponse) (*ChaincodeCmdFactory, error) {
199203
signer, err := common.GetDefaultSigner()
200204
if err != nil {
201205
return nil, err
202206
}
203-
mockEndorserClient := common.GetMockMultiEndorserClient(responses...)
207+
208+
errMsg := "invoke error"
209+
mockEndorerClient := common.GetMockEndorserClient(nil, errors.New(errMsg))
204210
mockBroadcastClient := common.GetMockBroadcastClient(nil)
211+
205212
mockCF := &ChaincodeCmdFactory{
206-
EndorserClient: mockEndorserClient,
213+
EndorserClient: mockEndorerClient,
207214
Signer: signer,
208215
BroadcastClient: mockBroadcastClient,
209216
}

peer/chaincode/resources.go

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ package chaincode
99
import (
1010
"bytes"
1111
"fmt"
12-
"io/ioutil"
13-
"os"
1412
"strings"
1513
"time"
1614

1715
"github.com/golang/protobuf/proto"
18-
"github.com/hyperledger/fabric/common/cauthdsl"
1916
"github.com/hyperledger/fabric/common/resourcesconfig"
20-
update2 "github.com/hyperledger/fabric/common/tools/configtxlator/update"
2117
"github.com/hyperledger/fabric/common/util"
2218
"github.com/hyperledger/fabric/core/chaincode/shim"
2319
"github.com/hyperledger/fabric/core/scc/lscc"
24-
"github.com/hyperledger/fabric/msp"
2520
"github.com/hyperledger/fabric/protos/common"
2621
"github.com/hyperledger/fabric/protos/peer"
2722
"github.com/hyperledger/fabric/protos/utils"
@@ -344,105 +339,3 @@ func getModPolicies(ccGrp *common.ConfigGroup, update ccUpdate) map[string]strin
344339
}
345340
return modPolicies
346341
}
347-
348-
func configBasedLifecycleUpdate(ss *sigSupport, cf *ChaincodeCmdFactory, config *common.Config, sendInit sendInitTransaction) error {
349-
var env *common.Envelope
350-
hash, err := fetchCCID(ss, cf.EndorserClient, chaincodeName, chaincodeVersion)
351-
if err != nil {
352-
return err
353-
}
354-
var pol *common.SignaturePolicyEnvelope
355-
if policy != "" {
356-
pol, err = cauthdsl.FromString(policy)
357-
if err != nil {
358-
return err
359-
}
360-
}
361-
362-
if policy == "" && (vscc == "vscc" || vscc == "") {
363-
return errors.New("policy must be specified when vscc flag is set to 'vscc' or missing")
364-
}
365-
366-
update := ccUpdate{
367-
policy: pol,
368-
computeDelta: update2.Compute,
369-
ccName: chaincodeName,
370-
oldConfig: config,
371-
version: chaincodeVersion,
372-
endorsement: escc,
373-
validation: vscc,
374-
hash: hash,
375-
chainID: channelID,
376-
SignatureSupport: &sigSupport{cf.Signer},
377-
}
378-
if resourceEnvelopeLoadPath == "" {
379-
// We're making a new config update
380-
env = update.buildCCUpdateEnvelope()
381-
} else {
382-
// We're loading the config update from disk
383-
updateEnv, err := loadEnvelope(resourceEnvelopeLoadPath)
384-
if err != nil {
385-
return err
386-
}
387-
// and appending our signature to it
388-
updateEnv = update.appendSignature(updateEnv)
389-
// and putting it back into an envelope
390-
env = update.updateIntoEnvelope(updateEnv)
391-
}
392-
if resourceEnvelopeSavePath != "" {
393-
return saveEnvelope(env)
394-
}
395-
if err := cf.BroadcastClient.Send(env); err != nil {
396-
return err
397-
}
398-
return sendInit()
399-
}
400-
401-
func loadEnvelope(file string) (*common.ConfigUpdateEnvelope, error) {
402-
data, err := ioutil.ReadFile(file)
403-
if err != nil {
404-
return nil, err
405-
}
406-
env := &common.Envelope{}
407-
if err := proto.Unmarshal(data, env); err != nil {
408-
return nil, err
409-
}
410-
payload := &common.Payload{}
411-
if err := proto.Unmarshal(env.Payload, payload); err != nil {
412-
return nil, err
413-
}
414-
update := &common.ConfigUpdateEnvelope{}
415-
if err := proto.Unmarshal(payload.Data, update); err != nil {
416-
return nil, err
417-
}
418-
return update, nil
419-
}
420-
421-
func saveEnvelope(env *common.Envelope) error {
422-
f, err := os.Create(resourceEnvelopeSavePath)
423-
if err != nil {
424-
return errors.Errorf("failed saving resource envelope to file %s: %v", resourceEnvelopeSavePath, err)
425-
}
426-
if _, err := f.Write(utils.MarshalOrPanic(env)); err != nil {
427-
return errors.Errorf("failed saving resource envelope to file %s: %v", resourceEnvelopeSavePath, err)
428-
}
429-
fmt.Printf(`Saved config update envelope to %s.
430-
You can now either:
431-
1) Append your signature using --resourceEnvelopeSave along with --resourceEnvelopeLoad
432-
2) Submit a transaction using only --resourceEnvelopeLoad
433-
`, f.Name())
434-
return nil
435-
}
436-
437-
type sigSupport struct {
438-
msp.SigningIdentity
439-
}
440-
441-
// NewSignatureHeader creates a new signature header
442-
func (s *sigSupport) NewSignatureHeader() (*common.SignatureHeader, error) {
443-
sID, err := s.Serialize()
444-
if err != nil {
445-
return nil, err
446-
}
447-
return utils.MakeSignatureHeader(sID, utils.CreateNonceOrPanic()), nil
448-
}

0 commit comments

Comments
 (0)