public AnchorBuilderTests()
 {
     this.anchorBuilder = new AnchorBuilder(
         new TestStorageEngine(transactions),
         recorder,
         state);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获取标签生成器
        /// </summary>
        protected override TagBuilder GetTagBuilder()
        {
            var builder = new AnchorBuilder();

            Config(builder);
            return(builder);
        }
 public AnchorBuilderTests()
 {
     this.anchorBuilder = new AnchorBuilder(
         new TestStorageEngine(transactions),
         recorder,
         state);
 }
Exemplo n.º 4
0
        public async Task Run(CancellationToken cancel)
        {
            IServiceScopeFactory scopeFactory = services.GetService <IServiceScopeFactory>();
            ILogger logger = services.GetRequiredService <ILogger>();

            while (!cancel.IsCancellationRequested)
            {
                using (IServiceScope scope = scopeFactory.CreateScope())
                {
                    IAnchorRecorder anchorRecorder = scope.ServiceProvider.GetService <IAnchorRecorder>();
                    IAnchorState    anchorState    = scope.ServiceProvider.GetService <IAnchorState>();

                    if (anchorRecorder == null || anchorState == null)
                    {
                        logger.LogInformation("Anchoring disabled");
                        return;
                    }

                    IStorageEngine storageEngine = scope.ServiceProvider.GetRequiredService <IStorageEngine>();

                    try
                    {
                        await storageEngine.Initialize();

                        await anchorState.Initialize();

                        AnchorBuilder anchorBuilder = new AnchorBuilder(storageEngine, anchorRecorder, anchorState);

                        while (!cancel.IsCancellationRequested)
                        {
                            LedgerAnchor anchor = await anchorBuilder.RecordAnchor();

                            if (anchor != null)
                            {
                                logger.LogInformation($"Recorded an anchor for {anchor.TransactionCount} transactions: {anchor.FullStoreHash.ToString()}");
                            }

                            await Task.Delay(TimeSpan.FromSeconds(10), cancel);
                        }
                    }
                    catch (Exception exception)
                    {
                        logger.LogError($"Error in the anchor worker:\r\n{exception}");

                        // Wait longer if an error occurred
                        await Task.Delay(TimeSpan.FromMinutes(1), cancel);
                    }
                }
            }
        }