From 9e32f15726dc1875a83178c2728850b87910b820 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 27 Mar 2024 11:25:38 +0100 Subject: [PATCH] node: fix TestUnconfirmedParents --- internal/node/transactionpool.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/node/transactionpool.go b/internal/node/transactionpool.go index 51b5f4141..5713c1d12 100644 --- a/internal/node/transactionpool.go +++ b/internal/node/transactionpool.go @@ -2,6 +2,7 @@ package node import ( "errors" + "slices" "go.sia.tech/core/types" "go.sia.tech/renterd/bus" @@ -60,15 +61,22 @@ func unconfirmedParents(txn types.Transaction, pool []types.Transaction) []types } } var parents []types.Transaction + txnsToCheck := []*types.Transaction{&txn} seen := make(map[types.TransactionID]bool) - for _, sci := range txn.SiacoinInputs { - if parent, ok := outputToParent[sci.ParentID]; ok { - if txid := parent.ID(); !seen[txid] { - seen[txid] = true - parents = append(parents, *parent) + for len(txnsToCheck) > 0 { + nextTxn := txnsToCheck[0] + txnsToCheck = txnsToCheck[1:] + for _, sci := range nextTxn.SiacoinInputs { + if parent, ok := outputToParent[sci.ParentID]; ok { + if txid := parent.ID(); !seen[txid] { + seen[txid] = true + parents = append(parents, *parent) + txnsToCheck = append(txnsToCheck, parent) + } } } } + slices.Reverse(parents) return parents }