Skip to content

Commit b83d16f

Browse files
Added blockmintxfee setting to BlockDefinitionOptions (#133)
* Added blockmintxfee setting to BlockDefinitionOptions Added RewardRequired Updated x42 consensus and added MinBlockFeeRate to consensus options. * Updated x42 consensus. * Added additional test node. * Removed RewardRequired and changed the reward check logic.
1 parent 0870ba0 commit b83d16f

9 files changed

Lines changed: 35 additions & 17 deletions

File tree

src/External/NBitcoin/ConsensusOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class ConsensusOptions
1919
/// <summary>The maximum allowed weight for a block, see BIP 141 (network rule)</summary>
2020
public uint MaxBlockWeight { get; set; }
2121

22+
/// <summary>Thee minimum feerate for a transaction in blocks mined.</summary>
23+
public long MinBlockFeeRate { get; set; }
24+
2225
/// <summary>The maximum allowed size for a serialized block, in bytes (only for buffer size limits). </summary>
2326
public uint MaxBlockSerializedSize { get; set; }
2427

@@ -59,6 +62,7 @@ public ConsensusOptions()
5962
// TODO: Remove this constructor. Should always set explicitly.
6063
this.MaxBlockSerializedSize = 4000000;
6164
this.MaxBlockWeight = 4000000;
65+
this.MinBlockFeeRate = 1000;
6266
this.WitnessScaleFactor = 4;
6367
this.MaxStandardVersion = 2;
6468
this.MaxStandardTxWeight = 400000;

src/Features/Blockcore.Features.Miner/BlockDefinitionOptions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public sealed class BlockDefinitionOptions
2020
/// <summary>Minimum fee rate for transactions to be included in blocks created by miner.</summary>
2121
public FeeRate BlockMinFeeRate { get; private set; }
2222

23-
public BlockDefinitionOptions(uint blockMaxWeight, uint blockMaxSize)
23+
public BlockDefinitionOptions(uint blockMaxWeight, uint blockMaxSize, int blockMinFeeRate)
2424
{
2525
this.BlockMaxWeight = blockMaxWeight;
2626
this.BlockMaxSize = blockMaxSize;
27-
this.BlockMinFeeRate = new FeeRate(PowMining.DefaultBlockMinTxFee); // TODO: Where should this be set, really?
27+
this.BlockMinFeeRate = new FeeRate(blockMinFeeRate);
2828
}
2929

3030
/// <summary>
@@ -36,6 +36,7 @@ public BlockDefinitionOptions RestrictForNetwork(Network network)
3636
uint minAllowedBlockWeight = MinBlockSize * (uint) network.Consensus.Options.WitnessScaleFactor;
3737
this.BlockMaxWeight = Math.Max(minAllowedBlockWeight, Math.Min(network.Consensus.Options.MaxBlockWeight, this.BlockMaxWeight));
3838
this.BlockMaxSize = Math.Max(MinBlockSize, Math.Min(network.Consensus.Options.MaxBlockSerializedSize, this.BlockMaxSize));
39+
this.BlockMinFeeRate = new FeeRate(Math.Max(network.Consensus.Options.MinBlockFeeRate, this.BlockMinFeeRate.FeePerK));
3940

4041
return this;
4142
}

src/Features/Blockcore.Features.Miner/MinerSettings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ public MinerSettings(NodeSettings nodeSettings)
9696

9797
uint blockMaxSize = (uint) config.GetOrDefault<int>("blockmaxsize", (int) nodeSettings.Network.Consensus.Options.MaxBlockSerializedSize, this.logger);
9898
uint blockMaxWeight = (uint) config.GetOrDefault<int>("blockmaxweight", (int) nodeSettings.Network.Consensus.Options.MaxBlockWeight, this.logger);
99+
int blockmintxfee = config.GetOrDefault<int>("blockmintxfee", (int)nodeSettings.Network.Consensus.Options.MinBlockFeeRate, this.logger);
99100

100-
this.BlockDefinitionOptions = new BlockDefinitionOptions(blockMaxWeight, blockMaxSize).RestrictForNetwork(nodeSettings.Network);
101+
this.BlockDefinitionOptions = new BlockDefinitionOptions(blockMaxWeight, blockMaxSize, blockmintxfee).RestrictForNetwork(nodeSettings.Network);
101102

