From 7e2dcc04a43b14740f09291fbcccbfa8334cdccc Mon Sep 17 00:00:00 2001 From: dangershony Date: Fri, 4 Dec 2020 12:49:30 +0000 Subject: [PATCH 1/9] delete ruleset and migrate to edditorconfig --- src/.editorconfig | 140 ++++ src/Blockcore.ruleset | 128 --- src/Blockcore.sln | 2 - src/Blockcore/.editorconfig | 14 + src/Blockcore/Blockcore.csproj | 1 - .../Blockcore.Features.Diagnostic.csproj | 1 - src/None.ruleset | 767 ------------------ 7 files changed, 154 insertions(+), 899 deletions(-) delete mode 100644 src/Blockcore.ruleset create mode 100644 src/Blockcore/.editorconfig delete mode 100644 src/None.ruleset diff --git a/src/.editorconfig b/src/.editorconfig index 07658a799..4d1164e76 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -38,5 +38,145 @@ dotnet_naming_style.end_with_async.capitalization = pascal_case # SA1401: Fields should be private dotnet_diagnostic.SA1401.severity = none +# comments related +dotnet_diagnostic.CS1591.severity = none +dotnet_diagnostic.CS1574.severity = none +dotnet_diagnostic.CS1584.severity = none +dotnet_diagnostic.CS1723.severity = none +dotnet_diagnostic.CS1570.severity = none +dotnet_diagnostic.CS1571.severity = none +dotnet_diagnostic.CS1572.severity = none +dotnet_diagnostic.CS1570.severity = none +dotnet_diagnostic.CSxxxx.severity = none +dotnet_diagnostic.CSxxxx.severity = none +dotnet_diagnostic.CSxxxx.severity = none + +# migrated from rulset + + +dotnet_diagnostic.CA1001.severity = warning +dotnet_diagnostic.CA1009.severity = warning +dotnet_diagnostic.CA1016.severity = warning +dotnet_diagnostic.CA1033.severity = warning +dotnet_diagnostic.CA1049.severity = warning +dotnet_diagnostic.CA1060.severity = warning +dotnet_diagnostic.CA1061.severity = warning +dotnet_diagnostic.CA1063.severity = warning +dotnet_diagnostic.CA1065.severity = warning +dotnet_diagnostic.CA1301.severity = warning +dotnet_diagnostic.CA1400.severity = warning +dotnet_diagnostic.CA1401.severity = warning +dotnet_diagnostic.CA1403.severity = warning +dotnet_diagnostic.CA1404.severity = warning +dotnet_diagnostic.CA1405.severity = warning +dotnet_diagnostic.CA1410.severity = warning +dotnet_diagnostic.CA1415.severity = warning +dotnet_diagnostic.CA1821.severity = warning +dotnet_diagnostic.CA1900.severity = warning +dotnet_diagnostic.CA1901.severity = warning +dotnet_diagnostic.CA2002.severity = warning +dotnet_diagnostic.CA2100.severity = warning +dotnet_diagnostic.CA2101.severity = warning +dotnet_diagnostic.CA2108.severity = warning +dotnet_diagnostic.CA2111.severity = warning +dotnet_diagnostic.CA2112.severity = warning +dotnet_diagnostic.CA2114.severity = warning +dotnet_diagnostic.CA2116.severity = warning +dotnet_diagnostic.CA2117.severity = warning +dotnet_diagnostic.CA2122.severity = warning +dotnet_diagnostic.CA2123.severity = warning +dotnet_diagnostic.CA2124.severity = warning +dotnet_diagnostic.CA2126.severity = warning +dotnet_diagnostic.CA2131.severity = warning +dotnet_diagnostic.CA2132.severity = warning +dotnet_diagnostic.CA2133.severity = warning +dotnet_diagnostic.CA2134.severity = warning +dotnet_diagnostic.CA2137.severity = warning +dotnet_diagnostic.CA2138.severity = warning +dotnet_diagnostic.CA2140.severity = warning +dotnet_diagnostic.CA2141.severity = warning +dotnet_diagnostic.CA2146.severity = warning +dotnet_diagnostic.CA2147.severity = warning +dotnet_diagnostic.CA2149.severity = warning +dotnet_diagnostic.CA2200.severity = warning +dotnet_diagnostic.CA2202.severity = warning +dotnet_diagnostic.CA2207.severity = warning +dotnet_diagnostic.CA2212.severity = warning +dotnet_diagnostic.CA2213.severity = warning +dotnet_diagnostic.CA2214.severity = warning +dotnet_diagnostic.CA2216.severity = warning +dotnet_diagnostic.CA2220.severity = warning +dotnet_diagnostic.CA2229.severity = warning +dotnet_diagnostic.CA2231.severity = warning +dotnet_diagnostic.CA2232.severity = warning +dotnet_diagnostic.CA2235.severity = warning +dotnet_diagnostic.CA2236.severity = warning +dotnet_diagnostic.CA2237.severity = warning +dotnet_diagnostic.CA2238.severity = warning +dotnet_diagnostic.CA2240.severity = warning +dotnet_diagnostic.CA2241.severity = warning +dotnet_diagnostic.CA2242.severity = warning +dotnet_diagnostic.CS0618.severity = suggestion +dotnet_diagnostic.SA0001.severity = none +dotnet_diagnostic.SA1003.severity = none +dotnet_diagnostic.SA1008.severity = none +dotnet_diagnostic.SA1009.severity = none +dotnet_diagnostic.SA1012.severity = none +dotnet_diagnostic.SA1013.severity = none +dotnet_diagnostic.SA1100.severity = none +dotnet_diagnostic.SA1108.severity = none +dotnet_diagnostic.SA1110.severity = none +dotnet_diagnostic.SA1111.severity = none +dotnet_diagnostic.SA1116.severity = none +dotnet_diagnostic.SA1117.severity = none +dotnet_diagnostic.SA1119.severity = none +dotnet_diagnostic.SA1124.severity = none +dotnet_diagnostic.SA1127.severity = none +dotnet_diagnostic.SA1128.severity = none +dotnet_diagnostic.SA1131.severity = none +dotnet_diagnostic.SA1139.severity = none +dotnet_diagnostic.SA1201.severity = none +dotnet_diagnostic.SA1202.severity = none +dotnet_diagnostic.SA1203.severity = none +dotnet_diagnostic.SA1204.severity = none +dotnet_diagnostic.SA1214.severity = none +dotnet_diagnostic.SA1216.severity = none +dotnet_diagnostic.SA1217.severity = none +dotnet_diagnostic.SA1300.severity = none +dotnet_diagnostic.SA1402.severity = none +dotnet_diagnostic.SA1407.severity = none +dotnet_diagnostic.SA1413.severity = none +dotnet_diagnostic.SA1501.severity = none +dotnet_diagnostic.SA1502.severity = none +dotnet_diagnostic.SA1503.severity = none +dotnet_diagnostic.SA1512.severity = none +dotnet_diagnostic.SA1515.severity = none +dotnet_diagnostic.SA1520.severity = none +# Documentation stuff that needs to be hanged to warning at some point. +dotnet_diagnostic.SA1600.severity = none +dotnet_diagnostic.SA1602.severity = none +dotnet_diagnostic.SA1604.severity = none +dotnet_diagnostic.SA1611.severity = none +dotnet_diagnostic.SA1615.severity = none +dotnet_diagnostic.SA1616.severity = none +dotnet_diagnostic.SA1618.severity = none +dotnet_diagnostic.SA1623.severity = none +dotnet_diagnostic.SA1625.severity = none +dotnet_diagnostic.SA1629.severity = none +dotnet_diagnostic.SA1633.severity = none +dotnet_diagnostic.SA1640.severity = none +dotnet_diagnostic.SA1641.severity = none +dotnet_diagnostic.SA1642.severity = none +dotnet_diagnostic.SA1643.severity = none +dotnet_diagnostic.SA1649.severity = none +dotnet_diagnostic.SA1652.severity = none + + +# CS1658: Warning is overriding an error +dotnet_diagnostic.CS1658.severity = none + +# CS1573: Parameter has no matching param tag in the XML comment (but other parameters do) +dotnet_diagnostic.CS1573.severity = none + [*.{cs,vb}] dotnet_sort_system_directives_first = true \ No newline at end of file diff --git a/src/Blockcore.ruleset b/src/Blockcore.ruleset deleted file mode 100644 index 98fc1cf94..000000000 --- a/src/Blockcore.ruleset +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Blockcore.sln b/src/Blockcore.sln index 837fd9c39..89e0298ec 100644 --- a/src/Blockcore.sln +++ b/src/Blockcore.sln @@ -70,9 +70,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Global", "Global", "{0C6FDCCE-6D75-441F-86FA-2AD177196BF8}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - Blockcore.ruleset = Blockcore.ruleset Directory.Build.props = Directory.Build.props - None.ruleset = None.ruleset stylecop.json = stylecop.json test.runsettings = test.runsettings EndProjectSection diff --git a/src/Blockcore/.editorconfig b/src/Blockcore/.editorconfig new file mode 100644 index 000000000..a5d1a9d98 --- /dev/null +++ b/src/Blockcore/.editorconfig @@ -0,0 +1,14 @@ +# Editor configuration, see http://editorconfig.org + + +[ScriptEvaluationContext.cs] +dotnet_analyzer_diagnostic.severity = none + +[Script.cs] +dotnet_analyzer_diagnostic.severity = none + +[TransactionBuilder.cs] +dotnet_analyzer_diagnostic.severity = none + +[NBitcoin/**.cs] +dotnet_analyzer_diagnostic.severity = none \ No newline at end of file diff --git a/src/Blockcore/Blockcore.csproj b/src/Blockcore/Blockcore.csproj index 445b7cf5f..50402e573 100644 --- a/src/Blockcore/Blockcore.csproj +++ b/src/Blockcore/Blockcore.csproj @@ -6,7 +6,6 @@ Blockcore Blockcore.Core False - ..\Blockcore.ruleset true diff --git a/src/Features/Blockcore.Features.Diagnostic/Blockcore.Features.Diagnostic.csproj b/src/Features/Blockcore.Features.Diagnostic/Blockcore.Features.Diagnostic.csproj index e8f8761bd..f2664a1eb 100644 --- a/src/Features/Blockcore.Features.Diagnostic/Blockcore.Features.Diagnostic.csproj +++ b/src/Features/Blockcore.Features.Diagnostic/Blockcore.Features.Diagnostic.csproj @@ -1,7 +1,6 @@  - ..\..\None.ruleset true diff --git a/src/None.ruleset b/src/None.ruleset deleted file mode 100644 index b9ef06d4b..000000000 --- a/src/None.ruleset +++ /dev/null @@ -1,767 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 261c8c948d61464507fc830ce23a0119f9b78b44 Mon Sep 17 00:00:00 2001 From: dangershony Date: Fri, 4 Dec 2020 14:47:45 +0000 Subject: [PATCH 2/9] Fix more warnings --- src/.editorconfig | 5 +++- src/Blockcore/.editorconfig | 25 +++++++++++++++++- .../Consensus/Chain/ChainedHeader.cs | 26 ++++++++++--------- .../TransactionNotFoundException.cs | 7 +++-- .../Interfaces/UI/INavigationItem.cs | 9 ++++--- src/Blockcore/UI/BlazorModal/ModalService.cs | 4 +-- 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/.editorconfig b/src/.editorconfig index 4d1164e76..a6398443a 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -47,7 +47,7 @@ dotnet_diagnostic.CS1570.severity = none dotnet_diagnostic.CS1571.severity = none dotnet_diagnostic.CS1572.severity = none dotnet_diagnostic.CS1570.severity = none -dotnet_diagnostic.CSxxxx.severity = none +dotnet_diagnostic.CS1587.severity = none dotnet_diagnostic.CSxxxx.severity = none dotnet_diagnostic.CSxxxx.severity = none @@ -178,5 +178,8 @@ dotnet_diagnostic.CS1658.severity = none # CS1573: Parameter has no matching param tag in the XML comment (but other parameters do) dotnet_diagnostic.CS1573.severity = none +# xUnit2013: Do not use equality check to check for collection size. +dotnet_diagnostic.xUnit2013.severity = none + [*.{cs,vb}] dotnet_sort_system_directives_first = true \ No newline at end of file diff --git a/src/Blockcore/.editorconfig b/src/Blockcore/.editorconfig index a5d1a9d98..59455899c 100644 --- a/src/Blockcore/.editorconfig +++ b/src/Blockcore/.editorconfig @@ -1,5 +1,6 @@ # Editor configuration, see http://editorconfig.org +# todo: fix styling on the classes bellow [ScriptEvaluationContext.cs] dotnet_analyzer_diagnostic.severity = none @@ -7,8 +8,30 @@ dotnet_analyzer_diagnostic.severity = none [Script.cs] dotnet_analyzer_diagnostic.severity = none +[Transaction.cs] +dotnet_analyzer_diagnostic.severity = none + [TransactionBuilder.cs] dotnet_analyzer_diagnostic.severity = none +[TransactionSignature.cs] +dotnet_analyzer_diagnostic.severity = none + +[StandardScriptTemplate.cs] +dotnet_analyzer_diagnostic.severity = none + +[IpExtensions.cs] +dotnet_analyzer_diagnostic.severity = none + +[ValidatedAddress.cs] +dotnet_analyzer_diagnostic.severity = none + +[Network.cs] +dotnet_analyzer_diagnostic.severity = none + +[ScriptReader.cs] +dotnet_analyzer_diagnostic.severity = none + [NBitcoin/**.cs] -dotnet_analyzer_diagnostic.severity = none \ No newline at end of file +dotnet_analyzer_diagnostic.severity = none + diff --git a/src/Blockcore/Consensus/Chain/ChainedHeader.cs b/src/Blockcore/Consensus/Chain/ChainedHeader.cs index 8c49a848b..758a14524 100644 --- a/src/Blockcore/Consensus/Chain/ChainedHeader.cs +++ b/src/Blockcore/Consensus/Chain/ChainedHeader.cs @@ -231,8 +231,10 @@ public ChainedHeader(BlockHeader header, uint256 headerHash, ChainedHeader previ this.CalculateChainWork(); if (header is PosBlockHeader posBlockHeader) + { if (posBlockHeader.ProvenBlockHeader != null) this.ProvenBlockHeader = posBlockHeader.ProvenBlockHeader; + } } public ChainedHeader(BlockHeader header, uint256 headerHash, int height) : this(header, headerHash) @@ -305,7 +307,7 @@ public BlockLocator GetLocator() // Exponentially larger steps back, plus the genesis block. int height = Math.Max(pindex.Height - nStep, 0); - pindex = GetAncestor(height); + pindex = this.GetAncestor(height); if (blockHashes.Count > 10) nStep *= 2; @@ -379,7 +381,7 @@ public override string ToString() /// to verify the correct chained block header has been found. public ChainedHeader FindAncestorOrSelf(ChainedHeader chainedHeader) { - ChainedHeader found = GetAncestor(chainedHeader.Height); + ChainedHeader found = this.GetAncestor(chainedHeader.Height); if ((found != null) && (found.HashBlock == chainedHeader.HashBlock)) return found; @@ -414,7 +416,7 @@ public ChainedHeader FindAncestorOrSelf(uint256 blockHash, int height = 0) /// The target proof of work. public Target GetNextWorkRequired(Network network) { - return GetNextWorkRequired(network.Consensus); + return this.GetNextWorkRequired(network.Consensus); } /// @@ -427,7 +429,7 @@ public Target GetNextWorkRequired(IConsensus consensus) BlockHeader dummy = consensus.ConsensusFactory.CreateBlockHeader(); dummy.HashPrevBlock = this.HashBlock; dummy.BlockTime = DateTimeOffset.UtcNow; - return GetNextWorkRequired(dummy, consensus); + return this.GetNextWorkRequired(dummy, consensus); } /// @@ -438,7 +440,7 @@ public Target GetNextWorkRequired(IConsensus consensus) /// The target proof of work. public Target GetNextWorkRequired(BlockHeader block, Network network) { - return GetNextWorkRequired(block, network.Consensus); + return this.GetNextWorkRequired(block, network.Consensus); } /// @@ -459,7 +461,7 @@ public Target GetNextWorkRequired(BlockHeader block, IConsensus consensus) /// The target proof of work. public Target GetWorkRequired(Network network) { - return GetWorkRequired(network.Consensus); + return this.GetWorkRequired(network.Consensus); } /// @@ -507,7 +509,7 @@ public Target GetWorkRequired(IConsensus consensus) // Go back by what we want to be 14 days worth of blocks. long pastHeight = lastBlock.Height - (difficultyAdjustmentInterval - 1); - ChainedHeader firstChainedHeader = GetAncestor((int)pastHeight); + ChainedHeader firstChainedHeader = this.GetAncestor((int)pastHeight); if (firstChainedHeader == null) throw new NotSupportedException("Can only calculate work of a full chain"); @@ -574,7 +576,7 @@ public bool Validate(Network network) return BlockStake.Validate(network, this); bool genesisCorrect = (this.Height != 0) || this.HashBlock == network.GetGenesis().GetHash(); - return genesisCorrect && Validate(network.Consensus); + return genesisCorrect && this.Validate(network.Consensus); } /// @@ -593,7 +595,7 @@ public bool Validate(IConsensus consensus) bool heightCorrect = (this.Height == 0) || (this.Height == this.Previous.Height + 1); bool hashPrevCorrect = (this.Height == 0) || (this.Header.HashPrevBlock == this.Previous.HashBlock); bool hashCorrect = this.HashBlock == this.Header.GetHash(); - bool workCorrect = CheckProofOfWorkAndTarget(consensus); + bool workCorrect = this.CheckProofOfWorkAndTarget(consensus); return heightCorrect && hashPrevCorrect && hashCorrect && workCorrect; } @@ -605,7 +607,7 @@ public bool Validate(IConsensus consensus) /// Whether proof of work is valid. public bool CheckProofOfWorkAndTarget(Network network) { - return CheckProofOfWorkAndTarget(network.Consensus); + return this.CheckProofOfWorkAndTarget(network.Consensus); } /// @@ -615,7 +617,7 @@ public bool CheckProofOfWorkAndTarget(Network network) /// Whether proof of work is valid. public bool CheckProofOfWorkAndTarget(IConsensus consensus) { - return (this.Height == 0) || (this.Header.CheckProofOfWork() && (this.Header.Bits == GetWorkRequired(consensus))); + return (this.Height == 0) || (this.Header.CheckProofOfWork() && (this.Header.Bits == this.GetWorkRequired(consensus))); } /// @@ -733,7 +735,7 @@ private int GetSkipHeight(int height) // but the following expression was taken from bitcoin core. There it was tested in simulations // and performed well. // Skip steps are exponential - Using skip, max 110 steps to go back up to 2^18 blocks. - return (height & 1) != 0 ? InvertLowestOne(InvertLowestOne(height - 1)) + 1 : InvertLowestOne(height); + return (height & 1) != 0 ? this.InvertLowestOne(this.InvertLowestOne(height - 1)) + 1 : this.InvertLowestOne(height); } /// diff --git a/src/Blockcore/Consensus/TransactionInfo/TransactionNotFoundException.cs b/src/Blockcore/Consensus/TransactionInfo/TransactionNotFoundException.cs index e92fb88b2..de18185dd 100644 --- a/src/Blockcore/Consensus/TransactionInfo/TransactionNotFoundException.cs +++ b/src/Blockcore/Consensus/TransactionInfo/TransactionNotFoundException.cs @@ -8,24 +8,27 @@ public class TransactionNotFoundException : Exception public TransactionNotFoundException() { } + public TransactionNotFoundException(uint256 txId) : this(null, txId, null) { - } + public TransactionNotFoundException(string message, uint256 txId) : this(message, txId, null) { } + public TransactionNotFoundException(string message, uint256 txId, Exception inner) : base(message ?? "Transaction " + txId + " not found", inner) { this.TxId = txId; } + public uint256 TxId { get; set; } } -} +} \ No newline at end of file diff --git a/src/Blockcore/Interfaces/UI/INavigationItem.cs b/src/Blockcore/Interfaces/UI/INavigationItem.cs index 493d7aa42..7ed968cad 100644 --- a/src/Blockcore/Interfaces/UI/INavigationItem.cs +++ b/src/Blockcore/Interfaces/UI/INavigationItem.cs @@ -7,10 +7,13 @@ namespace Blockcore.Interfaces.UI public interface INavigationItem { public string Name { get; } + public string Navigation { get; } + public string Icon { get; } - public bool IsVisible {get; } - public int NavOrder {get; } - + + public bool IsVisible { get; } + + public int NavOrder { get; } } } \ No newline at end of file diff --git a/src/Blockcore/UI/BlazorModal/ModalService.cs b/src/Blockcore/UI/BlazorModal/ModalService.cs index 78dcadca6..f66995f8b 100644 --- a/src/Blockcore/UI/BlazorModal/ModalService.cs +++ b/src/Blockcore/UI/BlazorModal/ModalService.cs @@ -18,12 +18,12 @@ public void Show(string title, Type contentType) var content = new RenderFragment(x => { x.OpenComponent(1, contentType); x.CloseComponent(); }); - OnShow?.Invoke(title, content); + this.OnShow?.Invoke(title, content); } public void Close() { - OnClose?.Invoke(); + this.OnClose?.Invoke(); } } } \ No newline at end of file From 2d1834c69d9fb7085409cce1dff2148e6009c91d Mon Sep 17 00:00:00 2001 From: dangershony Date: Fri, 4 Dec 2020 17:32:50 +0000 Subject: [PATCH 3/9] Fix many warnings --- src/.editorconfig | 10 ++++++++-- .../Base/Deployments/BIP9Deployments.cs | 11 +++++------ .../Base/Deployments/BIP9DeploymentsArray.cs | 1 + src/Blockcore/Broadcasters/BroadcasterBase.cs | 5 ++++- src/Blockcore/Consensus/BlockInfo/Block.cs | 1 + .../Consensus/BlockInfo/BlockHeader.cs | 14 ++++++++++---- .../Consensus/BlockInfo/BlockSignature.cs | 9 +++++---- .../Consensus/BlockInfo/BlockStake.cs | 13 ++++++++++++- src/Blockcore/Consensus/Chain/ChainIndexer.cs | 7 ++++--- src/Blockcore/Consensus/Chain/ChainStore.cs | 1 + .../Consensus/Chain/ChainedHeader.cs | 11 +++++------ .../Consensus/ScriptAddressResult.cs | 3 +-- .../Consensus/ScriptInfo/StandardScripts.cs | 10 +++++----- src/Blockcore/Networks/NetworkRegistration.cs | 19 ++++++++++--------- .../Utilities/AsyncManualResetEvent.cs | 4 ++-- src/Blockcore/Utilities/ReaderWriterLock.cs | 2 ++ src/Directory.Build.props | 1 - .../FeeFilter/FeeFilterBehavior.cs | 8 ++++++-- .../WatchOnlyWalleRPCController.cs | 2 ++ 19 files changed, 84 insertions(+), 48 deletions(-) diff --git a/src/.editorconfig b/src/.editorconfig index a6398443a..3a77970fd 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -48,7 +48,7 @@ dotnet_diagnostic.CS1571.severity = none dotnet_diagnostic.CS1572.severity = none dotnet_diagnostic.CS1570.severity = none dotnet_diagnostic.CS1587.severity = none -dotnet_diagnostic.CSxxxx.severity = none +dotnet_diagnostic.CS1580.severity = none dotnet_diagnostic.CSxxxx.severity = none # migrated from rulset @@ -170,7 +170,13 @@ dotnet_diagnostic.SA1642.severity = none dotnet_diagnostic.SA1643.severity = none dotnet_diagnostic.SA1649.severity = none dotnet_diagnostic.SA1652.severity = none - +dotnet_diagnostic.SA1612.severity = none +dotnet_diagnostic.SA1614.severity = none +dotnet_diagnostic.SA1648.severity = none +dotnet_diagnostic.SA1005.severity = none +dotnet_diagnostic.SA1601.severity = none +dotnet_diagnostic.SA1107.severity = none +dotnet_diagnostic.SA1114.severity = none # CS1658: Warning is overriding an error dotnet_diagnostic.CS1658.severity = none diff --git a/src/Blockcore/Base/Deployments/BIP9Deployments.cs b/src/Blockcore/Base/Deployments/BIP9Deployments.cs index ef03744ca..3a6f777ee 100644 --- a/src/Blockcore/Base/Deployments/BIP9Deployments.cs +++ b/src/Blockcore/Base/Deployments/BIP9Deployments.cs @@ -16,7 +16,7 @@ public class BIP9DeploymentsParameters // 75% of 144 blocks public const long DefaultRegTestThreshold = 108; - + public BIP9DeploymentsParameters(string name, int bit, DateTimeOffset startTime, DateTimeOffset timeout, long threshold) { this.Bit = bit; @@ -25,9 +25,9 @@ public BIP9DeploymentsParameters(string name, int bit, DateTimeOffset startTime, this.Threshold = threshold; this.Name = name.ToLower(); } - + public BIP9DeploymentsParameters(string name, int bit, long startTime, long timeout, long threshold) - : this(name, bit, (DateTimeOffset) Utils.UnixTimeToDateTime(startTime), Utils.UnixTimeToDateTime(timeout), threshold) + : this(name, bit, (DateTimeOffset)Utils.UnixTimeToDateTime(startTime), Utils.UnixTimeToDateTime(timeout), threshold) { } @@ -53,13 +53,12 @@ public DateTimeOffset Timeout private set; } - public string Name + public string Name { get; private set; } - /// Specifies the activation threshold for this deployment. The BIP9 specification originally set the threshold at >=1916 blocks (95% of 2016), /// or >=1512 for testnet (75% of 2016). public long Threshold @@ -68,4 +67,4 @@ public long Threshold private set; } } -} +} \ No newline at end of file diff --git a/src/Blockcore/Base/Deployments/BIP9DeploymentsArray.cs b/src/Blockcore/Base/Deployments/BIP9DeploymentsArray.cs index 3916c253e..4da9a73d2 100644 --- a/src/Blockcore/Base/Deployments/BIP9DeploymentsArray.cs +++ b/src/Blockcore/Base/Deployments/BIP9DeploymentsArray.cs @@ -10,6 +10,7 @@ namespace Blockcore.Base.Deployments public class BIP9DeploymentFlags { public ScriptVerify ScriptFlags { get; set; } + public Transaction.LockTimeFlags LockTimeFlags { get; set; } public BIP9DeploymentFlags() diff --git a/src/Blockcore/Broadcasters/BroadcasterBase.cs b/src/Blockcore/Broadcasters/BroadcasterBase.cs index 83d041c90..a1779b921 100644 --- a/src/Blockcore/Broadcasters/BroadcasterBase.cs +++ b/src/Blockcore/Broadcasters/BroadcasterBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Blockcore.AsyncWork; using Blockcore.EventBus; using Blockcore.Utilities; @@ -38,7 +39,7 @@ public void Init(ClientEventBroadcasterSettings broadcasterSettings) this.asyncLoop = this.asyncProvider.CreateAndRunAsyncLoop( $"Broadcast {this.GetType().Name}", - async token => + token => { if (this.eventsHub.HasConsumers) { @@ -47,6 +48,8 @@ public void Init(ClientEventBroadcasterSettings broadcasterSettings) this.eventsHub.OnEvent(clientEvent); } } + + return Task.CompletedTask; }, this.nodeLifetime.ApplicationStopping, repeatEvery: TimeSpan.FromSeconds(Math.Max(broadcasterSettings.BroadcastFrequencySeconds, 5)), diff --git a/src/Blockcore/Consensus/BlockInfo/Block.cs b/src/Blockcore/Consensus/BlockInfo/Block.cs index 15d77f1ac..662e1c041 100644 --- a/src/Blockcore/Consensus/BlockInfo/Block.cs +++ b/src/Blockcore/Consensus/BlockInfo/Block.cs @@ -116,6 +116,7 @@ public Block WithOptions(ConsensusFactory consensusFactory, TransactionOptions o instance.ReadWrite(bms); } + return instance; } diff --git a/src/Blockcore/Consensus/BlockInfo/BlockHeader.cs b/src/Blockcore/Consensus/BlockInfo/BlockHeader.cs index caf5e61c2..6435e93aa 100644 --- a/src/Blockcore/Consensus/BlockInfo/BlockHeader.cs +++ b/src/Blockcore/Consensus/BlockInfo/BlockHeader.cs @@ -22,15 +22,18 @@ public class BlockHeader : IBitcoinSerializable /// Current header version. public virtual int CurrentVersion => 3; - private static BigInteger Pow256 = BigInteger.ValueOf(2).Pow(256); + private static BigInteger pow256 = BigInteger.ValueOf(2).Pow(256); private uint256 hashPrevBlock; + public uint256 HashPrevBlock { get { return this.hashPrevBlock; } set { this.hashPrevBlock = value; } } private uint time; + public uint Time { get { return this.time; } set { this.time = value; } } private uint bits; + public Target Bits { get { return this.bits; } set { this.bits = value; } } protected int version; @@ -38,9 +41,11 @@ public class BlockHeader : IBitcoinSerializable public int Version { get { return this.version; } set { this.version = value; } } private uint nonce; + public uint Nonce { get { return this.nonce; } set { this.nonce = value; } } private uint256 hashMerkleRoot; + public uint256 HashMerkleRoot { get { return this.hashMerkleRoot; } set { this.hashMerkleRoot = value; } } public bool IsNull { get { return (this.bits == 0); } } @@ -55,6 +60,7 @@ public DateTimeOffset BlockTime { return Utils.UnixTimeToDateTime(this.time); } + set { this.time = Utils.DateTimeToUnixTime(value); @@ -98,7 +104,7 @@ public virtual void ReadWrite(BitcoinStream stream) stream.ReadWrite(ref this.nonce); } - #endregion + #endregion IBitcoinSerializable Members /// Populates stream with items that will be used during hash calculation. protected virtual void ReadWriteHashingStream(BitcoinStream stream) @@ -173,7 +179,7 @@ public void PrecomputeHash(bool invalidateExisting = false, bool lazily = false) public bool CheckProofOfWork() { BigInteger bits = this.Bits.ToBigInteger(); - if ((bits.CompareTo(BigInteger.Zero) <= 0) || (bits.CompareTo(Pow256) >= 0)) + if ((bits.CompareTo(BigInteger.Zero) <= 0) || (bits.CompareTo(pow256) >= 0)) return false; return this.GetPoWHash() <= this.Bits.ToUInt256(); @@ -226,4 +232,4 @@ public Target GetWorkRequired(IConsensus consensus, ChainedHeader prev) return new ChainedHeader(this, this.GetHash(), prev).GetWorkRequired(consensus); } } -} +} \ No newline at end of file diff --git a/src/Blockcore/Consensus/BlockInfo/BlockSignature.cs b/src/Blockcore/Consensus/BlockInfo/BlockSignature.cs index cbcadd117..ee296fe58 100644 --- a/src/Blockcore/Consensus/BlockInfo/BlockSignature.cs +++ b/src/Blockcore/Consensus/BlockInfo/BlockSignature.cs @@ -18,8 +18,8 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((BlockSignature) obj); + if (obj.GetType() != this.GetType()) return false; + return this.Equals((BlockSignature)obj); } public override int GetHashCode() @@ -40,6 +40,7 @@ public byte[] Signature { return this.signature; } + set { this.signature = value; @@ -79,11 +80,11 @@ public void ReadWrite(BitcoinStream stream) stream.ReadWriteAsVarString(ref this.signature); } - #endregion + #endregion IBitcoinSerializable Members public override string ToString() { return Encoders.Hex.EncodeData(this.signature); } } -} +} \ No newline at end of file diff --git a/src/Blockcore/Consensus/BlockInfo/BlockStake.cs b/src/Blockcore/Consensus/BlockInfo/BlockStake.cs index 9dbcf04a8..54cae3872 100644 --- a/src/Blockcore/Consensus/BlockInfo/BlockStake.cs +++ b/src/Blockcore/Consensus/BlockInfo/BlockStake.cs @@ -15,9 +15,11 @@ namespace Blockcore.Consensus.BlockInfo public enum BlockFlag //block index flags { BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block + BLOCK_STAKE_ENTROPY = (1 << 1), // entropy bit for stake modifier + BLOCK_STAKE_MODIFIER = (1 << 2), // regenerated stake modifier - }; + } public class BlockStake : IBitcoinSerializable { @@ -45,6 +47,7 @@ public BlockFlag Flags { return (BlockFlag)this.flags; } + set { this.flags = (int)value; @@ -67,11 +70,13 @@ public void ReadWrite(BitcoinStream stream) stream.ReadWrite(ref this.Mint); stream.ReadWrite(ref this.StakeModifier); stream.ReadWrite(ref this.StakeModifierV2); + if (this.IsProofOfStake()) { stream.ReadWrite(ref this.PrevoutStake); stream.ReadWrite(ref this.StakeTime); } + stream.ReadWrite(ref this.HashProof); } @@ -181,6 +186,7 @@ public uint Time { return this.nTime; } + set { this.nTime = value; @@ -250,6 +256,7 @@ public override void ReadWrite(BitcoinStream stream) stream.ReadWrite(ref this.vout); this.vout.Transaction = this; } + if (((flags & 1) != 0) && witSupported) { /* The witness flag is present, and we support witnesses. */ @@ -257,6 +264,7 @@ public override void ReadWrite(BitcoinStream stream) var wit = new Witness(this.Inputs); wit.ReadWrite(stream); } + if (flags != 0) { /* Unknown flag in the serialization */ @@ -279,6 +287,7 @@ public override void ReadWrite(BitcoinStream stream) flags |= 1; } } + if (flags != 0) { /* Use extended format in case witnesses are to be serialized. */ @@ -286,6 +295,7 @@ public override void ReadWrite(BitcoinStream stream) stream.ReadWrite(ref vinDummy); stream.ReadWrite(ref flags); } + stream.ReadWrite(ref this.vin); this.vin.Transaction = this; stream.ReadWrite(ref this.vout); @@ -296,6 +306,7 @@ public override void ReadWrite(BitcoinStream stream) wit.ReadWrite(stream); } } + stream.ReadWriteStruct(ref this.nLockTime); } } diff --git a/src/Blockcore/Consensus/Chain/ChainIndexer.cs b/src/Blockcore/Consensus/Chain/ChainIndexer.cs index 02b992cdd..0815b1b2a 100644 --- a/src/Blockcore/Consensus/Chain/ChainIndexer.cs +++ b/src/Blockcore/Consensus/Chain/ChainIndexer.cs @@ -30,6 +30,7 @@ public class ChainIndexer /// The tip height of the best known validated chain. /// public int Height => this.Tip.Height; + public ChainedHeader Genesis => this.GetHeader(0); public ChainIndexer() @@ -39,7 +40,7 @@ public ChainIndexer() } public ChainIndexer(Network network) : this() - { + { this.Network = network; this.Initialize(new ChainedHeader(network.GetGenesis().Header, network.GetGenesis().GetHash(), 0)); @@ -78,7 +79,7 @@ public void Initialize(ChainedHeader chainedHeader) this.Tip = chainedHeader; } } - + /// /// Returns the first chained block header that exists in the chain from the list of block hashes. /// @@ -187,7 +188,7 @@ public void Add(ChainedHeader addTip) { lock (this.lockObject) { - if(this.Tip.HashBlock != addTip.Previous.HashBlock) + if (this.Tip.HashBlock != addTip.Previous.HashBlock) throw new InvalidOperationException("New tip must be consecutive"); this.blocksById.Add(addTip.HashBlock, addTip); diff --git a/src/Blockcore/Consensus/Chain/ChainStore.cs b/src/Blockcore/Consensus/Chain/ChainStore.cs index d2b41634a..7b6a1dbac 100644 --- a/src/Blockcore/Consensus/Chain/ChainStore.cs +++ b/src/Blockcore/Consensus/Chain/ChainStore.cs @@ -48,6 +48,7 @@ public void ReadWrite(BitcoinStream stream) public class ChainDataItem { public int Height { get; set; } + public ChainData Data { get; set; } } diff --git a/src/Blockcore/Consensus/Chain/ChainedHeader.cs b/src/Blockcore/Consensus/Chain/ChainedHeader.cs index 758a14524..c9466d21b 100644 --- a/src/Blockcore/Consensus/Chain/ChainedHeader.cs +++ b/src/Blockcore/Consensus/Chain/ChainedHeader.cs @@ -60,7 +60,7 @@ public enum ValidationState public class ChainedHeader { /// Value of 2^256. - private static BigInteger Pow256 = BigInteger.ValueOf(2).Pow(256); + private static BigInteger pow256 = BigInteger.ValueOf(2).Pow(256); /// Window length for calculating median time span. private const int MedianTimeSpan = 11; @@ -77,9 +77,6 @@ public class ChainedHeader /// Height of the entry in the chain. The genesis block has height 0. public int Height { get; private set; } - /// Block header for this entry. - //public BlockHeader Header { get; private set; } - public BlockHeader Header { get @@ -253,8 +250,10 @@ public ChainedHeader(BlockHeader header, uint256 headerHash, int height) : this( this.CalculateChainWork(); if (header is PosBlockHeader posBlockHeader) + { if (posBlockHeader.ProvenBlockHeader != null) this.ProvenBlockHeader = posBlockHeader.ProvenBlockHeader; + } } /// @@ -284,10 +283,10 @@ public BigInteger GetBlockTarget() { BigInteger target = this.Header.Bits.ToBigInteger(); - if ((target.CompareTo(BigInteger.Zero) <= 0) || (target.CompareTo(Pow256) >= 0)) + if ((target.CompareTo(BigInteger.Zero) <= 0) || (target.CompareTo(pow256) >= 0)) return BigInteger.Zero; - return Pow256.Divide(target.Add(BigInteger.One)); + return pow256.Divide(target.Add(BigInteger.One)); } /// Gets a for this chain entry. diff --git a/src/Blockcore/Consensus/ScriptAddressResult.cs b/src/Blockcore/Consensus/ScriptAddressResult.cs index 9aa1dede4..fc10c1865 100644 --- a/src/Blockcore/Consensus/ScriptAddressResult.cs +++ b/src/Blockcore/Consensus/ScriptAddressResult.cs @@ -37,6 +37,5 @@ public bool IsNullOrEmpty() /// Will return the script cold public address if exists, Otherwise returns /// public string ColdAddress { get; set; } = string.Empty; - } -} +} \ No newline at end of file diff --git a/src/Blockcore/Consensus/ScriptInfo/StandardScripts.cs b/src/Blockcore/Consensus/ScriptInfo/StandardScripts.cs index ca6518668..74251670d 100644 --- a/src/Blockcore/Consensus/ScriptInfo/StandardScripts.cs +++ b/src/Blockcore/Consensus/ScriptInfo/StandardScripts.cs @@ -9,7 +9,7 @@ namespace Blockcore.Consensus.ScriptInfo { public static class StandardScripts { - public static readonly List standardTemplates = new List + public static readonly List StandardTemplates = new List { PayToPubkeyHashTemplate.Instance, PayToPubkeyTemplate.Instance, @@ -25,8 +25,8 @@ public static class StandardScripts /// The standard script template to register. public static void RegisterStandardScriptTemplate(ScriptTemplate scriptTemplate) { - if (!standardTemplates.Any(template => (template.Type == scriptTemplate.Type))) - standardTemplates.Add(scriptTemplate); + if (!StandardTemplates.Any(template => (template.Type == scriptTemplate.Type))) + StandardTemplates.Add(scriptTemplate); } public static bool IsStandardTransaction(Transaction tx, Network network) @@ -41,12 +41,12 @@ public static bool AreOutputsStandard(Network network, Transaction tx) public static ScriptTemplate GetTemplateFromScriptPubKey(Script script) { - return standardTemplates.FirstOrDefault(t => t.CheckScriptPubKey(script)); + return StandardTemplates.FirstOrDefault(t => t.CheckScriptPubKey(script)); } public static bool IsStandardScriptPubKey(Network network, Script scriptPubKey) { - return standardTemplates.Any(template => template.CheckScriptPubKey(scriptPubKey)); + return StandardTemplates.Any(template => template.CheckScriptPubKey(scriptPubKey)); } private static bool IsStandardScriptSig(Network network, Script scriptSig, Script scriptPubKey) diff --git a/src/Blockcore/Networks/NetworkRegistration.cs b/src/Blockcore/Networks/NetworkRegistration.cs index e7d73111c..4ecbc62ab 100644 --- a/src/Blockcore/Networks/NetworkRegistration.cs +++ b/src/Blockcore/Networks/NetworkRegistration.cs @@ -11,12 +11,12 @@ namespace Blockcore.Networks /// public static class NetworkRegistration { - private static readonly ConcurrentDictionary registeredNetworks = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary RegisteredNetworks = new ConcurrentDictionary(); /// /// Register an immutable instance so it is queryable through and . /// - /// If the network already exists, the already registered instance will be returned from the collection. + /// If the network already exists, the already registered instance will be returned from the collection. /// /// public static Network Register(Network network) @@ -38,18 +38,18 @@ public static Network Register(Network network) if (network.Consensus == null) throw new InvalidOperationException("A consensus needs to be provided."); - registeredNetworks.TryAdd(networkName.ToLowerInvariant(), network); + RegisteredNetworks.TryAdd(networkName.ToLowerInvariant(), network); } return network; } /// - /// Clears the collection. + /// Clears the collection. /// public static void Clear() { - registeredNetworks.Clear(); + RegisteredNetworks.Clear(); } /// @@ -59,17 +59,17 @@ public static void Clear() /// The network or null of the name does not match any network. public static Network GetNetwork(string name) { - if (!registeredNetworks.Any()) + if (!RegisteredNetworks.Any()) return null; - return registeredNetworks.TryGet(name.ToLowerInvariant()); + return RegisteredNetworks.TryGet(name.ToLowerInvariant()); } public static IEnumerable GetNetworks() { - if (registeredNetworks.Any()) + if (RegisteredNetworks.Any()) { - List others = registeredNetworks.Values.Distinct().ToList(); + List others = RegisteredNetworks.Values.Distinct().ToList(); foreach (Network network in others) yield return network; @@ -89,6 +89,7 @@ internal static Network GetNetworkFromBase58Data(string base58, Base58Type? expe return network; } } + return null; } } diff --git a/src/Blockcore/Utilities/AsyncManualResetEvent.cs b/src/Blockcore/Utilities/AsyncManualResetEvent.cs index 97404bfbd..135053083 100644 --- a/src/Blockcore/Utilities/AsyncManualResetEvent.cs +++ b/src/Blockcore/Utilities/AsyncManualResetEvent.cs @@ -117,7 +117,7 @@ public async Task WaitAsync(CancellationToken cancellationToken) } /// - /// Sets the event, atomically completing every task returned by . If the event is already set, this method does nothing. + /// Sets the event, atomically completing every task returned by . If the event is already set, this method does nothing. /// public void Set() { @@ -148,4 +148,4 @@ private TaskCompletionSource CreateAsyncTaskSource() return new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } } -} +} \ No newline at end of file diff --git a/src/Blockcore/Utilities/ReaderWriterLock.cs b/src/Blockcore/Utilities/ReaderWriterLock.cs index f8d717e3d..5a22fa746 100644 --- a/src/Blockcore/Utilities/ReaderWriterLock.cs +++ b/src/Blockcore/Utilities/ReaderWriterLock.cs @@ -42,6 +42,7 @@ public IDisposable LockWrite() internal bool TryLockWrite(out IDisposable locked) { locked = null; + if (this.rwLock.TryEnterWriteLock(0)) { locked = new ActionDisposable(() => @@ -49,6 +50,7 @@ internal bool TryLockWrite(out IDisposable locked) }, () => this.rwLock.ExitWriteLock()); return true; } + return false; } } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 8ab2d1d63..c70a6e018 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -6,7 +6,6 @@ false Blockcore MIT - $(MSBuildThisFileDirectory)None.ruleset https://www.blockcore.net git git://github.com/block-core/blockcore diff --git a/src/Features/Blockcore.Features.MemoryPool/FeeFilter/FeeFilterBehavior.cs b/src/Features/Blockcore.Features.MemoryPool/FeeFilter/FeeFilterBehavior.cs index 6d4a7c284..a46f15d74 100644 --- a/src/Features/Blockcore.Features.MemoryPool/FeeFilter/FeeFilterBehavior.cs +++ b/src/Features/Blockcore.Features.MemoryPool/FeeFilter/FeeFilterBehavior.cs @@ -52,7 +52,7 @@ public FeeFilterBehavior( this.logger = loggerFactory.CreateLogger(this.GetType().FullName); } - private async Task ProcessFeeFilterAsync(INetworkPeer peer, FeeFilterPayload feeFilter) + private Task ProcessFeeFilterAsync(INetworkPeer peer, FeeFilterPayload feeFilter) { if (peer.PeerVersion.Relay) { @@ -66,6 +66,8 @@ private async Task ProcessFeeFilterAsync(INetworkPeer peer, FeeFilterPayload fee this.logger.LogDebug("Received feefilter of `{0}` from peer id: {1}", feeFilter.NewFeeFilter, peer.Connection.Id); } } + + return Task.CompletedTask; } private void StartFeeFilterBroadcast(INetworkPeer sender) @@ -168,7 +170,7 @@ protected override void AttachCore() this.AttachedPeer.MessageReceived.Register(this.OnMessageReceivedAsync); } - private async Task OnStateChangedAsync(INetworkPeer sender, NetworkPeerState arg) + private Task OnStateChangedAsync(INetworkPeer sender, NetworkPeerState arg) { if (arg == NetworkPeerState.HandShaked) { @@ -183,6 +185,8 @@ private async Task OnStateChangedAsync(INetworkPeer sender, NetworkPeerState arg this.asyncLoop = null; } } + + return Task.CompletedTask; } protected override void DetachCore() diff --git a/src/Features/Blockcore.Features.WalletWatchOnly/API/Controllers/WatchOnlyWalleRPCController.cs b/src/Features/Blockcore.Features.WalletWatchOnly/API/Controllers/WatchOnlyWalleRPCController.cs index 0013e5477..f0f5f3413 100644 --- a/src/Features/Blockcore.Features.WalletWatchOnly/API/Controllers/WatchOnlyWalleRPCController.cs +++ b/src/Features/Blockcore.Features.WalletWatchOnly/API/Controllers/WatchOnlyWalleRPCController.cs @@ -55,7 +55,9 @@ public class WatchOnlyWalleRPCController : FeatureController /// /// The wallet name set by selectwallet method. This is static since the controller is a stateless type. This value should probably be cached by an injected service in the future. /// +#pragma warning disable 649 private static readonly string CurrentWalletName; +#pragma warning restore 649 /// public WatchOnlyWalleRPCController( From 2c61b246b3d3a9f73818fea3a4881d7bcc39bdb2 Mon Sep 17 00:00:00 2001 From: dangershony Date: Fri, 4 Dec 2020 19:06:50 +0000 Subject: [PATCH 4/9] Fix warnings on UI elements --- .../UI/Pages/Stake.razor | 1 + .../NodeHostFeature.cs | 4 +- .../UI/Pages/Logs.razor | 7 +- .../UI/Pages/Modal/ModalWalletCreate.razor | 121 +++++++++--------- .../UI/Pages/Modal/ModalWalletRecover.razor | 120 ++++++++--------- .../UI/Pages/Wallets.razor | 4 +- 6 files changed, 132 insertions(+), 125 deletions(-) diff --git a/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor b/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor index 9b6b1073b..a0771037f 100644 --- a/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor +++ b/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor @@ -370,6 +370,7 @@ else this.MiningFeature.StartStaking(this.WalletName, this.Password); this.LoadStats(); + await Task.CompletedTask; } private bool IsStarting { get; set; } private async Task callStartStaking() diff --git a/src/Features/Blockcore.Features.NodeHost/NodeHostFeature.cs b/src/Features/Blockcore.Features.NodeHost/NodeHostFeature.cs index d61d3c1f1..0866ad67b 100644 --- a/src/Features/Blockcore.Features.NodeHost/NodeHostFeature.cs +++ b/src/Features/Blockcore.Features.NodeHost/NodeHostFeature.cs @@ -22,8 +22,6 @@ namespace Blockcore.Features.NodeHost /// public sealed class NodeHostFeature : FullNodeFeature { - internal static Dictionary eventBroadcasterSettings; - /// How long we are willing to wait for the NodeHost to stop. private const int NodeHostStopTimeoutSeconds = 10; @@ -137,4 +135,4 @@ public static IFullNodeBuilder UseNodeHost(this IFullNodeBuilder fullNodeBuilder return fullNodeBuilder; } } -} +} \ No newline at end of file diff --git a/src/Features/Blockcore.Features.NodeHost/UI/Pages/Logs.razor b/src/Features/Blockcore.Features.NodeHost/UI/Pages/Logs.razor index 7d9f0e32d..836856ba1 100644 --- a/src/Features/Blockcore.Features.NodeHost/UI/Pages/Logs.razor +++ b/src/Features/Blockcore.Features.NodeHost/UI/Pages/Logs.razor @@ -5,7 +5,7 @@

