Commit 8d9a202e authored by Alexey's avatar Alexey

Code review fixes have been introduced for genesis-block generation routine

Some solution tuning performed
parent 02cb8519
{ {
"profiles": { "profiles": {
"Stratis.StratisD": { "DeStream.DeStream": {
"commandName": "Project"
},
"DeStream.DeStreamD Test": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "-testnet -debug -loglevel=trace " "commandLineArgs": "-testnet -debug -loglevel=trace"
},
"Stratis.StratisD": {
"commandName": "Project"
}, },
"Stratis.StratisD Test": { "Stratis.StratisD Test": {
"commandName": "Project", "commandName": "Project",
......
...@@ -103,7 +103,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stratis.Bitcoin.Tests.Walle ...@@ -103,7 +103,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stratis.Bitcoin.Tests.Walle
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stratis.Bitcoin.IntegrationTests.Common", "Stratis.Bitcoin.IntegrationTests.Common\Stratis.Bitcoin.IntegrationTests.Common.csproj", "{F7DD01DA-B888-4817-A5FA-3A87B69BFCA7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stratis.Bitcoin.IntegrationTests.Common", "Stratis.Bitcoin.IntegrationTests.Common\Stratis.Bitcoin.IntegrationTests.Common.csproj", "{F7DD01DA-B888-4817-A5FA-3A87B69BFCA7}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeStream.DeStreamD.ForTest", "DeStream.DeStreamD.ForTest\DeStream.DeStreamD.ForTest.csproj", "{D6749732-118C-4BDD-B184-5229AAB83341}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeStream.DeStreamD.ForTest", "DeStream.DeStreamD.ForTest\DeStream.DeStreamD.ForTest.csproj", "{D6749732-118C-4BDD-B184-5229AAB83341}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DeStream", "DeStream", "{4F374E46-C086-44BE-B785-2F88E2093016}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -308,6 +310,10 @@ Global ...@@ -308,6 +310,10 @@ Global
{6181B889-81B0-4A1E-A29F-E20DCD8BFC1F} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45} {6181B889-81B0-4A1E-A29F-E20DCD8BFC1F} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{CB7A2800-8E98-4CD5-A88A-832E03AF7ABF} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2} {CB7A2800-8E98-4CD5-A88A-832E03AF7ABF} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{978482B2-AE17-421E-AD6F-ED9667C6B8A1} = {A0CEDD86-D446-436E-8C35-261B30CEE5D3} {978482B2-AE17-421E-AD6F-ED9667C6B8A1} = {A0CEDD86-D446-436E-8C35-261B30CEE5D3}
{DFFB8C9F-4186-417F-A843-A5E1E6125164} = {4F374E46-C086-44BE-B785-2F88E2093016}
{5303E8B0-C422-4D1C-8096-24DF6AF75E31} = {4F374E46-C086-44BE-B785-2F88E2093016}
{CFE3D6A4-8B4F-4466-984B-74909ED2DA20} = {4F374E46-C086-44BE-B785-2F88E2093016}
{79B71F10-9B43-45C2-ADA4-A84324810D5C} = {4F374E46-C086-44BE-B785-2F88E2093016}
{B6FB52FE-F754-49B0-A65F-02F5C82B33EE} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2} {B6FB52FE-F754-49B0-A65F-02F5C82B33EE} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{F1755154-88DC-4434-98FB-7D22C95BA640} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2} {F1755154-88DC-4434-98FB-7D22C95BA640} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
{F7DD01DA-B888-4817-A5FA-3A87B69BFCA7} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2} {F7DD01DA-B888-4817-A5FA-3A87B69BFCA7} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
......
...@@ -198,6 +198,8 @@ namespace NBitcoin ...@@ -198,6 +198,8 @@ namespace NBitcoin
/// </summary> /// </summary>
public Money GenesisReward { get; protected set; } public Money GenesisReward { get; protected set; }
public string GenesisWalletAddress { get; protected set; }
/// <summary> /// <summary>
/// Mines a new genesis block, to use with a new network. /// Mines a new genesis block, to use with a new network.
/// Typically, 3 such genesis blocks need to be created when bootstrapping a new coin: for Main, Test and Reg networks. /// Typically, 3 such genesis blocks need to be created when bootstrapping a new coin: for Main, Test and Reg networks.
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using NBitcoin.BouncyCastle.Math; using NBitcoin.BouncyCastle.Math;
using NBitcoin.DataEncoders; using NBitcoin.DataEncoders;
...@@ -12,6 +13,8 @@ namespace NBitcoin.Networks ...@@ -12,6 +13,8 @@ namespace NBitcoin.Networks
public DeStreamMain() public DeStreamMain()
{ {
string InitialWalletAddress = "TPPL2wmtxGzP8U6hQsGkRA9yCMsazB33ft";
decimal InitialCoins = 6000000000;
var messageStart = new byte[4]; var messageStart = new byte[4];
messageStart[0] = 0x70; messageStart[0] = 0x70;
...@@ -31,6 +34,7 @@ namespace NBitcoin.Networks ...@@ -31,6 +34,7 @@ namespace NBitcoin.Networks
this.MinRelayTxFee = 10000; this.MinRelayTxFee = 10000;
this.MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds; this.MaxTimeOffsetSeconds = StratisMaxTimeOffsetSeconds;
this.MaxTipAge = StratisDefaultMaxTipAgeInSeconds; this.MaxTipAge = StratisDefaultMaxTipAgeInSeconds;
this.CoinTicker = "DST";
this.Consensus.SubsidyHalvingInterval = 210000; this.Consensus.SubsidyHalvingInterval = 210000;
this.Consensus.MajorityEnforceBlockUpgrade = 750; this.Consensus.MajorityEnforceBlockUpgrade = 750;
...@@ -55,11 +59,6 @@ namespace NBitcoin.Networks ...@@ -55,11 +59,6 @@ namespace NBitcoin.Networks
this.Consensus.CoinType = 105; this.Consensus.CoinType = 105;
this.Consensus.DefaultAssumeValid = new uint256("0x55a8205ae4bbf18f4d238c43f43005bd66e0b1f679b39e2c5c62cf6903693a5e"); // 795970 this.Consensus.DefaultAssumeValid = new uint256("0x55a8205ae4bbf18f4d238c43f43005bd66e0b1f679b39e2c5c62cf6903693a5e"); // 795970
this.Genesis = CreateStratisGenesisBlock(this.Consensus.ConsensusFactory, 1470467000, 1831645, 0x1e0fffff, 1, Money.Zero);
this.Consensus.HashGenesisBlock = this.Genesis.GetHash();
Assert(this.Consensus.HashGenesisBlock == uint256.Parse("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"));
Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse("0x65a26bc20b0351aebf05829daefa8f7db2f800623439f3c114257c91447f1518"));
this.Checkpoints = new Dictionary<int, CheckpointInfo> this.Checkpoints = new Dictionary<int, CheckpointInfo>
{ {
{ 0, new CheckpointInfo(new uint256("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) }, { 0, new CheckpointInfo(new uint256("0x0000066e91e46e5a264d42c89e1204963b2ee6be230b443e9159020539d972af"), new uint256("0x0000000000000000000000000000000000000000000000000000000000000000")) },
...@@ -81,6 +80,7 @@ namespace NBitcoin.Networks ...@@ -81,6 +80,7 @@ namespace NBitcoin.Networks
{ 576000, new CheckpointInfo(new uint256("0xe705476b940e332098d1d5b475d7977312ff8c08cbc8256ce46a3e2c6d5408b8"), new uint256("0x10e31bb5e245ea19650280cfd3ac1a76259fa0002d02e861d2ab5df290534b56")) }, { 576000, new CheckpointInfo(new uint256("0xe705476b940e332098d1d5b475d7977312ff8c08cbc8256ce46a3e2c6d5408b8"), new uint256("0x10e31bb5e245ea19650280cfd3ac1a76259fa0002d02e861d2ab5df290534b56")) },
}; };
this.Base58Prefixes = new byte[12][];
this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (63) }; this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (63) };
this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (125) }; this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (125) };
this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (63 + 128) }; this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (63 + 128) };
...@@ -95,32 +95,64 @@ namespace NBitcoin.Networks ...@@ -95,32 +95,64 @@ namespace NBitcoin.Networks
this.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 }; this.Base58Prefixes[(int)Base58Type.COLORED_ADDRESS] = new byte[] { 0x13 };
var encoder = new Bech32Encoder("bc"); var encoder = new Bech32Encoder("bc");
this.Bech32Encoders = new Bech32Encoder[2];
this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder; this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder; this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
this.DNSSeeds.AddRange(new[] this.DNSSeeds = new List<DNSSeedData>
{ {
new DNSSeedData("node1.destream.io", "node1.destream.io"), new DNSSeedData("node1.destream.io", "node1.destream.io"),
new DNSSeedData("node2.destream.io", "node2.destream.io") new DNSSeedData("node2.destream.io", "node2.destream.io")
}); };
string[] seedNodes = { "95.128.181.103", "95.128.181.80" };
this.SeedNodes = ConvertToNetworkAddresses(seedNodes, this.DefaultPort).ToList();
// Create the genesis block.
this.GenesisTime = 1470467000;
this.GenesisNonce = 1831645;
this.GenesisBits = 0x1e0fffff;
this.GenesisVersion = 1;
this.GenesisReward = Money.Coins(InitialCoins);
this.GenesisWalletAddress = InitialWalletAddress;
this.Genesis = CreateDeStreamGenesisBlock(this.Consensus.ConsensusFactory, this.GenesisTime, this.GenesisNonce, this.GenesisBits, this.GenesisVersion, this.GenesisReward, this.GenesisWalletAddress);
this.Consensus.HashGenesisBlock = this.Genesis.GetHash();
var seeds = new[] { "95.128.181.103", "95.128.181.80" }; // Assert(this.Consensus.HashGenesisBlock == uint256.Parse("c5974b227ccb19ebd97578285a5937bb4bfb6dcdbf473966d8a2f9c714a8dbb0"));
// Convert the seeds array into usable address objects. // Assert(this.Genesis.Header.HashMerkleRoot == uint256.Parse("9e3fff58fb1ba15a69198e22d99572fa024afb754bfe1d3b8d28b86fd9de62df"));
Random rand = new Random(); }
TimeSpan oneWeek = TimeSpan.FromDays(7);
foreach (string seed in seeds) protected Block CreateDeStreamGenesisBlock(ConsensusFactory consensusFactory, uint nTime, uint nNonce, uint nBits, int nVersion, Money InitialCoins, string InitialWalletAddress)
{ {
// It'll only connect to one or two seed nodes because once it connects, string pszTimestamp = "DESTREAM IS THE FIRST DECENTRALIZED GLOBAL FINANCIAL ECOSYSTEM FOR STREAMERS";
// it'll get a pile of addresses with newer timestamps.
// Seed nodes are given a random 'last seen time' of between one and two weeks ago. Transaction txNew = consensusFactory.CreateTransaction();
NetworkAddress addr = new NetworkAddress txNew.Version = 1;
txNew.Time = nTime;
txNew.AddInput(new TxIn()
{ {
Time = DateTime.UtcNow - (TimeSpan.FromSeconds(rand.NextDouble() * oneWeek.TotalSeconds)) - oneWeek, ScriptSig = new Script(Op.GetPushOp(0), new Op()
Endpoint = Utils.ParseIpEndpoint(seed, this.DefaultPort) {
}; Code = (OpcodeType)0x1,
PushData = new[] { (byte)42 }
}, Op.GetPushOp(Encoders.ASCII.DecodeData(pszTimestamp)))
});
this.SeedNodes.Add(addr); byte[] prefix = this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS];
} byte[] destination_publicKey = Encoders.Base58Check.DecodeData(InitialWalletAddress).Skip(prefix.Length).ToArray();
Script destination = (new KeyId(new uint160(destination_publicKey))).ScriptPubKey;
txNew.AddOutput(new TxOut(InitialCoins, destination));
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;
} }
} }
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment