Skip to content

Commit

Permalink
Merge pull request planetarium#2535 from moreal/main-to-dev-180
Browse files Browse the repository at this point in the history
Backmerge 180 release
  • Loading branch information
moreal authored Aug 9, 2024
2 parents a195b1f + 8ed5403 commit e5b784a
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 119 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 98 files
+1 −0 .Lib9c.Benchmarks/.gitignore
+88 −0 .Lib9c.Benchmarks/Actions/AutoJoinGuild.cs
+110 −0 .Lib9c.Benchmarks/Actions/MigratePledgeToGuild.cs
+42 −0 .Lib9c.Benchmarks/Actions/TransferAsset.cs
+6 −0 .Lib9c.Benchmarks/Lib9c.Benchmarks.csproj
+43 −110 .Lib9c.Benchmarks/Program.cs
+1 −0 .Lib9c.Plugin/PluginActionEvaluator.cs
+1 −1 .Lib9c.Tests/Action/ActionContext.cs
+1 −1 .Lib9c.Tests/Action/ClaimItemsTest.cs
+2 −7 .Lib9c.Tests/Action/Garages/BulkUnloadFromGaragesTest.cs
+2 −7 .Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs
+2 −7 .Lib9c.Tests/Action/Garages/UnloadFromMyGaragesTest.cs
+82 −0 .Lib9c.Tests/Action/Guild/AcceptGuildApplicationTest.cs
+56 −0 .Lib9c.Tests/Action/Guild/ApplyGuildTest.cs
+210 −0 .Lib9c.Tests/Action/Guild/BanGuildMemberTest.cs
+64 −0 .Lib9c.Tests/Action/Guild/CancelGuildApplicationTest.cs
+71 −0 .Lib9c.Tests/Action/Guild/MakeGuildTest.cs
+95 −0 .Lib9c.Tests/Action/Guild/Migration/GuildMigrationCtrlTest.cs
+172 −0 .Lib9c.Tests/Action/Guild/Migration/MigratePledgeToGuildTest.cs
+62 −0 .Lib9c.Tests/Action/Guild/QuitGuildTest.cs
+83 −0 .Lib9c.Tests/Action/Guild/RejectGuildApplicationTest.cs
+106 −0 .Lib9c.Tests/Action/Guild/RemoveGuildTest.cs
+82 −0 .Lib9c.Tests/Action/Guild/UnbanGuildMemberTest.cs
+213 −0 .Lib9c.Tests/Action/IssueTokenTest.cs
+5 −5 .Lib9c.Tests/CurrenciesTest.cs
+1 −1 .Lib9c.Tests/Lib9c.Tests.csproj
+34 −0 .Lib9c.Tests/Model/Guild/GuildApplicationTest.Snapshot.verified.txt
+38 −0 .Lib9c.Tests/Model/Guild/GuildApplicationTest.cs
+34 −0 .Lib9c.Tests/Model/Guild/GuildParticipantTest.Snapshot.verified.txt
+38 −0 .Lib9c.Tests/Model/Guild/GuildParticipantTest.cs
+34 −0 .Lib9c.Tests/Model/Guild/GuildTest.Snapshot.verified.txt
+37 −0 .Lib9c.Tests/Model/Guild/GuildTest.cs
+55 −0 .Lib9c.Tests/Model/Item/InventoryTest.cs
+106 −0 .Lib9c.Tests/PolicyAction/Tx/Begin/AutoJoinGuildTest.cs
+40 −10 .Lib9c.Tests/TableData/Garages/LoadIntoMyGaragesCostSheetTest.cs
+18 −0 .Lib9c.Tests/Util/AddressUtil.cs
+1 −1 .github/workflows/publish.yml
+23 −0 @planetarium/lib9c/src/actions/approve_pledge.ts
+10 −0 @planetarium/lib9c/src/actions/make_guild.ts
+25 −0 @planetarium/lib9c/src/actions/migrate_pledge_to_guild.ts
+9 −0 @planetarium/lib9c/src/index.ts
+21 −0 @planetarium/lib9c/tests/actions/approve_pledge.test.ts
+4 −0 @planetarium/lib9c/tests/actions/fixtures.ts
+7 −0 @planetarium/lib9c/tests/actions/make_guild.test.ts
+21 −0 @planetarium/lib9c/tests/actions/migrate_pledge_to_guild.test.ts
+1 −0 Lib9c.Abstractions/Lib9c.Abstractions.csproj
+1 −0 Lib9c.MessagePack/Lib9c.MessagePack.csproj
+1 −0 Lib9c.Policy/Policy/BlockPolicySource.cs
+1 −0 Lib9c.Renderers/Lib9c.Renderers.csproj
+1 −1 Lib9c/Action/ClaimItems.cs
+2 −4 Lib9c/Action/ClaimStakeReward.cs
+57 −0 Lib9c/Action/Guild/AcceptGuildApplication.cs
+59 −0 Lib9c/Action/Guild/ApplyGuild.cs
+63 −0 Lib9c/Action/Guild/BanGuildMember.cs
+41 −0 Lib9c/Action/Guild/CancelGuildApplication.cs
+10 −0 Lib9c/Action/Guild/GuildConfig.cs
+51 −0 Lib9c/Action/Guild/MakeGuild.cs
+62 −0 Lib9c/Action/Guild/Migration/Controls/GuildMigrationCtrl.cs
+11 −0 Lib9c/Action/Guild/Migration/GuildMigrationFailedException.cs
+61 −0 Lib9c/Action/Guild/Migration/MigratePledgeToGuild.cs
+42 −0 Lib9c/Action/Guild/QuitGuild.cs
+57 −0 Lib9c/Action/Guild/RejectGuildApplication.cs
+45 −0 Lib9c/Action/Guild/RemoveGuild.cs
+62 −0 Lib9c/Action/Guild/UnbanGuildMember.cs
+126 −0 Lib9c/Action/IssueToken.cs
+42 −0 Lib9c/Addresses.cs
+8 −1 Lib9c/Currencies.cs
+13 −0 Lib9c/Extensions/ActionContextExtensions.cs
+14 −0 Lib9c/Extensions/AgentAddressExtensions.cs
+16 −0 Lib9c/Extensions/RandomExtensions.cs
+17 −0 Lib9c/Extensions/WorldExtensions.cs
+1 −1 Lib9c/Lib9c.csproj
+62 −0 Lib9c/Model/Guild/Guild.cs
+41 −0 Lib9c/Model/Guild/GuildApplication.cs
+62 −0 Lib9c/Model/Guild/GuildParticipant.cs
+118 −1 Lib9c/Model/Item/Inventory.cs
+131 −0 Lib9c/Module/Guild/GuildApplicationModule.cs
+97 −0 Lib9c/Module/Guild/GuildBanModule.cs
+60 −0 Lib9c/Module/Guild/GuildMemberCounterModule.cs
+87 −0 Lib9c/Module/Guild/GuildModule.cs
+103 −0 Lib9c/Module/Guild/GuildParticipantModule.cs
+58 −0 Lib9c/PolicyAction/Tx/Begin/AutoJoinGuild.cs
+5 −5 Lib9c/TableCSV/Cost/EnhancementCostSheetV3.csv
+4 −1 Lib9c/TableCSV/Event/EventConsumableItemRecipeSheet.csv
+2 −1 Lib9c/TableCSV/Event/EventDungeonSheet.csv
+21 −1 Lib9c/TableCSV/Event/EventDungeonStageSheet.csv
+61 −1 Lib9c/TableCSV/Event/EventDungeonStageWaveSheet.csv
+2 −1 Lib9c/TableCSV/Event/EventScheduleSheet.csv
+11 −9 Lib9c/TableCSV/Garages/LoadIntoMyGaragesCostSheet.csv
+4 −1 Lib9c/TableCSV/Item/ConsumableItemSheet.csv
+3 −1 Lib9c/TableCSV/Item/CostumeItemSheet.csv
+7 −3 Lib9c/TableCSV/Item/CostumeStatSheet.csv
+6 −1 Lib9c/TableCSV/Item/ItemRequirementSheet.csv
+7 −1 Lib9c/TableCSV/Item/MaterialItemSheet.csv
+53 −0 Lib9c/TableData/Garages/LoadIntoMyGaragesCostSheet.cs
+59 −0 Lib9c/TypedAddress/AgentAddress.cs
+61 −0 Lib9c/TypedAddress/GuildAddress.cs
+59 −0 Lib9c/TypedAddress/PledgeAddress.cs
8 changes: 0 additions & 8 deletions NineChronicles.Headless.Executable/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ public class Configuration

