diff --git a/common/configtx/test/helper.go b/common/configtx/test/helper.go index 94c11de1f6b..a0f946cacee 100644 --- a/common/configtx/test/helper.go +++ b/common/configtx/test/helper.go @@ -53,7 +53,7 @@ func MakeChannelConfig(channelID string) (*cb.Config, error) { // MakeGenesisBlockFromMSPs creates a genesis block using the MSPs provided for the given channelID func MakeGenesisBlockFromMSPs(channelID string, appMSPConf, ordererMSPConf *mspproto.MSPConfig, appOrgID, ordererOrgID string) (*cb.Block, error) { profile := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) - profile.Orderer.Organizations = nil + channelGroup, err := encoder.NewChannelGroup(profile) if err != nil { logger.Panicf("Error creating channel config: %s", err) diff --git a/integration/lifecycle/lifecycle_test.go b/integration/lifecycle/lifecycle_test.go index 6f87eec9901..8427208723c 100644 --- a/integration/lifecycle/lifecycle_test.go +++ b/integration/lifecycle/lifecycle_test.go @@ -8,7 +8,6 @@ package lifecycle import ( "bytes" - "fmt" "os" "path/filepath" "syscall" @@ -23,8 +22,6 @@ import ( "github.com/hyperledger/fabric/integration/nwo/commands" "github.com/hyperledger/fabric/integration/nwo/fabricconfig" "github.com/hyperledger/fabric/integration/nwo/runner" - "github.com/hyperledger/fabric/internal/configtxlator/update" - "github.com/hyperledger/fabric/protoutil" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/gbytes" @@ -313,20 +310,7 @@ var _ = Describe("Lifecycle", func() { // update the channel config to include org3 updatedConfig.ChannelGroup.Groups["Application"].Groups["Org3"] = org3Group.ConfigGroup - ordererOrg3Endpoint := &common.OrdererAddresses{ - Addresses: []string{"127.0.0.1:7050"}, - } - updatedConfig.ChannelGroup.Groups["Orderer"].Groups["Org3"] = &common.ConfigGroup{ - Values: map[string]*common.ConfigValue{ - "Endpoints": { - Value: protoutil.MarshalOrPanic(ordererOrg3Endpoint), - ModPolicy: "/Channel/Application/Writers", - }, - }, - ModPolicy: "/Channel/Application/Writers", - } - fmt.Printf("Lifecycle: org3 info: %v", updatedConfig.ChannelGroup.Groups["Orderer"].Groups["Org3"]) - updateConfigSucceeds(network, orderer, "testchannel", currentConfig, updatedConfig, testPeers[0], testPeers...) + nwo.UpdateConfig(network, orderer, "testchannel", currentConfig, updatedConfig, true, testPeers[0], testPeers...) By("joining the org3 peers to the channel") network.JoinChannel("testchannel", orderer, org3peer0) @@ -420,55 +404,3 @@ var _ = Describe("Lifecycle", func() { Expect(sess.Err).To(gbytes.Say(`Chaincode invoke successful. result: status:200`)) }) }) - -func updateConfigSucceeds(n *nwo.Network, orderer *nwo.Orderer, channel string, current, updated *common.Config, peer *nwo.Peer, additionalSigners ...*nwo.Peer) { - tempDir, err := os.MkdirTemp("", "updateConfig") - Expect(err).NotTo(HaveOccurred()) - defer os.RemoveAll(tempDir) - - // compute update - configUpdate, err := update.Compute(current, updated) - Expect(err).NotTo(HaveOccurred()) - configUpdate.ChannelId = channel - - signedEnvelope, err := protoutil.CreateSignedEnvelope( - common.HeaderType_CONFIG_UPDATE, - channel, - nil, // local signer - &common.ConfigUpdateEnvelope{ConfigUpdate: protoutil.MarshalOrPanic(configUpdate)}, - 0, // message version - 0, // epoch - ) - Expect(err).NotTo(HaveOccurred()) - Expect(signedEnvelope).NotTo(BeNil()) - - updateFile := filepath.Join(tempDir, "update.pb") - err = os.WriteFile(updateFile, protoutil.MarshalOrPanic(signedEnvelope), 0o600) - Expect(err).NotTo(HaveOccurred()) - - for _, signer := range additionalSigners { - sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{ - File: updateFile, - ClientAuth: n.ClientAuthRequired, - }) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) - } - - sess, err := n.OrdererAdminSession(orderer, peer, commands.SignConfigTx{ - File: updateFile, - ClientAuth: n.ClientAuthRequired, - }) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) - - sess, err = n.OrdererAdminSession(orderer, peer, commands.ChannelUpdate{ - ChannelID: channel, - Orderer: n.OrdererAddress(orderer, nwo.ListenPort), - File: updateFile, - ClientAuth: n.ClientAuthRequired, - }) - Expect(err).NotTo(HaveOccurred()) - Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) - Expect(sess.Err).To(gbytes.Say("Successfully submitted channel update")) -} diff --git a/internal/peer/common/common_test.go b/internal/peer/common/common_test.go index 18b5a6686c5..d520a368c2a 100644 --- a/internal/peer/common/common_test.go +++ b/internal/peer/common/common_test.go @@ -269,6 +269,7 @@ func TestGetOrdererEndpointFromConfigTx(t *testing.T) { t.Run("green-path", func(t *testing.T) { profile := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir()) + profile.Capabilities = map[string]bool{"V_2": true} channelGroup, err := encoder.NewChannelGroup(profile) require.NoError(t, err) channelConfig := &cb.Config{ChannelGroup: channelGroup} diff --git a/orderer/common/cluster/util_test.go b/orderer/common/cluster/util_test.go index d6fc85d4f7f..48a34865cf1 100644 --- a/orderer/common/cluster/util_test.go +++ b/orderer/common/cluster/util_test.go @@ -14,6 +14,10 @@ import ( "errors" "fmt" "math" + "os" + "os/exec" + "path" + "path/filepath" "strings" "sync" "testing" @@ -40,6 +44,7 @@ import ( "github.com/hyperledger/fabric/orderer/common/cluster" "github.com/hyperledger/fabric/orderer/common/cluster/mocks" "github.com/hyperledger/fabric/protoutil" + "github.com/onsi/gomega/gexec" "github.com/stretchr/testify/require" ) @@ -351,13 +356,13 @@ func injectGlobalOrdererEndpoint(t *testing.T, block *common.Block, endpoint str Value: protoutil.MarshalOrPanic(ordererAddresses.Value()), ModPolicy: "/Channel/Orderer/Admins", } - // Remove the per org addresses, if applicable + // Update the per org addresses ordererGrps := confEnv.Config.ChannelGroup.Groups[channelconfig.OrdererGroupKey].Groups for _, grp := range ordererGrps { if grp.Values[channelconfig.EndpointsKey] == nil { continue } - grp.Values[channelconfig.EndpointsKey].Value = nil + grp.Values[channelconfig.EndpointsKey].Value = protoutil.MarshalOrPanic(ordererAddresses.Value()) } // And put it back into the block payload.Data = protoutil.MarshalOrPanic(confEnv) @@ -470,7 +475,32 @@ func TestEndpointconfigFromConfigBlockFailures(t *testing.T) { } func TestBlockValidationPolicyVerifier(t *testing.T) { + dir := filepath.Join(os.TempDir()) + os.Mkdir(dir, 0o700) + defer os.RemoveAll(dir) + + cryptogen, err := gexec.Build("github.com/hyperledger/fabric/cmd/cryptogen") + require.NoError(t, err) + defer os.Remove(cryptogen) + + cryptoConfigDir := filepath.Join(dir, "crypto-config") + b, err := exec.Command(cryptogen, "generate", fmt.Sprintf("--output=%s", cryptoConfigDir)).CombinedOutput() + require.NoError(t, err, string(b)) + config := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir()) + config.Orderer.Organizations = append(config.Orderer.Organizations, &genesisconfig.Organization{ + MSPDir: filepath.Join(cryptoConfigDir, "ordererOrganizations", "example.com", "msp"), + OrdererEndpoints: []string{"foo:7050", "bar:8050"}, + MSPType: "bccsp", + ID: "SampleMSP", + Name: "SampleOrg", + Policies: map[string]*genesisconfig.Policy{ + "Admins": {Type: "ImplicitMeta", Rule: "ANY Admins"}, + "Readers": {Type: "ImplicitMeta", Rule: "ANY Readers"}, + "Writers": {Type: "ImplicitMeta", Rule: "ANY Writers"}, + }, + }) + group, err := encoder.NewChannelGroup(config) require.NoError(t, err) require.NotNil(t, group) @@ -758,7 +788,8 @@ func TestBlockVerifierBuilderNoConfigBlock(t *testing.T) { } func TestBlockVerifierFunc(t *testing.T) { - block := sampleConfigBlock() + block := sampleConfigBlock(t) + require.NotNil(t, block) bvfunc := cluster.BlockVerifierBuilder(&mocks.BCCSP{}) verifier := bvfunc(block) @@ -779,7 +810,21 @@ func TestBlockVerifierFunc(t *testing.T) { require.NoError(t, err) } -func sampleConfigBlock() *common.Block { +func sampleConfigBlock(t *testing.T) *common.Block { + certDir := t.TempDir() + tlsCA, err := tlsgen.NewCA() + require.NoError(t, err) + config := genesisconfig.Load(genesisconfig.SampleAppChannelSmartBftProfile, configtest.GetDevConfigDir()) + generateCertificatesSmartBFT(t, config, tlsCA, certDir) + config.Orderer.Organizations[0].OrdererEndpoints = []string{"127.0.0.1:7050"} + + group, err := encoder.NewChannelGroup(config) + if err != nil { + return nil + } + + sampleOrg := group.Groups["Orderer"].Groups["SampleOrg"] + return &common.Block{ Header: &common.BlockHeader{ PreviousHash: []byte("foo"), @@ -819,6 +864,9 @@ func sampleConfigBlock() *common.Block { }, }, }, + Groups: map[string]*common.ConfigGroup{ + "SampleOrg": sampleOrg, + }, Values: map[string]*common.ConfigValue{ "BatchSize": { Value: protoutil.MarshalOrPanic(&orderer.BatchSize{ @@ -867,6 +915,27 @@ func sampleConfigBlock() *common.Block { } } +func generateCertificatesSmartBFT(t *testing.T, confAppSmartBFT *genesisconfig.Profile, tlsCA tlsgen.CA, certDir string) { + for i, c := range confAppSmartBFT.Orderer.ConsenterMapping { + t.Logf("BFT Consenter: %+v", c) + srvC, err := tlsCA.NewServerCertKeyPair(c.Host) + require.NoError(t, err) + srvP := path.Join(certDir, fmt.Sprintf("server%d.crt", i)) + err = os.WriteFile(srvP, srvC.Cert, 0o644) + require.NoError(t, err) + + clnC, err := tlsCA.NewClientCertKeyPair() + require.NoError(t, err) + clnP := path.Join(certDir, fmt.Sprintf("client%d.crt", i)) + err = os.WriteFile(clnP, clnC.Cert, 0o644) + require.NoError(t, err) + + c.Identity = srvP + c.ServerTLSCert = srvP + c.ClientTLSCert = clnP + } +} + func TestGetTLSSessionBinding(t *testing.T) { serverCert, err := ca.NewServerCertKeyPair("127.0.0.1") require.NoError(t, err) diff --git a/orderer/common/multichannel/chainsupport_test.go b/orderer/common/multichannel/chainsupport_test.go index e41d760b32b..1a265402a17 100644 --- a/orderer/common/multichannel/chainsupport_test.go +++ b/orderer/common/multichannel/chainsupport_test.go @@ -28,6 +28,12 @@ func TestConsensusMetadataValidation(t *testing.T) { mockResources := &mocks.Resources{} mockResources.ConfigtxValidatorReturns(mockValidator) mockResources.OrdererConfigReturns(mockOrderer, true) + mockChannelConfig := &mocks.ChannelConfig{} + mockChannelConfig.OrdererAddressesReturns([]string{"127.0.0.1"}) + mockChannelCapabilities := &mocks.ChannelCapabilities{} + mockChannelCapabilities.ConsensusTypeBFTReturns(true) + mockChannelConfig.CapabilitiesReturns(mockChannelCapabilities) + mockResources.ChannelConfigReturns(mockChannelConfig) ms := &mutableResourcesMock{ Resources: mockResources, diff --git a/orderer/common/multichannel/ledger_resources_test.go b/orderer/common/multichannel/ledger_resources_test.go index fd8f7dc9a97..e22267826e1 100644 --- a/orderer/common/multichannel/ledger_resources_test.go +++ b/orderer/common/multichannel/ledger_resources_test.go @@ -72,7 +72,8 @@ func (mrm *mutableResourcesMock) CreateBundle(channelID string, c *common.Config } func testConfigEnvelope(t *testing.T) *common.ConfigEnvelope { - conf := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir()) + conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) + conf.Orderer.Organizations[0].OrdererEndpoints = []string{"127.0.0.1:7050"} group, err := encoder.NewChannelGroup(conf) require.NoError(t, err) group.Groups["Orderer"].Values["ConsensusType"].Value, err = proto.Marshal(&orderer.ConsensusType{ diff --git a/orderer/common/multichannel/util_test.go b/orderer/common/multichannel/util_test.go index 5a5ee462648..d356e46f348 100644 --- a/orderer/common/multichannel/util_test.go +++ b/orderer/common/multichannel/util_test.go @@ -120,10 +120,11 @@ func makeConfigTx(chainID string, i int) *cb.Envelope { } func makeConfigTxFull(chainID string, i int) *cb.Envelope { - gConf := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir()) + gConf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) gConf.Orderer.Capabilities = map[string]bool{ capabilities.OrdererV2_0: true, } + gConf.Orderer.Organizations[0].OrdererEndpoints = []string{"127.0.0.1:7050"} gConf.Orderer.MaxChannels = 10 channelGroup, err := encoder.NewChannelGroup(gConf) if err != nil { @@ -138,10 +139,11 @@ func makeConfigTxFull(chainID string, i int) *cb.Envelope { } func makeConfigTxMig(chainID string, i int) *cb.Envelope { - gConf := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir()) + gConf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) gConf.Orderer.Capabilities = map[string]bool{ capabilities.OrdererV2_0: true, } + gConf.Orderer.Organizations[0].OrdererEndpoints = []string{"127.0.0.1:7050"} gConf.Orderer.OrdererType = "solo" channelGroup, err := encoder.NewChannelGroup(gConf) if err != nil {