@@ -17,13 +17,13 @@ limitations under the License.
17
17
package noopssinglechain
18
18
19
19
import (
20
+ "fmt"
20
21
"time"
21
22
22
23
"github.com/golang/protobuf/proto"
23
24
"github.com/hyperledger/fabric/core/chaincode"
24
25
"github.com/hyperledger/fabric/core/committer"
25
26
"github.com/hyperledger/fabric/core/ledger/kvledger"
26
- "github.com/hyperledger/fabric/core/util"
27
27
"github.com/hyperledger/fabric/events/producer"
28
28
"github.com/hyperledger/fabric/protos/common"
29
29
"github.com/hyperledger/fabric/protos/orderer"
@@ -33,14 +33,10 @@ import (
33
33
"golang.org/x/net/context"
34
34
"google.golang.org/grpc"
35
35
36
- "fmt"
37
-
38
36
"github.com/hyperledger/fabric/core/ledger"
39
37
"github.com/hyperledger/fabric/core/peer"
40
- "github.com/hyperledger/fabric/gossip/gossip"
41
- "github.com/hyperledger/fabric/gossip/integration"
42
38
gossip_proto "github.com/hyperledger/fabric/gossip/proto"
43
- "github.com/hyperledger/fabric/gossip/state "
39
+ "github.com/hyperledger/fabric/gossip/service "
44
40
pb "github.com/hyperledger/fabric/protos/peer"
45
41
)
46
42
@@ -57,11 +53,9 @@ type DeliverService struct {
57
53
client orderer.AtomicBroadcast_DeliverClient
58
54
windowSize uint64
59
55
unAcknowledged uint64
60
- committer * committer.LedgerCommitter
61
56
62
- stateProvider state.GossipStateProvider
63
- gossip gossip.Gossip
64
- conn * grpc.ClientConn
57
+ chainID string
58
+ conn * grpc.ClientConn
65
59
}
66
60
67
61
// StopDeliveryService sends stop to the delivery service reference
@@ -73,25 +67,22 @@ func StopDeliveryService(service *DeliverService) {
73
67
74
68
// NewDeliverService construction function to create and initilize
75
69
// delivery service instance
76
- func NewDeliverService (chainID string , address string , grpcServer * grpc. Server ) * DeliverService {
70
+ func NewDeliverService (chainID string ) * DeliverService {
77
71
if viper .GetBool ("peer.committer.enabled" ) {
78
72
logger .Infof ("Creating committer for single noops endorser" )
79
-
80
73
deliverService := & DeliverService {
81
74
// Instance of RawLedger
82
- committer : committer . NewLedgerCommitter ( kvledger . GetLedger ( chainID )) ,
75
+ chainID : chainID ,
83
76
windowSize : 10 ,
84
77
}
85
78
86
- deliverService .initStateProvider (address , grpcServer )
87
-
88
79
return deliverService
89
80
}
90
81
logger .Infof ("Committer disabled" )
91
82
return nil
92
83
}
93
84
94
- func (d * DeliverService ) startDeliver () error {
85
+ func (d * DeliverService ) startDeliver (committer committer. Committer ) error {
95
86
logger .Info ("Starting deliver service client" )
96
87
err := d .initDeliver ()
97
88
@@ -100,7 +91,7 @@ func (d *DeliverService) startDeliver() error {
100
91
return err
101
92
}
102
93
103
- height , err := d . committer .LedgerHeight ()
94
+ height , err := committer .LedgerHeight ()
104
95
if err != nil {
105
96
logger .Errorf ("Can't get legder height from committer [%s]" , err )
106
97
return err
@@ -153,36 +144,24 @@ func (d *DeliverService) stopDeliver() {
153
144
}
154
145
}
155
146
156
- func (d * DeliverService ) initStateProvider (address string , grpcServer * grpc.Server ) error {
157
- bootstrap := viper .GetStringSlice ("peer.gossip.bootstrap" )
158
- logger .Debug ("Initializing state provideer, endpoint = " , address , " bootstrap set = " , bootstrap )
159
-
160
- gossip , gossipComm := integration .NewGossipComponent (address , grpcServer , bootstrap ... )
161
-
162
- d .gossip = gossip
163
- d .stateProvider = state .NewGossipStateProvider (gossip , gossipComm , d .committer )
164
- return nil
165
- }
166
-
167
- // Start the delivery service to read the block via delivery
168
- // protocol from the orderers
169
- func (d * DeliverService ) Start () {
170
- go d .checkLeaderAndRunDeliver ()
171
- }
172
-
173
147
// Stop all service and release resources
174
148
func (d * DeliverService ) Stop () {
175
149
d .stopDeliver ()
176
- d .stateProvider .Stop ()
177
- d .gossip .Stop ()
178
150
}
179
151
180
- func (d * DeliverService ) checkLeaderAndRunDeliver () {
152
+ func (d * DeliverService ) JoinChannel (committer committer.Committer , configBlock * common.Block ) {
153
+ if err := service .GetGossipService ().JoinChannel (committer , configBlock ); err != nil {
154
+ panic ("Cannot join channel, exiting" )
155
+ }
156
+
157
+ go d .checkLeaderAndRunDeliver (committer )
158
+ }
181
159
160
+ func (d * DeliverService ) checkLeaderAndRunDeliver (committer committer.Committer ) {
182
161
isLeader := viper .GetBool ("peer.gossip.orgLeader" )
183
162
184
163
if isLeader {
185
- d .startDeliver ()
164
+ d .startDeliver (committer )
186
165
}
187
166
}
188
167
@@ -192,7 +171,7 @@ func (d *DeliverService) seekOldest() error {
192
171
Seek : & orderer.SeekInfo {
193
172
Start : orderer .SeekInfo_OLDEST ,
194
173
WindowSize : d .windowSize ,
195
- ChainID : util . GetTestChainID () ,
174
+ ChainID : d . chainID ,
196
175
},
197
176
},
198
177
})
@@ -205,7 +184,7 @@ func (d *DeliverService) seekLatestFromCommitter(height uint64) error {
205
184
Start : orderer .SeekInfo_SPECIFIED ,
206
185
WindowSize : d .windowSize ,
207
186
SpecifiedNumber : height ,
208
- ChainID : util . GetTestChainID () ,
187
+ ChainID : d . chainID ,
209
188
},
210
189
},
211
190
})
@@ -317,17 +296,17 @@ func (d *DeliverService) readUntilClose() {
317
296
}
318
297
}
319
298
320
- numberOfPeers := len (d . gossip .GetPeers ())
299
+ numberOfPeers := len (service . GetGossipService () .GetPeers ())
321
300
// Create payload with a block received
322
301
payload := createPayload (seqNum , block )
323
302
// Use payload to create gossip message
324
303
gossipMsg := createGossipMsg (payload )
325
304
logger .Debugf ("Adding payload locally, buffer seqNum = [%d], peers number [%d]" , seqNum , numberOfPeers )
326
305
// Add payload to local state payloads buffer
327
- d . stateProvider .AddPayload (payload )
306
+ service . GetGossipService () .AddPayload (d . chainID , payload )
328
307
// Gossip messages with other nodes
329
308
logger .Debugf ("Gossiping block [%d], peers number [%d]" , seqNum , numberOfPeers )
330
- d . gossip .Gossip (gossipMsg )
309
+ service . GetGossipService () .Gossip (gossipMsg )
331
310
if err = producer .SendProducerBlockEvent (block ); err != nil {
332
311
logger .Errorf ("Error sending block event %s" , err )
333
312
}
0 commit comments