Ejemplo n.º 1
0
        private static IContainer SetupIocContainer(bool isMiner, SmartContractRunnerFactory smartContractRunnerFactory)
        {
            var builder = new ContainerBuilder();

            //builder.RegisterModule(new MainModule()); // todo : eventually we won't need this

            // Module registrations
            builder.RegisterModule(new LoggerAutofacModule());
            builder.RegisterModule(new DatabaseAutofacModule());
            builder.RegisterModule(new NetworkAutofacModule());
            builder.RegisterModule(new MinerAutofacModule(null));
            builder.RegisterModule(new ChainAutofacModule());
            builder.RegisterModule(new KernelAutofacModule());
            builder.RegisterModule(new SmartContractAutofacModule());

            builder.RegisterInstance(smartContractRunnerFactory).As <ISmartContractRunnerFactory>().SingleInstance();
            builder.RegisterType <ServicePack>().PropertiesAutowired();
            builder.RegisterType <ActorEnvironment>().SingleInstance();
            IContainer container;

            try
            {
                container = builder.Build();
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return(null);
            }
            return(container);
        }
Ejemplo n.º 2
0
        public void Init(ContainerBuilder builder)
        {
            RunnerConfig.Instance.SdkDir = Path.GetDirectoryName(typeof(RunnerAElfModule).Assembly.Location);

            var runner = new SmartContractRunner();
            var smartContractRunnerFactory = new SmartContractRunnerFactory();

            smartContractRunnerFactory.AddRunner(0, runner);
            smartContractRunnerFactory.AddRunner(1, runner);

            builder.RegisterInstance(smartContractRunnerFactory).As <ISmartContractRunnerFactory>().SingleInstance();
        }
Ejemplo n.º 3
0
        protected override void ConfigureContainer(ContainerBuilder builder)
        {
            ChainConfig.Instance.ChainId    = Hash.Generate().DumpHex();
            NodeConfig.Instance.NodeAccount = Address.Generate().DumpHex();

            var assembly1 = typeof(IDataProvider).Assembly;

            builder.RegisterAssemblyTypes(assembly1).AsImplementedInterfaces();
            var assembly2 = typeof(ISerializer <>).Assembly;

            builder.RegisterAssemblyTypes(assembly2).AsImplementedInterfaces();
            var assembly3 = typeof(DataProvider).Assembly;

            builder.RegisterAssemblyTypes(assembly3).AsImplementedInterfaces();
            var assembly4 = typeof(BlockValidationService).Assembly;

            builder.RegisterAssemblyTypes(assembly4).AsImplementedInterfaces();
            var assembly5 = typeof(Execution.ParallelTransactionExecutingService).Assembly;

            builder.RegisterAssemblyTypes(assembly5).AsImplementedInterfaces();
            var assembly6 = typeof(AElf.Node.Node).Assembly;

            builder.RegisterAssemblyTypes(assembly6).AsImplementedInterfaces();
            var assembly7 = typeof(BlockHeader).Assembly;

            builder.RegisterAssemblyTypes(assembly7).AsImplementedInterfaces();
            builder.RegisterGeneric(typeof(Serializer <>)).As(typeof(ISerializer <>));

            builder.RegisterModule(new LoggerAutofacModule());
            builder.RegisterModule(new DatabaseAutofacModule());
            builder.RegisterModule(new SmartContractAutofacModule());
            builder.RegisterModule(new ChainAutofacModule());
            builder.RegisterModule(new KernelAutofacModule());
            builder.RegisterInstance(new TxPoolConfig()).As <ITxPoolConfig>();
            builder.RegisterType <ChainService>().As <IChainService>();
            builder.RegisterType <Grouper>().As <IGrouper>();
            builder.RegisterType <ServicePack>().PropertiesAutowired();
            builder.RegisterType <ActorEnvironment>().As <IActorEnvironment>().SingleInstance();
            builder.RegisterType <SimpleExecutingService>().As <IExecutingService>();

            var smartContractRunnerFactory = new SmartContractRunnerFactory();
            var runner = new SmartContractRunner(ContractCodes.TestContractFolder);

            smartContractRunnerFactory.AddRunner(0, runner);
            smartContractRunnerFactory.AddRunner(1, runner);
            builder.RegisterInstance(smartContractRunnerFactory).As <ISmartContractRunnerFactory>().SingleInstance();
            builder.RegisterType <TxValidator>().As <ITxValidator>();
            builder.RegisterType <TxSignatureVerifier>().As <ITxSignatureVerifier>();
            builder.RegisterType <TxRefBlockValidator>().As <ITxRefBlockValidator>();
            builder.RegisterType <TxHub>().As <ITxHub>();
            // configure your container
            // e.g. builder.RegisterModule<TestOverrideModule>();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var  confParser = new ConfigParser();
            bool parsed;

            try
            {
                parsed = confParser.Parse(args);
            }
            catch (Exception e)
            {
                _logger.Error(e, "Exception while parse config.");
                throw;
            }

            if (!parsed)
            {
                return;
            }

            RunnerConfig.Instance.SdkDir = Path.GetDirectoryName(typeof(RunnerAElfModule).Assembly.Location);
            var runner = new SmartContractRunner();
            var smartContractRunnerFactory = new SmartContractRunnerFactory();

            smartContractRunnerFactory.AddRunner(0, runner);
            smartContractRunnerFactory.AddRunner(1, runner);

            // Setup ioc
            var container = SetupIocContainer(true, smartContractRunnerFactory);

            if (container == null)
            {
                _logger.Error("IoC setup failed.");
                return;
            }

            if (!CheckDBConnect(container))
            {
                _logger.Error("Database connection failed.");
                return;
            }

            using (var scope = container.BeginLifetimeScope())
            {
                var service = scope.Resolve <ActorEnvironment>();
                service.InitWorkActorSystem();
                Console.WriteLine("Press Control + C to terminate.");
                Console.CancelKeyPress += async(sender, eventArgs) => { await service.StopAsync(); };
                service.TerminationHandle.Wait();
            }
        }
