From f3da0ba2bcb1dfdcba602d1312061dafe0839f52 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Wed, 8 Mar 2017 15:26:54 -0500 Subject: [PATCH] [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 Signed-off-by: Kostas Christidis --- common/configtx/api/api.go | 3 +++ common/configtx/manager.go | 17 +++++++++++++---- common/mocks/configtx/configtx.go | 7 +++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/common/configtx/api/api.go b/common/configtx/api/api.go index caa870e853f..b8a49e82dc5 100644 --- a/common/configtx/api/api.go +++ b/common/configtx/api/api.go @@ -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 } diff --git a/common/configtx/manager.go b/common/configtx/manager.go index aa367e1ced4..c31e1be4897 100644 --- a/common/configtx/manager.go +++ b/common/configtx/manager.go @@ -43,6 +43,7 @@ type configSet struct { channelID string sequence uint64 configMap map[string]comparable + configEnv *cb.ConfigEnvelope } type configManager struct { @@ -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, } @@ -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) @@ -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() @@ -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 } @@ -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 +} diff --git a/common/mocks/configtx/configtx.go b/common/mocks/configtx/configtx.go index 90f3c3075ae..aa3296142b9 100644 --- a/common/mocks/configtx/configtx.go +++ b/common/mocks/configtx/configtx.go @@ -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