From 4289049d15718542b5e91c8b814a81300dc89793 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Tue, 7 Feb 2017 15:33:19 -0500 Subject: [PATCH] [FAB-2102] Move app shared config to common https://jira.hyperledger.org/browse/FAB-2102 Just as with the orderer shared configuration, having it declared outside of common was causing problems with imports. Additionally, in order to specify a config schema with the pending more flexible config scheme, this change is necessary. Change-Id: Ia73e7c06fceb2ab340af7e925796fd1917440643 Signed-off-by: Jason Yellick --- common/configtx/api/api.go | 7 +++++ .../handlers/application}/sharedconfig.go | 31 +++++++------------ .../application}/sharedconfig_test.go | 13 ++++---- .../application}/sharedconfig_util.go | 2 +- .../handlers/application}/template_test.go | 2 +- core/peer/peer.go | 16 +++++----- peer/channel/create.go | 4 +-- 7 files changed, 37 insertions(+), 38 deletions(-) rename {peer/sharedconfig => common/configtx/handlers/application}/sharedconfig.go (74%) rename {peer/sharedconfig => common/configtx/handlers/application}/sharedconfig_test.go (90%) rename {peer/sharedconfig => common/configtx/handlers/application}/sharedconfig_util.go (98%) rename {peer/sharedconfig => common/configtx/handlers/application}/template_test.go (97%) diff --git a/common/configtx/api/api.go b/common/configtx/api/api.go index 2230e9acaef..7708473c219 100644 --- a/common/configtx/api/api.go +++ b/common/configtx/api/api.go @@ -24,8 +24,15 @@ import ( "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" + pb "github.com/hyperledger/fabric/protos/peer" ) +// ApplicationConfig stores the common shared application config +type ApplicationConfig interface { + // AnchorPeers returns the list of gossip anchor peers + AnchorPeers() []*pb.AnchorPeer +} + // OrdererConfig stores the common shared orderer config type OrdererConfig interface { // ConsensusType returns the configured consensus type diff --git a/peer/sharedconfig/sharedconfig.go b/common/configtx/handlers/application/sharedconfig.go similarity index 74% rename from peer/sharedconfig/sharedconfig.go rename to common/configtx/handlers/application/sharedconfig.go index 33aa9bae83b..008070440e1 100644 --- a/peer/sharedconfig/sharedconfig.go +++ b/common/configtx/handlers/application/sharedconfig.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package sharedconfig +package application import ( "fmt" @@ -34,40 +34,31 @@ const ( var logger = logging.MustGetLogger("peer/sharedconfig") -// Descriptor stores the common peer config -// It is intended to be the primary accessor of DescriptorImpl -// It is intended to discourage use of the other exported DescriptorImpl methods -// which are used for updating the chain config by the configtx.Manager -type Descriptor interface { - // AnchorPeers returns the list of anchor peers for the channel - AnchorPeers() []*pb.AnchorPeer -} - type sharedConfig struct { anchorPeers []*pb.AnchorPeer } -// DescriptorImpl is an implementation of Manager and configtx.ConfigHandler +// SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler // In general, it should only be referenced as an Impl for the configtx.Manager -type DescriptorImpl struct { +type SharedConfigImpl struct { pendingConfig *sharedConfig config *sharedConfig } -// NewDescriptorImpl creates a new DescriptorImpl with the given CryptoHelper -func NewDescriptorImpl() *DescriptorImpl { - return &DescriptorImpl{ +// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper +func NewSharedConfigImpl() *SharedConfigImpl { + return &SharedConfigImpl{ config: &sharedConfig{}, } } // AnchorPeers returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver -func (di *DescriptorImpl) AnchorPeers() []*pb.AnchorPeer { +func (di *SharedConfigImpl) AnchorPeers() []*pb.AnchorPeer { return di.config.anchorPeers } // BeginConfig is used to start a new config proposal -func (di *DescriptorImpl) BeginConfig() { +func (di *SharedConfigImpl) BeginConfig() { logger.Debugf("Beginning a possible new peer shared config") if di.pendingConfig != nil { logger.Panicf("Programming error, cannot call begin in the middle of a proposal") @@ -76,13 +67,13 @@ func (di *DescriptorImpl) BeginConfig() { } // RollbackConfig is used to abandon a new config proposal -func (di *DescriptorImpl) RollbackConfig() { +func (di *SharedConfigImpl) RollbackConfig() { logger.Debugf("Rolling back proposed peer shared config") di.pendingConfig = nil } // CommitConfig is used to commit a new config proposal -func (di *DescriptorImpl) CommitConfig() { +func (di *SharedConfigImpl) CommitConfig() { logger.Debugf("Committing new peer shared config") if di.pendingConfig == nil { logger.Panicf("Programming error, cannot call commit without an existing proposal") @@ -92,7 +83,7 @@ func (di *DescriptorImpl) CommitConfig() { } // ProposeConfig is used to add new config to the config proposal -func (di *DescriptorImpl) ProposeConfig(configItem *cb.ConfigItem) error { +func (di *SharedConfigImpl) ProposeConfig(configItem *cb.ConfigItem) error { if configItem.Type != cb.ConfigItem_Peer { return fmt.Errorf("Expected type of ConfigItem_Peer, got %v", configItem.Type) } diff --git a/peer/sharedconfig/sharedconfig_test.go b/common/configtx/handlers/application/sharedconfig_test.go similarity index 90% rename from peer/sharedconfig/sharedconfig_test.go rename to common/configtx/handlers/application/sharedconfig_test.go index 3b453154f8b..a509cbbe831 100644 --- a/peer/sharedconfig/sharedconfig_test.go +++ b/common/configtx/handlers/application/sharedconfig_test.go @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package sharedconfig +package application import ( "reflect" "testing" + configtxapi "github.com/hyperledger/fabric/common/configtx/api" cb "github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric/protos/peer" @@ -39,7 +40,7 @@ func makeInvalidConfigItem(key string) *cb.ConfigItem { } func TestInterface(t *testing.T) { - _ = Descriptor(NewDescriptorImpl()) + _ = configtxapi.ApplicationConfig(NewSharedConfigImpl()) } func TestDoubleBegin(t *testing.T) { @@ -49,7 +50,7 @@ func TestDoubleBegin(t *testing.T) { } }() - m := NewDescriptorImpl() + m := NewSharedConfigImpl() m.BeginConfig() m.BeginConfig() } @@ -61,12 +62,12 @@ func TestCommitWithoutBegin(t *testing.T) { } }() - m := NewDescriptorImpl() + m := NewSharedConfigImpl() m.CommitConfig() } func TestRollback(t *testing.T) { - m := NewDescriptorImpl() + m := NewSharedConfigImpl() m.pendingConfig = &sharedConfig{} m.RollbackConfig() if m.pendingConfig != nil { @@ -81,7 +82,7 @@ func TestAnchorPeers(t *testing.T) { } invalidMessage := makeInvalidConfigItem(AnchorPeersKey) validMessage := TemplateAnchorPeers(endVal) - m := NewDescriptorImpl() + m := NewSharedConfigImpl() m.BeginConfig() err := m.ProposeConfig(invalidMessage) diff --git a/peer/sharedconfig/sharedconfig_util.go b/common/configtx/handlers/application/sharedconfig_util.go similarity index 98% rename from peer/sharedconfig/sharedconfig_util.go rename to common/configtx/handlers/application/sharedconfig_util.go index 58d96fa324c..d3e78e472a9 100644 --- a/peer/sharedconfig/sharedconfig_util.go +++ b/common/configtx/handlers/application/sharedconfig_util.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package sharedconfig +package application import ( cb "github.com/hyperledger/fabric/protos/common" diff --git a/peer/sharedconfig/template_test.go b/common/configtx/handlers/application/template_test.go similarity index 97% rename from peer/sharedconfig/template_test.go rename to common/configtx/handlers/application/template_test.go index 929f7ba7e52..53daef4727f 100644 --- a/peer/sharedconfig/template_test.go +++ b/common/configtx/handlers/application/template_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package sharedconfig +package application import ( "testing" diff --git a/core/peer/peer.go b/core/peer/peer.go index ddb441c263a..47d0390df44 100644 --- a/core/peer/peer.go +++ b/core/peer/peer.go @@ -24,6 +24,7 @@ import ( "github.com/hyperledger/fabric/common/configtx" configtxapi "github.com/hyperledger/fabric/common/configtx/api" + configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application" "github.com/hyperledger/fabric/core/comm" "github.com/hyperledger/fabric/core/committer" "github.com/hyperledger/fabric/core/committer/txvalidator" @@ -32,7 +33,6 @@ import ( "github.com/hyperledger/fabric/gossip/service" "github.com/hyperledger/fabric/msp" mspmgmt "github.com/hyperledger/fabric/msp/mgmt" - "github.com/hyperledger/fabric/peer/sharedconfig" "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" "github.com/op/go-logging" @@ -44,7 +44,7 @@ var peerLogger = logging.MustGetLogger("peer") type chainSupport struct { configtxapi.Manager - sharedconfig.Descriptor + configtxapi.ApplicationConfig ledger ledger.PeerLedger } @@ -160,14 +160,14 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error { return err } - sharedConfigHandler := sharedconfig.NewDescriptorImpl() + sharedConfigHandler := configtxapplication.NewSharedConfigImpl() gossipEventer := service.GetGossipService().NewConfigEventer() gossipCallbackWrapper := func(cm configtxapi.Manager) { gossipEventer.ProcessConfigUpdate(&chainSupport{ - Manager: cm, - Descriptor: sharedConfigHandler, + Manager: cm, + ApplicationConfig: sharedConfigHandler, }) } @@ -186,9 +186,9 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error { mspmgmt.XXXSetMSPManager(cid, configtxManager.MSPManager()) cs := &chainSupport{ - Manager: configtxManager, - Descriptor: sharedConfigHandler, - ledger: ledger, + Manager: configtxManager, + ApplicationConfig: sharedConfigHandler, + ledger: ledger, } c := committer.NewLedgerCommitter(ledger, txvalidator.NewTxValidator(cs)) diff --git a/peer/channel/create.go b/peer/channel/create.go index 2c52cb8cb6b..1b4e3b3d782 100644 --- a/peer/channel/create.go +++ b/peer/channel/create.go @@ -22,11 +22,11 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/common/configtx" + configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application" configtxtest "github.com/hyperledger/fabric/common/configtx/test" mspmgmt "github.com/hyperledger/fabric/msp/mgmt" "github.com/hyperledger/fabric/orderer/common/bootstrap/provisional" "github.com/hyperledger/fabric/peer/common" - "github.com/hyperledger/fabric/peer/sharedconfig" cb "github.com/hyperledger/fabric/protos/common" "github.com/spf13/cobra" ) @@ -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.NewSimpleTemplate(sharedconfig.TemplateAnchorPeers(anchorPeers)) + gossTemplate := configtx.NewSimpleTemplate(configtxapplication.TemplateAnchorPeers(anchorPeers)) chCrtTemp := configtx.NewCompositeTemplate(oTemplate, mspTemplate, gossTemplate) signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()