Skip to content

Commit

Permalink
[FAB-2102] Move app shared config to common
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 8, 2017
1 parent 3b320c6 commit 4289049
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
7 changes: 7 additions & 0 deletions common/configtx/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package application

import (
"fmt"
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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) {
Expand All @@ -49,7 +50,7 @@ func TestDoubleBegin(t *testing.T) {
}
}()

m := NewDescriptorImpl()
m := NewSharedConfigImpl()
m.BeginConfig()
m.BeginConfig()
}
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package application

import (
"testing"
Expand Down
16 changes: 8 additions & 8 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -44,7 +44,7 @@ var peerLogger = logging.MustGetLogger("peer")

type chainSupport struct {
configtxapi.Manager
sharedconfig.Descriptor
configtxapi.ApplicationConfig
ledger ledger.PeerLedger
}

Expand Down Expand Up @@ -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,
})
}

Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions peer/channel/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4289049

Please sign in to comment.