Skip to content

Commit

Permalink
[FAB-2703] (PA) Expose committed configEnvelope
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
Signed-off-by: Kostas Christidis <kostas@christidis.io>
  • Loading branch information
Jason Yellick authored and kchristidis committed Apr 26, 2017
1 parent c3c64fa commit f3da0ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions common/configtx/api/api.go
Expand Up @@ -41,6 +41,9 @@ type Manager interface {
// ChainID retrieves the chain ID associated with this manager
ChainID() string

// ConfigEnvelope returns the current config envelope
ConfigEnvelope() *cb.ConfigEnvelope

// Sequence returns the current sequence number of the config
Sequence() uint64
}
Expand Down
17 changes: 13 additions & 4 deletions common/configtx/manager.go
Expand Up @@ -43,6 +43,7 @@ type configSet struct {
channelID string
sequence uint64
configMap map[string]comparable
configEnv *cb.ConfigEnvelope
}

type configManager struct {
Expand Down Expand Up @@ -113,6 +114,7 @@ func NewManagerImpl(envConfig *cb.Envelope, initializer api.Initializer, callOnU
sequence: configEnv.Config.Sequence,
configMap: configMap,
channelID: header.ChannelId,
configEnv: configEnv,
},
callOnUpdate: callOnUpdate,
}
Expand Down Expand Up @@ -142,12 +144,12 @@ func (cm *configManager) ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigE
func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
configUpdateEnv, err := envelopeToConfigUpdate(configtx)
if err != nil {
return nil, err
return nil, fmt.Errorf("Error converting envelope to config update: %s", err)
}

configMap, err := cm.authorizeUpdate(configUpdateEnv)
if err != nil {
return nil, err
return nil, fmt.Errorf("Error authorizing update: %s", err)
}

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

result, err := cm.processConfig(channelGroup)
if err != nil {
return nil, err
return nil, fmt.Errorf("Error processing updated config: %s", err)
}

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

result.commit()
cm.commitCallbacks()

cm.current = &configSet{
configMap: configMap,
channelID: cm.current.channelID,
sequence: configEnv.Config.Sequence,
configEnv: configEnv,
}

cm.commitCallbacks()

return nil
}

Expand All @@ -251,3 +255,8 @@ func (cm *configManager) ChainID() string {
func (cm *configManager) Sequence() uint64 {
return cm.current.sequence
}

// ConfigEnvelope returns the current config envelope
func (cm *configManager) ConfigEnvelope() *cb.ConfigEnvelope {
return cm.current.configEnv
}
7 changes: 5 additions & 2 deletions common/mocks/configtx/configtx.go
Expand Up @@ -179,11 +179,14 @@ type Manager struct {

// ProposeConfigUpdateVal is returns as the value for ProposeConfigUpdate
ProposeConfigUpdateVal *cb.ConfigEnvelope

// ConfigEnvelopeVal is returned as the value for ConfigEnvelope()
ConfigEnvelopeVal *cb.ConfigEnvelope
}

// ConfigEnvelope is currently unimplemented
// ConfigEnvelope returns the ConfigEnvelopeVal
func (cm *Manager) ConfigEnvelope() *cb.ConfigEnvelope {
panic("Unimplemented")
return cm.ConfigEnvelopeVal
}

// ConsensusType returns the ConsensusTypeVal
Expand Down

0 comments on commit f3da0ba

Please sign in to comment.