From 6f62622183e4ceb8c596550c1cf9a88e489c0e66 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:04:51 +0200 Subject: [PATCH 01/10] Fix: Memleak in mempool --- .../engine/mempool/v1/state_metadata.go | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/protocol/engine/mempool/v1/state_metadata.go b/pkg/protocol/engine/mempool/v1/state_metadata.go index f275afe43..16c1d57a4 100644 --- a/pkg/protocol/engine/mempool/v1/state_metadata.go +++ b/pkg/protocol/engine/mempool/v1/state_metadata.go @@ -31,8 +31,7 @@ type StateMetadata struct { func NewStateMetadata(state mempool.State, optSource ...*TransactionMetadata) *StateMetadata { return (&StateMetadata{ - state: state, - source: lo.First(optSource), + state: state, spent: promise.NewEvent(), doubleSpent: promise.NewEvent(), @@ -51,11 +50,15 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata if len(optSource) == 0 { return s } - source := optSource[0] - s.spenderIDs.InheritFrom(source.spenderIDs) + s.source = optSource[0] + s.source.evicted.OnTrigger(func() { + s.source = nil + }) + + s.spenderIDs.InheritFrom(s.source.spenderIDs) - source.earliestIncludedValidAttachment.OnUpdate(func(_, newValue iotago.BlockID) { + s.source.earliestIncludedValidAttachment.OnUpdate(func(_, newValue iotago.BlockID) { s.inclusionSlot.Compute(func(currentValue *iotago.SlotIndex) *iotago.SlotIndex { if newSlot := newValue.Slot(); currentValue == nil || newSlot < *currentValue { return &newSlot @@ -65,10 +68,10 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata }) }) - source.OnAccepted(func() { s.accepted.Set(true) }) - source.OnRejected(func() { s.rejected.Trigger() }) - source.OnCommittedSlotUpdated(lo.Void(s.committedSlot.Set)) - source.OnOrphanedSlotUpdated(lo.Void(s.orphanedSlot.Set)) + s.source.OnAccepted(func() { s.accepted.Set(true) }) + s.source.OnRejected(func() { s.rejected.Trigger() }) + s.source.OnCommittedSlotUpdated(lo.Void(s.committedSlot.Set)) + s.source.OnOrphanedSlotUpdated(lo.Void(s.orphanedSlot.Set)) return s } From 98d26894f775cc3228a996668b015fa7d3aba8a2 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:47:08 +0200 Subject: [PATCH 02/10] Remove signed transaction metadata field from the block --- pkg/protocol/engine/blocks/block.go | 4 ---- .../engine/booker/inmemorybooker/booker.go | 20 ++++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/protocol/engine/blocks/block.go b/pkg/protocol/engine/blocks/block.go index e27463b59..acbd6bf7d 100644 --- a/pkg/protocol/engine/blocks/block.go +++ b/pkg/protocol/engine/blocks/block.go @@ -23,9 +23,6 @@ type Block struct { // PayloadDependenciesAvailable is triggered when the dependencies of the block's payload are available. PayloadDependenciesAvailable reactive.Event - // SignedTransactionMetadata contains the signed transaction metadata of the block. - SignedTransactionMetadata reactive.Variable[mempool.SignedTransactionMetadata] - // BlockDAG block missing bool missingBlockID iotago.BlockID @@ -89,7 +86,6 @@ func newEmptyBlock() *Block { return &Block{ ParentsBooked: reactive.NewEvent(), PayloadDependenciesAvailable: reactive.NewEvent(), - SignedTransactionMetadata: reactive.NewVariable[mempool.SignedTransactionMetadata](), witnesses: ds.NewSet[account.SeatIndex](), spenderIDs: ds.NewSet[iotago.TransactionID](), diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 042f5b751..6e8a554e8 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -97,13 +97,12 @@ func (b *Booker) Init(ledger ledger.Ledger, loadBlockFromStorage func(iotago.Blo func (b *Booker) Queue(block *blocks.Block) error { signedTransactionMetadata, containsTransaction := b.ledger.AttachTransaction(block) if !containsTransaction { - b.setupBlock(block) + b.setupBlock(block, nil) return nil } else if signedTransactionMetadata == nil { return ierrors.Errorf("transaction in block %s was not attached", block.ID()) } - block.SignedTransactionMetadata.Set(signedTransactionMetadata) // Based on the assumption that we always fork and the UTXO and Tangle past cones are always fully known. signedTransactionMetadata.OnSignaturesValid(func() { @@ -117,16 +116,16 @@ func (b *Booker) Queue(block *blocks.Block) error { transactionMetadata.OnBooked(func() { block.SetPayloadSpenderIDs(transactionMetadata.SpenderIDs()) - b.setupBlock(block) + b.setupBlock(block, signedTransactionMetadata) }) transactionMetadata.OnInvalid(func(_ error) { - b.setupBlock(block) + b.setupBlock(block, signedTransactionMetadata) }) }) signedTransactionMetadata.OnSignaturesInvalid(func(_ error) { - b.setupBlock(block) + b.setupBlock(block, signedTransactionMetadata) }) return nil @@ -135,9 +134,10 @@ func (b *Booker) Queue(block *blocks.Block) error { // Reset resets the component to a clean state as if it was created at the last commitment. func (b *Booker) Reset() { /* nothing to reset but comply with interface */ } -func (b *Booker) setupBlock(block *blocks.Block) { +func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempool.SignedTransactionMetadata) { var payloadDependencies, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] - if signedTransactionMetadata := block.SignedTransactionMetadata.Get(); signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { + + if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { payloadDependencies = signedTransactionMetadata.TransactionMetadata().Inputs() directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() } @@ -155,8 +155,10 @@ func (b *Booker) setupBlock(block *blocks.Block) { parentBlock.Booked().OnUpdateOnce(func(_ bool, _ bool) { if directlyReferencedPayloadDependencies != nil { - if parentTransactionMetadata := parentBlock.SignedTransactionMetadata.Get(); parentTransactionMetadata != nil { - directlyReferencedPayloadDependencies.AddAll(parentTransactionMetadata.TransactionMetadata().Outputs()) + if signedTx, hasTx := parentBlock.SignedTransaction(); hasTx { + if parentTransactionMetadata, exists := b.ledger.TransactionMetadata(signedTx.Transaction.MustID()); exists { + directlyReferencedPayloadDependencies.AddAll(parentTransactionMetadata.Outputs()) + } } } From 5f0784e0e2d5162ac0e9605fcb186fd05a3252b2 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:14:11 +0200 Subject: [PATCH 03/10] Test a theory --- .../engine/booker/inmemorybooker/booker.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 6e8a554e8..50704f629 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -135,10 +135,10 @@ func (b *Booker) Queue(block *blocks.Block) error { func (b *Booker) Reset() { /* nothing to reset but comply with interface */ } func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempool.SignedTransactionMetadata) { - var payloadDependencies, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] + var _, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { - payloadDependencies = signedTransactionMetadata.TransactionMetadata().Inputs() + _ = signedTransactionMetadata.TransactionMetadata().Inputs() directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() } @@ -164,6 +164,7 @@ func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempo if unbookedParentsCount.Add(-1) == 0 { block.ParentsBooked.Trigger() + block.PayloadDependenciesAvailable.Trigger() } }) @@ -174,13 +175,13 @@ func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempo }) }) - block.ParentsBooked.OnTrigger(func() { - if directlyReferencedPayloadDependencies != nil { - payloadDependencies.DeleteAll(directlyReferencedPayloadDependencies) - } - - block.WaitForPayloadDependencies(payloadDependencies) - }) + //block.ParentsBooked.OnTrigger(func() { + // if directlyReferencedPayloadDependencies != nil { + // payloadDependencies.DeleteAll(directlyReferencedPayloadDependencies) + // } + // + // block.WaitForPayloadDependencies(payloadDependencies) + //}) block.PayloadDependenciesAvailable.OnTrigger(func() { if err := b.book(block); err != nil { From 4e412bd6f13e8d57778ac3a4f50c7e1d111bce09 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:45:59 +0200 Subject: [PATCH 04/10] Add debug log --- pkg/protocol/engine/booker/inmemorybooker/booker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 50704f629..f905090fd 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -214,6 +214,9 @@ func (b *Booker) book(block *blocks.Block) error { } block.SetSpenderIDs(spendersToInherit) + + b.LogTrace("spenders to inherit", "spenders count", spendersToInherit.Size()) + block.SetBooked() b.events.BlockBooked.Trigger(block) From 28ab78728fccdb0e1ab1e8d01d951423426fd1b6 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:13:05 +0200 Subject: [PATCH 05/10] Disable more things --- .../engine/booker/inmemorybooker/booker.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index f905090fd..461e83fba 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -135,12 +135,12 @@ func (b *Booker) Queue(block *blocks.Block) error { func (b *Booker) Reset() { /* nothing to reset but comply with interface */ } func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempool.SignedTransactionMetadata) { - var _, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] + //var _, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] - if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { - _ = signedTransactionMetadata.TransactionMetadata().Inputs() - directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() - } + //if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { + // _ = signedTransactionMetadata.TransactionMetadata().Inputs() + // directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() + //} var unbookedParentsCount atomic.Int32 unbookedParentsCount.Store(int32(len(block.Parents()))) @@ -154,13 +154,13 @@ func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempo } parentBlock.Booked().OnUpdateOnce(func(_ bool, _ bool) { - if directlyReferencedPayloadDependencies != nil { - if signedTx, hasTx := parentBlock.SignedTransaction(); hasTx { - if parentTransactionMetadata, exists := b.ledger.TransactionMetadata(signedTx.Transaction.MustID()); exists { - directlyReferencedPayloadDependencies.AddAll(parentTransactionMetadata.Outputs()) - } - } - } + //if directlyReferencedPayloadDependencies != nil { + // if signedTx, hasTx := parentBlock.SignedTransaction(); hasTx { + // if parentTransactionMetadata, exists := b.ledger.TransactionMetadata(signedTx.Transaction.MustID()); exists { + // directlyReferencedPayloadDependencies.AddAll(parentTransactionMetadata.Outputs()) + // } + // } + //} if unbookedParentsCount.Add(-1) == 0 { block.ParentsBooked.Trigger() From 2f3e2beb782c10cc728f2b9fda015da4e28dc682 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:28:18 +0200 Subject: [PATCH 06/10] Revert "Disable more things" This reverts commit 28ab78728fccdb0e1ab1e8d01d951423426fd1b6. --- .../engine/booker/inmemorybooker/booker.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 461e83fba..f905090fd 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -135,12 +135,12 @@ func (b *Booker) Queue(block *blocks.Block) error { func (b *Booker) Reset() { /* nothing to reset but comply with interface */ } func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempool.SignedTransactionMetadata) { - //var _, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] + var _, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] - //if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { - // _ = signedTransactionMetadata.TransactionMetadata().Inputs() - // directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() - //} + if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { + _ = signedTransactionMetadata.TransactionMetadata().Inputs() + directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() + } var unbookedParentsCount atomic.Int32 unbookedParentsCount.Store(int32(len(block.Parents()))) @@ -154,13 +154,13 @@ func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempo } parentBlock.Booked().OnUpdateOnce(func(_ bool, _ bool) { - //if directlyReferencedPayloadDependencies != nil { - // if signedTx, hasTx := parentBlock.SignedTransaction(); hasTx { - // if parentTransactionMetadata, exists := b.ledger.TransactionMetadata(signedTx.Transaction.MustID()); exists { - // directlyReferencedPayloadDependencies.AddAll(parentTransactionMetadata.Outputs()) - // } - // } - //} + if directlyReferencedPayloadDependencies != nil { + if signedTx, hasTx := parentBlock.SignedTransaction(); hasTx { + if parentTransactionMetadata, exists := b.ledger.TransactionMetadata(signedTx.Transaction.MustID()); exists { + directlyReferencedPayloadDependencies.AddAll(parentTransactionMetadata.Outputs()) + } + } + } if unbookedParentsCount.Add(-1) == 0 { block.ParentsBooked.Trigger() From abb156c1193198d4dc99954e9c3e1c71cd3d7c57 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:28:19 +0200 Subject: [PATCH 07/10] Revert "Add debug log" This reverts commit 4e412bd6f13e8d57778ac3a4f50c7e1d111bce09. --- pkg/protocol/engine/booker/inmemorybooker/booker.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index f905090fd..50704f629 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -214,9 +214,6 @@ func (b *Booker) book(block *blocks.Block) error { } block.SetSpenderIDs(spendersToInherit) - - b.LogTrace("spenders to inherit", "spenders count", spendersToInherit.Size()) - block.SetBooked() b.events.BlockBooked.Trigger(block) From e2eb24caf0d6fa22c394a61d588223f5770b19b7 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:28:19 +0200 Subject: [PATCH 08/10] Revert "Test a theory" This reverts commit 5f0784e0e2d5162ac0e9605fcb186fd05a3252b2. --- .../engine/booker/inmemorybooker/booker.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 50704f629..6e8a554e8 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -135,10 +135,10 @@ func (b *Booker) Queue(block *blocks.Block) error { func (b *Booker) Reset() { /* nothing to reset but comply with interface */ } func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempool.SignedTransactionMetadata) { - var _, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] + var payloadDependencies, directlyReferencedPayloadDependencies ds.Set[mempool.StateMetadata] if signedTransactionMetadata != nil && signedTransactionMetadata.SignaturesInvalid() == nil && !signedTransactionMetadata.TransactionMetadata().IsInvalid() { - _ = signedTransactionMetadata.TransactionMetadata().Inputs() + payloadDependencies = signedTransactionMetadata.TransactionMetadata().Inputs() directlyReferencedPayloadDependencies = ds.NewSet[mempool.StateMetadata]() } @@ -164,7 +164,6 @@ func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempo if unbookedParentsCount.Add(-1) == 0 { block.ParentsBooked.Trigger() - block.PayloadDependenciesAvailable.Trigger() } }) @@ -175,13 +174,13 @@ func (b *Booker) setupBlock(block *blocks.Block, signedTransactionMetadata mempo }) }) - //block.ParentsBooked.OnTrigger(func() { - // if directlyReferencedPayloadDependencies != nil { - // payloadDependencies.DeleteAll(directlyReferencedPayloadDependencies) - // } - // - // block.WaitForPayloadDependencies(payloadDependencies) - //}) + block.ParentsBooked.OnTrigger(func() { + if directlyReferencedPayloadDependencies != nil { + payloadDependencies.DeleteAll(directlyReferencedPayloadDependencies) + } + + block.WaitForPayloadDependencies(payloadDependencies) + }) block.PayloadDependenciesAvailable.OnTrigger(func() { if err := b.book(block); err != nil { From ab053d6002fdbc361507b53c72634d581d0bdaa1 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:39:00 +0200 Subject: [PATCH 09/10] Call unhook for all evicted elements in SpendDAG. --- .../engine/mempool/spenddag/spenddagv1/spenddag.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/protocol/engine/mempool/spenddag/spenddagv1/spenddag.go b/pkg/protocol/engine/mempool/spenddag/spenddagv1/spenddag.go index ee42e7989..47e93973b 100644 --- a/pkg/protocol/engine/mempool/spenddag/spenddagv1/spenddag.go +++ b/pkg/protocol/engine/mempool/spenddag/spenddagv1/spenddag.go @@ -412,13 +412,12 @@ func (c *SpendDAG[SpenderID, ResourceID, VoteRank]) evictSpender(spenderID Spend // remove the spenders from the spenddag dictionary for _, evictedSpenderID := range evictedSpenderIDs { c.spendersByID.Delete(evictedSpenderID) - } - - // unhook the spend events and remove the unhook method from the storage - unhookFunc, unhookExists := c.spendUnhooks.Get(spenderID) - if unhookExists { - unhookFunc() - c.spendUnhooks.Delete(spenderID) + // unhook the spend events and remove the unhook method from the storage + unhookFunc, unhookExists := c.spendUnhooks.Get(spenderID) + if unhookExists { + unhookFunc() + c.spendUnhooks.Delete(spenderID) + } } return evictedSpenderIDs From 83d895c8ba0519e63512a7075d0903b102b99597 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Fri, 19 Apr 2024 03:04:53 +0200 Subject: [PATCH 10/10] Refactor: removed unused code --- pkg/protocol/engine/mempool/state_metadata.go | 2 -- .../engine/mempool/v1/state_metadata.go | 29 +++++-------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/pkg/protocol/engine/mempool/state_metadata.go b/pkg/protocol/engine/mempool/state_metadata.go index dd41cb473..8cda596b2 100644 --- a/pkg/protocol/engine/mempool/state_metadata.go +++ b/pkg/protocol/engine/mempool/state_metadata.go @@ -6,8 +6,6 @@ import ( ) type StateMetadata interface { - CreatingTransaction() TransactionMetadata - State() State SpenderIDs() reactive.Set[iotago.TransactionID] diff --git a/pkg/protocol/engine/mempool/v1/state_metadata.go b/pkg/protocol/engine/mempool/v1/state_metadata.go index 16c1d57a4..9400ed9bb 100644 --- a/pkg/protocol/engine/mempool/v1/state_metadata.go +++ b/pkg/protocol/engine/mempool/v1/state_metadata.go @@ -12,8 +12,7 @@ import ( ) type StateMetadata struct { - state mempool.State - source *TransactionMetadata + state mempool.State // lifecycle spenderCount uint64 @@ -50,15 +49,11 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata if len(optSource) == 0 { return s } + source := optSource[0] - s.source = optSource[0] - s.source.evicted.OnTrigger(func() { - s.source = nil - }) - - s.spenderIDs.InheritFrom(s.source.spenderIDs) + s.spenderIDs.InheritFrom(source.spenderIDs) - s.source.earliestIncludedValidAttachment.OnUpdate(func(_, newValue iotago.BlockID) { + source.earliestIncludedValidAttachment.OnUpdate(func(_, newValue iotago.BlockID) { s.inclusionSlot.Compute(func(currentValue *iotago.SlotIndex) *iotago.SlotIndex { if newSlot := newValue.Slot(); currentValue == nil || newSlot < *currentValue { return &newSlot @@ -68,22 +63,14 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata }) }) - s.source.OnAccepted(func() { s.accepted.Set(true) }) - s.source.OnRejected(func() { s.rejected.Trigger() }) - s.source.OnCommittedSlotUpdated(lo.Void(s.committedSlot.Set)) - s.source.OnOrphanedSlotUpdated(lo.Void(s.orphanedSlot.Set)) + source.OnAccepted(func() { s.accepted.Set(true) }) + source.OnRejected(func() { s.rejected.Trigger() }) + source.OnCommittedSlotUpdated(lo.Void(s.committedSlot.Set)) + source.OnOrphanedSlotUpdated(lo.Void(s.orphanedSlot.Set)) return s } -func (s *StateMetadata) CreatingTransaction() mempool.TransactionMetadata { - if s.source == nil { - return nil - } - - return s.source -} - func (s *StateMetadata) State() mempool.State { return s.state }