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

Commit

Permalink
Merge pull request #674 from iotaledger/feat/improve-passing-onlineco…
Browse files Browse the repository at this point in the history
…mmittee

Improve passing OnlineCommittee size callback
  • Loading branch information
piotrm50 authored Jan 17, 2024
2 parents 928e923 + c5edd2a commit 6d2857a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 6 additions & 2 deletions pkg/protocol/engine/ledger/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func NewProvider() module.Provider[*engine.Engine, ledger.Ledger] {

e.Constructed.OnTrigger(func() {
e.Events.Ledger.LinkTo(l.events)
l.spendDAG = spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](l.sybilProtection.SeatManager().OnlineCommittee().Size)
l.spendDAG = spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](func() int {
return l.sybilProtection.SeatManager().OnlineCommittee().Size()
})
e.Events.SpendDAG.LinkTo(l.spendDAG.Events())

l.setRetainTransactionFailureFunc(e.Retainer.RetainTransactionFailure)
Expand Down Expand Up @@ -111,7 +113,9 @@ func New(
commitmentLoader: commitmentLoader,
sybilProtection: sybilProtection,
errorHandler: errorHandler,
spendDAG: spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](sybilProtection.SeatManager().OnlineCommittee().Size),
spendDAG: spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](func() int {
return sybilProtection.SeatManager().OnlineCommittee().Size()
}),
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/protocol/engine/mempool/v1/inclusion_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,24 @@ func (s *inclusionFlags) OnRejected(callback func()) {
s.rejected.OnTrigger(callback)
}

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

// OnCommitted registers a callback that gets triggered when the entity gets committed.
// OnCommittedSlotUpdated registers a callback that gets triggered when the slot in which the entity is committed gets updated..
func (s *inclusionFlags) OnCommittedSlotUpdated(callback func(slot iotago.SlotIndex)) {
s.committedSlot.OnUpdate(func(_ iotago.SlotIndex, newValue iotago.SlotIndex) {
callback(newValue)
})
}

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

// OnOrphaned registers a callback that gets triggered when the entity gets orphaned.
// OnOrphanedSlotUpdated registers a callback that gets triggered when the orphaned slot is updated.
func (s *inclusionFlags) OnOrphanedSlotUpdated(callback func(slot iotago.SlotIndex)) {
s.orphanedSlot.OnUpdate(func(_ iotago.SlotIndex, newValue iotago.SlotIndex) {
callback(newValue)
Expand Down
4 changes: 3 additions & 1 deletion pkg/protocol/engine/tipselection/v1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func NewProvider(opts ...options.Option[TipSelection]) module.Provider[*engine.E
e.Constructed.OnTrigger(func() {
// wait for submodules to be constructed (so all of their properties are available)
module.OnAllConstructed(func() {
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))
t.Construct(e.TipManager, e.Ledger.SpendDAG(), e.Ledger.MemPool().TransactionMetadata, func() iotago.BlockID { return lo.Return1(e.EvictionState.LatestActiveRootBlock()) }, DynamicLivenessThreshold(func() int {
return e.SybilProtection.SeatManager().OnlineCommittee().Size()
}))
}, e.TipManager, e.Ledger, e.SybilProtection)
})

Expand Down
3 changes: 2 additions & 1 deletion pkg/protocol/sybilprotection/seatmanager/seatmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type SeatManager interface {
// OnlineCommittee returns the set of online validators that is used to track acceptance.
OnlineCommittee() ds.Set[account.SeatIndex]

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

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

// Interface embeds the required methods of the module.Interface.
Expand Down

0 comments on commit 6d2857a

Please sign in to comment.