Skip to content

Commit

Permalink
Merge pull request #2050 from planetarium/release/0.4.0
Browse files Browse the repository at this point in the history
Release/0.4.0
  • Loading branch information
sonohoshi authored Aug 3, 2023
2 parents 7f72ea1 + 63ca3c9 commit 700c770
Show file tree
Hide file tree
Showing 937 changed files with 4,356 additions and 2,581 deletions.
24 changes: 9 additions & 15 deletions .Lib9c.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
using System.Linq;
using System.Security.Cryptography;
using Bencodex.Types;
using Libplanet;
using Libplanet.Action;
using Libplanet.Assets;
using Libplanet.Action.State;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
using Libplanet.Blocks;
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.RocksDBStore;
using Libplanet.State;
using Libplanet.Store;
using Libplanet.Store.Trie;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Nekoyume.Action.Loader;
using Nekoyume.Blockchain;
using Nekoyume.Blockchain.Policy;
Expand Down Expand Up @@ -89,8 +90,7 @@ static void Main(string[] args)
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new BlockChainStates(store, stateStore),
new NCActionLoader(),
null);
new NCActionLoader());
var chain = new BlockChain(
policy,
stagePolicy,
Expand Down Expand Up @@ -152,7 +152,7 @@ static void Main(string[] args)
Console.WriteLine("Total elapsed\t{0}", ended - started);
}

