From bab19f0c36c1cdd62cab74e3b6380ec391647c2b Mon Sep 17 00:00:00 2001 From: hyeon Date: Mon, 22 Jul 2024 17:03:22 +0900 Subject: [PATCH 1/8] Bump headless: release/170 --- NineChronicles.Headless | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineChronicles.Headless b/NineChronicles.Headless index de03aa5b..68ccd1bd 160000 --- a/NineChronicles.Headless +++ b/NineChronicles.Headless @@ -1 +1 @@ -Subproject commit de03aa5b59e30426375120e4d257963016d67913 +Subproject commit 68ccd1bd3289f708ecbac12e32aa181124a02f6c From d6b5fb5882da60ba5592bfaf4665e3f3154d9f17 Mon Sep 17 00:00:00 2001 From: area363 Date: Tue, 23 Jul 2024 11:32:58 +0900 Subject: [PATCH 2/8] fix libplanet project reference --- .../NineChronicles.DataProvider.Tests.csproj | 1 + NineChronicles.DataProvider.sln | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj b/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj index 2d984808..4958c21f 100644 --- a/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj +++ b/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj @@ -23,6 +23,7 @@ + diff --git a/NineChronicles.DataProvider.sln b/NineChronicles.DataProvider.sln index 792a72e5..ed8e2303 100644 --- a/NineChronicles.DataProvider.sln +++ b/NineChronicles.DataProvider.sln @@ -24,11 +24,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c.Renderers", "NineChro EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c.Utils", "NineChronicles.Headless\Lib9c\Lib9c.Utils\Lib9c.Utils.csproj", "{0B12D053-8CB1-445E-91AA-D23EDDE2CC88}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Action", "NineChronicles.Headless\Lib9c\.Libplanet\Libplanet.Action\Libplanet.Action.csproj", "{116A01C6-D07A-4E5B-87E1-871D931CFCFE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Action", "NineChronicles.Headless\Lib9c\.Libplanet\src\Libplanet.Action\Libplanet.Action.csproj", "{116A01C6-D07A-4E5B-87E1-871D931CFCFE}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c", "NineChronicles.Headless\Lib9c\Lib9c\Lib9c.csproj", "{CED5FBEB-7EE8-477D-B5A5-B6B2BEEBCA61}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Mocks", "NineChronicles.Headless\Lib9c\.Libplanet\Libplanet.Mocks\Libplanet.Mocks.csproj", "{994BA4E6-804B-45A1-B1A4-7230368C4914}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Mocks", "NineChronicles.Headless\Lib9c\.Libplanet\test\Libplanet.Mocks\Libplanet.Mocks.csproj", "{994BA4E6-804B-45A1-B1A4-7230368C4914}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From ce69a6f60d8a37be0c3a351601233524f4ef1288 Mon Sep 17 00:00:00 2001 From: area363 Date: Wed, 24 Jul 2024 07:10:14 +0900 Subject: [PATCH 3/8] auto migrate db --- .../Program.cs | 101 +++++++++++------- .../NineChronicles.DataProvider.Tests.csproj | 1 - 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/NineChronicles.DataProvider.Executable/Program.cs b/NineChronicles.DataProvider.Executable/Program.cs index c8c66087..ec64c3ac 100644 --- a/NineChronicles.DataProvider.Executable/Program.cs +++ b/NineChronicles.DataProvider.Executable/Program.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Net.Http; using Libplanet.Headless.Hosting; +using Microsoft.Extensions.Logging; using Nekoyume.Action.Loader; using IPAddress = System.Net.IPAddress; @@ -38,51 +39,12 @@ public class Program : CoconaLiteConsoleAppBase { public static async Task Main(string[] args) { + var host = CreateHostBuilder(args).Build(); + await MigrateDatabaseAsync(host); await CoconaLiteApp.CreateHostBuilder() .RunAsync(args); } - // EF Core uses this method at design time to access the DbContext - public static IHostBuilder CreateHostBuilder(string[] args) - => Host.CreateDefaultBuilder(args) - .ConfigureServices(services => - { - services.AddDbContextFactory(options => - { - // Get configuration from appsettings or env - var configurationBuilder = new ConfigurationBuilder() - .AddJsonFile("appsettings.json") - .AddEnvironmentVariables("NC_"); - IConfiguration config = configurationBuilder.Build(); - var headlessConfig = new Configuration(); - config.Bind(headlessConfig); - if (headlessConfig.MySqlConnectionString != string.Empty) - { - args = new[] { headlessConfig.MySqlConnectionString }; - } - - if (args.Length == 1) - { - options.UseMySql( - args[0], - ServerVersion.AutoDetect( - args[0]), - b => - { - b.MigrationsAssembly("NineChronicles.DataProvider.Executable"); - b.CommandTimeout(600000); - }); - } - else - { - options.UseSqlite( - @"Data Source=9c.gg.db", - b => b.MigrationsAssembly("NineChronicles.DataProvider.Executable") - ); - } - }); - }); - [PrimaryCommand] public async Task Run( [Option(Description = "The path of the appsettings JSON file.")] string? configPath = null) @@ -276,5 +238,62 @@ IActionEvaluatorConfiguration GetActionEvaluatorConfiguration(IConfiguration con await hostBuilder.RunConsoleAsync(token); } + + // EF Core uses this method at design time to access the DbContext + private static IHostBuilder CreateHostBuilder(string[] args) + => Host.CreateDefaultBuilder(args) + .ConfigureServices(services => + { + services.AddDbContextFactory(options => + { + // Get configuration from appsettings or env + var configurationBuilder = new ConfigurationBuilder() + .AddJsonFile("appsettings.json") + .AddEnvironmentVariables("NC_"); + IConfiguration config = configurationBuilder.Build(); + var headlessConfig = new Configuration(); + config.Bind(headlessConfig); + if (headlessConfig.MySqlConnectionString != string.Empty) + { + args = new[] { headlessConfig.MySqlConnectionString }; + } + + if (args.Length == 1) + { + options.UseMySql( + args[0], + ServerVersion.AutoDetect( + args[0]), + b => + { + b.MigrationsAssembly("NineChronicles.DataProvider.Executable"); + b.CommandTimeout(600000); + }); + } + else + { + options.UseSqlite( + @"Data Source=9c.gg.db", + b => b.MigrationsAssembly("NineChronicles.DataProvider.Executable") + ); + } + }); + }); + + private static async Task MigrateDatabaseAsync(IHost host) + { + using var scope = host.Services.CreateScope(); + var services = scope.ServiceProvider; + try + { + var context = ServiceProviderServiceExtensions.GetRequiredService(services); + await context.Database.MigrateAsync(); + } + catch (Exception ex) + { + var logger = ServiceProviderServiceExtensions.GetRequiredService>(services); + logger.LogError(ex, "An error occurred while migrating the database."); + } + } } } diff --git a/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj b/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj index 4958c21f..35c5c327 100644 --- a/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj +++ b/NineChronicles.DataProvider.Tests/NineChronicles.DataProvider.Tests.csproj @@ -22,7 +22,6 @@ - From 05e950823a15c4b8cee2a44d61b07e0532b450ee Mon Sep 17 00:00:00 2001 From: area363 Date: Wed, 24 Jul 2024 12:42:52 +0900 Subject: [PATCH 4/8] add adventure boss migration code --- .../Commands/MySqlMigration.cs | 172 +++++++++++++++++- .../Store/MySql/AdventureBossStore.cs | 11 ++ .../AdventureBossRenderSubscriber.cs | 83 +++------ 3 files changed, 200 insertions(+), 66 deletions(-) diff --git a/NineChronicles.DataProvider.Executable/Commands/MySqlMigration.cs b/NineChronicles.DataProvider.Executable/Commands/MySqlMigration.cs index 92dca5d8..4f971879 100644 --- a/NineChronicles.DataProvider.Executable/Commands/MySqlMigration.cs +++ b/NineChronicles.DataProvider.Executable/Commands/MySqlMigration.cs @@ -1,4 +1,7 @@ +using Nekoyume.Action.AdventureBoss; using Nekoyume.Model.EnumType; +using NineChronicles.DataProvider.DataRendering.AdventureBoss; +using NineChronicles.DataProvider.Store.Models.AdventureBoss; namespace NineChronicles.DataProvider.Executable.Commands { @@ -43,6 +46,12 @@ namespace NineChronicles.DataProvider.Executable.Commands public class MySqlMigration { + private readonly Dictionary _adventureBossSeasonDict = new (); + private readonly List _adventureBossWantedList = new (); + private readonly List _adventureBossChallengeList = new (); + private readonly List _adventureBossRushList = new (); + private readonly List _adventureBossUnlockFloorList = new (); + private readonly List _adventureBossClaimRewardList = new (); private string _connectionString; private IStore _baseStore; private BlockChain _baseChain; @@ -93,7 +102,7 @@ public class MySqlMigration private List _requestPledgeList; [Command(Description = "Migrate action data in rocksdb store to mysql db.")] - public void Migration( + public async Task Migration( [Option('o', Description = "Rocksdb path to migrate.")] string storePath, [Option( @@ -191,7 +200,9 @@ public void Migration( _ => blockPolicy.BlockAction, baseStateStore, new NCActionLoader()); - _baseChain = new BlockChain(blockPolicy, stagePolicy, _baseStore, baseStateStore, genesis, blockChainStates, actionEvaluator); + _baseChain = new BlockChain( + blockPolicy, stagePolicy, _baseStore, baseStateStore, genesis, blockChainStates, actionEvaluator + ); // Check offset and limit value based on chain height long height = _baseChain.Tip.Index; @@ -273,7 +284,11 @@ public void Migration( } foreach (var item in - _baseStore.IterateIndexes(_baseChain.Id, offset + offsetIdx ?? 0 + offsetIdx, limitInterval).Select((value, i) => new { i, value })) + _baseStore.IterateIndexes( + _baseChain.Id, + offset + offsetIdx ?? 0 + offsetIdx, + limitInterval + ).Select((value, i) => new { i, value })) { var block = _baseStore.GetBlock(item.value); _blockList.Add(BlockData.GetBlockInfo(block)); @@ -292,12 +307,20 @@ public void Migration( } } - taskArray[item.i] = Task.Factory.StartNew(() => + try { - List actionEvaluations = EvaluateBlock(block); - Console.WriteLine($"Block progress: #{block.Index}/{remainingCount}"); - return actionEvaluations; - }); + taskArray[item.i] = Task.Factory.StartNew(() => + { + List actionEvaluations = EvaluateBlock(block); + Console.WriteLine($"Block progress: #{block.Index}/{remainingCount}"); + return actionEvaluations; + }); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + } } if (interval < remainingCount) @@ -362,10 +385,46 @@ public void Migration( _mySqlStore.StorePetEnhancementList(_petEnhancementList); _mySqlStore.StoreTransferAssetList(_transferAssetList); _mySqlStore.StoreRequestPledgeList(_requestPledgeList); + await Task.Run(async () => + { + Console.WriteLine($"[Adventure Boss] {_adventureBossSeasonDict.Count} Season"); + await _mySqlStore.StoreAdventureBossSeasonList(_adventureBossSeasonDict.Values.ToList()); + }); + + await Task.Run(async () => + { + Console.WriteLine($"[Adventure Boss] {_adventureBossWantedList.Count} Wanted"); + await _mySqlStore.StoreAdventureBossWantedList(_adventureBossWantedList); + }); + + await Task.Run(async () => + { + Console.WriteLine($"[Adventure Boss] {_adventureBossChallengeList.Count} Challenge"); + await _mySqlStore.StoreAdventureBossChallengeList(_adventureBossChallengeList); + }); + + await Task.Run(async () => + { + Console.WriteLine($"[Adventure Boss] {_adventureBossRushList.Count} Rush"); + await _mySqlStore.StoreAdventureBossRushList(_adventureBossRushList); + }); + + await Task.Run(async () => + { + Console.WriteLine($"[Adventure Boss] {_adventureBossUnlockFloorList.Count} Unlock"); + await _mySqlStore.StoreAdventureBossUnlockFloorList(_adventureBossUnlockFloorList); + }); + + await Task.Run(async () => + { + Console.WriteLine($"[Adventure Boss] {_adventureBossClaimRewardList.Count} claim"); + await _mySqlStore.StoreAdventureBossClaimRewardList(_adventureBossClaimRewardList); + }); } catch (Exception e) { Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); } DateTimeOffset end = DateTimeOffset.UtcNow; @@ -1141,6 +1200,103 @@ private void ProcessTasks(Task>[] taskArray, IB Console.WriteLine( "Stored RequestPledge action in block #{0}. Time Taken: {1} ms.", ae.InputContext.BlockIndex, (end - start).Milliseconds); } + + switch (action) + { + // avatarNames will be stored as "N/A" for optimization + case Wanted wanted: + _avatarList.Add(AvatarData.GetAvatarInfo( + outputState, + ae.InputContext.Signer, + wanted.AvatarAddress, + _blockTimeOffset, + BattleType.Adventure + )); + _adventureBossWantedList.Add(AdventureBossWantedData.GetWantedInfo( + outputState, _blockIndex, _blockTimeOffset, wanted + )); + Console.WriteLine( + $"[Adventure Boss] Wanted added : {_adventureBossWantedList.Count}"); + + // Update season info + _adventureBossSeasonDict[wanted.Season] = + AdventureBossSeasonData.GetAdventureBossSeasonInfo( + outputState, wanted.Season, _blockTimeOffset + ); + Console.WriteLine( + $"[Adventure Boss] Season added : {_adventureBossSeasonDict.Count}"); + break; + case ExploreAdventureBoss challenge: + _avatarList.Add(AvatarData.GetAvatarInfo( + outputState, + ae.InputContext.Signer, + challenge.AvatarAddress, + _blockTimeOffset, + BattleType.Adventure + )); + _adventureBossChallengeList.Add(AdventureBossChallengeData.GetChallengeInfo( + inputState, outputState, _blockIndex, _blockTimeOffset, challenge + )); + Console.WriteLine( + $"[Adventure Boss] Challenge added : {_adventureBossChallengeList.Count}"); + break; + case SweepAdventureBoss rush: + _avatarList.Add(AvatarData.GetAvatarInfo( + outputState, + ae.InputContext.Signer, + rush.AvatarAddress, + _blockTimeOffset, + BattleType.Adventure + )); + _adventureBossRushList.Add(AdventureBossRushData.GetRushInfo( + inputState, outputState, _blockIndex, _blockTimeOffset, rush + )); + Console.WriteLine( + $"[Adventure Boss] Rush added : {_adventureBossRushList.Count}"); + break; + case UnlockFloor unlock: + _avatarList.Add(AvatarData.GetAvatarInfo( + outputState, + ae.InputContext.Signer, + unlock.AvatarAddress, + _blockTimeOffset, + BattleType.Adventure + )); + _adventureBossUnlockFloorList.Add(AdventureBossUnlockFloorData.GetUnlockInfo( + inputState, outputState, _blockIndex, _blockTimeOffset, unlock + )); + Console.WriteLine( + $"[Adventure Boss] Unlock added : {_adventureBossUnlockFloorList.Count}"); + break; + case ClaimAdventureBossReward claim: + { + _avatarList.Add(AvatarData.GetAvatarInfo( + outputState, + ae.InputContext.Signer, + claim.AvatarAddress, + _blockTimeOffset, + BattleType.Adventure + )); + _adventureBossClaimRewardList.Add(AdventureBossClaimRewardData.GetClaimInfo( + inputState, _blockIndex, _blockTimeOffset, claim + )); + Console.WriteLine( + $"[Adventure Boss] Claim added : {_adventureBossClaimRewardList.Count}"); + + // Update season info + var latestSeason = inputState.GetLatestAdventureBossSeason(); + var season = latestSeason.EndBlockIndex <= _blockIndex + ? latestSeason.Season // New season not started + : latestSeason.Season - 1; // New season started + _adventureBossSeasonDict[season] = + AdventureBossSeasonData.GetAdventureBossSeasonInfo( + outputState, season, _blockTimeOffset + ); + Console.WriteLine( + $"[Adventure Boss] Season updated : {_adventureBossSeasonDict.Count}"); + break; + } + } } } } diff --git a/NineChronicles.DataProvider/Store/MySql/AdventureBossStore.cs b/NineChronicles.DataProvider/Store/MySql/AdventureBossStore.cs index a89f43be..5da342bd 100644 --- a/NineChronicles.DataProvider/Store/MySql/AdventureBossStore.cs +++ b/NineChronicles.DataProvider/Store/MySql/AdventureBossStore.cs @@ -42,6 +42,7 @@ public async partial Task StoreAdventureBossSeasonList(List(); + Log.Debug("[DataProvider] AdventureBossStore adventure boss list"); tasks.Add(Task.Run(async () => { + Log.Debug($"[Adventure Boss] {_adventureBossSeasonDict.Count} Season"); await MySqlStore.StoreAdventureBossSeasonList(_adventureBossSeasonDict.Values.ToList()); } )); tasks.Add(Task.Run(async () => { + Log.Debug($"[DataProvider] AdventureBoss{_adventureBossWantedList.Count} Wanted"); await MySqlStore.StoreAdventureBossWantedList(_adventureBossWantedList); } )); tasks.Add(Task.Run(async () => { + Log.Debug($"[DataProvider] AdventureBoss{_adventureBossChallengeList.Count} Challenge"); await MySqlStore.StoreAdventureBossChallengeList(_adventureBossChallengeList); } )); tasks.Add(Task.Run(async () => { + Log.Debug($"[DataProvider] AdventureBoss{_adventureBossRushList.Count} Rush"); await MySqlStore.StoreAdventureBossRushList(_adventureBossRushList); } )); tasks.Add(Task.Run(async () => { + Log.Debug($"[DataProvider] AdventureBoss{_adventureBossUnlockFloorList.Count} Unlock"); await MySqlStore.StoreAdventureBossUnlockFloorList(_adventureBossUnlockFloorList); } )); tasks.Add(Task.Run(async () => { + Log.Debug($"[DataProvider] AdventureBoss{_adventureBossClaimRewardList.Count} claim"); await MySqlStore.StoreAdventureBossClaimRewardList(_adventureBossClaimRewardList); } )); @@ -77,6 +84,7 @@ private void StoreAdventureBossList() private void ClearAdventureBossList() { + Log.Debug("[DataProvider] AdventureBossClear adventure boss action lists"); _adventureBossSeasonDict.Clear(); _adventureBossWantedList.Clear(); _adventureBossChallengeList.Clear(); @@ -87,36 +95,29 @@ private void ClearAdventureBossList() partial void SubscribeAdventureBossWanted(ActionEvaluation evt) { + Log.Debug("[DataProvider] AdventureBossSubscribe Wanted"); try { if (evt.Exception is null && evt.Action is { } wanted) { - var start = DateTimeOffset.UtcNow; var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); - var avatarAddress = wanted.AvatarAddress; - if (!_avatars.Contains(avatarAddress)) - { - _avatars.Add(avatarAddress); - _avatarList.Add(AvatarData.GetAvatarInfo(outputState, evt.Signer, avatarAddress, _blockTimeOffset, BattleType.Adventure)); - } - _adventureBossWantedList.Add(AdventureBossWantedData.GetWantedInfo( outputState, evt.BlockIndex, _blockTimeOffset, wanted )); + Log.Debug($"[Adventure Boss] Wanted added : {_adventureBossWantedList.Count}"); // Update season info _adventureBossSeasonDict[wanted.Season] = AdventureBossSeasonData.GetAdventureBossSeasonInfo( outputState, wanted.Season, _blockTimeOffset ); - var end = DateTimeOffset.UtcNow; - Log.Debug("[DataProvider] Stored AdventureBossWanted action in block #{BlockIndex}. Time taken: {Time} ms", evt.BlockIndex, end - start); + Log.Debug($"[Adventure Boss] Season added : {_adventureBossSeasonDict.Count}"); } } catch (Exception e) { Log.Error( e, - "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -125,32 +126,24 @@ partial void SubscribeAdventureBossWanted(ActionEvaluation evt) partial void SubscribeAdventureBossChallenge(ActionEvaluation evt) { + Log.Debug("[DataProvider] AdventureBossSubscribe Explore"); try { if (evt.Exception is null && evt.Action is { } challenge) { - var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); - var avatarAddress = challenge.AvatarAddress; - if (!_avatars.Contains(avatarAddress)) - { - _avatars.Add(avatarAddress); - _avatarList.Add(AvatarData.GetAvatarInfo(outputState, evt.Signer, avatarAddress, _blockTimeOffset, BattleType.Adventure)); - } - _adventureBossChallengeList.Add(AdventureBossChallengeData.GetChallengeInfo( prevState, outputState, evt.BlockIndex, _blockTimeOffset, challenge )); - var end = DateTimeOffset.UtcNow; - Log.Debug("[DataProvider] Stored AdventureBossChallenge action in block #{BlockIndex}. Time taken: {Time} ms", evt.BlockIndex, end - start); + Log.Debug($"[DataProvider] AdventureBossChallenge added : {_adventureBossChallengeList.Count}"); } } catch (Exception e) { Log.Error( e, - "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -159,32 +152,24 @@ partial void SubscribeAdventureBossChallenge(ActionEvaluation evt) { + Log.Debug("[DataProvider] AdventureBossSubscribe Rush"); try { if (evt.Exception is null && evt.Action is { } rush) { - var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); - var avatarAddress = rush.AvatarAddress; - if (!_avatars.Contains(avatarAddress)) - { - _avatars.Add(avatarAddress); - _avatarList.Add(AvatarData.GetAvatarInfo(outputState, evt.Signer, avatarAddress, _blockTimeOffset, BattleType.Adventure)); - } - _adventureBossRushList.Add(AdventureBossRushData.GetRushInfo( prevState, outputState, evt.BlockIndex, _blockTimeOffset, rush )); - var end = DateTimeOffset.UtcNow; - Log.Debug("[DataProvider] Stored AdventureBossRush action in block #{BlockIndex}. Time taken: {Time} ms", evt.BlockIndex, end - start); + Log.Debug($"[DataProvider] AdventureBossRush added : {_adventureBossRushList.Count}"); } } catch (Exception e) { Log.Error( e, - "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -193,32 +178,24 @@ partial void SubscribeAdventureBossRush(ActionEvaluation evt partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation evt) { + Log.Debug("[DataProvider] AdventureBossSubscribe UnlockFloor"); try { if (evt.Exception is null && evt.Action is { } unlock) { - var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); - var avatarAddress = unlock.AvatarAddress; - if (!_avatars.Contains(avatarAddress)) - { - _avatars.Add(avatarAddress); - _avatarList.Add(AvatarData.GetAvatarInfo(outputState, evt.Signer, avatarAddress, _blockTimeOffset, BattleType.Adventure)); - } - _adventureBossUnlockFloorList.Add(AdventureBossUnlockFloorData.GetUnlockInfo( prevState, outputState, evt.BlockIndex, _blockTimeOffset, unlock )); - var end = DateTimeOffset.UtcNow; - Log.Debug("[DataProvider] Stored AdventureBossUnlock action in block #{BlockIndex}. Time taken: {Time} ms", evt.BlockIndex, end - start); + Log.Debug($"[DataProvider] AdventureBossUnlock added : {_adventureBossUnlockFloorList.Count}"); } } catch (Exception e) { Log.Error( e, - "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -227,28 +204,19 @@ partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation evt partial void SubscribeAdventureBossClaim(ActionEvaluation evt) { + Log.Debug("[DataProvider] AdventureBossSubscribe Claim"); try { if (evt.Exception is null && evt.Action is { } claim) { - var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); - var avatarAddress = claim.AvatarAddress; - if (!_avatars.Contains(avatarAddress)) - { - _avatars.Add(avatarAddress); - _avatarList.Add(AvatarData.GetAvatarInfo(outputState, evt.Signer, avatarAddress, _blockTimeOffset, BattleType.Adventure)); - } - _adventureBossClaimRewardList.Add(AdventureBossClaimRewardData.GetClaimInfo( prevState, evt.BlockIndex, _blockTimeOffset, claim )); - var end = DateTimeOffset.UtcNow; - Log.Debug("[DataProvider] Stored AdventureBossClaim action in block #{BlockIndex}. Time taken: {Time} ms", evt.BlockIndex, end - start); + Log.Debug($"[DataProvider] AdventureBossClaim added : {_adventureBossClaimRewardList.Count}"); // Update season info - start = DateTimeOffset.UtcNow; var latestSeason = prevState.GetLatestAdventureBossSeason(); var season = latestSeason.EndBlockIndex <= evt.BlockIndex ? latestSeason.Season // New season not started @@ -256,15 +224,14 @@ partial void SubscribeAdventureBossClaim(ActionEvaluation Date: Wed, 24 Jul 2024 13:00:41 +0900 Subject: [PATCH 5/8] fix log messages --- .../AdventureBossRenderSubscriber.cs | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs b/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs index e4c1a149..cb526cf9 100644 --- a/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs +++ b/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs @@ -84,7 +84,7 @@ private void StoreAdventureBossList() private void ClearAdventureBossList() { - Log.Debug("[DataProvider] AdventureBossClear adventure boss action lists"); + Log.Debug("[DataProvider] Clear adventure boss action lists"); _adventureBossSeasonDict.Clear(); _adventureBossWantedList.Clear(); _adventureBossChallengeList.Clear(); @@ -95,22 +95,24 @@ private void ClearAdventureBossList() partial void SubscribeAdventureBossWanted(ActionEvaluation evt) { - Log.Debug("[DataProvider] AdventureBossSubscribe Wanted"); try { if (evt.Exception is null && evt.Action is { } wanted) { + var start = DateTimeOffset.UtcNow; var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); _adventureBossWantedList.Add(AdventureBossWantedData.GetWantedInfo( outputState, evt.BlockIndex, _blockTimeOffset, wanted )); - Log.Debug($"[Adventure Boss] Wanted added : {_adventureBossWantedList.Count}"); + var end = DateTimeOffset.UtcNow; + Log.Debug("[DataProvider] Stored {count} AdventureBossWanted action in block #{BlockIndex}. Time taken: {Time} ms", _adventureBossWantedList.Count, evt.BlockIndex, end - start); // Update season info _adventureBossSeasonDict[wanted.Season] = AdventureBossSeasonData.GetAdventureBossSeasonInfo( outputState, wanted.Season, _blockTimeOffset ); - Log.Debug($"[Adventure Boss] Season added : {_adventureBossSeasonDict.Count}"); + end = DateTimeOffset.UtcNow; + Log.Debug("[DataProvider] Stored {count} AdventureBossSeason action in block #{BlockIndex}. Time taken: {Time} ms", _adventureBossSeasonDict.Count, evt.BlockIndex, end - start); } } catch (Exception e) @@ -126,24 +128,25 @@ partial void SubscribeAdventureBossWanted(ActionEvaluation evt) partial void SubscribeAdventureBossChallenge(ActionEvaluation evt) { - Log.Debug("[DataProvider] AdventureBossSubscribe Explore"); try { if (evt.Exception is null && evt.Action is { } challenge) { + var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); _adventureBossChallengeList.Add(AdventureBossChallengeData.GetChallengeInfo( prevState, outputState, evt.BlockIndex, _blockTimeOffset, challenge )); - Log.Debug($"[DataProvider] AdventureBossChallenge added : {_adventureBossChallengeList.Count}"); + var end = DateTimeOffset.UtcNow; + Log.Debug("[DataProvider] Stored {count} AdventureBossChallenge action in block #{BlockIndex}. Time taken: {Time} ms", _adventureBossChallengeList.Count, evt.BlockIndex, end - start); } } catch (Exception e) { Log.Error( e, - "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -152,9 +155,9 @@ partial void SubscribeAdventureBossChallenge(ActionEvaluation evt) { - Log.Debug("[DataProvider] AdventureBossSubscribe Rush"); try { + var start = DateTimeOffset.UtcNow; if (evt.Exception is null && evt.Action is { } rush) { var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); @@ -162,14 +165,15 @@ partial void SubscribeAdventureBossRush(ActionEvaluation evt _adventureBossRushList.Add(AdventureBossRushData.GetRushInfo( prevState, outputState, evt.BlockIndex, _blockTimeOffset, rush )); - Log.Debug($"[DataProvider] AdventureBossRush added : {_adventureBossRushList.Count}"); + var end = DateTimeOffset.UtcNow; + Log.Debug("[DataProvider] Stored {count} AdventureBossRush action in block #{BlockIndex}. Time taken: {Time} ms", _adventureBossRushList.Count, evt.BlockIndex, end - start); } } catch (Exception e) { Log.Error( e, - "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -178,24 +182,25 @@ partial void SubscribeAdventureBossRush(ActionEvaluation evt partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation evt) { - Log.Debug("[DataProvider] AdventureBossSubscribe UnlockFloor"); try { if (evt.Exception is null && evt.Action is { } unlock) { + var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); _adventureBossUnlockFloorList.Add(AdventureBossUnlockFloorData.GetUnlockInfo( prevState, outputState, evt.BlockIndex, _blockTimeOffset, unlock )); - Log.Debug($"[DataProvider] AdventureBossUnlock added : {_adventureBossUnlockFloorList.Count}"); + var end = DateTimeOffset.UtcNow; + Log.Debug("[DataProvider] Stored {count} AdventureBossUnlock action in block #{BlockIndex}. Time taken: {Time} ms", _adventureBossUnlockFloorList.Count, evt.BlockIndex, end - start); } } catch (Exception e) { Log.Error( e, - "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "[DataProvider]RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -204,19 +209,21 @@ partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation evt partial void SubscribeAdventureBossClaim(ActionEvaluation evt) { - Log.Debug("[DataProvider] AdventureBossSubscribe Claim"); try { if (evt.Exception is null && evt.Action is { } claim) { + var start = DateTimeOffset.UtcNow; var prevState = new World(_blockChainStates.GetWorldState(evt.PreviousState)); var outputState = new World(_blockChainStates.GetWorldState(evt.OutputState)); _adventureBossClaimRewardList.Add(AdventureBossClaimRewardData.GetClaimInfo( prevState, evt.BlockIndex, _blockTimeOffset, claim )); - Log.Debug($"[DataProvider] AdventureBossClaim added : {_adventureBossClaimRewardList.Count}"); + var end = DateTimeOffset.UtcNow; + Log.Debug("[DataProvider] Stored {count} AdventureBossClaim action in block #{BlockIndex}. Time taken: {Time} ms", _adventureBossClaimRewardList.Count, evt.BlockIndex, end - start); // Update season info + start = DateTimeOffset.UtcNow; var latestSeason = prevState.GetLatestAdventureBossSeason(); var season = latestSeason.EndBlockIndex <= evt.BlockIndex ? latestSeason.Season // New season not started @@ -224,14 +231,15 @@ partial void SubscribeAdventureBossClaim(ActionEvaluation Date: Wed, 24 Jul 2024 13:02:39 +0900 Subject: [PATCH 6/8] fix format --- .../Subscriber/AdventureBossRenderSubscriber.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs b/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs index cb526cf9..7bdc809a 100644 --- a/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs +++ b/NineChronicles.DataProvider/Subscriber/AdventureBossRenderSubscriber.cs @@ -119,7 +119,7 @@ partial void SubscribeAdventureBossWanted(ActionEvaluation evt) { Log.Error( e, - "RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); @@ -200,7 +200,7 @@ partial void SubscribeAdventureBossUnlockFloor(ActionEvaluation evt { Log.Error( e, - "[DataProvider]RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", + "[DataProvider] RenderSubscriber Error: {ErrorMessage}, StackTrace: {StackTrace}", e.Message, e.StackTrace ); From 79f16a71c575a341a45d0be71936f98ba33e2f7b Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 26 Jul 2024 13:54:01 +0900 Subject: [PATCH 7/8] Fix missing update hammer count --- NineChronicles.DataProvider/RenderSubscriber.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NineChronicles.DataProvider/RenderSubscriber.cs b/NineChronicles.DataProvider/RenderSubscriber.cs index 3e3a8f1e..768e7a5c 100644 --- a/NineChronicles.DataProvider/RenderSubscriber.cs +++ b/NineChronicles.DataProvider/RenderSubscriber.cs @@ -661,6 +661,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) { var hammerId = kv.Key; var exp = enhancementCostSheet.GetHammerExp(hammerId); + totalHammerCount += kv.Value; totalHammerExp += exp * kv.Value; } From f752b950abad321d8c69f754e43e12190c29cf08 Mon Sep 17 00:00:00 2001 From: area363 Date: Tue, 30 Jul 2024 16:04:35 +0900 Subject: [PATCH 8/8] bump headless --- NineChronicles.Headless | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineChronicles.Headless b/NineChronicles.Headless index 68ccd1bd..22bb2979 160000 --- a/NineChronicles.Headless +++ b/NineChronicles.Headless @@ -1 +1 @@ -Subproject commit 68ccd1bd3289f708ecbac12e32aa181124a02f6c +Subproject commit 22bb2979b07181201575c8f9592d1fdfaa3e9685