Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ImpleumX network #258

Merged
merged 30 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c557e39
readme
stepkillah Sep 5, 2020
f33f466
Merge branch 'master' of https://github.com/block-core/blockcore
stepkillah Sep 5, 2020
fd9b443
added impleum network
stepkillah Sep 5, 2020
9e8e1a1
build removed
stepkillah Sep 5, 2020
0f29ad3
build removed
stepkillah Sep 5, 2020
4671d77
Merged with blockcore
stepkillah Dec 5, 2020
ea11673
Impleum network new settings prepared
stepkillah Dec 5, 2020
3b5673b
merged
stepkillah Dec 11, 2020
a8c44ee
Merged with blockcore. Fixing Impleum network params
stepkillah Dec 11, 2020
181554c
Impleum update mamx supply
stepkillah Dec 11, 2020
68a56d7
Impleum magic comment added
stepkillah Dec 11, 2020
6fc8d63
temporary remove workflows
stepkillah Dec 11, 2020
3afb6d2
Fix for impleum bad address
stepkillah Dec 12, 2020
6315df9
Update DNSSeedData
shtah Dec 13, 2020
eb737c4
Updates static Nodes
shtah Dec 13, 2020
4759a9f
Update ImpleumSetup.cs
shtah Dec 13, 2020
8c938a2
Update ImpleumSetup.cs
shtah Dec 13, 2020
6948b43
Update ImpleumSetup.cs
shtah Dec 13, 2020
4b0bd52
Upate MinTxFee
shtah Dec 13, 2020
a538fd7
Upate MinTxFee TestNet
shtah Dec 14, 2020
657dc6d
Upate MinTxFee TestNet
shtah Dec 14, 2020
35f1510
Impleum: Fix for MaxTxFee
stepkillah Dec 14, 2020
506673b
Merge branch 'master' of https://github.com/block-core/blockcore
stepkillah Dec 26, 2020
c1c3609
fix bip 9 deployments
stepkillah Dec 26, 2020
e43df82
Ass mainnet nodes
shtah Dec 27, 2020
7a58de9
Add mainnet nodes
shtah Dec 27, 2020
78ffbda
cd /Users/elenabulanova/IMPL/D/ddd/blockcore
Dec 31, 2020
d3b3006
Workflows add
Dec 31, 2020
a6a2267
Fix DefaultThreshold
stepkillah Jan 8, 2021
8e323b2
Merge branch 'master' of https://github.com/block-core/blockcore
stepkillah Jan 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Build

on:
push:
branches:
Expand Down
7 changes: 7 additions & 0 deletions src/Blockcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Persiste
EndProject
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}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.Impleum", "Networks\Blockcore.Networks.Impleum\Blockcore.Networks.Impleum.csproj", "{64E9C309-867E-45F6-A88E-7BC061305D0B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -339,6 +341,10 @@ Global
{4275AF0C-587B-4C9D-A100-0F2DD1702674}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4275AF0C-587B-4C9D-A100-0F2DD1702674}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4275AF0C-587B-4C9D-A100-0F2DD1702674}.Release|Any CPU.Build.0 = Release|Any CPU
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64E9C309-867E-45F6-A88E-7BC061305D0B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -397,6 +403,7 @@ Global
{BC0A50DF-0816-4613-B6B1-D1FEC384DFAE} = {2A20F4A8-01E8-4C44-A394-65C2DE6FBF28}
{8098D7F8-8B2F-451C-8DCB-90597B768F96} = {64694A14-97E0-4CBC-8032-754F9353B2DD}
{4275AF0C-587B-4C9D-A100-0F2DD1702674} = {64694A14-97E0-4CBC-8032-754F9353B2DD}
{64E9C309-867E-45F6-A88E-7BC061305D0B} = {3B56C02B-4468-4268-B797-851562789FCC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C780ABA-5872-4B83-AD3F-A5BD423AD907}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
<ProjectReference Include="..\..\Features\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
<ProjectReference Include="..\..\Features\Blockcore.Features.MemoryPool\Blockcore.Features.MemoryPool.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Blockcore.Base.Deployments;
using Blockcore.Consensus.ScriptInfo;
using Blockcore.Consensus.TransactionInfo;

