/// <summary>
        /// Builds a node with basic services and RPC enabled.
        /// </summary>
        /// <param name="dir">Data directory that the node should use.</param>
        /// <returns>Interface to the newly built node.</returns>
        public IFullNode BuildServicedNode(string dir)
        {
            var       nodeSettings    = new NodeSettings(args: new string[] { $"-datadir={dir}" });
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePowConsensus()
                                        .UseMempool()
                                        .AddRPC()
                                        .Build();

            return(fullNode);
        }
        /// <summary>
        /// Builds a node with basic services and RPC enabled.
        /// </summary>
        /// <param name="dir">Data directory that the node should use.</param>
        /// <returns>Interface to the newly built node.</returns>
        public IFullNode BuildServicedNode(string dir)
        {
            var nodeSettings = new NodeSettings(this.Network, args: new string[] { $"-datadir={dir}" });
            var persistenceProviderManager = new TestPersistenceProviderManager(nodeSettings);

            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings, persistenceProviderManager);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePowConsensus()
                                        .UseMempool()
                                        .AddRPC()
                                        .Build();

            return(fullNode);
        }
        /// <summary>
        /// Builds a node with POS miner and RPC enabled.
        /// </summary>
        /// <param name="dataDir">Data directory that the node should use.</param>
        /// <param name="staking">Flag to signal that the node should the start staking on start up or not.</param>
        /// <returns>Interface to the newly built node.</returns>
        /// <remarks>Currently the node built here does not actually stake as it has no coins in the wallet,
        /// but all the features required for it are enabled.</remarks>
        public static IFullNode BuildStakingNode(string dataDir, bool staking = true)
        {
            var       nodeSettings    = new NodeSettings(networksSelector: Networks.Networks.Stratis, protocolVersion: ProtocolVersion.ALT_PROTOCOL_VERSION, args: new string[] { $"-datadir={dataDir}", $"-stake={(staking ? 1 : 0)}", "-walletname=dummy", "-walletpassword=dummy" });
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePosConsensus()
                                        .UseMempool()
                                        .UseWallet()
                                        .AddPowPosMining()
                                        .AddRPC()
                                        .MockIBD()
                                        .Build();

            return(fullNode);
        }
