diff --git a/src/FederationSetup/FederationSetup.csproj b/src/FederationSetup/FederationSetup.csproj index 6b00bb9a07..35b1065233 100644 --- a/src/FederationSetup/FederationSetup.csproj +++ b/src/FederationSetup/FederationSetup.csproj @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. diff --git a/src/FodyNlogAdapter/FodyNlogAdapter.csproj b/src/FodyNlogAdapter/FodyNlogAdapter.csproj index df1ed4756a..97694f5156 100644 --- a/src/FodyNlogAdapter/FodyNlogAdapter.csproj +++ b/src/FodyNlogAdapter/FodyNlogAdapter.csproj @@ -3,7 +3,7 @@ netcoreapp3.1 FodyNlogAdapter - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. Stratis.Utils.FodyNlogAdapter diff --git a/src/Stratis.Bitcoin.Cli/Stratis.Bitcoin.Cli.csproj b/src/Stratis.Bitcoin.Cli/Stratis.Bitcoin.Cli.csproj index 705cb7fafe..2ffd80ad27 100644 --- a/src/Stratis.Bitcoin.Cli/Stratis.Bitcoin.Cli.csproj +++ b/src/Stratis.Bitcoin.Cli/Stratis.Bitcoin.Cli.csproj @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.Api/Stratis.Bitcoin.Features.Api.csproj b/src/Stratis.Bitcoin.Features.Api/Stratis.Bitcoin.Features.Api.csproj index da83363c82..c98a4b91a1 100644 --- a/src/Stratis.Bitcoin.Features.Api/Stratis.Bitcoin.Features.Api.csproj +++ b/src/Stratis.Bitcoin.Features.Api/Stratis.Bitcoin.Features.Api.csproj @@ -6,7 +6,7 @@ Stratis.Bitcoin.Features.Api Library Stratis.Features.Api - 1.3.1.0 + 1.3.2.0 False library diff --git a/src/Stratis.Bitcoin.Features.BlockStore/Stratis.Bitcoin.Features.BlockStore.csproj b/src/Stratis.Bitcoin.Features.BlockStore/Stratis.Bitcoin.Features.BlockStore.csproj index 749a9ecaa9..90639f0330 100644 --- a/src/Stratis.Bitcoin.Features.BlockStore/Stratis.Bitcoin.Features.BlockStore.csproj +++ b/src/Stratis.Bitcoin.Features.BlockStore/Stratis.Bitcoin.Features.BlockStore.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.ColdStaking/Stratis.Bitcoin.Features.ColdStaking.csproj b/src/Stratis.Bitcoin.Features.ColdStaking/Stratis.Bitcoin.Features.ColdStaking.csproj index 0abe03eebf..e4f9b98c5e 100644 --- a/src/Stratis.Bitcoin.Features.ColdStaking/Stratis.Bitcoin.Features.ColdStaking.csproj +++ b/src/Stratis.Bitcoin.Features.ColdStaking/Stratis.Bitcoin.Features.ColdStaking.csproj @@ -7,7 +7,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.Consensus/Stratis.Bitcoin.Features.Consensus.csproj b/src/Stratis.Bitcoin.Features.Consensus/Stratis.Bitcoin.Features.Consensus.csproj index 391c3081d2..6b304aad12 100644 --- a/src/Stratis.Bitcoin.Features.Consensus/Stratis.Bitcoin.Features.Consensus.csproj +++ b/src/Stratis.Bitcoin.Features.Consensus/Stratis.Bitcoin.Features.Consensus.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.Dns/Stratis.Bitcoin.Features.Dns.csproj b/src/Stratis.Bitcoin.Features.Dns/Stratis.Bitcoin.Features.Dns.csproj index aab208ead3..e41bc4eb56 100644 --- a/src/Stratis.Bitcoin.Features.Dns/Stratis.Bitcoin.Features.Dns.csproj +++ b/src/Stratis.Bitcoin.Features.Dns/Stratis.Bitcoin.Features.Dns.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.ExternalAPI/Stratis.Bitcoin.Features.ExternalApi.csproj b/src/Stratis.Bitcoin.Features.ExternalAPI/Stratis.Bitcoin.Features.ExternalApi.csproj index 9c138626dc..0132e461c6 100644 --- a/src/Stratis.Bitcoin.Features.ExternalAPI/Stratis.Bitcoin.Features.ExternalApi.csproj +++ b/src/Stratis.Bitcoin.Features.ExternalAPI/Stratis.Bitcoin.Features.ExternalApi.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis.Features.ExternalAPI Stratis.Features.ExternalAPI diff --git a/src/Stratis.Bitcoin.Features.Interop/Stratis.Bitcoin.Features.Interop.csproj b/src/Stratis.Bitcoin.Features.Interop/Stratis.Bitcoin.Features.Interop.csproj index fb615455a8..ea98f0700b 100644 --- a/src/Stratis.Bitcoin.Features.Interop/Stratis.Bitcoin.Features.Interop.csproj +++ b/src/Stratis.Bitcoin.Features.Interop/Stratis.Bitcoin.Features.Interop.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis.Features.Interop Stratis.Features.Interop diff --git a/src/Stratis.Bitcoin.Features.LightWallet/Stratis.Bitcoin.Features.LightWallet.csproj b/src/Stratis.Bitcoin.Features.LightWallet/Stratis.Bitcoin.Features.LightWallet.csproj index bc9538caf9..4fd582956c 100644 --- a/src/Stratis.Bitcoin.Features.LightWallet/Stratis.Bitcoin.Features.LightWallet.csproj +++ b/src/Stratis.Bitcoin.Features.LightWallet/Stratis.Bitcoin.Features.LightWallet.csproj @@ -7,7 +7,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.MemoryPool/Stratis.Bitcoin.Features.MemoryPool.csproj b/src/Stratis.Bitcoin.Features.MemoryPool/Stratis.Bitcoin.Features.MemoryPool.csproj index b49f913713..47c48d012d 100644 --- a/src/Stratis.Bitcoin.Features.MemoryPool/Stratis.Bitcoin.Features.MemoryPool.csproj +++ b/src/Stratis.Bitcoin.Features.MemoryPool/Stratis.Bitcoin.Features.MemoryPool.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False library Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.Miner/Stratis.Bitcoin.Features.Miner.csproj b/src/Stratis.Bitcoin.Features.Miner/Stratis.Bitcoin.Features.Miner.csproj index 8adb42dfa1..752d84c697 100644 --- a/src/Stratis.Bitcoin.Features.Miner/Stratis.Bitcoin.Features.Miner.csproj +++ b/src/Stratis.Bitcoin.Features.Miner/Stratis.Bitcoin.Features.Miner.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.Notifications/Stratis.Bitcoin.Features.Notifications.csproj b/src/Stratis.Bitcoin.Features.Notifications/Stratis.Bitcoin.Features.Notifications.csproj index 395f7df892..0a36683fea 100644 --- a/src/Stratis.Bitcoin.Features.Notifications/Stratis.Bitcoin.Features.Notifications.csproj +++ b/src/Stratis.Bitcoin.Features.Notifications/Stratis.Bitcoin.Features.Notifications.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common.csproj b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common.csproj index 39a72f36c7..02daa149b9 100644 --- a/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common.csproj +++ b/src/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common/Stratis.Bitcoin.Features.PoA.IntegrationTests.Common.csproj @@ -13,7 +13,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False diff --git a/src/Stratis.Bitcoin.Features.PoA/Stratis.Bitcoin.Features.PoA.csproj b/src/Stratis.Bitcoin.Features.PoA/Stratis.Bitcoin.Features.PoA.csproj index 375e558077..975d88b05c 100644 --- a/src/Stratis.Bitcoin.Features.PoA/Stratis.Bitcoin.Features.PoA.csproj +++ b/src/Stratis.Bitcoin.Features.PoA/Stratis.Bitcoin.Features.PoA.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.RPC/Stratis.Bitcoin.Features.RPC.csproj b/src/Stratis.Bitcoin.Features.RPC/Stratis.Bitcoin.Features.RPC.csproj index a2a335e62e..e6932eec0a 100644 --- a/src/Stratis.Bitcoin.Features.RPC/Stratis.Bitcoin.Features.RPC.csproj +++ b/src/Stratis.Bitcoin.Features.RPC/Stratis.Bitcoin.Features.RPC.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.SignalR/Stratis.Bitcoin.Features.SignalR.csproj b/src/Stratis.Bitcoin.Features.SignalR/Stratis.Bitcoin.Features.SignalR.csproj index 3110f6f10c..2d124a4cbb 100644 --- a/src/Stratis.Bitcoin.Features.SignalR/Stratis.Bitcoin.Features.SignalR.csproj +++ b/src/Stratis.Bitcoin.Features.SignalR/Stratis.Bitcoin.Features.SignalR.csproj @@ -1,7 +1,7 @@  netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis.Features.SignalR Stratis.Features.SignalR Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.SmartContracts/Stratis.Bitcoin.Features.SmartContracts.csproj b/src/Stratis.Bitcoin.Features.SmartContracts/Stratis.Bitcoin.Features.SmartContracts.csproj index ba98209c02..8130548340 100644 --- a/src/Stratis.Bitcoin.Features.SmartContracts/Stratis.Bitcoin.Features.SmartContracts.csproj +++ b/src/Stratis.Bitcoin.Features.SmartContracts/Stratis.Bitcoin.Features.SmartContracts.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis.Features.SmartContracts Stratis.Features.SmartContracts diff --git a/src/Stratis.Bitcoin.Features.Wallet/Stratis.Bitcoin.Features.Wallet.csproj b/src/Stratis.Bitcoin.Features.Wallet/Stratis.Bitcoin.Features.Wallet.csproj index 11c724d423..1705efde17 100644 --- a/src/Stratis.Bitcoin.Features.Wallet/Stratis.Bitcoin.Features.Wallet.csproj +++ b/src/Stratis.Bitcoin.Features.Wallet/Stratis.Bitcoin.Features.Wallet.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Features.WatchOnlyWallet/Stratis.Bitcoin.Features.WatchOnlyWallet.csproj b/src/Stratis.Bitcoin.Features.WatchOnlyWallet/Stratis.Bitcoin.Features.WatchOnlyWallet.csproj index 4e0ca802f0..afe132eb8b 100644 --- a/src/Stratis.Bitcoin.Features.WatchOnlyWallet/Stratis.Bitcoin.Features.WatchOnlyWallet.csproj +++ b/src/Stratis.Bitcoin.Features.WatchOnlyWallet/Stratis.Bitcoin.Features.WatchOnlyWallet.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.IntegrationTests.Common/Stratis.Bitcoin.IntegrationTests.Common.csproj b/src/Stratis.Bitcoin.IntegrationTests.Common/Stratis.Bitcoin.IntegrationTests.Common.csproj index 2d8249b70d..5c4708f8d7 100644 --- a/src/Stratis.Bitcoin.IntegrationTests.Common/Stratis.Bitcoin.IntegrationTests.Common.csproj +++ b/src/Stratis.Bitcoin.IntegrationTests.Common/Stratis.Bitcoin.IntegrationTests.Common.csproj @@ -13,7 +13,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False diff --git a/src/Stratis.Bitcoin.Networks/Stratis.Bitcoin.Networks.csproj b/src/Stratis.Bitcoin.Networks/Stratis.Bitcoin.Networks.csproj index 22a4a9ec21..de93e098a1 100644 --- a/src/Stratis.Bitcoin.Networks/Stratis.Bitcoin.Networks.csproj +++ b/src/Stratis.Bitcoin.Networks/Stratis.Bitcoin.Networks.csproj @@ -14,9 +14,9 @@ false false false - 1.3.1.0 - 1.3.1.0 - 1.3.1.0 + 1.3.2.0 + 1.3.2.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Bitcoin.Tests.Common/Stratis.Bitcoin.Tests.Common.csproj b/src/Stratis.Bitcoin.Tests.Common/Stratis.Bitcoin.Tests.Common.csproj index 41a83b2313..ce6b84ceea 100644 --- a/src/Stratis.Bitcoin.Tests.Common/Stratis.Bitcoin.Tests.Common.csproj +++ b/src/Stratis.Bitcoin.Tests.Common/Stratis.Bitcoin.Tests.Common.csproj @@ -13,7 +13,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False diff --git a/src/Stratis.Bitcoin/Controllers/Models/AddressBalancesResult.cs b/src/Stratis.Bitcoin/Controllers/Models/AddressBalancesResult.cs index ea21e8a9e6..675c596685 100644 --- a/src/Stratis.Bitcoin/Controllers/Models/AddressBalancesResult.cs +++ b/src/Stratis.Bitcoin/Controllers/Models/AddressBalancesResult.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using LiteDB; using NBitcoin; using Newtonsoft.Json; @@ -121,5 +122,29 @@ public static long CalculateBalance(this IEnumerable balan return balance; } + + public static long CalculateMinBalance(this IEnumerable balanceChanges, int startHeight) + { + long balance = 0; + long? minbalance = null; + + // If the balance drop occurs within a block it should not count towards the minimum. + var balancesByHeight = balanceChanges + .Select(b => new AddressBalanceChange() { BalanceChangedHeight = b.BalanceChangedHeight, Satoshi = b.Deposited ? b.Satoshi : -b.Satoshi }) + .GroupBy(b => b.BalanceChangedHeight, b => b.Satoshi, (key, g) => new AddressBalanceChange { BalanceChangedHeight = key, Satoshi = g.Sum() }); + + foreach (AddressBalanceChange change in balancesByHeight) + { + balance += change.Satoshi; + + if (change.BalanceChangedHeight < startHeight) + continue; + + if (!minbalance.HasValue || balance < minbalance.Value) + minbalance = balance; + } + + return minbalance ?? balance; + } } } \ No newline at end of file diff --git a/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs b/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs index 6e6153b237..4e43a79c01 100644 --- a/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs +++ b/src/Stratis.Bitcoin/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1.0")] -[assembly: AssemblyFileVersion("1.3.1.0")] +[assembly: AssemblyVersion("1.3.2.0")] +[assembly: AssemblyFileVersion("1.3.2.0")] [assembly: InternalsVisibleTo("Stratis.Bitcoin.Tests")] \ No newline at end of file diff --git a/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj b/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj index 46762450c1..6a2550f2e5 100644 --- a/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj +++ b/src/Stratis.Bitcoin/Stratis.Bitcoin.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0-dev + 1.3.2.0-dev False ..\Stratis.ruleset Stratis Group Ltd. diff --git a/src/Stratis.CirrusD/Stratis.CirrusD.csproj b/src/Stratis.CirrusD/Stratis.CirrusD.csproj index d6f0c68741..795dc8631a 100644 --- a/src/Stratis.CirrusD/Stratis.CirrusD.csproj +++ b/src/Stratis.CirrusD/Stratis.CirrusD.csproj @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis Group Ltd. diff --git a/src/Stratis.CirrusDnsD/Stratis.CirrusDnsD.csproj b/src/Stratis.CirrusDnsD/Stratis.CirrusDnsD.csproj index 865fe3e0aa..d9f424f643 100644 --- a/src/Stratis.CirrusDnsD/Stratis.CirrusDnsD.csproj +++ b/src/Stratis.CirrusDnsD/Stratis.CirrusDnsD.csproj @@ -17,7 +17,7 @@ latest Stratis Group Ltd. - 1.3.1.0 + 1.3.2.0 diff --git a/src/Stratis.CirrusMinerD/Stratis.CirrusMinerD.csproj b/src/Stratis.CirrusMinerD/Stratis.CirrusMinerD.csproj index 5fdaa1eaa6..f8579282f7 100644 --- a/src/Stratis.CirrusMinerD/Stratis.CirrusMinerD.csproj +++ b/src/Stratis.CirrusMinerD/Stratis.CirrusMinerD.csproj @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis Group Ltd. diff --git a/src/Stratis.CirrusPegD/Stratis.CirrusPegD.csproj b/src/Stratis.CirrusPegD/Stratis.CirrusPegD.csproj index 8c05bad801..e40b5e32a0 100644 --- a/src/Stratis.CirrusPegD/Stratis.CirrusPegD.csproj +++ b/src/Stratis.CirrusPegD/Stratis.CirrusPegD.csproj @@ -3,7 +3,7 @@ Exe netcoreapp3.1 - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. diff --git a/src/Stratis.Features.Collateral/CheckCollateralFullValidationRule.cs b/src/Stratis.Features.Collateral/CheckCollateralFullValidationRule.cs index f723391b82..a94ed94a6c 100644 --- a/src/Stratis.Features.Collateral/CheckCollateralFullValidationRule.cs +++ b/src/Stratis.Features.Collateral/CheckCollateralFullValidationRule.cs @@ -79,7 +79,7 @@ public override Task RunAsync(RuleContext context) } IFederationMember federationMember = this.federationHistory.GetFederationMemberForBlock(context.ValidationContext.ChainedHeaderToValidate); - if (!this.collateralChecker.CheckCollateral(federationMember, commitmentHeight.Value)) + if (!this.collateralChecker.CheckCollateral(federationMember, commitmentHeight.Value, context.ValidationContext.ChainedHeaderToValidate.Height)) { // By setting rejectUntil we avoid banning a peer that provided a block. context.ValidationContext.RejectUntil = this.dateTime.GetUtcNow() + TimeSpan.FromSeconds(this.collateralCheckBanDurationSeconds); diff --git a/src/Stratis.Features.Collateral/CollateralChecker.cs b/src/Stratis.Features.Collateral/CollateralChecker.cs index 189daabb64..aadddd86a1 100644 --- a/src/Stratis.Features.Collateral/CollateralChecker.cs +++ b/src/Stratis.Features.Collateral/CollateralChecker.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging; using NBitcoin; using Stratis.Bitcoin.AsyncWork; +using Stratis.Bitcoin.Base.Deployments; using Stratis.Bitcoin.Configuration.Logging; using Stratis.Bitcoin.Controllers.Models; using Stratis.Bitcoin.EventBus; @@ -28,14 +29,20 @@ public interface ICollateralChecker : IDisposable /// Checks if given federation member fulfills the collateral requirement. /// The federation member whose collateral will be checked. /// Counter chain height at which collateral should be checked. + /// Used for BIP 9 activation. /// True if the collateral requirement is fulfilled and false otherwise. - bool CheckCollateral(IFederationMember federationMember, int heightToCheckAt); + bool CheckCollateral(IFederationMember federationMember, int heightToCheckAt, int localChainHeight); int GetCounterChainConsensusHeight(); } public class CollateralChecker : ICollateralChecker { + /// + /// The number of Strax blocks the collateral should remain above the threshold to be suiable for mining a block. + /// + private const int collateralMaturationPeriod = 500; + private readonly IBlockStoreClient blockStoreClient; private readonly IFederationManager federationManager; @@ -67,12 +74,15 @@ public class CollateralChecker : ICollateralChecker /// All access should be protected by . private int counterChainConsensusTipHeight; + private readonly double blockRatio; + private readonly NodeDeployments nodeDeployments; + private Task updateCollateralContinuouslyTask; private bool collateralUpdated; public CollateralChecker(IHttpClientFactory httpClientFactory, ICounterChainSettings settings, IFederationManager federationManager, - ISignals signals, Network network, IAsyncProvider asyncProvider, INodeLifetime nodeLifetime) + ISignals signals, Network network, IAsyncProvider asyncProvider, INodeLifetime nodeLifetime, NodeDeployments nodeDeployments) { this.federationManager = federationManager; this.signals = signals; @@ -84,6 +94,7 @@ public CollateralChecker(IHttpClientFactory httpClientFactory, ICounterChainSett this.balancesDataByAddress = new Dictionary(); this.logger = LogManager.GetCurrentClassLogger(); this.blockStoreClient = new BlockStoreClient(httpClientFactory, $"http://{settings.CounterChainApiHost}", settings.CounterChainApiPort); + this.nodeDeployments = nodeDeployments; } public async Task InitializeAsync() @@ -208,7 +219,7 @@ private async Task UpdateCollateralInfoAsync(CancellationToken cancellation) } /// - public bool CheckCollateral(IFederationMember federationMember, int heightToCheckAt) + public bool CheckCollateral(IFederationMember federationMember, int heightToCheckAt, int localChainHeight) { if (!this.collateralUpdated) { @@ -254,7 +265,29 @@ public bool CheckCollateral(IFederationMember federationMember, int heightToChec this.logger.LogInformation("Calculated balance for '{0}' at {1} is {2}, collateral requirement is {3}.", member.CollateralMainchainAddress, heightToCheckAt, Money.Satoshis(balance).ToUnit(MoneyUnit.BTC), member.CollateralAmount); - return balance >= member.CollateralAmount.Satoshi; + if (balance < member.CollateralAmount.Satoshi) + return false; + + int release1320ActivationHeight = 0; + if (this.nodeDeployments?.BIP9.ArraySize > 0 /* Not NoBIP9Deployments */) + release1320ActivationHeight = this.nodeDeployments.BIP9.ActivationHeightProviders[1 /* Release1320 */].ActivationHeight; + + // Legacy behavior before activation. + if (localChainHeight < release1320ActivationHeight) + return true; + + // Checks that the collateral remained valid for at least half a round. + int startHeight = heightToCheckAt - collateralMaturationPeriod; + long minBalance = balanceData.BalanceChanges.Where(x => x.BalanceChangedHeight <= heightToCheckAt).CalculateMinBalance(startHeight); + + if (minBalance < member.CollateralAmount.Satoshi) + { + this.logger.LogInformation("The collateral has to remain above {0} for {1} Strax blocks before a block can be mined.", + Money.Satoshis(member.CollateralAmount.Satoshi).ToUnit(MoneyUnit.BTC), collateralMaturationPeriod); + return false; + } + + return true; } } diff --git a/src/Stratis.Features.Collateral/CollateralPoAMiner.cs b/src/Stratis.Features.Collateral/CollateralPoAMiner.cs index 9b207cb427..bc3c4e550c 100644 --- a/src/Stratis.Features.Collateral/CollateralPoAMiner.cs +++ b/src/Stratis.Features.Collateral/CollateralPoAMiner.cs @@ -87,7 +87,7 @@ protected override void FillBlockTemplate(BlockTemplate blockTemplate, out bool } // Check our own collateral at a given commitment height. - bool success = this.collateralChecker.CheckCollateral(currentMember, commitmentHeight); + bool success = this.collateralChecker.CheckCollateral(currentMember, commitmentHeight, this.chainIndexer[blockTemplate.Block.Header.HashPrevBlock].Height + 1); if (!success) { diff --git a/src/Stratis.Features.Collateral/Stratis.Features.Collateral.csproj b/src/Stratis.Features.Collateral/Stratis.Features.Collateral.csproj index 08ee347031..2601ffa943 100644 --- a/src/Stratis.Features.Collateral/Stratis.Features.Collateral.csproj +++ b/src/Stratis.Features.Collateral/Stratis.Features.Collateral.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 4.0.9.0 + 4.0.9.1 Stratis Group Ltd. diff --git a/src/Stratis.Features.Diagnostic/Stratis.Features.Diagnostic.csproj b/src/Stratis.Features.Diagnostic/Stratis.Features.Diagnostic.csproj index c53fc350d4..f6b62df9ef 100644 --- a/src/Stratis.Features.Diagnostic/Stratis.Features.Diagnostic.csproj +++ b/src/Stratis.Features.Diagnostic/Stratis.Features.Diagnostic.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 ..\None.ruleset true - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. diff --git a/src/Stratis.Features.FederatedPeg.Tests/CheckCollateralFullValidationRuleTests.cs b/src/Stratis.Features.FederatedPeg.Tests/CheckCollateralFullValidationRuleTests.cs index 1507c92a6c..fb4046be71 100644 --- a/src/Stratis.Features.FederatedPeg.Tests/CheckCollateralFullValidationRuleTests.cs +++ b/src/Stratis.Features.FederatedPeg.Tests/CheckCollateralFullValidationRuleTests.cs @@ -97,7 +97,7 @@ public async Task SkippedIfIBDAsync() [Fact] public async Task PassesIfCollateralIsOkAsync() { - this.collateralCheckerMock.Setup(x => x.CheckCollateral(It.IsAny(), It.IsAny())).Returns(true); + this.collateralCheckerMock.Setup(x => x.CheckCollateral(It.IsAny(), It.IsAny(), It.IsAny())).Returns(true); this.collateralCheckerMock.Setup(x => x.GetCounterChainConsensusHeight()).Returns(5000); await this.rule.RunAsync(this.ruleContext); @@ -106,7 +106,7 @@ public async Task PassesIfCollateralIsOkAsync() [Fact] public async Task ThrowsIfCollateralCheckFailsAsync() { - this.collateralCheckerMock.Setup(x => x.CheckCollateral(It.IsAny(), It.IsAny())).Returns(false); + this.collateralCheckerMock.Setup(x => x.CheckCollateral(It.IsAny(), It.IsAny(), It.IsAny())).Returns(false); await Assert.ThrowsAsync(() => this.rule.RunAsync(this.ruleContext)); } diff --git a/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs b/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs index 5de8cc606b..7972dbb2da 100644 --- a/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs +++ b/src/Stratis.Features.FederatedPeg.Tests/CollateralCheckerTests.cs @@ -9,6 +9,7 @@ using NBitcoin; using Stratis.Bitcoin; using Stratis.Bitcoin.AsyncWork; +using Stratis.Bitcoin.Base.Deployments; using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Controllers.Models; using Stratis.Bitcoin.EventBus; @@ -77,7 +78,8 @@ private void InitializeCollateralChecker([CallerMemberName] string callingMethod federationManager.Initialize(); - this.collateralChecker = new CollateralChecker(clientFactory, counterChainSettings, federationManager, signals, network, asyncMock.Object, (new Mock()).Object); + this.collateralChecker = new CollateralChecker(clientFactory, counterChainSettings, federationManager, signals, network, + asyncMock.Object, new Mock().Object, new NodeDeployments(network, chainIndexerMock.Object)); } [Fact] @@ -128,9 +130,9 @@ public async Task CanInitializeAndCheckCollateralAsync() await this.collateralChecker.InitializeAsync(); - Assert.True(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[0], this.collateralCheckHeight)); - Assert.True(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[1], this.collateralCheckHeight)); - Assert.False(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[2], this.collateralCheckHeight)); + Assert.True(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[0], this.collateralCheckHeight, 0)); + Assert.True(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[1], this.collateralCheckHeight, 0)); + Assert.False(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[2], this.collateralCheckHeight, 0)); // Now change what the client returns and make sure collateral check fails after update. AddressIndexerData updated = collateralData.BalancesData.First(b => b.Address == this.collateralFederationMembers[0].CollateralMainchainAddress); @@ -139,7 +141,7 @@ public async Task CanInitializeAndCheckCollateralAsync() // Wait CollateralUpdateIntervalSeconds + 1 seconds await Task.Delay(21_000); - Assert.False(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[0], this.collateralCheckHeight)); + Assert.False(this.collateralChecker.CheckCollateral(this.collateralFederationMembers[0], this.collateralCheckHeight, 0)); this.collateralChecker.Dispose(); } diff --git a/src/Stratis.Features.FederatedPeg/Stratis.Features.FederatedPeg.csproj b/src/Stratis.Features.FederatedPeg/Stratis.Features.FederatedPeg.csproj index 56b34f2de0..fa3927d9e4 100644 --- a/src/Stratis.Features.FederatedPeg/Stratis.Features.FederatedPeg.csproj +++ b/src/Stratis.Features.FederatedPeg/Stratis.Features.FederatedPeg.csproj @@ -12,7 +12,7 @@ Full ..\None.ruleset Stratis Group Ltd. - 4.0.9.0 + 4.0.9.1 diff --git a/src/Stratis.Features.SQLiteWalletRepository/Stratis.Features.SQLiteWalletRepository.csproj b/src/Stratis.Features.SQLiteWalletRepository/Stratis.Features.SQLiteWalletRepository.csproj index 5fab0b685c..d4844b6586 100644 --- a/src/Stratis.Features.SQLiteWalletRepository/Stratis.Features.SQLiteWalletRepository.csproj +++ b/src/Stratis.Features.SQLiteWalletRepository/Stratis.Features.SQLiteWalletRepository.csproj @@ -14,7 +14,7 @@ false false false - 1.3.1.0 + 1.3.2.0 False Stratis Group Ltd. diff --git a/src/Stratis.Sidechains.Networks/CirrusDev.cs b/src/Stratis.Sidechains.Networks/CirrusDev.cs index f7beff73ec..46193fd98d 100644 --- a/src/Stratis.Sidechains.Networks/CirrusDev.cs +++ b/src/Stratis.Sidechains.Networks/CirrusDev.cs @@ -107,7 +107,8 @@ public CirrusDev() var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. - [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", 0, DateTime.Parse("2022-3-22 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold) + [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", CirrusBIP9Deployments.FlagBitRelease1300, DateTime.Parse("2022-3-22 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold), + [CirrusBIP9Deployments.Release1320] = new BIP9DeploymentsParameters("Release1320", CirrusBIP9Deployments.FlagBitRelease1320, DateTime.Parse("2022-6-15 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold) }; this.Consensus = new Consensus( diff --git a/src/Stratis.Sidechains.Networks/CirrusMain.cs b/src/Stratis.Sidechains.Networks/CirrusMain.cs index 38bc7237b6..22d2415a8b 100644 --- a/src/Stratis.Sidechains.Networks/CirrusMain.cs +++ b/src/Stratis.Sidechains.Networks/CirrusMain.cs @@ -197,7 +197,8 @@ public CirrusMain() var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. - [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", 0, DateTime.Parse("2022-3-22 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Parse("2023-1-1 +0").ToUnixTimestamp(), 1512 /* 75% Activation Threshold */) + [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", CirrusBIP9Deployments.FlagBitRelease1300, DateTime.Parse("2022-3-22 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Parse("2023-1-1 +0").ToUnixTimestamp(), 1512 /* 75% Activation Threshold */), + [CirrusBIP9Deployments.Release1320] = new BIP9DeploymentsParameters("Release1320", CirrusBIP9Deployments.FlagBitRelease1320, DateTime.Parse("2022-6-15 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Parse("2023-1-1 +0").ToUnixTimestamp(), 1512 /* 75% Activation Threshold */) }; this.Consensus = new Consensus( diff --git a/src/Stratis.Sidechains.Networks/CirrusRegTest.cs b/src/Stratis.Sidechains.Networks/CirrusRegTest.cs index 0941f94155..30938850aa 100644 --- a/src/Stratis.Sidechains.Networks/CirrusRegTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusRegTest.cs @@ -126,7 +126,8 @@ public CirrusRegTest() var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. - [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", 0, DateTime.Parse("2022-3-22 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold) + [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", CirrusBIP9Deployments.FlagBitRelease1300, DateTime.Parse("2022-3-22 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold), + [CirrusBIP9Deployments.Release1320] = new BIP9DeploymentsParameters("Release1320", CirrusBIP9Deployments.FlagBitRelease1320, DateTime.Parse("2022-6-15 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Now.AddDays(50).ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold) }; this.Consensus = new Consensus( diff --git a/src/Stratis.Sidechains.Networks/CirrusTest.cs b/src/Stratis.Sidechains.Networks/CirrusTest.cs index 07311a2252..4ea3585e51 100644 --- a/src/Stratis.Sidechains.Networks/CirrusTest.cs +++ b/src/Stratis.Sidechains.Networks/CirrusTest.cs @@ -148,7 +148,8 @@ public CirrusTest() var bip9Deployments = new CirrusBIP9Deployments() { // Deployment will go active once 75% of nodes are on 1.3.0.0 or later. - [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", 0, DateTime.Parse("2022-3-28 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Parse("2023-1-1 +0").ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultTestnetThreshold) + [CirrusBIP9Deployments.Release1300] = new BIP9DeploymentsParameters("Release1300", CirrusBIP9Deployments.FlagBitRelease1300, DateTime.Parse("2022-3-28 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Parse("2023-1-1 +0").ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultTestnetThreshold), + [CirrusBIP9Deployments.Release1320] = new BIP9DeploymentsParameters("Release1320", CirrusBIP9Deployments.FlagBitRelease1320, DateTime.Parse("2022-6-15 +0").ToUnixTimestamp() /* Activation date lower bound */, DateTime.Parse("2023-1-1 +0").ToUnixTimestamp(), BIP9DeploymentsParameters.DefaultRegTestThreshold) }; this.Consensus = new Consensus( diff --git a/src/Stratis.Sidechains.Networks/Deployments/CirrusBIP9Deployments.cs b/src/Stratis.Sidechains.Networks/Deployments/CirrusBIP9Deployments.cs index be0d2de7ef..2aa393ec8b 100644 --- a/src/Stratis.Sidechains.Networks/Deployments/CirrusBIP9Deployments.cs +++ b/src/Stratis.Sidechains.Networks/Deployments/CirrusBIP9Deployments.cs @@ -9,9 +9,13 @@ public class CirrusBIP9Deployments : BIP9DeploymentsArray { // The position of each deployment in the deployments array. Note that this is decoupled from the actual position of the flag bit for the deployment in the block version. public const int Release1300 = 0; + public const int Release1320 = 1; + + public const int FlagBitRelease1300 = 0; + public const int FlagBitRelease1320 = 1; // The number of deployments. - public const int NumberOfDeployments = 1; + public const int NumberOfDeployments = 2; /// /// Constructs the BIP9 deployments array. diff --git a/src/Stratis.Sidechains.Networks/Stratis.Sidechains.Networks.csproj b/src/Stratis.Sidechains.Networks/Stratis.Sidechains.Networks.csproj index 5102c99edf..1ec622faaf 100644 --- a/src/Stratis.Sidechains.Networks/Stratis.Sidechains.Networks.csproj +++ b/src/Stratis.Sidechains.Networks/Stratis.Sidechains.Networks.csproj @@ -5,7 +5,7 @@ Full ..\None.ruleset - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. Stratis.Sidechains.Networks diff --git a/src/Stratis.StraxD/Stratis.StraxD.csproj b/src/Stratis.StraxD/Stratis.StraxD.csproj index 8353bba2db..d3a6c1da49 100644 --- a/src/Stratis.StraxD/Stratis.StraxD.csproj +++ b/src/Stratis.StraxD/Stratis.StraxD.csproj @@ -16,7 +16,7 @@ latest - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd. diff --git a/src/Stratis.StraxDnsD/Stratis.StraxDnsD.csproj b/src/Stratis.StraxDnsD/Stratis.StraxDnsD.csproj index 8617e43c82..f02d643d2b 100644 --- a/src/Stratis.StraxDnsD/Stratis.StraxDnsD.csproj +++ b/src/Stratis.StraxDnsD/Stratis.StraxDnsD.csproj @@ -16,7 +16,7 @@ latest - 1.3.1.0 + 1.3.2.0 Stratis Group Ltd.