From 02fb2f7e96c0a5a640a5f356e37e4c071c1a9412 Mon Sep 17 00:00:00 2001 From: jkrvivian Date: Wed, 8 Nov 2023 21:29:21 +0800 Subject: [PATCH] Hook to TransactionMetadata OnRejected to capture conflicting reason correctly --- pkg/retainer/retainer/retainer.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/retainer/retainer/retainer.go b/pkg/retainer/retainer/retainer.go index ebd061047..8e110c82b 100644 --- a/pkg/retainer/retainer/retainer.go +++ b/pkg/retainer/retainer/retainer.go @@ -87,14 +87,6 @@ func NewProvider() module.Provider[*engine.Engine, retainer.Retainer] { r.RetainBlockFailure(b.ID(), apimodels.BlockFailureDroppedDueToCongestion) }) - e.Events.SpendDAG.SpendRejected.Hook(func(spendID iotago.TransactionID) { - txMetadata, exist := e.Ledger.MemPool().TransactionMetadata(spendID) - if !exist { - return - } - r.RetainTransactionFailure(txMetadata.EarliestIncludedAttachment(), iotago.ErrTxConflicting) - }, asyncOpt) - e.HookInitialized(func() { e.Ledger.MemPool().OnSignedTransactionAttached(func(signedTransactionMetadata mempool.SignedTransactionMetadata) { attachment := signedTransactionMetadata.Attachments()[0] @@ -116,6 +108,10 @@ func NewProvider() module.Provider[*engine.Engine, retainer.Retainer] { r.RetainTransactionFailure(attachment, err) }) + transactionMetadata.OnRejected(func() { + r.RetainTransactionFailure(attachment, iotago.ErrTxConflicting) + }) + transactionMetadata.OnAccepted(func() { attachmentID := transactionMetadata.EarliestIncludedAttachment() if slot := attachmentID.Slot(); slot > 0 {