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

Commit 6d2857a

Browse files
authored
Merge pull request #674 from iotaledger/feat/improve-passing-onlinecommittee
Improve passing OnlineCommittee size callback
2 parents 928e923 + c5edd2a commit 6d2857a

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

pkg/protocol/engine/ledger/ledger/ledger.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ func NewProvider() module.Provider[*engine.Engine, ledger.Ledger] {
6464

6565
e.Constructed.OnTrigger(func() {
6666
e.Events.Ledger.LinkTo(l.events)
67-
l.spendDAG = spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](l.sybilProtection.SeatManager().OnlineCommittee().Size)
67+
l.spendDAG = spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](func() int {
68+
return l.sybilProtection.SeatManager().OnlineCommittee().Size()
69+
})
6870
e.Events.SpendDAG.LinkTo(l.spendDAG.Events())
6971

7072
l.setRetainTransactionFailureFunc(e.Retainer.RetainTransactionFailure)
@@ -111,7 +113,9 @@ func New(
111113
commitmentLoader: commitmentLoader,
112114
sybilProtection: sybilProtection,
113115
errorHandler: errorHandler,
114-
spendDAG: spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](sybilProtection.SeatManager().OnlineCommittee().Size),
116+
spendDAG: spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](func() int {
117+
return sybilProtection.SeatManager().OnlineCommittee().Size()
118+
}),
115119
}
116120
}
117121

pkg/protocol/engine/mempool/v1/inclusion_flags.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,24 @@ func (s *inclusionFlags) OnRejected(callback func()) {
7575
s.rejected.OnTrigger(callback)
7676
}
7777

78-
// IsCommitted returns true if the entity was committed.
78+
// CommittedSlot returns the slot in which the entity is committed and a bool value indicating if the entity was committed.
7979
func (s *inclusionFlags) CommittedSlot() (slot iotago.SlotIndex, isCommitted bool) {
8080
return s.committedSlot.Get(), s.committedSlot.Get() != 0
8181
}
8282

83-
// OnCommitted registers a callback that gets triggered when the entity gets committed.
83+
// OnCommittedSlotUpdated registers a callback that gets triggered when the slot in which the entity is committed gets updated..
8484
func (s *inclusionFlags) OnCommittedSlotUpdated(callback func(slot iotago.SlotIndex)) {
8585
s.committedSlot.OnUpdate(func(_ iotago.SlotIndex, newValue iotago.SlotIndex) {
8686
callback(newValue)
8787
})
8888
}
8989

90-
// IsOrphaned returns true if the entity was orphaned.
90+
// OrphanedSlot returns a slot in which the entity has been orphaned and a bool flag indicating whether it was orphaned.
9191
func (s *inclusionFlags) OrphanedSlot() (slot iotago.SlotIndex, isOrphaned bool) {
9292
return s.orphanedSlot.Get(), s.orphanedSlot.Get() != 0
9393
}
9494

95-
// OnOrphaned registers a callback that gets triggered when the entity gets orphaned.
95+
// OnOrphanedSlotUpdated registers a callback that gets triggered when the orphaned slot is updated.
9696
func (s *inclusionFlags) OnOrphanedSlotUpdated(callback func(slot iotago.SlotIndex)) {
9797
s.orphanedSlot.OnUpdate(func(_ iotago.SlotIndex, newValue iotago.SlotIndex) {
9898
callback(newValue)

pkg/protocol/engine/tipselection/v1/provider.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func NewProvider(opts ...options.Option[TipSelection]) module.Provider[*engine.E
2121
e.Constructed.OnTrigger(func() {
2222
// wait for submodules to be constructed (so all of their properties are available)
2323
module.OnAllConstructed(func() {
24-
t.Construct(e.TipManager, e.Ledger.SpendDAG(), e.Ledger.MemPool().TransactionMetadata, func() iotago.BlockID { return lo.Return1(e.EvictionState.LatestActiveRootBlock()) }, DynamicLivenessThreshold(e.SybilProtection.SeatManager().OnlineCommittee().Size))
24+
t.Construct(e.TipManager, e.Ledger.SpendDAG(), e.Ledger.MemPool().TransactionMetadata, func() iotago.BlockID { return lo.Return1(e.EvictionState.LatestActiveRootBlock()) }, DynamicLivenessThreshold(func() int {
25+
return e.SybilProtection.SeatManager().OnlineCommittee().Size()
26+
}))
2527
}, e.TipManager, e.Ledger, e.SybilProtection)
2628
})
2729

pkg/protocol/sybilprotection/seatmanager/seatmanager.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ type SeatManager interface {
3131
// OnlineCommittee returns the set of online validators that is used to track acceptance.
3232
OnlineCommittee() ds.Set[account.SeatIndex]
3333

34-
// SeatCount returns the number of seats in the SeatManager.
34+
// SeatCountInSlot returns the number of seats in the SeatManager for the given slot's epoch.
3535
SeatCountInSlot(slot iotago.SlotIndex) int
3636

37+
// SeatCountInEpoch returns the number of seats in the SeatManager for the given epoch.
3738
SeatCountInEpoch(epoch iotago.EpochIndex) int
3839

3940
// Interface embeds the required methods of the module.Interface.

0 commit comments

Comments
 (0)