From 3edd99d39b3c52b408d05e3f99b616cf0c09ac22 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Thu, 5 Sep 2024 14:58:01 +0900 Subject: [PATCH 1/3] Replaced preload state reporting with dummies --- .../GraphTypes/StandaloneSubscriptionTest.cs | 91 ------------------- .../GraphTypes/StandaloneSubscription.cs | 31 +------ 2 files changed, 4 insertions(+), 118 deletions(-) diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs index 91cde4e91..c6bf40997 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneSubscriptionTest.cs @@ -126,97 +126,6 @@ public async Task SubscribeTx() return (block, transactions); } - [Fact] - public async Task SubscribePreloadProgress() - { - var cts = new CancellationTokenSource(); - - var apvPrivateKey = new PrivateKey(); - var apv = AppProtocolVersion.Sign(apvPrivateKey, 0); - var genesisBlock = BlockChain.ProposeGenesisBlock( - transactions: new IAction[] - { - new Initialize( - new ValidatorSet( - new[] - { - new Validator(ProposerPrivateKey.PublicKey, BigInteger.One), - new Validator(apvPrivateKey.PublicKey, BigInteger.One) - } - .ToList()), - states: ImmutableDictionary.Create()) - }.Select((sa, nonce) => Transaction.Create(nonce, new PrivateKey(), null, new[] { sa.PlainValue })) - .ToImmutableList(), - privateKey: new PrivateKey()); - var validators = new List - { - ProposerPrivateKey, apvPrivateKey - }.OrderBy(x => x.Address).ToList(); - - // 에러로 인하여 NineChroniclesNodeService 를 사용할 수 없습니다. https://git.io/JfS0M - // 따라서 LibplanetNodeService로 비슷한 환경을 맞춥니다. - // 1. 노드를 생성합니다. - var seedNode = CreateLibplanetNodeService(genesisBlock, apv, apvPrivateKey.PublicKey); - await StartAsync(seedNode.Swarm, cts.Token); - - // 2. Progress를 넘겨 preloadProgress subscription 과 연결합니다. - var service = CreateLibplanetNodeService( - genesisBlock, - apv, - apvPrivateKey.PublicKey, - new Progress(state => - { - StandaloneContextFx.PreloadStateSubject.OnNext(state); - }), - new[] { seedNode.Swarm.AsPeer }); - - Block block = seedNode.BlockChain.ProposeBlock(ProposerPrivateKey); - seedNode.BlockChain.Append(block, GenerateBlockCommit(block.Index, block.Hash, validators)); - var result = await ExecuteSubscriptionQueryAsync("subscription { preloadProgress { currentPhase totalPhase extra { type currentCount totalCount } } }"); - Assert.IsType(result); - - _ = service.StartAsync(cts.Token); - - await service.PreloadEnded.WaitAsync(cts.Token); - - var subscribeResult = (SubscriptionExecutionResult)result; - var stream = subscribeResult.Streams!.Values.FirstOrDefault(); - - // BlockHashDownloadState : 2 - // BlockDownloadState : 1 - // BlockVerificationState : 1 - // ActionExecutionState : 1 - var preloadProgressRecords = - new List<(long currentPhase, long totalPhase, string type, long currentCount, long totalCount)>(); - var expectedPreloadProgress = new[] - { - (1L, 5L, "BlockHashDownloadState", 0L, 0L), - (1L, 5L, "BlockHashDownloadState", 1L, 1L), - (2L, 5L, "BlockDownloadState", 1L, 1L), - (3L, 5L, "BlockVerificationState", 1L, 1L), - (5L, 5L, "ActionExecutionState", 1L, 1L), - }.ToImmutableHashSet(); - foreach (var index in Enumerable.Range(1, expectedPreloadProgress.Count())) - { - var rawEvents = await stream.Take(index); - var events = (Dictionary)((ExecutionNode)rawEvents.Data!).ToValue()!; - var preloadProgress = (Dictionary)events["preloadProgress"]; - var preloadProgressExtra = (Dictionary)preloadProgress["extra"]; - - preloadProgressRecords.Add(( - (long)preloadProgress["currentPhase"], - (long)preloadProgress["totalPhase"], - (string)preloadProgressExtra["type"], - (long)preloadProgressExtra["currentCount"], - (long)preloadProgressExtra["totalCount"])); - } - - Assert.Equal(expectedPreloadProgress, preloadProgressRecords.ToImmutableHashSet()); - - await seedNode.StopAsync(cts.Token); - await service.StopAsync(cts.Token); - } - [Fact(Timeout = 25000)] public async Task SubscribeDifferentAppProtocolVersionEncounter() { diff --git a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs index f0d278ecc..083aa38cf 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs @@ -90,34 +90,11 @@ public PreloadStateExtraType() public PreloadStateType() { - Field>(name: "currentPhase", resolve: context => context.Source.CurrentPhase); - Field>(name: "totalPhase", resolve: context => BlockSyncState.TotalPhase); + // Dummy report. + Field>(name: "currentPhase", resolve: context => 0); + Field>(name: "totalPhase", resolve: context => 0); Field>(name: "extra", resolve: context => - { - var preloadState = context.Source; - return preloadState switch - { - ActionExecutionState actionExecutionState => new PreloadStateExtra(nameof(ActionExecutionState), - actionExecutionState.ExecutedBlockCount, - actionExecutionState.TotalBlockCount), - BlockDownloadState blockDownloadState => new PreloadStateExtra(nameof(BlockDownloadState), - blockDownloadState.ReceivedBlockCount, - blockDownloadState.TotalBlockCount), - BlockHashDownloadState blockHashDownloadState => new PreloadStateExtra( - nameof(BlockHashDownloadState), - blockHashDownloadState.ReceivedBlockHashCount, - blockHashDownloadState.EstimatedTotalBlockHashCount), - BlockVerificationState blockVerificationState => new PreloadStateExtra( - nameof(BlockVerificationState), - blockVerificationState.VerifiedBlockCount, - blockVerificationState.TotalBlockCount), - StateDownloadState stateDownloadState => new PreloadStateExtra( - nameof(StateDownloadState), - stateDownloadState.ReceivedIterationCount, - stateDownloadState.TotalIterationCount), - _ => throw new ExecutionError($"Not supported preload state. {preloadState.GetType()}"), - }; - }); + new PreloadStateExtra(nameof(BlockSyncState), 0, 0)); } } From 1dd286e3cc960e3ad80c822be5a4e240617eda1f Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 6 Sep 2024 09:58:45 +0900 Subject: [PATCH 2/3] Added deprecation note --- NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs index 083aa38cf..af0600912 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs @@ -143,6 +143,7 @@ public StandaloneSubscription(StandaloneContext standaloneContext, IConfiguratio AddField(new EventStreamFieldType { Name = "preloadProgress", + DeprecationReason = "Since Libplanet 5.3.0 preload progress is no longer reported.", Type = typeof(PreloadStateType), Resolver = new FuncFieldResolver(context => (context.Source as BlockSyncState)!), Subscriber = new EventStreamResolver(context => StandaloneContext.PreloadStateSubject.AsObservable()), From f91e6151eb0a67db7f7a870178a00e8f3b392fe1 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 6 Sep 2024 10:23:34 +0900 Subject: [PATCH 3/3] Cleanup --- Libplanet.Headless/Hosting/LibplanetNodeService.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Libplanet.Headless/Hosting/LibplanetNodeService.cs b/Libplanet.Headless/Hosting/LibplanetNodeService.cs index f918f14a4..8cc6e3b77 100644 --- a/Libplanet.Headless/Hosting/LibplanetNodeService.cs +++ b/Libplanet.Headless/Hosting/LibplanetNodeService.cs @@ -373,9 +373,6 @@ Task BootstrapSwarmAsync(int depth) dialTimeout: null, cancellationToken: cancellationToken); - // We assume the first phase of preloading is BlockHashDownloadState... - ((IProgress)PreloadProgress)?.Report(new BlockHashDownloadState()); - if (peers.Any()) { try