public static void AddBeaconNodeQuickStart(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton <IOperationPool, MockedOperationPool>();

            if (!configuration.GetValue <bool>("QuickStart:UseSystemClock"))
            {
                long clockOffset = 0L;
                if (configuration.GetSection("QuickStart:ClockOffset").Exists())
                {
                    clockOffset = configuration.GetValue <long>("QuickStart:ClockOffset");
                }
                else if (configuration.GetSection("QuickStart:GenesisTime").Exists())
                {
                    ulong genesisTime = configuration.GetValue <ulong>("QuickStart:GenesisTime");
                    clockOffset = (long)genesisTime - DateTimeOffset.Now.ToUnixTimeSeconds();
                }

                if (clockOffset != 0)
                {
                    services.AddSingleton <IClock>(serviceProvider =>
                    {
                        ILogger <QuickStartClock> logger = serviceProvider.GetService <ILogger <QuickStartClock> >();
                        if (logger.IsWarn())
                        {
                            Log.QuickStartClockCreated(logger, clockOffset, null);
                        }
                        QuickStartClock quickStartClock = new QuickStartClock(clockOffset);
                        return(quickStartClock);
                    });
                }
            }
        }
Exemplo n.º 2
0
        public static void AddBeaconNodeQuickStart(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton <INodeStart, QuickStart>();
            services.AddSingleton <IEth1DataProvider, MockedEth1DataProvider>();
            services.AddSingleton <IOperationPool, MockedOperationPool>();
            services.Configure <QuickStartParameters>(x =>
            {
                configuration.Bind("QuickStart", section =>
                {
                    x.GenesisTime         = section.GetValue <ulong>("GenesisTime");
                    x.ValidatorCount      = section.GetValue <ulong>("ValidatorCount");
                    x.Eth1BlockHash       = new Hash32(section.GetBytesFromPrefixedHex("Eth1BlockHash", () => s_defaultEth1BlockHash));
                    x.Eth1Timestamp       = section.GetValue("Eth1Timestamp", DefaultEth1Timestamp);
                    x.UseSystemClock      = section.GetValue <bool>("UseSystemClock");
                    x.ValidatorStartIndex = section.GetValue <ulong>("ValidatorStartIndex");
                    x.NumberOfValidators  = section.GetValue <ulong>("NumberOfValidators");
                    x.ClockOffset         = section.GetValue <long>("ClockOffset");
                });
            });

            if (!configuration.GetValue <bool>("QuickStart:UseSystemClock"))
            {
                long clockOffset;
                if (configuration.GetSection("QuickStart:ClockOffset").Exists())
                {
                    clockOffset = configuration.GetValue <long>("QuickStart:ClockOffset");
                }
                else
                {
                    ulong genesisTime = configuration.GetValue <ulong>("QuickStart:GenesisTime");
                    clockOffset = (long)genesisTime - DateTimeOffset.Now.ToUnixTimeSeconds();
                }

                services.AddSingleton <IClock>(serviceProvider =>
                {
                    ILogger <QuickStartClock> logger = serviceProvider.GetService <ILogger <QuickStartClock> >();
                    if (logger.IsWarn())
                    {
                        Log.QuickStartClockCreated(logger, clockOffset, null);
                    }
                    QuickStartClock quickStartClock = new QuickStartClock(clockOffset);
                    return(quickStartClock);
                });
            }
        }
Exemplo n.º 3
0
        public static void AddQuickStart(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddSingleton <INodeStart, QuickStart>();
            services.Configure <QuickStartParameters>(x =>
            {
                configuration.Bind("QuickStart", section =>
                {
                    x.GenesisTime    = section.GetValue <ulong>("GenesisTime");
                    x.ValidatorCount = section.GetValue <ulong>("ValidatorCount");
                    x.Eth1BlockHash  = new Hash32(section.GetBytesFromPrefixedHex("Eth1BlockHash", () => s_defaultEth1BlockHash));
                    x.Eth1Timestamp  = section.GetValue("Eth1Timestamp", DefaultEth1Timestamp);
                    x.UseSystemClock = section.GetValue <bool>("UseSystemClock");
                });
            });

            if (!configuration.GetValue <bool>("QuickStart:UseSystemClock"))
            {
                var genesisTime     = configuration.GetValue <ulong>("QuickStart:GenesisTime");
                var quickStartClock = new QuickStartClock(genesisTime);
                services.AddSingleton <IClock>(quickStartClock);
            }
        }