This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FS] Input consolidation when too many inputs at once. (#3705)
* Input consolidation step 1 * Test for our specific issue * Add comments to input-consolidator * Extra comment * Stage 2 * Add feature registration * ConsolidatingTransaction * More skeleton * Skeleton adjustment * fullySigned * Technically completed, now to test. * Remove 1 subscription * 1 Test * 1 Solid test * 1 InputConsolidator test * One more working test * Add logging * Ready for review * Fixed one test * All tests passing * Importat missing line * Special validation for consolidation transactions otherwise they won't pass validation * Fees wrong way round * Documentation * try catch * Fix to broadcast if we call again * Slight documentation fix * Fix test * Consolidate Input Console Display * Push gross fix * Time * Small changes * Debugging lines * Attempt to see what's failing * another try catch * Even more logging * Checking for deadlock * Use events to remove deadlock * Remove more error checks * Actually async * fee change * Cleaning up * skeleton moving forward * Namespace fix * Multiple consolidation txs at a time * Append -> AppendLine * Last number for performance * Performance * Use partial transaction requester for consolidation transactions too * Consolidation transactions one at a time. * Changes based on feedback * Changes as requested * Task.Run around blocking lock * Get benefit of transactionbuilder PR * Changes based on feedback * Fix async parts * Wasn't returning where it should be * Fix time for PoS networks * Changes as requested * Changes as requested * CheckTemplateAndSign * Introduce lock for task * Updating documentation
- Loading branch information
1 parent
65667f5
commit d9702be
Showing
29 changed files
with
1,088 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Stratis.Features.FederatedPeg.Tests/InputConsolidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.Collections.Generic; | ||
using Moq; | ||
using NBitcoin; | ||
using Stratis.Bitcoin.Configuration; | ||
using Stratis.Bitcoin.Features.Wallet.Interfaces; | ||
using Stratis.Bitcoin.Tests.Common; | ||
using Stratis.Features.FederatedPeg.InputConsolidation; | ||
using Xunit; | ||
|
||
namespace Stratis.Features.FederatedPeg.Tests | ||
{ | ||
public class InputConsolidatorTests : CrossChainTestBase | ||
{ | ||
[Fact] | ||
public void ConsolidationTransactionOnlyBuiltWhenWalletHasManyInputs() | ||
{ | ||
var dataFolder = new DataFolder(TestBase.CreateTestDir(this)); | ||
|
||
this.Init(dataFolder); | ||
|
||
var broadcasterManager = new Mock<IBroadcasterManager>(); | ||
|
||
var inputConsolidator = new InputConsolidator( | ||
this.FederationWalletTransactionHandler, | ||
this.federationWalletManager, | ||
broadcasterManager.Object, | ||
this.federatedPegSettings, | ||
this.loggerFactory, | ||
this.signals, | ||
this.asyncProvider, | ||
this.network); | ||
|
||
Assert.Null(inputConsolidator.CreateRequiredConsolidationTransactions(Money.Coins(100m))); | ||
} | ||
|
||
[Fact] | ||
public void ConsolidationTransactionBuildsCorrectly() | ||
{ | ||
var dataFolder = new DataFolder(TestBase.CreateTestDir(this)); | ||
|
||
this.Init(dataFolder); | ||
|
||
var broadcasterManager = new Mock<IBroadcasterManager>(); | ||
|
||
var inputConsolidator = new InputConsolidator( | ||
this.FederationWalletTransactionHandler, | ||
this.federationWalletManager, | ||
broadcasterManager.Object, | ||
this.federatedPegSettings, | ||
this.loggerFactory, | ||
this.signals, | ||
this.asyncProvider, | ||
this.network); | ||
|
||
// Lets set the funding transactions to many really small outputs | ||
const int numUtxos = FederatedPegSettings.MaxInputs * 2; | ||
const decimal individualAmount = 0.1m; | ||
const decimal depositAmount = numUtxos * individualAmount - 1; // Large amount minus some for fees. | ||
BitcoinAddress address = new Script("").Hash.GetAddress(this.network); | ||
|
||
this.wallet.MultiSigAddress.Transactions.Clear(); | ||
this.fundingTransactions.Clear(); | ||
|
||
Money[] funding = new Money[numUtxos]; | ||
|
||
for (int i = 0; i < funding.Length; i++) | ||
{ | ||
funding[i] = new Money(individualAmount, MoneyUnit.BTC); | ||
} | ||
|
||
this.AddFundingTransaction(funding); | ||
|
||
List<ConsolidationTransaction> transactions = inputConsolidator.CreateRequiredConsolidationTransactions(Money.Coins(depositAmount)); | ||
|
||
Assert.Equal(2, transactions.Count); | ||
Assert.Equal(this.federatedPegSettings.MultiSigAddress.ScriptPubKey, transactions[0].PartialTransaction.Outputs[0].ScriptPubKey); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Stratis.Features.FederatedPeg/Events/WalletNeedsConsolidation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using NBitcoin; | ||
using Stratis.Bitcoin.EventBus; | ||
|
||
namespace Stratis.Features.FederatedPeg.Events | ||
{ | ||
public class WalletNeedsConsolidation : EventBase | ||
{ | ||
/// <summary> | ||
/// The amount required for the next withdrawal transaction.. | ||
/// </summary> | ||
public Money Amount { get; } | ||
|
||
public WalletNeedsConsolidation(Money amount) | ||
{ | ||
this.Amount = amount; | ||
} | ||
} | ||
} |
Oops, something went wrong.