Example #1
0
        public static int Main(string[] args)
        {
            _logger = new NLogLogger("spawner.logs.txt");

            if (args.Length > 1)
            {
                _logger.Error("Expecting at most one argument - the name of the config file (default when empty).");
                Console.ReadLine();
                return(1);
            }

            string configFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, args.Length == 1 ? args[0] : "spawner.json");
            string jsonText       = File.ReadAllText(configFileName);

            IJsonSerializer serializer    = new UnforgivingJsonSerializer();
            SpawnerConfig   spawnerConfig = serializer.Deserialize <SpawnerConfig>(jsonText);

            foreach ((string name, InitParams parameters) in spawnerConfig.Runners)
            {
                string serialized       = serializer.Serialize(parameters, true);
                string singleConfigPath = Path.Combine(Path.GetTempPath(), $"nethermind.runner.{name}.config.json");
                File.WriteAllText(singleConfigPath, serialized);

                CreateAppConsole(spawnerConfig.ReleasePath, name, new[] { singleConfigPath });
            }

            _logger.Info("Press ENTER to close all the spawned processes.");
            Console.ReadLine();
            foreach ((string name, Process process) in Processes)
            {
                _logger.Info($"Closing {name}...");
                if (!process.HasExited)
                {
                    process.Kill();
                    process.WaitForExit(5000);
                    if (process.HasExited)
                    {
                        _logger.Info($"{name} closed.");
                    }
                    else
                    {
                        _logger.Error($"{name} could not be closed.");
                    }
                }
                else
                {
                    _logger.Info($"{name} already exited.");
                }

                process.Close();
            }

            _logger.Info("Press ENTER to exit.");

            Console.ReadKey();
            return(0);
        }
Example #2
0
        public static async Task Main(params string[] args)
        {
            HttpClient client = new HttpClient();

            string[] transactionHashes = Directory.GetFiles(@"D:\tx_traces\nethermind").Select(Path.GetFileNameWithoutExtension).ToArray();
            for (int i = 0; i < transactionHashes.Length; i++)
            {
                try
                {
                    string gethPath = "D:\\tx_traces\\geth_" + transactionHashes[i] + ".txt";
                    string nethPath = "D:\\tx_traces\\nethermind\\" + transactionHashes[i] + ".txt";

                    Console.WriteLine($"Downloading {i} of {transactionHashes.Length}");
                    HttpRequestMessage msg = new HttpRequestMessage(HttpMethod.Post, "http://10.0.1.6:8545");
                    msg.Content = new StringContent($"{{\"jsonrpc\":\"2.0\",\"method\":\"debug_traceTransaction\",\"params\":[\"{transactionHashes[i]}\"],\"id\":42}}");
                    msg.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    HttpResponseMessage rsp = await client.SendAsync(msg);

                    string text = await rsp.Content.ReadAsStringAsync();

                    File.WriteAllText(gethPath, text);

                    IJsonSerializer         serializer = new UnforgivingJsonSerializer();
                    WrappedTransactionTrace gethTrace  = serializer.Deserialize <WrappedTransactionTrace>(text);
                    string           nethText          = File.ReadAllText(nethPath);
                    TransactionTrace nethTrace         = serializer.Deserialize <TransactionTrace>(nethText);

                    if (gethTrace.Result.Gas != nethTrace.Gas)
                    {
                        Console.WriteLine($"Gas difference in {transactionHashes[i]} - neth {nethTrace.Gas} vs geth {gethTrace.Result.Gas}");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Failed at {i} with {e}");
                }
            }

            Console.WriteLine("Complete");
            Console.ReadLine();
        }
Example #3
0
        protected override (CommandLineApplication, Func <InitParams>) BuildCommandLineApp()
        {
            var app = new CommandLineApplication {
                Name = "Nethermind.Runner"
            };

            app.HelpOption("-?|-h|--help");
            var configFile = app.Option("-c|--config <configFile>", "config file path", CommandOptionType.SingleValue);

            InitParams InitParams()
            {
                IJsonSerializer serializer = new UnforgivingJsonSerializer();

                return(serializer.Deserialize <InitParams>(File.ReadAllText(configFile.HasValue() ? configFile.Value() : DefaultConfigFile)));
            };

            return(app, InitParams);
        }
Example #4
0
        public static int Main(string[] args)
        {
            _logger = new SimpleConsoleLogger();

            if (args.Length > 1)
            {
                _logger.Error("Expecting at most one argument - the name of the config file (default when empty).");
                Console.ReadLine();
                return(1);
            }

            string configFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, args.Length == 1 ? args[0] : "spawner_discovery_large.json");
            string jsonText       = File.ReadAllText(configFileName);

            IJsonSerializer serializer    = new UnforgivingJsonSerializer();
            SpawnerConfig   spawnerConfig = serializer.Deserialize <SpawnerConfig>(jsonText);

            var configTempDir = Path.Combine(Path.GetTempPath(), "SpawnerConfigs");

            if (!Directory.Exists(configTempDir))
            {
                Directory.CreateDirectory(configTempDir);
            }

            var files = Directory.GetFiles(configTempDir);

            foreach (var file in files)
            {
                File.Delete(file);
            }

            _logger.Info($"Storing all runner configs in: {configTempDir}");

            List <ProcessWrapper> wrappers = new List <ProcessWrapper>();

            foreach ((string name, JToken parameters) in spawnerConfig.Runners)
            {
                string serialized       = serializer.Serialize(parameters, true);
                string singleConfigPath = Path.Combine(configTempDir, $"nethermind.runner.{name}.cfg");
                File.WriteAllText(singleConfigPath, serialized);

                try
                {
                    wrappers.Add(CreateAppConsole(spawnerConfig.ReleasePath, spawnerConfig.DbBasePath, name, new[] { singleConfigPath }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            ChaosMonkey chaosMonkey = new ChaosMonkey(_logger, new ChaosMonkey.ChaosMonkeyOptions {
                IntervalSeconds = 0, AllDownIntervalSeconds = 0
            }, wrappers.ToArray());

            chaosMonkey.Start();

            _logger.Info("Press ENTER to close all the spawned processes.");
            Console.ReadLine();

            chaosMonkey.Stop();

            _logger.Info("Press ENTER to exit.");

            Console.ReadKey();
            return(0);
        }