Skip to content

Commit

Permalink
[FAB-5236] System channel ID should be configurable
Browse files Browse the repository at this point in the history
System channel ID is hardcoded to 'testchainid' when using provisional
genesis method. This should be configurable so that we could run multiple
tests against a stateful service, e.g. Kafka, without cleaning up the
environment after each run. Otherwise, after the first run, later ones
would recognize 'testchainid' and recover states from it. Also, we meant
to deprecate this hardcoded manner anyway.

Note: this is for testing purpose only, so we don't expose it in the
orderer config yaml.

Change-Id: I60590f52c304e003e3dd74c27aa0f3bec3bb996a
Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
  • Loading branch information
guoger committed Jul 25, 2017
1 parent 60f8f32 commit 452c7eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions orderer/common/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"path/filepath"

bccsp "github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
)

const (
Expand Down Expand Up @@ -74,6 +75,7 @@ type General struct {
TLS TLS
GenesisMethod string
GenesisProfile string
SystemChannel string
GenesisFile string
Profile Profile
LogLevel string
Expand Down Expand Up @@ -167,6 +169,7 @@ var defaults = TopLevel{
ListenPort: 7050,
GenesisMethod: "provisional",
GenesisProfile: "SampleSingleMSPSolo",
SystemChannel: provisional.TestChainID,
GenesisFile: "genesisblock",
Profile: Profile{
Enabled: false,
Expand Down Expand Up @@ -276,6 +279,8 @@ func (c *TopLevel) completeInitialization(configDir string) {
c.General.GenesisFile = defaults.General.GenesisFile
case c.General.GenesisProfile == "":
c.General.GenesisProfile = defaults.General.GenesisProfile
case c.General.SystemChannel == "":
c.General.SystemChannel = defaults.General.SystemChannel

case c.Kafka.TLS.Enabled && c.Kafka.TLS.Certificate == "":
logger.Panicf("General.Kafka.TLS.Certificate must be set if General.Kafka.TLS.Enabled is set to true.")
Expand Down
6 changes: 6 additions & 0 deletions orderer/common/localconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/common/configtx/tool/provisional"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -111,6 +112,11 @@ func TestKafkaTLSConfig(t *testing.T) {
}
}

func TestSystemChannel(t *testing.T) {
conf := Load()
assert.Equal(t, provisional.TestChainID, conf.General.SystemChannel, "System channel ID should be '%s' by default", provisional.TestChainID)
}

func TestProfileConfig(t *testing.T) {
uconf := &TopLevel{General: General{Profile: Profile{Enabled: true}}}
uconf.completeInitialization(DummyPath)
Expand Down
2 changes: 1 addition & 1 deletion orderer/common/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func initializeBootstrapChannel(conf *config.TopLevel, lf ledger.Factory) {
// Select the bootstrapping mechanism
switch conf.General.GenesisMethod {
case "provisional":
genesisBlock = provisional.New(genesisconfig.Load(conf.General.GenesisProfile)).GenesisBlock()
genesisBlock = provisional.New(genesisconfig.Load(conf.General.GenesisProfile)).GenesisBlockForChannel(conf.General.SystemChannel)
case "file":
genesisBlock = file.New(conf.General.GenesisFile).GenesisBlock()
default:
Expand Down
12 changes: 7 additions & 5 deletions orderer/common/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (

"github.com/Shopify/sarama"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/localmsp"
coreconfig "github.com/hyperledger/fabric/core/config"
config "github.com/hyperledger/fabric/orderer/common/localconfig"
logging "github.com/op/go-logging"
// logging "github.com/op/go-logging"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"github.com/op/go-logging"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -164,9 +164,10 @@ func TestInitializeBootstrapChannel(t *testing.T) {
initializeBootstrapChannel(bootstrapConfig, ledgerFactory)
})
} else {
initializeBootstrapChannel(bootstrapConfig, ledgerFactory)
assert.NotPanics(t, func() {
initializeBootstrapChannel(bootstrapConfig, ledgerFactory)
})
}

})
}
}
Expand Down Expand Up @@ -216,6 +217,7 @@ func TestInitializeMultiChainManager(t *testing.T) {
LedgerType: "ram",
GenesisMethod: "provisional",
GenesisProfile: "SampleSingleMSPSolo",
SystemChannel: provisional.TestChainID,
LocalMSPDir: localMSPDir,
LocalMSPID: "DEFAULT",
BCCSP: &factory.FactoryOpts{
Expand Down

0 comments on commit 452c7eb

Please sign in to comment.