Skip to content

Commit 36b08c7

Browse files
author
Jason Yellick
committed
[FAB-5340] Respect new max message size on reconf
Currently, the size filter only reads the max message size at construction time. This means that if this size is reconfigured, the filter will not work correctly until restart. This CR changes the sizefilter to re-read the size value each time. Change-Id: Ib61c74dd8031fc61e107dc10ab9eba9d8b6b866e Signed-off-by: Jason Yellick <[email protected]>
1 parent 1f279a0 commit 36b08c7

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

orderer/common/sizefilter/sizefilter.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,36 @@ package sizefilter
1818

1919
import (
2020
"github.com/hyperledger/fabric/orderer/common/filter"
21-
ab "github.com/hyperledger/fabric/protos/common"
21+
cb "github.com/hyperledger/fabric/protos/common"
22+
ab "github.com/hyperledger/fabric/protos/orderer"
2223
logging "github.com/op/go-logging"
2324
)
2425

2526
var logger = logging.MustGetLogger("orderer/common/sizefilter")
2627

28+
// Support defines the subset of the channel support required to create this filter
29+
type Support interface {
30+
BatchSize() *ab.BatchSize
31+
}
32+
2733
// MaxBytesRule rejects messages larger than maxBytes
28-
func MaxBytesRule(maxBytes uint32) filter.Rule {
29-
return &maxBytesRule{maxBytes: maxBytes}
34+
func MaxBytesRule(support Support) filter.Rule {
35+
return &maxBytesRule{support: support}
3036
}
3137

3238
type maxBytesRule struct {
33-
maxBytes uint32
39+
support Support
3440
}
3541

36-
func (r *maxBytesRule) Apply(message *ab.Envelope) (filter.Action, filter.Committer) {
37-
if size := messageByteSize(message); size > r.maxBytes {
38-
logger.Warningf("%d byte message payload exceeds maximum allowed %d bytes", size, r.maxBytes)
42+
func (r *maxBytesRule) Apply(message *cb.Envelope) (filter.Action, filter.Committer) {
43+
maxBytes := r.support.BatchSize().AbsoluteMaxBytes
44+
if size := messageByteSize(message); size > maxBytes {
45+
logger.Warningf("%d byte message payload exceeds maximum allowed %d bytes", size, maxBytes)
3946
return filter.Reject, nil
4047
}
4148
return filter.Forward, nil
4249
}
4350

44-
func messageByteSize(message *ab.Envelope) uint32 {
51+
func messageByteSize(message *cb.Envelope) uint32 {
4552
return uint32(len(message.Payload) + len(message.Signature))
4653
}

orderer/common/sizefilter/sizefilter_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ import (
2020
"testing"
2121

2222
"github.com/golang/protobuf/proto"
23+
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
2324
"github.com/hyperledger/fabric/orderer/common/filter"
2425
cb "github.com/hyperledger/fabric/protos/common"
26+
ab "github.com/hyperledger/fabric/protos/orderer"
2527
)
2628

2729
func TestMaxBytesRule(t *testing.T) {
2830
dataSize := uint32(100)
2931
maxBytes := calcMessageBytesForPayloadDataSize(dataSize)
30-
rs := filter.NewRuleSet([]filter.Rule{MaxBytesRule(maxBytes), filter.AcceptRule})
32+
rs := filter.NewRuleSet([]filter.Rule{MaxBytesRule(&mockconfig.Orderer{BatchSizeVal: &ab.BatchSize{AbsoluteMaxBytes: maxBytes}}), filter.AcceptRule})
3133

3234
t.Run("LessThan", func(t *testing.T) {
3335
_, err := rs.Apply(makeMessage(make([]byte, dataSize-1)))

orderer/multichain/chainsupport.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func newChainSupport(
168168
func createStandardFilters(ledgerResources *ledgerResources) *filter.RuleSet {
169169
return filter.NewRuleSet([]filter.Rule{
170170
filter.EmptyRejectRule,
171-
sizefilter.MaxBytesRule(ledgerResources.SharedConfig().BatchSize().AbsoluteMaxBytes),
171+
sizefilter.MaxBytesRule(ledgerResources.SharedConfig()),
172172
sigfilter.New(policies.ChannelWriters, ledgerResources.PolicyManager()),
173173
configtxfilter.NewFilter(ledgerResources),
174174
filter.AcceptRule,
@@ -180,7 +180,7 @@ func createStandardFilters(ledgerResources *ledgerResources) *filter.RuleSet {
180180
func createSystemChainFilters(ml *multiLedger, ledgerResources *ledgerResources) *filter.RuleSet {
181181
return filter.NewRuleSet([]filter.Rule{
182182
filter.EmptyRejectRule,
183-
sizefilter.MaxBytesRule(ledgerResources.SharedConfig().BatchSize().AbsoluteMaxBytes),
183+
sizefilter.MaxBytesRule(ledgerResources.SharedConfig()),
184184
sigfilter.New(policies.ChannelWriters, ledgerResources.PolicyManager()),
185185
newSystemChainFilter(ledgerResources, ml),
186186
configtxfilter.NewFilter(ledgerResources),

0 commit comments

Comments
 (0)