Example #4
0
        /// <summary>
        /// Builds a node with POS miner and RPC enabled.
        /// </summary>
        /// <param name="dataDir">Data directory that the node should use.</param>
        /// <returns>Interface to the newly built node.</returns>
        /// <remarks>Currently the node built here does not actually stake as it has no coins in the wallet,
        /// but all the features required for it are enabled.</remarks>
        public static IFullNode BuildStakingNode(string dataDir, bool staking = true)
        {
            var       nodeSettings    = new NodeSettings(args: new string[] { $"-datadir={dataDir}", $"-stake={(staking ? 1 : 0)}", "-walletname=dummy", "-walletpassword=dummy" });
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePosConsensus()
                                        .UseMempool()
                                        .UseWallet()
                                        .AddPowPosMining()
                                        .AddRPC()
                                        .MockIBD()
                                        .Build();

            return(fullNode);
        }
        /// <summary>
        /// Builds a node with POS miner and RPC enabled.
        /// </summary>
        /// <param name="dataDir">Data directory that the node should use.</param>
        /// <param name="staking">Flag to signal that the node should the start staking on start up or not.</param>
        /// <returns>Interface to the newly built node.</returns>
        /// <remarks>Currently the node built here does not actually stake as it has no coins in the wallet,
        /// but all the features required for it are enabled.</remarks>
        public static IFullNode BuildStakingNode(string dataDir, bool staking = true)
        {
            var nodeSettings = new NodeSettings(networksSelector: Networks.Stratis.Networks.Stratis, args: new string[] { $"-datadir={dataDir}", $"-stake={(staking ? 1 : 0)}", "-walletname=dummy", "-walletpassword=dummy" });
            var persistenceProviderManager = new TestPersistenceProviderManager(nodeSettings);

            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings, persistenceProviderManager);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePosConsensus()
                                        .UseMempool()
                                        .UseWallet()
                                        .AddPowPosMining()
                                        .AddRPC()
                                        .MockIBD()
                                        .UseTestChainedHeaderTree()
                                        .Build();

            return(fullNode);
        }
        public void CanHaveAllFullnodeServicesTest()
        {
            // This test is put in the mempool feature because the
            // mempool requires all the features to be a fullnode.

            var nodeSettings = new NodeSettings(KnownNetworks.TestNet, args: new string[] {
                $"-datadir=Blockcore.Features.MemoryPool.Tests/TestData/FullNodeBuilderTest/CanHaveAllServicesTest"
            });

            var persistenceManager = new TestPersistenceProviderManager(nodeSettings);

            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings, persistenceManager);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePowConsensus()
                                        .UseMempool()
                                        .Build();

            IServiceProvider serviceProvider = fullNode.Services.ServiceProvider;
            var network             = serviceProvider.GetService <Network>();
            var settings            = serviceProvider.GetService <NodeSettings>();
            var consensusManager    = serviceProvider.GetService <IConsensusManager>() as ConsensusManager;
            var chain               = serviceProvider.GetService <ChainIndexer>();
            var chainState          = serviceProvider.GetService <IChainState>() as ChainState;
            var consensusRuleEngine = serviceProvider.GetService <IConsensusRuleEngine>();

            consensusRuleEngine.SetupRulesEngineParent();
            var mempoolManager    = serviceProvider.GetService <MempoolManager>();
            var connectionManager = serviceProvider.GetService <IConnectionManager>() as ConnectionManager;

            Assert.NotNull(fullNode);
            Assert.NotNull(network);
            Assert.NotNull(settings);
            Assert.NotNull(consensusManager);
            Assert.NotNull(chain);
            Assert.NotNull(chainState);
            Assert.NotNull(consensusRuleEngine);
            Assert.NotNull(mempoolManager);
            Assert.NotNull(connectionManager);
        }
        public void CanHaveAllFullnodeServicesTest()
        {
            // This test is put in the mempool feature because the
            // mempool requires all the features to be a fullnode


            NodeSettings nodeSettings = new NodeSettings(args: new string[] {
                $"-datadir=Stratis.Bitcoin.Features.MemoryPool.Tests/TestData/FullNodeBuilderTest/CanHaveAllServicesTest"
            });
            var       fullNodeBuilder = new FullNodeBuilder(nodeSettings);
            IFullNode fullNode        = fullNodeBuilder
                                        .UseBlockStore()
                                        .UsePowConsensus()
                                        .UseMempool()
                                        .Build();

            IServiceProvider serviceProvider = fullNode.Services.ServiceProvider;
            var network           = serviceProvider.GetService <Network>();
            var settings          = serviceProvider.GetService <NodeSettings>();
            var consensusLoop     = serviceProvider.GetService <IConsensusLoop>() as ConsensusLoop;
            var chain             = serviceProvider.GetService <NBitcoin.ConcurrentChain>();
            var chainState        = serviceProvider.GetService <IChainState>() as ChainState;
            var blockStoreManager = serviceProvider.GetService <BlockStoreManager>();
            var consensusRules    = serviceProvider.GetService <IConsensusRules>();

            consensusRules.Register(serviceProvider.GetService <IRuleRegistration>());
            var mempoolManager    = serviceProvider.GetService <MempoolManager>();
            var connectionManager = serviceProvider.GetService <IConnectionManager>() as ConnectionManager;

            Assert.NotNull(fullNode);
            Assert.NotNull(network);
            Assert.NotNull(settings);
            Assert.NotNull(consensusLoop);
            Assert.NotNull(chain);
            Assert.NotNull(chainState);
            Assert.NotNull(blockStoreManager);
            Assert.NotNull(mempoolManager);
            Assert.NotNull(connectionManager);
        }
