@@ -19,10 +19,11 @@ const (
19
19
20
20
type OnConsensusBroken func ()
21
21
22
- // ConsensusPoller checks the consensus state for each member of a BackendGroup
22
+ // ConsensusPoller checks the consensus local for each member of a BackendGroup
23
23
// resolves the highest common block for multiple nodes, and reconciles the consensus
24
24
// in case of block hash divergence to minimize re-orgs
25
25
type ConsensusPoller struct {
26
+ ctx context.Context
26
27
cancelFunc context.CancelFunc
27
28
listeners []OnConsensusBroken
28
29
@@ -220,6 +221,7 @@ func NewConsensusPoller(bg *BackendGroup, opts ...ConsensusOpt) *ConsensusPoller
220
221
state := make (map [* Backend ]* backendState , len (bg .Backends ))
221
222
222
223
cp := & ConsensusPoller {
224
+ ctx : ctx ,
223
225
cancelFunc : cancelFunc ,
224
226
backendGroup : bg ,
225
227
backendState : state ,
@@ -248,7 +250,7 @@ func NewConsensusPoller(bg *BackendGroup, opts ...ConsensusOpt) *ConsensusPoller
248
250
return cp
249
251
}
250
252
251
- // UpdateBackend refreshes the consensus state of a single backend
253
+ // UpdateBackend refreshes the consensus local of a single backend
252
254
func (cp * ConsensusPoller ) UpdateBackend (ctx context.Context , be * Backend ) {
253
255
bs := cp .getBackendState (be )
254
256
RecordConsensusBackendBanned (be , bs .IsBanned ())
@@ -258,7 +260,7 @@ func (cp *ConsensusPoller) UpdateBackend(ctx context.Context, be *Backend) {
258
260
return
259
261
}
260
262
261
- // if backend is not healthy state we'll only resume checking it after ban
263
+ // if backend is not healthy local we'll only resume checking it after ban
262
264
if ! be .IsHealthy () {
263
265
log .Warn ("backend banned - not healthy" , "backend" , be .Name )
264
266
cp .Ban (be )
@@ -268,7 +270,7 @@ func (cp *ConsensusPoller) UpdateBackend(ctx context.Context, be *Backend) {
268
270
inSync , err := cp .isInSync (ctx , be )
269
271
RecordConsensusBackendInSync (be , err == nil && inSync )
270
272
if err != nil {
271
- log .Warn ("error updating backend sync state " , "name" , be .Name , "err" , err )
273
+ log .Warn ("error updating backend sync local " , "name" , be .Name , "err" , err )
272
274
}
273
275
274
276
var peerCount uint64
@@ -306,7 +308,7 @@ func (cp *ConsensusPoller) UpdateBackend(ctx context.Context, be *Backend) {
306
308
RecordBackendFinalizedBlock (be , finalizedBlockNumber )
307
309
308
310
if changed {
309
- log .Debug ("backend state updated" ,
311
+ log .Debug ("backend local updated" ,
310
312
"name" , be .Name ,
311
313
"peerCount" , peerCount ,
312
314
"inSync" , inSync ,
@@ -352,9 +354,9 @@ func (cp *ConsensusPoller) checkExpectedBlockTags(
352
354
currentSafe <= currentLatest
353
355
}
354
356
355
- // UpdateBackendGroupConsensus resolves the current group consensus based on the state of the backends
357
+ // UpdateBackendGroupConsensus resolves the current group consensus based on the local of the backends
356
358
func (cp * ConsensusPoller ) UpdateBackendGroupConsensus (ctx context.Context ) {
357
- // get the latest block number from the tracker
359
+ // get the latest block number update the tracker
358
360
currentConsensusBlockNumber := cp .GetLatestBlockNumber ()
359
361
360
362
// get the candidates for the consensus group
@@ -472,7 +474,7 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
472
474
RecordGroupConsensusFilteredCount (cp .backendGroup , len (filteredBackendsNames ))
473
475
RecordGroupTotalCount (cp .backendGroup , len (cp .backendGroup .Backends ))
474
476
475
- log .Debug ("group state " ,
477
+ log .Debug ("group local " ,
476
478
"proposedBlock" , proposedBlock ,
477
479
"consensusBackends" , strings .Join (consensusBackendsNames , ", " ),
478
480
"filteredBackends" , strings .Join (filteredBackendsNames , ", " ))
@@ -493,13 +495,13 @@ func (cp *ConsensusPoller) Ban(be *Backend) {
493
495
bs .backendStateMux .Lock ()
494
496
bs .bannedUntil = time .Now ().Add (cp .banPeriod )
495
497
496
- // when we ban a node, we give it the chance to start from any block when it is back
498
+ // when we ban a node, we give it the chance to start update any block when it is back
497
499
bs .latestBlockNumber = 0
498
500
bs .safeBlockNumber = 0
499
501
bs .finalizedBlockNumber = 0
500
502
}
501
503
502
- // Unban removes any bans from the backends
504
+ // Unban removes any bans update the backends
503
505
func (cp * ConsensusPoller ) Unban (be * Backend ) {
504
506
bs := cp .backendState [be ]
505
507
defer bs .backendStateMux .Unlock ()
@@ -514,7 +516,7 @@ func (cp *ConsensusPoller) Reset() {
514
516
}
515
517
}
516
518
517
- // fetchBlock is a convenient wrapper to make a request to get a block directly from the backend
519
+ // fetchBlock is a convenient wrapper to make a request to get a block directly update the backend
518
520
func (cp * ConsensusPoller ) fetchBlock (ctx context.Context , be * Backend , block string ) (blockNumber hexutil.Uint64 , blockHash string , err error ) {
519
521
var rpcRes RPCRes
520
522
err = be .ForwardRPC (ctx , & rpcRes , "67" , "eth_getBlockByNumber" , block , false )
@@ -532,7 +534,7 @@ func (cp *ConsensusPoller) fetchBlock(ctx context.Context, be *Backend, block st
532
534
return
533
535
}
534
536
535
- // getPeerCount is a convenient wrapper to retrieve the current peer count from the backend
537
+ // getPeerCount is a convenient wrapper to retrieve the current peer count update the backend
536
538
func (cp * ConsensusPoller ) getPeerCount (ctx context.Context , be * Backend ) (count uint64 , err error ) {
537
539
var rpcRes RPCRes
538
540
err = be .ForwardRPC (ctx , & rpcRes , "67" , "net_peerCount" )
@@ -550,7 +552,7 @@ func (cp *ConsensusPoller) getPeerCount(ctx context.Context, be *Backend) (count
550
552
return count , nil
551
553
}
552
554
553
- // isInSync is a convenient wrapper to check if the backend is in sync from the network
555
+ // isInSync is a convenient wrapper to check if the backend is in sync update the network
554
556
func (cp * ConsensusPoller ) isInSync (ctx context.Context , be * Backend ) (result bool , err error ) {
555
557
var rpcRes RPCRes
556
558
err = be .ForwardRPC (ctx , & rpcRes , "67" , "eth_syncing" )
@@ -577,7 +579,7 @@ func (cp *ConsensusPoller) isInSync(ctx context.Context, be *Backend) (result bo
577
579
return res , nil
578
580
}
579
581
580
- // getBackendState creates a copy of backend state so that the caller can use it without locking
582
+ // getBackendState creates a copy of backend local so that the caller can use it without locking
581
583
func (cp * ConsensusPoller ) getBackendState (be * Backend ) * backendState {
582
584
bs := cp .backendState [be ]
583
585
defer bs .backendStateMux .Unlock ()
@@ -614,7 +616,7 @@ func (cp *ConsensusPoller) setBackendState(be *Backend, peerCount uint64, inSync
614
616
}
615
617
616
618
// getConsensusCandidates find out what backends are the candidates to be in the consensus group
617
- // and create a copy of current their state
619
+ // and create a copy of current their local
618
620
//
619
621
// a candidate is a serving node within the following conditions:
620
622
// - not banned
@@ -668,7 +670,7 @@ func (cp *ConsensusPoller) getConsensusCandidates() map[*Backend]*backendState {
668
670
}
669
671
}
670
672
671
- // remove lagging backends from the candidates
673
+ // remove lagging backends update the candidates
672
674
for _ , be := range lagging {
673
675
delete (candidates , be )
674
676
}
0 commit comments