Ejemplo n.º 5
0
        protected override void ConfigureContainer(ContainerBuilder builder)
        {
            var assembly1 = typeof(IDataProvider).Assembly;

            builder.RegisterAssemblyTypes(assembly1).AsImplementedInterfaces();
            var assembly2 = typeof(ISerializer <>).Assembly;

            builder.RegisterAssemblyTypes(assembly2).AsImplementedInterfaces();
            var assembly3 = typeof(DataProvider).Assembly;

            builder.RegisterAssemblyTypes(assembly3).AsImplementedInterfaces();
            var assembly4 = typeof(BlockValidationService).Assembly;

            builder.RegisterAssemblyTypes(assembly4).AsImplementedInterfaces();
            var assembly5 = typeof(Execution.ParallelTransactionExecutingService).Assembly;

            builder.RegisterAssemblyTypes(assembly5).AsImplementedInterfaces();
            var assembly6 = typeof(AElf.Node.Node).Assembly;

            builder.RegisterAssemblyTypes(assembly6).AsImplementedInterfaces();
            var assembly7 = typeof(BlockHeader).Assembly;

            builder.RegisterAssemblyTypes(assembly7).AsImplementedInterfaces();
            builder.RegisterGeneric(typeof(Serializer <>)).As(typeof(ISerializer <>));

            builder.RegisterModule(new DatabaseAutofacModule());
            builder.RegisterModule(new LoggerAutofacModule());
            builder.RegisterModule(new ChainAutofacModule());
            builder.RegisterModule(new KernelAutofacModule());
            builder.RegisterModule(new SmartContractAutofacModule());

            var smartContractRunnerFactory = new SmartContractRunnerFactory();
            var runner = new SmartContractRunner("../../../../AElf.Runtime.CSharp.Tests.TestContract/bin/Debug/netstandard2.0/");

            smartContractRunnerFactory.AddRunner(0, runner);
            smartContractRunnerFactory.AddRunner(1, runner);
            builder.RegisterInstance(smartContractRunnerFactory).As <ISmartContractRunnerFactory>().SingleInstance();
            // configure your container
            // e.g. builder.RegisterModule<TestOverrideModule>();
        }
