Skip to content

Commit 6d229a8

Browse files
stepkillahshtahElena Bulanova
authored
Adding ImpleumX network (#258)
* readme * added impleum network * build removed * build removed * Impleum network new settings prepared * Merged with blockcore. Fixing Impleum network params * Impleum update mamx supply * Impleum magic comment added * temporary remove workflows * Fix for impleum bad address * Update DNSSeedData * Updates static Nodes * Update ImpleumSetup.cs * Update ImpleumSetup.cs * Update ImpleumSetup.cs * Upate MinTxFee * Upate MinTxFee TestNet * Upate MinTxFee TestNet * Impleum: Fix for MaxTxFee * fix bip 9 deployments * Ass mainnet nodes * Add mainnet nodes * cd /Users/elenabulanova/IMPL/D/ddd/blockcore * Workflows add * Fix DefaultThreshold Co-authored-by: Yuriy Bulah <1c@ua.fm> Co-authored-by: Elena Bulanova <elenabulanova@MacBook-Pro-Elena-2.local>
1 parent 7b25fb9 commit 6d229a8

15 files changed

Lines changed: 882 additions & 1 deletion

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Build
2-
2+
33
on:
44
push:
55
branches:

src/Blockcore.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Persiste
129129
EndProject
130130
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Persistence.LevelDb.CorePackage", "Features\Persistence\Blockcore.Features.Persistence.LevelDb.CorePackage\Blockcore.Features.Persistence.LevelDb.CorePackage.csproj", "{4275AF0C-587B-4C9D-A100-0F2DD1702674}"
131131
EndProject
132+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.Impleum", "Networks\Blockcore.Networks.Impleum\Blockcore.Networks.Impleum.csproj", "{64E9C309-867E-45F6-A88E-7BC061305D0B}"
133+
EndProject
132134
Global
133135
GlobalSection(SolutionConfigurationPlatforms) = preSolution
134136
Debug|Any CPU = Debug|Any CPU
@@ -339,6 +341,10 @@ Global
339341
{4275AF0C-587B-4C9D-A100-0F2DD1702674}.Debug|Any CPU.Build.0 = Debug|Any CPU
340342
{4275AF0C-587B-4C9D-A100-0F2DD1702674}.Release|Any CPU.ActiveCfg = Release|Any CPU
341343
{4275AF0C-587B-4C9D-A100-0F2DD1702674}.Release|Any CPU.Build.0 = Release|Any CPU
344+
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
345+
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
346+
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
347+
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Release|Any CPU.Build.0 = Release|Any CPU
342348
EndGlobalSection
343349
GlobalSection(SolutionProperties) = preSolution
344350
HideSolutionNode = FALSE
@@ -397,6 +403,7 @@ Global
397403
{BC0A50DF-0816-4613-B6B1-D1FEC384DFAE} = {2A20F4A8-01E8-4C44-A394-65C2DE6FBF28}
398404
{8098D7F8-8B2F-451C-8DCB-90597B768F96} = {64694A14-97E0-4CBC-8032-754F9353B2DD}
399405
{4275AF0C-587B-4C9D-A100-0F2DD1702674} = {64694A14-97E0-4CBC-8032-754F9353B2DD}
406+
{64E9C309-867E-45F6-A88E-7BC061305D0B} = {3B56C02B-4468-4268-B797-851562789FCC}
400407
EndGlobalSection
401408
GlobalSection(ExtensibilityGlobals) = postSolution
402409
SolutionGuid = {6C780ABA-5872-4B83-AD3F-A5BD423AD907}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
9+
<ProjectReference Include="..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
10+
<ProjectReference Include="..\..\Features\Blockcore.Features.MemoryPool\Blockcore.Features.MemoryPool.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Blockcore.Base.Deployments;
2+
using Blockcore.Consensus.ScriptInfo;
3+
using Blockcore.Consensus.TransactionInfo;
4+
5+
namespace Blockcore.Networks.Impleum.Deployments
6+
{
7+
/// <summary>
8+
/// BIP9 deployments for the Blockcore sample coin network.
9+
/// </summary>
10+
public class ImpleumBIP9Deployments : BIP9DeploymentsArray
11+
{
12+
// The position of each deployment in the deployments array. Note that this is decoupled from the actual position of the flag bit for the deployment in the block version.
13+
public const int CSV = 0;
14+
public const int Segwit = 1;
15+
public const int ColdStaking = 2; // TODO: Move this to the end of the deployments to leave room for others from Bitcoin?
16+
17+
// The number of deployments.
18+
public const int NumberOfDeployments = 3;
19+
20+
/// <summary>
21+
/// Constructs the BIP9 deployments array.
22+
/// </summary>
23+
public ImpleumBIP9Deployments() : base(NumberOfDeployments)
24+
{
25+
}
26+
27+
/// <summary>
28+
/// Gets the deployment flags to set when the deployment activates.
29+
/// </summary>
30+
/// <param name="deployment">The deployment number.</param>
31+
/// <returns>The deployment flags.</returns>
32+
public override BIP9DeploymentFlags GetFlags(int deployment)
33+
{
34+
// The flags get combined in the caller, so it is ok to make a fresh object here.
35+
var flags = new BIP9DeploymentFlags();
36+
37+
switch (deployment)
38+
{
39+
case ColdStaking:
40+
flags.ScriptFlags = ScriptVerify.CheckColdStakeVerify;
41+
break;
42+
43+
case CSV:
44+
// Start enforcing BIP68 (sequence locks), BIP112 (CHECKSEQUENCEVERIFY) and BIP113 (Median Time Past) using versionbits logic.
45+
flags.ScriptFlags = ScriptVerify.CheckSequenceVerify;
46+
flags.LockTimeFlags = Transaction.LockTimeFlags.VerifySequence | Transaction.LockTimeFlags.MedianTimePast;
47+
break;
48+
49+
case Segwit:
50+
// Start enforcing WITNESS rules using versionbits logic.
51+
flags.ScriptFlags = ScriptVerify.Witness;
52+
break;
53+
}
54+
55+
return flags;
56+
}
57+
}
58+
}
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Blockcore.Base.Deployments;
4+
using Blockcore.Consensus;
5+
using Blockcore.Consensus.BlockInfo;
6+
using Blockcore.Consensus.ScriptInfo;
7+
using Blockcore.Consensus.TransactionInfo;
8+
using Blockcore.Features.Consensus.Rules.CommonRules;
9+
using Blockcore.Features.Consensus.Rules.ProvenHeaderRules;
10+
using Blockcore.Features.Consensus.Rules.UtxosetRules;
11+
using Blockcore.Features.MemoryPool.Rules;
12+
using Blockcore.Networks.Impleum.Deployments;
13+
using Blockcore.Networks.Impleum.Policies;
14+
using Blockcore.Networks.Impleum.Rules;
15+
using NBitcoin;
16+
using NBitcoin.BouncyCastle.Math;
17+
using NBitcoin.DataEncoders;
18+
19+
namespace Blockcore.Networks.Impleum
20+
{
21+
public class ImpleumMain : Network
22+
{
23+
public ImpleumMain()
24+
{
25+
this.NetworkType = NetworkType.Mainnet;
26+
this.DefaultConfigFilename = ImpleumSetup.ConfigFileName; // The default name used for the Impleum configuration file.
27+
28+
this.Name = ImpleumSetup.Main.Name;
29+
this.CoinTicker = ImpleumSetup.Main.CoinTicker;
30+
this.Magic = ImpleumSetup.Main.Magic;
31+
this.RootFolderName = ImpleumSetup.Main.RootFolderName;
32+
this.DefaultPort = ImpleumSetup.Main.DefaultPort;
33+
this.DefaultRPCPort = ImpleumSetup.Main.DefaultRPCPort;
34+
this.DefaultAPIPort = ImpleumSetup.Main.DefaultAPIPort;
35+
36+
this.DefaultMaxOutboundConnections = 16;
37+
this.DefaultMaxInboundConnections = 109;
38+
this.MaxTipAge = 2 * 60 * 60;
39+
this.MinTxFee = 10000;
40+
this.MaxTxFee = Money.Coins(0.1m);
41+
this.FallbackFee = 10000;
42+
this.MinRelayTxFee = 10000;
43+
this.MaxTimeOffsetSeconds = 25 * 60;
44+
this.DefaultBanTimeSeconds = 11250; // 500 (MaxReorg) * 45 (TargetSpacing) / 2 = 3 hours, 7 minutes and 30 seconds
45+
46+
var consensusFactory = new PosConsensusFactory();
47+
48+
Block genesisBlock = CreateGenesisBlock(consensusFactory,
49+
ImpleumSetup.Main.GenesisTime,
50+
ImpleumSetup.Main.GenesisNonce,
51+
ImpleumSetup.Main.GenesisBits,
52+
ImpleumSetup.Main.GenesisVersion,
53+
ImpleumSetup.Main.GenesisReward,
54+
ImpleumSetup.GenesisText);
55+
56+
this.Genesis = genesisBlock;
57+
58+
// Taken from StratisX.
59+
var consensusOptions = new PosConsensusOptions()
60+
{
61+
MaxBlockBaseSize = 1_000_000,
62+
MaxStandardVersion = 2,
63+
MaxStandardTxWeight = 100_000,
64+
MaxBlockSigopsCost = 20_000,
65+
MaxStandardTxSigopsCost = 20_000 / 5,
66+
WitnessScaleFactor = 4
67+
};
68+
69+
var buriedDeployments = new BuriedDeploymentsArray
70+
{
71+
[BuriedDeployments.BIP34] = 0,
72+
[BuriedDeployments.BIP65] = 0,
73+
[BuriedDeployments.BIP66] = 0
74+
};
75+
76+
var bip9Deployments = new ImpleumBIP9Deployments()
77+
{
78+
// Always active.
79+
[ImpleumBIP9Deployments.CSV] = new BIP9DeploymentsParameters("CSV", 0, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold),
80+
[ImpleumBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold),
81+
[ImpleumBIP9Deployments.ColdStaking] = new BIP9DeploymentsParameters("ColdStaking", 2, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold)
82+
};
83+
84+
this.Consensus = new Consensus.Consensus(
85+
consensusFactory: consensusFactory,
86+
consensusOptions: consensusOptions,
87+
coinType: ImpleumSetup.CoinType,
88+
hashGenesisBlock: genesisBlock.GetHash(),
89+
subsidyHalvingInterval: 210000,
90+
majorityEnforceBlockUpgrade: 750,
91+
majorityRejectBlockOutdated: 950,
92+
majorityWindow: 1000,
93+
buriedDeployments: buriedDeployments,
94+
bip9Deployments: bip9Deployments,
95+
bip34Hash: null,
96+
minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
97+
maxReorgLength: 500,
98+
defaultAssumeValid: null,
99+
maxMoney: Money.Coins(ImpleumSetup.MaxSupply),
100+
coinbaseMaturity: 50,
101+
premineHeight: 2,
102+
premineReward: Money.Coins(ImpleumSetup.PremineReward),
103+
proofOfWorkReward: Money.Coins(ImpleumSetup.PoWBlockReward),
104+
targetTimespan: TimeSpan.FromSeconds(14 * 24 * 60 * 60), // two weeks
105+
targetSpacing: ImpleumSetup.TargetSpacing,
106+
powAllowMinDifficultyBlocks: false,
107+
posNoRetargeting: false,
108+
powNoRetargeting: false,
109+
powLimit: new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),
110+
minimumChainWork: null,
111+
isProofOfStake: true,
112+
lastPowBlock: ImpleumSetup.Main.LastPowBlock,
113+
proofOfStakeLimit: new BigInteger(uint256
114+
.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)),
115+
proofOfStakeLimitV2: new BigInteger(uint256
116+
.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)),
117+
proofOfStakeReward: Money.Coins(ImpleumSetup.PoSBlockReward),
118+
proofOfStakeTimestampMask: ImpleumSetup.ProofOfStakeTimestampMask
119+
)
120+
{
121+
PosEmptyCoinbase = ImpleumSetup.IsPoSv3(),
122+
PosUseTimeFieldInKernalHash = ImpleumSetup.IsPoSv3()
123+
};
124+
125+
126+
// TODO: Set your Base58Prefixes
127+
this.Base58Prefixes = new byte[12][];
128+
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (ImpleumSetup.Main.PubKeyAddress) };
129+
this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (ImpleumSetup.Main.ScriptAddress) };
130+
this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (ImpleumSetup.Main.SecretAddress) };
131+
132+
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
133+
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
134+
this.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
135+
this.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
136+
this.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
137+
this.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
138+
this.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
139+
140+
this.Bech32Encoders = new Bech32Encoder[2];
141+
var encoder = new Bech32Encoder(ImpleumSetup.Main.CoinTicker.ToLowerInvariant());
142+
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
143+
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
144+
145+
this.Checkpoints = ImpleumSetup.Main.Checkpoints;
146+
this.DNSSeeds = ImpleumSetup.Main.DNS;
147+
this.SeedNodes = ImpleumSetup.Main.Nodes;
148+
149+
this.StandardScriptsRegistry = new ImpleumStandardScriptsRegistry();
150+
151+
// 64 below should be changed to TargetSpacingSeconds when we move that field.
152+
Assert(this.DefaultBanTimeSeconds <= this.Consensus.MaxReorgLength * 64 / 2);
153+
154+
Assert(this.Consensus.HashGenesisBlock == uint256.Parse(ImpleumSetup.Main.HashGenesisBlock));
155+
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse(ImpleumSetup.Main.HashMerkleRoot));
156+
157+
RegisterRules(this.Consensus);
158+
RegisterMempoolRules(this.Consensus);
159+
}
160+
161+
protected void RegisterRules(IConsensus consensus)
162+
{
163+
consensus.ConsensusRules
164+
.Register<HeaderTimeChecksRule>()
165+
.Register<HeaderTimeChecksPosRule>()
166+
.Register<PosFutureDriftRule>()
167+
.Register<CheckDifficultyPosRule>()
168+
.Register<ImpleumHeaderVersionRule>()
169+
.Register<ProvenHeaderSizeRule>()
170+
.Register<ProvenHeaderCoinstakeRule>();
171+
172+
consensus.ConsensusRules
173+
.Register<BlockMerkleRootRule>()
174+
.Register<PosBlockSignatureRepresentationRule>()
175+
.Register<PosBlockSignatureRule>();
176+
177+
consensus.ConsensusRules
178+
.Register<SetActivationDeploymentsPartialValidationRule>()
179+
.Register<PosTimeMaskRule>()
180+
181+
// rules that are inside the method ContextualCheckBlock
182+
.Register<TransactionLocktimeActivationRule>()
183+
.Register<CoinbaseHeightActivationRule>()
184+
.Register<WitnessCommitmentsRule>()
185+
.Register<BlockSizeRule>()
186+
187+
// rules that are inside the method CheckBlock
188+
.Register<EnsureCoinbaseRule>()
189+
.Register<CheckPowTransactionRule>()
190+
.Register<CheckPosTransactionRule>()
191+
.Register<CheckSigOpsRule>()
192+
.Register<PosCoinstakeRule>();
193+
194+
consensus.ConsensusRules
195+
.Register<SetActivationDeploymentsFullValidationRule>()
196+
197+
.Register<CheckDifficultyHybridRule>()
198+
199+
// rules that require the store to be loaded (coinview)
200+
.Register<FetchUtxosetRule>()
201+
.Register<TransactionDuplicationActivationRule>()
202+
.Register<CheckPosUtxosetRule>() // implements BIP68, MaxSigOps and BlockReward calculation
203+
// Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated
204+
// and that the "IsColdCoinStake" flag would have been set by the OP_CHECKCOLDSTAKEVERIFY opcode if applicable.
205+
.Register<PosColdStakingRule>()
206+
.Register<PushUtxosetRule>()
207+
.Register<FlushUtxosetRule>();
208+
}
209+
210+
protected void RegisterMempoolRules(IConsensus consensus)
211+
{
212+
consensus.MempoolRules = new List<Type>()
213+
{
214+
typeof(CheckConflictsMempoolRule),
215+
typeof(CheckCoinViewMempoolRule),
216+
typeof(CreateMempoolEntryMempoolRule),
217+
typeof(CheckSigOpsMempoolRule),
218+
typeof(CheckFeeMempoolRule),
219+
typeof(CheckRateLimitMempoolRule),
220+
typeof(CheckAncestorsMempoolRule),
221+
typeof(CheckReplacementMempoolRule),
222+
typeof(CheckAllInputsMempoolRule),
223+
typeof(CheckTxOutDustRule)
224+
};
225+
}
226+
227+
protected static Block CreateGenesisBlock(ConsensusFactory consensusFactory, uint nTime, uint nNonce, uint nBits, int nVersion, Money genesisReward, string genesisText)
228+
{
229+
Transaction txNew = consensusFactory.CreateTransaction();
230+
txNew.Version = 1;
231+
232+
if (txNew is IPosTransactionWithTime posTx)
233+
{
234+
posTx.Time = nTime;
235+
}
236+
237+
txNew.AddInput(new TxIn()
238+
{
239+
ScriptSig = new Script(Op.GetPushOp(0), new Op()
240+
{
241+
Code = (OpcodeType)0x1,
242+
PushData = new[] { (byte)42 }
243+
}, Op.GetPushOp(Encoders.ASCII.DecodeData(genesisText)))
244+
});
245+
246+
txNew.AddOutput(new TxOut()
247+
{
248+
Value = genesisReward,
249+
});
250+
251+
Block genesis = consensusFactory.CreateBlock();
252+
genesis.Header.BlockTime = Utils.UnixTimeToDateTime(nTime);
253+
genesis.Header.Bits = nBits;
254+
genesis.Header.Nonce = nNonce;
255+
genesis.Header.Version = nVersion;
256+
genesis.Transactions.Add(txNew);
257+
genesis.Header.HashPrevBlock = uint256.Zero;
258+
genesis.UpdateMerkleRoot();
259+
260+
return genesis;
261+
}
262+
}
263+
}

0 commit comments

Comments
 (0)