diff --git a/orderer/common/broadcast/broadcast_test.go b/orderer/common/broadcast/broadcast_test.go index 9cb1ad3301c..67304bb93a8 100644 --- a/orderer/common/broadcast/broadcast_test.go +++ b/orderer/common/broadcast/broadcast_test.go @@ -124,7 +124,7 @@ func (ms *mockSupport) Configure(configUpdate *cb.Envelope, config *cb.Envelope, return ms.Order(config, configSeq) } -func (ms *mockSupport) ClassifyMsg(chdr *cb.ChannelHeader) (msgprocessor.Classification, error) { +func (ms *mockSupport) ClassifyMsg(chdr *cb.ChannelHeader) msgprocessor.Classification { panic("UNIMPLMENTED") } diff --git a/orderer/common/msgprocessor/msgprocessor.go b/orderer/common/msgprocessor/msgprocessor.go index 05c5b30d736..6bd0ecc6f49 100644 --- a/orderer/common/msgprocessor/msgprocessor.go +++ b/orderer/common/msgprocessor/msgprocessor.go @@ -48,7 +48,7 @@ const ( // arrives through the Broadcast interface. type Processor interface { // ClassifyMsg inspects the message header to determine which type of processing is necessary - ClassifyMsg(chdr *cb.ChannelHeader) (Classification, error) + ClassifyMsg(chdr *cb.ChannelHeader) Classification // ProcessNormalMsg will check the validity of a message based on the current configuration. It returns the current // configuration sequence number and nil on success, or an error if the message is not valid diff --git a/orderer/common/msgprocessor/standardchannel.go b/orderer/common/msgprocessor/standardchannel.go index 95859ca5d2b..0aea9835cf1 100644 --- a/orderer/common/msgprocessor/standardchannel.go +++ b/orderer/common/msgprocessor/standardchannel.go @@ -58,20 +58,16 @@ func CreateStandardChannelFilters(filterSupport channelconfig.Resources) *RuleSe } // ClassifyMsg inspects the message to determine which type of processing is necessary -func (s *StandardChannel) ClassifyMsg(chdr *cb.ChannelHeader) (Classification, error) { +func (s *StandardChannel) ClassifyMsg(chdr *cb.ChannelHeader) Classification { switch chdr.Type { case int32(cb.HeaderType_CONFIG_UPDATE): - return ConfigUpdateMsg, nil + return ConfigUpdateMsg case int32(cb.HeaderType_ORDERER_TRANSACTION): - // XXX eventually, this should return an error, but for now to allow the old message flow, return ConfigUpdateMsg - return ConfigUpdateMsg, nil - // return 0, fmt.Errorf("Transactions of type ORDERER_TRANSACTION cannot be Broadcast") + return ConfigUpdateMsg case int32(cb.HeaderType_CONFIG): - // XXX eventually, this should return an error, but for now to allow the old message flow, return ConfigUpdateMsg - return ConfigUpdateMsg, nil - // return 0, fmt.Errorf("Transactions of type CONFIG cannot be Broadcast") + return ConfigUpdateMsg default: - return NormalMsg, nil + return NormalMsg } } diff --git a/orderer/common/msgprocessor/standardchannel_test.go b/orderer/common/msgprocessor/standardchannel_test.go index b0381178275..e4d04db7213 100644 --- a/orderer/common/msgprocessor/standardchannel_test.go +++ b/orderer/common/msgprocessor/standardchannel_test.go @@ -42,24 +42,20 @@ func (ms *mockSystemChannelFilterSupport) ChainID() string { func TestClassifyMsg(t *testing.T) { t.Run("ConfigUpdate", func(t *testing.T) { - class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG_UPDATE)}) + class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG_UPDATE)}) assert.Equal(t, class, ConfigUpdateMsg) - assert.Nil(t, err) }) t.Run("OrdererTx", func(t *testing.T) { - class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ORDERER_TRANSACTION)}) + class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ORDERER_TRANSACTION)}) assert.Equal(t, class, ConfigUpdateMsg) - assert.Nil(t, err) }) t.Run("ConfigTx", func(t *testing.T) { - class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG)}) + class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG)}) assert.Equal(t, class, ConfigUpdateMsg) - assert.Nil(t, err) }) t.Run("EndorserTx", func(t *testing.T) { - class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ENDORSER_TRANSACTION)}) + class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ENDORSER_TRANSACTION)}) assert.Equal(t, class, NormalMsg) - assert.Nil(t, err) }) } diff --git a/orderer/common/multichannel/registrar.go b/orderer/common/multichannel/registrar.go index 4ab0cd34b70..f0e519b301c 100644 --- a/orderer/common/multichannel/registrar.go +++ b/orderer/common/multichannel/registrar.go @@ -179,13 +179,8 @@ func (r *Registrar) BroadcastChannelSupport(msg *cb.Envelope) (*cb.ChannelHeader cs = r.systemChannel } - class, err := cs.ClassifyMsg(chdr) - if err != nil { - return nil, false, nil, fmt.Errorf("could not classify message: %s", err) - } - isConfig := false - switch class { + switch cs.ClassifyMsg(chdr) { case msgprocessor.ConfigUpdateMsg: isConfig = true default: diff --git a/orderer/common/multichannel/util_test.go b/orderer/common/multichannel/util_test.go index 770b81d89bf..9a3dc435818 100644 --- a/orderer/common/multichannel/util_test.go +++ b/orderer/common/multichannel/util_test.go @@ -68,10 +68,7 @@ func (mch *mockChain) Start() { logger.Panicf("If a message has arrived to this point, it should already have had header inspected once: %s", err) } - class, err := mch.support.ClassifyMsg(chdr) - if err != nil { - logger.Panicf("If a message has arrived to this point, it should already have been classified once: %s", err) - } + class := mch.support.ClassifyMsg(chdr) switch class { case msgprocessor.ConfigUpdateMsg: batch := mch.support.BlockCutter().Cut() diff --git a/orderer/consensus/kafka/chain.go b/orderer/consensus/kafka/chain.go index 504838d50f6..2f74926fb4f 100644 --- a/orderer/consensus/kafka/chain.go +++ b/orderer/consensus/kafka/chain.go @@ -398,10 +398,7 @@ func processRegular(regularMessage *ab.KafkaMessageRegular, support consensus.Co logger.Panicf("If a message has arrived to this point, it should already have had its header inspected once") } - class, err := support.ClassifyMsg(chdr) - if err != nil { - logger.Panicf("[channel: %s] If a message has arrived to this point, it should already have been classified once", support.ChainID()) - } + class := support.ClassifyMsg(chdr) switch class { case msgprocessor.ConfigUpdateMsg: _, err := support.ProcessNormalMsg(env) diff --git a/orderer/mocks/common/multichannel/multichannel.go b/orderer/mocks/common/multichannel/multichannel.go index 33066a31741..c5c44b146d0 100644 --- a/orderer/mocks/common/multichannel/multichannel.go +++ b/orderer/mocks/common/multichannel/multichannel.go @@ -44,9 +44,6 @@ type ConsenterSupport struct { // ClassifyMsgVal is returned by ClassifyMsg ClassifyMsgVal msgprocessor.Classification - // ClassifyMsgErr is the err returned by ClassifyMsg - ClassifyMsgErr error - // ConfigSeqVal is returned as the configSeq for Process*Msg ConfigSeqVal uint64 @@ -120,8 +117,8 @@ func (mcs *ConsenterSupport) NewSignatureHeader() (*cb.SignatureHeader, error) { } // ClassifyMsg returns ClassifyMsgVal, ClassifyMsgErr -func (mcs *ConsenterSupport) ClassifyMsg(chdr *cb.ChannelHeader) (msgprocessor.Classification, error) { - return mcs.ClassifyMsgVal, mcs.ClassifyMsgErr +func (mcs *ConsenterSupport) ClassifyMsg(chdr *cb.ChannelHeader) msgprocessor.Classification { + return mcs.ClassifyMsgVal } // ProcessNormalMsg returns ConfigSeqVal, ProcessNormalMsgErr