@@ -210,7 +210,7 @@ func (t *Transitive) Gossip(ctx context.Context) error {
210
210
return nil
211
211
}
212
212
213
- lastAccepted , err := t .GetBlock (ctx , lastAcceptedID )
213
+ lastAccepted , err := t .getBlock (ctx , lastAcceptedID )
214
214
if err != nil {
215
215
t .Ctx .Log .Warn ("dropping gossip request" ,
216
216
zap .String ("reason" , "block couldn't be loaded" ),
@@ -296,7 +296,7 @@ func (t *Transitive) Put(ctx context.Context, nodeID ids.NodeID, requestID uint3
296
296
if _ , err := t .issueFrom (ctx , nodeID , blk , issuedMetric ); err != nil {
297
297
return err
298
298
}
299
- return t .buildBlocks (ctx )
299
+ return t .executeDeferredWork (ctx )
300
300
}
301
301
302
302
func (t * Transitive ) GetFailed (ctx context.Context , nodeID ids.NodeID , requestID uint32 ) error {
@@ -319,9 +319,7 @@ func (t *Transitive) GetFailed(ctx context.Context, nodeID ids.NodeID, requestID
319
319
320
320
// Because the get request was dropped, we no longer expect blkID to be issued.
321
321
t .blocked .Abandon (ctx , blkID )
322
- t .metrics .numRequests .Set (float64 (t .blkReqs .Len ()))
323
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
324
- return t .buildBlocks (ctx )
322
+ return t .executeDeferredWork (ctx )
325
323
}
326
324
327
325
func (t * Transitive ) PullQuery (ctx context.Context , nodeID ids.NodeID , requestID uint32 , blkID ids.ID , requestedHeight uint64 ) error {
@@ -335,7 +333,7 @@ func (t *Transitive) PullQuery(ctx context.Context, nodeID ids.NodeID, requestID
335
333
return err
336
334
}
337
335
338
- return t .buildBlocks (ctx )
336
+ return t .executeDeferredWork (ctx )
339
337
}
340
338
341
339
func (t * Transitive ) PushQuery (ctx context.Context , nodeID ids.NodeID , requestID uint32 , blkBytes []byte , requestedHeight uint64 ) error {
@@ -376,7 +374,7 @@ func (t *Transitive) PushQuery(ctx context.Context, nodeID ids.NodeID, requestID
376
374
return err
377
375
}
378
376
379
- return t .buildBlocks (ctx )
377
+ return t .executeDeferredWork (ctx )
380
378
}
381
379
382
380
func (t * Transitive ) Chits (ctx context.Context , nodeID ids.NodeID , requestID uint32 , preferredID ids.ID , preferredIDAtHeight ids.ID , acceptedID ids.ID ) error {
@@ -432,8 +430,7 @@ func (t *Transitive) Chits(ctx context.Context, nodeID ids.NodeID, requestID uin
432
430
}
433
431
434
432
t .blocked .Register (ctx , v )
435
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
436
- return t .buildBlocks (ctx )
433
+ return t .executeDeferredWork (ctx )
437
434
}
438
435
439
436
func (t * Transitive ) QueryFailed (ctx context.Context , nodeID ids.NodeID , requestID uint32 ) error {
@@ -450,8 +447,7 @@ func (t *Transitive) QueryFailed(ctx context.Context, nodeID ids.NodeID, request
450
447
requestID : requestID ,
451
448
},
452
449
)
453
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
454
- return t .buildBlocks (ctx )
450
+ return t .executeDeferredWork (ctx )
455
451
}
456
452
457
453
func (* Transitive ) Timeout (context.Context ) error {
@@ -474,7 +470,7 @@ func (t *Transitive) Notify(ctx context.Context, msg common.Message) error {
474
470
case common .PendingTxs :
475
471
// the pending txs message means we should attempt to build a block.
476
472
t .pendingBuildBlocks ++
477
- return t .buildBlocks (ctx )
473
+ return t .executeDeferredWork (ctx )
478
474
case common .StateSyncDone :
479
475
t .Ctx .StateSyncing .Set (false )
480
476
return nil
@@ -497,7 +493,7 @@ func (t *Transitive) Start(ctx context.Context, startReqID uint32) error {
497
493
return err
498
494
}
499
495
500
- lastAccepted , err := t .GetBlock (ctx , lastAcceptedID )
496
+ lastAccepted , err := t .getBlock (ctx , lastAcceptedID )
501
497
if err != nil {
502
498
t .Ctx .Log .Error ("failed to get last accepted block" ,
503
499
zap .Error (err ),
@@ -549,7 +545,7 @@ func (t *Transitive) Start(ctx context.Context, startReqID uint32) error {
549
545
return fmt .Errorf ("failed to notify VM that consensus is starting: %w" ,
550
546
err )
551
547
}
552
- return nil
548
+ return t . executeDeferredWork ( ctx )
553
549
}
554
550
555
551
func (t * Transitive ) HealthCheck (ctx context.Context ) (interface {}, error ) {
@@ -580,7 +576,19 @@ func (t *Transitive) HealthCheck(ctx context.Context) (interface{}, error) {
580
576
return intf , fmt .Errorf ("vm: %w ; consensus: %w" , vmErr , consensusErr )
581
577
}
582
578
583
- func (t * Transitive ) GetBlock (ctx context.Context , blkID ids.ID ) (snowman.Block , error ) {
579
+ func (t * Transitive ) executeDeferredWork (ctx context.Context ) error {
580
+ if err := t .buildBlocks (ctx ); err != nil {
581
+ return err
582
+ }
583
+
584
+ t .metrics .numRequests .Set (float64 (t .blkReqs .Len ()))
585
+ t .metrics .numBlocked .Set (float64 (len (t .pending )))
586
+ t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
587
+ t .metrics .numNonVerifieds .Set (float64 (t .nonVerifieds .Len ()))
588
+ return nil
589
+ }
590
+
591
+ func (t * Transitive ) getBlock (ctx context.Context , blkID ids.ID ) (snowman.Block , error ) {
584
592
if blk , ok := t .pending [blkID ]; ok {
585
593
return blk , nil
586
594
}
@@ -733,7 +741,7 @@ func (t *Transitive) issueFromByID(
733
741
blkID ids.ID ,
734
742
issuedMetric prometheus.Counter ,
735
743
) (bool , error ) {
736
- blk , err := t .GetBlock (ctx , blkID )
744
+ blk , err := t .getBlock (ctx , blkID )
737
745
if err != nil {
738
746
t .sendRequest (ctx , nodeID , blkID , issuedMetric )
739
747
return false , nil
@@ -759,7 +767,7 @@ func (t *Transitive) issueFrom(
759
767
760
768
blkID = blk .Parent ()
761
769
var err error
762
- blk , err = t .GetBlock (ctx , blkID )
770
+ blk , err = t .getBlock (ctx , blkID )
763
771
764
772
// If we don't have this ancestor, request it from [vdr]
765
773
if err != nil || ! blk .Status ().Fetched () {
@@ -780,10 +788,6 @@ func (t *Transitive) issueFrom(
780
788
// dependencies may still be waiting. Therefore, they should abandoned.
781
789
t .blocked .Abandon (ctx , blkID )
782
790
}
783
-
784
- // Tracks performance statistics
785
- t .metrics .numRequests .Set (float64 (t .blkReqs .Len ()))
786
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
787
791
return issued , t .errs .Err
788
792
}
789
793
@@ -804,7 +808,7 @@ func (t *Transitive) issueWithAncestors(
804
808
return false , err
805
809
}
806
810
blkID = blk .Parent ()
807
- blk , err = t .GetBlock (ctx , blkID )
811
+ blk , err = t .getBlock (ctx , blkID )
808
812
if err != nil {
809
813
status = choices .Unknown
810
814
break
@@ -826,7 +830,6 @@ func (t *Transitive) issueWithAncestors(
826
830
// We don't have this block and have no reason to expect that we will get it.
827
831
// Abandon the block to avoid a memory leak.
828
832
t .blocked .Abandon (ctx , blkID )
829
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
830
833
return false , t .errs .Err
831
834
}
832
835
@@ -869,7 +872,7 @@ func (t *Transitive) issue(
869
872
870
873
// block on the parent if needed
871
874
parentID := blk .Parent ()
872
- if parent , err := t .GetBlock (ctx , parentID ); err != nil || ! (t .Consensus .Decided (parent ) || t .Consensus .Processing (parentID )) {
875
+ if parent , err := t .getBlock (ctx , parentID ); err != nil || ! (t .Consensus .Decided (parent ) || t .Consensus .Processing (parentID )) {
873
876
t .Ctx .Log .Verbo ("block waiting for parent to be issued" ,
874
877
zap .Stringer ("blkID" , blkID ),
875
878
zap .Stringer ("parentID" , parentID ),
@@ -878,11 +881,6 @@ func (t *Transitive) issue(
878
881
}
879
882
880
883
t .blocked .Register (ctx , i )
881
-
882
- // Tracks performance statistics
883
- t .metrics .numRequests .Set (float64 (t .blkReqs .Len ()))
884
- t .metrics .numBlocked .Set (float64 (len (t .pending )))
885
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
886
884
return t .errs .Err
887
885
}
888
886
@@ -912,9 +910,6 @@ func (t *Transitive) sendRequest(
912
910
zap .Stringer ("blkID" , blkID ),
913
911
)
914
912
t .Sender .SendGet (ctx , nodeID , t .requestID , blkID )
915
-
916
- // Tracks performance statistics
917
- t .metrics .numRequests .Set (float64 (t .blkReqs .Len ()))
918
913
}
919
914
920
915
// Send a query for this block. If push is set to true, blkBytes will be used to
@@ -990,16 +985,14 @@ func (t *Transitive) deliver(
990
985
// longer pending
991
986
t .removeFromPending (blk )
992
987
parentID := blk .Parent ()
993
- parent , err := t .GetBlock (ctx , parentID )
988
+ parent , err := t .getBlock (ctx , parentID )
994
989
// Because the dependency must have been fulfilled by the time this function
995
990
// is called - we don't expect [err] to be non-nil. But it is handled for
996
991
// completness and future proofing.
997
992
if err != nil || ! (parent .Status () == choices .Accepted || t .Consensus .Processing (parentID )) {
998
993
// if the parent isn't processing or the last accepted block, then this
999
994
// block is effectively rejected
1000
995
t .blocked .Abandon (ctx , blkID )
1001
- t .metrics .numBlocked .Set (float64 (len (t .pending ))) // Tracks performance statistics
1002
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
1003
996
return t .errs .Err
1004
997
}
1005
998
@@ -1012,8 +1005,6 @@ func (t *Transitive) deliver(
1012
1005
}
1013
1006
if ! blkAdded {
1014
1007
t .blocked .Abandon (ctx , blkID )
1015
- t .metrics .numBlocked .Set (float64 (len (t .pending ))) // Tracks performance statistics
1016
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
1017
1008
return t .errs .Err
1018
1009
}
1019
1010
@@ -1077,11 +1068,6 @@ func (t *Transitive) deliver(
1077
1068
1078
1069
// If we should issue multiple queries at the same time, we need to repoll
1079
1070
t .repoll (ctx )
1080
-
1081
- // Tracks performance statistics
1082
- t .metrics .numRequests .Set (float64 (t .blkReqs .Len ()))
1083
- t .metrics .numBlocked .Set (float64 (len (t .pending )))
1084
- t .metrics .numBlockers .Set (float64 (t .blocked .Len ()))
1085
1071
return t .errs .Err
1086
1072
}
1087
1073
@@ -1108,7 +1094,6 @@ func (t *Transitive) addToNonVerifieds(blk snowman.Block) {
1108
1094
if t .nonVerifieds .Has (parentID ) || t .Consensus .Processing (parentID ) {
1109
1095
t .nonVerifieds .Add (blkID , parentID )
1110
1096
t .nonVerifiedCache .Put (blkID , blk )
1111
- t .metrics .numNonVerifieds .Set (float64 (t .nonVerifieds .Len ()))
1112
1097
}
1113
1098
}
1114
1099
@@ -1140,7 +1125,6 @@ func (t *Transitive) addUnverifiedBlockToConsensus(
1140
1125
issuedMetric .Inc ()
1141
1126
t .nonVerifieds .Remove (blkID )
1142
1127
t .nonVerifiedCache .Evict (blkID )
1143
- t .metrics .numNonVerifieds .Set (float64 (t .nonVerifieds .Len ()))
1144
1128
t .metrics .issuerStake .Observe (float64 (t .Validators .GetWeight (t .Ctx .SubnetID , nodeID )))
1145
1129
t .Ctx .Log .Verbo ("adding block to consensus" ,
1146
1130
zap .Stringer ("nodeID" , nodeID ),
0 commit comments