@@ -48,12 +48,22 @@ type TipMetadata struct {
48
48
// that is connected to the tips.
49
49
isReferencedByTips reactive.Variable [bool ]
50
50
51
+ // isLatestValidatorBlock is true if the block is the latest block of a validator.
52
+ isLatestValidatorBlock reactive.Variable [bool ]
53
+
54
+ // referencesLatestValidatorBlock is true if the block is the latest validator block or has parents that reference
55
+ // the latest validator block.
56
+ referencesLatestValidatorBlock reactive.Variable [bool ]
57
+
51
58
// isStrongTip is true if the block is a strong tip pool member and is not strongly referenced by other tips.
52
59
isStrongTip reactive.Variable [bool ]
53
60
54
61
// isWeakTip is true if the block is a weak tip pool member and is not referenced by other tips.
55
62
isWeakTip reactive.Variable [bool ]
56
63
64
+ // isValidatorTip is true if the block is a strong tip and references the latest validator block.
65
+ isValidatorTip reactive.Variable [bool ]
66
+
57
67
// isMarkedOrphaned is true if the liveness threshold has been reached and the block was not accepted.
58
68
isMarkedOrphaned reactive.Variable [bool ]
59
69
@@ -85,21 +95,30 @@ type TipMetadata struct {
85
95
86
96
// weaklyOrphanedWeakParents holds the number of weak parents that are weakly orphaned.
87
97
weaklyOrphanedWeakParents reactive.Counter [bool ]
98
+
99
+ // parentsReferencingLatestValidatorBlock holds the number of parents that reference the latest validator block.
100
+ parentsReferencingLatestValidatorBlock reactive.Counter [bool ]
88
101
}
89
102
90
103
// NewBlockMetadata creates a new TipMetadata instance.
91
104
func NewBlockMetadata (block * blocks.Block ) * TipMetadata {
92
105
t := & TipMetadata {
93
- block : block ,
94
- tipPool : reactive.NewVariable [tipmanager.TipPool ](tipmanager .TipPool .Max ),
95
- livenessThresholdReached : reactive .NewEvent (),
96
- evicted : reactive .NewEvent (),
97
- stronglyConnectedStrongChildren : reactive .NewCounter [bool ](),
98
- connectedWeakChildren : reactive .NewCounter [bool ](),
99
- stronglyOrphanedStrongParents : reactive .NewCounter [bool ](),
100
- weaklyOrphanedWeakParents : reactive .NewCounter [bool ](),
106
+ block : block ,
107
+ tipPool : reactive.NewVariable [tipmanager.TipPool ](tipmanager .TipPool .Max ),
108
+ livenessThresholdReached : reactive .NewEvent (),
109
+ evicted : reactive .NewEvent (),
110
+ isLatestValidatorBlock : reactive .NewVariable [bool ](),
111
+ stronglyConnectedStrongChildren : reactive .NewCounter [bool ](),
112
+ connectedWeakChildren : reactive .NewCounter [bool ](),
113
+ stronglyOrphanedStrongParents : reactive .NewCounter [bool ](),
114
+ weaklyOrphanedWeakParents : reactive .NewCounter [bool ](),
115
+ parentsReferencingLatestValidatorBlock : reactive .NewCounter [bool ](),
101
116
}
102
117
118
+ t .referencesLatestValidatorBlock = reactive .NewDerivedVariable2 (func (_ bool , isLatestValidatorBlock bool , parentsReferencingLatestValidatorBlock int ) bool {
119
+ return isLatestValidatorBlock || parentsReferencingLatestValidatorBlock > 0
120
+ }, t .isLatestValidatorBlock , t .parentsReferencingLatestValidatorBlock )
121
+
103
122
t .isMarkedOrphaned = reactive .NewDerivedVariable2 [bool , bool ](func (_ bool , isLivenessThresholdReached bool , isAccepted bool ) bool {
104
123
return isLivenessThresholdReached && ! isAccepted
105
124
}, t .livenessThresholdReached , block .Accepted ())
@@ -160,6 +179,10 @@ func NewBlockMetadata(block *blocks.Block) *TipMetadata {
160
179
return isWeakTipPoolMember && ! isReferencedByTips
161
180
}, t .isWeakTipPoolMember , t .isReferencedByTips )
162
181
182
+ t .isValidatorTip = reactive .NewDerivedVariable2 (func (_ bool , isStrongTip bool , referencesLatestValidatorBlock bool ) bool {
183
+ return isStrongTip && referencesLatestValidatorBlock
184
+ }, t .isStrongTip , t .referencesLatestValidatorBlock )
185
+
163
186
return t
164
187
}
165
188
@@ -206,6 +229,7 @@ func (t *TipMetadata) Evicted() reactive.Event {
206
229
// connectStrongParent sets up the parent and children related properties for a strong parent.
207
230
func (t * TipMetadata ) connectStrongParent (strongParent * TipMetadata ) {
208
231
t .stronglyOrphanedStrongParents .Monitor (strongParent .isStronglyOrphaned )
232
+ t .parentsReferencingLatestValidatorBlock .Monitor (strongParent .referencesLatestValidatorBlock )
209
233
210
234
// unsubscribe when the parent is evicted, since we otherwise continue to hold a reference to it.
211
235
unsubscribe := strongParent .stronglyConnectedStrongChildren .Monitor (t .isStronglyConnectedToTips )
0 commit comments