Example #8
0
        public void StartFullNode(string[] startParameters)
        {
            PosBlockHeader.CustomPoWHash = ObsidianHash.GetObsidianPoWHash;

            try
            {
                var nodeSettings = new NodeSettings(networksSelector: ObsidianNetworksSelector.Obsidian,
                                                    protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, agent: $"{GetName()}, StratisNode", args: startParameters)
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                IFullNodeBuilder builder = new FullNodeBuilder();

                builder = builder.UseNodeSettings(nodeSettings);
                builder = builder.UseBlockStore();
                builder = builder.UsePosConsensus();
                builder = builder.UseMempool();
                builder = builder.UseColdStakingWallet();
                builder = builder.AddPowPosMining();
                //.UseApi()
                builder   = builder.AddRPC();
                _fullNode = (FullNode)builder.Build();

                LogQueue = XamarinLogger.Queue;

                if (_fullNode != null)
                {
                    Task.Run(async() => await RunAsync(_fullNode));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(@"There was a problem initializing or running the node. Details: '{0}'", ex.Message);
                NodeCrashed?.Invoke(this, EventArgs.Empty);
            }
        }
Example #9
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                var isTestNet = args.Contains("-testnet");
                var isStratis = args.Contains("stratis");
                var agent     = "Breeze";

                // This setting is not in NodeSettings yet, so get it directly from the args
                ConfigurationOptionWrapper <string>   registrationStoreDirectory = new ConfigurationOptionWrapper <string>("RegistrationStoreDirectory", args.GetValueOf("-storedir"));
                ConfigurationOptionWrapper <string>[] configurationOptions       = { registrationStoreDirectory };

                NodeSettings nodeSettings;

                if (isStratis)
                {
                    //if (NodeSettings.PrintHelp(args, Network.StratisMain))
                    //    return;

                    Network network = isTestNet ? Network.StratisTest : Network.StratisMain;
                    if (isTestNet)
                    {
                        args = args.Append("-addnode=51.141.28.47").ToArray(); // TODO: fix this temp hack
                    }
                    nodeSettings = new NodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent, args: args, loadConfiguration: false);
                }
                else
                {
                    nodeSettings = new NodeSettings(agent: agent, args: args, loadConfiguration: false);
                }

                IFullNodeBuilder fullNodeBuilder = null;

                if (args.Contains("light"))
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseWatchOnlyWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings);

                    if (args.Contains("stratis"))
                    {
                        fullNodeBuilder.UsePosConsensus();
                    }
                    else
                    {
                        fullNodeBuilder.UsePowConsensus();
                    }

                    fullNodeBuilder.UseBlockStore()
                    .UseMempool()
                    .UseBlockNotification()
                    .UseTransactionNotification()
                    .UseWallet()
                    .UseWatchOnlyWallet();

                    if (args.Contains("stratis"))
                    {
                        fullNodeBuilder.AddPowPosMining();
                    }
                    else
                    {
                        fullNodeBuilder.AddMining();
                    }

                    fullNodeBuilder.AddRPC()
                    .UseApi();
                }

                if (args.Contains("registration"))
                {
                    //fullNodeBuilder.UseInterNodeCommunication();
                    fullNodeBuilder.UseRegistration();
                }

                // Need this to happen for both TB and non-TB daemon
                Logs.Configure(new FuncLoggerFactory(i => new DualLogger(i, (a, b) => true, false)));

                // Start NTumbleBit logging to the console
                SetupTumbleBitConsoleLogs(nodeSettings);

                // Currently TumbleBit is bitcoin only
                if (args.Contains("-tumblebit"))
                {
                    // We no longer pass the URI in via the command line, the registration feature selects a random one
                    fullNodeBuilder.UseTumbleBit(configurationOptions);
                }

                IFullNode node = fullNodeBuilder.Build();

                // Add logging to NLog
                SetupTumbleBitNLogs(nodeSettings);

                // Start Full Node - this will also start the API.
                await node.RunAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Example #10
