Skip to content

Commit e96154e

Browse files
authored
Add Blockcore.Node project for quick and easy debug of multiple chains (#115)
- Adds a new project that can launch multiple chains based on startup argument. This allows us to remove the existing node projects, they are no longer needed.
1 parent aaba809 commit e96154e

6 files changed

Lines changed: 261 additions & 0 deletions

File tree

src/Blockcore.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "x42.Networks", "Networks\x4
117117
EndProject
118118
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "x42.Node", "Networks\x42\x42.Node\x42.Node.csproj", "{8E17F166-F15A-42F7-9407-06CE2A4AA0AF}"
119119
EndProject
120+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Node", "Node", "{8820C3A5-74B4-45AB-B80C-2495DFBA4A2B}"
121+
EndProject
122+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blockcore.Node", "Node\Blockcore.Node\Blockcore.Node.csproj", "{D0A183FE-C913-4F8F-92EC-BD4502745140}"
123+
EndProject
120124
Global
121125
GlobalSection(SolutionConfigurationPlatforms) = preSolution
122126
Debug|Any CPU = Debug|Any CPU
@@ -295,6 +299,10 @@ Global
295299
{8E17F166-F15A-42F7-9407-06CE2A4AA0AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
296300
{8E17F166-F15A-42F7-9407-06CE2A4AA0AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
297301
{8E17F166-F15A-42F7-9407-06CE2A4AA0AF}.Release|Any CPU.Build.0 = Release|Any CPU
302+
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
303+
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Debug|Any CPU.Build.0 = Debug|Any CPU
304+
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Release|Any CPU.ActiveCfg = Release|Any CPU
305+
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Release|Any CPU.Build.0 = Release|Any CPU
298306
EndGlobalSection
299307
GlobalSection(SolutionProperties) = preSolution
300308
HideSolutionNode = FALSE
@@ -347,6 +355,7 @@ Global
347355
{88A9A633-DA22-412B-A04C-2A3405D3E2C8} = {3B56C02B-4468-4268-B797-851562789FCC}
348356
{36CE71D7-812A-40D7-96B7-8220E8E86643} = {88A9A633-DA22-412B-A04C-2A3405D3E2C8}
349357
{8E17F166-F15A-42F7-9407-06CE2A4AA0AF} = {88A9A633-DA22-412B-A04C-2A3405D3E2C8}
358+
{D0A183FE-C913-4F8F-92EC-BD4502745140} = {8820C3A5-74B4-45AB-B80C-2495DFBA4A2B}
350359
EndGlobalSection
351360
GlobalSection(ExtensibilityGlobals) = postSolution
352361
SolutionGuid = {6C780ABA-5872-4B83-AD3F-A5BD423AD907}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<Authors>Blockcore</Authors>
7+
<AssemblyTitle>Blockcore.Node</AssemblyTitle>
8+
<AssemblyName>Blockcore.Node</AssemblyName>
9+
<PackageId>Blockcore.Node</PackageId>
10+
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\Networks\Bitcoin\Blockcore.Networks.Bitcoin\Blockcore.Networks.Bitcoin.csproj" />
15+
<ProjectReference Include="..\..\Networks\City\City\City.csproj" />
16+
<ProjectReference Include="..\..\Networks\Stratis\Blockcore.Networks.Stratis\Blockcore.Networks.Stratis.csproj" />
17+
<ProjectReference Include="..\..\Networks\x42\x42\x42.Networks.csproj" />
18+
<ProjectReference Include="..\..\Networks\Xds\Blockcore.Networks.Xds\Blockcore.Networks.Xds.csproj" />
19+
<ProjectReference Include="..\..\Features\Blockcore.Features.Api\Blockcore.Features.Api.csproj" />
20+
<ProjectReference Include="..\..\Features\Blockcore.Features.BlockStore\Blockcore.Features.BlockStore.csproj" />
21+
<ProjectReference Include="..\..\Features\Blockcore.Features.ColdStaking\Blockcore.Features.ColdStaking.csproj" />
22+
<ProjectReference Include="..\..\Features\Blockcore.Features.Diagnostic\Blockcore.Features.Diagnostic.csproj" />
23+
<ProjectReference Include="..\..\Features\Blockcore.Features.Miner\Blockcore.Features.Miner.csproj" />
24+
<ProjectReference Include="..\..\Features\Blockcore.Features.RPC\Blockcore.Features.RPC.csproj" />
25+
<ProjectReference Include="..\..\Features\Blockcore.Features.SignalR\Blockcore.Features.SignalR.csproj" />
26+
<ProjectReference Include="..\..\Features\Blockcore.Features.Wallet\Blockcore.Features.Wallet.csproj" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Blockcore.Configuration;
2+
using NBitcoin.Protocol;
3+
4+
namespace Blockcore.Node
5+
{
6+
public static class NetworkSelector
7+
{
8+
public static NodeSettings Create(string chain, string[] args)
9+
{
10+
chain = chain.ToUpperInvariant();
11+
12+
NodeSettings nodeSettings = null;
13+
14+
switch (chain)
15+
{
16+
case "BTC":
17+
nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Bitcoin.Networks.Bitcoin, args: args);
18+
break;
19+
case "CITY":
20+
nodeSettings = new NodeSettings(networksSelector: City.Networks.Networks.City,
21+
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args)
22+
{
23+
MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
24+
};
25+
break;
26+
case "STRAT":
27+
nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Stratis.Networks.Stratis,
28+
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args);
29+
break;
30+
case "X42":
31+
nodeSettings = new NodeSettings(networksSelector: x42.Networks.Networks.x42,
32+
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args)
33+
{
34+
MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
35+
};
36+
break;
37+
case "XDS":
38+
nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Xds.Networks.Xds,
39+
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args)
40+
{
41+
MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
42+
};
43+
break;
44+
}
45+
46+
return nodeSettings;
47+
}
48+
}
49+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Blockcore.Builder;
2+
using Blockcore.Configuration;
3+
using Blockcore.Features.Api;
4+
using Blockcore.Features.BlockStore;
5+
using Blockcore.Features.ColdStaking;
6+
using Blockcore.Features.Consensus;
7+
using Blockcore.Features.Diagnostic;
8+
using Blockcore.Features.MemoryPool;
9+
using Blockcore.Features.Miner;
10+
using Blockcore.Features.RPC;
11+
using Blockcore.Features.Wallet;
12+
13+
namespace Blockcore.Node
14+
{
15+
public static class NodeBuilder
16+
{
17+
public static IFullNodeBuilder Create(string chain, NodeSettings settings)
18+
{
19+
chain = chain.ToUpperInvariant();
20+
21+
IFullNodeBuilder nodeBuilder = CreateBaseBuilder(chain, settings);
22+
23+
switch (chain)
24+
{
25+
case "BTC":
26+
nodeBuilder.UsePowConsensus().AddMining().UseWallet();
27+
break;
28+
case "CITY":
29+
case "STRAT":
30+
case "X42":
31+
case "XDS":
32+
nodeBuilder.UsePosConsensus().AddPowPosMining().UseColdStakingWallet();
33+
break;
34+
}
35+
36+
return nodeBuilder;
37+
}
38+
39+
private static IFullNodeBuilder CreateBaseBuilder(string chain, NodeSettings settings)
40+
{
41+
IFullNodeBuilder nodeBuilder = new FullNodeBuilder()
42+
.UseNodeSettings(settings)
43+
.UseBlockStore()
44+
.UseMempool()
45+
.UseApi()
46+
.AddRPC()
47+
.UseDiagnosticFeature();
48+
49+
return nodeBuilder;
50+
}
51+
}
52+
}

src/Node/Blockcore.Node/Program.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Blockcore.Builder;
6+
using Blockcore.Configuration;
7+
using Blockcore.Features.SignalR;
8+
using Blockcore.Features.SignalR.Broadcasters;
9+
using Blockcore.Features.SignalR.Events;
10+
using Blockcore.Utilities;
11+
12+
namespace Blockcore.Node
13+
{
14+
public class Program
15+
{
16+
public static async Task Main(string[] args)
17+
{
18+
try
19+
{
20+
string chain = args
21+
.DefaultIfEmpty("--chain=BTC")
22+
.Where(arg => arg.StartsWith("--chain", ignoreCase: true, CultureInfo.InvariantCulture))
23+
.Select(arg => arg.Replace("--chain=", string.Empty, ignoreCase: true, CultureInfo.InvariantCulture))
24+
.FirstOrDefault();
25+
26+
NodeSettings nodeSettings = NetworkSelector.Create(chain, args);
27+
IFullNodeBuilder nodeBuilder = NodeBuilder.Create(chain, nodeSettings);
28+
29+
if (nodeSettings.EnableSignalR)
30+
{
31+
nodeBuilder.AddSignalR(options =>
32+
{
33+
options.EventsToHandle = new[]
34+
{
35+
(IClientEvent) new BlockConnectedClientEvent(),
36+
new TransactionReceivedClientEvent()
37+
};
38+
39+
options.ClientEventBroadcasters = new[]
40+
{
41+
(Broadcaster: typeof(StakingBroadcaster), ClientEventBroadcasterSettings: new ClientEventBroadcasterSettings { BroadcastFrequencySeconds = 5 }),
42+
(Broadcaster: typeof(WalletInfoBroadcaster), ClientEventBroadcasterSettings: new ClientEventBroadcasterSettings { BroadcastFrequencySeconds = 5 })
43+
};
44+
});
45+
}
46+
47+
IFullNode node = nodeBuilder.Build();
48+
49+
if (node != null)
50+
await node.RunAsync();
51+
}
52+
catch (Exception ex)
53+
{
54+
Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex);
55+
}
56+
}
57+
}
58+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"profiles": {
3+
"BTC (MAIN/RPC)": {
4+
"commandName": "Project",
5+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser"
6+
},
7+
"BTC (MAIN/RPC/LOW-MEM)": {
8+
"commandName": "Project",
9+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -maxblkmem=5 -dbcache=50"
10+
},
11+
"BTC (TEST/RPC)": {
12+
"commandName": "Project",
13+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -testnet"
14+
},
15+
"BTC (MAIN/LOCAL/RPC)": {
16+
"commandName": "Project",
17+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata"
18+
},
19+
"BTC (TEST/LOCAL/RPC)": {
20+
"commandName": "Project",
21+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet"
22+
},
23+
"BTC (MAIN/LOCAL/RPC/DEFAULT)": {
24+
"commandName": "Project",
25+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -defaultwalletname=default -defaultwalletpassword=default -unlockdefaultwallet -server"
26+
},
27+
"BTC (TEST/LOCAL/RPC/DEFAULT)": {
28+
"commandName": "Project",
29+
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -defaultwalletname=default -defaultwalletpassword=default -unlockdefaultwallet -server -testnet"
30+
},
31+
"CITY (MAIN/LOCAL/RPC)": {
32+
"commandName": "Project",
33+
"commandLineArgs": "--chain=CITY -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata"
34+
},
35+
"CITY (TEST/LOCAL/RPC)": {
36+
"commandName": "Project",
37+
"commandLineArgs": "--chain=CITY -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet"
38+
},
39+
"STRAT (MAIN/LOCAL/RPC)": {
40+
"commandName": "Project",
41+
"commandLineArgs": "--chain=STRAT -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata"
42+
},
43+
"STRAT (TEST/LOCAL/RPC)": {
44+
"commandName": "Project",
45+
"commandLineArgs": "--chain=STRAT -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet"
46+
},
47+
"X42 (MAIN/LOCAL/RPC)": {
48+
"commandName": "Project",
49+
"commandLineArgs": "--chain=X42-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata"
50+
},
51+
"X42 (TEST/LOCAL/RPC)": {
52+
"commandName": "Project",
53+
"commandLineArgs": "--chain=X42 -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet"
54+
},
55+
"XDS (MAIN/LOCAL/RPC)": {
56+
"commandName": "Project",
57+
"commandLineArgs": "--chain=XDS -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata"
58+
},
59+
"XDS (TEST/LOCAL/RPC)": {
60+
"commandName": "Project",
61+
"commandLineArgs": "--chain=XDS -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet"
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)