diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 9f1b62066..8b360baf6 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -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 @@ -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) } diff --git a/pkg/protocol/engine/mempool/tests/tests.go b/pkg/protocol/engine/mempool/tests/tests.go index 22a074d34..c14fdd591 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -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})) } @@ -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()) @@ -312,9 +312,9 @@ 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")))) @@ -322,9 +322,9 @@ func TestSetTxOrphanageMultipleAttachments(t *testing.T, tf *TestFramework) { 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")))) diff --git a/pkg/protocol/engine/mempool/transaction_metadata.go b/pkg/protocol/engine/mempool/transaction_metadata.go index 6fb9f5d09..e594a7d5a 100644 --- a/pkg/protocol/engine/mempool/transaction_metadata.go +++ b/pkg/protocol/engine/mempool/transaction_metadata.go @@ -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)) } diff --git a/pkg/protocol/engine/mempool/v1/inclusion_flags.go b/pkg/protocol/engine/mempool/v1/inclusion_flags.go index 22352fa74..ce4225556 100644 --- a/pkg/protocol/engine/mempool/v1/inclusion_flags.go +++ b/pkg/protocol/engine/mempool/v1/inclusion_flags.go @@ -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) }) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index 84870661d..2345b4707 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -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()) }) } @@ -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) diff --git a/pkg/protocol/engine/mempool/v1/state_metadata.go b/pkg/protocol/engine/mempool/v1/state_metadata.go index 23d3c6729..a5933f284 100644 --- a/pkg/protocol/engine/mempool/v1/state_metadata.go +++ b/pkg/protocol/engine/mempool/v1/state_metadata.go @@ -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 } @@ -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() }) } diff --git a/pkg/protocol/engine/mempool/v1/transaction_metadata.go b/pkg/protocol/engine/mempool/v1/transaction_metadata.go index 1183e3223..01348df86 100644 --- a/pkg/protocol/engine/mempool/v1/transaction_metadata.go +++ b/pkg/protocol/engine/mempool/v1/transaction_metadata.go @@ -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() { @@ -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) }) } @@ -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) } }) diff --git a/pkg/testsuite/mock/node.go b/pkg/testsuite/mock/node.go index 11b3abf9b..3d62cb05c 100644 --- a/pkg/testsuite/mock/node.go +++ b/pkg/testsuite/mock/node.go @@ -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() { diff --git a/pkg/testsuite/transactions.go b/pkg/testsuite/transactions.go index 3b2b3e2c5..65cedd452 100644 --- a/pkg/testsuite/transactions.go +++ b/pkg/testsuite/transactions.go @@ -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) {