Skip to content

Commit

Permalink
Properties renames
Browse files Browse the repository at this point in the history
  • Loading branch information
karimodm committed Oct 5, 2023
1 parent b6cf776 commit 4c26ea7
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions pkg/protocol/engine/booker/inmemorybooker/booker.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (b *Booker) Queue(block *blocks.Block) error {
signedTransactionMetadata.OnSignaturesValid(func() {
transactionMetadata := signedTransactionMetadata.TransactionMetadata()

if orphanedSlot, isOrphaned := transactionMetadata.GetOrphanedSlot(); isOrphaned && orphanedSlot <= block.SlotCommitmentID().Slot() {
if orphanedSlot, isOrphaned := transactionMetadata.OrphanedSlot(); isOrphaned && orphanedSlot <= block.SlotCommitmentID().Slot() {
block.SetInvalid()

return
Expand Down Expand Up @@ -158,7 +158,7 @@ func (b *Booker) book(block *blocks.Block) error {
return ierrors.Errorf("failed to load transaction %s for block %s", conflictID.String(), block.ID())
}

if orphanedSlot, orphaned := txMetadata.GetOrphanedSlot(); orphaned && orphanedSlot <= block.SlotCommitmentID().Slot() {
if orphanedSlot, orphaned := txMetadata.OrphanedSlot(); orphaned && orphanedSlot <= block.SlotCommitmentID().Slot() {
// Merge-to-master orphaned conflicts.
conflictsToInherit.Delete(conflictID)
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/protocol/engine/mempool/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ func TestSetInclusionSlot(t *testing.T, tf *TestFramework) {
tf.CommitSlot(3)
tf.RequireTransactionsEvicted(transactionDeletionState)

require.False(t, lo.Return2(tx1Metadata.GetOrphanedSlot()))
require.False(t, lo.Return2(tx2Metadata.GetOrphanedSlot()))
require.False(t, lo.Return2(tx3Metadata.GetOrphanedSlot()))
require.False(t, lo.Return2(tx1Metadata.OrphanedSlot()))
require.False(t, lo.Return2(tx2Metadata.OrphanedSlot()))
require.False(t, lo.Return2(tx3Metadata.OrphanedSlot()))

tf.RequireAttachmentsEvicted(lo.MergeMaps(attachmentDeletionState, map[string]bool{"block1": true, "block2": true, "block3": false}))
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestSetTransactionOrphanage(t *testing.T, tf *TestFramework) {
// We only evict after MCA
tf.RequireTransactionsEvicted(map[string]bool{"tx1": false, "tx2": false, "tx3": false})

require.True(t, lo.Return2(tx1Metadata.GetOrphanedSlot()))
require.True(t, lo.Return2(tx1Metadata.OrphanedSlot()))
require.True(t, tx2Metadata.IsPending())
require.True(t, tx3Metadata.IsPending())

Expand Down Expand Up @@ -312,19 +312,19 @@ func TestSetTxOrphanageMultipleAttachments(t *testing.T, tf *TestFramework) {
require.False(t, tx3Metadata.IsAccepted())

tf.Instance.Evict(1)
require.False(t, lo.Return2(tx1Metadata.GetOrphanedSlot()))
require.False(t, lo.Return2(tx2Metadata.GetOrphanedSlot()))
require.False(t, lo.Return2(tx3Metadata.GetOrphanedSlot()))
require.False(t, lo.Return2(tx1Metadata.OrphanedSlot()))
require.False(t, lo.Return2(tx2Metadata.OrphanedSlot()))
require.False(t, lo.Return2(tx3Metadata.OrphanedSlot()))

require.True(t, lo.Return2(tf.ConflictDAG.ConflictSets(tf.TransactionID("tx1"))))
require.True(t, lo.Return2(tf.ConflictDAG.ConflictSets(tf.TransactionID("tx2"))))
require.True(t, lo.Return2(tf.ConflictDAG.ConflictSets(tf.TransactionID("tx3"))))

tf.Instance.Evict(2)

require.True(t, lo.Return2(tx1Metadata.GetOrphanedSlot()))
require.True(t, lo.Return2(tx2Metadata.GetOrphanedSlot()))
require.True(t, lo.Return2(tx3Metadata.GetOrphanedSlot()))
require.True(t, lo.Return2(tx1Metadata.OrphanedSlot()))
require.True(t, lo.Return2(tx2Metadata.OrphanedSlot()))
require.True(t, lo.Return2(tx3Metadata.OrphanedSlot()))

// All conflicts still exist, as they are kept around until MCA
require.True(t, lo.Return2(tf.ConflictDAG.ConflictSets(tf.TransactionID("tx1"))))
Expand Down
8 changes: 4 additions & 4 deletions pkg/protocol/engine/mempool/transaction_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ type inclusionFlags interface {

OnAccepted(callback func())

GetCommittedSlot() (slot iotago.SlotIndex, isCommitted bool)
CommittedSlot() (slot iotago.SlotIndex, isCommitted bool)

OnCommitted(callback func(slot iotago.SlotIndex))
OnCommittedSlotUpdated(callback func(slot iotago.SlotIndex))

IsRejected() bool

OnRejected(callback func())

GetOrphanedSlot() (slot iotago.SlotIndex, isOrphaned bool)
OrphanedSlot() (slot iotago.SlotIndex, isOrphaned bool)

OnOrphaned(callback func(slot iotago.SlotIndex))
OnOrphanedSlotUpdated(callback func(slot iotago.SlotIndex))
}
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 @@ -76,24 +76,24 @@ func (s *inclusionFlags) OnRejected(callback func()) {
}

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

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

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

// OnOrphaned registers a callback that gets triggered when the entity gets orphaned.
func (s *inclusionFlags) OnOrphaned(callback func(slot iotago.SlotIndex)) {
func (s *inclusionFlags) OnOrphanedSlotUpdated(callback func(slot iotago.SlotIndex)) {
s.orphanedOnSlot.OnUpdate(func(_, newValue iotago.SlotIndex) {
callback(newValue)
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/protocol/engine/mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ func (m *MemPool[VoteRank]) setupTransaction(transaction *TransactionMetadata) {
transaction.signingTransactions.Range((*SignedTransactionMetadata).setEvicted)
})

transaction.OnCommitted(func(slot iotago.SlotIndex) {
transaction.OnCommittedSlotUpdated(func(slot iotago.SlotIndex) {
lo.Return1(m.delayedTransactionEviction.GetOrCreate(slot, func() ds.Set[iotago.TransactionID] { return ds.NewSet[iotago.TransactionID]() })).Add(transaction.ID())
})

transaction.OnOrphaned(func(slot iotago.SlotIndex) {
transaction.OnOrphanedSlotUpdated(func(slot iotago.SlotIndex) {
lo.Return1(m.delayedTransactionEviction.GetOrCreate(slot, func() ds.Set[iotago.TransactionID] { return ds.NewSet[iotago.TransactionID]() })).Add(transaction.ID())
})
}
Expand All @@ -494,13 +494,13 @@ func (m *MemPool[VoteRank]) setupOutputState(stateMetadata *StateMetadata) {
m.cachedStateRequests.Delete(stateMetadata.state.StateID(), stateMetadata.HasNoSpenders)
})

stateMetadata.OnCommitted(func(slot iotago.SlotIndex) {
stateMetadata.OnCommittedSlotUpdated(func(slot iotago.SlotIndex) {
lo.Return1(m.delayedOutputStateEviction.GetOrCreate(slot, func() *shrinkingmap.ShrinkingMap[iotago.Identifier, *StateMetadata] {
return shrinkingmap.New[iotago.Identifier, *StateMetadata]()
})).Set(stateMetadata.state.StateID(), stateMetadata)
})

stateMetadata.OnOrphaned(func(slot iotago.SlotIndex) {
stateMetadata.OnOrphanedSlotUpdated(func(slot iotago.SlotIndex) {
lo.Return1(m.delayedOutputStateEviction.GetOrCreate(slot, func() *shrinkingmap.ShrinkingMap[iotago.Identifier, *StateMetadata] {
return shrinkingmap.New[iotago.Identifier, *StateMetadata]()
})).Set(stateMetadata.state.StateID(), stateMetadata)
Expand Down
8 changes: 4 additions & 4 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.OnCommitted(lo.Void(s.committedOnSlot.Set))
source.OnOrphaned(lo.Void(s.orphanedOnSlot.Set))
source.OnCommittedSlotUpdated(lo.Void(s.committedOnSlot.Set))
source.OnOrphanedSlotUpdated(lo.Void(s.orphanedOnSlot.Set))

return s
}
Expand Down Expand Up @@ -139,11 +139,11 @@ func (s *StateMetadata) setupSpender(spender *TransactionMetadata) {
s.spendAccepted.Set(nil)
})

spender.OnCommitted(func(_ iotago.SlotIndex) {
spender.OnCommittedSlotUpdated(func(_ iotago.SlotIndex) {
s.spendCommitted.Set(spender)

s.decreaseSpenderCount()
})

spender.OnOrphaned(func(_ iotago.SlotIndex) { s.decreaseSpenderCount() })
spender.OnOrphanedSlotUpdated(func(_ iotago.SlotIndex) { s.decreaseSpenderCount() })
}
6 changes: 3 additions & 3 deletions pkg/protocol/engine/mempool/v1/transaction_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (t *TransactionMetadata) setupInput(input *StateMetadata) {
t.parentConflictIDs.InheritFrom(input.conflictIDs)

input.OnRejected(func() { t.rejected.Trigger() })
input.OnOrphaned(func(slot iotago.SlotIndex) {
input.OnOrphanedSlotUpdated(func(slot iotago.SlotIndex) {
t.orphanedOnSlot.Set(slot)
})
input.OnAccepted(func() {
Expand Down Expand Up @@ -278,7 +278,7 @@ func (t *TransactionMetadata) setupInput(input *StateMetadata) {

input.OnSpendCommitted(func(spender mempool.TransactionMetadata) {
if spender != t {
spender.OnCommitted(func(slot iotago.SlotIndex) {
spender.OnCommittedSlotUpdated(func(slot iotago.SlotIndex) {
t.orphanedOnSlot.Set(slot)
})
}
Expand All @@ -295,7 +295,7 @@ func (t *TransactionMetadata) setup() (self *TransactionMetadata) {
})

t.allValidAttachmentsEvicted.OnUpdate(func(_, slot iotago.SlotIndex) {
if !lo.Return2(t.GetCommittedSlot()) {
if !lo.Return2(t.CommittedSlot()) {
t.orphanedOnSlot.Set(slot)
}
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/testsuite/mock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,12 @@ func (n *Node) attachEngineLogs(failOnBlockFiltered bool, instance *engine.Engin
fmt.Printf("%s > [%s] MemPool.TransactionInvalid(%s): %s\n", n.Name, engineName, err, transactionMetadata.ID())
})

transactionMetadata.OnOrphaned(func(slot iotago.SlotIndex) {
fmt.Printf("%s > [%s] MemPool.TransactionOrphaned in slot %d: %s\n", n.Name, engineName, slot, transactionMetadata.ID())
transactionMetadata.OnOrphanedSlotUpdated(func(slot iotago.SlotIndex) {
fmt.Printf("%s > [%s] MemPool.TransactiOnOrphanedSlotUpdated in slot %d: %s\n", n.Name, engineName, slot, transactionMetadata.ID())
})

transactionMetadata.OnCommitted(func(slot iotago.SlotIndex) {
fmt.Printf("%s > [%s] MemPool.TransactionCommitted in slot %d: %s\n", n.Name, engineName, slot, transactionMetadata.ID())
transactionMetadata.OnCommittedSlotUpdated(func(slot iotago.SlotIndex) {
fmt.Printf("%s > [%s] MemPool.TransactiOnCommittedSlotUpdated in slot %d: %s\n", n.Name, engineName, slot, transactionMetadata.ID())
})

transactionMetadata.OnPending(func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/testsuite/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (t *TestSuite) AssertTransactionsInCachePending(expectedTransactions []*iot
}

func (t *TestSuite) AssertTransactionsInCacheOrphaned(expectedTransactions []*iotago.Transaction, expectedFlag bool, nodes ...*mock.Node) {
t.assertTransactionsInCacheWithFunc(expectedTransactions, expectedFlag, func(tm mempool.TransactionMetadata) bool { return lo.Return2(tm.GetOrphanedSlot()) }, nodes...)
t.assertTransactionsInCacheWithFunc(expectedTransactions, expectedFlag, func(tm mempool.TransactionMetadata) bool { return lo.Return2(tm.OrphanedSlot()) }, nodes...)
}

func (t *TestSuite) AssertTransactionInCacheConflicts(transactionConflicts map[*iotago.Transaction][]string, nodes ...*mock.Node) {
Expand Down

0 comments on commit 4c26ea7

Please sign in to comment.