Skip to content

Commit

Permalink
[FAB-5340] Respect new max message size on reconf
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jul 17, 2017
1 parent 1f279a0 commit 36b08c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 15 additions & 8 deletions orderer/common/sizefilter/sizefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,36 @@ package sizefilter

import (
"github.com/hyperledger/fabric/orderer/common/filter"
ab "github.com/hyperledger/fabric/protos/common"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
logging "github.com/op/go-logging"
)

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

// Support defines the subset of the channel support required to create this filter
type Support interface {
BatchSize() *ab.BatchSize
}

// MaxBytesRule rejects messages larger than maxBytes
func MaxBytesRule(maxBytes uint32) filter.Rule {
return &maxBytesRule{maxBytes: maxBytes}
func MaxBytesRule(support Support) filter.Rule {
return &maxBytesRule{support: support}
}

type maxBytesRule struct {
maxBytes uint32
support Support
}

func (r *maxBytesRule) Apply(message *ab.Envelope) (filter.Action, filter.Committer) {
if size := messageByteSize(message); size > r.maxBytes {
logger.Warningf("%d byte message payload exceeds maximum allowed %d bytes", size, r.maxBytes)
func (r *maxBytesRule) Apply(message *cb.Envelope) (filter.Action, filter.Committer) {
maxBytes := r.support.BatchSize().AbsoluteMaxBytes
if size := messageByteSize(message); size > maxBytes {
logger.Warningf("%d byte message payload exceeds maximum allowed %d bytes", size, maxBytes)
return filter.Reject, nil
}
return filter.Forward, nil
}

func messageByteSize(message *ab.Envelope) uint32 {
func messageByteSize(message *cb.Envelope) uint32 {
return uint32(len(message.Payload) + len(message.Signature))
}
4 changes: 3 additions & 1 deletion orderer/common/sizefilter/sizefilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"testing"

"github.com/golang/protobuf/proto"
mockconfig "github.com/hyperledger/fabric/common/mocks/config"
"github.com/hyperledger/fabric/orderer/common/filter"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
)

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

t.Run("LessThan", func(t *testing.T) {
_, err := rs.Apply(makeMessage(make([]byte, dataSize-1)))
Expand Down
4 changes: 2 additions & 2 deletions orderer/multichain/chainsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func newChainSupport(
func createStandardFilters(ledgerResources *ledgerResources) *filter.RuleSet {
return filter.NewRuleSet([]filter.Rule{
filter.EmptyRejectRule,
sizefilter.MaxBytesRule(ledgerResources.SharedConfig().BatchSize().AbsoluteMaxBytes),
sizefilter.MaxBytesRule(ledgerResources.SharedConfig()),
sigfilter.New(policies.ChannelWriters, ledgerResources.PolicyManager()),
configtxfilter.NewFilter(ledgerResources),
filter.AcceptRule,
Expand All @@ -180,7 +180,7 @@ func createStandardFilters(ledgerResources *ledgerResources) *filter.RuleSet {
func createSystemChainFilters(ml *multiLedger, ledgerResources *ledgerResources) *filter.RuleSet {
return filter.NewRuleSet([]filter.Rule{
filter.EmptyRejectRule,
sizefilter.MaxBytesRule(ledgerResources.SharedConfig().BatchSize().AbsoluteMaxBytes),
sizefilter.MaxBytesRule(ledgerResources.SharedConfig()),
sigfilter.New(policies.ChannelWriters, ledgerResources.PolicyManager()),
newSystemChainFilter(ledgerResources, ml),
configtxfilter.NewFilter(ledgerResources),
Expand Down

0 comments on commit 36b08c7

Please sign in to comment.