Ejemplo n.º 6
0
        public static async Task Main(string[] args)
        {
            BenchmarkOptions opts = null;

            Parser.Default.ParseArguments <BenchmarkOptions>(args)
            .WithParsed(o => { opts = o; })
            .WithNotParsed(errs => {});

            if (opts == null)
            {
                return;
            }

            if (opts.BenchmarkMethod == BenchmarkMethod.EvenGroup)
            {
                if (opts.SdkDir == null)
                {
                    opts.SdkDir = Directory.GetCurrentDirectory();
                    Console.WriteLine("No Sdk directory in arg, choose current directory: " + opts.SdkDir);
                }

                if (opts.DllDir == null)
                {
                    opts.DllDir = Directory.GetCurrentDirectory();
                    Console.WriteLine("No dll directory in arg, choose current directory: " + opts.DllDir);
                }

                if (!Directory.Exists(Path.GetFullPath(opts.SdkDir)))
                {
                    Console.WriteLine("directory " + Path.GetFullPath(opts.SdkDir) + " not exist");
                    return;
                }

                if (!File.Exists(Path.GetFullPath(Path.Combine(opts.DllDir, opts.ContractDll))))
                {
                    Console.WriteLine(
                        Path.GetFullPath(Path.Combine(opts.DllDir, opts.ContractDll) +
                                         " not exist"));
                    return;
                }

                if (!File.Exists(Path.GetFullPath(Path.Combine(opts.DllDir, opts.ZeroContractDll))))
                {
                    Console.WriteLine(
                        Path.GetFullPath(Path.Combine(opts.DllDir, opts.ZeroContractDll) +
                                         " not exist"));
                    return;
                }

                if (opts.GroupRange.Count() != 2 || opts.GroupRange.ElementAt(0) > opts.GroupRange.ElementAt(1))
                {
                    Console.WriteLine(
                        "please input 2 number to indicate the lower and upper bounds, where lower bound is lower than upper bound");
                    return;
                }

                if (opts.ConcurrencyLevel.HasValue)
                {
                    ActorConfig.Instance.ConcurrencyLevel = opts.ConcurrencyLevel.Value;
                }

                //enable parallel feature for benchmark
                ParallelConfig.Instance.IsParallelEnable = true;

                var builder = new ContainerBuilder();
                //builder.RegisterModule(new MainModule());
                builder.RegisterModule(new DatabaseAutofacModule());
                builder.RegisterModule(new LoggerAutofacModule());
                builder.RegisterModule(new ChainAutofacModule());
                builder.RegisterModule(new KernelAutofacModule());
                builder.RegisterModule(new SmartContractAutofacModule());
                builder.RegisterType <Benchmarks>().WithParameter("options", opts);
                var runner = new SmartContractRunner(opts.SdkDir);
                SmartContractRunnerFactory smartContractRunnerFactory = new SmartContractRunnerFactory();
                smartContractRunnerFactory.AddRunner(0, runner);
                smartContractRunnerFactory.AddRunner(1, runner);
                builder.RegisterInstance(smartContractRunnerFactory).As <ISmartContractRunnerFactory>().SingleInstance();

                if (ParallelConfig.Instance.IsParallelEnable)
                {
                    builder.RegisterType <Grouper>().As <IGrouper>();
                    builder.RegisterType <ServicePack>().As <ServicePack>().PropertiesAutowired();
                    builder.RegisterType <ActorEnvironment>().As <IActorEnvironment>().SingleInstance();
                    builder.RegisterType <ParallelTransactionExecutingService>().As <IExecutingService>();
                }
                else
                {
                    builder.RegisterType <SimpleExecutingService>().As <IExecutingService>();
                }

                var container = builder.Build();

                if (container == null)
                {
                    Console.WriteLine("IoC setup failed");
                    return;
                }

                if (!CheckDbConnect(container))
                {
                    Console.WriteLine("Database connection failed");
                    return;
                }

                using (var scope = container.BeginLifetimeScope())
                {
                    if (ParallelConfig.Instance.IsParallelEnable)
                    {
                        var actorEnv = scope.Resolve <IActorEnvironment>();
                        try
                        {
                            actorEnv.InitActorSystem();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }

                    var benchmarkTps = scope.Resolve <Benchmarks>();
                    await benchmarkTps.InitContract();

                    Thread.Sleep(200); //sleep 200 ms to let async console print in order
                    await benchmarkTps.BenchmarkEvenGroup();
                }
            }
            else if (opts.BenchmarkMethod == BenchmarkMethod.GenerateAccounts)
            {
                var dataGenerator = new TransactionDataGenerator(opts);
                dataGenerator.PersistAddrsToFile(opts.AccountFileDir);
            }

            Console.WriteLine("\n\nPress any key to continue ");
            Console.ReadKey();
        }