diff --git a/common/tools/configtxgen/encoder/encoder.go b/common/tools/configtxgen/encoder/encoder.go index bac0fe31aea..e5c8c22e36f 100644 --- a/common/tools/configtxgen/encoder/encoder.go +++ b/common/tools/configtxgen/encoder/encoder.go @@ -374,7 +374,7 @@ func NewConsortiumGroup(conf *genesisconfig.Consortium) (*cb.ConfigGroup, error) // NewChannelCreateConfigUpdate generates a ConfigUpdate which can be sent to the orderer to create a new channel. Optionally, the channel group of the // ordering system channel may be passed in, and the resulting ConfigUpdate will extract the appropriate versions from this file. -func NewChannelCreateConfigUpdate(channelID string, orderingSystemChannelGroup *cb.ConfigGroup, conf *genesisconfig.Profile) (*cb.ConfigUpdate, error) { +func NewChannelCreateConfigUpdate(channelID string, conf *genesisconfig.Profile) (*cb.ConfigUpdate, error) { if conf.Application == nil { return nil, errors.New("cannot define a new channel with no Application section") } @@ -383,7 +383,7 @@ func NewChannelCreateConfigUpdate(channelID string, orderingSystemChannelGroup * return nil, errors.New("cannot define a new channel with no Consortium value") } - // Otherwise, parse only the application section, and encapsulate it inside a channel group + // Parse only the application section, and encapsulate it inside a channel group ag, err := NewApplicationGroup(conf.Application) if err != nil { return nil, errors.Wrapf(err, "could not turn channel application profile into application group") @@ -391,53 +391,17 @@ func NewChannelCreateConfigUpdate(channelID string, orderingSystemChannelGroup * var template, newChannelGroup *cb.ConfigGroup - if orderingSystemChannelGroup != nil { - // In the case that a ordering system channel definition was provided, use it to compute the update - if orderingSystemChannelGroup.Groups == nil { - return nil, errors.New("missing all channel groups") - } - - consortiums, ok := orderingSystemChannelGroup.Groups[channelconfig.ConsortiumsGroupKey] - if !ok { - return nil, errors.New("bad consortiums group") - } - - consortium, ok := consortiums.Groups[conf.Consortium] - if !ok { - return nil, errors.Errorf("bad consortium: %s", conf.Consortium) - } - - template = proto.Clone(orderingSystemChannelGroup).(*cb.ConfigGroup) - template.Groups[channelconfig.ApplicationGroupKey] = proto.Clone(consortium).(*cb.ConfigGroup) - // This is a bit of a hack. If the channel config specifies all consortium members, then it does not look - // like a modification. The below adds a fake org with an illegal name which cannot actually exist, which - // will always appear to be deleted, triggering the correct update computation. - template.Groups[channelconfig.ApplicationGroupKey].Groups["*IllegalKey*!"] = &cb.ConfigGroup{} - delete(template.Groups, channelconfig.ConsortiumsGroupKey) - - newChannelGroup = proto.Clone(orderingSystemChannelGroup).(*cb.ConfigGroup) - delete(newChannelGroup.Groups, channelconfig.ConsortiumsGroupKey) - newChannelGroup.Groups[channelconfig.ApplicationGroupKey].Values = ag.Values - newChannelGroup.Groups[channelconfig.ApplicationGroupKey].Policies = ag.Policies - - for orgName, org := range template.Groups[channelconfig.ApplicationGroupKey].Groups { - if _, ok := ag.Groups[orgName]; ok { - newChannelGroup.Groups[channelconfig.ApplicationGroupKey].Groups[orgName] = org - } - } - } else { - newChannelGroup = &cb.ConfigGroup{ - Groups: map[string]*cb.ConfigGroup{ - channelconfig.ApplicationGroupKey: ag, - }, - } - - // Otherwise assume the orgs have not been modified - template = proto.Clone(newChannelGroup).(*cb.ConfigGroup) - template.Groups[channelconfig.ApplicationGroupKey].Values = nil - template.Groups[channelconfig.ApplicationGroupKey].Policies = nil + newChannelGroup = &cb.ConfigGroup{ + Groups: map[string]*cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: ag, + }, } + // Assume the orgs have not been modified + template = proto.Clone(newChannelGroup).(*cb.ConfigGroup) + template.Groups[channelconfig.ApplicationGroupKey].Values = nil + template.Groups[channelconfig.ApplicationGroupKey].Policies = nil + updt, err := update.Compute(&cb.Config{ChannelGroup: template}, &cb.Config{ChannelGroup: newChannelGroup}) if err != nil { return nil, errors.Wrapf(err, "could not compute update") @@ -457,8 +421,8 @@ func NewChannelCreateConfigUpdate(channelID string, orderingSystemChannelGroup * } // MakeChannelCreationTransaction is a handy utility function for creating transactions for channel creation -func MakeChannelCreationTransaction(channelID string, signer crypto.LocalSigner, orderingSystemChannelConfigGroup *cb.ConfigGroup, conf *genesisconfig.Profile) (*cb.Envelope, error) { - newChannelConfigUpdate, err := NewChannelCreateConfigUpdate(channelID, orderingSystemChannelConfigGroup, conf) +func MakeChannelCreationTransaction(channelID string, signer crypto.LocalSigner, conf *genesisconfig.Profile) (*cb.Envelope, error) { + newChannelConfigUpdate, err := NewChannelCreateConfigUpdate(channelID, conf) if err != nil { return nil, errors.Wrap(err, "config update generation failure") } diff --git a/common/tools/configtxgen/encoder/encoder_test.go b/common/tools/configtxgen/encoder/encoder_test.go index 521858643d7..04312e439cf 100644 --- a/common/tools/configtxgen/encoder/encoder_test.go +++ b/common/tools/configtxgen/encoder/encoder_test.go @@ -73,26 +73,26 @@ func TestConfigParsing(t *testing.T) { } func TestGoodChannelCreateConfigUpdate(t *testing.T) { - config := configtxgentest.Load(genesisconfig.SampleDevModeSoloProfile) - systemChannel, err := NewChannelGroup(config) - assert.NoError(t, err) - assert.NotNil(t, systemChannel) - createConfig := configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile) - //ACLs does not marshal deterministically. Set it to nil is ok as its not - //updated anyway - createConfig.Application.ACLs = nil - - configUpdate, err := NewChannelCreateConfigUpdate("channel.id", nil, createConfig) + configUpdate, err := NewChannelCreateConfigUpdate("channel.id", createConfig) assert.NoError(t, err) assert.NotNil(t, configUpdate) +} - defaultConfigUpdate, err := NewChannelCreateConfigUpdate("channel.id", systemChannel, createConfig) +func TestGoodChannelCreateNoAnchorPeers(t *testing.T) { + createConfig := configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile) + createConfig.Application.Organizations[0].AnchorPeers = nil + + configUpdate, err := NewChannelCreateConfigUpdate("channel.id", createConfig) assert.NoError(t, err) - assert.NotNil(t, defaultConfigUpdate) + assert.NotNil(t, configUpdate) - assert.True(t, proto.Equal(configUpdate, defaultConfigUpdate), "the config used has had no updates, so should equal default") + // Anchor peers should not be set + assert.True(t, proto.Equal( + configUpdate.WriteSet.Groups["Application"].Groups["SampleOrg"], + &cb.ConfigGroup{}, + )) } func TestChannelCreateWithResources(t *testing.T) { @@ -100,52 +100,20 @@ func TestChannelCreateWithResources(t *testing.T) { createConfig := configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile) createConfig.Application.Capabilities = nil - configUpdate, err := NewChannelCreateConfigUpdate("channel.id", nil, createConfig) + configUpdate, err := NewChannelCreateConfigUpdate("channel.id", createConfig) assert.NoError(t, err) assert.NotNil(t, configUpdate) assert.Nil(t, configUpdate.IsolatedData) }) } -func TestNegativeChannelCreateConfigUpdate(t *testing.T) { - config := configtxgentest.Load(genesisconfig.SampleDevModeSoloProfile) - channelConfig := configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile) - group, err := NewChannelGroup(config) - assert.NoError(t, err) - assert.NotNil(t, group) - - t.Run("NoGroups", func(t *testing.T) { - channelGroup := proto.Clone(group).(*cb.ConfigGroup) - channelGroup.Groups = nil - _, err := NewChannelCreateConfigUpdate("channel.id", &cb.ConfigGroup{}, channelConfig) - assert.Error(t, err) - assert.Regexp(t, "missing all channel groups", err.Error()) - }) - - t.Run("NoConsortiumsGroup", func(t *testing.T) { - channelGroup := proto.Clone(group).(*cb.ConfigGroup) - delete(channelGroup.Groups, channelconfig.ConsortiumsGroupKey) - _, err := NewChannelCreateConfigUpdate("channel.id", channelGroup, channelConfig) - assert.Error(t, err) - assert.Regexp(t, "bad consortiums group", err.Error()) - }) - - t.Run("NoConsortiums", func(t *testing.T) { - channelGroup := proto.Clone(group).(*cb.ConfigGroup) - delete(channelGroup.Groups[channelconfig.ConsortiumsGroupKey].Groups, genesisconfig.SampleConsortiumName) - _, err := NewChannelCreateConfigUpdate("channel.id", channelGroup, channelConfig) - assert.Error(t, err) - assert.Regexp(t, "bad consortium:", err.Error()) - }) -} - func TestMakeChannelCreationTransactionWithSigner(t *testing.T) { channelID := "foo" msptesttools.LoadDevMsp() signer := localmsp.NewSigner() - cct, err := MakeChannelCreationTransaction(channelID, signer, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) + cct, err := MakeChannelCreationTransaction(channelID, signer, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) assert.NoError(t, err, "Making chain creation tx") assert.NotEmpty(t, cct.Signature, "Should have signature") @@ -165,7 +133,7 @@ func TestMakeChannelCreationTransactionWithSigner(t *testing.T) { func TestMakeChannelCreationTransactionNoSigner(t *testing.T) { channelID := "foo" - cct, err := MakeChannelCreationTransaction(channelID, nil, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) + cct, err := MakeChannelCreationTransaction(channelID, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) assert.NoError(t, err, "Making chain creation tx") assert.Empty(t, cct.Signature, "Should have empty signature") diff --git a/common/tools/configtxgen/main.go b/common/tools/configtxgen/main.go index 7b878163850..4d42c3eb2d3 100644 --- a/common/tools/configtxgen/main.go +++ b/common/tools/configtxgen/main.go @@ -49,7 +49,7 @@ func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock func doOutputChannelCreateTx(conf *genesisconfig.Profile, channelID string, outputChannelCreateTx string) error { logger.Info("Generating new channel configtx") - configtx, err := encoder.MakeChannelCreationTransaction(channelID, nil, nil, conf) + configtx, err := encoder.MakeChannelCreationTransaction(channelID, nil, conf) if err != nil { return err } @@ -222,9 +222,9 @@ func main() { flag.Parse() - if channelID == "" { + if channelID == "" && (outputBlock != "" || outputChannelCreateTx != "" || outputAnchorPeersUpdate != "") { channelID = genesisconfig.TestChainID - logger.Warningf("Omitting the channel ID for configtxgen is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to '%s'.", channelID) + logger.Warningf("Omitting the channel ID for configtxgen for output operations is deprecated. Explicitly passing the channel ID will be required in the future, defaulting to '%s'.", channelID) } // show version diff --git a/common/tools/configtxlator/update/update.go b/common/tools/configtxlator/update/update.go index 70ae4ab80b7..7439a9a5048 100644 --- a/common/tools/configtxlator/update/update.go +++ b/common/tools/configtxlator/update/update.go @@ -17,9 +17,10 @@ limitations under the License. package update import ( + "bytes" "fmt" - "reflect" + "github.com/golang/protobuf/proto" cb "github.com/hyperledger/fabric/protos/common" ) @@ -38,7 +39,7 @@ func computePoliciesMapUpdate(original, updated map[string]*cb.ConfigPolicy) (re continue } - if originalPolicy.ModPolicy == updatedPolicy.ModPolicy && reflect.DeepEqual(originalPolicy.Policy, updatedPolicy.Policy) { + if originalPolicy.ModPolicy == updatedPolicy.ModPolicy && proto.Equal(originalPolicy.Policy, updatedPolicy.Policy) { sameSet[policyName] = &cb.ConfigPolicy{ Version: originalPolicy.Version, } @@ -83,7 +84,7 @@ func computeValuesMapUpdate(original, updated map[string]*cb.ConfigValue) (readS continue } - if originalValue.ModPolicy == updatedValue.ModPolicy && reflect.DeepEqual(originalValue.Value, updatedValue.Value) { + if originalValue.ModPolicy == updatedValue.ModPolicy && bytes.Equal(originalValue.Value, updatedValue.Value) { sameSet[valueName] = &cb.ConfigValue{ Version: originalValue.Version, } diff --git a/core/common/validation/config_test.go b/core/common/validation/config_test.go index 814e4f32861..4235aacb5b7 100644 --- a/core/common/validation/config_test.go +++ b/core/common/validation/config_test.go @@ -32,7 +32,7 @@ import ( func TestValidateConfigTx(t *testing.T) { chainID := util.GetTestChainID() profile := configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile) - chCrtEnv, err := encoder.MakeChannelCreationTransaction(genesisconfig.SampleConsortiumName, nil, nil, profile) + chCrtEnv, err := encoder.MakeChannelCreationTransaction(genesisconfig.SampleConsortiumName, nil, profile) if err != nil { t.Fatalf("MakeChannelCreationTransaction failed, err %s", err) return diff --git a/orderer/common/msgprocessor/systemchannel_test.go b/orderer/common/msgprocessor/systemchannel_test.go index 0f8e56182ae..7fcd70716ee 100644 --- a/orderer/common/msgprocessor/systemchannel_test.go +++ b/orderer/common/msgprocessor/systemchannel_test.go @@ -674,7 +674,7 @@ func TestNewChannelConfig(t *testing.T) { // Successful t.Run("Success", func(t *testing.T) { - createTx, err := encoder.MakeChannelCreationTransaction("foo", nil, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) + createTx, err := encoder.MakeChannelCreationTransaction("foo", nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) assert.Nil(t, err) res, err := templator.NewChannelConfig(createTx) assert.Nil(t, err) diff --git a/orderer/common/msgprocessor/systemchannelfilter_test.go b/orderer/common/msgprocessor/systemchannelfilter_test.go index d58857b8581..7d5ef2266ce 100644 --- a/orderer/common/msgprocessor/systemchannelfilter_test.go +++ b/orderer/common/msgprocessor/systemchannelfilter_test.go @@ -134,7 +134,7 @@ func TestGoodProposal(t *testing.T) { mcc := newMockChainCreator() - configUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, nil, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) + configUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) assert.Nil(t, err, "Error constructing configtx") ingressTx := makeConfigTxFromConfigUpdateTx(configUpdate) @@ -149,7 +149,7 @@ func TestProposalRejectedByConfig(t *testing.T) { mcc := newMockChainCreator() mcc.NewChannelConfigErr = fmt.Errorf("desired err text") - configUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, nil, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) + configUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) assert.Nil(t, err, "Error constructing configtx") ingressTx := makeConfigTxFromConfigUpdateTx(configUpdate) @@ -169,7 +169,7 @@ func TestNumChainsExceeded(t *testing.T) { mcc.ms.msc.MaxChannelsCountVal = 1 mcc.newChains = make([]*cb.Envelope, 2) - configUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, nil, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) + configUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, nil, configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile)) assert.Nil(t, err, "Error constructing configtx") ingressTx := makeConfigTxFromConfigUpdateTx(configUpdate) diff --git a/orderer/common/multichannel/registrar_test.go b/orderer/common/multichannel/registrar_test.go index c676ada1f6b..79fb633d6d7 100644 --- a/orderer/common/multichannel/registrar_test.go +++ b/orderer/common/multichannel/registrar_test.go @@ -177,7 +177,7 @@ func TestNewChain(t *testing.T) { manager := NewRegistrar(lf, consenters, mockCrypto()) orglessChannelConf := configtxgentest.Load(genesisconfig.SampleSingleMSPChannelProfile) orglessChannelConf.Application.Organizations = nil - envConfigUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, mockCrypto(), nil, orglessChannelConf) + envConfigUpdate, err := encoder.MakeChannelCreationTransaction(newChainID, mockCrypto(), orglessChannelConf) assert.NoError(t, err, "Constructing chain creation tx") res, err := manager.NewChannelConfig(envConfigUpdate) diff --git a/orderer/common/performance/utils.go b/orderer/common/performance/utils.go index 3f51ff254a4..7d87016e133 100644 --- a/orderer/common/performance/utils.go +++ b/orderer/common/performance/utils.go @@ -92,7 +92,7 @@ func CreateChannel(server *BenchmarkServer, channelProfile *genesisconfig.Profil defer client.Close() channelID := RandomID(10) - createChannelTx, err := encoder.MakeChannelCreationTransaction(channelID, localmsp.NewSigner(), nil, channelProfile) + createChannelTx, err := encoder.MakeChannelCreationTransaction(channelID, localmsp.NewSigner(), channelProfile) if err != nil { logger.Panicf("Failed to create channel creation transaction: %s", err) } diff --git a/orderer/sample_clients/broadcast_config/newchain.go b/orderer/sample_clients/broadcast_config/newchain.go index 760246cbe8c..d4369467b89 100644 --- a/orderer/sample_clients/broadcast_config/newchain.go +++ b/orderer/sample_clients/broadcast_config/newchain.go @@ -11,7 +11,7 @@ import ( ) func newChainRequest(consensusType, creationPolicy, newChannelID string) *cb.Envelope { - env, err := encoder.MakeChannelCreationTransaction(newChannelID, localmsp.NewSigner(), nil, genesisconfig.Load(genesisconfig.SampleSingleMSPChannelProfile)) + env, err := encoder.MakeChannelCreationTransaction(newChannelID, localmsp.NewSigner(), genesisconfig.Load(genesisconfig.SampleSingleMSPChannelProfile)) if err != nil { panic(err) } diff --git a/peer/channel/create.go b/peer/channel/create.go index 326b570acf5..039d8ecb4b7 100644 --- a/peer/channel/create.go +++ b/peer/channel/create.go @@ -69,7 +69,7 @@ func createCmd(cf *ChannelCmdFactory) *cobra.Command { } func createChannelFromDefaults(cf *ChannelCmdFactory) (*cb.Envelope, error) { - chCrtEnv, err := encoder.MakeChannelCreationTransaction(channelID, localsigner.NewSigner(), nil, genesisconfig.Load(genesisconfig.SampleSingleMSPChannelProfile)) + chCrtEnv, err := encoder.MakeChannelCreationTransaction(channelID, localsigner.NewSigner(), genesisconfig.Load(genesisconfig.SampleSingleMSPChannelProfile)) if err != nil { return nil, err }