Skip to content

Commit

Permalink
Move configuration tx to common protos
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Nov 10, 2016
1 parent 1230e0f commit bc358a5
Show file tree
Hide file tree
Showing 21 changed files with 1,247 additions and 1,155 deletions.
497 changes: 497 additions & 0 deletions bddtests/common/configuration_pb2.py

Large diffs are not rendered by default.

484 changes: 13 additions & 471 deletions bddtests/orderer/ab_pb2.py

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions orderer/common/bootstrap/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/hyperledger/fabric/orderer/common/cauthdsl"
"github.com/hyperledger/fabric/orderer/common/configtx"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

"github.com/golang/protobuf/proto"
)
Expand Down Expand Up @@ -51,8 +50,8 @@ func errorlessMarshal(thing proto.Message) []byte {
return data
}

func (b *bootstrapper) makeSignedConfigurationItem(id string, ctype ab.ConfigurationItem_ConfigurationType, data []byte, modificationPolicyID string) *ab.SignedConfigurationItem {
configurationBytes := errorlessMarshal(&ab.ConfigurationItem{
func (b *bootstrapper) makeSignedConfigurationItem(id string, ctype cb.ConfigurationItem_ConfigurationType, data []byte, modificationPolicyID string) *cb.SignedConfigurationItem {
configurationBytes := errorlessMarshal(&cb.ConfigurationItem{
Header: &cb.ChainHeader{
ChainID: b.chainID,
},
Expand All @@ -62,14 +61,14 @@ func (b *bootstrapper) makeSignedConfigurationItem(id string, ctype ab.Configura
Key: id,
Value: data,
})
return &ab.SignedConfigurationItem{
return &cb.SignedConfigurationItem{
ConfigurationItem: configurationBytes,
}
}

func sigPolicyToPolicy(sigPolicy *ab.SignaturePolicyEnvelope) []byte {
policy := &ab.Policy{
Type: &ab.Policy_SignaturePolicy{
func sigPolicyToPolicy(sigPolicy *cb.SignaturePolicyEnvelope) []byte {
policy := &cb.Policy{
Type: &cb.Policy_SignaturePolicy{
SignaturePolicy: sigPolicy,
},
}
Expand All @@ -80,12 +79,12 @@ func sigPolicyToPolicy(sigPolicy *ab.SignaturePolicyEnvelope) []byte {
func (b *bootstrapper) GenesisBlock() (*cb.Block, error) {

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

initialConfigTX := errorlessMarshal(&ab.ConfigurationEnvelope{
initialConfigTX := errorlessMarshal(&cb.ConfigurationEnvelope{
Sequence: 0,
ChainID: b.chainID,
Items: []*ab.SignedConfigurationItem{
Items: []*cb.SignedConfigurationItem{
lockdownDefaultModificationPolicy,
},
})
Expand Down
3 changes: 1 addition & 2 deletions orderer/common/broadcastfilter/configfilter/configfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/hyperledger/fabric/orderer/common/broadcastfilter"
"github.com/hyperledger/fabric/orderer/common/configtx"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

"github.com/golang/protobuf/proto"
)
Expand Down Expand Up @@ -48,7 +47,7 @@ func (cf *configFilter) Apply(message *cb.Envelope) broadcastfilter.Action {
return broadcastfilter.Forward
}

config := &ab.ConfigurationEnvelope{}
config := &cb.ConfigurationEnvelope{}
err = proto.Unmarshal(msgData.Data, config)
if err != nil {
return broadcastfilter.Reject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/hyperledger/fabric/orderer/common/broadcastfilter"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

"github.com/golang/protobuf/proto"
)
Expand All @@ -31,11 +30,11 @@ type mockConfigManager struct {
err error
}

func (mcm *mockConfigManager) Validate(configtx *ab.ConfigurationEnvelope) error {
func (mcm *mockConfigManager) Validate(configtx *cb.ConfigurationEnvelope) error {
return mcm.err
}

func (mcm *mockConfigManager) Apply(configtx *ab.ConfigurationEnvelope) error {
func (mcm *mockConfigManager) Apply(configtx *cb.ConfigurationEnvelope) error {
return mcm.err
}

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

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

func TestRejectBadConfig(t *testing.T) {
cf := New(&mockConfigManager{err: fmt.Errorf("Error")})
config, _ := proto.Marshal(&ab.ConfigurationEnvelope{})
config, _ := proto.Marshal(&cb.ConfigurationEnvelope{})
configBytes, _ := proto.Marshal(&cb.Payload{Header: &cb.Header{ChainHeader: &cb.ChainHeader{Type: int32(cb.HeaderType_CONFIGURATION_TRANSACTION)}}, Data: config})
result := cf.Apply(&cb.Envelope{
Payload: configBytes,
Expand Down
10 changes: 5 additions & 5 deletions orderer/common/cauthdsl/cauthdsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"fmt"

ab "github.com/hyperledger/fabric/protos/orderer"
cb "github.com/hyperledger/fabric/protos/common"
)

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

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

// compile recursively builds a go evaluatable function corresponding to the policy specified
func compile(policy *ab.SignaturePolicy, identities [][]byte, ch CryptoHelper) (func([]byte, [][]byte, [][]byte) bool, error) {
func compile(policy *cb.SignaturePolicy, identities [][]byte, ch CryptoHelper) (func([]byte, [][]byte, [][]byte) bool, error) {
switch t := policy.Type.(type) {
case *ab.SignaturePolicy_From:
case *cb.SignaturePolicy_From:
policies := make([]func([]byte, [][]byte, [][]byte) bool, len(t.From.Policies))
for i, policy := range t.From.Policies {
compiledPolicy, err := compile(policy, identities, ch)
Expand All @@ -71,7 +71,7 @@ func compile(policy *ab.SignaturePolicy, identities [][]byte, ch CryptoHelper) (
}
return verified >= t.From.N
}, nil
case *ab.SignaturePolicy_SignedBy:
case *cb.SignaturePolicy_SignedBy:
if t.SignedBy < 0 || t.SignedBy >= int32(len(identities)) {
return nil, fmt.Errorf("Identity index out of range, requested %d, but identies length is %d", t.SignedBy, len(identities))
}
Expand Down
36 changes: 18 additions & 18 deletions orderer/common/cauthdsl/cauthdsl_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,72 @@ limitations under the License.
package cauthdsl

import (
ab "github.com/hyperledger/fabric/protos/orderer"
cb "github.com/hyperledger/fabric/protos/common"

"github.com/golang/protobuf/proto"
)

// AcceptAllPolicy always evaluates to true
var AcceptAllPolicy *ab.SignaturePolicyEnvelope
var AcceptAllPolicy *cb.SignaturePolicyEnvelope

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

// RejectAllPolicy always evaluates to false
var RejectAllPolicy *ab.SignaturePolicyEnvelope
var RejectAllPolicy *cb.SignaturePolicyEnvelope

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

func init() {
var err error

AcceptAllPolicy = Envelope(NOutOf(0, []*ab.SignaturePolicy{}), [][]byte{})
AcceptAllPolicy = Envelope(NOutOf(0, []*cb.SignaturePolicy{}), [][]byte{})
MarshaledAcceptAllPolicy, err = proto.Marshal(AcceptAllPolicy)
if err != nil {
panic("Error marshaling trueEnvelope")
}

RejectAllPolicy = Envelope(NOutOf(1, []*ab.SignaturePolicy{}), [][]byte{})
RejectAllPolicy = Envelope(NOutOf(1, []*cb.SignaturePolicy{}), [][]byte{})
MarshaledRejectAllPolicy, err = proto.Marshal(RejectAllPolicy)
if err != nil {
panic("Error marshaling falseEnvelope")
}
}

// Envelope builds an envelope message embedding a SignaturePolicy
func Envelope(policy *ab.SignaturePolicy, identities [][]byte) *ab.SignaturePolicyEnvelope {
return &ab.SignaturePolicyEnvelope{
func Envelope(policy *cb.SignaturePolicy, identities [][]byte) *cb.SignaturePolicyEnvelope {
return &cb.SignaturePolicyEnvelope{
Version: 0,
Policy: policy,
Identities: identities,
}
}

// SignedBy creates a SignaturePolicy requiring a given signer's signature
func SignedBy(index int32) *ab.SignaturePolicy {
return &ab.SignaturePolicy{
Type: &ab.SignaturePolicy_SignedBy{
func SignedBy(index int32) *cb.SignaturePolicy {
return &cb.SignaturePolicy{
Type: &cb.SignaturePolicy_SignedBy{
SignedBy: index,
},
}
}

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

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

// NOutOf creates a policy which requires N out of the slice of policies to evaluate to true
func NOutOf(n int32, policies []*ab.SignaturePolicy) *ab.SignaturePolicy {
return &ab.SignaturePolicy{
Type: &ab.SignaturePolicy_From{
From: &ab.SignaturePolicy_NOutOf{
func NOutOf(n int32, policies []*cb.SignaturePolicy) *cb.SignaturePolicy {
return &cb.SignaturePolicy{
Type: &cb.SignaturePolicy_From{
From: &cb.SignaturePolicy_NOutOf{
N: n,
Policies: policies,
},
Expand Down
4 changes: 2 additions & 2 deletions orderer/common/cauthdsl/cauthdsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"

"github.com/golang/protobuf/proto"
ab "github.com/hyperledger/fabric/protos/orderer"
cb "github.com/hyperledger/fabric/protos/common"
)

var invalidSignature = []byte("badsigned")
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestNegatively(t *testing.T) {
rpolicy := Envelope(And(SignedBy(0), SignedBy(1)), signers)
rpolicy.Policy.Type = nil
b, _ := proto.Marshal(rpolicy)
policy := &ab.SignaturePolicyEnvelope{}
policy := &cb.SignaturePolicyEnvelope{}
_ = proto.Unmarshal(b, policy)
_, err := NewSignaturePolicyEvaluator(policy, mch)
if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions orderer/common/configtx/bytes_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package configtx

import (
ab "github.com/hyperledger/fabric/protos/orderer"
cb "github.com/hyperledger/fabric/protos/common"
)

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

// ProposeConfig called when config is added to a proposal
func (bh *BytesHandler) ProposeConfig(configItem *ab.ConfigurationItem) error {
func (bh *BytesHandler) ProposeConfig(configItem *cb.ConfigurationItem) error {
bh.proposed[configItem.Key] = configItem.Value
return nil
}
Expand Down
Loading

0 comments on commit bc358a5

Please sign in to comment.