0
        public static async Task MainAsync(string[] args)
        {
            try
            {
                var comparer = new CommandlineArgumentComparer();

                var isRegTest = args.Contains("regtest", comparer);
                var isTestNet = args.Contains("testnet", comparer);
                var isStratis = args.Contains("stratis", comparer);
                var isLight   = args.Contains("light", comparer);

                var    useRegistration = args.Contains("registration", comparer);
                var    useTumblebit    = args.Contains("tumblebit", comparer);
                var    useTor          = !args.Contains("noTor", comparer);
                string registrationStoreDirectoryPath = args.GetValueOf("-storedir");

                TumblerProtocolType tumblerProtocol;
                try
                {
                    string tumblerProtocolString = args.GetValueOf("-tumblerProtocol");
                    if (!isRegTest && (tumblerProtocolString != null || !useTor))
                    {
                        Console.WriteLine("Options -TumblerProtocol and -NoTor can only be used in combination with -RegTest switch.");
                        return;
                    }

                    if (tumblerProtocolString != null)
                    {
                        tumblerProtocol = Enum.Parse <TumblerProtocolType>(tumblerProtocolString, true);
                    }
                    else
                    {
                        tumblerProtocol = TumblerProtocolType.Tcp;
                    }

                    if (useTor && tumblerProtocol == TumblerProtocolType.Http)
                    {
                        Console.WriteLine("TumblerProtocol can only be changed to Http when Tor is disabled. Please use -NoTor switch to disable Tor.");
                        return;
                    }
                }
                catch
                {
                    Console.WriteLine($"Incorrect tumbling prococol specified; the valid values are {TumblerProtocolType.Tcp} and {TumblerProtocolType.Http}");
                    return;
                }

                var agent = "Breeze";

                NodeSettings nodeSettings;

                if (isStratis)
                {
                    //if (NodeSettings.PrintHelp(args, Network.StratisMain))
                    //    return;

                    Network network;
                    if (isRegTest)
                    {
                        network = Network.StratisRegTest;
                    }
                    else if (isTestNet)
                    {
                        args    = args.Append("-addnode=51.141.28.47").ToArray();      // TODO: fix this temp hack
                        network = Network.StratisTest;
                    }
                    else
                    {
                        network = Network.StratisMain;
                    }

                    nodeSettings = new NodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent, args: args, loadConfiguration: false);
                }
                else
                {
                    nodeSettings = new NodeSettings(agent: agent, args: args, loadConfiguration: false);
                }

                IFullNodeBuilder fullNodeBuilder = null;

                if (isLight)
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseWatchOnlyWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings);

                    if (isStratis)
                    {
                        fullNodeBuilder.UsePosConsensus();
                    }
                    else
                    {
                        fullNodeBuilder.UsePowConsensus();
                    }

                    fullNodeBuilder.UseBlockStore()
                    .UseMempool()
                    .UseBlockNotification()
                    .UseTransactionNotification()
                    .UseWallet()
                    .UseWatchOnlyWallet();

                    if (isStratis)
                    {
                        fullNodeBuilder.AddPowPosMining();
                    }
                    else
                    {
                        fullNodeBuilder.AddMining();
                    }

                    fullNodeBuilder.AddRPC()
                    .UseApi();
                }

                if (useRegistration)
                {
                    //fullNodeBuilder.UseInterNodeCommunication();
                    fullNodeBuilder.UseRegistration();
                }

                // Need this to happen for both TB and non-TB daemon
                string dataDir = nodeSettings.DataDir;
                if (string.IsNullOrEmpty(dataDir))
                {
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StratisNode");
                    }
                    else
                    {
                        dataDir = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".stratisnode");
                    }
                }

                string logDir = Path.Combine(dataDir, nodeSettings.Network.RootFolderName, nodeSettings.Network.Name, "Logs");
                Logs.Configure(new FuncLoggerFactory(i => new DualLogger(i, (a, b) => true, false)), logDir);

                // Start NTumbleBit logging to the console
                SetupTumbleBitConsoleLogs(nodeSettings);

                // Currently TumbleBit is bitcoin only
                if (useTumblebit)
                {
                    if (string.IsNullOrEmpty(registrationStoreDirectoryPath))
                    {
                        string networkName;
                        if (isRegTest)
                        {
                            networkName = "StratisRegTest";
                        }
                        else if (isTestNet)
                        {
                            networkName = "StratisTest";
                        }
                        else
                        {
                            networkName = "StratisMain";
                        }

                        registrationStoreDirectoryPath = Path.Combine(dataDir, "stratis", networkName, "registrationHistory.json");
                    }

                    // Those settings are not in NodeSettings yet, so get it directly from the args
                    ConfigurationOptionWrapper <object> registrationStoreDirectory = new ConfigurationOptionWrapper <object>("RegistrationStoreDirectory", registrationStoreDirectoryPath);
                    ConfigurationOptionWrapper <object> torOption             = new ConfigurationOptionWrapper <object>("Tor", useTor);
                    ConfigurationOptionWrapper <object> tumblerProtocolOption = new ConfigurationOptionWrapper <object>("TumblerProtocol", tumblerProtocol);
                    ConfigurationOptionWrapper <object> useDummyAddressOption = new ConfigurationOptionWrapper <object>("UseDummyAddress", true);

                    ConfigurationOptionWrapper <object>[] tumblebitConfigurationOptions = { registrationStoreDirectory, torOption, tumblerProtocolOption, useDummyAddressOption };


                    // We no longer pass the URI in via the command line, the registration feature selects a random one
                    fullNodeBuilder.UseTumbleBit(tumblebitConfigurationOptions);
                }

                IFullNode node = fullNodeBuilder.Build();

                // Add logging to NLog
                SetupTumbleBitNLogs(nodeSettings);

                // Start Full Node - this will also start the API.
                await node.RunAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
            }
        }
