Commit 20b11e35 authored by Sergei Zubov's avatar Sergei Zubov

Fix staking with unconfirmed transactions

FundsPreservationRule compares total inputs and outputs in block. If
block contains unconfirmed transactions, their input can't be found in
UTXOs. In that case, inputs are searched in transactions of validating
block.
parent 6cde68e8
......@@ -35,7 +35,7 @@ namespace DeStream.DeStreamD
.UseDeStreamPosConsensus()
.UseDeStreamMempool()
.UseDeStreamWallet()
.AddPowPosMining()
.AddDeStreamPowPosMining()
.UseApi()
.UseApps()
.AddRPC()
......
......@@ -18,9 +18,11 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
(context as UtxoRuleContext ??
throw new NotSupportedException($"Rule context must be {nameof(UtxoRuleContext)}")).UnspentOutputSet;
long totalIn = context.ValidationContext.BlockToValidate.Transactions.SelectMany(p =>
p.Inputs.RemoveChangePointer().Where(q => q.PrevOut != null)
.Select(q => inputs.AccessCoins(q.PrevOut.Hash)?.TryGetOutput(q.PrevOut.N)?.Value ?? 0))
.Sum(p => p ?? 0);
p.Inputs.RemoveChangePointer().Where(q => q.PrevOut != null).Select(q =>
inputs.AccessCoins(q.PrevOut.Hash)?.TryGetOutput(q.PrevOut.N)?.Value ??
context.ValidationContext.BlockToValidate.Transactions
.SingleOrDefault(r => r.GetHash() == q.PrevOut.Hash)?.Outputs[q.PrevOut.N]?.Value ??
throw new ConsensusErrorException(ConsensusErrors.BadTransactionMissingInput))).Sum(p => p ?? 0);
long totalOut = context.ValidationContext.BlockToValidate.Transactions.SelectMany(p => p.Outputs.Select(q => q.Value))
.Sum(p => p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment