Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public OutPoint[] GetIdsToFetch(Block block, bool enforceBIP30)
{
if (enforceBIP30)
{
// Calculate the hash outside the loop.
var txId = tx.GetHash();
foreach (var utxo in tx.Outputs.AsIndexedOutputs())
ids.Add(utxo.ToOutPoint());
ids.Add(new OutPoint() { Hash = txId, N = utxo.N });
}

if (!tx.IsCoinBase)
Expand Down
7 changes: 5 additions & 2 deletions src/Stratis.Bitcoin.Features.Consensus/UnspentOutputSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public void Update(Network network, Transaction transaction, int height)
}
}

foreach (IndexedTxOut output in transaction.Outputs.AsIndexedOutputs())
// Hash calculations are slow. Do this one outside the loop...
var txHash = transaction.GetHash();

foreach (IndexedTxOut output in transaction.Outputs.AsIndexedOutputs().ToList())
{
var outpoint = output.ToOutPoint();
var outpoint = new OutPoint() { Hash = txHash, N = output.N };
var coinbase = transaction.IsCoinBase;
var coinstake = network.Consensus.IsProofOfStake ? transaction.IsCoinStake : false;

Expand Down