Example #11
0
        public static async Task Main(string[] args)
        {
            try
            {
                Network network = args.Contains("-testnet")
                    ? NetworkRegistration.Register(new RedstoneTest())
                    : args.Contains("-regnet")
                    ? NetworkRegistration.Register(new RedstoneRegTest())
                    : NetworkRegistration.Register(new RedstoneMain());

                var nodeSettings = new NodeSettings(network: network, protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args.Concat(new[] { "-txIndex=1", "-addressIndex=1" }).ToArray())
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                bool keyGenerationRequired = RequiresKeyGeneration(nodeSettings);
                if (keyGenerationRequired)
                {
                    GenerateServiceNodeKey(nodeSettings);
                    return;
                }

                var dnsSettings = new DnsSettings(nodeSettings);

                var isDns = !string.IsNullOrWhiteSpace(dnsSettings.DnsHostName) &&
                            !string.IsNullOrWhiteSpace(dnsSettings.DnsNameServer) &&
                            !string.IsNullOrWhiteSpace(dnsSettings.DnsMailBox);

                var builder = new FullNodeBuilder()
                              .UseNodeSettings(nodeSettings);

                if (isDns)
                {
                    // Run as a full node with DNS or just a DNS service?
                    if (dnsSettings.DnsFullNode)
                    {
                        builder = builder
                                  .UseBlockStore()
                                  .UseRedstonePosConsensus()
                                  .UseMempool()
                                  .UseWallet()
                                  .AddRedstoneMining();
                    }
                    else
                    {
                        builder = builder.UsePosConsensus();
                    }

                    builder = builder
                              .UseApi()
                              .AddRPC()
                              .UseDns();
                }
                else
                {
                    builder = builder
                              .UseBlockStore()
                              .UseRedstonePosConsensus()
                              .UseMempool()
                              .UseColdStakingWallet()
                              .AddRedstoneMining()
                              .UseApi()
                              .UseWatchOnlyWallet()
                              .UseBlockNotification()
                              .UseTransactionNotification()
                              .AddServiceNodeRegistration()
                              .UseApps()
                              .UseBlockExplorer()
                              .AddRPC();
                }

                var node = builder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.ToString());
            }
        }
Example #12
0
        public static async Task Main(string[] args)
        {
            try
            {
                Network network = args.Contains("-testnet")
                    ? NetworkRegistration.Register(new RedstoneTest())
                    : args.Contains("-regnet")
                    ? NetworkRegistration.Register(new RedstoneRegTest())
                    : NetworkRegistration.Register(new RedstoneMain());

                var nodeSettings = new NodeSettings(network: network, protocolVersion: ProtocolVersion.PROVEN_HEADER_VERSION, args: args)
                {
                    MinProtocolVersion = ProtocolVersion.ALT_PROTOCOL_VERSION
                };

                var dnsSettings = new DnsSettings(nodeSettings);

                var isDns = !IsNullOrWhiteSpace(dnsSettings.DnsHostName) &&
                            !IsNullOrWhiteSpace(dnsSettings.DnsNameServer) &&
                            !IsNullOrWhiteSpace(dnsSettings.DnsMailBox);

                var builder = new FullNodeBuilder()
                              .UseNodeSettings(nodeSettings);

                if (isDns)
                {
                    if (args.Contains("-cold"))
                    {
                        throw new InvalidOperationException("-cold not allowed with Dns");
                    }

                    // Run as a full node with DNS or just a DNS service?
                    if (dnsSettings.DnsFullNode)
                    {
                        builder = builder
                                  .UseBlockStore()
                                  .UseRedstonePosConsensus()
                                  .UseMempool()
                                  .UseWallet()
                                  .AddRedstoneMining();
                    }
                    else
                    {
                        builder = builder.UsePosConsensus();
                    }

                    builder = builder
                              .UseApi()
                              .AddRPC()
                              .UseDns();
                }
                else
                {
                    builder = builder
                              .UseBlockStore()
                              .UseRedstonePosConsensus()
                              .UseMempool()
                              .UseWallet()
                              .UseColdStakingWallet()
                              .AddRedstoneMining()
                              .UseApi()
                              .UseApps()
                              .AddRPC();
                }

                var node = builder.Build();

                if (node != null)
                {
                    await node.RunAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.ToString());
            }
        }