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

Commit

Permalink
Merge branch 'develop' into fix/commitment-naming
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrm50 committed Mar 19, 2024
2 parents f8c49e0 + e8621d2 commit 361a0a0
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 102 deletions.
8 changes: 0 additions & 8 deletions pkg/protocol/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ func attachEngineLogs(instance *engine.Engine) func() {
instance.LogTrace("MemPool.TransactionBooked", "tx", transactionMetadata.ID())
})

transactionMetadata.OnConflicting(func() {
instance.LogTrace("MemPool.TransactionConflicting", "tx", transactionMetadata.ID())
})

transactionMetadata.OnAccepted(func() {
instance.LogTrace("MemPool.TransactionAccepted", "tx", transactionMetadata.ID())
})
Expand All @@ -275,10 +271,6 @@ func attachEngineLogs(instance *engine.Engine) func() {
instance.LogTrace("MemPool.TransactionCommittedSlotUpdated", "tx", transactionMetadata.ID(), "slot", slot)
})

transactionMetadata.OnPending(func() {
instance.LogTrace("MemPool.TransactionPending", "tx", transactionMetadata.ID())
})

transactionMetadata.OnEvicted(func() {
instance.LogTrace("MemPool.TransactionEvicted", "tx", transactionMetadata.ID())
})
Expand Down
18 changes: 0 additions & 18 deletions pkg/protocol/engine/mempool/tests/testframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,24 +303,6 @@ func (t *TestFramework) setupHookedEvents() {

require.True(t.test, metadata.IsAccepted(), "transaction is not marked as accepted")
})

metadata.OnPending(func() {
if debug.GetEnabled() {
t.test.Logf("[TRIGGERED] mempool.Events.TransactionPending with '%s'", metadata.ID())
}

require.True(t.test, metadata.IsPending(), "transaction is not marked as pending")
})

metadata.OnPending(func() {
// if debug.GetEnabled() {
// t.test.Logf("[TRIGGERED] mempool.Events.TransactionAccepted with '%s'", metadata.ID())
// }
//
// require.False(t.test, metadata.IsAccepted(), "transaction is not marked as pending")
//
// t.markTransactionAcceptedTriggered(metadata.ID(), true)
})
})
}

