Skip to content

Commit e2ab69c

Browse files
committed
[FAB-5284] Remove error return value of ClassifyMsg
This method used to take envelope, which may cause unmarshal error. It now takes only channel header, so we could safely remove the `error` return value, as it's always nil. Change-Id: Id6bebb8dda5eca190a14d8cbfe7b3d92cccdde1d Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
1 parent a657db2 commit e2ab69c

File tree

8 files changed

+16
-38
lines changed

8 files changed

+16
-38
lines changed

orderer/common/broadcast/broadcast_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (ms *mockSupport) Configure(configUpdate *cb.Envelope, config *cb.Envelope,
124124
return ms.Order(config, configSeq)
125125
}
126126

127-
func (ms *mockSupport) ClassifyMsg(chdr *cb.ChannelHeader) (msgprocessor.Classification, error) {
127+
func (ms *mockSupport) ClassifyMsg(chdr *cb.ChannelHeader) msgprocessor.Classification {
128128
panic("UNIMPLMENTED")
129129
}
130130

orderer/common/msgprocessor/msgprocessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const (
4848
// arrives through the Broadcast interface.
4949
type Processor interface {
5050
// ClassifyMsg inspects the message header to determine which type of processing is necessary
51-
ClassifyMsg(chdr *cb.ChannelHeader) (Classification, error)
51+
ClassifyMsg(chdr *cb.ChannelHeader) Classification
5252

5353
// ProcessNormalMsg will check the validity of a message based on the current configuration. It returns the current
5454
// configuration sequence number and nil on success, or an error if the message is not valid

orderer/common/msgprocessor/standardchannel.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,16 @@ func CreateStandardChannelFilters(filterSupport channelconfig.Resources) *RuleSe
5858
}
5959

6060
// ClassifyMsg inspects the message to determine which type of processing is necessary
61-
func (s *StandardChannel) ClassifyMsg(chdr *cb.ChannelHeader) (Classification, error) {
61+
func (s *StandardChannel) ClassifyMsg(chdr *cb.ChannelHeader) Classification {
6262
switch chdr.Type {
6363
case int32(cb.HeaderType_CONFIG_UPDATE):
64-
return ConfigUpdateMsg, nil
64+
return ConfigUpdateMsg
6565
case int32(cb.HeaderType_ORDERER_TRANSACTION):
66-
// XXX eventually, this should return an error, but for now to allow the old message flow, return ConfigUpdateMsg
67-
return ConfigUpdateMsg, nil
68-
// return 0, fmt.Errorf("Transactions of type ORDERER_TRANSACTION cannot be Broadcast")
66+
return ConfigUpdateMsg
6967
case int32(cb.HeaderType_CONFIG):
70-
// XXX eventually, this should return an error, but for now to allow the old message flow, return ConfigUpdateMsg
71-
return ConfigUpdateMsg, nil
72-
// return 0, fmt.Errorf("Transactions of type CONFIG cannot be Broadcast")
68+
return ConfigUpdateMsg
7369
default:
74-
return NormalMsg, nil
70+
return NormalMsg
7571
}
7672
}
7773

orderer/common/msgprocessor/standardchannel_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,20 @@ func (ms *mockSystemChannelFilterSupport) ChainID() string {
4242

4343
func TestClassifyMsg(t *testing.T) {
4444
t.Run("ConfigUpdate", func(t *testing.T) {
45-
class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG_UPDATE)})
45+
class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG_UPDATE)})
4646
assert.Equal(t, class, ConfigUpdateMsg)
47-
assert.Nil(t, err)
4847
})
4948
t.Run("OrdererTx", func(t *testing.T) {
50-
class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ORDERER_TRANSACTION)})
49+
class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ORDERER_TRANSACTION)})
5150
assert.Equal(t, class, ConfigUpdateMsg)
52-
assert.Nil(t, err)
5351
})
5452
t.Run("ConfigTx", func(t *testing.T) {
55-
class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG)})
53+
class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_CONFIG)})
5654
assert.Equal(t, class, ConfigUpdateMsg)
57-
assert.Nil(t, err)
5855
})
5956
t.Run("EndorserTx", func(t *testing.T) {
60-
class, err := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ENDORSER_TRANSACTION)})
57+
class := (&StandardChannel{}).ClassifyMsg(&cb.ChannelHeader{Type: int32(cb.HeaderType_ENDORSER_TRANSACTION)})
6158
assert.Equal(t, class, NormalMsg)
62-
assert.Nil(t, err)
6359
})
6460
}
6561

orderer/common/multichannel/registrar.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,8 @@ func (r *Registrar) BroadcastChannelSupport(msg *cb.Envelope) (*cb.ChannelHeader
179179
cs = r.systemChannel
180180
}
181181

182-
class, err := cs.ClassifyMsg(chdr)
183-
if err != nil {
184-
return nil, false, nil, fmt.Errorf("could not classify message: %s", err)
185-
}
186-
187182
isConfig := false
188-
switch class {
183+
switch cs.ClassifyMsg(chdr) {
189184
case msgprocessor.ConfigUpdateMsg:
190185
isConfig = true
191186
default:

orderer/common/multichannel/util_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ func (mch *mockChain) Start() {
6868
logger.Panicf("If a message has arrived to this point, it should already have had header inspected once: %s", err)
6969
}
7070

71-
class, err := mch.support.ClassifyMsg(chdr)
72-
if err != nil {
73-
logger.Panicf("If a message has arrived to this point, it should already have been classified once: %s", err)
74-
}
71+
class := mch.support.ClassifyMsg(chdr)
7572
switch class {
7673
case msgprocessor.ConfigUpdateMsg:
7774
batch := mch.support.BlockCutter().Cut()

orderer/consensus/kafka/chain.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,7 @@ func processRegular(regularMessage *ab.KafkaMessageRegular, support consensus.Co
398398
logger.Panicf("If a message has arrived to this point, it should already have had its header inspected once")
399399
}
400400

401-
class, err := support.ClassifyMsg(chdr)
402-
if err != nil {
403-
logger.Panicf("[channel: %s] If a message has arrived to this point, it should already have been classified once", support.ChainID())
404-
}
401+
class := support.ClassifyMsg(chdr)
405402
switch class {
406403
case msgprocessor.ConfigUpdateMsg:
407404
_, err := support.ProcessNormalMsg(env)

orderer/mocks/common/multichannel/multichannel.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ type ConsenterSupport struct {
4444
// ClassifyMsgVal is returned by ClassifyMsg
4545
ClassifyMsgVal msgprocessor.Classification
4646

47-
// ClassifyMsgErr is the err returned by ClassifyMsg
48-
ClassifyMsgErr error
49-
5047
// ConfigSeqVal is returned as the configSeq for Process*Msg
5148
ConfigSeqVal uint64
5249

@@ -120,8 +117,8 @@ func (mcs *ConsenterSupport) NewSignatureHeader() (*cb.SignatureHeader, error) {
120117
}
121118

122119
// ClassifyMsg returns ClassifyMsgVal, ClassifyMsgErr
123-
func (mcs *ConsenterSupport) ClassifyMsg(chdr *cb.ChannelHeader) (msgprocessor.Classification, error) {
124-
return mcs.ClassifyMsgVal, mcs.ClassifyMsgErr
120+
func (mcs *ConsenterSupport) ClassifyMsg(chdr *cb.ChannelHeader) msgprocessor.Classification {
121+
return mcs.ClassifyMsgVal
125122
}
126123

127124
// ProcessNormalMsg returns ConfigSeqVal, ProcessNormalMsgErr

0 commit comments

Comments
 (0)