Skip to content

Commit 4289049

Browse files
author
Jason Yellick
committed
[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 <[email protected]>
1 parent 3b320c6 commit 4289049

File tree

7 files changed

+37
-38
lines changed

7 files changed

+37
-38
lines changed

common/configtx/api/api.go

+7
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ import (
2424
"github.com/hyperledger/fabric/msp"
2525
cb "github.com/hyperledger/fabric/protos/common"
2626
ab "github.com/hyperledger/fabric/protos/orderer"
27+
pb "github.com/hyperledger/fabric/protos/peer"
2728
)
2829

30+
// ApplicationConfig stores the common shared application config
31+
type ApplicationConfig interface {
32+
// AnchorPeers returns the list of gossip anchor peers
33+
AnchorPeers() []*pb.AnchorPeer
34+
}
35+
2936
// OrdererConfig stores the common shared orderer config
3037
type OrdererConfig interface {
3138
// ConsensusType returns the configured consensus type

peer/sharedconfig/sharedconfig.go common/configtx/handlers/application/sharedconfig.go

+11-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package application
1818

1919
import (
2020
"fmt"
@@ -34,40 +34,31 @@ const (
3434

3535
var logger = logging.MustGetLogger("peer/sharedconfig")
3636

37-
// Descriptor stores the common peer config
38-
// It is intended to be the primary accessor of DescriptorImpl
39-
// It is intended to discourage use of the other exported DescriptorImpl methods
40-
// which are used for updating the chain config by the configtx.Manager
41-
type Descriptor interface {
42-
// AnchorPeers returns the list of anchor peers for the channel
43-
AnchorPeers() []*pb.AnchorPeer
44-
}
45-
4637
type sharedConfig struct {
4738
anchorPeers []*pb.AnchorPeer
4839
}
4940

50-
// DescriptorImpl is an implementation of Manager and configtx.ConfigHandler
41+
// SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler
5142
// In general, it should only be referenced as an Impl for the configtx.Manager
52-
type DescriptorImpl struct {
43+
type SharedConfigImpl struct {
5344
pendingConfig *sharedConfig
5445
config *sharedConfig
5546
}
5647

57-
// NewDescriptorImpl creates a new DescriptorImpl with the given CryptoHelper
58-
func NewDescriptorImpl() *DescriptorImpl {
59-
return &DescriptorImpl{
48+
// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
49+
func NewSharedConfigImpl() *SharedConfigImpl {
50+
return &SharedConfigImpl{
6051
config: &sharedConfig{},
6152
}
6253
}
6354

6455
// AnchorPeers returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
65-
func (di *DescriptorImpl) AnchorPeers() []*pb.AnchorPeer {
56+
func (di *SharedConfigImpl) AnchorPeers() []*pb.AnchorPeer {
6657
return di.config.anchorPeers
6758
}
6859

6960
// BeginConfig is used to start a new config proposal
70-
func (di *DescriptorImpl) BeginConfig() {
61+
func (di *SharedConfigImpl) BeginConfig() {
7162
logger.Debugf("Beginning a possible new peer shared config")
7263
if di.pendingConfig != nil {
7364
logger.Panicf("Programming error, cannot call begin in the middle of a proposal")
@@ -76,13 +67,13 @@ func (di *DescriptorImpl) BeginConfig() {
7667
}
7768

7869
// RollbackConfig is used to abandon a new config proposal
79-
func (di *DescriptorImpl) RollbackConfig() {
70+
func (di *SharedConfigImpl) RollbackConfig() {
8071
logger.Debugf("Rolling back proposed peer shared config")
8172
di.pendingConfig = nil
8273
}
8374

8475
// CommitConfig is used to commit a new config proposal
85-
func (di *DescriptorImpl) CommitConfig() {
76+
func (di *SharedConfigImpl) CommitConfig() {
8677
logger.Debugf("Committing new peer shared config")
8778
if di.pendingConfig == nil {
8879
logger.Panicf("Programming error, cannot call commit without an existing proposal")
@@ -92,7 +83,7 @@ func (di *DescriptorImpl) CommitConfig() {
9283
}
9384

9485
// ProposeConfig is used to add new config to the config proposal
95-
func (di *DescriptorImpl) ProposeConfig(configItem *cb.ConfigItem) error {
86+
func (di *SharedConfigImpl) ProposeConfig(configItem *cb.ConfigItem) error {
9687
if configItem.Type != cb.ConfigItem_Peer {
9788
return fmt.Errorf("Expected type of ConfigItem_Peer, got %v", configItem.Type)
9889
}

peer/sharedconfig/sharedconfig_test.go common/configtx/handlers/application/sharedconfig_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package application
1818

1919
import (
2020
"reflect"
2121
"testing"
2222

23+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2324
cb "github.com/hyperledger/fabric/protos/common"
2425
pb "github.com/hyperledger/fabric/protos/peer"
2526

@@ -39,7 +40,7 @@ func makeInvalidConfigItem(key string) *cb.ConfigItem {
3940
}
4041

4142
func TestInterface(t *testing.T) {
42-
_ = Descriptor(NewDescriptorImpl())
43+
_ = configtxapi.ApplicationConfig(NewSharedConfigImpl())
4344
}
4445

4546
func TestDoubleBegin(t *testing.T) {
@@ -49,7 +50,7 @@ func TestDoubleBegin(t *testing.T) {
4950
}
5051
}()
5152

52-
m := NewDescriptorImpl()
53+
m := NewSharedConfigImpl()
5354
m.BeginConfig()
5455
m.BeginConfig()
5556
}
@@ -61,12 +62,12 @@ func TestCommitWithoutBegin(t *testing.T) {
6162
}
6263
}()
6364

64-
m := NewDescriptorImpl()
65+
m := NewSharedConfigImpl()
6566
m.CommitConfig()
6667
}
6768

6869
func TestRollback(t *testing.T) {
69-
m := NewDescriptorImpl()
70+
m := NewSharedConfigImpl()
7071
m.pendingConfig = &sharedConfig{}
7172
m.RollbackConfig()
7273
if m.pendingConfig != nil {
@@ -81,7 +82,7 @@ func TestAnchorPeers(t *testing.T) {
8182
}
8283
invalidMessage := makeInvalidConfigItem(AnchorPeersKey)
8384
validMessage := TemplateAnchorPeers(endVal)
84-
m := NewDescriptorImpl()
85+
m := NewSharedConfigImpl()
8586
m.BeginConfig()
8687

8788
err := m.ProposeConfig(invalidMessage)

peer/sharedconfig/sharedconfig_util.go common/configtx/handlers/application/sharedconfig_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package application
1818

1919
import (
2020
cb "github.com/hyperledger/fabric/protos/common"

peer/sharedconfig/template_test.go common/configtx/handlers/application/template_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package application
1818

1919
import (
2020
"testing"

core/peer/peer.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/hyperledger/fabric/common/configtx"
2626
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
27+
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
2728
"github.com/hyperledger/fabric/core/comm"
2829
"github.com/hyperledger/fabric/core/committer"
2930
"github.com/hyperledger/fabric/core/committer/txvalidator"
@@ -32,7 +33,6 @@ import (
3233
"github.com/hyperledger/fabric/gossip/service"
3334
"github.com/hyperledger/fabric/msp"
3435
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
35-
"github.com/hyperledger/fabric/peer/sharedconfig"
3636
"github.com/hyperledger/fabric/protos/common"
3737
"github.com/hyperledger/fabric/protos/utils"
3838
"github.com/op/go-logging"
@@ -44,7 +44,7 @@ var peerLogger = logging.MustGetLogger("peer")
4444

4545
type chainSupport struct {
4646
configtxapi.Manager
47-
sharedconfig.Descriptor
47+
configtxapi.ApplicationConfig
4848
ledger ledger.PeerLedger
4949
}
5050

@@ -160,14 +160,14 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
160160
return err
161161
}
162162

163-
sharedConfigHandler := sharedconfig.NewDescriptorImpl()
163+
sharedConfigHandler := configtxapplication.NewSharedConfigImpl()
164164

165165
gossipEventer := service.GetGossipService().NewConfigEventer()
166166

167167
gossipCallbackWrapper := func(cm configtxapi.Manager) {
168168
gossipEventer.ProcessConfigUpdate(&chainSupport{
169-
Manager: cm,
170-
Descriptor: sharedConfigHandler,
169+
Manager: cm,
170+
ApplicationConfig: sharedConfigHandler,
171171
})
172172
}
173173

@@ -186,9 +186,9 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
186186
mspmgmt.XXXSetMSPManager(cid, configtxManager.MSPManager())
187187

188188
cs := &chainSupport{
189-
Manager: configtxManager,
190-
Descriptor: sharedConfigHandler,
191-
ledger: ledger,
189+
Manager: configtxManager,
190+
ApplicationConfig: sharedConfigHandler,
191+
ledger: ledger,
192192
}
193193

194194
c := committer.NewLedgerCommitter(ledger, txvalidator.NewTxValidator(cs))

peer/channel/create.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222

2323
"github.com/golang/protobuf/proto"
2424
"github.com/hyperledger/fabric/common/configtx"
25+
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
2526
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
2627
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2728
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
2829
"github.com/hyperledger/fabric/peer/common"
29-
"github.com/hyperledger/fabric/peer/sharedconfig"
3030
cb "github.com/hyperledger/fabric/protos/common"
3131
"github.com/spf13/cobra"
3232
)
@@ -55,7 +55,7 @@ func sendCreateChainTransaction(cf *ChannelCmdFactory) error {
5555
//TODO this is a temporary hack until `orderer.template` and 'msp.template' is supplied from the CLI
5656
oTemplate := configtxtest.OrdererTemplate()
5757
mspTemplate := configtxtest.MSPTemplate()
58-
gossTemplate := configtx.NewSimpleTemplate(sharedconfig.TemplateAnchorPeers(anchorPeers))
58+
gossTemplate := configtx.NewSimpleTemplate(configtxapplication.TemplateAnchorPeers(anchorPeers))
5959
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, mspTemplate, gossTemplate)
6060

6161
signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()

0 commit comments

Comments
 (0)