diff --git a/bddtests/chaincode.go b/bddtests/chaincode.go index c137fdbdfe0..c132f985bdd 100644 --- a/bddtests/chaincode.go +++ b/bddtests/chaincode.go @@ -52,5 +52,5 @@ func createProposalForChaincode(ccChaincodeDeploymentSpec *pb.ChaincodeDeploymen uuid := createPropsalID() // make proposal - return putils.CreateChaincodeProposal(uuid, lcChaincodeInvocationSpec, creator) + return putils.CreateChaincodeProposal(uuid, util.GetTestChainID(), lcChaincodeInvocationSpec, creator) } diff --git a/core/chaincode/exectransaction_test.go b/core/chaincode/exectransaction_test.go index 07e9602cd6a..dff2e39519d 100644 --- a/core/chaincode/exectransaction_test.go +++ b/core/chaincode/exectransaction_test.go @@ -128,7 +128,7 @@ func endTxSimulationCDS(txid string, txsim ledger.TxSimulator, payload []byte, c return err } // get a proposal - we need it to get a transaction - prop, err := putils.CreateProposalFromCDS(txid, cds, ss) + prop, err := putils.CreateProposalFromCDS(txid, util.GetTestChainID(), cds, ss) if err != nil { return err } @@ -143,7 +143,7 @@ func endTxSimulationCIS(txid string, txsim ledger.TxSimulator, payload []byte, c return err } // get a proposal - we need it to get a transaction - prop, err := putils.CreateProposalFromCIS(txid, cis, ss) + prop, err := putils.CreateProposalFromCIS(txid, util.GetTestChainID(), cis, ss) if err != nil { return err } diff --git a/core/committer/noopssinglechain/client.go b/core/committer/noopssinglechain/client.go index 997e60a336c..599bec15aee 100644 --- a/core/committer/noopssinglechain/client.go +++ b/core/committer/noopssinglechain/client.go @@ -23,6 +23,7 @@ import ( "github.com/hyperledger/fabric/core/chaincode" "github.com/hyperledger/fabric/core/committer" "github.com/hyperledger/fabric/core/ledger/kvledger" + "github.com/hyperledger/fabric/core/util" "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/orderer" putils "github.com/hyperledger/fabric/protos/utils" @@ -194,6 +195,7 @@ func (d *DeliverService) seekOldest() error { Seek: &orderer.SeekInfo{ Start: orderer.SeekInfo_OLDEST, WindowSize: d.windowSize, + ChainID: []byte(util.GetTestChainID()), }, }, }) @@ -206,6 +208,7 @@ func (d *DeliverService) seekLatestFromCommitter(height uint64) error { Start: orderer.SeekInfo_SPECIFIED, WindowSize: d.windowSize, SpecifiedNumber: height, + ChainID: []byte(util.GetTestChainID()), }, }, }) diff --git a/core/endorser/endorser_test.go b/core/endorser/endorser_test.go index f05e1542e1c..564727f3693 100644 --- a/core/endorser/endorser_test.go +++ b/core/endorser/endorser_test.go @@ -123,7 +123,7 @@ func closeListenerAndSleep(l net.Listener) { //Currently supported only for Invokes (Queries still go through devops client) func getProposal(cis *pb.ChaincodeInvocationSpec, creator []byte) (*pb.Proposal, error) { uuid := util.GenerateUUID() - return pbutils.CreateChaincodeProposal(uuid, cis, creator) + return pbutils.CreateChaincodeProposal(uuid, util.GetTestChainID(), cis, creator) } //getDeployProposal gets the proposal for the chaincode deployment diff --git a/core/ledger/kvledger/example/app.go b/core/ledger/kvledger/example/app.go index d0bfb58f4d9..1dc87faf3c4 100644 --- a/core/ledger/kvledger/example/app.go +++ b/core/ledger/kvledger/example/app.go @@ -114,7 +114,7 @@ func (app *App) QueryBalances(accounts []string) ([]int, error) { } func constructTransaction(simulationResults []byte) *common.Envelope { - txEnv, _ := ptestutils.ConstructSingedTxEnvWithDefaultSigner(util.GenerateUUID(), "foo", simulationResults, nil, nil) + txEnv, _ := ptestutils.ConstructSingedTxEnvWithDefaultSigner(util.GenerateUUID(), util.GetTestChainID(), "foo", simulationResults, nil, nil) return txEnv } diff --git a/core/ledger/testutil/test_helper.go b/core/ledger/testutil/test_helper.go index f91b788641f..5abf4e42f69 100644 --- a/core/ledger/testutil/test_helper.go +++ b/core/ledger/testutil/test_helper.go @@ -63,9 +63,9 @@ func ConstructTestTransaction(t *testing.T, simulationResults []byte, sign bool) ccName := "foo" txID := util.GenerateUUID() if sign { - return ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, ccName, simulationResults, nil, nil) + return ptestutils.ConstructSingedTxEnvWithDefaultSigner(txID, util.GetTestChainID(), ccName, simulationResults, nil, nil) } - return ptestutils.ConstructUnsingedTxEnv(txID, ccName, simulationResults, nil, nil) + return ptestutils.ConstructUnsingedTxEnv(txID, util.GetTestChainID(), ccName, simulationResults, nil, nil) } // ComputeBlockHash computes the crypto-hash of a block diff --git a/core/peer/fullflow_test.go b/core/peer/fullflow_test.go index ae581791577..b09a557b195 100644 --- a/core/peer/fullflow_test.go +++ b/core/peer/fullflow_test.go @@ -39,7 +39,7 @@ func getProposal() (*peer.Proposal, error) { uuid := util.GenerateUUID() - return utils.CreateProposalFromCIS(uuid, cis, signerSerialized) + return utils.CreateProposalFromCIS(uuid, util.GetTestChainID(), cis, signerSerialized) } func TestGoodPath(t *testing.T) { diff --git a/core/system_chaincode/escc/endorser_onevalidsignature_test.go b/core/system_chaincode/escc/endorser_onevalidsignature_test.go index a3c0677efbb..bc3e0c8a834 100644 --- a/core/system_chaincode/escc/endorser_onevalidsignature_test.go +++ b/core/system_chaincode/escc/endorser_onevalidsignature_test.go @@ -117,7 +117,7 @@ func TestInvoke(t *testing.T) { uuid := util.GenerateUUID() - proposal, err := putils.CreateChaincodeProposal(uuid, cis, sIdBytes) + proposal, err := putils.CreateChaincodeProposal(uuid, util.GetTestChainID(), cis, sIdBytes) if err != nil { t.Fail() t.Fatalf("couldn't generate chaincode proposal: err %s", err) diff --git a/core/system_chaincode/vscc/validator_onevalidsignature_test.go b/core/system_chaincode/vscc/validator_onevalidsignature_test.go index 9e892f0e033..76ac67f935f 100644 --- a/core/system_chaincode/vscc/validator_onevalidsignature_test.go +++ b/core/system_chaincode/vscc/validator_onevalidsignature_test.go @@ -35,7 +35,7 @@ func createTx() (*common.Envelope, error) { uuid := util.GenerateUUID() - prop, err := utils.CreateProposalFromCIS(uuid, cis, sid) + prop, err := utils.CreateProposalFromCIS(uuid, util.GetTestChainID(), cis, sid) if err != nil { return nil, err } diff --git a/core/util/utils.go b/core/util/utils.go index d8eca4752cc..f0553c295ad 100644 --- a/core/util/utils.go +++ b/core/util/utils.go @@ -140,3 +140,10 @@ func ArrayToChaincodeArgs(args []string) [][]byte { } return bargs } + +const testchainid = "**TEST_CHAINID**" + +//GetTestChainID returns the CHAINID constant in use by orderer +func GetTestChainID() string { + return testchainid +} diff --git a/peer/chaincode/chaincode.go b/peer/chaincode/chaincode.go index 8e420c5b835..1629eaaedf8 100755 --- a/peer/chaincode/chaincode.go +++ b/peer/chaincode/chaincode.go @@ -19,6 +19,7 @@ package chaincode import ( "fmt" + "github.com/hyperledger/fabric/core/util" "github.com/hyperledger/fabric/peer/common" "github.com/op/go-logging" "github.com/spf13/cobra" @@ -48,6 +49,8 @@ func Cmd() *cobra.Command { fmt.Sprint("Username for chaincode operations when security is enabled")) flags.StringVarP(&customIDGenAlg, "tid", "t", common.UndefinedParamValue, fmt.Sprint("Name of a custom ID generation algorithm (hashing and decoding) e.g. sha256base64")) + flags.StringVarP(&chainID, "chainID", "C", util.GetTestChainID(), + fmt.Sprint("The chain on which this command should be executed")) chaincodeCmd.AddCommand(deployCmd()) chaincodeCmd.AddCommand(invokeCmd()) @@ -67,6 +70,7 @@ var ( chaincodeQueryHex bool chaincodeAttributesJSON string customIDGenAlg string + chainID string ) var chaincodeCmd = &cobra.Command{ diff --git a/peer/chaincode/common.go b/peer/chaincode/common.go index 803b2ce5684..ce4bc42a931 100755 --- a/peer/chaincode/common.go +++ b/peer/chaincode/common.go @@ -191,7 +191,7 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool) (err uuid := cutil.GenerateUUID() var prop *pb.Proposal - prop, err = putils.CreateProposalFromCIS(uuid, invocation, creator) + prop, err = putils.CreateProposalFromCIS(uuid, chainID, invocation, creator) if err != nil { return fmt.Errorf("Error creating proposal %s: %s\n", chainFuncName, err) } diff --git a/peer/chaincode/deploy.go b/peer/chaincode/deploy.go index bbac2eae111..c7c89efb152 100755 --- a/peer/chaincode/deploy.go +++ b/peer/chaincode/deploy.go @@ -80,7 +80,7 @@ func deploy(cmd *cobra.Command) (*protcommon.Envelope, error) { uuid := util.GenerateUUID() - prop, err := utils.CreateProposalFromCDS(uuid, cds, creator) + prop, err := utils.CreateProposalFromCDS(uuid, chainID, cds, creator) if err != nil { return nil, fmt.Errorf("Error creating proposal %s: %s\n", chainFuncName, err) } diff --git a/protos/testutils/txtestutils.go b/protos/testutils/txtestutils.go index 47ac6dabfe3..40d828d0d23 100644 --- a/protos/testutils/txtestutils.go +++ b/protos/testutils/txtestutils.go @@ -79,18 +79,18 @@ func getMSPMgrConfigFile() (string, error) { // ConstructSingedTxEnvWithDefaultSigner constructs a transaction envelop for tests with a default signer. // This method helps other modules to construct a transaction with supplied parameters -func ConstructSingedTxEnvWithDefaultSigner(txid string, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) { - return ConstructSingedTxEnv(txid, ccName, simulationResults, events, visibility, signer) +func ConstructSingedTxEnvWithDefaultSigner(txid string, chainID, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) { + return ConstructSingedTxEnv(txid, chainID, ccName, simulationResults, events, visibility, signer) } // ConstructSingedTxEnv constructs a transaction envelop for tests -func ConstructSingedTxEnv(txid string, ccName string, simulationResults []byte, events []byte, visibility []byte, signer msp.SigningIdentity) (*common.Envelope, error) { +func ConstructSingedTxEnv(txid string, chainID string, ccName string, simulationResults []byte, events []byte, visibility []byte, signer msp.SigningIdentity) (*common.Envelope, error) { ss, err := signer.Serialize() if err != nil { return nil, err } - prop, err := putils.CreateChaincodeProposal(txid, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, ss) + prop, err := putils.CreateChaincodeProposal(txid, chainID, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, ss) if err != nil { return nil, err } @@ -108,8 +108,8 @@ func ConstructSingedTxEnv(txid string, ccName string, simulationResults []byte, } // ConstructUnsingedTxEnv creates a Transaction envelope from given inputs -func ConstructUnsingedTxEnv(txid string, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) { - prop, err := putils.CreateChaincodeProposal(txid, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, nil) +func ConstructUnsingedTxEnv(txid string, chainID string, ccName string, simulationResults []byte, events []byte, visibility []byte) (*common.Envelope, error) { + prop, err := putils.CreateChaincodeProposal(txid, chainID, &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeID: &pb.ChaincodeID{Name: ccName}}}, nil) if err != nil { return nil, err } diff --git a/protos/utils/proputils.go b/protos/utils/proputils.go index c6a0efdc361..e6428d7440c 100644 --- a/protos/utils/proputils.go +++ b/protos/utils/proputils.go @@ -196,7 +196,7 @@ func GetEnvelope(bytes []byte) (*common.Envelope, error) { } // CreateChaincodeProposal creates a proposal from given input -func CreateChaincodeProposal(txid string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) { +func CreateChaincodeProposal(txid string, chainID string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) { ccHdrExt := &peer.ChaincodeHeaderExtension{ChaincodeID: cis.ChaincodeSpec.ChaincodeID} ccHdrExtBytes, err := proto.Marshal(ccHdrExt) if err != nil { @@ -222,6 +222,7 @@ func CreateChaincodeProposal(txid string, cis *peer.ChaincodeInvocationSpec, cre hdr := &common.Header{ChainHeader: &common.ChainHeader{Type: int32(common.HeaderType_ENDORSER_TRANSACTION), TxID: txid, + ChainID: []byte(chainID), Extension: ccHdrExtBytes}, SignatureHeader: &common.SignatureHeader{Nonce: nonce, Creator: creator}} @@ -372,12 +373,12 @@ func GetActionFromEnvelope(envBytes []byte) (*peer.ChaincodeAction, error) { } // CreateProposalFromCIS returns a proposal given a serialized identity and a ChaincodeInvocationSpec -func CreateProposalFromCIS(txid string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) { - return CreateChaincodeProposal(txid, cis, creator) +func CreateProposalFromCIS(txid string, chainID string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) { + return CreateChaincodeProposal(txid, chainID, cis, creator) } // CreateProposalFromCDS returns a proposal given a serialized identity and a ChaincodeDeploymentSpec -func CreateProposalFromCDS(txid string, cds *peer.ChaincodeDeploymentSpec, creator []byte) (*peer.Proposal, error) { +func CreateProposalFromCDS(txid string, chainID string, cds *peer.ChaincodeDeploymentSpec, creator []byte) (*peer.Proposal, error) { b, err := proto.Marshal(cds) if err != nil { return nil, err @@ -391,5 +392,5 @@ func CreateProposalFromCDS(txid string, cds *peer.ChaincodeDeploymentSpec, creat CtorMsg: &peer.ChaincodeInput{Args: [][]byte{[]byte("deploy"), []byte("default"), b}}}} //...and get the proposal for it - return CreateProposalFromCIS(txid, lcccSpec, creator) + return CreateProposalFromCIS(txid, chainID, lcccSpec, creator) } diff --git a/protos/utils/proputils_test.go b/protos/utils/proputils_test.go index dfb88c6a35b..2750062862c 100644 --- a/protos/utils/proputils_test.go +++ b/protos/utils/proputils_test.go @@ -44,7 +44,7 @@ func createCIS() *pb.ChaincodeInvocationSpec { func TestProposal(t *testing.T) { uuid := util.GenerateUUID() // create a proposal from a ChaincodeInvocationSpec - prop, err := CreateChaincodeProposal(uuid, createCIS(), []byte("creator")) + prop, err := CreateChaincodeProposal(uuid, util.GetTestChainID(), createCIS(), []byte("creator")) if err != nil { t.Fatalf("Could not create chaincode proposal, err %s\n", err) return @@ -198,7 +198,7 @@ func TestProposalResponse(t *testing.T) { func TestEnvelope(t *testing.T) { // create a proposal from a ChaincodeInvocationSpec uuid := util.GenerateUUID() - prop, err := CreateChaincodeProposal(uuid, createCIS(), signerSerialized) + prop, err := CreateChaincodeProposal(uuid, util.GetTestChainID(), createCIS(), signerSerialized) if err != nil { t.Fatalf("Could not create chaincode proposal, err %s\n", err) return