Skip to content

Commit

Permalink
Moar renames
Browse files Browse the repository at this point in the history
  • Loading branch information
karimodm committed Oct 5, 2023
1 parent 4c26ea7 commit 07c98dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions pkg/protocol/engine/mempool/v1/inclusion_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ type inclusionFlags struct {
// accepted gets triggered when the entity gets marked as accepted.
accepted reactive.Variable[bool]

// committedOnSlot gets set to the slot in which the entity gets marked as committed.
committedOnSlot reactive.Variable[iotago.SlotIndex]
// committedSlot gets set to the slot in which the entity gets marked as committed.
committedSlot reactive.Variable[iotago.SlotIndex]

// rejected gets triggered when the entity gets marked as rejected.
rejected *promise.Event

// orphanedOnSlot gets set to the slot in which the entity gets marked as orphaned.
orphanedOnSlot reactive.Variable[iotago.SlotIndex]
// orphanedSlot gets set to the slot in which the entity gets marked as orphaned.
orphanedSlot reactive.Variable[iotago.SlotIndex]
}

// newInclusionFlags creates a new inclusionFlags instance.
func newInclusionFlags() *inclusionFlags {
return &inclusionFlags{
accepted: reactive.NewVariable[bool](),
committedOnSlot: reactive.NewVariable[iotago.SlotIndex](),
rejected: promise.NewEvent(),
accepted: reactive.NewVariable[bool](),
committedSlot: reactive.NewVariable[iotago.SlotIndex](),
rejected: promise.NewEvent(),
// Make sure the oldest orphaned index doesn't get overridden by newer TX spending the orphaned conflict further.
orphanedOnSlot: reactive.NewVariable[iotago.SlotIndex](func(currentValue, newValue iotago.SlotIndex) iotago.SlotIndex {
orphanedSlot: reactive.NewVariable[iotago.SlotIndex](func(currentValue, newValue iotago.SlotIndex) iotago.SlotIndex {
if currentValue != 0 {
return currentValue
}
Expand Down Expand Up @@ -77,24 +77,24 @@ func (s *inclusionFlags) OnRejected(callback func()) {

// IsCommitted returns true if the entity was committed.
func (s *inclusionFlags) CommittedSlot() (slot iotago.SlotIndex, isCommitted bool) {
return s.committedOnSlot.Get(), s.committedOnSlot.Get() != 0
return s.committedSlot.Get(), s.committedSlot.Get() != 0
}

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

// IsOrphaned returns true if the entity was orphaned.
func (s *inclusionFlags) OrphanedSlot() (slot iotago.SlotIndex, isOrphaned bool) {
return s.orphanedOnSlot.Get(), s.orphanedOnSlot.Get() != 0
return s.orphanedSlot.Get(), s.orphanedSlot.Get() != 0
}

// OnOrphaned registers a callback that gets triggered when the entity gets orphaned.
func (s *inclusionFlags) OnOrphanedSlotUpdated(callback func(slot iotago.SlotIndex)) {
s.orphanedOnSlot.OnUpdate(func(_, newValue iotago.SlotIndex) {
s.orphanedSlot.OnUpdate(func(_, newValue iotago.SlotIndex) {
callback(newValue)
})
}
2 changes: 1 addition & 1 deletion pkg/protocol/engine/mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (m *MemPool[VoteRank]) forkTransaction(transactionMetadata *TransactionMeta

if err := m.conflictDAG.UpdateConflictingResources(transactionMetadata.ID(), resourceIDs); err != nil {
// this is a hack, as with a reactive.Variable we cannot set it to 0 and still check if it was orphaned.
transactionMetadata.orphanedOnSlot.Set(1)
transactionMetadata.orphanedSlot.Set(1)

m.errorHandler(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/engine/mempool/v1/state_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata
source.OnPending(func() { s.accepted.Set(false) })
source.OnAccepted(func() { s.accepted.Set(true) })
source.OnRejected(func() { s.rejected.Trigger() })
source.OnCommittedSlotUpdated(lo.Void(s.committedOnSlot.Set))
source.OnOrphanedSlotUpdated(lo.Void(s.orphanedOnSlot.Set))
source.OnCommittedSlotUpdated(lo.Void(s.committedSlot.Set))
source.OnOrphanedSlotUpdated(lo.Void(s.orphanedSlot.Set))

return s
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/protocol/engine/mempool/v1/transaction_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (t *TransactionMetadata) markInputSolid() (allInputsSolid bool) {
}

func (t *TransactionMetadata) Commit() {
t.committedOnSlot.Set(t.earliestIncludedValidAttachment.Get().Slot())
t.committedSlot.Set(t.earliestIncludedValidAttachment.Get().Slot())
}

func (t *TransactionMetadata) IsConflicting() bool {
Expand Down Expand Up @@ -251,7 +251,7 @@ func (t *TransactionMetadata) setupInput(input *StateMetadata) {

input.OnRejected(func() { t.rejected.Trigger() })
input.OnOrphanedSlotUpdated(func(slot iotago.SlotIndex) {
t.orphanedOnSlot.Set(slot)
t.orphanedSlot.Set(slot)
})
input.OnAccepted(func() {
if atomic.AddUint64(&t.unacceptedInputsCount, ^uint64(0)) == 0 {
Expand Down Expand Up @@ -279,7 +279,7 @@ func (t *TransactionMetadata) setupInput(input *StateMetadata) {
input.OnSpendCommitted(func(spender mempool.TransactionMetadata) {
if spender != t {
spender.OnCommittedSlotUpdated(func(slot iotago.SlotIndex) {
t.orphanedOnSlot.Set(slot)
t.orphanedSlot.Set(slot)
})
}
})
Expand All @@ -296,7 +296,7 @@ func (t *TransactionMetadata) setup() (self *TransactionMetadata) {

t.allValidAttachmentsEvicted.OnUpdate(func(_, slot iotago.SlotIndex) {
if !lo.Return2(t.CommittedSlot()) {
t.orphanedOnSlot.Set(slot)
t.orphanedSlot.Set(slot)
}
})

Expand Down

0 comments on commit 07c98dc

Please sign in to comment.