Commit e851f7a0 authored by Jason Yellick's avatar Jason Yellick Committed by Gari Singh
Browse files

FAB-8591 Improve channel create/update error



This CR simply wraps the output returned from the configtx processing to
indicate whether the update processing was being treated as channel
creation, or as a channel update.  This is to assist users especially
when they attempt to recreate an extant channel resulting in a
previously difficult to understand error message.

Change-Id: I39d0adc0a4b9b53aa252710575e83309f5fa4524
Signed-off-by: default avatarJason Yellick <jyellick@us.ibm.com>
parent 75e19aa0
......@@ -22,7 +22,7 @@ func (vi *ValidatorImpl) verifyReadSet(readSet map[string]comparable) error {
}
if existing.version() != value.version() {
return errors.Errorf("readset expected key %s at version %d, but got version %d", key, value.version(), existing.version())
return errors.Errorf("proposed update requires that key %s be at version %d, but it is currently at version %d", key, value.version(), existing.version())
}
}
return nil
......
......@@ -7,11 +7,15 @@ SPDX-License-Identifier: Apache-2.0
package msgprocessor
import (
"fmt"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/common/policies"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
"github.com/pkg/errors"
)
// StandardChannelSupport includes the resources needed for the StandardChannel processor.
......@@ -98,7 +102,7 @@ func (s *StandardChannel) ProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.E
configEnvelope, err := s.support.ProposeConfigUpdate(env)
if err != nil {
return nil, 0, err
return nil, 0, errors.WithMessage(err, fmt.Sprintf("error applying config update to existing channel '%s'", s.support.ChainID()))
}
config, err = utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, s.support.ChainID(), s.support.Signer(), configEnvelope, msgVersion, epoch)
......
......@@ -69,6 +69,16 @@ func TestProcessNormalMsg(t *testing.T) {
}
func TestConfigUpdateMsg(t *testing.T) {
t.Run("BadUpdate", func(t *testing.T) {
ms := &mockSystemChannelFilterSupport{
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
ProposeConfigUpdateErr: fmt.Errorf("An error"),
}
config, cs, err := NewStandardChannel(ms, NewRuleSet(nil)).ProcessConfigUpdateMsg(&cb.Envelope{})
assert.Nil(t, config)
assert.Equal(t, uint64(0), cs)
assert.EqualError(t, err, "error applying config update to existing channel 'foo': An error")
})
t.Run("BadMsg", func(t *testing.T) {
ms := &mockSystemChannelFilterSupport{
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
......
......@@ -16,6 +16,8 @@ import (
"github.com/hyperledger/fabric/common/policies"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
"github.com/pkg/errors"
)
// ChannelConfigTemplator can be used to generate config templates.
......@@ -101,7 +103,7 @@ func (s *SystemChannel) ProcessConfigUpdateMsg(envConfigUpdate *cb.Envelope) (co
newChannelConfigEnv, err := bundle.ConfigtxValidator().ProposeConfigUpdate(envConfigUpdate)
if err != nil {
return nil, 0, err
return nil, 0, errors.WithMessage(err, fmt.Sprintf("error validating channel creation transaction for new channel '%s', could not succesfully apply update to template configuration", channelID))
}
newChannelEnvConfig, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, channelID, s.support.Signer(), newChannelConfigEnv, msgVersion, epoch)
......
......@@ -140,7 +140,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
},
}),
})
assert.Equal(t, mscs.NewChannelConfigVal.ProposeConfigUpdateError, err)
assert.EqualError(t, err, "error validating channel creation transaction for new channel 'foodifferent', could not succesfully apply update to template configuration: An error")
})
t.Run("BadSignEnvelope", func(t *testing.T) {
mscs := &mockSystemChannelSupport{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment