Skip to content

Commit f3da0ba

Browse files
Jason Yellickkchristidis
Jason Yellick
authored andcommitted
[FAB-2703] (PA) Expose committed configEnvelope
The config manager does not currently store the raw config envelope which generated the current config. For constructions which require access to the raw keys, this is problematic, so this CR stores, and adds a method to access this config envelop. Change-Id: Icf41cbef118f920f346325fcb11b710dbdeccf97 Signed-off-by: Jason Yellick <[email protected]> Signed-off-by: Kostas Christidis <[email protected]>
1 parent c3c64fa commit f3da0ba

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

common/configtx/api/api.go

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type Manager interface {
4141
// ChainID retrieves the chain ID associated with this manager
4242
ChainID() string
4343

44+
// ConfigEnvelope returns the current config envelope
45+
ConfigEnvelope() *cb.ConfigEnvelope
46+
4447
// Sequence returns the current sequence number of the config
4548
Sequence() uint64
4649
}

common/configtx/manager.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type configSet struct {
4343
channelID string
4444
sequence uint64
4545
configMap map[string]comparable
46+
configEnv *cb.ConfigEnvelope
4647
}
4748

4849
type configManager struct {
@@ -113,6 +114,7 @@ func NewManagerImpl(envConfig *cb.Envelope, initializer api.Initializer, callOnU
113114
sequence: configEnv.Config.Sequence,
114115
configMap: configMap,
115116
channelID: header.ChannelId,
117+
configEnv: configEnv,
116118
},
117119
callOnUpdate: callOnUpdate,
118120
}
@@ -142,12 +144,12 @@ func (cm *configManager) ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigE
142144
func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
143145
configUpdateEnv, err := envelopeToConfigUpdate(configtx)
144146
if err != nil {
145-
return nil, err
147+
return nil, fmt.Errorf("Error converting envelope to config update: %s", err)
146148
}
147149

148150
configMap, err := cm.authorizeUpdate(configUpdateEnv)
149151
if err != nil {
150-
return nil, err
152+
return nil, fmt.Errorf("Error authorizing update: %s", err)
151153
}
152154

153155
channelGroup, err := configMapToConfig(configMap)
@@ -157,7 +159,7 @@ func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigE
157159

158160
result, err := cm.processConfig(channelGroup)
159161
if err != nil {
160-
return nil, err
162+
return nil, fmt.Errorf("Error processing updated config: %s", err)
161163
}
162164

163165
result.rollback()
@@ -231,14 +233,16 @@ func (cm *configManager) Apply(configEnv *cb.ConfigEnvelope) error {
231233
}
232234

233235
result.commit()
234-
cm.commitCallbacks()
235236

236237
cm.current = &configSet{
237238
configMap: configMap,
238239
channelID: cm.current.channelID,
239240
sequence: configEnv.Config.Sequence,
241+
configEnv: configEnv,
240242
}
241243

244+
cm.commitCallbacks()
245+
242246
return nil
243247
}
244248

@@ -251,3 +255,8 @@ func (cm *configManager) ChainID() string {
251255
func (cm *configManager) Sequence() uint64 {
252256
return cm.current.sequence
253257
}
258+
259+
// ConfigEnvelope returns the current config envelope
260+
func (cm *configManager) ConfigEnvelope() *cb.ConfigEnvelope {
261+
return cm.current.configEnv
262+
}

common/mocks/configtx/configtx.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,14 @@ type Manager struct {
179179

180180
// ProposeConfigUpdateVal is returns as the value for ProposeConfigUpdate
181181
ProposeConfigUpdateVal *cb.ConfigEnvelope
182+
183+
// ConfigEnvelopeVal is returned as the value for ConfigEnvelope()
184+
ConfigEnvelopeVal *cb.ConfigEnvelope
182185
}
183186

184-
// ConfigEnvelope is currently unimplemented
187+
// ConfigEnvelope returns the ConfigEnvelopeVal
185188
func (cm *Manager) ConfigEnvelope() *cb.ConfigEnvelope {
186-
panic("Unimplemented")
189+
return cm.ConfigEnvelopeVal
187190
}
188191

189192
// ConsensusType returns the ConsensusTypeVal

0 commit comments

Comments
 (0)