diff --git a/core/service/mempoolCoreService.go b/core/service/mempoolCoreService.go index d852987ae..38bc8baf1 100644 --- a/core/service/mempoolCoreService.go +++ b/core/service/mempoolCoreService.go @@ -391,7 +391,6 @@ func sortFeePerByteThenTimestampThenID(members []*model.MempoolTransaction) { // PruneMempoolTransactions handle fresh clean the mempool // which is the mempool transaction has been hit expiration time func (mps *MempoolService) DeleteExpiredMempoolTransactions() error { - var ( expirationTime = time.Now().Add(-constant.MempoolExpiration).Unix() selectQ, qStr string @@ -407,26 +406,30 @@ func (mps *MempoolService) DeleteExpiredMempoolTransactions() error { defer rows.Close() mempools = mps.MempoolQuery.BuildModel(mempools, rows) + + err = mps.QueryExecutor.BeginTx() + if err != nil { + return err + } for _, m := range mempools { tx, err := util.ParseTransactionBytes(m.GetTransactionBytes(), true) if err != nil { + _ = mps.QueryExecutor.RollbackTx() return err } action, err := mps.ActionTypeSwitcher.GetTransactionType(tx) if err != nil { + _ = mps.QueryExecutor.RollbackTx() return err } err = action.UndoApplyUnconfirmed() if err != nil { + _ = mps.QueryExecutor.RollbackTx() return err } } qStr = mps.MempoolQuery.DeleteExpiredMempoolTransactions(expirationTime) - err = mps.QueryExecutor.BeginTx() - if err != nil { - return err - } err = mps.QueryExecutor.ExecuteTransaction(qStr) if err != nil { _ = mps.QueryExecutor.RollbackTx() @@ -436,6 +439,5 @@ func (mps *MempoolService) DeleteExpiredMempoolTransactions() error { if err != nil { return err } - return nil }