Skip to content

Commit

Permalink
[FAB-17123] Revert FAB-17038
Browse files Browse the repository at this point in the history
This reverts commit 3ec743b.

Change-Id: I0d375711eabc5d48b90afd29e82278b2745d7bc4
Signed-off-by: Danny Cao <dcao@us.ibm.com>
  • Loading branch information
caod123 authored and mastersingh24 committed Nov 22, 2019
1 parent fc86d1a commit 8d073c1
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 42 deletions.
5 changes: 3 additions & 2 deletions core/chaincode/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"

cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/flogging"
Expand Down Expand Up @@ -47,8 +48,8 @@ const (
)

var (
DefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
DefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: DefaultEndorsementPolicyRef,
},
})
Expand Down
13 changes: 7 additions & 6 deletions core/chaincode/lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/channelconfig"
Expand Down Expand Up @@ -609,8 +610,8 @@ var _ = Describe("ExternalFunctions", func() {
Expect(proto.Equal(committedDefinition.ValidationInfo, &lb.ChaincodeValidationInfo{
ValidationPlugin: "vscc",
ValidationParameter: protoutil.MarshalOrPanic(
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "/Channel/Application/Endorsement",
},
}),
Expand Down Expand Up @@ -875,8 +876,8 @@ var _ = Describe("ExternalFunctions", func() {
testDefinition.EndorsementInfo.EndorsementPlugin = "escc"
testDefinition.ValidationInfo.ValidationPlugin = "vscc"
testDefinition.ValidationInfo.ValidationParameter = protoutil.MarshalOrPanic(
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "/Channel/Application/Endorsement",
},
})
Expand Down Expand Up @@ -1044,8 +1045,8 @@ var _ = Describe("ExternalFunctions", func() {
testDefinition.EndorsementInfo.EndorsementPlugin = "escc"
testDefinition.ValidationInfo.ValidationPlugin = "vscc"
testDefinition.ValidationInfo.ValidationParameter = protoutil.MarshalOrPanic(
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
&pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "/Channel/Application/Endorsement",
},
})
Expand Down
8 changes: 4 additions & 4 deletions core/chaincode/lifecycle/metadata_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/policies"
Expand Down Expand Up @@ -72,16 +72,16 @@ type MetadataProvider struct {
}

func (mp *MetadataProvider) toSignaturePolicyEnvelope(channelID string, policyBytes []byte) ([]byte, error) {
p := &common.ApplicationPolicy{}
p := &peer.ApplicationPolicy{}
err := proto.Unmarshal(policyBytes, p)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal ApplicationPolicy bytes")
}

switch policy := p.Type.(type) {
case *common.ApplicationPolicy_SignaturePolicy:
case *peer.ApplicationPolicy_SignaturePolicy:
return protoutil.MarshalOrPanic(policy.SignaturePolicy), nil
case *common.ApplicationPolicy_ChannelConfigPolicyReference:
case *peer.ApplicationPolicy_ChannelConfigPolicyReference:
p, err := mp.ChannelPolicyReferenceProvider.NewPolicy(channelID, policy.ChannelConfigPolicyReference)
if err != nil {
return nil, errors.WithMessagef(err, "could not retrieve policy for reference '%s' on channel '%s'", policy.ChannelConfigPolicyReference, channelID)
Expand Down
9 changes: 5 additions & 4 deletions core/chaincode/lifecycle/metadata_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hyperledger/fabric/core/chaincode/lifecycle/mock"
"github.com/pkg/errors"

"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/protoutil"
. "github.com/onsi/ginkgo"
Expand All @@ -39,8 +40,8 @@ var _ = Describe("MetadataProvider", func() {
Version: "cc-version",
},
ValidationInfo: &lb.ChaincodeValidationInfo{
ValidationParameter: protoutil.MarshalOrPanic(&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_SignaturePolicy{
ValidationParameter: protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: cauthdsl.AcceptAllPolicy,
},
}),
Expand Down Expand Up @@ -114,8 +115,8 @@ var _ = Describe("MetadataProvider", func() {
Context("when the policy is of the channel reference type", func() {
BeforeEach(func() {
ccInfo.Definition.ValidationInfo.ValidationParameter = protoutil.MarshalOrPanic(
&cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: "barf",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
tmocks "github.com/hyperledger/fabric/core/committer/txvalidator/mocks"
"github.com/hyperledger/fabric/core/committer/txvalidator/plugin"
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestSamplePlugin(t *testing.T) {
txnData, _ := proto.Marshal(&transaction)

v := plugindispatcher.NewPluginValidator(pm, qec, deserializer, capabilities, mcpmg, nil)
acceptAllPolicyBytes, _ := proto.Marshal(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.AcceptAllPolicy}})
acceptAllPolicyBytes, _ := proto.Marshal(&peer.ApplicationPolicy{Type: &peer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.AcceptAllPolicy}})
ctx := &plugindispatcher.Context{
Namespace: "mycc",
PluginName: "vscc",
Expand Down
6 changes: 3 additions & 3 deletions core/committer/txvalidator/v20/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (

func signedByAnyMember(ids []string) []byte {
p := cauthdsl.SignedByAnyMember(ids)
return protoutil.MarshalOrPanic(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: p}})
return protoutil.MarshalOrPanic(&protospeer.ApplicationPolicy{Type: &protospeer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: p}})
}

func v20Capabilities() *tmocks.ApplicationCapabilities {
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestParallelValidation(t *testing.T) {
mockCR.On("CollectionValidationInfo", ccID, "col1", mock.Anything).Return(nil, nil, nil)

policy := cauthdsl.SignedByMspPeer("Org1")
polBytes := protoutil.MarshalOrPanic(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: policy}})
polBytes := protoutil.MarshalOrPanic(&protospeer.ApplicationPolicy{Type: &protospeer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: policy}})
mockQE.On("GetState", "lscc", ccID).Return(protoutil.MarshalOrPanic(&ccp.ChaincodeData{
Name: ccID,
Version: ccVersion,
Expand Down Expand Up @@ -927,7 +927,7 @@ func TestValidateTxWithStateBasedEndorsement(t *testing.T) {
Vscc: "vscc",
Policy: signedByAnyMember([]string{"SampleOrg"}),
}), nil)
mockQE.On("GetStateMetadata", ccID, "key").Return(map[string][]byte{peer.MetaDataKeys_VALIDATION_PARAMETER.String(): protoutil.MarshalOrPanic(&common.ApplicationPolicy{Type: &common.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.RejectAllPolicy}})}, nil)
mockQE.On("GetStateMetadata", ccID, "key").Return(map[string][]byte{peer.MetaDataKeys_VALIDATION_PARAMETER.String(): protoutil.MarshalOrPanic(&protospeer.ApplicationPolicy{Type: &protospeer.ApplicationPolicy_SignaturePolicy{SignaturePolicy: cauthdsl.RejectAllPolicy}})}, nil)

tx := getEnv(ccID, nil, createRWset(t, ccID), t)
b := &common.Block{Data: &common.BlockData{Data: [][]byte{protoutil.MarshalOrPanic(tx)}}, Header: &common.BlockHeader{Number: 3}}
Expand Down
5 changes: 3 additions & 2 deletions core/committer/txvalidator/v20/valinforetriever/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package valinforetriever
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/core/committer/txvalidator/v20/plugindispatcher"
"github.com/hyperledger/fabric/core/ledger"
)
Expand Down Expand Up @@ -64,8 +65,8 @@ func (v *ValidationInfoRetrieveShim) ValidationInfo(channelID, chaincodeName str
}

newArgs, err := proto.Marshal(
&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spe,
},
},
Expand Down
5 changes: 3 additions & 2 deletions core/committer/txvalidator/v20/valinforetriever/shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/protoutil"

"github.com/hyperledger/fabric/core/committer/txvalidator/v20/valinforetriever"
Expand Down Expand Up @@ -143,8 +144,8 @@ func TestValidationInfoRetrieverFromLegacyWithConversion(t *testing.T) {
assert.NoError(t, unexpectedErr)
assert.NoError(t, validationErr)
assert.Equal(t, "vscc", plugin)
assert.Equal(t, protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
assert.Equal(t, protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: &common.SignaturePolicyEnvelope{Version: 1},
},
}), args)
Expand Down
4 changes: 2 additions & 2 deletions core/handlers/validation/builtin/v20/validation_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func (n *toApplicationPolicyTranslator) Translate(b []byte) ([]byte, error) {
return nil, errors.Wrap(err, "could not unmarshal signature policy envelope")
}

return protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
return protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spe,
},
}), nil
Expand Down
4 changes: 2 additions & 2 deletions core/handlers/validation/builtin/v20/validation_logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func TestToApplicationPolicyTranslator_Translate(t *testing.T) {

res, err = tr.Translate(protoutil.MarshalOrPanic(cauthdsl.SignedByMspMember("the right honourable member for Ipswich")))
assert.NoError(t, err)
assert.Equal(t, res, protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
assert.Equal(t, res, protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: cauthdsl.SignedByMspMember("the right honourable member for Ipswich"),
},
}))
Expand Down
7 changes: 4 additions & 3 deletions core/policy/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package policy
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
Expand Down Expand Up @@ -145,16 +146,16 @@ func (a *ApplicationPolicyEvaluator) evaluateChannelConfigPolicyReference(channe
}

func (a *ApplicationPolicyEvaluator) Evaluate(policyBytes []byte, signatureSet []*protoutil.SignedData) error {
p := &common.ApplicationPolicy{}
p := &peer.ApplicationPolicy{}
err := proto.Unmarshal(policyBytes, p)
if err != nil {
return errors.Wrap(err, "failed to unmarshal ApplicationPolicy bytes")
}

switch policy := p.Type.(type) {
case *common.ApplicationPolicy_SignaturePolicy:
case *peer.ApplicationPolicy_SignaturePolicy:
return a.evaluateSignaturePolicy(policy.SignaturePolicy, signatureSet)
case *common.ApplicationPolicy_ChannelConfigPolicyReference:
case *peer.ApplicationPolicy_ChannelConfigPolicyReference:
return a.evaluateChannelConfigPolicyReference(policy.ChannelConfigPolicyReference, signatureSet)
default:
return errors.Errorf("unsupported policy type %T", policy)
Expand Down
13 changes: 7 additions & 6 deletions core/policy/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/core/policy/mocks"
"github.com/hyperledger/fabric/msp"
Expand All @@ -31,8 +32,8 @@ func TestComponentIntegrationSignaturePolicyEnv(t *testing.T) {
}

spenv := cauthdsl.SignedByMspMember("msp")
mspenv := protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
mspenv := protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spenv,
},
})
Expand Down Expand Up @@ -78,8 +79,8 @@ func TestEvaluator(t *testing.T) {
// SCENARIO: signature policy supplied - good and bad path

spenv := &common.SignaturePolicyEnvelope{}
mspenv := protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_SignaturePolicy{
mspenv := protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spenv,
},
})
Expand All @@ -98,8 +99,8 @@ func TestEvaluator(t *testing.T) {
// SCENARIO: channel ref policy supplied - good and bad path

chrefstr := "Quo usque tandem abutere, Catilina, patientia nostra?"
chrefstrEnv := protoutil.MarshalOrPanic(&common.ApplicationPolicy{
Type: &common.ApplicationPolicy_ChannelConfigPolicyReference{
chrefstrEnv := protoutil.MarshalOrPanic(&peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: chrefstr,
},
})
Expand Down
10 changes: 5 additions & 5 deletions internal/peer/lifecycle/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ func createPolicyBytes(signaturePolicy, channelConfigPolicy string) ([]byte, err
return nil, errors.New("cannot specify both \"--signature-policy\" and \"--channel-config-policy\"")
}

var applicationPolicy *cb.ApplicationPolicy
var applicationPolicy *pb.ApplicationPolicy
if signaturePolicy != "" {
signaturePolicyEnvelope, err := cauthdsl.FromString(signaturePolicy)
if err != nil {
return nil, errors.Errorf("invalid signature policy: %s", signaturePolicy)
}

applicationPolicy = &cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_SignaturePolicy{
applicationPolicy = &pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: signaturePolicyEnvelope,
},
}
}

if channelConfigPolicy != "" {
applicationPolicy = &cb.ApplicationPolicy{
Type: &cb.ApplicationPolicy_ChannelConfigPolicyReference{
applicationPolicy = &pb.ApplicationPolicy{
Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: channelConfigPolicy,
},
}
Expand Down

0 comments on commit 8d073c1

Please sign in to comment.