Skip to content

Commit

Permalink
Merge "[FAB-2172] Remove '*Next' from Config"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Feb 14, 2017
2 parents 2976b31 + 28e0d18 commit 372d853
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 83 deletions.
6 changes: 3 additions & 3 deletions common/configtx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func computeSequence(configGroup *cb.ConfigGroup) uint64 {

// computeChannelIdAndSequence returns the chain id and the sequence number for a config envelope
// or an error if there is a problem with the config envelope
func computeChannelIdAndSequence(config *cb.ConfigNext) (string, uint64, error) {
func computeChannelIdAndSequence(config *cb.Config) (string, uint64, error) {
if config.Channel == nil {
return "", 0, errors.New("Empty envelope unsupported")
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func validateChainID(chainID string) error {
}

func NewManagerImpl(configtx *cb.ConfigEnvelope, initializer api.Initializer, callOnUpdate []func(api.Manager)) (api.Manager, error) {
config, err := UnmarshalConfigNext(configtx.Config)
config, err := UnmarshalConfig(configtx.Config)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func (cm *configManager) recurseConfig(result map[string]comparable, path []stri
}

func (cm *configManager) processConfig(configtx *cb.ConfigEnvelope) (configMap map[string]comparable, err error) {
config, err := UnmarshalConfigNext(configtx.Config)
config, err := UnmarshalConfig(configtx.Config)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func makeMarshaledConfig(chainID string, configPairs ...*configPair) []byte {
values[pair.key] = pair.value
}

config := &cb.ConfigNext{
config := &cb.Config{
Header: &cb.ChannelHeader{ChannelId: chainID},
Channel: &cb.ConfigGroup{
Values: values,
Expand Down Expand Up @@ -438,7 +438,7 @@ func TestInvalidProposal(t *testing.T) {
func TestMissingHeader(t *testing.T) {
group := cb.NewConfigGroup()
group.Values["foo"] = &cb.ConfigValue{}
data := utils.MarshalOrPanic(&cb.ConfigNext{Channel: group})
data := utils.MarshalOrPanic(&cb.Config{Channel: group})
_, err := NewManagerImpl(&cb.ConfigEnvelope{
Config: data,
}, defaultInitializer(), nil)
Expand Down
18 changes: 9 additions & 9 deletions common/configtx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ type Template interface {
Envelope(chainID string) (*cb.ConfigEnvelope, error)
}

type simpleTemplateNext struct {
type simpleTemplate struct {
configGroup *cb.ConfigGroup
}

// NewSimpleTemplateNext creates a Template using the supplied ConfigGroup
func NewSimpleTemplateNext(configGroups ...*cb.ConfigGroup) Template {
// NewSimpleTemplate creates a Template using the supplied ConfigGroup
func NewSimpleTemplate(configGroups ...*cb.ConfigGroup) Template {
sts := make([]Template, len(configGroups))
for i, group := range configGroups {
sts[i] = &simpleTemplateNext{
sts[i] = &simpleTemplate{
configGroup: group,
}
}
return NewCompositeTemplate(sts...)
}

// Envelope returns a ConfigEnvelopes for the given chainID
func (st *simpleTemplateNext) Envelope(chainID string) (*cb.ConfigEnvelope, error) {
config, err := proto.Marshal(&cb.ConfigNext{
func (st *simpleTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error) {
config, err := proto.Marshal(&cb.Config{
Header: &cb.ChannelHeader{
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
Expand Down Expand Up @@ -128,7 +128,7 @@ func (ct *compositeTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error
if err != nil {
return nil, err
}
config, err := UnmarshalConfigNext(configEnv.Config)
config, err := UnmarshalConfig(configEnv.Config)
if err != nil {
return nil, err
}
Expand All @@ -138,7 +138,7 @@ func (ct *compositeTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error
}
}

marshaledConfig, err := proto.Marshal(&cb.ConfigNext{
marshaledConfig, err := proto.Marshal(&cb.Config{
Header: &cb.ChannelHeader{
ChannelId: chainID,
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
Expand All @@ -164,7 +164,7 @@ func NewChainCreationTemplate(creationPolicy string, template Template) Template
}),
}

return NewCompositeTemplate(NewSimpleTemplateNext(result), template)
return NewCompositeTemplate(NewSimpleTemplate(result), template)
}

// MakeChainCreationTransaction is a handy utility function for creating new chain transactions using the underlying Template framework
Expand Down
12 changes: 6 additions & 6 deletions common/configtx/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func verifyItemsResult(t *testing.T, template Template, count int) {
t.Fatalf("Should not have errored: %s", err)
}

configNext, err := UnmarshalConfigNext(configEnv.Config)
configNext, err := UnmarshalConfig(configEnv.Config)
if err != nil {
t.Fatalf("Should not have errored: %s", err)
}
Expand All @@ -54,7 +54,7 @@ func simpleGroup(index int) *cb.ConfigGroup {
}

func TestSimpleTemplate(t *testing.T) {
simple := NewSimpleTemplateNext(
simple := NewSimpleTemplate(
simpleGroup(0),
simpleGroup(1),
)
Expand All @@ -63,11 +63,11 @@ func TestSimpleTemplate(t *testing.T) {

func TestCompositeTemplate(t *testing.T) {
composite := NewCompositeTemplate(
NewSimpleTemplateNext(
NewSimpleTemplate(
simpleGroup(0),
simpleGroup(1),
),
NewSimpleTemplateNext(
NewSimpleTemplate(
simpleGroup(2),
),
)
Expand All @@ -76,7 +76,7 @@ func TestCompositeTemplate(t *testing.T) {
}

func TestNewChainTemplate(t *testing.T) {
simple := NewSimpleTemplateNext(
simple := NewSimpleTemplate(
simpleGroup(0),
simpleGroup(1),
)
Expand All @@ -90,7 +90,7 @@ func TestNewChainTemplate(t *testing.T) {
t.Fatalf("Error creation a chain creation config")
}

configNext, err := UnmarshalConfigNext(configEnv.Config)
configNext, err := UnmarshalConfig(configEnv.Config)
if err != nil {
t.Fatalf("Should not have errored: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func MSPTemplate() configtx.Template {
if err != nil {
logger.Panicf("Could not load sample MSP config: %s", err)
}
return configtx.NewSimpleTemplateNext(configtxmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey}, mspConf))
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey}, mspConf))
}

// ApplicationTemplate returns the test application template
func ApplicationTemplate() configtx.Template {
return configtx.NewSimpleTemplateNext(configtxapplication.DefaultAnchorPeers())
return configtx.NewSimpleTemplate(configtxapplication.DefaultAnchorPeers())
}

// CompositeTemplate returns the composite template of peer, orderer, and MSP
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/tool/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func New(conf *genesisconfig.TopLevel) Generator {
}

func (bs *bootstrapper) ChannelTemplate() configtx.Template {
return configtx.NewSimpleTemplateNext(bs.minimalGroups...)
return configtx.NewSimpleTemplate(bs.minimalGroups...)
}

func (bs *bootstrapper) GenesisBlock() *cb.Block {
block, err := genesis.NewFactoryImpl(
configtx.NewCompositeTemplate(
configtx.NewSimpleTemplateNext(bs.systemChainGroups...),
configtx.NewSimpleTemplate(bs.systemChainGroups...),
bs.ChannelTemplate(),
),
).Block(TestChainID)
Expand Down
6 changes: 3 additions & 3 deletions common/configtx/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"github.com/golang/protobuf/proto"
)

// UnmarshalConfigNext attempts to unmarshal bytes to a *cb.ConfigNext
func UnmarshalConfigNext(data []byte) (*cb.ConfigNext, error) {
config := &cb.ConfigNext{}
// UnmarshalConfig attempts to unmarshal bytes to a *cb.Config
func UnmarshalConfig(data []byte) (*cb.Config, error) {
config := &cb.Config{}
err := proto.Unmarshal(data, config)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion common/genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestSanity(t *testing.T) {
impl := NewFactoryImpl(configtx.NewSimpleTemplateNext())
impl := NewFactoryImpl(configtx.NewSimpleTemplate())
_, err := impl.Block("TestChainID")
if err != nil {
t.Fatalf("Basic sanity fails")
Expand Down
2 changes: 1 addition & 1 deletion orderer/multichain/systemchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (sc *systemChain) proposeChain(configTx *cb.Envelope) cb.Status {
}

func (sc *systemChain) authorize(configEnvelope *cb.ConfigEnvelope) cb.Status {
configNext := &cb.ConfigNext{}
configNext := &cb.Config{}
err := proto.Unmarshal(configEnvelope.Config, configNext)
if err != nil {
logger.Debugf("Failing to validate chain creation because of unmarshaling error: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion orderer/multichain/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func makeConfigTx(chainID string, i int) *cb.Envelope {
group.Groups[configtxorderer.GroupKey].Values[fmt.Sprintf("%d", i)] = &cb.ConfigValue{
Value: []byte(fmt.Sprintf("%d", i)),
}
configTemplate := configtx.NewSimpleTemplateNext(group)
configTemplate := configtx.NewSimpleTemplate(group)
configEnv, err := configTemplate.Envelope(chainID)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion peer/channel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func sendCreateChainTransaction(cf *ChannelCmdFactory) error {
//TODO this is a temporary hack until `orderer.template` and 'msp.template' is supplied from the CLI
oTemplate := configtxtest.OrdererTemplate()
mspTemplate := configtxtest.MSPTemplate()
gossTemplate := configtx.NewSimpleTemplateNext(configtxapplication.TemplateAnchorPeers(anchorPeers))
gossTemplate := configtx.NewSimpleTemplate(configtxapplication.TemplateAnchorPeers(anchorPeers))
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, mspTemplate, gossTemplate)

signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()
Expand Down
2 changes: 1 addition & 1 deletion protos/common/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 46 additions & 47 deletions protos/common/configtx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions protos/common/configtx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package common;
// 4. All configuration changes have a LastModification of one more than the last configuration's highest LastModification number
// 5. All configuration changes satisfy the corresponding modification policy
message ConfigEnvelope {
bytes config = 1; // A marshaled ConfigNext structure
bytes config = 1; // A marshaled Config structure
repeated ConfigSignature signatures = 2; // Signatures over the config
}

Expand All @@ -62,9 +62,8 @@ message ConfigValueSchema {}

message ConfigPolicySchema {}

// XXX this structure is to allow us to minimize the diffs in this change series
// it will be renamed Config once the original is ready to be removed
message ConfigNext {
// Config represents the config for a particular channel
message Config {
ChannelHeader header = 1;
ConfigGroup channel = 2;
}
Expand Down

0 comments on commit 372d853

Please sign in to comment.