Skip to content

Commit a8af1e9

Browse files
author
Jason Yellick
committed
Hook multichain manager into main path
The previous changeset created the multichain manager but left it entirely out of the execution path. This changeset hooks the multichain manager into the primary path and removes much of the redundant code it replaces. This changeset only supports solo as a consumer of the multichain manager, but kafka will follow next (as the multichain manager gives multichain support for free to implementers of its Consenter interface). Change-Id: I4e5b19971afe5b434843f3e0011fd18df098aa0f Signed-off-by: Jason Yellick <[email protected]>
1 parent 157479b commit a8af1e9

File tree

12 files changed

+401
-267
lines changed

12 files changed

+401
-267
lines changed

orderer/common/blockcutter/blockcutter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func init() {
3131
logging.SetLevel(logging.DEBUG, "")
3232
}
3333

34-
// Target defines a sink for the ordered broadcast messages
34+
// Receiver defines a sink for the ordered broadcast messages
3535
type Receiver interface {
3636
// Ordered should be invoked sequentially as messages are ordered
3737
// If the message is a valid normal message and does not fill the batch, nil, true is returned

orderer/common/broadcast/broadcast.go

+33-24
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package broadcast
1818

1919
import (
2020
"github.com/hyperledger/fabric/orderer/common/broadcastfilter"
21-
"github.com/hyperledger/fabric/orderer/common/configtx"
21+
"github.com/hyperledger/fabric/orderer/multichain"
2222
cb "github.com/hyperledger/fabric/protos/common"
2323
ab "github.com/hyperledger/fabric/protos/orderer"
2424

25+
"github.com/golang/protobuf/proto"
2526
"github.com/op/go-logging"
2627
)
2728

@@ -31,34 +32,24 @@ func init() {
3132
logging.SetLevel(logging.DEBUG, "")
3233
}
3334

34-
// Target defines an interface which the broadcast handler will direct broadcasts to
35-
type Target interface {
36-
// Enqueue accepts a message and returns true on acceptance, or false on shutdown
37-
Enqueue(env *cb.Envelope) bool
38-
}
39-
4035
// Handler defines an interface which handles broadcasts
4136
type Handler interface {
4237
// Handle starts a service thread for a given gRPC connection and services the broadcast connection
4338
Handle(srv ab.AtomicBroadcast_BroadcastServer) error
4439
}
4540

4641
type handlerImpl struct {
47-
queueSize int
48-
target Target
49-
filters *broadcastfilter.RuleSet
50-
configManager configtx.Manager
51-
exitChan chan struct{}
42+
queueSize int
43+
ml multichain.Manager
44+
exitChan chan struct{}
5245
}
5346

5447
// NewHandlerImpl constructs a new implementation of the Handler interface
55-
func NewHandlerImpl(queueSize int, target Target, filters *broadcastfilter.RuleSet, configManager configtx.Manager) Handler {
48+
func NewHandlerImpl(queueSize int, ml multichain.Manager) Handler {
5649
return &handlerImpl{
57-
queueSize: queueSize,
58-
filters: filters,
59-
configManager: configManager,
60-
target: target,
61-
exitChan: make(chan struct{}),
50+
queueSize: queueSize,
51+
ml: ml,
52+
exitChan: make(chan struct{}),
6253
}
6354
}
6455

@@ -70,25 +61,30 @@ func (bh *handlerImpl) Handle(srv ab.AtomicBroadcast_BroadcastServer) error {
7061
return b.queueEnvelopes(srv)
7162
}
7263

64+
type msgAndChainSupport struct {
65+
msg *cb.Envelope
66+
chainSupport multichain.ChainSupport
67+
}
68+
7369
type broadcaster struct {
7470
bs *handlerImpl
75-
queue chan *cb.Envelope
71+
queue chan *msgAndChainSupport
7672
}
7773

7874
func newBroadcaster(bs *handlerImpl) *broadcaster {
7975
b := &broadcaster{
8076
bs: bs,
81-
queue: make(chan *cb.Envelope, bs.queueSize),
77+
queue: make(chan *msgAndChainSupport, bs.queueSize),
8278
}
8379
return b
8480
}
8581

8682
func (b *broadcaster) drainQueue() {
8783
for {
8884
select {
89-
case msg, ok := <-b.queue:
85+
case msgAndChainSupport, ok := <-b.queue:
9086
if ok {
91-
if !b.bs.target.Enqueue(msg) {
87+
if !msgAndChainSupport.chainSupport.Chain().Enqueue(msgAndChainSupport.msg) {
9288
return
9389
}
9490
} else {
@@ -108,14 +104,27 @@ func (b *broadcaster) queueEnvelopes(srv ab.AtomicBroadcast_BroadcastServer) err
108104
return err
109105
}
110106

111-
action, _ := b.bs.filters.Apply(msg)
107+
payload := &cb.Payload{}
108+
err = proto.Unmarshal(msg.Payload, payload)
109+
if payload.Header == nil || payload.Header.ChainHeader == nil || payload.Header.ChainHeader.ChainID == nil {
110+
logger.Debugf("Received malformed message, dropping connection")
111+
return srv.Send(&ab.BroadcastResponse{Status: cb.Status_BAD_REQUEST})
112+
}
113+
114+
chainSupport, ok := b.bs.ml.GetChain(payload.Header.ChainHeader.ChainID)
115+
if !ok {
116+
// XXX Hook in chain creation logic here
117+
panic("Unimplemented")
118+
}
119+
120+
action, _ := chainSupport.Filters().Apply(msg)
112121

113122
switch action {
114123
case broadcastfilter.Reconfigure:
115124
fallthrough
116125
case broadcastfilter.Accept:
117126
select {
118-
case b.queue <- msg:
127+
case b.queue <- &msgAndChainSupport{msg: msg, chainSupport: chainSupport}:
119128
err = srv.Send(&ab.BroadcastResponse{Status: cb.Status_SUCCESS})
120129
default:
121130
err = srv.Send(&ab.BroadcastResponse{Status: cb.Status_SERVICE_UNAVAILABLE})

0 commit comments

Comments
 (0)