namespace Blockcore.Networks.Impleum.Deployments
{
/// <summary>
/// BIP9 deployments for the Blockcore sample coin network.
/// </summary>
public class ImpleumBIP9Deployments : BIP9DeploymentsArray
{
// 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.
public const int CSV = 0;
public const int Segwit = 1;
public const int ColdStaking = 2; // TODO: Move this to the end of the deployments to leave room for others from Bitcoin?

// The number of deployments.
public const int NumberOfDeployments = 3;

/// <summary>
/// Constructs the BIP9 deployments array.
/// </summary>
public ImpleumBIP9Deployments() : base(NumberOfDeployments)
{
}

/// <summary>
/// Gets the deployment flags to set when the deployment activates.
/// </summary>
/// <param name="deployment">The deployment number.</param>
/// <returns>The deployment flags.</returns>
public override BIP9DeploymentFlags GetFlags(int deployment)
{
// The flags get combined in the caller, so it is ok to make a fresh object here.
var flags = new BIP9DeploymentFlags();

switch (deployment)
{
case ColdStaking:
flags.ScriptFlags = ScriptVerify.CheckColdStakeVerify;
break;

case CSV:
// Start enforcing BIP68 (sequence locks), BIP112 (CHECKSEQUENCEVERIFY) and BIP113 (Median Time Past) using versionbits logic.
flags.ScriptFlags = ScriptVerify.CheckSequenceVerify;
flags.LockTimeFlags = Transaction.LockTimeFlags.VerifySequence | Transaction.LockTimeFlags.MedianTimePast;
break;

case Segwit:
// Start enforcing WITNESS rules using versionbits logic.
flags.ScriptFlags = ScriptVerify.Witness;
break;
}

return flags;
}
}
}
263 changes: 263 additions & 0 deletions src/Networks/Blockcore.Networks.Impleum/ImpleumMain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
using System;
using System.Collections.Generic;
using Blockcore.Base.Deployments;
using Blockcore.Consensus;
using Blockcore.Consensus.BlockInfo;
using Blockcore.Consensus.ScriptInfo;
using Blockcore.Consensus.TransactionInfo;
using Blockcore.Features.Consensus.Rules.CommonRules;
using Blockcore.Features.Consensus.Rules.ProvenHeaderRules;
using Blockcore.Features.Consensus.Rules.UtxosetRules;
using Blockcore.Features.MemoryPool.Rules;
using Blockcore.Networks.Impleum.Deployments;
using Blockcore.Networks.Impleum.Policies;
using Blockcore.Networks.Impleum.Rules;
using NBitcoin;
using NBitcoin.BouncyCastle.Math;
using NBitcoin.DataEncoders;