// Copied from BlockChain<T>.SetStates().
// Copied from BlockChain.DetermineBlockStateRootHash().
private static void SetStates(
Guid chainId,
IStore store,
Expand All @@ -162,18 +162,12 @@ private static void SetStates(
bool buildStateReferences
)
{
IImmutableSet<Address> stateUpdatedAddresses = actionEvaluations
.SelectMany(a => a.OutputState.Delta.StateUpdatedAddresses)
.ToImmutableHashSet();
IImmutableSet<(Address, Currency)> updatedFungibleAssets = actionEvaluations
.SelectMany(a => a.OutputState.Delta.UpdatedFungibleAssets)
.ToImmutableHashSet();
IImmutableDictionary<KeyBytes, IValue> totalDelta = actionEvaluations.GetRawTotalDelta();

if (!stateStore.ContainsStateRoot(block.StateRootHash))
{
HashDigest<SHA256>? prevStateRootHash = store.GetStateRootHash(block.PreviousHash);
var totalDelta = GetTotalDelta(actionEvaluations, ToStateKey, ToFungibleAssetKey);
stateStore.Commit(prevStateRootHash, totalDelta);
ITrie stateRoot = stateStore.Commit(prevStateRootHash, totalDelta);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using Lib9c.Tests;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet;
using Libplanet.Action;
using Libplanet.State;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model;
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.DevExtensions.Tests/Action/Craft/UnlockRecipeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Lib9c.Tests;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet;
using Libplanet.State;
using Libplanet.Crypto;
using Libplanet.Action.State;
using Nekoyume.Action;
using Nekoyume.Model.Item;
using Nekoyume.Model.State;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
using Bencodex.Types;
using Lib9c.DevExtensions.Action;
using Lib9c.Tests.Action;
using Libplanet;
using Libplanet.Assets;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.State;
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model.Item;
Expand Down
5 changes: 2 additions & 3 deletions .Lib9c.DevExtensions.Tests/Action/FaucetCurrencyTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Immutable;
using Lib9c.DevExtensions.Action;
using Lib9c.Tests.Action;
using Libplanet;
using Libplanet.Assets;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.State;
using Libplanet.Types.Assets;
using Nekoyume.Action;
using Nekoyume.Model.State;
using Serilog;
Expand Down
3 changes: 1 addition & 2 deletions .Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Linq;
using Lib9c.DevExtensions.Action;
using Lib9c.Tests.Action;
using Libplanet;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.State;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Helper;
Expand Down
9 changes: 5 additions & 4 deletions .Lib9c.DevExtensions.Tests/Action/ManipulateStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
using Lib9c.Tests;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet;
using Libplanet.Assets;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.State;
using Libplanet.Types.Assets;
using Nekoyume.Action;
using Nekoyume.Helper;
using Nekoyume.Model;
Expand All @@ -28,10 +27,12 @@ public class ManipulateStateTest
{
private static readonly Address AdminAddr = new PrivateKey().ToAddress();

// See also InitializeUtil.cs
private static readonly Currency Ncg = Currency.Legacy(
"NCG",
2,
new[] { AdminAddr }.ToImmutableHashSet());
null
);

private static readonly Currency Crystal = CrystalCalculator.CRYSTAL;

Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.DevExtensions.Tests/Action/Stage/ClearStageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Lib9c.Tests;
using Lib9c.Tests.Action;
using Lib9c.Tests.Util;
using Libplanet;
using Libplanet.State;
using Libplanet.Crypto;
using Libplanet.Action.State;
using Nekoyume.Action;
using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.DevExtensions.Tests/UtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using Libplanet;
using Libplanet.Crypto;
using Xunit;

namespace Lib9c.DevExtensions.Tests
Expand Down
11 changes: 5 additions & 6 deletions .Lib9c.Miner.Tests/CustomActionsDeserializableValidatorTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Collections.Immutable;
using Bencodex.Types;
using Libplanet;
using Libplanet.Action;
using Libplanet.Action.Loader;
using Libplanet.Assets;
using Libplanet.Blocks;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.State;
using Libplanet.Tx;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Tx;
using Nekoyume.Blockchain;

namespace Lib9c.Proposer.Tests;
Expand Down Expand Up @@ -64,7 +63,7 @@ private class MockTransaction : ITransaction
public PublicKey PublicKey { get; init; }
public BlockHash? GenesisHash { get; init; }
public TxActionList Actions =>
new(SystemAction is { } sa ? new List(sa) : new List(CustomActions!));
new(SystemAction is { } sa ? new IValue[]{ sa } : CustomActions!);

public FungibleAssetValue? MaxGasPrice => null;

Expand Down
9 changes: 9 additions & 0 deletions .Lib9c.StateService.Shared/Lib9c.StateService.Shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Lib9c.StateService.Shared;

public class RemoteEvaluationRequest
{
public byte[] PreEvaluationBlock { get; set; }

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / nuget

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / release

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / release

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'PreEvaluationBlock' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
6 changes: 6 additions & 0 deletions .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Lib9c.StateService.Shared;

public class RemoteEvaluationResponse
{
public byte[][] Evaluations { get; set; }

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / nuget

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / release

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / release

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 5 in .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'Evaluations' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
52 changes: 52 additions & 0 deletions .Lib9c.StateService/Controllers/RemoteEvaluationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Bencodex;
using Bencodex.Types;
using Lib9c.StateService.Shared;
using Libplanet.Action;
using Libplanet.Action.State;
using Libplanet.Extensions.ActionEvaluatorCommonComponents;
using Microsoft.AspNetCore.Mvc;
using Nekoyume.Action;
using Nekoyume.Action.Loader;

namespace Lib9c.StateService.Controllers;

[ApiController]
[Route("/evaluation")]
public class RemoteEvaluationController : ControllerBase
{
private readonly IBlockChainStates _blockChainStates;
private readonly ILogger<RemoteEvaluationController> _logger;
private readonly Codec _codec;

public RemoteEvaluationController(
IBlockChainStates blockChainStates,
ILogger<RemoteEvaluationController> logger,
Codec codec)
{
_blockChainStates = blockChainStates;
_logger = logger;
_codec = codec;
}

[HttpPost]
public ActionResult<RemoteEvaluationResponse> GetEvaluation([FromBody] RemoteEvaluationRequest request)
{
var decoded = _codec.Decode(request.PreEvaluationBlock);
if (decoded is not Dictionary dictionary)
{
return StatusCode(StatusCodes.Status400BadRequest);
}

var preEvaluationBlock = PreEvaluationBlockMarshaller.Unmarshal(dictionary);
var actionEvaluator =
new ActionEvaluator(
context => new RewardGold(),
_blockChainStates,
new NCActionLoader());
return Ok(new RemoteEvaluationResponse
{
Evaluations = actionEvaluator.Evaluate(preEvaluationBlock).Select(ActionEvaluationMarshaller.Serialize)
.ToArray(),
});
}
}
20 changes: 20 additions & 0 deletions .Lib9c.StateService/Lib9c.StateService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\.Libplanet.Extensions.RemoteBlockChainStates\Libplanet.Extensions.RemoteBlockChainStates.csproj" />
<ProjectReference Include="..\.Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj" />
<ProjectReference Include="..\.Lib9c.StateService.Shared\Lib9c.StateService.Shared.csproj" />
<ProjectReference Include="..\Lib9c\Lib9c.csproj" />
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions .Lib9c.StateService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Bencodex;
using Libplanet.Action.State;
using Libplanet.Extensions.RemoteBlockChainStates;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddEnvironmentVariables();

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton<Codec>();

builder.Services.AddSingleton<IBlockChainStates, RemoteBlockChainStates>(_ =>
{
const string DefaultEndpoint = "http://localhost:31280/graphql/explorer";
var endpoint = builder.Configuration.GetValue<string>("RemoteBlockChainStatesEndpoint") ?? DefaultEndpoint;
return new RemoteBlockChainStates(new Uri(endpoint));
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
41 changes: 41 additions & 0 deletions .Lib9c.StateService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:25712",
"sslPort": 44330
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5157",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7140;http://localhost:5157",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
11 changes: 11 additions & 0 deletions .Lib9c.StateService/appsettings-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "object",
"description": "appsettings.json to configure application.",
"properties": {
"RemoteBlockChainStatesEndpoint": {
"type": "string",
"description": "The headless' Libplanet.Explorer GraphQL endpoint. (e.g., http://localhost/graphql/explorer)"
}
},
"required": ["RemoteBlockChainStatesEndpoint"]
}
8 changes: 8 additions & 0 deletions .Lib9c.StateService/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Loading

0 comments on commit 700c770

Please sign in to comment.