-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<Authors>Blockcore</Authors> | ||
<AssemblyTitle>Blockcore.Node</AssemblyTitle> | ||
<AssemblyName>Blockcore.Node</AssemblyName> | ||
<PackageId>Blockcore.Node</PackageId> | ||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Networks\Bitcoin\Blockcore.Networks.Bitcoin\Blockcore.Networks.Bitcoin.csproj" /> | ||
<ProjectReference Include="..\..\Networks\City\City\City.csproj" /> | ||
<ProjectReference Include="..\..\Networks\Stratis\Blockcore.Networks.Stratis\Blockcore.Networks.Stratis.csproj" /> | ||
<ProjectReference Include="..\..\Networks\x42\x42\x42.Networks.csproj" /> | ||
<ProjectReference Include="..\..\Networks\Xds\Blockcore.Networks.Xds\Blockcore.Networks.Xds.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.Api\Blockcore.Features.Api.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.BlockStore\Blockcore.Features.BlockStore.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.ColdStaking\Blockcore.Features.ColdStaking.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.Diagnostic\Blockcore.Features.Diagnostic.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.Miner\Blockcore.Features.Miner.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.RPC\Blockcore.Features.RPC.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.SignalR\Blockcore.Features.SignalR.csproj" /> | ||
<ProjectReference Include="..\..\Features\Blockcore.Features.Wallet\Blockcore.Features.Wallet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Blockcore.Configuration; | ||
using NBitcoin.Protocol; | ||
|
||
namespace Blockcore.Node | ||
{ | ||
public static class NetworkSelector | ||
{ | ||
public static NodeSettings Create(string chain, string[] args) | ||
{ | ||
chain = chain.ToUpperInvariant(); | ||
|
||
NodeSettings nodeSettings = null; | ||
|
||
switch (chain) | ||
{ | ||
case "BTC": | ||
nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Bitcoin.Networks.Bitcoin, args: args); | ||
break; | ||
case "CITY": | ||
nodeSettings = new NodeSettings(networksSelector: City.Networks.Networks.City, | ||
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args) | ||
{ | ||
MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION | ||
}; | ||
break; | ||
case "STRAT": | ||
nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Stratis.Networks.Stratis, | ||
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args); | ||
break; | ||
case "X42": | ||
nodeSettings = new NodeSettings(networksSelector: x42.Networks.Networks.x42, | ||
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args) | ||
{ | ||
MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION | ||
}; | ||
break; | ||
case "XDS": | ||
nodeSettings = new NodeSettings(networksSelector: Blockcore.Networks.Xds.Networks.Xds, | ||
protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args) | ||
{ | ||
MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION | ||
}; | ||
break; | ||
} | ||
|
||
return nodeSettings; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Blockcore.Builder; | ||
using Blockcore.Configuration; | ||
using Blockcore.Features.Api; | ||
using Blockcore.Features.BlockStore; | ||
using Blockcore.Features.ColdStaking; | ||
using Blockcore.Features.Consensus; | ||
using Blockcore.Features.Diagnostic; | ||
using Blockcore.Features.MemoryPool; | ||
using Blockcore.Features.Miner; | ||
using Blockcore.Features.RPC; | ||
using Blockcore.Features.Wallet; | ||
|
||
namespace Blockcore.Node | ||
{ | ||
public static class NodeBuilder | ||
{ | ||
public static IFullNodeBuilder Create(string chain, NodeSettings settings) | ||
{ | ||
chain = chain.ToUpperInvariant(); | ||
|
||
IFullNodeBuilder nodeBuilder = CreateBaseBuilder(chain, settings); | ||
|
||
switch (chain) | ||
{ | ||
case "BTC": | ||
nodeBuilder.UsePowConsensus().AddMining().UseWallet(); | ||
break; | ||
case "CITY": | ||
case "STRAT": | ||
case "X42": | ||
case "XDS": | ||
nodeBuilder.UsePosConsensus().AddPowPosMining().UseColdStakingWallet(); | ||
break; | ||
} | ||
|
||
return nodeBuilder; | ||
} | ||
|
||
private static IFullNodeBuilder CreateBaseBuilder(string chain, NodeSettings settings) | ||
{ | ||
IFullNodeBuilder nodeBuilder = new FullNodeBuilder() | ||
.UseNodeSettings(settings) | ||
.UseBlockStore() | ||
.UseMempool() | ||
.UseApi() | ||
.AddRPC() | ||
.UseDiagnosticFeature(); | ||
|
||
return nodeBuilder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Blockcore.Builder; | ||
using Blockcore.Configuration; | ||
using Blockcore.Features.SignalR; | ||
using Blockcore.Features.SignalR.Broadcasters; | ||
using Blockcore.Features.SignalR.Events; | ||
using Blockcore.Utilities; | ||
|
||
namespace Blockcore.Node | ||
{ | ||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
try | ||
{ | ||
string chain = args | ||
.DefaultIfEmpty("--chain=BTC") | ||
.Where(arg => arg.StartsWith("--chain", ignoreCase: true, CultureInfo.InvariantCulture)) | ||
.Select(arg => arg.Replace("--chain=", string.Empty, ignoreCase: true, CultureInfo.InvariantCulture)) | ||
.FirstOrDefault(); | ||
|
||
NodeSettings nodeSettings = NetworkSelector.Create(chain, args); | ||
IFullNodeBuilder nodeBuilder = NodeBuilder.Create(chain, nodeSettings); | ||
|
||
if (nodeSettings.EnableSignalR) | ||
{ | ||
nodeBuilder.AddSignalR(options => | ||
{ | ||
options.EventsToHandle = new[] | ||
{ | ||
(IClientEvent) new BlockConnectedClientEvent(), | ||
new TransactionReceivedClientEvent() | ||
}; | ||
|
||
options.ClientEventBroadcasters = new[] | ||
{ | ||
(Broadcaster: typeof(StakingBroadcaster), ClientEventBroadcasterSettings: new ClientEventBroadcasterSettings { BroadcastFrequencySeconds = 5 }), | ||
(Broadcaster: typeof(WalletInfoBroadcaster), ClientEventBroadcasterSettings: new ClientEventBroadcasterSettings { BroadcastFrequencySeconds = 5 }) | ||
}; | ||
}); | ||
} | ||
|
||
IFullNode node = nodeBuilder.Build(); | ||
|
||
if (node != null) | ||
await node.RunAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"profiles": { | ||
"BTC (MAIN/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser" | ||
}, | ||
"BTC (MAIN/RPC/LOW-MEM)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -maxblkmem=5 -dbcache=50" | ||
}, | ||
"BTC (TEST/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -testnet" | ||
}, | ||
"BTC (MAIN/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata" | ||
}, | ||
"BTC (TEST/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet" | ||
}, | ||
"BTC (MAIN/LOCAL/RPC/DEFAULT)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -defaultwalletname=default -defaultwalletpassword=default -unlockdefaultwallet -server" | ||
}, | ||
"BTC (TEST/LOCAL/RPC/DEFAULT)": { | ||
"commandName": "Project", | ||
"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" | ||
}, | ||
"CITY (MAIN/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=CITY -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata" | ||
}, | ||
"CITY (TEST/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=CITY -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet" | ||
}, | ||
"STRAT (MAIN/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=STRAT -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata" | ||
}, | ||
"STRAT (TEST/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=STRAT -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet" | ||
}, | ||
"X42 (MAIN/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=X42-server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata" | ||
}, | ||
"X42 (TEST/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=X42 -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet" | ||
}, | ||
"XDS (MAIN/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=XDS -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata" | ||
}, | ||
"XDS (TEST/LOCAL/RPC)": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--chain=XDS -server -rpcallowip=127.0.0.1 -rpcbind=127.0.0.1 -rpcpassword=rpcpassword -rpcuser=rpcuser -datadir=nodedata -testnet" | ||
} | ||
} | ||
} |