Skip to content

Commit 6430223

Browse files
authored
Added support for xRhodium (XRC) (#286)
* Added support for xRhodium (XRC) node * Fixed xRhodium (XRC) RegTest network consensus * Added xRhodium XRC icon * Refactoring
1 parent 8595042 commit 6430223

18 files changed

Lines changed: 1264 additions & 0 deletions

src/Blockcore.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.BCP", "N
135135
EndProject
136136
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.X1", "Networks\Blockcore.Networks.X1\Blockcore.Networks.X1.csproj", "{9A2BA15A-C316-42B4-8E4D-E01B4873190C}"
137137
EndProject
138+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.XRC", "Networks\Blockcore.Networks.XRC\Blockcore.Networks.XRC.csproj", "{4615D1C6-14CD-47CA-8B78-A462A37057F6}"
139+
EndProject
138140
Global
139141
GlobalSection(SolutionConfigurationPlatforms) = preSolution
140142
Debug|Any CPU = Debug|Any CPU
@@ -357,6 +359,10 @@ Global
357359
{9A2BA15A-C316-42B4-8E4D-E01B4873190C}.Debug|Any CPU.Build.0 = Debug|Any CPU
358360
{9A2BA15A-C316-42B4-8E4D-E01B4873190C}.Release|Any CPU.ActiveCfg = Release|Any CPU
359361
{9A2BA15A-C316-42B4-8E4D-E01B4873190C}.Release|Any CPU.Build.0 = Release|Any CPU
362+
{4615D1C6-14CD-47CA-8B78-A462A37057F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
363+
{4615D1C6-14CD-47CA-8B78-A462A37057F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
364+
{4615D1C6-14CD-47CA-8B78-A462A37057F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
365+
{4615D1C6-14CD-47CA-8B78-A462A37057F6}.Release|Any CPU.Build.0 = Release|Any CPU
360366
EndGlobalSection
361367
GlobalSection(SolutionProperties) = preSolution
362368
HideSolutionNode = FALSE
@@ -418,6 +424,7 @@ Global
418424
{64E9C309-867E-45F6-A88E-7BC061305D0B} = {3B56C02B-4468-4268-B797-851562789FCC}
419425
{120500DF-C04F-43CC-9A1E-523A6429301F} = {3B56C02B-4468-4268-B797-851562789FCC}
420426
{9A2BA15A-C316-42B4-8E4D-E01B4873190C} = {3B56C02B-4468-4268-B797-851562789FCC}
427+
{4615D1C6-14CD-47CA-8B78-A462A37057F6} = {3B56C02B-4468-4268-B797-851562789FCC}
421428
EndGlobalSection
422429
GlobalSection(ExtensibilityGlobals) = postSolution
423430
SolutionGuid = {6C780ABA-5872-4B83-AD3F-A5BD423AD907}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<AssemblyTitle>Blockcore.Networks.xRhodium</AssemblyTitle>
5+
<AssemblyName>Blockcore.Networks.XRC</AssemblyName>
6+
<PackageId>Blockcore.Networks.xRhodium</PackageId>
7+
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
8+
<IsPackable>true</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<EmbeddedResource Include="icon.png" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
17+
<ProjectReference Include="..\..\Features\Blockcore.Features.MemoryPool\Blockcore.Features.MemoryPool.csproj" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Folder Include="Rules\" />
22+
</ItemGroup>
23+
</Project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.IO;
2+
using Blockcore.Consensus.BlockInfo;
3+
using Blockcore.Networks.XRC.Crypto;
4+
using NBitcoin;
5+
using NBitcoin.Crypto;
6+
7+
namespace Blockcore.Networks.XRC.Consensus
8+
{
9+
public class XRCBlockHeader : PosBlockHeader
10+
{
11+
private const int X13_HASH_MINERUNCOMPATIBLE = 1;
12+
private const int X13_HASH_MINERCOMPATIBLE = 2;
13+
private const uint XRC_X13_HASH_HARDFORK = 1541879606;
14+
15+
public override uint256 GetHash()
16+
{
17+
uint256 hash = null;
18+
uint256[] innerHashes = this.hashes;
19+
20+
if (innerHashes != null)
21+
hash = innerHashes[0];
22+
23+
if (hash != null)
24+
return hash;
25+
26+
using (var hs = new HashStream())
27+
{
28+
this.ReadWriteHashingStream(new BitcoinStream(hs, true));
29+
hash = hs.GetHash();
30+
}
31+
32+
innerHashes = this.hashes;
33+
if (innerHashes != null)
34+
{
35+
innerHashes[0] = hash;
36+
}
37+
38+
return hash;
39+
}
40+
41+
public override uint256 GetPoWHash()
42+
{
43+
using (var ms = new MemoryStream())
44+
{
45+
this.ReadWriteHashingStream(new BitcoinStream(ms, true));
46+
//block HardFork - height: 1648, time - 1541879606, hash - a75312cab7cf2a6ee89ab33bcb0ab9f96676fbc965041d50b889d9469eff6cdb
47+
if (this.Time > XRC_X13_HASH_HARDFORK)
48+
{
49+
return XRCHashX13.Instance.Hash(this.ToBytes(), X13_HASH_MINERCOMPATIBLE);
50+
}
51+
else
52+
{
53+
return XRCHashX13.Instance.Hash(this.ToBytes(), X13_HASH_MINERUNCOMPATIBLE);
54+
}
55+
}
56+
}
57+
}
58+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Blockcore.Base.Deployments;
4+
using Blockcore.Consensus;
5+
using NBitcoin;
6+
using NBitcoin.BouncyCastle.Math;
7+
8+
namespace Blockcore.Networks.XRC.Consensus
9+
{
10+
public class XRCConsensus : IConsensus
11+
{
12+
/// <inheritdoc />
13+
public long CoinbaseMaturity { get; set; }
14+
15+
/// <inheritdoc />
16+
public Money PremineReward { get; }
17+
18+
/// <inheritdoc />
19+
public long PremineHeight { get; }
20+
21+
/// <inheritdoc />
22+
public Money ProofOfWorkReward { get; }
23+
24+
/// <inheritdoc />
25+
public Money ProofOfStakeReward { get; }
26+
27+
/// <inheritdoc />
28+
public uint MaxReorgLength { get; private set; }
29+
30+
/// <inheritdoc />
31+
public long MaxMoney { get; }
32+
33+
public ConsensusOptions Options { get; set; }
34+
35+
public BuriedDeploymentsArray BuriedDeployments { get; }
36+
37+
public IBIP9DeploymentsArray BIP9Deployments { get; }
38+
39+
public int SubsidyHalvingInterval { get; }
40+
41+
public int MajorityEnforceBlockUpgrade { get; }
42+
43+
public int MajorityRejectBlockOutdated { get; }
44+
45+
public int MajorityWindow { get; }
46+
47+
public uint256 BIP34Hash { get; }
48+
49+
public Target PowLimit { get; }
50+
public Target PowLimit2 { get; }
51+
public int PowLimit2Height { get; }
52+
public uint PowLimit2Time { get; }
53+
54+
public TimeSpan TargetTimespan { get; }
55+
56+
public TimeSpan TargetSpacing { get; }
57+
58+
public bool PowAllowMinDifficultyBlocks { get; }
59+
60+
/// <inheritdoc />
61+
public bool PosNoRetargeting { get; }
62+
63+
/// <inheritdoc />
64+
public bool PowNoRetargeting { get; }
65+
66+
public uint256 HashGenesisBlock { get; }
67+
68+
/// <inheritdoc />
69+
public uint256 MinimumChainWork { get; }
70+
71+
public int MinerConfirmationWindow { get; set; }
72+
73+
/// <inheritdoc />
74+
public int CoinType { get; }
75+
76+
public BigInteger ProofOfStakeLimit { get; }
77+
78+
public BigInteger ProofOfStakeLimitV2 { get; }
79+
80+
/// <inheritdoc />
81+
public int LastPOWBlock { get; set; }
82+
83+
/// <inheritdoc />
84+
public bool IsProofOfStake { get; }
85+
86+
/// <inheritdoc />
87+
public bool PosEmptyCoinbase { get; set; }
88+
89+
/// <inheritdoc />
90+
public bool PosUseTimeFieldInKernalHash { get; set; }
91+
92+
/// <inheritdoc />
93+
public uint ProofOfStakeTimestampMask { get; set; }
94+
95+
/// <inheritdoc />
96+
public uint256 DefaultAssumeValid { get; }
97+
98+
/// <inheritdoc />
99+
public ConsensusFactory ConsensusFactory { get; }
100+
101+
/// <inheritdoc />
102+
public ConsensusRules ConsensusRules { get; }
103+
104+
/// <inheritdoc />
105+
public List<Type> MempoolRules { get; set; }
106+
107+
public XRCConsensus(
108+
ConsensusFactory consensusFactory,
109+
ConsensusOptions consensusOptions,
110+
int coinType,
111+
uint256 hashGenesisBlock,
112+
int subsidyHalvingInterval,
113+
int majorityEnforceBlockUpgrade,
114+
int majorityRejectBlockOutdated,
115+
int majorityWindow,
116+
BuriedDeploymentsArray buriedDeployments,
117+
IBIP9DeploymentsArray bip9Deployments,
118+
uint256 bip34Hash,
119+
int minerConfirmationWindow,
120+
uint maxReorgLength,
121+
uint256 defaultAssumeValid,
122+
long maxMoney,
123+
long coinbaseMaturity,
124+
long premineHeight,
125+
Money premineReward,
126+
Money proofOfWorkReward,
127+
TimeSpan targetTimespan,
128+
TimeSpan targetSpacing,
129+
bool powAllowMinDifficultyBlocks,
130+
bool posNoRetargeting,
131+
bool powNoRetargeting,
132+
Target powLimit,
133+
Target powLimit2,
134+
int powLimit2Height,
135+
uint powLimit2Time,
136+
uint256 minimumChainWork,
137+
bool isProofOfStake,
138+
int lastPowBlock,
139+
BigInteger proofOfStakeLimit,
140+
BigInteger proofOfStakeLimitV2,
141+
Money proofOfStakeReward,
142+
uint proofOfStakeTimestampMask)
143+
{
144+
this.CoinbaseMaturity = coinbaseMaturity;
145+
this.PremineReward = premineReward;
146+
this.PremineHeight = premineHeight;
147+
this.ProofOfWorkReward = proofOfWorkReward;
148+
this.ProofOfStakeReward = proofOfStakeReward;
149+
this.MaxReorgLength = maxReorgLength;
150+
this.MaxMoney = maxMoney;
151+
this.Options = consensusOptions;
152+
this.BuriedDeployments = buriedDeployments;
153+
this.BIP9Deployments = bip9Deployments;
154+
this.SubsidyHalvingInterval = subsidyHalvingInterval;
155+
this.MajorityEnforceBlockUpgrade = majorityEnforceBlockUpgrade;
156+
this.MajorityRejectBlockOutdated = majorityRejectBlockOutdated;
157+
this.MajorityWindow = majorityWindow;
158+
this.BIP34Hash = bip34Hash;
159+
this.PowLimit = powLimit;
160+
this.PowLimit2 = powLimit2;
161+
this.PowLimit2Height = powLimit2Height;
162+
this.PowLimit2Time = powLimit2Time;
163+
this.TargetTimespan = targetTimespan;
164+
this.TargetSpacing = targetSpacing;
165+
this.PowAllowMinDifficultyBlocks = powAllowMinDifficultyBlocks;
166+
this.PosNoRetargeting = posNoRetargeting;
167+
this.PowNoRetargeting = powNoRetargeting;
168+
this.HashGenesisBlock = hashGenesisBlock;
169+
this.MinimumChainWork = minimumChainWork;
170+
this.MinerConfirmationWindow = minerConfirmationWindow;
171+
this.CoinType = coinType;
172+
this.ProofOfStakeLimit = proofOfStakeLimit;
173+
this.ProofOfStakeLimitV2 = proofOfStakeLimitV2;
174+
this.LastPOWBlock = lastPowBlock;
175+
this.IsProofOfStake = isProofOfStake;
176+
this.DefaultAssumeValid = defaultAssumeValid;
177+
this.ConsensusFactory = consensusFactory;
178+
this.ConsensusRules = new ConsensusRules();
179+
this.MempoolRules = new List<Type>();
180+
this.ProofOfStakeTimestampMask = proofOfStakeTimestampMask;
181+
}
182+
}
183+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Blockcore.Consensus;
5+
using Blockcore.Consensus.BlockInfo;
6+
7+
namespace Blockcore.Networks.XRC.Consensus
8+
{
9+
public class XRCConsensusFactory : ConsensusFactory
10+
{
11+
public XRCConsensusFactory() : base()
12+
{
13+
this.Protocol = new ConsensusProtocol();
14+
this.Protocol.ProtocolVersion = 80000; //XRC PROTOCOL
15+
this.Protocol.MinProtocolVersion = 80000; //XRC PROTOCOL
16+
}
17+
18+
public override BlockHeader CreateBlockHeader()
19+
{
20+
return new XRCBlockHeader();
21+
}
22+
23+
}
24+
}

0 commit comments

Comments
 (0)