@@ -10,6 +10,7 @@ import (
1010 "github.com/iotaledger/hive.go/runtime/event"
1111 "github.com/iotaledger/hive.go/runtime/module"
1212 "github.com/iotaledger/hive.go/runtime/syncutils"
13+ "github.com/iotaledger/iota-core/pkg/core/account"
1314 "github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
1415 "github.com/iotaledger/iota-core/pkg/protocol/engine/tipmanager"
1516 iotago "github.com/iotaledger/iota.go/v4"
@@ -20,11 +21,14 @@ type TipManager struct {
2021 // retrieveBlock is a function that retrieves a Block from the Tangle.
2122 retrieveBlock func (blockID iotago.BlockID ) (block * blocks.Block , exists bool )
2223
24+ // retrieveCommitteeInSlot is a function that retrieves the committee in a given slot.
25+ retrieveCommitteeInSlot func (slot iotago.SlotIndex ) (* account.SeatedAccounts , bool )
26+
2327 // tipMetadataStorage contains the TipMetadata of all Blocks that are managed by the TipManager.
2428 tipMetadataStorage * shrinkingmap.ShrinkingMap [iotago.SlotIndex , * shrinkingmap.ShrinkingMap [iotago.BlockID , * TipMetadata ]]
2529
2630 // latestValidatorBlocks contains a Variable for each validator that stores the latest validator block.
27- latestValidatorBlocks * shrinkingmap.ShrinkingMap [iotago. AccountID , reactive.Variable [* TipMetadata ]]
31+ latestValidatorBlocks * shrinkingmap.ShrinkingMap [account. SeatIndex , reactive.Variable [* TipMetadata ]]
2832
2933 // validatorTipSet contains the subset of blocks from the strong tip set that reference the latest validator block.
3034 validatorTipSet * randommap.RandomMap [iotago.BlockID , * TipMetadata ]
@@ -49,15 +53,19 @@ type TipManager struct {
4953}
5054
5155// New creates a new TipManager.
52- func New (blockRetriever func (blockID iotago.BlockID ) (block * blocks.Block , exists bool )) * TipManager {
56+ func New (
57+ blockRetriever func (blockID iotago.BlockID ) (block * blocks.Block , exists bool ),
58+ retrieveCommitteeInSlot func (slot iotago.SlotIndex ) (* account.SeatedAccounts , bool ),
59+ ) * TipManager {
5360 t := & TipManager {
54- retrieveBlock : blockRetriever ,
55- tipMetadataStorage : shrinkingmap .New [iotago.SlotIndex , * shrinkingmap.ShrinkingMap [iotago.BlockID , * TipMetadata ]](),
56- latestValidatorBlocks : shrinkingmap .New [iotago.AccountID , reactive.Variable [* TipMetadata ]](),
57- validatorTipSet : randommap .New [iotago.BlockID , * TipMetadata ](),
58- strongTipSet : randommap .New [iotago.BlockID , * TipMetadata ](),
59- weakTipSet : randommap .New [iotago.BlockID , * TipMetadata ](),
60- blockAdded : event .New1 [tipmanager.TipMetadata ](),
61+ retrieveBlock : blockRetriever ,
62+ retrieveCommitteeInSlot : retrieveCommitteeInSlot ,
63+ 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 ](),
66+ strongTipSet : randommap .New [iotago.BlockID , * TipMetadata ](),
67+ weakTipSet : randommap .New [iotago.BlockID , * TipMetadata ](),
68+ blockAdded : event .New1 [tipmanager.TipMetadata ](),
6169 }
6270
6371 t .TriggerConstructed ()
@@ -89,23 +97,20 @@ func (t *TipManager) OnBlockAdded(handler func(block tipmanager.TipMetadata)) (u
8997 return t .blockAdded .Hook (handler ).Unhook
9098}
9199
92- // AddValidator adds a validator to the tracking of the TipManager.
93- func (t * TipManager ) AddValidator ( accountID iotago. AccountID ) ( added bool ) {
94- _ , added = t .latestValidatorBlocks .GetOrCreate (accountID , func () reactive.Variable [* TipMetadata ] {
100+ // AddSeat adds a validator to the tracking of the TipManager.
101+ func (t * TipManager ) AddSeat ( seat account. SeatIndex ) {
102+ t .latestValidatorBlocks .GetOrCreate (seat , func () reactive.Variable [* TipMetadata ] {
95103 return reactive .NewVariable [* TipMetadata ]()
96104 })
97-
98- return added
99105}
100106
101- // RemoveValidator removes a validator from the tracking of the TipManager.
102- func (t * TipManager ) RemoveValidator ( accountID iotago. AccountID ) ( removed bool ) {
103- latestValidatorBlock , removed := t .latestValidatorBlocks .DeleteAndReturn (accountID )
107+ // RemoveSeat removes a validator from the tracking of the TipManager.
108+ func (t * TipManager ) RemoveSeat ( seat account. SeatIndex ) {
109+ latestValidatorBlock , removed := t .latestValidatorBlocks .DeleteAndReturn (seat )
104110 if removed {
105111 latestValidatorBlock .Set (nil )
106112 }
107113
108- return removed
109114}
110115
111116func (t * TipManager ) ValidationTips (optAmount ... int ) []tipmanager.TipMetadata {
@@ -200,8 +205,18 @@ func (t *TipManager) trackLatestValidatorBlock(tipMetadata *TipMetadata) (teardo
200205 return
201206 }
202207
203- // We only track the validation blocks of validators that are tracked by the TipManager (via AddValidator).
204- latestValidatorBlock , exists := t .latestValidatorBlocks .Get (tipMetadata .Block ().ProtocolBlock ().Header .IssuerID )
208+ committee , exists := t .retrieveCommitteeInSlot (tipMetadata .Block ().ID ().Slot ())
209+ if ! exists {
210+ return
211+ }
212+
213+ seat , exists := committee .GetSeat (tipMetadata .Block ().ProtocolBlock ().Header .IssuerID )
214+ if ! exists {
215+ return
216+ }
217+
218+ // We only track the validation blocks of validators that are tracked by the TipManager (via AddSeat).
219+ latestValidatorBlock , exists := t .latestValidatorBlocks .Get (seat )
205220 if ! exists {
206221 return
207222 }
0 commit comments