Node Logs

- +
@@ -15,5 +15,8 @@ } @code { - private async Task ReloadPage(){} + private async Task ReloadPage() + { + await Task.CompletedTask; + } } \ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletCreate.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletCreate.razor index 0ff98b766..b69314e9e 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletCreate.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletCreate.razor @@ -11,79 +11,81 @@ @if (ShowForm) { -
-
-
-
-
- -
- +
+
+
+
+
+ +
+ +
+
+ +
-
- -
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- -
- -
- + +
+ +
+ +
+
+ @if (IsSubmitting) + { + + } + else + { + + } +
+
@Alert
-
- @if (IsSubmitting) - { - - } - else - { - - } -
-
@Alert
-
-} else { -
-
-
-
-
@Alert
- +} +else +{ +
+
+
+
+
@Alert
+ +
-
} @code { - bool ShowForm { get; set; } = true; + bool ShowForm { get; set; } = true; public string WalletName { get; set; } public string Mnemonic { get; set; } private string Password { get; set; } @@ -100,7 +102,7 @@ StateHasChanged(); await Task.Delay(1); } - private async Task CreateWallet() + private async Task CreateWallet() { if (string.IsNullOrEmpty(this.Mnemonic)) { this.Alert = "Ensure that you have generated a new Mnemonic"; return; } if (string.IsNullOrEmpty(this.WalletName)) { this.Alert = "Please enter a wallet name"; return; } @@ -114,6 +116,7 @@ this.WalletSyncManager.SyncFromDate(this.DateTimeProvider.GetUtcNow()); this.Alert = "Your wallet has now been created."; ShowForm = false; + await Task.CompletedTask; } private void GenerateMnemonic() { diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletRecover.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletRecover.razor index 083793b73..a6a7f1366 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletRecover.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/Modal/ModalWalletRecover.razor @@ -11,83 +11,85 @@ @if (ShowForm) { -
-
-
-
-
- -
- +
+
+
+
+
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
- -
- -
- + +
+ +
+ +
+
+ @if (IsSubmitting) + { + + } + else + { + + } +
+
@Alert
-
- @if (IsSubmitting) - { - - } - else - { - - } -
-
@Alert
-
-} else { -
-
-
-
-
@Alert
- +} +else +{ +
+
+
+
+
@Alert
+ +
-
} @code { - - bool ShowForm { get; set; } = true; + + bool ShowForm { get; set; } = true; private void CloseModal() { - ModalService.Close(); + ModalService.Close(); NavigationManager.NavigateTo("walletview/" + WalletName + "/account 0"); StateHasChanged(); } - + public string WalletName { get; set; } public string Mnemonic { get; set; } private string Password { get; set; } @@ -115,6 +117,6 @@ var wallet = this.WalletManager.RecoverWallet(this.Password, this.WalletName, this.Mnemonic, this.DateTimeProvider.GetUtcNow(), passphrase: this.Passphrase); this.Alert = "Your wallet has now been recovered."; ShowForm = false; + await Task.CompletedTask; } - } \ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor index 23c2c5004..9d57d27ad 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor @@ -81,10 +81,10 @@ - -
From da8e393b84635df98a6a5a7e9ba651bc61499767 Mon Sep 17 00:00:00 2001 From: dangershony Date: Fri, 4 Dec 2020 19:13:03 +0000 Subject: [PATCH 5/9] From now on treat warnings as errors --- src/Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c70a6e018..33a2a05af 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -42,5 +42,6 @@ 1591;1572;1573;1574 + true \ No newline at end of file From 6fc3d50739e1b36012a5a570f77967e87e9c4960 Mon Sep 17 00:00:00 2001 From: dangershony Date: Sat, 5 Dec 2020 18:34:02 +0000 Subject: [PATCH 6/9] fix warning --- src/Blockcore/Builder/FullNodeBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Blockcore/Builder/FullNodeBuilder.cs b/src/Blockcore/Builder/FullNodeBuilder.cs index 4c6dade60..2d9eb7bb3 100644 --- a/src/Blockcore/Builder/FullNodeBuilder.cs +++ b/src/Blockcore/Builder/FullNodeBuilder.cs @@ -228,6 +228,7 @@ private IServiceCollection BuildServices() { this.PersistenceProviderManager = new PersistenceProviderManager(this.NodeSettings); } + this.PersistenceProviderManager.Initialize(); // register services before features From b7fd4f0656382599f8b699cc3fe4eb66198dd180 Mon Sep 17 00:00:00 2001 From: dangershony Date: Sat, 5 Dec 2020 21:38:08 +0000 Subject: [PATCH 7/9] Fix rocks db proj reference name --- ...lockcore.Features.Persistence.LevelDb.CorePackage.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Features/Persistence/Blockcore.Features.Persistence.LevelDb.CorePackage/Blockcore.Features.Persistence.LevelDb.CorePackage.csproj b/src/Features/Persistence/Blockcore.Features.Persistence.LevelDb.CorePackage/Blockcore.Features.Persistence.LevelDb.CorePackage.csproj index 75ab916e8..c5d085ee3 100644 --- a/src/Features/Persistence/Blockcore.Features.Persistence.LevelDb.CorePackage/Blockcore.Features.Persistence.LevelDb.CorePackage.csproj +++ b/src/Features/Persistence/Blockcore.Features.Persistence.LevelDb.CorePackage/Blockcore.Features.Persistence.LevelDb.CorePackage.csproj @@ -2,9 +2,9 @@ LevelDb persistence package for core features - Blockcore.Features.Persistence.LevelDb.Package - Blockcore.Features.Persistence.LevelDb.Package - Blockcore.Features.Persistence.LevelDb.Package + Blockcore.Features.Persistence.LevelDb.CorePackage + Blockcore.Features.Persistence.LevelDb.CorePackage + Blockcore.Features.Persistence.LevelDb.CorePackage False Blockcore true From db402ae58f042987dae483ec75e78b7a1b7c7629 Mon Sep 17 00:00:00 2001 From: dangershony Date: Mon, 7 Dec 2020 00:01:26 +0000 Subject: [PATCH 8/9] Fix persistance to separate pow and pow --- .../FullNodeBuilderConsensusExtension.cs | 4 +-- .../PersistenceProvider.cs | 12 ++++++++- .../PersistenceProvider.cs | 12 ++++++++- .../ColdStakingTests.cs | 4 +-- .../ConsensusManagerTests.cs | 4 +-- .../TestPersistenceProviderManager.cs | 27 ++++++++++++++----- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/Features/Blockcore.Features.Consensus/FullNodeBuilderConsensusExtension.cs b/src/Features/Blockcore.Features.Consensus/FullNodeBuilderConsensusExtension.cs index b421d23ca..3b5952332 100644 --- a/src/Features/Blockcore.Features.Consensus/FullNodeBuilderConsensusExtension.cs +++ b/src/Features/Blockcore.Features.Consensus/FullNodeBuilderConsensusExtension.cs @@ -28,7 +28,7 @@ public static IFullNodeBuilder UsePowConsensus(this IFullNodeBuilder fullNodeBui .AddFeature() .FeatureServices(services => { - fullNodeBuilder.PersistenceProviderManager.RequirePersistence(services); + fullNodeBuilder.PersistenceProviderManager.RequirePersistence(services); services.AddSingleton(); services.AddSingleton(); @@ -53,7 +53,7 @@ public static IFullNodeBuilder UsePosConsensus(this IFullNodeBuilder fullNodeBui .AddFeature() .FeatureServices(services => { - fullNodeBuilder.PersistenceProviderManager.RequirePersistence(services); + fullNodeBuilder.PersistenceProviderManager.RequirePersistence(services); services.AddSingleton(provider => (IStakdb)provider.GetService()); services.AddSingleton(); diff --git a/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.LevelDb/PersistenceProvider.cs b/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.LevelDb/PersistenceProvider.cs index bec452b5c..969c45902 100644 --- a/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.LevelDb/PersistenceProvider.cs +++ b/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.LevelDb/PersistenceProvider.cs @@ -6,7 +6,17 @@ namespace Blockcore.Features.Consensus.Persistence.LevelDb { - public class PersistenceProvider : PersistenceProviderBase + public class PowPersistenceProvider : PersistenceProviderBase + { + public override string Tag => LevelDbPersistence.Name; + + public override void AddRequiredServices(IServiceCollection services) + { + services.AddSingleton(); + } + } + + public class PosPersistenceProvider : PersistenceProviderBase { public override string Tag => LevelDbPersistence.Name; diff --git a/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.RocksDb/PersistenceProvider.cs b/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.RocksDb/PersistenceProvider.cs index 9118c0481..de96a6d03 100644 --- a/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.RocksDb/PersistenceProvider.cs +++ b/src/Features/Persistence/Blockcore.Features.Consensus.Persistence.RocksDb/PersistenceProvider.cs @@ -6,7 +6,17 @@ namespace Blockcore.Features.Consensus.Persistence.RocksDb { - public class PersistenceProvider : PersistenceProviderBase + public class PowPersistenceProvider : PersistenceProviderBase + { + public override string Tag => RocksDbPersistence.Name; + + public override void AddRequiredServices(IServiceCollection services) + { + services.AddSingleton(); + } + } + + public class PosPersistenceProvider : PersistenceProviderBase { public override string Tag => RocksDbPersistence.Name; diff --git a/src/Tests/Blockcore.IntegrationTests/ColdStakingTests.cs b/src/Tests/Blockcore.IntegrationTests/ColdStakingTests.cs index a9465d111..d56620645 100644 --- a/src/Tests/Blockcore.IntegrationTests/ColdStakingTests.cs +++ b/src/Tests/Blockcore.IntegrationTests/ColdStakingTests.cs @@ -21,9 +21,9 @@ namespace Blockcore.IntegrationTests ///
public class StratisOverrideRegTest : StratisRegTest { - public StratisOverrideRegTest() : base() + public StratisOverrideRegTest(string name = null) : base() { - this.Name = Guid.NewGuid().ToString(); + this.Name = name ?? Guid.NewGuid().ToString(); } } diff --git a/src/Tests/Blockcore.IntegrationTests/ConsensusManagerTests.cs b/src/Tests/Blockcore.IntegrationTests/ConsensusManagerTests.cs index ed67ed945..6e7e68e8d 100644 --- a/src/Tests/Blockcore.IntegrationTests/ConsensusManagerTests.cs +++ b/src/Tests/Blockcore.IntegrationTests/ConsensusManagerTests.cs @@ -523,7 +523,7 @@ public void ConsensusManager_Fork_Occurs_When_Stake_Coins_Are_Spent_And_Found_In { using (NodeBuilder builder = NodeBuilder.Create(this)) { - var network = new StratisOverrideRegTest(); + var network = new StratisOverrideRegTest("stake_coins"); var sharedMnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve).ToString(); @@ -588,7 +588,7 @@ public void ConsensusManager_Fork_Occurs_When_Stake_Coins_Are_Mined_And_Found_In { using (NodeBuilder builder = NodeBuilder.Create(this)) { - var network = new StratisOverrideRegTest(); + var network = new StratisOverrideRegTest("mined_coins"); var sharedMnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve).ToString(); diff --git a/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs b/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs index 83531cded..58c888a9f 100644 --- a/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs +++ b/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs @@ -16,13 +16,26 @@ public TestPersistenceProviderManager(NodeSettings nodeSettings) : base(nodeSett public override void Initialize() { - // manually register LevelDb implementation - this.persistenceProviders["LevelDb".ToLowerInvariant()] = new System.Collections.Generic.List + if (this.nodeSettings.Network.Consensus.IsProofOfStake) { - new Features.Base.Persistence.LevelDb.PersistenceProvider(), - new Features.Consensus.Persistence.LevelDb.PersistenceProvider(), - new Features.BlockStore.Persistence.LevelDb.PersistenceProvider(), - }; + // manually register LevelDb implementation + this.persistenceProviders["LevelDb".ToLowerInvariant()] = new System.Collections.Generic.List + { + new Features.Base.Persistence.LevelDb.PersistenceProvider(), + new Features.Consensus.Persistence.LevelDb.PosPersistenceProvider(), + new Features.BlockStore.Persistence.LevelDb.PersistenceProvider(), + }; + } + else + { + // manually register LevelDb implementation + this.persistenceProviders["LevelDb".ToLowerInvariant()] = new System.Collections.Generic.List + { + new Features.Base.Persistence.LevelDb.PersistenceProvider(), + new Features.Consensus.Persistence.LevelDb.PowPersistenceProvider(), + new Features.BlockStore.Persistence.LevelDb.PersistenceProvider(), + }; + } } } -} +} \ No newline at end of file From e894867364007b0c7f6ecce91863595baceb57af Mon Sep 17 00:00:00 2001 From: dangershony Date: Mon, 7 Dec 2020 01:07:08 +0000 Subject: [PATCH 9/9] Fix unit tests --- .../ApiSettingsTest.cs | 32 ++++++++++++------- .../TestPersistenceProviderManager.cs | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Tests/Blockcore.Features.NodeHost.Tests/ApiSettingsTest.cs b/src/Tests/Blockcore.Features.NodeHost.Tests/ApiSettingsTest.cs index 46b6a13c1..46b0632e5 100644 --- a/src/Tests/Blockcore.Features.NodeHost.Tests/ApiSettingsTest.cs +++ b/src/Tests/Blockcore.Features.NodeHost.Tests/ApiSettingsTest.cs @@ -66,7 +66,7 @@ public void GivenApiPortIsProvided_ThenPortIsUsedWithDefaultApiUri() { // Arrange. int customPort = 55555; - var nodeSettings = new NodeSettings(this.Network, args:new[] { $"-apiport={customPort}" }); + var nodeSettings = new NodeSettings(this.Network, args: new[] { $"-apiport={customPort}" }); // Act. NodeHostSettings settings = FullNodeSetup(nodeSettings); @@ -85,12 +85,11 @@ public void GivenApiUriIsProvided_AndGivenBitcoinNetwork_ThenApiUriIsUsedWithDef // Arrange. string customApiUri = "http://0.0.0.0"; Network network = KnownNetworks.Main; - var nodeSettings = new NodeSettings(network, args:new[] { $"-apiuri={customApiUri}" }); + var nodeSettings = new NodeSettings(network, args: new[] { $"-apiuri={customApiUri}" }); // Act. NodeHostSettings settings = FullNodeSetup(nodeSettings); - // Assert. Assert.Equal(network.DefaultAPIPort, settings.ApiPort); Assert.Equal(new Uri($"{customApiUri}:{network.DefaultAPIPort}"), settings.ApiUri); @@ -105,7 +104,7 @@ public void GivenApiUriIsProvided_AndGivenStratisNetwork_ThenApiUriIsUsedWithDef // Arrange. string customApiUri = "http://0.0.0.0"; Network network = KnownNetworks.StratisMain; - var nodeSettings = new NodeSettings(network, args:new[] { $"-apiuri={customApiUri}" }); + var nodeSettings = new NodeSettings(network, args: new[] { $"-apiuri={customApiUri}" }); // Act. NodeHostSettings settings = FullNodeSetup(nodeSettings); @@ -125,7 +124,7 @@ public void GivenApiUri_AndApiPortIsProvided_AndGivenBitcoinNetwork_ThenApiUriIs string customApiUri = "http://0.0.0.0"; int customPort = 55555; Network network = KnownNetworks.Main; - var nodeSettings = new NodeSettings(network, args:new[] { $"-apiuri={customApiUri}", $"-apiport={customPort}" }); + var nodeSettings = new NodeSettings(network, args: new[] { $"-apiuri={customApiUri}", $"-apiport={customPort}" }); // Act. NodeHostSettings settings = FullNodeSetup(nodeSettings); @@ -145,7 +144,7 @@ public void GivenApiUriIncludingPortIsProvided_ThenUseThePassedApiUri() int customPort = 5522; string customApiUri = $"http://0.0.0.0:{customPort}"; Network network = KnownNetworks.Main; - var nodeSettings = new NodeSettings(network, args:new[] { $"-apiuri={customApiUri}" }); + var nodeSettings = new NodeSettings(network, args: new[] { $"-apiuri={customApiUri}" }); // Act. NodeHostSettings settings = FullNodeSetup(nodeSettings); @@ -267,13 +266,22 @@ public void GivenUseHttpsAndNoCertificateFilePath_ThenShouldThrowConfigurationEx private static NodeHostSettings FullNodeSetup(NodeSettings nodeSettings) { - return new FullNodeBuilder() + IFullNodeBuilder node = new FullNodeBuilder() .UsePersistenceProviderMananger(new TestPersistenceProviderManager(nodeSettings)) .UseNodeSettings(nodeSettings) - .UseNodeHost() - .UsePowConsensus() - .Build() - .NodeService(); + .UseNodeHost(); + + if (nodeSettings.Network.Consensus.IsProofOfStake) + { + node.UsePosConsensus(); + } + else + { + node.UsePowConsensus(); + } + + return node.Build() + .NodeService(); } } -} +} \ No newline at end of file diff --git a/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs b/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs index 58c888a9f..074fde398 100644 --- a/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs +++ b/src/Tests/Blockcore.Tests.Common/TestPersistenceProviderManager.cs @@ -16,7 +16,7 @@ public TestPersistenceProviderManager(NodeSettings nodeSettings) : base(nodeSett public override void Initialize() { - if (this.nodeSettings.Network.Consensus.IsProofOfStake) + if (this.nodeSettings != null && this.nodeSettings.Network.Consensus.IsProofOfStake) { // manually register LevelDb implementation this.persistenceProviders["LevelDb".ToLowerInvariant()] = new System.Collections.Generic.List