Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAB-17912 Ch.Part.API: reject joins #1375

Merged
merged 1 commit into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions orderer/common/multichannel/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ func (r *Registrar) ChannelInfo(channelID string) (types.ChannelInfo, error) {
}

func (r *Registrar) JoinChannel(channelID string, configBlock *cb.Block) (types.ChannelInfo, error) {
r.lock.RLock()
defer r.lock.RUnlock()

if r.systemChannelID != "" {
return types.ChannelInfo{}, types.ErrSystemChannelExists
}

_, ok := r.chains[channelID]
if ok {
return types.ChannelInfo{}, types.ErrChannelAlreadyExists
}

//TODO
return types.ChannelInfo{}, errors.New("Not implemented yet")
}
Expand Down
58 changes: 57 additions & 1 deletion orderer/common/multichannel/registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package multichannel

import (
"github.com/hyperledger/fabric/orderer/common/types"
"io/ioutil"
"os"
"testing"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/hyperledger/fabric/orderer/common/blockcutter"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"github.com/hyperledger/fabric/orderer/common/multichannel/mocks"
"github.com/hyperledger/fabric/orderer/common/types"
"github.com/hyperledger/fabric/orderer/consensus"
"github.com/hyperledger/fabric/protoutil"
"github.com/pkg/errors"
Expand Down Expand Up @@ -508,3 +508,59 @@ func TestBroadcastChannelSupport(t *testing.T) {
assert.Equal(t, "channel creation request not allowed because the orderer system channel is not defined", err.Error())
})
}

func TestRegistrar_JoinChannel(t *testing.T) {
// system channel
confSys := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir())
genesisBlockSys := encoder.New(confSys).GenesisBlockForChannel("sys-channel")
confApp := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile, configtest.GetDevConfigDir())
confApp.Consortiums = nil
confApp.Consortium = ""
genesisBlockApp := encoder.New(confApp).GenesisBlockForChannel("my-channel")

cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore())
assert.NoError(t, err)

t.Run("Reject join when system channel exists", func(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "registrar_test-")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)

ledgerFactory, _ := newLedgerAndFactory(tmpdir, "sys-channel", genesisBlockSys)
mockConsenters := map[string]consensus.Consenter{confSys.Orderer.OrdererType: &mockConsenter{}}
registrar := NewRegistrar(localconfig.TopLevel{}, ledgerFactory, mockCrypto(), &disabled.Provider{}, cryptoProvider)
registrar.Initialize(mockConsenters)

info, err := registrar.JoinChannel("some-app-channel", &cb.Block{})
assert.EqualError(t, err, "system channel exists")
assert.Equal(t, types.ChannelInfo{}, info)
})

t.Run("Reject join when channel exists", func(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "registrar_test-")
require.NoError(t, err)
defer os.RemoveAll(tmpdir)

ledgerFactory, _ := newLedgerAndFactory(tmpdir, "", nil)
mockConsenters := map[string]consensus.Consenter{confSys.Orderer.OrdererType: &mockConsenter{}}
config := localconfig.TopLevel{}
config.General.BootstrapMethod = "none"
config.General.GenesisFile = ""
registrar := NewRegistrar(config, ledgerFactory, mockCrypto(), &disabled.Provider{}, cryptoProvider)
registrar.Initialize(mockConsenters)

ledger, err := ledgerFactory.GetOrCreate("my-channel")
assert.NoError(t, err)
ledger.Append(genesisBlockApp)

// Before creating the chain, it doesn't exist
assert.Nil(t, registrar.GetChain("my-channel"))
// After creating the chain, it exists
registrar.CreateChain("my-channel")
assert.NotNil(t, registrar.GetChain("my-channel"))

info, err := registrar.JoinChannel("my-channel", &cb.Block{})
assert.EqualError(t, err, "channel already exists")
assert.Equal(t, types.ChannelInfo{}, info)
})
}