102103
this.EnableCoinStakeSplitting = config.GetOrDefault("enablecoinstakesplitting", true, this.logger);
103104
this.MinimumSplitCoinValue = config.GetOrDefault("minimumsplitcoinvalue", MinimumSplitCoinValueDefaultValue, this.logger);
@@ -123,6 +124,7 @@ public static void PrintHelp(Network network)
123124
builder.AppendLine("-walletpassword=<string> Password to unlock the wallet.");
124125
builder.AppendLine("-blockmaxsize=<number> Maximum block size (in bytes) for the miner to generate.");
125126
builder.AppendLine("-blockmaxweight=<number> Maximum block weight (in weight units) for the miner to generate.");
127+
builder.AppendLine("-blockmintxfee=<number> Minimum fee rate for transactions to be included in blocks created by miner.");
126128
builder.AppendLine("-enablecoinstakesplitting=<0 or 1> Enable splitting coins when staking. This is true by default.");
127129
builder.AppendLine($"-minimumstakingcoinvalue=<number> Minimum size of the coins considered for staking, in satoshis. Default value is {MinimumStakingCoinValueDefaultValue:N0} satoshis (= {MinimumStakingCoinValueDefaultValue / (decimal)Money.COIN:N1} Coin).");
128130
builder.AppendLine($"-minimumsplitcoinvalue=<number> Targeted minimum value of staking coins after splitting, in satoshis. Default value is {MinimumSplitCoinValueDefaultValue:N0} satoshis (= {MinimumSplitCoinValueDefaultValue / Money.COIN} Coin).");
@@ -154,6 +156,8 @@ public static void BuildDefaultConfigurationFile(StringBuilder builder, Network
154156
builder.AppendLine($"#blockmaxsize={network.Consensus.Options.MaxBlockSerializedSize}");
155157
builder.AppendLine("#Maximum block weight (in weight units) for the miner to generate.");
156158
builder.AppendLine($"#blockmaxweight={network.Consensus.Options.MaxBlockWeight}");
159+
builder.AppendLine("#Minimum fee rate for transactions to be included in blocks created by miner.");
160+
builder.AppendLine($"#blockmintxfee={network.Consensus.Options.MinBlockFeeRate}");
157161
builder.AppendLine("#Enable splitting coins when staking.");
158162
builder.AppendLine("#enablecoinstakesplitting=1");
159163
builder.AppendLine("#Minimum size of the coins considered for staking, in satoshis.");

src/Features/Blockcore.Features.Miner/PowMining.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public class PowMining : IPowMining
4747
/// <summary>Provider of time functions.</summary>
4848
private readonly IDateTimeProvider dateTimeProvider;
4949

50-
/// <summary>Default for "-blockmintxfee", which sets the minimum feerate for a transaction in blocks created by mining code.</summary>
51-
public const int DefaultBlockMinTxFee = 1000;
52-
5350
private uint256 hashPrevBlock;
5451

5552
private const int InnerLoopCount = 0x10000;

src/Features/Blockcore.Features.Miner/Staking/PosMinting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ await Task.Run(() => Parallel.ForEach(workerContexts, cwc =>
719719

720720
// Get reward for newly created block.
721721
long reward = fees + this.consensusManager.ConsensusRules.GetRule<CheckPosUtxosetRule>().GetProofOfStakeReward(chainTip.Height + 1);
722-
if (reward <= 0)
722+
if (reward < 0)
723723
{
724724
// TODO: This can't happen unless we remove reward for mined block.
725725
// If this can happen over time then this check could be done much sooner

src/Networks/x42/x42/Networks/x42Main.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public x42Main()
3131
maxStandardTxSigopsCost: 20_000 / 5,
3232
witnessScaleFactor: 4
3333
);
34+
consensusOptions.MinBlockFeeRate = Money.Zero;
3435
// END MODIFICATIONS
3536

3637
CoinSetup setup = x42Setup.Instance.Setup;
@@ -109,7 +110,7 @@ public x42Main()
109110
minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
110111
maxReorgLength: 500,
111112
defaultAssumeValid: null,
112-
maxMoney: long.MaxValue,
113+
maxMoney: Money.Coins(42 * 1000000),
113114
coinbaseMaturity: 50,
114115
premineHeight: 2,
115116
premineReward: Money.Coins(setup.PremineReward),

src/Networks/x42/x42/Networks/x42Test.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NBitcoin.BouncyCastle.Math;
99
using NBitcoin.DataEncoders;
1010
using NBitcoin.Protocol;
11+
using x42.Networks.Deployments;
1112

1213
namespace x42.Networks
1314
{
@@ -24,6 +25,7 @@ public x42Test()
2425
maxStandardTxSigopsCost: 20_000 / 5,
2526
witnessScaleFactor: 4
2627
);
28+
consensusOptions.MinBlockFeeRate = Money.Zero;
2729
// END MODIFICATIONS
2830

2931
CoinSetup setup = x42Setup.Instance.Setup;
@@ -47,6 +49,10 @@ public x42Test()
4749
this.DefaultAPIPort = network.DefaultAPIPort;
4850
this.DefaultBanTimeSeconds = 288; // 9 (MaxReorg) * 64 (TargetSpacing) / 2 = 4 hours, 26 minutes and 40 seconds
4951

52+
this.MinTxFee = Money.Zero;
53+
this.FallbackFee = Money.Zero;
54+
this.MinRelayTxFee = Money.Zero;
55+
5056
var consensusFactory = new PosConsensusFactory();
5157

5258
// Create the genesis block.
@@ -73,6 +79,13 @@ public x42Test()
7379
[BuriedDeployments.BIP66] = 0
7480
};
7581

82+
var bip9Deployments = new x42BIP9Deployments
83+
{
84+
[x42BIP9Deployments.ColdStaking] = new BIP9DeploymentsParameters("ColdStaking", 27, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold),
85+
[x42BIP9Deployments.CSV] = new BIP9DeploymentsParameters("CSV", 0, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold),
86+
[x42BIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, new DateTime(2020, 3, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(2021, 3, 1, 0, 0, 0, DateTimeKind.Utc), BIP9DeploymentsParameters.DefaultMainnetThreshold)
87+
};
88+
7689
consensusFactory.Protocol = new ConsensusProtocol()
7790
{
7891
ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION,
@@ -89,7 +102,7 @@ public x42Test()
89102
majorityRejectBlockOutdated: 950,
90103
majorityWindow: 1000,
91104
buriedDeployments: buriedDeployments,
92-
bip9Deployments: new NoBIP9Deployments(),
105+
bip9Deployments: bip9Deployments,
93106
bip34Hash: null,
94107
minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
95108
maxReorgLength: 9,

src/Networks/x42/x42/x42Setup.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class x42Setup
2525
ProofOfStakeTimestampMask = 0x0000000F,
2626
BlocksWithoutRewards = true,
2727
LastProofOfStakeRewardHeight = 12155230,
28-
ProofOfStakeRewardAfterSubsidyLimit = 2,
28+
ProofOfStakeRewardAfterSubsidyLimit = Money.Coins(2),
2929
SubsidyLimit = 400000,
3030
PoSVersion = 3
3131
};
@@ -50,7 +50,7 @@ internal class x42Setup
5050
HashGenesisBlock = "0x04ffe583707a96c1c2eb54af33a4b1dc6d9d8e09fea8c9a7b097ba88f0cb64c4",
5151
HashMerkleRoot = "0x6e3439a32382f83dee4f94a6f8bdd38908bcf0c82ec09aba85c5321357f01f67",
5252
DNS = new[] { "mainnet1.x42seed.host", "mainnetnode1.x42seed.host", "tech.x42.cloud", "x42.seed.blockcore.net" },
53-
Nodes = new[] { "34.255.35.42", "52.211.235.48", "63.32.82.169" },
53+
Nodes = new[] { "34.255.35.42", "52.211.235.48", "63.32.82.169", "18.179.72.204", "15.188.129.215", "18.157.117.214" },
5454
Checkpoints = new Dictionary<int, CheckpointInfo>
5555
{
5656
{ 0, new CheckpointInfo(new uint256("0x04ffe583707a96c1c2eb54af33a4b1dc6d9d8e09fea8c9a7b097ba88f0cb64c4"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) }, // Genisis
@@ -60,7 +60,7 @@ internal class x42Setup
6060
{ 200000, new CheckpointInfo(new uint256("0xaa276a1c51c025ff1a21fd4b07bfa5d55effc173840e054dd851b20dbb1f2f17"), new uint256("0x63d4bc7b0272703e94ae79103970ea324dc85221e88a51c39a170744848c0cc7")) },
6161
{ 300000, new CheckpointInfo(new uint256("0xff72e73ee8f87c0de9bf82c3bb758f4905c3e005493f2ed1faede7c120961750"), new uint256("0x2097fc9edfb8dfe287db45bbce820e168c50be32c9840b1cddf56b297011fc69")) },
6262
{ 500000, new CheckpointInfo(new uint256("0x7f9a88ebb32f47090ec37a110c5a05c1162a604dfbfb69c8d492e771cdb63289"), new uint256("0x19db6890c5c934e883bc99eb197509b0a81f19faeefcf49fd7fa6dab83644bfb")) },
63-
{ 634600, new CheckpointInfo(new uint256("0x5c0eb47bc96ba437e6d2550aceaa73ad9a4568110de83380d6a7b5f00aee7308"), new uint256("0x12ef7b665a07cef572c9b8d9ee44f41230d6a65e960d372f9396194ed6f51e53")) }
63+
{ 800000, new CheckpointInfo(new uint256("0x981083b047ecf8157a8b2dc24e17ca8cfad01b4e2dabc314df97f3b64fdf37f5"), new uint256("0xf3f0a821801b32c73a7c4f42416ddad3f74b732bd517c968a9b93a33d3684e0b")) }
6464
}
6565
};
6666

@@ -111,7 +111,7 @@ internal class x42Setup
111111
HashGenesisBlock = "0x11bd504102b42b24680d7b4f9b9e9521adc1b690253494d108193cdfcdd2ef0b",
112112
HashMerkleRoot = "0x87e7f7df2fbe9fa56c627e59342e0d8142eb5e44c5e5769609059a60f17d0702",
113113
DNS = new[] { "testnet1.x42seed.host" },
114-
Nodes = new[] { "63.32.82.169" },
114+
Nodes = new[] { "63.32.82.169", "35.155.194.159" },
115115
Checkpoints = new Dictionary<int, CheckpointInfo>
116116
{
117117
{ 0, new CheckpointInfo(new uint256("0x11bd504102b42b24680d7b4f9b9e9521adc1b690253494d108193cdfcdd2ef0b"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) }, // Genisis

src/Tests/Blockcore.IntegrationTests/MinerTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public class MinerTests
5151

5252
private readonly Network network;
5353

54-
private static FeeRate blockMinFeeRate = new FeeRate(PowMining.DefaultBlockMinTxFee);
55-
5654
public static PowBlockDefinition AssemblerForTest(TestContext testContext)
5755
{
5856
return new PowBlockDefinition(testContext.consensus, testContext.DateTimeProvider, new LoggerFactory(), testContext.mempool, testContext.mempoolLock, new MinerSettings(NodeSettings.Default(testContext.network)), testContext.network, testContext.ConsensusRules, new NodeDeployments(testContext.network, testContext.ChainIndexer));
@@ -312,7 +310,7 @@ public async Task MinerTestPackageSelectionAsync()
312310

313311
// Calculate a fee on child transaction that will put the package just
314312
// below the block min tx fee (assuming 1 child tx of the same size).
315-
Money feeToUse = blockMinFeeRate.GetFee(2 * freeTxSize) - 1;
313+
Money feeToUse = new FeeRate(this.network.Consensus.Options.MinBlockFeeRate).GetFee(2 * freeTxSize) - 1;
316314

317315
tx = context.network.CreateTransaction(tx.ToBytes());
318316
tx.Inputs[0].PrevOut.Hash = hashFreeTx;
@@ -354,7 +352,7 @@ public async Task MinerTestPackageSelectionAsync()
354352
tx = context.network.CreateTransaction(tx.ToBytes());
355353
tx.Inputs[0].PrevOut.Hash = hashFreeTx2;
356354
tx.Outputs.RemoveAt(1);
357-
feeToUse = blockMinFeeRate.GetFee(freeTxSize);
355+
feeToUse = new FeeRate(this.network.Consensus.Options.MinBlockFeeRate).GetFee(freeTxSize);
358356
tx.Outputs[0].Value = 5000000000L - 100000000 - feeToUse;
359357
uint256 hashLowFeeTx2 = tx.GetHash();
360358
context.mempool.AddUnchecked(hashLowFeeTx2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));

0 commit comments

Comments
 (0)