@@ -17,11 +17,9 @@ limitations under the License.
17
17
package blockcutter
18
18
19
19
import (
20
- "github.com/hyperledger/fabric/orderer/common/broadcastfilter"
21
- "github.com/hyperledger/fabric/orderer/common/configtx"
20
+ "github.com/hyperledger/fabric/orderer/common/filter"
22
21
cb "github.com/hyperledger/fabric/protos/common"
23
22
24
- "github.com/golang/protobuf/proto"
25
23
"github.com/op/go-logging"
26
24
)
27
25
@@ -34,98 +32,79 @@ func init() {
34
32
// Receiver defines a sink for the ordered broadcast messages
35
33
type Receiver interface {
36
34
// Ordered should be invoked sequentially as messages are ordered
37
- // If the message is a valid normal message and does not fill the batch, nil, true is returned
38
- // If the message is a valid normal message and fills a batch, the batch, true is returned
35
+ // If the message is a valid normal message and does not fill the batch, nil, nil, true is returned
36
+ // If the message is a valid normal message and fills a batch, the batch, committers, true is returned
39
37
// If the message is a valid special message (like a config message) it terminates the current batch
40
- // and returns the current batch (if it is not empty), plus a second batch containing the special transaction and true
41
- // If the ordered message is determined to be invalid, then nil, false is returned
42
- Ordered (msg * cb.Envelope ) ([][]* cb.Envelope , bool )
38
+ // and returns the current batch and committers (if it is not empty), plus a second batch containing the special transaction and commiter, and true
39
+ // If the ordered message is determined to be invalid, then nil, nil, false is returned
40
+ Ordered (msg * cb.Envelope ) ([][]* cb.Envelope , [][]filter. Committer , bool )
43
41
44
42
// Cut returns the current batch and starts a new one
45
- Cut () []* cb.Envelope
43
+ Cut () ( []* cb.Envelope , []filter. Committer )
46
44
}
47
45
48
46
type receiver struct {
49
- batchSize int
50
- filters * broadcastfilter .RuleSet
51
- configManager configtx. Manager
52
- curBatch [] * cb. Envelope
47
+ batchSize int
48
+ filters * filter .RuleSet
49
+ curBatch [] * cb. Envelope
50
+ batchComs []filter. Committer
53
51
}
54
52
55
53
// NewReceiverImpl creates a Receiver implementation based on the given batchsize, filters, and configtx manager
56
- func NewReceiverImpl (batchSize int , filters * broadcastfilter .RuleSet , configManager configtx. Manager ) Receiver {
54
+ func NewReceiverImpl (batchSize int , filters * filter .RuleSet ) Receiver {
57
55
return & receiver {
58
- batchSize : batchSize ,
59
- filters : filters ,
60
- configManager : configManager ,
56
+ batchSize : batchSize ,
57
+ filters : filters ,
61
58
}
62
59
}
63
60
64
61
// Ordered should be invoked sequentially as messages are ordered
65
- // If the message is a valid normal message and does not fill the batch, nil, true is returned
66
- // If the message is a valid normal message and fills a batch, the batch, true is returned
62
+ // If the message is a valid normal message and does not fill the batch, nil, nil, true is returned
63
+ // If the message is a valid normal message and fills a batch, the batch, committers, true is returned
67
64
// If the message is a valid special message (like a config message) it terminates the current batch
68
- // and returns the current batch (if it is not empty), plus a second batch containing the special transaction and true
69
- // If the ordered message is determined to be invalid, then nil, false is returned
70
- func (r * receiver ) Ordered (msg * cb.Envelope ) ([][]* cb.Envelope , bool ) {
65
+ // and returns the current batch and committers (if it is not empty), plus a second batch containing the special transaction and commiter, and true
66
+ // If the ordered message is determined to be invalid, then nil, nil, false is returned
67
+ func (r * receiver ) Ordered (msg * cb.Envelope ) ([][]* cb.Envelope , [][]filter. Committer , bool ) {
71
68
// The messages must be filtered a second time in case configuration has changed since the message was received
72
- action , _ := r .filters .Apply (msg )
73
- switch action {
74
- case broadcastfilter .Accept :
75
- logger .Debugf ("Enqueuing message into batch" )
76
- r .curBatch = append (r .curBatch , msg )
77
-
78
- if len (r .curBatch ) < r .batchSize {
79
- return nil , true
80
- }
81
-
82
- logger .Debugf ("Batch size met, creating block" )
83
- newBatch := r .curBatch
84
- r .curBatch = nil
85
- return [][]* cb.Envelope {newBatch }, true
86
- case broadcastfilter .Reconfigure :
87
- // TODO, this is unmarshaling for a second time, we need a cleaner interface, maybe Apply returns a second arg with thing to put in the batch
88
- payload := & cb.Payload {}
89
- if err := proto .Unmarshal (msg .Payload , payload ); err != nil {
90
- logger .Errorf ("A change was flagged as configuration, but could not be unmarshaled: %v" , err )
91
- return nil , false
92
- }
93
- newConfig := & cb.ConfigurationEnvelope {}
94
- if err := proto .Unmarshal (payload .Data , newConfig ); err != nil {
95
- logger .Errorf ("A change was flagged as configuration, but could not be unmarshaled: %v" , err )
96
- return nil , false
97
- }
98
- err := r .configManager .Validate (newConfig )
99
- if err != nil {
100
- logger .Warningf ("A configuration change made it through the ingress filter but could not be included in a batch: %v" , err )
101
- return nil , false
102
- }
69
+ committer , err := r .filters .Apply (msg )
70
+ if err != nil {
71
+ logger .Debugf ("Rejecting message: %s" , err )
72
+ return nil , nil , false
73
+ }
103
74
104
- logger .Debugf ("Configuration change applied successfully, committing previous block and configuration block" )
75
+ if committer .Isolated () {
76
+ logger .Debugf ("Found message which requested to be isolated, cutting into its own block" )
105
77
firstBatch := r .curBatch
106
78
r .curBatch = nil
79
+ firstComs := r .batchComs
80
+ r .batchComs = nil
107
81
secondBatch := []* cb.Envelope {msg }
108
82
if firstBatch == nil {
109
- return [][]* cb.Envelope {secondBatch }, true
83
+ return [][]* cb.Envelope {secondBatch }, [][]filter. Committer {[]filter. Committer { committer }}, true
110
84
}
111
- return [][]* cb.Envelope {firstBatch , secondBatch }, true
112
- case broadcastfilter .Reject :
113
- logger .Debugf ("Rejecting message" )
114
- return nil , false
115
- case broadcastfilter .Forward :
116
- logger .Debugf ("Ignoring message because it was not accepted by a filter" )
117
- return nil , false
118
- default :
119
- logger .Fatalf ("Received an unknown rule response: %v" , action )
85
+ return [][]* cb.Envelope {firstBatch , secondBatch }, [][]filter.Committer {firstComs , []filter.Committer {committer }}, true
120
86
}
121
87
122
- return nil , false // Unreachable
88
+ logger .Debugf ("Enqueuing message into batch" )
89
+ r .curBatch = append (r .curBatch , msg )
90
+ r .batchComs = append (r .batchComs , committer )
123
91
92
+ if len (r .curBatch ) < r .batchSize {
93
+ return nil , nil , true
94
+ }
95
+
96
+ logger .Debugf ("Batch size met, creating block" )
97
+ newBatch := r .curBatch
98
+ newComs := r .batchComs
99
+ r .curBatch = nil
100
+ return [][]* cb.Envelope {newBatch }, [][]filter.Committer {newComs }, true
124
101
}
125
102
126
103
// Cut returns the current batch and starts a new one
127
- func (r * receiver ) Cut () []* cb.Envelope {
104
+ func (r * receiver ) Cut () ( []* cb.Envelope , []filter. Committer ) {
128
105
batch := r .curBatch
129
106
r .curBatch = nil
130
- return batch
107
+ committers := r .batchComs
108
+ r .batchComs = nil
109
+ return batch , committers
131
110
}
0 commit comments