Make sure we match the user's sequence

This commit is contained in:
nicolas.dorier 2020-05-05 04:44:55 +09:00
parent 59bdb943dd
commit dad2642fa7
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
2 changed files with 9 additions and 2 deletions

View File

@ -392,6 +392,7 @@ namespace BTCPayServer.Tests
lastInvoiceId = invoice.Id;
var invoiceAddress = BitcoinAddress.Create(invoice.BitcoinAddress, cashCow.Network);
var txBuilder = network.NBitcoinNetwork.CreateTransactionBuilder();
txBuilder.OptInRBF = true;
txBuilder.AddCoins(coin);
txBuilder.Send(invoiceAddress, vector.Paid);
txBuilder.SendFees(vector.Fee);
@ -402,6 +403,10 @@ namespace BTCPayServer.Tests
if (vector.ExpectedError is null)
{
Assert.Contains(pj.Inputs, o => o.PrevOut == receiverCoin.Outpoint);
foreach (var input in pj.GetGlobalTransaction().Inputs)
{
Assert.Equal(Sequence.OptInRBF, input.Sequence);
}
if (!skipLockedCheck)
Assert.True(await payjoinRepository.TryUnlock(receiverCoin.Outpoint));
}

View File

@ -331,10 +331,13 @@ namespace BTCPayServer.Payments.PayJoin
var ourNewOutput = newTx.Outputs[originalPaymentOutput.Index];
HashSet<TxOut> isOurOutput = new HashSet<TxOut>();
isOurOutput.Add(ourNewOutput);
var rand = new Random();
int senderInputCount = newTx.Inputs.Count;
foreach (var selectedUTXO in selectedUTXOs.Select(o => o.Value))
{
contributedAmount += (Money)selectedUTXO.Value;
newTx.Inputs.Add(selectedUTXO.Outpoint);
var newInput = newTx.Inputs.Add(selectedUTXO.Outpoint);
newInput.Sequence = newTx.Inputs[rand.Next(0, senderInputCount)].Sequence;
}
ourNewOutput.Value += contributedAmount;
var minRelayTxFee = this._dashboard.Get(network.CryptoCode).Status.BitcoinStatus?.MinRelayTxFee ??
@ -376,7 +379,6 @@ namespace BTCPayServer.Payments.PayJoin
}
}
var rand = new Random();
Utils.Shuffle(newTx.Inputs, rand);
Utils.Shuffle(newTx.Outputs, rand);