Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exp/arena list #2296

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- release/*
# This branch is for testing only. Use until the next(v200080) release.
- test/action-evaluation-publisher-elapse-metric
- exp/arena-list
tags:
- "*"
workflow_dispatch:
Expand Down
4 changes: 4 additions & 0 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ IActionLoader MakeSingleActionLoader()
.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation()
.AddPrometheusExporter());

// worker
services.AddHostedService<ArenaParticipantsWorker>();
services.AddSingleton<ArenaMemoryCache>();
});

NineChroniclesNodeService service =
Expand Down
1 change: 1 addition & 0 deletions NineChronicles.Headless.Tests/GraphQLTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static Task<ExecutionResult> ExecuteQueryAsync<TObjectGraphType>(
}

services.AddLibplanetExplorer();
services.AddSingleton<ArenaMemoryCache>();

var serviceProvider = services.BuildServiceProvider();
return ExecuteQueryAsync<TObjectGraphType>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public GraphQLTestBase(ITestOutputHelper output)
services.AddLibplanetExplorer();
services.AddSingleton(ncService);
services.AddSingleton(ncService.Store);
services.AddSingleton<ArenaMemoryCache>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
Schema = new StandaloneSchema(serviceProvider);

Expand Down
2 changes: 1 addition & 1 deletion NineChronicles.Headless.Tests/GraphTypes/StateQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public async Task Garage(
sb.ToString(),
source: new StateContext(
mockState,
0L));
0L, new ArenaMemoryCache()));
Assert.Null(queryResult.Errors);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
var garages = (Dictionary<string, object>)data["garages"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task Query(int goldBalance, string goldDecimalString, int crystalBa

var queryResult = await ExecuteQueryAsync<AgentStateType>(
query,
source: new AgentStateType.AgentStateContext(agentState, mockState, 0)
source: new AgentStateType.AgentStateContext(agentState, mockState, 0, new ArenaMemoryCache())
);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
var expected = new Dictionary<string, object>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task Query(AvatarState avatarState, Dictionary<string, object> expe
source: new AvatarStateType.AvatarStateContext(
avatarState,
mockState,
0));
0, new ArenaMemoryCache()));
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
Assert.Equal(expected, data);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public async Task QueryWithCombinationSlotState(AvatarState avatarState, Diction
source: new AvatarStateType.AvatarStateContext(
avatarState,
mockState,
0));
0, new ArenaMemoryCache()));
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
Assert.Equal(expected, data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task Query(StakeStateV2 stakeState, Address stakeStateAddress, long
stakeState,
stakeStateAddress,
mockState,
blockIndex));
blockIndex, new ArenaMemoryCache()));
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
Assert.Equal(expected, data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public WorldBossScenarioTest()
[1] = true,
[2] = false,
};
_stateContext = new StateContext(GetMockState(), 1L);
_stateContext = new StateContext(GetMockState(), 1L, new ArenaMemoryCache());
var minerPrivateKey = new PrivateKey();
var initializeStates = new InitializeStates(
rankingState: new RankingState0(),
Expand Down
12 changes: 12 additions & 0 deletions NineChronicles.Headless/ArenaMemoryCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;

namespace NineChronicles.Headless;

public class ArenaMemoryCache
{
public MemoryCache Cache { get; } = new(new OptionsWrapper<MemoryCacheOptions>(new MemoryCacheOptions
{
SizeLimit = null
}));
}
38 changes: 38 additions & 0 deletions NineChronicles.Headless/ArenaParticipant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Libplanet.Crypto;
using Nekoyume.Model.State;

namespace NineChronicles.Headless;

public class ArenaParticipant
{
public readonly Address AvatarAddr;
public readonly int Score;
public readonly int Rank;
public int WinScore;
public int LoseScore;
public readonly int Cp;
public readonly int PortraitId;
public readonly string NameWithHash;
public readonly int Level;

public ArenaParticipant(
Address avatarAddr,
int score,
int rank,
AvatarState avatarState,
int portraitId,
int winScore,
int loseScore,
int cp)
{
AvatarAddr = avatarAddr;
Score = score;
Rank = rank;
WinScore = winScore;
LoseScore = loseScore;
Cp = cp;
PortraitId = portraitId;
NameWithHash = avatarState.NameWithHash;
Level = avatarState.level;
}
}
Loading
Loading