@@ -27,7 +27,6 @@ import (
27
27
"github.com/hyperledger/fabric/protos/transientstore"
28
28
"github.com/hyperledger/fabric/protoutil"
29
29
"github.com/pkg/errors"
30
- "github.com/spf13/viper"
31
30
)
32
31
33
32
// GossipStateProvider is the interface to acquire sequences of the ledger blocks
@@ -166,7 +165,7 @@ type GossipStateProviderImpl struct {
166
165
167
166
blockingMode bool
168
167
169
- config * Configuration
168
+ config * StateConfig
170
169
}
171
170
172
171
var logger = util .GetLogger (util .StateLogger , "" )
@@ -188,53 +187,16 @@ func (v *stateRequestValidator) validate(request *proto.RemoteStateRequest, batc
188
187
return nil
189
188
}
190
189
191
- // readConfiguration reading state configuration
192
- func readConfiguration () * Configuration {
193
- config := & Configuration {
194
- AntiEntropyInterval : defAntiEntropyInterval ,
195
- AntiEntropyStateResponseTimeout : defAntiEntropyStateResponseTimeout ,
196
- AntiEntropyBatchSize : defAntiEntropyBatchSize ,
197
- MaxBlockDistance : defMaxBlockDistance ,
198
- AntiEntropyMaxRetries : defAntiEntropyMaxRetries ,
199
- ChannelBufferSize : defChannelBufferSize ,
200
- EnableStateTransfer : true ,
201
- }
202
-
203
- if viper .IsSet ("peer.gossip.state.checkInterval" ) {
204
- config .AntiEntropyInterval = viper .GetDuration ("peer.gossip.state.checkInterval" )
205
- }
206
-
207
- if viper .IsSet ("peer.gossip.state.responseTimeout" ) {
208
- config .AntiEntropyStateResponseTimeout = viper .GetDuration ("peer.gossip.state.responseTimeout" )
209
- }
210
-
211
- if viper .IsSet ("peer.gossip.state.batchSize" ) {
212
- config .AntiEntropyBatchSize = uint64 (viper .GetInt ("peer.gossip.state.batchSize" ))
213
- }
214
-
215
- if viper .IsSet ("peer.gossip.state.blockBufferSize" ) {
216
- config .MaxBlockDistance = viper .GetInt ("peer.gossip.state.blockBufferSize" )
217
- }
218
-
219
- if viper .IsSet ("peer.gossip.state.maxRetries" ) {
220
- config .AntiEntropyMaxRetries = viper .GetInt ("peer.gossip.state.maxRetries" )
221
- }
222
-
223
- if viper .IsSet ("peer.gossip.state.channelSize" ) {
224
- config .ChannelBufferSize = viper .GetInt ("peer.gossip.state.channelSize" )
225
- }
226
-
227
- if viper .IsSet ("peer.gossip.state.enabled" ) {
228
- config .EnableStateTransfer = viper .GetBool ("peer.gossip.state.enabled" )
229
- }
230
-
231
- return config
232
- }
233
-
234
190
// NewGossipStateProvider creates state provider with coordinator instance
235
191
// to orchestrate arrival of private rwsets and blocks before committing them into the ledger.
236
- func NewGossipStateProvider (chainID string , services * ServicesMediator , ledger ledgerResources ,
237
- stateMetrics * metrics.StateMetrics , blockingMode bool ) GossipStateProvider {
192
+ func NewGossipStateProvider (
193
+ chainID string ,
194
+ services * ServicesMediator ,
195
+ ledger ledgerResources ,
196
+ stateMetrics * metrics.StateMetrics ,
197
+ blockingMode bool ,
198
+ config * StateConfig ,
199
+ ) GossipStateProvider {
238
200
239
201
gossipChan , _ := services .Accept (func (message interface {}) bool {
240
202
// Get only data messages
@@ -278,48 +240,31 @@ func NewGossipStateProvider(chainID string, services *ServicesMediator, ledger l
278
240
return nil
279
241
}
280
242
281
- // Reading state configuration
282
- config := readConfiguration ()
283
-
284
243
s := & GossipStateProviderImpl {
285
244
// MessageCryptoService
286
245
mediator : services ,
287
-
288
246
// Chain ID
289
247
chainID : chainID ,
290
-
291
248
// Channel to read new messages from
292
249
gossipChan : gossipChan ,
293
-
294
250
// Channel to read direct messages from other peers
295
251
commChan : commChan ,
296
-
297
252
// Create a queue for payloads, wrapped in a metrics buffer
298
253
payloads : & metricsBuffer {
299
254
PayloadsBuffer : NewPayloadsBuffer (height ),
300
255
sizeMetrics : stateMetrics .PayloadBufferSize ,
301
256
chainID : chainID ,
302
257
},
303
-
304
- ledger : ledger ,
305
-
306
- stateResponseCh : make (chan protoext.ReceivedMessage , config .ChannelBufferSize ),
307
-
308
- stateRequestCh : make (chan protoext.ReceivedMessage , config .ChannelBufferSize ),
309
-
310
- stopCh : make (chan struct {}),
311
-
258
+ ledger : ledger ,
259
+ stateResponseCh : make (chan protoext.ReceivedMessage , config .StateChannelSize ),
260
+ stateRequestCh : make (chan protoext.ReceivedMessage , config .StateChannelSize ),
261
+ stopCh : make (chan struct {}),
312
262
stateTransferActive : 0 ,
313
-
314
- once : sync.Once {},
315
-
316
- stateMetrics : stateMetrics ,
317
-
318
- requestValidator : & stateRequestValidator {},
319
-
320
- blockingMode : blockingMode ,
321
-
322
- config : config ,
263
+ once : sync.Once {},
264
+ stateMetrics : stateMetrics ,
265
+ requestValidator : & stateRequestValidator {},
266
+ blockingMode : blockingMode ,
267
+ config : config ,
323
268
}
324
269
325
270
logger .Infof ("Updating metadata information, " +
@@ -331,7 +276,7 @@ func NewGossipStateProvider(chainID string, services *ServicesMediator, ledger l
331
276
go s .listen ()
332
277
// Deliver in order messages into the incoming channel
333
278
go s .deliverPayloads ()
334
- if s .config .EnableStateTransfer {
279
+ if s .config .StateEnabled {
335
280
// Execute anti entropy to fill missing gaps
336
281
go s .antiEntropy ()
337
282
}
@@ -438,7 +383,7 @@ func (s *GossipStateProviderImpl) directMessage(msg protoext.ReceivedMessage) {
438
383
incoming := msg .GetGossipMessage ()
439
384
440
385
if incoming .GetStateRequest () != nil {
441
- if len (s .stateRequestCh ) < s .config .ChannelBufferSize {
386
+ if len (s .stateRequestCh ) < s .config .StateChannelSize {
442
387
// Forward state request to the channel, if there are too
443
388
// many message of state request ignore to avoid flooding.
444
389
s .stateRequestCh <- msg
@@ -471,7 +416,7 @@ func (s *GossipStateProviderImpl) handleStateRequest(msg protoext.ReceivedMessag
471
416
}
472
417
request := msg .GetGossipMessage ().GetStateRequest ()
473
418
474
- if err := s .requestValidator .validate (request , s .config .AntiEntropyBatchSize ); err != nil {
419
+ if err := s .requestValidator .validate (request , s .config .StateBatchSize ); err != nil {
475
420
logger .Errorf ("State request validation failed, %s. Ignoring request..." , err )
476
421
return
477
422
}
@@ -654,7 +599,7 @@ func (s *GossipStateProviderImpl) antiEntropy() {
654
599
select {
655
600
case <- s .stopCh :
656
601
return
657
- case <- time .After (s .config .AntiEntropyInterval ):
602
+ case <- time .After (s .config .StateCheckInterval ):
658
603
ourHeight , err := s .ledger .LedgerHeight ()
659
604
if err != nil {
660
605
// Unable to read from ledger continue to the next round
@@ -699,15 +644,15 @@ func (s *GossipStateProviderImpl) requestBlocksInRange(start uint64, end uint64)
699
644
defer atomic .StoreInt32 (& s .stateTransferActive , 0 )
700
645
701
646
for prev := start ; prev <= end ; {
702
- next := min (end , prev + s .config .AntiEntropyBatchSize )
647
+ next := min (end , prev + s .config .StateBatchSize )
703
648
704
649
gossipMsg := s .stateRequestMessage (prev , next )
705
650
706
651
responseReceived := false
707
652
tryCounts := 0
708
653
709
654
for ! responseReceived {
710
- if tryCounts > s .config .AntiEntropyMaxRetries {
655
+ if tryCounts > s .config .StateMaxRetries {
711
656
logger .Warningf ("Wasn't able to get blocks in range [%d...%d), after %d retries" ,
712
657
prev , next , tryCounts )
713
658
return
@@ -745,7 +690,7 @@ func (s *GossipStateProviderImpl) requestBlocksInRange(start uint64, end uint64)
745
690
}
746
691
prev = index + 1
747
692
responseReceived = true
748
- case <- time .After (s .config .AntiEntropyStateResponseTimeout ):
693
+ case <- time .After (s .config .StateResponseTimeout ):
749
694
}
750
695
}
751
696
}
@@ -824,11 +769,11 @@ func (s *GossipStateProviderImpl) addPayload(payload *proto.Payload, blockingMod
824
769
return errors .Wrap (err , "Failed obtaining ledger height" )
825
770
}
826
771
827
- if ! blockingMode && payload .SeqNum - height >= uint64 (s .config .MaxBlockDistance ) {
772
+ if ! blockingMode && payload .SeqNum - height >= uint64 (s .config .StateBlockBufferSize ) {
828
773
return errors .Errorf ("Ledger height is at %d, cannot enqueue block with sequence of %d" , height , payload .SeqNum )
829
774
}
830
775
831
- for blockingMode && s .payloads .Size () > s .config .MaxBlockDistance * 2 {
776
+ for blockingMode && s .payloads .Size () > s .config .StateBlockBufferSize * 2 {
832
777
time .Sleep (enqueueRetryInterval )
833
778
}
834
779
0 commit comments