@@ -30,11 +30,11 @@ var logger = logging.MustGetLogger("orderer/common/blockcutter")
30
30
type Receiver interface {
31
31
// Ordered should be invoked sequentially as messages are ordered
32
32
// If the current message valid, and no batches need to be cut:
33
- // - Ordered will return nil, nil, and true (indicating ok ).
33
+ // - Ordered will return nil, nil, and true (indicating valid Tx ).
34
34
// If the current message valid, and batches need to be cut:
35
- // - Ordered will return 1 or 2 batches of messages, 1 or 2 batches of committers, and true (indicating ok ).
35
+ // - Ordered will return 1 or 2 batches of messages, 1 or 2 batches of committers, and true (indicating valid Tx ).
36
36
// If the current message is invalid:
37
- // - Ordered will return nil, nil, and false (to indicate not ok ).
37
+ // - Ordered will return nil, nil, and false (to indicate invalid Tx ).
38
38
//
39
39
// Given a valid message, if the current message needs to be isolated (as determined during filtering).
40
40
// - Ordered will return:
@@ -45,7 +45,9 @@ type Receiver interface {
45
45
// - The current message needs to be isolated (as determined during filtering).
46
46
// - The current message will cause the pending batch size in bytes to exceed BatchSize.PreferredMaxBytes.
47
47
// - After adding the current message to the pending batch, the message count has reached BatchSize.MaxMessageCount.
48
- Ordered (msg * cb.Envelope ) ([][]* cb.Envelope , [][]filter.Committer , bool )
48
+ //
49
+ // In any case, `pending` is set to true if there are still messages pending in the receiver after cutting the block.
50
+ Ordered (msg * cb.Envelope ) (messageBatches [][]* cb.Envelope , committers [][]filter.Committer , validTx bool , pending bool )
49
51
50
52
// Cut returns the current batch and starts a new one
51
53
Cut () ([]* cb.Envelope , []filter.Committer )
@@ -69,29 +71,34 @@ func NewReceiverImpl(sharedConfigManager config.Orderer, filters *filter.RuleSet
69
71
70
72
// Ordered should be invoked sequentially as messages are ordered
71
73
// If the current message valid, and no batches need to be cut:
72
- // - Ordered will return nil, nil, and true (indicating ok ).
74
+ // - Ordered will return nil, nil, true (indicating valid tx) and true (indicating there are pending messages ).
73
75
// If the current message valid, and batches need to be cut:
74
- // - Ordered will return 1 or 2 batches of messages, 1 or 2 batches of committers, and true (indicating ok ).
76
+ // - Ordered will return 1 or 2 batches of messages, 1 or 2 batches of committers, and true (indicating valid tx ).
75
77
// If the current message is invalid:
76
- // - Ordered will return nil, nil, and false (to indicate not ok ).
78
+ // - Ordered will return nil, nil, and false (to indicate invalid tx ).
77
79
//
78
80
// Given a valid message, if the current message needs to be isolated (as determined during filtering).
79
81
// - Ordered will return:
80
82
// * The pending batch of (if not empty), and a second batch containing only the isolated message.
81
83
// * The corresponding batches of committers.
82
- // * true (indicating ok ).
84
+ // * true (indicating valid tx ).
83
85
// Otherwise, given a valid message, the pending batch, if not empty, will be cut and returned if:
84
86
// - The current message needs to be isolated (as determined during filtering).
85
87
// - The current message will cause the pending batch size in bytes to exceed BatchSize.PreferredMaxBytes.
86
88
// - After adding the current message to the pending batch, the message count has reached BatchSize.MaxMessageCount.
87
- func (r * receiver ) Ordered (msg * cb.Envelope ) ([][]* cb.Envelope , [][]filter.Committer , bool ) {
89
+ //
90
+ // In any case, `pending` is set to true if there are still messages pending in the receiver after cutting the block.
91
+ func (r * receiver ) Ordered (msg * cb.Envelope ) (messageBatches [][]* cb.Envelope , committerBatches [][]filter.Committer , validTx bool , pending bool ) {
88
92
// The messages must be filtered a second time in case configuration has changed since the message was received
89
93
committer , err := r .filters .Apply (msg )
90
94
if err != nil {
91
95
logger .Debugf ("Rejecting message: %s" , err )
92
- return nil , nil , false
96
+ return // We don't bother to determine `pending` here as it's not processed in error case
93
97
}
94
98
99
+ // message is valid
100
+ validTx = true
101
+
95
102
messageSizeBytes := messageSizeBytes (msg )
96
103
97
104
if committer .Isolated () || messageSizeBytes > r .sharedConfigManager .BatchSize ().PreferredMaxBytes {
@@ -102,9 +109,6 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
102
109
logger .Debugf ("The current message, with %v bytes, is larger than the preferred batch size of %v bytes and will be isolated." , messageSizeBytes , r .sharedConfigManager .BatchSize ().PreferredMaxBytes )
103
110
}
104
111
105
- messageBatches := [][]* cb.Envelope {}
106
- committerBatches := [][]filter.Committer {}
107
-
108
112
// cut pending batch, if it has any messages
109
113
if len (r .pendingBatch ) > 0 {
110
114
messageBatch , committerBatch := r .Cut ()
@@ -116,12 +120,9 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
116
120
messageBatches = append (messageBatches , []* cb.Envelope {msg })
117
121
committerBatches = append (committerBatches , []filter.Committer {committer })
118
122
119
- return messageBatches , committerBatches , true
123
+ return
120
124
}
121
125
122
- messageBatches := [][]* cb.Envelope {}
123
- committerBatches := [][]filter.Committer {}
124
-
125
126
messageWillOverflowBatchSizeBytes := r .pendingBatchSizeBytes + messageSizeBytes > r .sharedConfigManager .BatchSize ().PreferredMaxBytes
126
127
127
128
if messageWillOverflowBatchSizeBytes {
@@ -136,21 +137,17 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
136
137
r .pendingBatch = append (r .pendingBatch , msg )
137
138
r .pendingBatchSizeBytes += messageSizeBytes
138
139
r .pendingCommitters = append (r .pendingCommitters , committer )
140
+ pending = true
139
141
140
142
if uint32 (len (r .pendingBatch )) >= r .sharedConfigManager .BatchSize ().MaxMessageCount {
141
143
logger .Debugf ("Batch size met, cutting batch" )
142
144
messageBatch , committerBatch := r .Cut ()
143
145
messageBatches = append (messageBatches , messageBatch )
144
146
committerBatches = append (committerBatches , committerBatch )
147
+ pending = false
145
148
}
146
149
147
- // return nils instead of empty slices
148
- if len (messageBatches ) == 0 {
149
- return nil , nil , true
150
- }
151
-
152
- return messageBatches , committerBatches , true
153
-
150
+ return
154
151
}
155
152
156
153
// Cut returns the current batch and starts a new one
0 commit comments