Skip to content

Commit d6b475a

Browse files
author
Jason Yellick
committedAug 4, 2017
[FAB-5552] Fix some TODOs in msgprocessor
The restructuring of the msgprocessor code has left some outstanding TODOs. In particular, for conditions where a CONFIG_UPDATE is rewrapped into a containing message, like a CONFIG or an ORDERER_TRANSACTION, this wrapping message could end up violating rules for the channel, like the maximum message size. This could see the message silently dropped by the consenter (silent from a client perspective). This CR adds a second pass of filtering in the message flow which generates a wrapping message. Also fixes a small comment bug from a previous CR. Change-Id: Ic482a8195720992c68e9986a1ff7f34004d5986c Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent cc5ca30 commit d6b475a

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed
 

‎orderer/common/broadcast/broadcast.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Handler interface {
2323
Handle(srv ab.AtomicBroadcast_BroadcastServer) error
2424
}
2525

26-
// ChannelSupportRegistrar provides a way for the Handler to look up the Support for a chain
26+
// ChannelSupportRegistrar provides a way for the Handler to look up the Support for a channel
2727
type ChannelSupportRegistrar interface {
2828
// BroadcastChannelSupport returns the message channel header, whether the message is a config update
2929
// and the channel resources for a message or an error if the message is not a message which can

‎orderer/common/msgprocessor/standardchannel.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,15 @@ func (s *StandardChannel) ProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.E
107107
return nil, 0, err
108108
}
109109

110-
// XXX We should probably run at least the size filter against this new tx one more time
110+
// We re-apply the filters here, especially for the size filter, to ensure that the transaction we
111+
// just constructed is not too large for our consenter. It additionally reapplies the signature
112+
// check, which although not strictly necessary, is a good sanity check, in case the orderer
113+
// has not been configured with the right cert material. The additional overhead of the signature
114+
// check is negligable, as this is the reconfig path and not the normal path.
115+
err = s.filters.Apply(config)
116+
if err != nil {
117+
return nil, 0, err
118+
}
111119

112120
return config, seq, nil
113121
}

‎orderer/common/msgprocessor/systemchannel.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ func (s *SystemChannel) ProcessConfigUpdateMsg(envConfigUpdate *cb.Envelope) (co
115115
return nil, 0, err
116116
}
117117

118-
// XXX we should verify that this still passes the size filter
118+
// We re-apply the filters here, especially for the size filter, to ensure that the transaction we
119+
// just constructed is not too large for our consenter. It additionally reapplies the signature
120+
// check, which although not strictly necessary, is a good sanity check, in case the orderer
121+
// has not been configured with the right cert material. The additional overhead of the signature
122+
// check is negligable, as this is the channel creation path and not the normal path.
123+
err = s.StandardChannel.filters.Apply(wrappedOrdererTransaction)
124+
if err != nil {
125+
return nil, 0, err
126+
}
119127

120128
return wrappedOrdererTransaction, s.support.Sequence(), nil
121129
}

‎orderer/common/msgprocessor/systemchannel_test.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
7878
t.Run("Missing header", func(t *testing.T) {
7979
mscs := &mockSystemChannelSupport{}
8080
ms := &mockSystemChannelFilterSupport{}
81-
_, _, err := NewSystemChannel(ms, mscs, nil).ProcessConfigUpdateMsg(&cb.Envelope{})
81+
_, _, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule})).ProcessConfigUpdateMsg(&cb.Envelope{})
8282
assert.NotNil(t, err)
8383
assert.Regexp(t, "no header was set", err.Error())
8484
})
@@ -108,7 +108,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
108108
ms := &mockSystemChannelFilterSupport{
109109
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
110110
}
111-
_, _, err := NewSystemChannel(ms, mscs, nil).ProcessConfigUpdateMsg(&cb.Envelope{
111+
_, _, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule})).ProcessConfigUpdateMsg(&cb.Envelope{
112112
Payload: utils.MarshalOrPanic(&cb.Payload{
113113
Header: &cb.Header{
114114
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
@@ -128,7 +128,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
128128
ms := &mockSystemChannelFilterSupport{
129129
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
130130
}
131-
_, _, err := NewSystemChannel(ms, mscs, nil).ProcessConfigUpdateMsg(&cb.Envelope{
131+
_, _, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule})).ProcessConfigUpdateMsg(&cb.Envelope{
132132
Payload: utils.MarshalOrPanic(&cb.Payload{
133133
Header: &cb.Header{
134134
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
@@ -146,7 +146,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
146146
ms := &mockSystemChannelFilterSupport{
147147
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
148148
}
149-
_, _, err := NewSystemChannel(ms, mscs, nil).ProcessConfigUpdateMsg(&cb.Envelope{
149+
_, _, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule})).ProcessConfigUpdateMsg(&cb.Envelope{
150150
Payload: utils.MarshalOrPanic(&cb.Payload{
151151
Header: &cb.Header{
152152
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
@@ -157,6 +157,27 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
157157
})
158158
assert.Regexp(t, "Marshal called with nil", err)
159159
})
160+
t.Run("BadByFilter", func(t *testing.T) {
161+
mscs := &mockSystemChannelSupport{
162+
NewChannelConfigVal: &mockconfigtx.Manager{
163+
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
164+
},
165+
}
166+
ms := &mockSystemChannelFilterSupport{
167+
SequenceVal: 7,
168+
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
169+
}
170+
_, _, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{RejectRule})).ProcessConfigUpdateMsg(&cb.Envelope{
171+
Payload: utils.MarshalOrPanic(&cb.Payload{
172+
Header: &cb.Header{
173+
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{
174+
ChannelId: testChannelID + "different",
175+
}),
176+
},
177+
}),
178+
})
179+
assert.Equal(t, RejectRule.Apply(nil), err)
180+
})
160181
t.Run("Good", func(t *testing.T) {
161182
mscs := &mockSystemChannelSupport{
162183
NewChannelConfigVal: &mockconfigtx.Manager{
@@ -167,7 +188,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) {
167188
SequenceVal: 7,
168189
ProposeConfigUpdateVal: &cb.ConfigEnvelope{},
169190
}
170-
config, cs, err := NewSystemChannel(ms, mscs, nil).ProcessConfigUpdateMsg(&cb.Envelope{
191+
config, cs, err := NewSystemChannel(ms, mscs, NewRuleSet([]Rule{AcceptRule})).ProcessConfigUpdateMsg(&cb.Envelope{
171192
Payload: utils.MarshalOrPanic(&cb.Payload{
172193
Header: &cb.Header{
173194
ChannelHeader: utils.MarshalOrPanic(&cb.ChannelHeader{

0 commit comments

Comments
 (0)
Please sign in to comment.