namespace Blockcore.Networks.Impleum
{
public class ImpleumMain : Network
{
public ImpleumMain()
{
this.NetworkType = NetworkType.Mainnet;
this.DefaultConfigFilename = ImpleumSetup.ConfigFileName; // The default name used for the Impleum configuration file.

this.Name = ImpleumSetup.Main.Name;
this.CoinTicker = ImpleumSetup.Main.CoinTicker;
this.Magic = ImpleumSetup.Main.Magic;
this.RootFolderName = ImpleumSetup.Main.RootFolderName;
this.DefaultPort = ImpleumSetup.Main.DefaultPort;
this.DefaultRPCPort = ImpleumSetup.Main.DefaultRPCPort;
this.DefaultAPIPort = ImpleumSetup.Main.DefaultAPIPort;

this.DefaultMaxOutboundConnections = 16;
this.DefaultMaxInboundConnections = 109;
this.MaxTipAge = 2 * 60 * 60;
this.MinTxFee = 10000;
this.MaxTxFee = Money.Coins(0.1m);
this.FallbackFee = 10000;
this.MinRelayTxFee = 10000;
this.MaxTimeOffsetSeconds = 25 * 60;
this.DefaultBanTimeSeconds = 11250; // 500 (MaxReorg) * 45 (TargetSpacing) / 2 = 3 hours, 7 minutes and 30 seconds

var consensusFactory = new PosConsensusFactory();

Block genesisBlock = CreateGenesisBlock(consensusFactory,
ImpleumSetup.Main.GenesisTime,
ImpleumSetup.Main.GenesisNonce,
ImpleumSetup.Main.GenesisBits,
ImpleumSetup.Main.GenesisVersion,
ImpleumSetup.Main.GenesisReward,
ImpleumSetup.GenesisText);

this.Genesis = genesisBlock;

// Taken from StratisX.
var consensusOptions = new PosConsensusOptions()
{
MaxBlockBaseSize = 1_000_000,
MaxStandardVersion = 2,
MaxStandardTxWeight = 100_000,
MaxBlockSigopsCost = 20_000,
MaxStandardTxSigopsCost = 20_000 / 5,
WitnessScaleFactor = 4
};

var buriedDeployments = new BuriedDeploymentsArray
{
[BuriedDeployments.BIP34] = 0,
[BuriedDeployments.BIP65] = 0,
[BuriedDeployments.BIP66] = 0
};

var bip9Deployments = new ImpleumBIP9Deployments()
{
// Always active.
[ImpleumBIP9Deployments.CSV] = new BIP9DeploymentsParameters("CSV", 0, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold),
[ImpleumBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold),
[ImpleumBIP9Deployments.ColdStaking] = new BIP9DeploymentsParameters("ColdStaking", 2, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.DefaultMainnetThreshold)
};

this.Consensus = new Consensus.Consensus(
consensusFactory: consensusFactory,
consensusOptions: consensusOptions,
coinType: ImpleumSetup.CoinType,
hashGenesisBlock: genesisBlock.GetHash(),
subsidyHalvingInterval: 210000,
majorityEnforceBlockUpgrade: 750,
majorityRejectBlockOutdated: 950,
majorityWindow: 1000,
buriedDeployments: buriedDeployments,
bip9Deployments: bip9Deployments,
bip34Hash: null,
minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
maxReorgLength: 500,
defaultAssumeValid: null,
maxMoney: Money.Coins(ImpleumSetup.MaxSupply),
coinbaseMaturity: 50,
premineHeight: 2,
premineReward: Money.Coins(ImpleumSetup.PremineReward),
proofOfWorkReward: Money.Coins(ImpleumSetup.PoWBlockReward),
targetTimespan: TimeSpan.FromSeconds(14 * 24 * 60 * 60), // two weeks
targetSpacing: ImpleumSetup.TargetSpacing,
powAllowMinDifficultyBlocks: false,
posNoRetargeting: false,
powNoRetargeting: false,
powLimit: new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),
minimumChainWork: null,
isProofOfStake: true,
lastPowBlock: ImpleumSetup.Main.LastPowBlock,
proofOfStakeLimit: new BigInteger(uint256
.Parse("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)),
proofOfStakeLimitV2: new BigInteger(uint256
.Parse("000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff").ToBytes(false)),
proofOfStakeReward: Money.Coins(ImpleumSetup.PoSBlockReward),
proofOfStakeTimestampMask: ImpleumSetup.ProofOfStakeTimestampMask
)
{
PosEmptyCoinbase = ImpleumSetup.IsPoSv3(),
PosUseTimeFieldInKernalHash = ImpleumSetup.IsPoSv3()
};


// TODO: Set your Base58Prefixes
this.Base58Prefixes = new byte[12][];
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (ImpleumSetup.Main.PubKeyAddress) };
this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (ImpleumSetup.Main.ScriptAddress) };
this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (ImpleumSetup.Main.SecretAddress) };

this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
this.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
this.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
this.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
this.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
this.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };

this.Bech32Encoders = new Bech32Encoder[2];
var encoder = new Bech32Encoder(ImpleumSetup.Main.CoinTicker.ToLowerInvariant());
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;

this.Checkpoints = ImpleumSetup.Main.Checkpoints;
this.DNSSeeds = ImpleumSetup.Main.DNS;
this.SeedNodes = ImpleumSetup.Main.Nodes;

this.StandardScriptsRegistry = new ImpleumStandardScriptsRegistry();

