Skip to content

Commit bc358a5

Browse files
author
Jason Yellick
committed
Move configuration tx to common protos
The configuration transaction must be read by anyone who wishes to understand a chain. This means that it does not belong with the orderer protos where it previously resided. This changeset moves the configuration transaction proto definitions out of the orderer proto dir and into the common proto dir. Change-Id: Idd03b8e18dd096826b9c3fbea5e648996fed6693 Signed-off-by: Jason Yellick <[email protected]>
1 parent 1230e0f commit bc358a5

21 files changed

+1247
-1155
lines changed

bddtests/common/configuration_pb2.py

+497
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bddtests/orderer/ab_pb2.py

+13-471
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/common/bootstrap/static/static.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/hyperledger/fabric/orderer/common/cauthdsl"
2424
"github.com/hyperledger/fabric/orderer/common/configtx"
2525
cb "github.com/hyperledger/fabric/protos/common"
26-
ab "github.com/hyperledger/fabric/protos/orderer"
2726

2827
"github.com/golang/protobuf/proto"
2928
)
@@ -51,8 +50,8 @@ func errorlessMarshal(thing proto.Message) []byte {
5150
return data
5251
}
5352

54-
func (b *bootstrapper) makeSignedConfigurationItem(id string, ctype ab.ConfigurationItem_ConfigurationType, data []byte, modificationPolicyID string) *ab.SignedConfigurationItem {
55-
configurationBytes := errorlessMarshal(&ab.ConfigurationItem{
53+
func (b *bootstrapper) makeSignedConfigurationItem(id string, ctype cb.ConfigurationItem_ConfigurationType, data []byte, modificationPolicyID string) *cb.SignedConfigurationItem {
54+
configurationBytes := errorlessMarshal(&cb.ConfigurationItem{
5655
Header: &cb.ChainHeader{
5756
ChainID: b.chainID,
5857
},
@@ -62,14 +61,14 @@ func (b *bootstrapper) makeSignedConfigurationItem(id string, ctype ab.Configura
6261
Key: id,
6362
Value: data,
6463
})
65-
return &ab.SignedConfigurationItem{
64+
return &cb.SignedConfigurationItem{
6665
ConfigurationItem: configurationBytes,
6766
}
6867
}
6968

70-
func sigPolicyToPolicy(sigPolicy *ab.SignaturePolicyEnvelope) []byte {
71-
policy := &ab.Policy{
72-
Type: &ab.Policy_SignaturePolicy{
69+
func sigPolicyToPolicy(sigPolicy *cb.SignaturePolicyEnvelope) []byte {
70+
policy := &cb.Policy{
71+
Type: &cb.Policy_SignaturePolicy{
7372
SignaturePolicy: sigPolicy,
7473
},
7574
}
@@ -80,12 +79,12 @@ func sigPolicyToPolicy(sigPolicy *ab.SignaturePolicyEnvelope) []byte {
8079
func (b *bootstrapper) GenesisBlock() (*cb.Block, error) {
8180

8281
// Lock down the default modification policy to prevent any further policy modifications
83-
lockdownDefaultModificationPolicy := b.makeSignedConfigurationItem(configtx.DefaultModificationPolicyID, ab.ConfigurationItem_Policy, sigPolicyToPolicy(cauthdsl.RejectAllPolicy), configtx.DefaultModificationPolicyID)
82+
lockdownDefaultModificationPolicy := b.makeSignedConfigurationItem(configtx.DefaultModificationPolicyID, cb.ConfigurationItem_Policy, sigPolicyToPolicy(cauthdsl.RejectAllPolicy), configtx.DefaultModificationPolicyID)
8483

85-
initialConfigTX := errorlessMarshal(&ab.ConfigurationEnvelope{
84+
initialConfigTX := errorlessMarshal(&cb.ConfigurationEnvelope{
8685
Sequence: 0,
8786
ChainID: b.chainID,
88-
Items: []*ab.SignedConfigurationItem{
87+
Items: []*cb.SignedConfigurationItem{
8988
lockdownDefaultModificationPolicy,
9089
},
9190
})

orderer/common/broadcastfilter/configfilter/configfilter.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/hyperledger/fabric/orderer/common/broadcastfilter"
2121
"github.com/hyperledger/fabric/orderer/common/configtx"
2222
cb "github.com/hyperledger/fabric/protos/common"
23-
ab "github.com/hyperledger/fabric/protos/orderer"
2423

2524
"github.com/golang/protobuf/proto"
2625
)
@@ -48,7 +47,7 @@ func (cf *configFilter) Apply(message *cb.Envelope) broadcastfilter.Action {
4847
return broadcastfilter.Forward
4948
}
5049

51-
config := &ab.ConfigurationEnvelope{}
50+
config := &cb.ConfigurationEnvelope{}
5251
err = proto.Unmarshal(msgData.Data, config)
5352
if err != nil {
5453
return broadcastfilter.Reject

orderer/common/broadcastfilter/configfilter/configfilter_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/hyperledger/fabric/orderer/common/broadcastfilter"
2424
cb "github.com/hyperledger/fabric/protos/common"
25-
ab "github.com/hyperledger/fabric/protos/orderer"
2625

2726
"github.com/golang/protobuf/proto"
2827
)
@@ -31,11 +30,11 @@ type mockConfigManager struct {
3130
err error
3231
}
3332

34-
func (mcm *mockConfigManager) Validate(configtx *ab.ConfigurationEnvelope) error {
33+
func (mcm *mockConfigManager) Validate(configtx *cb.ConfigurationEnvelope) error {
3534
return mcm.err
3635
}
3736

38-
func (mcm *mockConfigManager) Apply(configtx *ab.ConfigurationEnvelope) error {
37+
func (mcm *mockConfigManager) Apply(configtx *cb.ConfigurationEnvelope) error {
3938
return mcm.err
4039
}
4140

@@ -51,7 +50,7 @@ func TestForwardNonConfig(t *testing.T) {
5150

5251
func TestAcceptGoodConfig(t *testing.T) {
5352
cf := New(&mockConfigManager{})
54-
config, _ := proto.Marshal(&ab.ConfigurationEnvelope{})
53+
config, _ := proto.Marshal(&cb.ConfigurationEnvelope{})
5554
configBytes, _ := proto.Marshal(&cb.Payload{Header: &cb.Header{ChainHeader: &cb.ChainHeader{Type: int32(cb.HeaderType_CONFIGURATION_TRANSACTION)}}, Data: config})
5655
result := cf.Apply(&cb.Envelope{
5756
Payload: configBytes,
@@ -63,7 +62,7 @@ func TestAcceptGoodConfig(t *testing.T) {
6362

6463
func TestRejectBadConfig(t *testing.T) {
6564
cf := New(&mockConfigManager{err: fmt.Errorf("Error")})
66-
config, _ := proto.Marshal(&ab.ConfigurationEnvelope{})
65+
config, _ := proto.Marshal(&cb.ConfigurationEnvelope{})
6766
configBytes, _ := proto.Marshal(&cb.Payload{Header: &cb.Header{ChainHeader: &cb.ChainHeader{Type: int32(cb.HeaderType_CONFIGURATION_TRANSACTION)}}, Data: config})
6867
result := cf.Apply(&cb.Envelope{
6968
Payload: configBytes,

orderer/common/cauthdsl/cauthdsl.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"bytes"
2121
"fmt"
2222

23-
ab "github.com/hyperledger/fabric/protos/orderer"
23+
cb "github.com/hyperledger/fabric/protos/common"
2424
)
2525

2626
// CryptoHelper is used to provide a plugin point for different signature validation types
@@ -34,7 +34,7 @@ type SignaturePolicyEvaluator struct {
3434
}
3535

3636
// NewSignaturePolicyEvaluator evaluates a protbuf SignaturePolicy to produce a 'compiled' version which can be invoked in code
37-
func NewSignaturePolicyEvaluator(policy *ab.SignaturePolicyEnvelope, ch CryptoHelper) (*SignaturePolicyEvaluator, error) {
37+
func NewSignaturePolicyEvaluator(policy *cb.SignaturePolicyEnvelope, ch CryptoHelper) (*SignaturePolicyEvaluator, error) {
3838
if policy.Version != 0 {
3939
return nil, fmt.Errorf("This evaluator only understands messages of version 0, but version was %d", policy.Version)
4040
}
@@ -50,9 +50,9 @@ func NewSignaturePolicyEvaluator(policy *ab.SignaturePolicyEnvelope, ch CryptoHe
5050
}
5151

5252
// compile recursively builds a go evaluatable function corresponding to the policy specified
53-
func compile(policy *ab.SignaturePolicy, identities [][]byte, ch CryptoHelper) (func([]byte, [][]byte, [][]byte) bool, error) {
53+
func compile(policy *cb.SignaturePolicy, identities [][]byte, ch CryptoHelper) (func([]byte, [][]byte, [][]byte) bool, error) {
5454
switch t := policy.Type.(type) {
55-
case *ab.SignaturePolicy_From:
55+
case *cb.SignaturePolicy_From:
5656
policies := make([]func([]byte, [][]byte, [][]byte) bool, len(t.From.Policies))
5757
for i, policy := range t.From.Policies {
5858
compiledPolicy, err := compile(policy, identities, ch)
@@ -71,7 +71,7 @@ func compile(policy *ab.SignaturePolicy, identities [][]byte, ch CryptoHelper) (
7171
}
7272
return verified >= t.From.N
7373
}, nil
74-
case *ab.SignaturePolicy_SignedBy:
74+
case *cb.SignaturePolicy_SignedBy:
7575
if t.SignedBy < 0 || t.SignedBy >= int32(len(identities)) {
7676
return nil, fmt.Errorf("Identity index out of range, requested %d, but identies length is %d", t.SignedBy, len(identities))
7777
}

orderer/common/cauthdsl/cauthdsl_builder.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,72 @@ limitations under the License.
1717
package cauthdsl
1818

1919
import (
20-
ab "github.com/hyperledger/fabric/protos/orderer"
20+
cb "github.com/hyperledger/fabric/protos/common"
2121

2222
"github.com/golang/protobuf/proto"
2323
)
2424

2525
// AcceptAllPolicy always evaluates to true
26-
var AcceptAllPolicy *ab.SignaturePolicyEnvelope
26+
var AcceptAllPolicy *cb.SignaturePolicyEnvelope
2727

2828
// MarshaledAcceptAllPolicy is the Marshaled version of AcceptAllPolicy
2929
var MarshaledAcceptAllPolicy []byte
3030

3131
// RejectAllPolicy always evaluates to false
32-
var RejectAllPolicy *ab.SignaturePolicyEnvelope
32+
var RejectAllPolicy *cb.SignaturePolicyEnvelope
3333

3434
// MarshaledRejectAllPolicy is the Marshaled version of RejectAllPolicy
3535
var MarshaledRejectAllPolicy []byte
3636

3737
func init() {
3838
var err error
3939

40-
AcceptAllPolicy = Envelope(NOutOf(0, []*ab.SignaturePolicy{}), [][]byte{})
40+
AcceptAllPolicy = Envelope(NOutOf(0, []*cb.SignaturePolicy{}), [][]byte{})
4141
MarshaledAcceptAllPolicy, err = proto.Marshal(AcceptAllPolicy)
4242
if err != nil {
4343
panic("Error marshaling trueEnvelope")
4444
}
4545

46-
RejectAllPolicy = Envelope(NOutOf(1, []*ab.SignaturePolicy{}), [][]byte{})
46+
RejectAllPolicy = Envelope(NOutOf(1, []*cb.SignaturePolicy{}), [][]byte{})
4747
MarshaledRejectAllPolicy, err = proto.Marshal(RejectAllPolicy)
4848
if err != nil {
4949
panic("Error marshaling falseEnvelope")
5050
}
5151
}
5252

5353
// Envelope builds an envelope message embedding a SignaturePolicy
54-
func Envelope(policy *ab.SignaturePolicy, identities [][]byte) *ab.SignaturePolicyEnvelope {
55-
return &ab.SignaturePolicyEnvelope{
54+
func Envelope(policy *cb.SignaturePolicy, identities [][]byte) *cb.SignaturePolicyEnvelope {
55+
return &cb.SignaturePolicyEnvelope{
5656
Version: 0,
5757
Policy: policy,
5858
Identities: identities,
5959
}
6060
}
6161

6262
// SignedBy creates a SignaturePolicy requiring a given signer's signature
63-
func SignedBy(index int32) *ab.SignaturePolicy {
64-
return &ab.SignaturePolicy{
65-
Type: &ab.SignaturePolicy_SignedBy{
63+
func SignedBy(index int32) *cb.SignaturePolicy {
64+
return &cb.SignaturePolicy{
65+
Type: &cb.SignaturePolicy_SignedBy{
6666
SignedBy: index,
6767
},
6868
}
6969
}
7070

7171
// And is a convenience method which utilizes NOutOf to produce And equivalent behavior
72-
func And(lhs, rhs *ab.SignaturePolicy) *ab.SignaturePolicy {
73-
return NOutOf(2, []*ab.SignaturePolicy{lhs, rhs})
72+
func And(lhs, rhs *cb.SignaturePolicy) *cb.SignaturePolicy {
73+
return NOutOf(2, []*cb.SignaturePolicy{lhs, rhs})
7474
}
7575

7676
// Or is a convenience method which utilizes NOutOf to produce Or equivalent behavior
77-
func Or(lhs, rhs *ab.SignaturePolicy) *ab.SignaturePolicy {
78-
return NOutOf(1, []*ab.SignaturePolicy{lhs, rhs})
77+
func Or(lhs, rhs *cb.SignaturePolicy) *cb.SignaturePolicy {
78+
return NOutOf(1, []*cb.SignaturePolicy{lhs, rhs})
7979
}
8080

8181
// NOutOf creates a policy which requires N out of the slice of policies to evaluate to true
82-
func NOutOf(n int32, policies []*ab.SignaturePolicy) *ab.SignaturePolicy {
83-
return &ab.SignaturePolicy{
84-
Type: &ab.SignaturePolicy_From{
85-
From: &ab.SignaturePolicy_NOutOf{
82+
func NOutOf(n int32, policies []*cb.SignaturePolicy) *cb.SignaturePolicy {
83+
return &cb.SignaturePolicy{
84+
Type: &cb.SignaturePolicy_From{
85+
From: &cb.SignaturePolicy_NOutOf{
8686
N: n,
8787
Policies: policies,
8888
},

orderer/common/cauthdsl/cauthdsl_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/golang/protobuf/proto"
24-
ab "github.com/hyperledger/fabric/protos/orderer"
24+
cb "github.com/hyperledger/fabric/protos/common"
2525
)
2626

2727
var invalidSignature = []byte("badsigned")
@@ -100,7 +100,7 @@ func TestNegatively(t *testing.T) {
100100
rpolicy := Envelope(And(SignedBy(0), SignedBy(1)), signers)
101101
rpolicy.Policy.Type = nil
102102
b, _ := proto.Marshal(rpolicy)
103-
policy := &ab.SignaturePolicyEnvelope{}
103+
policy := &cb.SignaturePolicyEnvelope{}
104104
_ = proto.Unmarshal(b, policy)
105105
_, err := NewSignaturePolicyEvaluator(policy, mch)
106106
if err == nil {

orderer/common/configtx/bytes_handler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package configtx
1818

1919
import (
20-
ab "github.com/hyperledger/fabric/protos/orderer"
20+
cb "github.com/hyperledger/fabric/protos/common"
2121
)
2222

2323
// BytesHandler is a trivial ConfigHandler which simpy tracks the bytes stores in a config
@@ -56,7 +56,7 @@ func (bh *BytesHandler) CommitConfig() {
5656
}
5757

5858
// ProposeConfig called when config is added to a proposal
59-
func (bh *BytesHandler) ProposeConfig(configItem *ab.ConfigurationItem) error {
59+
func (bh *BytesHandler) ProposeConfig(configItem *cb.ConfigurationItem) error {
6060
bh.proposed[configItem.Key] = configItem.Value
6161
return nil
6262
}

0 commit comments

Comments
 (0)