forked from TheRetroMike/rmt-miningcore
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitcoinjob-rtt.patch
More file actions
108 lines (98 loc) · 4.63 KB
/
Copy pathbitcoinjob-rtt.patch
File metadata and controls
108 lines (98 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
diff --git a/src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs b/src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs
index 9432b4e6..db9344b2 100644
--- a/src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs
+++ b/src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs
@@ -37,6 +37,8 @@ public class BitcoinJob
private BitcoinTemplate.BitcoinNetworkParams networkParams;
protected readonly ConcurrentDictionary<string, bool> submissions = new(StringComparer.OrdinalIgnoreCase);
protected uint256 blockTargetValue;
+ // Optional Real Time Target (Heartbeat) for eCash
+ protected uint256? rttTargetValue;
protected byte[] coinbaseFinal;
protected string coinbaseFinalHex;
protected byte[] coinbaseInitial;
@@ -45,7 +47,7 @@ public class BitcoinJob
protected MerkleTree mt;
protected string[] merkleSegwitBranchesHex;
protected MerkleTree mtSegwit;
-
+
///////////////////////////////////////////
// GetJobParams related properties
@@ -272,7 +274,7 @@ public class BitcoinJob
raw = scriptPubKey;
rawLength = (uint)raw.Length;
}
-
+
bs.ReadWrite(ref amount);
bs.ReadWriteAsVarInt(ref rawLength);
bs.ReadWrite(raw);
@@ -344,7 +346,7 @@ public class BitcoinJob
if(coin.HasCoinbaseDevReward)
rewardToPool = CreateCoinbaseDevRewardOutputs(tx, rewardToPool);
- if(coin.HasCoinbaseStakingReward)
+ if (coin.HasCoinbaseStakingReward)
rewardToPool = CreateCoinbaseStakingRewardOutputs(tx, rewardToPool);
if(coin.HasCommunity)
@@ -356,7 +358,7 @@ public class BitcoinJob
if(coin.HasDeveloper)
rewardToPool = CreateDeveloperOutputs(tx, rewardToPool);
- if(coin.HasFoundation)
+ if (coin.HasFoundation)
rewardToPool = CreateFoundationOutputs(tx, rewardToPool);
// Remaining amount goes to pool
@@ -435,13 +437,22 @@ public class BitcoinJob
var headerValue = new uint256(headerHash);
// calc share-diff
- var diff1 = coin.Diff1 != null ? BigInteger.Parse(coin.Diff1, NumberStyles.HexNumber) : BitcoinConstants.Diff1;
- var shareDiff = (double) new BigRational(diff1, headerHash.ToBigInteger()) * shareMultiplier;
+ var diff1 = coin.Diff1 != null ? BigInteger.Parse(coin.Diff1, NumberStyles.HexNumber) : BitcoinConstants.Diff1;
+ var shareDiff = (double) new BigRational(diff1, headerHash.ToBigInteger()) * shareMultiplier;
var stratumDifficulty = context.Difficulty;
var ratio = shareDiff / stratumDifficulty;
+ // compute effective target (normal bits target, optionally clamped by RTT)
+ var effectiveTargetValue = blockTargetValue;
+ if(rttTargetValue.HasValue)
+ {
+ // RTT is a stricter target; choose the harder one (lower target value)
+ if(rttTargetValue.Value < effectiveTargetValue)
+ effectiveTargetValue = rttTargetValue.Value;
+ }
+
// check if the share meets the much harder block difficulty (block candidate)
- var isBlockCandidate = headerValue <= blockTargetValue;
+ var isBlockCandidate = headerValue <= effectiveTargetValue;
// test if share meets at least workers current difficulty
if(!isBlockCandidate && ratio < 0.99)
@@ -574,7 +585,7 @@ public class BitcoinJob
foreach(var masterNode in masternodes)
{
if(masterNode.Amount > 0)
- {
+ {
var payeeReward = masterNode.Amount;
//DASH blocks require a OP_RETURN Burn with no payee address
@@ -589,7 +600,7 @@ public class BitcoinJob
var payeeDestination = BitcoinUtils.AddressToDestination(masterNode.Payee, network);
tx.Outputs.Add(payeeReward, payeeDestination);
}
-
+
reward -= payeeReward;
}
}
@@ -1019,6 +1030,14 @@ public class BitcoinJob
blockTargetValue = tmp.ToUInt256();
}
+ // Optional RTT target (eCash heartbeat). Safe for other coins: only set if present.
+ rttTargetValue = null;
+ if(BlockTemplate.Rtt?.NextTarget != null)
+ {
+ var rttTmp = new Target(BlockTemplate.Rtt.NextTarget.HexToByteArray());
+ rttTargetValue = rttTmp.ToUInt256();
+ }
+
previousBlockHashReversedHex = BlockTemplate.PreviousBlockhash
.HexToByteArray()
.ReverseByteOrder()