Expand Down
6 changes: 0 additions & 6 deletions pkg/protocol/engine/mempool/transaction_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ type TransactionMetadata interface {

OnBooked(func())

IsConflicting() bool

OnConflicting(func())

ValidAttachments() []iotago.BlockID

EarliestIncludedAttachment() iotago.BlockID
Expand All @@ -53,8 +49,6 @@ type TransactionMetadata interface {
type inclusionFlags interface {
IsPending() bool

OnPending(callback func())

IsAccepted() bool

OnAccepted(callback func())
Expand Down
9 changes: 0 additions & 9 deletions pkg/protocol/engine/mempool/v1/inclusion_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ func (s *inclusionFlags) OnAccepted(callback func()) {
})
}

// OnPending registers a callback that gets triggered when the entity gets pending.
func (s *inclusionFlags) OnPending(callback func()) {
s.accepted.OnUpdate(func(wasAccepted bool, isAccepted bool) {
if !isAccepted && wasAccepted {
callback()
}
})
}

// IsRejected returns true if the entity was rejected.
func (s *inclusionFlags) IsRejected() bool {
return s.rejected.WasTriggered()
Expand Down
36 changes: 17 additions & 19 deletions pkg/protocol/engine/mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,21 @@ func (m *MemPool[VoteRank]) bookTransaction(transaction *TransactionMetadata) {
}

func (m *MemPool[VoteRank]) forkTransaction(transactionMetadata *TransactionMetadata, resourceIDs ds.Set[mempool.StateID]) {
transactionMetadata.conflicting.Trigger()
m.spendDAG.CreateSpender(transactionMetadata.ID())

unsubscribe := transactionMetadata.parentSpenderIDs.OnUpdate(func(appliedMutations ds.SetMutations[iotago.TransactionID]) {
if err := m.spendDAG.UpdateSpenderParents(transactionMetadata.ID(), appliedMutations.AddedElements(), appliedMutations.DeletedElements()); err != nil {
panic(err)
}
})

transactionMetadata.OnEvicted(func() {
unsubscribe()

m.spendDAG.EvictSpender(transactionMetadata.ID())
})

transactionMetadata.spenderIDs.Replace(ds.NewSet(transactionMetadata.id))

if err := m.spendDAG.UpdateSpentResources(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.
Expand Down Expand Up @@ -522,7 +536,7 @@ func (m *MemPool[VoteRank]) updateStateDiffs(transaction *TransactionMetadata, p
return ierrors.Wrapf(err, "failed to get state diff for slot %d", newIndex)
}

if err = stateDiff.AddTransaction(transaction, m.errorHandler); err != nil {
if err = stateDiff.AddTransaction(transaction); err != nil {
return ierrors.Wrapf(err, "failed to add transaction to state diff, txID: %s", transaction.ID())
}
}
Expand Down Expand Up @@ -552,28 +566,12 @@ func (m *MemPool[VoteRank]) setupTransaction(transaction *TransactionMetadata) {
return
}

if err := stateDiff.AddTransaction(transaction, m.errorHandler); err != nil {
if err := stateDiff.AddTransaction(transaction); err != nil {
m.errorHandler(ierrors.Wrapf(err, "failed to add transaction to state diff, txID: %s", transaction.ID()))
}
}
})

transaction.OnConflicting(func() {
m.spendDAG.CreateSpender(transaction.ID())

unsubscribe := transaction.parentSpenderIDs.OnUpdate(func(appliedMutations ds.SetMutations[iotago.TransactionID]) {
if err := m.spendDAG.UpdateSpenderParents(transaction.ID(), appliedMutations.AddedElements(), appliedMutations.DeletedElements()); err != nil {
panic(err)
}
})

transaction.OnEvicted(func() {
unsubscribe()

m.spendDAG.EvictSpender(transaction.ID())
})
})

transaction.OnEarliestIncludedAttachmentUpdated(func(prevBlock iotago.BlockID, newBlock iotago.BlockID) {
if err := m.updateStateDiffs(transaction, prevBlock.Slot(), newBlock.Slot()); err != nil {
m.errorHandler(ierrors.Wrap(err, "failed to update state diffs"))
Expand Down
8 changes: 1 addition & 7 deletions pkg/protocol/engine/mempool/v1/state_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,12 @@ func (s *StateDiff) updateCompactedStateChanges(transaction *TransactionMetadata
}
}

func (s *StateDiff) AddTransaction(transaction *TransactionMetadata, errorHandler func(error)) error {
func (s *StateDiff) AddTransaction(transaction *TransactionMetadata) error {
if _, exists := s.executedTransactions.Set(transaction.ID(), transaction); !exists {
if err := s.mutations.Add(transaction.ID()); err != nil {
return ierrors.Wrapf(err, "failed to add transaction to state diff, txID: %s", transaction.ID())
}
s.updateCompactedStateChanges(transaction, 1)

transaction.OnPending(func() {
if err := s.RollbackTransaction(transaction); err != nil {
errorHandler(ierrors.Wrapf(err, "failed to rollback transaction, txID: %s", transaction.ID()))
}
})
}

return nil
Expand Down
7 changes: 0 additions & 7 deletions pkg/protocol/engine/mempool/v1/state_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata

s.spenderIDs.InheritFrom(source.spenderIDs)

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.committedSlot.Set))
Expand Down Expand Up @@ -137,12 +136,6 @@ func (s *StateMetadata) setupSpender(spender *TransactionMetadata) {
}
})

spender.OnPending(func() {
if !s.state.IsReadOnly() {
s.spendAccepted.Set(nil)
}
})

spender.OnCommittedSlotUpdated(func(_ iotago.SlotIndex) {
if !s.state.IsReadOnly() {
s.spendCommitted.Set(spender)
Expand Down
24 changes: 0 additions & 24 deletions pkg/protocol/engine/mempool/v1/transaction_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type TransactionMetadata struct {
// predecessors for acceptance
unacceptedInputsCount uint64
allInputsAccepted reactive.Variable[bool]
conflicting reactive.Event
conflictAccepted reactive.Event

// attachments
Expand Down Expand Up @@ -78,7 +77,6 @@ func NewTransactionMetadata(transaction mempool.Transaction, referencedInputs []

unacceptedInputsCount: uint64(len(referencedInputs)),
allInputsAccepted: reactive.NewVariable[bool](),
conflicting: reactive.NewEvent(),
conflictAccepted: reactive.NewEvent(),

signingTransactions: reactive.NewSet[*SignedTransactionMetadata](),
Expand Down Expand Up @@ -214,14 +212,6 @@ func (t *TransactionMetadata) Commit() {
t.committedSlot.Set(t.earliestIncludedValidAttachment.Get().Slot())
}

func (t *TransactionMetadata) IsConflicting() bool {
return t.conflicting.WasTriggered()
}

func (t *TransactionMetadata) OnConflicting(callback func()) {
t.conflicting.OnTrigger(callback)
}

func (t *TransactionMetadata) IsConflictAccepted() bool {
return t.conflictAccepted.WasTriggered()
}
Expand Down Expand Up @@ -259,12 +249,6 @@ func (t *TransactionMetadata) setupInput(input *StateMetadata) {
}
})

input.OnPending(func() {
if atomic.AddUint64(&t.unacceptedInputsCount, 1) == 1 && t.allInputsAccepted.Set(false) {
t.accepted.Set(false)
}
})

input.OnAcceptedSpenderUpdated(func(spender mempool.TransactionMetadata) {
//nolint:forcetypeassert // we can be sure that the spender is a TransactionMetadata
if spender.(*TransactionMetadata) != nil && spender != t {
Expand All @@ -282,14 +266,6 @@ func (t *TransactionMetadata) setupInput(input *StateMetadata) {
}

func (t *TransactionMetadata) setup() (self *TransactionMetadata) {
cancelConflictInheritance := t.spenderIDs.InheritFrom(t.parentSpenderIDs)

t.OnConflicting(func() {
cancelConflictInheritance()

t.spenderIDs.Replace(ds.NewSet(t.id))
})

t.allValidAttachmentsEvicted.OnUpdate(func(_ iotago.SlotIndex, slot iotago.SlotIndex) {
if !lo.Return2(t.CommittedSlot()) {
t.orphanedSlot.Set(slot)
Expand Down
4 changes: 0 additions & 4 deletions pkg/testsuite/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ func (t *TestSuite) AssertTransactionsInCacheBooked(expectedTransactions []*iota
t.assertTransactionsInCacheWithFunc(expectedTransactions, expectedFlag, mempool.TransactionMetadata.IsBooked, nodes...)
}

func (t *TestSuite) AssertTransactionsInCacheConflicting(expectedTransactions []*iotago.Transaction, expectedFlag bool, nodes ...*mock.Node) {
t.assertTransactionsInCacheWithFunc(expectedTransactions, expectedFlag, mempool.TransactionMetadata.IsConflicting, nodes...)
}

func (t *TestSuite) AssertTransactionsInCacheInvalid(expectedTransactions []*iotago.Transaction, expectedFlag bool, nodes ...*mock.Node) {
t.assertTransactionsInCacheWithFunc(expectedTransactions, expectedFlag, mempool.TransactionMetadata.IsInvalid, nodes...)
}
Expand Down

0 comments on commit 361a0a0

Please sign in to comment.