// 64 below should be changed to TargetSpacingSeconds when we move that field.
Assert(this.DefaultBanTimeSeconds <= this.Consensus.MaxReorgLength * 64 / 2);

Assert(this.Consensus.HashGenesisBlock == uint256.Parse(ImpleumSetup.Main.HashGenesisBlock));
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse(ImpleumSetup.Main.HashMerkleRoot));

RegisterRules(this.Consensus);
RegisterMempoolRules(this.Consensus);
}

protected void RegisterRules(IConsensus consensus)
{
consensus.ConsensusRules
.Register<HeaderTimeChecksRule>()
.Register<HeaderTimeChecksPosRule>()
.Register<PosFutureDriftRule>()
.Register<CheckDifficultyPosRule>()
.Register<ImpleumHeaderVersionRule>()
.Register<ProvenHeaderSizeRule>()
.Register<ProvenHeaderCoinstakeRule>();

consensus.ConsensusRules
.Register<BlockMerkleRootRule>()
.Register<PosBlockSignatureRepresentationRule>()
.Register<PosBlockSignatureRule>();

consensus.ConsensusRules
.Register<SetActivationDeploymentsPartialValidationRule>()
.Register<PosTimeMaskRule>()

// rules that are inside the method ContextualCheckBlock
.Register<TransactionLocktimeActivationRule>()
.Register<CoinbaseHeightActivationRule>()
.Register<WitnessCommitmentsRule>()
.Register<BlockSizeRule>()

// rules that are inside the method CheckBlock
.Register<EnsureCoinbaseRule>()
.Register<CheckPowTransactionRule>()
.Register<CheckPosTransactionRule>()
.Register<CheckSigOpsRule>()
.Register<PosCoinstakeRule>();

consensus.ConsensusRules
.Register<SetActivationDeploymentsFullValidationRule>()

.Register<CheckDifficultyHybridRule>()

// rules that require the store to be loaded (coinview)
.Register<FetchUtxosetRule>()
.Register<TransactionDuplicationActivationRule>()
.Register<CheckPosUtxosetRule>() // implements BIP68, MaxSigOps and BlockReward calculation
// Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated
// and that the "IsColdCoinStake" flag would have been set by the OP_CHECKCOLDSTAKEVERIFY opcode if applicable.
.Register<PosColdStakingRule>()
.Register<PushUtxosetRule>()
.Register<FlushUtxosetRule>();
}

protected void RegisterMempoolRules(IConsensus consensus)
{
consensus.MempoolRules = new List<Type>()
{
typeof(CheckConflictsMempoolRule),
typeof(CheckCoinViewMempoolRule),
typeof(CreateMempoolEntryMempoolRule),
typeof(CheckSigOpsMempoolRule),
typeof(CheckFeeMempoolRule),
typeof(CheckRateLimitMempoolRule),
typeof(CheckAncestorsMempoolRule),
typeof(CheckReplacementMempoolRule),
typeof(CheckAllInputsMempoolRule),
typeof(CheckTxOutDustRule)
};
}

protected static Block CreateGenesisBlock(ConsensusFactory consensusFactory, uint nTime, uint nNonce, uint nBits, int nVersion, Money genesisReward, string genesisText)
{
Transaction txNew = consensusFactory.CreateTransaction();
txNew.Version = 1;

if (txNew is IPosTransactionWithTime posTx)
{
posTx.Time = nTime;
}

txNew.AddInput(new TxIn()
{
ScriptSig = new Script(Op.GetPushOp(0), new Op()
{
Code = (OpcodeType)0x1,
PushData = new[] { (byte)42 }
}, Op.GetPushOp(Encoders.ASCII.DecodeData(genesisText)))
});

txNew.AddOutput(new TxOut()
{
Value = genesisReward,
});

Block genesis = consensusFactory.CreateBlock();
genesis.Header.BlockTime = Utils.UnixTimeToDateTime(nTime);
genesis.Header.Bits = nBits;
genesis.Header.Nonce = nNonce;
genesis.Header.Version = nVersion;
genesis.Transactions.Add(txNew);
genesis.Header.HashPrevBlock = uint256.Zero;
genesis.UpdateMerkleRoot();

return genesis;
}
}
}
Loading