public int? MaxTransactionPerBlock { get; set; }

public string SentryDsn { get; set; } = "";

public double SentryTraceSampleRate { get; set; } = 0.01;

public AccessControlServiceOptions? AccessControlService { get; set; }

public int ArenaParticipantsSyncInterval { get; set; } = 1000;
Expand Down Expand Up @@ -147,8 +143,6 @@ public void Overwrite(
double? consensusTargetBlockIntervalMilliseconds,
int? consensusProposeSecondBase,
int? maxTransactionPerBlock,
string? sentryDsn,
double? sentryTraceSampleRate,
int? arenaParticipantsSyncInterval,
bool? remoteKeyValueService
)
Expand Down Expand Up @@ -201,8 +195,6 @@ public void Overwrite(
ConsensusTargetBlockIntervalMilliseconds = consensusTargetBlockIntervalMilliseconds ?? ConsensusTargetBlockIntervalMilliseconds;
ConsensusProposeSecondBase = consensusProposeSecondBase ?? ConsensusProposeSecondBase;
MaxTransactionPerBlock = maxTransactionPerBlock ?? MaxTransactionPerBlock;
SentryDsn = sentryDsn ?? SentryDsn;
SentryTraceSampleRate = sentryTraceSampleRate ?? SentryTraceSampleRate;
ArenaParticipantsSyncInterval = arenaParticipantsSyncInterval ?? ArenaParticipantsSyncInterval;
RemoteKeyValueService = remoteKeyValueService ?? RemoteKeyValueService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<VersionPrefix>1.0.0</VersionPrefix>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>..\NineChronicles.Headless.Common.ruleset</CodeAnalysisRuleSet>
<ServerGarbageCollection>true</ServerGarbageCollection>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;DevEx</Configurations>
<Platforms>AnyCPU</Platforms>
Expand All @@ -30,10 +29,6 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="Pyroscope" Version="0.8.14" />
<PackageReference Include="Pyroscope.OpenTelemetry" Version="0.2.0" />
<PackageReference Include="Sentry.Serilog" Version="3.23.0" />
<PackageReference Include="Sentry" Version="3.23.0" />
<PackageReference Include="Sentry.AspNetCore.Grpc" Version="3.22.0" />
<PackageReference Include="Sentry.DiagnosticSource" Version="3.22.0" />
<PackageReference Include="Serilog.Expressions" Version="1.1.1" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
Expand Down
66 changes: 4 additions & 62 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using NineChronicles.Headless.Executable.IO;
using NineChronicles.Headless.Properties;
using Org.BouncyCastle.Security;
using Sentry;
using Serilog;
using Serilog.Formatting.Compact;
using System;
Expand All @@ -25,14 +24,14 @@
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Lib9c.DevExtensions.Action.Loader;
using Libplanet.Action;
using Libplanet.Action.Loader;
// import necessary for sentry exception filters
using Libplanet.Types.Blocks;
using Libplanet.Headless;
using Libplanet.Headless.Hosting;
Expand Down Expand Up @@ -216,10 +215,6 @@ public async Task Run(
[Option("config", new[] { 'C' },
Description = "Absolute path of \"appsettings.json\" file to provide headless configurations.")]
string? configPath = "appsettings.json",
[Option(Description = "Sentry DSN")]
string? sentryDsn = "",
[Option(Description = "Trace sample rate for sentry")]
double? sentryTraceSampleRate = null,
[Option(Description = "arena participants list sync interval time")]
int? arenaParticipantsSyncInterval = null,
[Option(Description = "arena participants list sync enable")]
Expand All @@ -229,10 +224,6 @@ public async Task Run(
[Ignore] CancellationToken? cancellationToken = null
)
{
#if SENTRY || ! DEBUG
try
{
#endif
var configurationBuilder = new ConfigurationBuilder();
if (Uri.IsWellFormedUriString(configPath, UriKind.Absolute))
{
Expand Down Expand Up @@ -312,40 +303,9 @@ public async Task Run(
txLifeTime, messageTimeout, tipTimeout, demandBuffer, skipPreload,
minimumBroadcastTarget, bucketSize, chainTipStaleBehaviorType, txQuotaPerSigner, maximumPollPeers,
consensusPort, consensusPrivateKeyString, consensusSeedStrings, consensusTargetBlockIntervalMilliseconds, consensusProposeSecondBase,
maxTransactionPerBlock, sentryDsn, sentryTraceSampleRate, arenaParticipantsSyncInterval, remoteKeyValueService
maxTransactionPerBlock, arenaParticipantsSyncInterval, remoteKeyValueService
);

#if SENTRY || ! DEBUG
loggerConf = loggerConf
.WriteTo.Sentry(o =>
{
o.InitializeSdk = false;
});

using var _ = SentrySdk.Init(o =>
{
o.SendDefaultPii = true;
o.Dsn = headlessConfig.SentryDsn;
// TODO: We need to specify `o.Release` after deciding the version scheme.
// https://docs.sentry.io/workflow/releases/?platform=csharp
//o.Debug = true;
o.Release = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? "Unknown";
o.SampleRate = 0.01f;
o.TracesSampleRate = headlessConfig.SentryTraceSampleRate;
o.AddExceptionFilterForType<TimeoutException>();
o.AddExceptionFilterForType<IOException>();
o.AddExceptionFilterForType<CommunicationFailException>();
o.AddExceptionFilterForType<InvalidBlockIndexException>();
});

// Set global tag
SentrySdk.ConfigureScope(scope =>
{
scope.SetTag("host", headlessConfig.Host ?? "no-host");
});
#endif

// Clean-up previous temporary log files.
if (Directory.Exists("_logs"))
{
Expand All @@ -354,6 +314,8 @@ public async Task Run(

Log.Logger = loggerConf.CreateLogger();

Log.Information("The {0} garbage collector is running.", GCSettings.IsServerGC ? "server" : "workstation");

if (!headlessConfig.NoMiner && headlessConfig.MinerPrivateKeyString is null)
{
throw new CommandExitedException(
Expand Down Expand Up @@ -480,7 +442,6 @@ IActionLoader MakeSingleActionLoader()
hostBuilder.ConfigureServices(services =>
{
services.AddSingleton(_ => standaloneContext);
services.AddSingleton<ConcurrentDictionary<string, ITransaction>>();
services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(
serviceName: Assembly.GetEntryAssembly()?.GetName().Name ?? "NineChronicles.Headless",
Expand Down Expand Up @@ -543,7 +504,6 @@ IActionLoader MakeSingleActionLoader()
IPAddress.Loopback.ToString(),
rpcProperties.RpcListenPort,
context,
new ConcurrentDictionary<string, Sentry.ITransaction>(),
arenaMemoryCache
);

Expand Down Expand Up @@ -574,7 +534,6 @@ IActionLoader MakeSingleActionLoader()
IPAddress.Loopback.ToString(),
0,
context,
new ConcurrentDictionary<string, Sentry.ITransaction>(),
arenaMemoryCache
);
hostBuilder.UseNineChroniclesNode(
Expand Down Expand Up @@ -625,23 +584,6 @@ IActionLoader MakeSingleActionLoader()
{
Log.Error(e, "Unexpected exception occurred during Run. {e}", e);
}

#if SENTRY || ! DEBUG
}
catch (CommandExitedException)
{
throw;
}
catch (Exception exceptionToCapture)
{
SentrySdk.CaptureException(exceptionToCapture);
throw;
}
#endif
}

static void ConfigureSentryOptions(SentryOptions o)
{
}
}
}
1 change: 0 additions & 1 deletion NineChronicles.Headless.Tests/GraphQLStartupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public GraphQLStartupTest()
"",
0,
new RpcContext(),
new ConcurrentDictionary<string, Sentry.ITransaction>(),
new StateMemoryCache()
);
_startup = new GraphQLService.GraphQLStartup(_configuration, standaloneContext, publisher);
Expand Down
51 changes: 51 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,5 +1539,56 @@ public async Task RetrieveAvatarAssets()

Assert.Equal(avatarAddress, action.AvatarAddress);
}

[Theory]
[InlineData(true, true)]
[InlineData(true, false)]
[InlineData(false, true)]
[InlineData(false, false)]
public async Task IssueToken(bool favExist, bool itemExist)
{
var avatarAddress = new PrivateKey().Address;
var fungibleAssetValues = favExist
? "[{ticker: \"CRYSTAL\", decimalPlaces: 18, quantity: 100}]"
: "[]";
var items = itemExist
? "[{itemId: 500000, count: 100, tradable: true}, {itemId: 500000, count: 100, tradable: false}]"
: "[]";
var query = $@"{{
issueToken(
avatarAddress: ""{avatarAddress}"",
fungibleAssetValues: {fungibleAssetValues},
items: {items}
)
}}";

var queryResult = await ExecuteQueryAsync<ActionQuery>(query, standaloneContext: _standaloneContext);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
var plainValue = _codec.Decode(ByteUtil.ParseHex((string)data["issueToken"]));
Assert.IsType<Dictionary>(plainValue);
var actionBase = DeserializeNCAction(plainValue);
var action = Assert.IsType<IssueToken>(actionBase);

Assert.Equal(avatarAddress, action.AvatarAddress);
Assert.Equal(favExist, action.FungibleAssetValues.Any());
Assert.Equal(itemExist, action.Items.Any());

if (favExist)
{
var fav = action.FungibleAssetValues.First();
Assert.Equal(Currencies.Crystal * 100, fav);
}

if (itemExist)
{
for (int i = 0; i < action.Items.Count; i++)
{
var (itemId, count, tradable) = action.Items[i];
Assert.Equal(500000, itemId);
Assert.Equal(100, count);
Assert.Equal(i == 0, tradable);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public GraphQLTestBase(ITestOutputHelper output)
"",
0,
new RpcContext(),
new ConcurrentDictionary<string, Sentry.ITransaction>(),
new StateMemoryCache()
);
services.AddSingleton(publisher);
Expand Down
23 changes: 4 additions & 19 deletions NineChronicles.Headless/ActionEvaluationPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class ActionEvaluationPublisher : BackgroundService
private MemoryCache _memoryCache;

private RpcContext _context;
private ConcurrentDictionary<string, Sentry.ITransaction> _sentryTraces;

public ActionEvaluationPublisher(
BlockRenderer blockRenderer,
Expand All @@ -67,7 +66,6 @@ public ActionEvaluationPublisher(
string host,
int port,
RpcContext context,
ConcurrentDictionary<string, Sentry.ITransaction> sentryTraces,
StateMemoryCache cache)
{
_blockRenderer = blockRenderer;
Expand All @@ -78,7 +76,6 @@ public ActionEvaluationPublisher(
_host = host;
_port = port;
_context = context;
_sentryTraces = sentryTraces;
var memoryCacheOptions = new MemoryCacheOptions();
var options = Options.Create(memoryCacheOptions);
_cache = new MemoryCache(options);
Expand Down Expand Up @@ -137,7 +134,7 @@ public async Task AddClient(Address clientAddress)
};

GrpcChannel channel = GrpcChannel.ForAddress($"http://{_host}:{_port}", options);
Client client = await Client.CreateAsync(channel, _blockChainStates, clientAddress, _context, _sentryTraces);
Client client = await Client.CreateAsync(channel, _blockChainStates, clientAddress, _context);
if (_clients.TryAdd(clientAddress, client))
{
if (clientAddress == default)
Expand Down Expand Up @@ -401,37 +398,32 @@ private sealed class Client : IAsyncDisposable

public ImmutableHashSet<Address> TargetAddresses { get; set; }

public readonly ConcurrentDictionary<string, Sentry.ITransaction> SentryTraces;

private Client(
IActionEvaluationHub hub,
IBlockChainStates blockChainStates,
Address clientAddress,
RpcContext context,
ConcurrentDictionary<string, Sentry.ITransaction> sentryTraces)
RpcContext context)
{
_hub = hub;
_blockChainStates = blockChainStates;
_clientAddress = clientAddress;
_context = context;
TargetAddresses = ImmutableHashSet<Address>.Empty;
SentryTraces = sentryTraces;
}

public static async Task<Client> CreateAsync(
GrpcChannel channel,
IBlockChainStates blockChainStates,
Address clientAddress,
RpcContext context,
ConcurrentDictionary<string, Sentry.ITransaction> sentryTraces)
RpcContext context)
{
IActionEvaluationHub hub = await StreamingHubClient.ConnectAsync<IActionEvaluationHub, IActionEvaluationHubReceiver>(
channel,
null!
);
await hub.JoinAsync(clientAddress.ToHex());

return new Client(hub, blockChainStates, clientAddress, context, sentryTraces);
return new Client(hub, blockChainStates, clientAddress, context);
}

public void Subscribe(
Expand Down Expand Up @@ -530,13 +522,6 @@ await _hub.BroadcastRenderBlockAsync(
// FIXME add logger as property
Log.Error(e, "[{ClientAddress}] Skip broadcasting render due to the unexpected exception", _clientAddress);
}

if (ev.TxId is TxId txId && SentryTraces.TryRemove(txId.ToString() ?? "", out var sentryTrace))
{
var span = sentryTrace.GetLastActiveSpan();
span?.Finish();
sentryTrace.Finish();
}
}
);

Expand Down
Loading

0 comments on commit e5b784a

Please sign in to comment.