예제 #1
0
        public void Kill()
        {
            lock (this.lockObject)
            {
                this.runner.Stop();

                if (!this.runner.IsDisposed)
                {
                    throw new Exception($"Problem disposing of a node of type {this.runner.GetType()}.");
                }

                this.State = CoreNodeState.Killed;
            }
        }
예제 #2
0
		public void Kill(bool cleanFolder = true)
		{
			lock(l)
			{
				if(_Process != null && !_Process.HasExited)
				{
					_Process.Kill();
					_Process.WaitForExit();
				}
				_State = CoreNodeState.Killed;
				if(cleanFolder)
					CleanFolder();
			}
		}
예제 #3
0
        public async Task StartAsync()
        {
            var config = new NodeConfigParameters
            {
                { "regtest", "1" },
                { "regtest.rest", "1" },
                { "regtest.listenonion", "0" },
                { "regtest.server", "1" },
                { "regtest.txindex", "1" },
                { "regtest.rpcuser", Creds.UserName },
                { "regtest.rpcpassword", Creds.Password },
                { "regtest.whitebind", "127.0.0.1:" + P2pPort.ToString() },
                { "regtest.rpcport", RpcPort.ToString() },
                { "regtest.printtoconsole", "0" },               // Set it to one if do not mind loud debug logs
                { "regtest.keypool", "10" },
                { "regtest.pid", "bitcoind.pid" }
            };

            config.Import(ConfigParameters);
            File.WriteAllText(Config, config.ToString());
            using (await KillerLock.LockAsync())
            {
                Process = Process.Start(new FileInfo(Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
                State   = CoreNodeState.Starting;
                string pidFile = Path.Combine(DataDir, "regtest", "bitcoind.pid");
                if (!File.Exists(pidFile))
                {
                    Directory.CreateDirectory(Path.Combine(DataDir, "regtest"));
                    File.WriteAllText(pidFile, Process.Id.ToString());
                }
            }
            while (true)
            {
                try
                {
                    await CreateRpcClient().GetBlockHashAsync(0);

                    State = CoreNodeState.Running;
                    break;
                }
                catch
                {
                }
                if (Process is null || Process.HasExited)
                {
                    break;
                }
            }
        }
예제 #4
0
        private void StartBitcoinCoreRunner()
        {
            while (true)
            {
                try
                {
                    CreateRPCClient().GetBlockHashAsync(0).GetAwaiter().GetResult();
                    this.State = CoreNodeState.Running;
                    break;
                }
                catch { }

                Task.Delay(200);
            }
        }
예제 #5
0
 public void Kill(bool cleanFolder = true)
 {
     lock (_l)
     {
         if (_process != null && !_process.HasExited)
         {
             _process.Kill();
             _process.WaitForExit();
         }
         State = CoreNodeState.Killed;
         if (cleanFolder)
         {
             IoHelpers.DeleteRecursivelyWithMagicDustAsync(Folder).GetAwaiter().GetResult();
         }
     }
 }
예제 #6
0
        public CoreNode Start(Action startAction = null)
        {
            lock (this.lockObject)
            {
                this.runner.AddRewardClaimer         = this.addRewardClaimer;
                this.runner.AlwaysFlushBlocks        = this.builderAlwaysFlushBlocks;
                this.runner.EnablePeerDiscovery      = this.builderEnablePeerDiscovery;
                this.runner.OverrideDateTimeProvider = this.builderOverrideDateTimeProvider;

                if (this.builderNoValidation)
                {
                    this.DisableValidation();
                }

                this.runner.BuildNode();

                startAction?.Invoke();
                foreach (Action action in this.startActions)
                {
                    action.Invoke();
                }

                this.runner.Start();
                this.State = CoreNodeState.Starting;
            }

            if (this.runner is BitcoinCoreRunner)
            {
                WaitForExternalNodeStartup();
            }
            else
            {
                StartStratisRunner();
            }

            this.State = CoreNodeState.Running;

            foreach (Action runAction in this.runActions)
            {
                runAction.Invoke();
            }

            return(this);
        }
        public async Task StartAsync()
        {
            NodeConfigParameters config = new NodeConfigParameters();

            config.Add("regtest", "1");
            config.Add("rest", "1");
            config.Add("server", "1");
            config.Add("txindex", "1");
            config.Add("rpcuser", creds.UserName);
            config.Add("rpcpassword", creds.Password);
            if (!WhiteBind)
            {
                config.Add("port", ports[0].ToString());
            }
            else
            {
                config.Add("whitebind", "127.0.0.1:" + ports[0].ToString());
            }
            config.Add("rpcport", ports[1].ToString());
            config.Add("printtoconsole", "1");
            config.Add("keypool", "10");
            config.Import(ConfigParameters, true);
            File.WriteAllText(_Config, config.ToString());
            lock (l)
            {
                _Process = Process.Start(new FileInfo(this._Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + dataDir + " -debug=net");
                _State   = CoreNodeState.Starting;
            }
            while (true)
            {
                try
                {
                    await CreateRPCClient().GetBlockHashAsync(0).ConfigureAwait(false);

                    _State = CoreNodeState.Running;
                    break;
                }
                catch { }
                if (_Process == null || _Process.HasExited)
                {
                    break;
                }
            }
        }
예제 #8
0
        public void Start()
        {
            lock (this.lockObject)
            {
                this.runner.Start();
                this.State = CoreNodeState.Starting;
            }

            if (this.runner is BitcoinCoreRunner)
            {
                StartBitcoinCoreRunner();
            }
            else
            {
                StartStratisRunner();
            }

            this.State = CoreNodeState.Running;
        }
예제 #9
0
 /// <summary>
 /// Used with precompiled bitcoind and stratisd node
 /// executables, not SBFN runners.
 /// </summary>
 private void WaitForExternalNodeStartup()
 {
     TimeSpan duration = TimeSpan.FromMinutes(5);
     var cancellationToken = new CancellationTokenSource(duration).Token;
     TestBase.WaitLoop(() =>
     {
         try
         {
             CreateRPCClient().GetBlockHashAsync(0).GetAwaiter().GetResult();
             this.State = CoreNodeState.Running;
             return true;
         }
         catch
         {
             return false;
         }
     }, cancellationToken: cancellationToken,
         failureReason: $"Failed to invoke GetBlockHash on node instance after {duration}");
 }
예제 #10
0
        public async Task StartAsync()
        {
            var config = new NodeConfigParameters
            {
                { "regtest", "1" },
                { "regtest.rest", "1" },
                { "regtest.listenonion", "0" },
                { "regtest.server", "1" },
                { "regtest.txindex", "1" },
                { "regtest.rpcuser", Creds.UserName },
                { "regtest.rpcpassword", Creds.Password },
                { "regtest.whitebind", "127.0.0.1:" + _ports[0].ToString() },
                { "regtest.rpcport", _ports[1].ToString() },
                { "regtest.printtoconsole", "0" },               // Set it to one if don't mind loud debug logs
                { "regtest.keypool", "10" }
            };

            config.Import(ConfigParameters);
            File.WriteAllText(Config, config.ToString());
            lock (_l)
            {
                _process = Process.Start(new FileInfo(_Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
                State    = CoreNodeState.Starting;
            }
            while (true)
            {
                try
                {
                    await CreateRpcClient().GetBlockHashAsync(0);

                    State = CoreNodeState.Running;
                    break;
                }
                catch
                {
                }
                if (_process is null || _process.HasExited)
                {
                    break;
                }
            }
        }
예제 #11
0
        private void StartBitcoinCoreRunner()
        {
            TimeSpan duration          = TimeSpan.FromMinutes(5);
            var      cancellationToken = new CancellationTokenSource(duration).Token;

            TestHelper.WaitLoop(() =>
            {
                try
                {
                    CreateRPCClient().GetBlockHashAsync(0).GetAwaiter().GetResult();
                    this.State = CoreNodeState.Running;
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }, cancellationToken: cancellationToken,
                                failureReason: $"Failed to invoke GetBlockHash on BitcoinCore instance after {duration}");
        }
예제 #12
0
        private async Task Run()
        {
            lock (l)
            {
                if (_Builder.NodeImplementation.CreateWallet)
                {
                    CreateDefaultWallet();
                }

                string appPath = new FileInfo(this._Builder.BitcoinD).FullName;
                string args    = "-conf=bitcoin.conf" + " -datadir=" + dataDir + " -debug=net";

                if (_Builder.ShowNodeConsole)
                {
                    ProcessStartInfo info = new ProcessStartInfo(appPath, args);
                    info.UseShellExecute = true;
                    _Process             = Process.Start(info);
                }
                else
                {
                    _Process = Process.Start(appPath, args);
                }

                _State = CoreNodeState.Starting;
            }
            while (true)
            {
                try
                {
                    await CreateRPCClient().GetBlockHashAsync(0).ConfigureAwait(false);

                    _State = CoreNodeState.Running;
                    break;
                }
                catch { }
                if (_Process == null || _Process.HasExited)
                {
                    break;
                }
            }
        }
예제 #13
0
        public void Start()
        {
            Directory.CreateDirectory(this.runner.DataFolder);

            var config = new NodeConfigParameters();

            config.Add("regtest", "1");
            config.Add("rest", "1");
            config.Add("server", "1");
            config.Add("txindex", "1");
            if (!this.CookieAuth)
            {
                config.Add("rpcuser", this.creds.UserName);
                config.Add("rpcpassword", this.creds.Password);
            }
            config.Add("port", this.ports[0].ToString());
            config.Add("rpcport", this.ports[1].ToString());
            config.Add("apiport", this.ports[2].ToString());
            config.Add("printtoconsole", "1");
            config.Add("keypool", "10");
            config.Add("agentprefix", "node" + this.ports[0].ToString());
            config.Import(this.ConfigParameters);
            File.WriteAllText(this.Config, config.ToString());

            lock (this.lockObject)
            {
                this.runner.Start();
                this.State = CoreNodeState.Starting;
            }

            if (this.runner is BitcoinCoreRunner)
            {
                StartBitcoinCoreRunner();
            }
            else
            {
                StartStratisRunner();
            }

            this.State = CoreNodeState.Running;
        }
        public CoreNode(string folder, INodeRunner runner, NodeBuilder builder, bool cleanfolders = true, string configfile = "bitcoin.conf")
        {
            this.runner  = runner;
            this.builder = builder;
            this.folder  = folder;
            this.state   = CoreNodeState.Stopped;
            if (cleanfolders)
            {
                CleanFolder();
            }
            Directory.CreateDirectory(folder);
            this.dataDir = Path.Combine(folder, "data");
            Directory.CreateDirectory(this.dataDir);
            var pass = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20));

            this.creds  = new NetworkCredential(pass, pass);
            this.config = Path.Combine(this.dataDir, configfile);
            this.ConfigParameters.Import(builder.ConfigParameters);
            this.ports = new int[2];
            FindPorts(this.ports);
        }
        public async Task StartAsync()
        {
            NodeConfigParameters config = new NodeConfigParameters();

            config.Add("regtest", "1");
            config.Add("rest", "1");
            config.Add("server", "1");
            config.Add("txindex", "1");
            config.Add("rpcuser", this.creds.UserName);
            config.Add("rpcpassword", this.creds.Password);
            config.Add("port", this.ports[0].ToString());
            config.Add("rpcport", this.ports[1].ToString());
            config.Add("printtoconsole", "1");
            config.Add("keypool", "10");
            config.Import(this.ConfigParameters);
            File.WriteAllText(this.config, config.ToString());
            lock (this.lockObject)
            {
                this.runner.Start(this.dataDir);
                this.state = CoreNodeState.Starting;
            }
            while (true)
            {
                try
                {
                    await CreateRPCClient().GetBlockHashAsync(0);

                    this.state = CoreNodeState.Running;
                    break;
                }
                catch
                {
                }
                if (this.runner.HasExited)
                {
                    break;
                }
            }
        }
예제 #16
0
        private async Task Run()
        {
            lock (l)
            {
                _Process = Process.Start(new FileInfo(this._Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + dataDir + " -debug=net");
                _State   = CoreNodeState.Starting;
            }
            while (true)
            {
                try
                {
                    await CreateRPCClient().GetBlockHashAsync(0).ConfigureAwait(false);

                    _State = CoreNodeState.Running;
                    break;
                }
                catch { }
                if (_Process == null || _Process.HasExited)
                {
                    break;
                }
            }
        }