diff --git a/Src/Autarkysoft.Bitcoin/Blockchain/Consensus.cs b/Src/Autarkysoft.Bitcoin/Blockchain/Consensus.cs index ecf7c6d..db1849e 100644 --- a/Src/Autarkysoft.Bitcoin/Blockchain/Consensus.cs +++ b/Src/Autarkysoft.Bitcoin/Blockchain/Consensus.cs @@ -52,6 +52,7 @@ public Consensus(int height, NetworkType netType) { case NetworkType.MainNet: PowLimit = Digest256.ParseHex("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + AllowMinDifficultyBlocks = false; MaxSigOpCount = 80000; HalvingInterval = 210000; bip16 = 170060; @@ -64,6 +65,7 @@ public Consensus(int height, NetworkType netType) break; case NetworkType.TestNet: PowLimit = Digest256.ParseHex("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + AllowMinDifficultyBlocks = true; MaxSigOpCount = 80000; HalvingInterval = 210000; bip16 = 1718436; @@ -76,6 +78,7 @@ public Consensus(int height, NetworkType netType) break; case NetworkType.RegTest: PowLimit = Digest256.ParseHex("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + AllowMinDifficultyBlocks = true; MaxSigOpCount = 80000; HalvingInterval = 150; bip16 = 0; @@ -190,6 +193,9 @@ public ulong BlockReward /// public int MinBlockVersion => minBlkVer; + /// + public bool AllowMinDifficultyBlocks { get; } + /// public Digest256 PowLimit { get; } diff --git a/Src/Autarkysoft.Bitcoin/Blockchain/IConsensus.cs b/Src/Autarkysoft.Bitcoin/Blockchain/IConsensus.cs index fa1d30b..17bb5a7 100644 --- a/Src/Autarkysoft.Bitcoin/Blockchain/IConsensus.cs +++ b/Src/Autarkysoft.Bitcoin/Blockchain/IConsensus.cs @@ -90,6 +90,11 @@ public interface IConsensus /// int MinBlockVersion { get; } + /// + /// Allows fall back to minimum difficulty in TestNet + /// + bool AllowMinDifficultyBlocks { get; } + /// /// Proof of work limit /// diff --git a/Src/Denovo/Models/ConsensusModel.cs b/Src/Denovo/Models/ConsensusModel.cs index d130460..60a637f 100644 --- a/Src/Denovo/Models/ConsensusModel.cs +++ b/Src/Denovo/Models/ConsensusModel.cs @@ -143,7 +143,7 @@ public bool IsTaprootEnabled } public int MinBlockVersion => backup.MinBlockVersion; - + public bool AllowMinDifficultyBlocks => backup.AllowMinDifficultyBlocks; public Digest256 PowLimit => backup.PowLimit; public IBlock GetGenesisBlock() => backup.GetGenesisBlock(); diff --git a/Src/Tests/Bitcoin/Blockchain/MockConsensus.cs b/Src/Tests/Bitcoin/Blockchain/MockConsensus.cs index 0e5cb1a..845b428 100644 --- a/Src/Tests/Bitcoin/Blockchain/MockConsensus.cs +++ b/Src/Tests/Bitcoin/Blockchain/MockConsensus.cs @@ -155,6 +155,18 @@ public int MinBlockVersion } } + + internal bool? _allowMinDiff; + public bool AllowMinDifficultyBlocks + { + get + { + Assert.True(_allowMinDiff.HasValue, UnexpectedCall); + return _allowMinDiff.Value; + } + } + + internal Digest256? _powLimit; public Digest256 PowLimit {