Skip to content

Commit

Permalink
Add AllowMinDifficultyBlocks to (I)Consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Jul 28, 2024
1 parent eae2229 commit 839819a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Src/Autarkysoft.Bitcoin/Blockchain/Consensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -190,6 +193,9 @@ public ulong BlockReward
/// <inheritdoc/>
public int MinBlockVersion => minBlkVer;

/// <inheritdoc/>
public bool AllowMinDifficultyBlocks { get; }

/// <inheritdoc/>
public Digest256 PowLimit { get; }

Expand Down
5 changes: 5 additions & 0 deletions Src/Autarkysoft.Bitcoin/Blockchain/IConsensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public interface IConsensus
/// </summary>
int MinBlockVersion { get; }

/// <summary>
/// Allows fall back to minimum difficulty in TestNet
/// </summary>
bool AllowMinDifficultyBlocks { get; }

/// <summary>
/// Proof of work limit
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Src/Denovo/Models/ConsensusModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions Src/Tests/Bitcoin/Blockchain/MockConsensus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 839819a

Please sign in to comment.