Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 7f24d25

Browse files
committed
Rename validator to validation block
1 parent e2b4628 commit 7f24d25

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

Diff for: pkg/protocol/engine/tipmanager/v1/tip_metadata.go

+37-37
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ type TipMetadata struct {
4949
// that is connected to the tips.
5050
isReferencedByTips reactive.Variable[bool]
5151

52-
// isLatestValidatorBlock is true if the block is the latest block of a validator.
53-
isLatestValidatorBlock reactive.Variable[bool]
52+
// isLatestValidationBlock is true if the block is the latest block of a validator.
53+
isLatestValidationBlock reactive.Variable[bool]
5454

55-
// referencesLatestValidatorBlock is true if the block is the latest validator block or has parents that reference
55+
// referencesLatestValidationBlock is true if the block is the latest validator block or has parents that reference
5656
// the latest validator block.
57-
referencesLatestValidatorBlock reactive.Variable[bool]
57+
referencesLatestValidationBlock reactive.Variable[bool]
5858

5959
// isStrongTip is true if the block is a strong tip pool member and is not strongly referenced by other tips.
6060
isStrongTip reactive.Variable[bool]
6161

6262
// isWeakTip is true if the block is a weak tip pool member and is not referenced by other tips.
6363
isWeakTip reactive.Variable[bool]
6464

65-
// isValidatorTip is true if the block is a strong tip and references the latest validator block.
66-
isValidatorTip reactive.Variable[bool]
65+
// isValidationTip is true if the block is a strong tip and references the latest validator block.
66+
isValidationTip reactive.Variable[bool]
6767

6868
// isMarkedOrphaned is true if the liveness threshold has been reached and the block was not accepted.
6969
isMarkedOrphaned reactive.Variable[bool]
@@ -97,28 +97,28 @@ type TipMetadata struct {
9797
// weaklyOrphanedWeakParents holds the number of weak parents that are weakly orphaned.
9898
weaklyOrphanedWeakParents reactive.Counter[bool]
9999

100-
// parentsReferencingLatestValidatorBlock holds the number of parents that reference the latest validator block.
101-
parentsReferencingLatestValidatorBlock reactive.Counter[bool]
100+
// parentsReferencingLatestValidationBlock holds the number of parents that reference the latest validator block.
101+
parentsReferencingLatestValidationBlock reactive.Counter[bool]
102102
}
103103

104104
// NewBlockMetadata creates a new TipMetadata instance.
105105
func NewBlockMetadata(block *blocks.Block) *TipMetadata {
106106
t := &TipMetadata{
107-
block: block,
108-
tipPool: reactive.NewVariable[tipmanager.TipPool](tipmanager.TipPool.Max),
109-
livenessThresholdReached: reactive.NewEvent(),
110-
evicted: reactive.NewEvent(),
111-
isLatestValidatorBlock: reactive.NewVariable[bool](),
112-
stronglyConnectedStrongChildren: reactive.NewCounter[bool](),
113-
connectedWeakChildren: reactive.NewCounter[bool](),
114-
stronglyOrphanedStrongParents: reactive.NewCounter[bool](),
115-
weaklyOrphanedWeakParents: reactive.NewCounter[bool](),
116-
parentsReferencingLatestValidatorBlock: reactive.NewCounter[bool](),
107+
block: block,
108+
tipPool: reactive.NewVariable[tipmanager.TipPool](tipmanager.TipPool.Max),
109+
livenessThresholdReached: reactive.NewEvent(),
110+
evicted: reactive.NewEvent(),
111+
isLatestValidationBlock: reactive.NewVariable[bool](),
112+
stronglyConnectedStrongChildren: reactive.NewCounter[bool](),
113+
connectedWeakChildren: reactive.NewCounter[bool](),
114+
stronglyOrphanedStrongParents: reactive.NewCounter[bool](),
115+
weaklyOrphanedWeakParents: reactive.NewCounter[bool](),
116+
parentsReferencingLatestValidationBlock: reactive.NewCounter[bool](),
117117
}
118118

119-
t.referencesLatestValidatorBlock = reactive.NewDerivedVariable2(func(_ bool, isLatestValidatorBlock bool, parentsReferencingLatestValidatorBlock int) bool {
120-
return isLatestValidatorBlock || parentsReferencingLatestValidatorBlock > 0
121-
}, t.isLatestValidatorBlock, t.parentsReferencingLatestValidatorBlock)
119+
t.referencesLatestValidationBlock = reactive.NewDerivedVariable2(func(_ bool, isLatestValidationBlock bool, parentsReferencingLatestValidationBlock int) bool {
120+
return isLatestValidationBlock || parentsReferencingLatestValidationBlock > 0
121+
}, t.isLatestValidationBlock, t.parentsReferencingLatestValidationBlock)
122122

123123
t.isMarkedOrphaned = reactive.NewDerivedVariable2[bool, bool](func(_ bool, isLivenessThresholdReached bool, isAccepted bool) bool {
124124
return isLivenessThresholdReached && !isAccepted
@@ -180,9 +180,9 @@ func NewBlockMetadata(block *blocks.Block) *TipMetadata {
180180
return isWeakTipPoolMember && !isReferencedByTips
181181
}, t.isWeakTipPoolMember, t.isReferencedByTips)
182182

183-
t.isValidatorTip = reactive.NewDerivedVariable2(func(_ bool, isStrongTip bool, referencesLatestValidatorBlock bool) bool {
184-
return isStrongTip && referencesLatestValidatorBlock
185-
}, t.isStrongTip, t.referencesLatestValidatorBlock)
183+
t.isValidationTip = reactive.NewDerivedVariable2(func(_ bool, isStrongTip bool, referencesLatestValidationBlock bool) bool {
184+
return isStrongTip && referencesLatestValidationBlock
185+
}, t.isStrongTip, t.referencesLatestValidationBlock)
186186

187187
return t
188188
}
@@ -227,25 +227,25 @@ func (t *TipMetadata) Evicted() reactive.Event {
227227
return t.evicted
228228
}
229229

230-
// registerAsLatestValidatorBlock registers the TipMetadata as the latest validator block if it is newer than the
231-
// currently registered block and sets the isLatestValidatorBlock variable accordingly. The function returns true if the
230+
// registerAsLatestValidationBlock registers the TipMetadata as the latest validation block if it is newer than the
231+
// currently registered block and sets the isLatestValidationBlock variable accordingly. The function returns true if the
232232
// operation was successful.
233-
func (t *TipMetadata) registerAsLatestValidatorBlock(latestValidatorBlock reactive.Variable[*TipMetadata]) (registered bool) {
234-
latestValidatorBlock.Compute(func(currentLatestValidatorBlock *TipMetadata) *TipMetadata {
235-
registered = currentLatestValidatorBlock == nil || currentLatestValidatorBlock.block.IssuingTime().Before(t.block.IssuingTime())
233+
func (t *TipMetadata) registerAsLatestValidationBlock(latestValidationBlock reactive.Variable[*TipMetadata]) (registered bool) {
234+
latestValidationBlock.Compute(func(currentLatestValidationBlock *TipMetadata) *TipMetadata {
235+
registered = currentLatestValidationBlock == nil || currentLatestValidationBlock.block.IssuingTime().Before(t.block.IssuingTime())
236236

237-
return lo.Cond(registered, t, currentLatestValidatorBlock)
237+
return lo.Cond(registered, t, currentLatestValidationBlock)
238238
})
239239

240240
if registered {
241-
t.isLatestValidatorBlock.Set(true)
241+
t.isLatestValidationBlock.Set(true)
242242

243-
// Once the latestValidatorBlock is updated again (by another block), we need to reset the isLatestValidatorBlock
243+
// Once the latestValidationBlock is updated again (by another block), we need to reset the isLatestValidationBlock
244244
// variable.
245-
latestValidatorBlock.OnUpdateOnce(func(_ *TipMetadata, _ *TipMetadata) {
246-
t.isLatestValidatorBlock.Set(false)
247-
}, func(_ *TipMetadata, latestValidatorBlock *TipMetadata) bool {
248-
return latestValidatorBlock != t
245+
latestValidationBlock.OnUpdateOnce(func(_ *TipMetadata, _ *TipMetadata) {
246+
t.isLatestValidationBlock.Set(false)
247+
}, func(_ *TipMetadata, latestValidationBlock *TipMetadata) bool {
248+
return latestValidationBlock != t
249249
})
250250
}
251251

@@ -255,7 +255,7 @@ func (t *TipMetadata) registerAsLatestValidatorBlock(latestValidatorBlock reacti
255255
// connectStrongParent sets up the parent and children related properties for a strong parent.
256256
func (t *TipMetadata) connectStrongParent(strongParent *TipMetadata) {
257257
t.stronglyOrphanedStrongParents.Monitor(strongParent.isStronglyOrphaned)
258-
t.parentsReferencingLatestValidatorBlock.Monitor(strongParent.referencesLatestValidatorBlock)
258+
t.parentsReferencingLatestValidationBlock.Monitor(strongParent.referencesLatestValidationBlock)
259259

260260
// unsubscribe when the parent is evicted, since we otherwise continue to hold a reference to it.
261261
unsubscribe := strongParent.stronglyConnectedStrongChildren.Monitor(t.isStronglyConnectedToTips)

Diff for: pkg/protocol/engine/tipmanager/v1/tipmanager.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ type TipManager struct {
2727
// tipMetadataStorage contains the TipMetadata of all Blocks that are managed by the TipManager.
2828
tipMetadataStorage *shrinkingmap.ShrinkingMap[iotago.SlotIndex, *shrinkingmap.ShrinkingMap[iotago.BlockID, *TipMetadata]]
2929

30-
// latestValidatorBlocks contains a Variable for each validator that stores the latest validator block.
31-
latestValidatorBlocks *shrinkingmap.ShrinkingMap[account.SeatIndex, reactive.Variable[*TipMetadata]]
30+
// latestValidationBlocks contains a Variable for each validator that stores the latest validation block.
31+
latestValidationBlocks *shrinkingmap.ShrinkingMap[account.SeatIndex, reactive.Variable[*TipMetadata]]
3232

33-
// validatorTipSet contains the subset of blocks from the strong tip set that reference the latest validator block.
34-
validatorTipSet *randommap.RandomMap[iotago.BlockID, *TipMetadata]
33+
// validationTipSet contains the subset of blocks from the strong tip set that reference the latest validation block.
34+
validationTipSet *randommap.RandomMap[iotago.BlockID, *TipMetadata]
3535

3636
// strongTipSet contains the blocks of the strong tip pool that have no referencing children.
3737
strongTipSet *randommap.RandomMap[iotago.BlockID, *TipMetadata]
@@ -61,8 +61,8 @@ func New(
6161
retrieveBlock: blockRetriever,
6262
retrieveCommitteeInSlot: retrieveCommitteeInSlot,
6363
tipMetadataStorage: shrinkingmap.New[iotago.SlotIndex, *shrinkingmap.ShrinkingMap[iotago.BlockID, *TipMetadata]](),
64-
latestValidatorBlocks: shrinkingmap.New[account.SeatIndex, reactive.Variable[*TipMetadata]](),
65-
validatorTipSet: randommap.New[iotago.BlockID, *TipMetadata](),
64+
latestValidationBlocks: shrinkingmap.New[account.SeatIndex, reactive.Variable[*TipMetadata]](),
65+
validationTipSet: randommap.New[iotago.BlockID, *TipMetadata](),
6666
strongTipSet: randommap.New[iotago.BlockID, *TipMetadata](),
6767
weakTipSet: randommap.New[iotago.BlockID, *TipMetadata](),
6868
blockAdded: event.New1[tipmanager.TipMetadata](),
@@ -99,22 +99,22 @@ func (t *TipManager) OnBlockAdded(handler func(block tipmanager.TipMetadata)) (u
9999

100100
// AddSeat adds a validator to the tracking of the TipManager.
101101
func (t *TipManager) AddSeat(seat account.SeatIndex) {
102-
t.latestValidatorBlocks.GetOrCreate(seat, func() reactive.Variable[*TipMetadata] {
102+
t.latestValidationBlocks.GetOrCreate(seat, func() reactive.Variable[*TipMetadata] {
103103
return reactive.NewVariable[*TipMetadata]()
104104
})
105105
}
106106

107107
// RemoveSeat removes a validator from the tracking of the TipManager.
108108
func (t *TipManager) RemoveSeat(seat account.SeatIndex) {
109-
latestValidatorBlock, removed := t.latestValidatorBlocks.DeleteAndReturn(seat)
109+
latestValidationBlock, removed := t.latestValidationBlocks.DeleteAndReturn(seat)
110110
if removed {
111-
latestValidatorBlock.Set(nil)
111+
latestValidationBlock.Set(nil)
112112
}
113113

114114
}
115115

116116
func (t *TipManager) ValidationTips(optAmount ...int) []tipmanager.TipMetadata {
117-
return t.selectTips(t.validatorTipSet, optAmount...)
117+
return t.selectTips(t.validationTipSet, optAmount...)
118118
}
119119

120120
// StrongTips returns the strong tips of the TipManager (with an optional limit).
@@ -161,14 +161,14 @@ func (t *TipManager) Shutdown() {
161161
// setupBlockMetadata sets up the behavior of the given Block.
162162
func (t *TipManager) setupBlockMetadata(tipMetadata *TipMetadata) {
163163
tipMetadata.isStrongTipPoolMember.WithNonEmptyValue(func(_ bool) func() {
164-
return t.trackLatestValidatorBlock(tipMetadata)
164+
return t.trackLatestValidationBlock(tipMetadata)
165165
})
166166

167-
tipMetadata.isValidatorTip.OnUpdate(func(_ bool, isValidatorTip bool) {
168-
if isValidatorTip {
169-
t.validatorTipSet.Set(tipMetadata.ID(), tipMetadata)
167+
tipMetadata.isValidationTip.OnUpdate(func(_ bool, isValidationTip bool) {
168+
if isValidationTip {
169+
t.validationTipSet.Set(tipMetadata.ID(), tipMetadata)
170170
} else {
171-
t.validatorTipSet.Delete(tipMetadata.ID())
171+
t.validationTipSet.Delete(tipMetadata.ID())
172172
}
173173
})
174174

@@ -199,8 +199,8 @@ func (t *TipManager) setupBlockMetadata(tipMetadata *TipMetadata) {
199199
t.blockAdded.Trigger(tipMetadata)
200200
}
201201

202-
// trackLatestValidatorBlock tracks the latest validator block and takes care of marking the corresponding TipMetadata.
203-
func (t *TipManager) trackLatestValidatorBlock(tipMetadata *TipMetadata) (teardown func()) {
202+
// trackLatestValidationBlock tracks the latest validator block and takes care of marking the corresponding TipMetadata.
203+
func (t *TipManager) trackLatestValidationBlock(tipMetadata *TipMetadata) (teardown func()) {
204204
if _, isValidationBlock := tipMetadata.Block().ValidationBlock(); !isValidationBlock {
205205
return
206206
}
@@ -216,19 +216,19 @@ func (t *TipManager) trackLatestValidatorBlock(tipMetadata *TipMetadata) (teardo
216216
}
217217

218218
// We only track the validation blocks of validators that are tracked by the TipManager (via AddSeat).
219-
latestValidatorBlock, exists := t.latestValidatorBlocks.Get(seat)
219+
latestValidationBlock, exists := t.latestValidationBlocks.Get(seat)
220220
if !exists {
221221
return
222222
}
223223

224-
if !tipMetadata.registerAsLatestValidatorBlock(latestValidatorBlock) {
224+
if !tipMetadata.registerAsLatestValidationBlock(latestValidationBlock) {
225225
return
226226
}
227227

228228
// reset the latest validator block to nil if we are still the latest one during teardown
229229
return func() {
230-
latestValidatorBlock.Compute(func(latestValidatorBlock *TipMetadata) *TipMetadata {
231-
return lo.Cond(latestValidatorBlock == tipMetadata, nil, latestValidatorBlock)
230+
latestValidationBlock.Compute(func(latestValidationBlock *TipMetadata) *TipMetadata {
231+
return lo.Cond(latestValidationBlock == tipMetadata, nil, latestValidationBlock)
232232
})
233233
}
234234
}

0 commit comments

Comments
 (0)