Skip to content

Commit

Permalink
[FAB-2074] Make config protos consistent in naming
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2074

There are some pieces of the configuration transaction which refer to
Configuration and others which refer to Config, this normalizes things.

Change-Id: Ib8ef14d7b06f85e42536574f272b89f587203a67
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 7, 2017
1 parent f8e86df commit 5ed12d2
Show file tree
Hide file tree
Showing 53 changed files with 620 additions and 622 deletions.
4 changes: 2 additions & 2 deletions common/cauthdsl/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func makePolicySource(policyResult bool) []byte {

func addPolicy(manager *policies.ManagerImpl, id string, policy []byte) {
manager.BeginConfig()
err := manager.ProposeConfig(&cb.ConfigurationItem{
Type: cb.ConfigurationItem_Policy,
err := manager.ProposeConfig(&cb.ConfigItem{
Type: cb.ConfigItem_Policy,
Key: id,
Value: policy,
})
Expand Down
6 changes: 3 additions & 3 deletions common/cauthdsl/policy_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
)

// TemplatePolicy creates a headerless configuration item representing a policy for a given key
func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.ConfigurationItem {
return &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Policy,
func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.ConfigItem {
return &cb.ConfigItem{
Type: cb.ConfigItem_Policy,
Key: key,
Value: utils.MarshalOrPanic(&cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Expand Down
26 changes: 13 additions & 13 deletions common/chainconfig/chainconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (

// Chain config keys
const (
// HashingAlgorithmKey is the cb.ConfigurationItem type key name for the HashingAlgorithm message
// HashingAlgorithmKey is the cb.ConfigItem type key name for the HashingAlgorithm message
HashingAlgorithmKey = "HashingAlgorithm"

// BlockDataHashingStructureKey is the cb.ConfigurationItem type key name for the BlockDataHashingStructure message
// BlockDataHashingStructureKey is the cb.ConfigItem type key name for the BlockDataHashingStructure message
BlockDataHashingStructureKey = "BlockDataHashingStructure"

// OrdererAddressesKey is the cb.ConfigurationItem type key name for the OrdererAddresses message
// OrdererAddressesKey is the cb.ConfigItem type key name for the OrdererAddresses message
OrdererAddressesKey = "OrdererAddresses"
)

Expand All @@ -47,10 +47,10 @@ const (

var logger = logging.MustGetLogger("common/chainconfig")

// Descriptor stores the common chain configuration
// Descriptor stores the common chain config
// It is intended to be the primary accessor of DescriptorImpl
// It is intended to discourage use of the other exported DescriptorImpl methods
// which are used for updating the chain configuration by the configtx.Manager
// which are used for updating the chain config by the configtx.Manager
type Descriptor interface {
// HashingAlgorithm returns the default algorithm to be used when hashing
// such as computing block hashes, and CreationPolicy digests
Expand Down Expand Up @@ -99,20 +99,20 @@ func (pm *DescriptorImpl) OrdererAddresses() []string {
return pm.config.ordererAddresses
}

// BeginConfig is used to start a new configuration proposal
// BeginConfig is used to start a new config proposal
func (pm *DescriptorImpl) BeginConfig() {
if pm.pendingConfig != nil {
logger.Panicf("Programming error, cannot call begin in the middle of a proposal")
}
pm.pendingConfig = &chainConfig{}
}

// RollbackConfig is used to abandon a new configuration proposal
// RollbackConfig is used to abandon a new config proposal
func (pm *DescriptorImpl) RollbackConfig() {
pm.pendingConfig = nil
}

// CommitConfig is used to commit a new configuration proposal
// CommitConfig is used to commit a new config proposal
func (pm *DescriptorImpl) CommitConfig() {
if pm.pendingConfig == nil {
logger.Panicf("Programming error, cannot call commit without an existing proposal")
Expand All @@ -121,10 +121,10 @@ func (pm *DescriptorImpl) CommitConfig() {
pm.pendingConfig = nil
}

// ProposeConfig is used to add new configuration to the configuration proposal
func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
if configItem.Type != cb.ConfigurationItem_Chain {
return fmt.Errorf("Expected type of ConfigurationItem_Chain, got %v", configItem.Type)
// ProposeConfig is used to add new config to the config proposal
func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigItem) error {
if configItem.Type != cb.ConfigItem_Chain {
return fmt.Errorf("Expected type of ConfigItem_Chain, got %v", configItem.Type)
}

switch configItem.Key {
Expand Down Expand Up @@ -157,7 +157,7 @@ func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigurationItem) error
}
pm.pendingConfig.ordererAddresses = ordererAddresses.Addresses
default:
logger.Warningf("Uknown Chain configuration item with key %s", configItem.Key)
logger.Warningf("Uknown Chain config item with key %s", configItem.Key)
}
return nil
}
6 changes: 3 additions & 3 deletions common/chainconfig/chainconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func init() {
logging.SetLevel(logging.DEBUG, "")
}

func makeInvalidConfigItem(key string) *cb.ConfigurationItem {
return &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Chain,
func makeInvalidConfigItem(key string) *cb.ConfigItem {
return &cb.ConfigItem{
Type: cb.ConfigItem_Chain,
Key: key,
Value: []byte("Garbage Data"),
}
Expand Down
36 changes: 18 additions & 18 deletions common/chainconfig/chainconfig_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,49 @@ import (

const defaultHashingAlgorithm = SHA3Shake256

// TemplateHashingAlgorithm creates a headerless configuration item representing the hashing algorithm
func TemplateHashingAlgorithm(name string) *cb.ConfigurationItem {
return &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Chain,
// TemplateHashingAlgorithm creates a headerless config item representing the hashing algorithm
func TemplateHashingAlgorithm(name string) *cb.ConfigItem {
return &cb.ConfigItem{
Type: cb.ConfigItem_Chain,
Key: HashingAlgorithmKey,
Value: utils.MarshalOrPanic(&cb.HashingAlgorithm{Name: name}),
}

}

// DefaultHashingAlgorithm creates a headerless configuration item for the default hashing algorithm
func DefaultHashingAlgorithm() *cb.ConfigurationItem {
// DefaultHashingAlgorithm creates a headerless config item for the default hashing algorithm
func DefaultHashingAlgorithm() *cb.ConfigItem {
return TemplateHashingAlgorithm(defaultHashingAlgorithm)
}

const defaultBlockDataHashingStructureWidth = math.MaxUint32

// TemplateBlockDataHashingStructure creates a headerless configuration item representing the block data hashing structure
func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigurationItem {
return &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Chain,
// TemplateBlockDataHashingStructure creates a headerless config item representing the block data hashing structure
func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigItem {
return &cb.ConfigItem{
Type: cb.ConfigItem_Chain,
Key: BlockDataHashingStructureKey,
Value: utils.MarshalOrPanic(&cb.BlockDataHashingStructure{Width: width}),
}
}

// DefaultBlockDatahashingStructure creates a headerless configuration item for the default block data hashing structure
func DefaultBlockDataHashingStructure() *cb.ConfigurationItem {
// DefaultBlockDatahashingStructure creates a headerless config item for the default block data hashing structure
func DefaultBlockDataHashingStructure() *cb.ConfigItem {
return TemplateBlockDataHashingStructure(defaultBlockDataHashingStructureWidth)
}

var defaultOrdererAddresses = []string{"127.0.0.1:7050"}

// TemplateOrdererAddressess creates a headerless configuration item representing the orderer addresses
func TemplateOrdererAddresses(addresses []string) *cb.ConfigurationItem {
return &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Chain,
// TemplateOrdererAddressess creates a headerless config item representing the orderer addresses
func TemplateOrdererAddresses(addresses []string) *cb.ConfigItem {
return &cb.ConfigItem{
Type: cb.ConfigItem_Chain,
Key: OrdererAddressesKey,
Value: utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: addresses}),
}
}

// DefaultOrdererAddresses creates a headerless configuration item for the default orderer addresses
func DefaultOrdererAddresses() *cb.ConfigurationItem {
// DefaultOrdererAddresses creates a headerless config item for the default orderer addresses
func DefaultOrdererAddresses() *cb.ConfigItem {
return TemplateOrdererAddresses(defaultOrdererAddresses)
}
2 changes: 1 addition & 1 deletion common/configtx/bytes_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (bh *BytesHandler) CommitConfig() {
}

// ProposeConfig called when config is added to a proposal
func (bh *BytesHandler) ProposeConfig(configItem *cb.ConfigurationItem) error {
func (bh *BytesHandler) ProposeConfig(configItem *cb.ConfigItem) error {
bh.proposed[configItem.Key] = configItem.Value
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions common/configtx/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func NewFilter(manager Manager) filter.Rule {

type configCommitter struct {
manager Manager
configEnvelope *cb.ConfigurationEnvelope
configEnvelope *cb.ConfigEnvelope
}

func (cc *configCommitter) Commit() {
err := cc.manager.Apply(cc.configEnvelope)
if err != nil {
panic(fmt.Errorf("Could not apply configuration transaction which should have already been validated: %s", err))
panic(fmt.Errorf("Could not apply config transaction which should have already been validated: %s", err))
}
}

Expand All @@ -65,7 +65,7 @@ func (cf *configFilter) Apply(message *cb.Envelope) (filter.Action, filter.Commi
return filter.Forward, nil
}

config := &cb.ConfigurationEnvelope{}
config := &cb.ConfigEnvelope{}
err = proto.Unmarshal(msgData.Data, config)
if err != nil {
return filter.Reject, nil
Expand Down
16 changes: 8 additions & 8 deletions common/configtx/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import (

type mockConfigManager struct {
mockconfigtx.Manager
applied *cb.ConfigurationEnvelope
applied *cb.ConfigEnvelope
err error
}

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

func (mcm *mockConfigManager) Apply(configtx *cb.ConfigurationEnvelope) error {
func (mcm *mockConfigManager) Apply(configtx *cb.ConfigEnvelope) error {
mcm.applied = configtx
return mcm.err
}
Expand All @@ -65,31 +65,31 @@ func TestForwardNonConfig(t *testing.T) {
func TestAcceptGoodConfig(t *testing.T) {
mcm := &mockConfigManager{}
cf := NewFilter(mcm)
configEnv := &cb.ConfigurationEnvelope{}
configEnv := &cb.ConfigEnvelope{}
config, _ := proto.Marshal(configEnv)
configBytes, _ := proto.Marshal(&cb.Payload{Header: &cb.Header{ChainHeader: &cb.ChainHeader{Type: int32(cb.HeaderType_CONFIGURATION_TRANSACTION)}}, Data: config})
configEnvelope := &cb.Envelope{
Payload: configBytes,
}
result, committer := cf.Apply(configEnvelope)
if result != filter.Accept {
t.Fatal("Should have indicated a good config message causes a reconfiguration")
t.Fatal("Should have indicated a good config message causes a reconfig")
}

if !committer.Isolated() {
t.Fatal("Configuration transactions should be isolated to their own block")
t.Fatal("Config transactions should be isolated to their own block")
}

committer.Commit()

if !reflect.DeepEqual(mcm.applied, configEnv) {
t.Fatalf("Should have applied new configuration on commit got %v and %v", mcm.applied, configEnv)
t.Fatalf("Should have applied new config on commit got %v and %v", mcm.applied, configEnv)
}
}

func TestRejectBadConfig(t *testing.T) {
cf := NewFilter(&mockConfigManager{err: fmt.Errorf("Error")})
config, _ := proto.Marshal(&cb.ConfigurationEnvelope{})
config, _ := proto.Marshal(&cb.ConfigEnvelope{})
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
14 changes: 7 additions & 7 deletions common/configtx/inspector/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/golang/protobuf/proto"
)

func viewableConfigurationEnvelope(name string, configEnvelope *cb.ConfigurationEnvelope) Viewable {
func viewableConfigEnvelope(name string, configEnvelope *cb.ConfigEnvelope) Viewable {
return &field{
name: name,
values: []Viewable{viewableConfig("Config", configEnvelope.Config), viewableConfigurationSignatureSlice("Signatures", configEnvelope.Signatures)},
values: []Viewable{viewableConfig("Config", configEnvelope.Config), viewableConfigSignatureSlice("Signatures", configEnvelope.Signatures)},
}
}

Expand All @@ -38,26 +38,26 @@ func viewableConfig(name string, configBytes []byte) Viewable {
}
values := make([]Viewable, len(config.Items))
for i, item := range config.Items {
values[i] = viewableConfigurationItem(fmt.Sprintf("Element %d", i), item)
values[i] = viewableConfigItem(fmt.Sprintf("Element %d", i), item)
}
return &field{
name: name,
values: values,
}
}

func viewableConfigurationSignatureSlice(name string, configSigs []*cb.ConfigurationSignature) Viewable {
func viewableConfigSignatureSlice(name string, configSigs []*cb.ConfigSignature) Viewable {
values := make([]Viewable, len(configSigs))
for i, item := range configSigs {
values[i] = viewableConfigurationSignature(fmt.Sprintf("Element %d", i), item)
values[i] = viewableConfigSignature(fmt.Sprintf("Element %d", i), item)
}
return &field{
name: name,
values: values,
}
}

func viewableConfigurationSignature(name string, configSig *cb.ConfigurationSignature) Viewable {
func viewableConfigSignature(name string, configSig *cb.ConfigSignature) Viewable {
children := make([]Viewable, 2)

sigHeader := &cb.SignatureHeader{}
Expand All @@ -83,7 +83,7 @@ func viewableSignatureHeader(name string, sh *cb.SignatureHeader) Viewable {
}
}

func viewableConfigurationItem(name string, ci *cb.ConfigurationItem) Viewable {
func viewableConfigItem(name string, ci *cb.ConfigItem) Viewable {

values := make([]Viewable, 6) // Type, Key, Header, LastModified, ModificationPolicy, Value
values[0] = viewableString("Type", fmt.Sprintf("%v", ci.Type))
Expand Down
10 changes: 5 additions & 5 deletions common/configtx/inspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
cb "github.com/hyperledger/fabric/protos/common"
)

var typeMap map[cb.ConfigurationItem_ConfigurationType]ConfigurationItemValueLens = make(map[cb.ConfigurationItem_ConfigurationType]ConfigurationItemValueLens)
var typeMap map[cb.ConfigItem_ConfigType]ConfigItemValueLens = make(map[cb.ConfigItem_ConfigType]ConfigItemValueLens)

type ConfigurationItemValueLens interface {
type ConfigItemValueLens interface {
// Value takes a config item and returns a Viewable version of its value
Value(configItem *cb.ConfigurationItem) Viewable
Value(configItem *cb.ConfigItem) Viewable
}

type Viewable interface {
Expand Down Expand Up @@ -55,7 +55,7 @@ func printViewable(viewable Viewable, curDepth int) {
}
}

func PrintConfiguration(configEnvelope *cb.ConfigurationEnvelope) {
viewable := viewableConfigurationEnvelope("ConfigurationEnvelope", configEnvelope)
func PrintConfig(configEnvelope *cb.ConfigEnvelope) {
viewable := viewableConfigEnvelope("ConfigEnvelope", configEnvelope)
printViewable(viewable, 0)
}
2 changes: 1 addition & 1 deletion common/configtx/inspector/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func TestFromTemplate(t *testing.T) {
if err != nil {
t.Fatalf("Error creating signed items: %s", err)
}
PrintConfiguration(configEnvelope)
PrintConfig(configEnvelope)
}
6 changes: 3 additions & 3 deletions common/configtx/inspector/orderer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
)

// This file contains the functions needed to create Viewables for protos defined in
// the orderer configuration proto
// the orderer config proto

type ordererTypes struct{}

func (ot ordererTypes) Value(configItem *cb.ConfigurationItem) Viewable {
func (ot ordererTypes) Value(configItem *cb.ConfigItem) Viewable {
name := "Value"
switch configItem.Key {
case "ConsensusType":
Expand Down Expand Up @@ -147,5 +147,5 @@ func viewableBatchSize(name string, batchSize *ab.BatchSize) Viewable {
}

func init() {
typeMap[cb.ConfigurationItem_Orderer] = ordererTypes{}
typeMap[cb.ConfigItem_Orderer] = ordererTypes{}
}
4 changes: 2 additions & 2 deletions common/configtx/inspector/policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

type policyTypes struct{}

func (ot policyTypes) Value(configItem *cb.ConfigurationItem) Viewable {
func (ot policyTypes) Value(configItem *cb.ConfigItem) Viewable {
name := "Value"
value := &cb.Policy{}
if err := proto.Unmarshal(configItem.Value, value); err != nil {
Expand Down Expand Up @@ -59,5 +59,5 @@ func viewableSignaturePolicyEnvelope(name string, signaturePolicyEnvelope *cb.Si
}

func init() {
typeMap[cb.ConfigurationItem_Policy] = policyTypes{}
typeMap[cb.ConfigItem_Policy] = policyTypes{}
}
Loading

0 comments on commit 5ed12d2

Please sign in to comment.