diff --git a/.Lib9c.Plugin.Shared/IPluginActionEvaluator.cs b/.Lib9c.Plugin.Shared/IPluginActionEvaluator.cs new file mode 100644 index 0000000000..7f2d17b3ef --- /dev/null +++ b/.Lib9c.Plugin.Shared/IPluginActionEvaluator.cs @@ -0,0 +1,7 @@ +namespace Lib9c.Plugin.Shared +{ + public interface IPluginActionEvaluator + { + byte[][] Evaluate(byte[] blockBytes, byte[]? baseStateRootHashBytes); + } +} diff --git a/.Lib9c.Plugin.Shared/IPluginKeyValueStore.cs b/.Lib9c.Plugin.Shared/IPluginKeyValueStore.cs new file mode 100644 index 0000000000..55004c42dc --- /dev/null +++ b/.Lib9c.Plugin.Shared/IPluginKeyValueStore.cs @@ -0,0 +1,23 @@ +using System.Collections.Immutable; + +namespace Lib9c.Plugin.Shared +{ + public interface IPluginKeyValueStore + { + public byte[] Get(in ImmutableArray key); + + public void Set(in ImmutableArray key, byte[] value); + + public void Set(IDictionary, byte[]> values); + + public void Delete(in ImmutableArray key); + + public void Delete(IEnumerable> keys); + + public bool Exists(in ImmutableArray key); + + public IEnumerable> ListKeys(); + + public void Dispose(); + } +} diff --git a/.Lib9c.Plugin.Shared/Lib9c.Plugin.Shared.csproj b/.Lib9c.Plugin.Shared/Lib9c.Plugin.Shared.csproj new file mode 100644 index 0000000000..132c02c59c --- /dev/null +++ b/.Lib9c.Plugin.Shared/Lib9c.Plugin.Shared.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/.Lib9c.Plugin/Lib9c.Plugin.csproj b/.Lib9c.Plugin/Lib9c.Plugin.csproj new file mode 100644 index 0000000000..13a041c34a --- /dev/null +++ b/.Lib9c.Plugin/Lib9c.Plugin.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + true + + + + + + + false + runtime + + + + diff --git a/.Lib9c.Plugin/PluginActionEvaluator.cs b/.Lib9c.Plugin/PluginActionEvaluator.cs new file mode 100644 index 0000000000..55bd9ea460 --- /dev/null +++ b/.Lib9c.Plugin/PluginActionEvaluator.cs @@ -0,0 +1,34 @@ +using System.Security.Cryptography; +using Lib9c.Plugin.Shared; +using Libplanet.Action; +using Libplanet.Common; +using Libplanet.Extensions.ActionEvaluatorCommonComponents; +using Libplanet.Store; +using Nekoyume.Action; +using Nekoyume.Action.Loader; + + +namespace Lib9c.Plugin +{ + public class PluginActionEvaluator : IPluginActionEvaluator + { + private readonly IActionEvaluator _actionEvaluator; + + public PluginActionEvaluator(IPluginKeyValueStore keyValueStore) + { + var stateStore = new TrieStateStore(new WrappedKeyValueStore(keyValueStore)); + _actionEvaluator = new ActionEvaluator( + _ => new RewardGold(), + stateStore, + new NCActionLoader()); + } + + public byte[][] Evaluate(byte[] blockBytes, byte[]? baseStateRootHashBytes) + { + return _actionEvaluator.Evaluate( + PreEvaluationBlockMarshaller.Deserialize(blockBytes), + baseStateRootHashBytes is { } bytes ? new HashDigest(bytes) : null) + .Select(eval => ActionEvaluationMarshaller.Serialize(eval)).ToArray(); + } + } +} diff --git a/.Lib9c.Plugin/WrappedKeyValueStore.cs b/.Lib9c.Plugin/WrappedKeyValueStore.cs new file mode 100644 index 0000000000..dde51d60dc --- /dev/null +++ b/.Lib9c.Plugin/WrappedKeyValueStore.cs @@ -0,0 +1,44 @@ +using Lib9c.Plugin.Shared; +using Libplanet.Store.Trie; + +namespace Lib9c.Plugin +{ + public class WrappedKeyValueStore : IKeyValueStore + { + private readonly IPluginKeyValueStore _pluginKeyValueStore; + + public WrappedKeyValueStore(IPluginKeyValueStore pluginKeyValueStore) + { + _pluginKeyValueStore = pluginKeyValueStore; + } + + public void Dispose() + { + _pluginKeyValueStore.Dispose(); + } + + public byte[] Get(in KeyBytes key) => + _pluginKeyValueStore.Get(key.ByteArray); + + public void Set(in KeyBytes key, byte[] value) => + _pluginKeyValueStore.Set(key.ByteArray, value); + + public void Set(IDictionary values) => + _pluginKeyValueStore.Set( + values.ToDictionary(kv => + kv.Key.ByteArray, kv => kv.Value)); + + public void Delete(in KeyBytes key) => + _pluginKeyValueStore.Delete(key.ByteArray); + + public void Delete(IEnumerable keys) => + _pluginKeyValueStore.Delete( + keys.Select(key => key.ByteArray)); + + public bool Exists(in KeyBytes key) => + _pluginKeyValueStore.Exists(key.ByteArray); + + public IEnumerable ListKeys() => + _pluginKeyValueStore.ListKeys().Select(key => new KeyBytes(key)); + } +} diff --git a/.github/workflows/lib9c_plugin_build_and_push_s3.yaml b/.github/workflows/lib9c_plugin_build_and_push_s3.yaml new file mode 100644 index 0000000000..4634826a63 --- /dev/null +++ b/.github/workflows/lib9c_plugin_build_and_push_s3.yaml @@ -0,0 +1,30 @@ +name: lib9c plugin build and push s3 + +on: + workflow_dispatch: + +jobs: + s3-lib9c-plugin: + strategy: + matrix: + runtime: [ "osx-arm64", "linux-arm64", "linux-x64", "win-x64" ] + name: Publish Lib9c.Plugin (${{ matrix.runtime }}) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.400 + - name: Publish Lib9c.Plugin + run: dotnet publish ./.Lib9c.Plugin/Lib9c.Plugin.csproj -o out -r ${{ matrix.runtime }} + - name: Compress the build result + run: zip -r ../${{ matrix.runtime }}.zip . + working-directory: ./out + - name: Upload S3 + run: aws s3 cp ${{ matrix.runtime }}.zip s3://9c-dx/Lib9c.Plugin/${{ github.sha }}/ + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: "us-east-2" diff --git a/Lib9c.sln b/Lib9c.sln index 37a3e8594e..b2c1c6bf76 100644 --- a/Lib9c.sln +++ b/Lib9c.sln @@ -60,19 +60,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Types", ".Libplan EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Store", ".Libplanet\Libplanet.Store\Libplanet.Store.csproj", "{82BCD815-0AB6-4EEF-A12B-CDB9CD98EEA1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents", ".Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj", "{64C44AFB-1E14-44D3-B236-A4A37DF2C27A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents", ".Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj", "{64C44AFB-1E14-44D3-B236-A4A37DF2C27A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents.Tests", ".Libplanet.Extensions.ActionEvaluatorCommonComponents.Tests\Libplanet.Extensions.ActionEvaluatorCommonComponents.Tests.csproj", "{EACB2E8D-9A13-491C-BACD-5D79C6C13783}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents.Tests", ".Libplanet.Extensions.ActionEvaluatorCommonComponents.Tests\Libplanet.Extensions.ActionEvaluatorCommonComponents.Tests.csproj", "{EACB2E8D-9A13-491C-BACD-5D79C6C13783}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Extensions.RemoteActionEvaluator", ".Libplanet.Extensions.RemoteActionEvaluator\Libplanet.Extensions.RemoteActionEvaluator.csproj", "{0ED5DBA2-C334-40F2-8EB6-2B4D15C1AB4B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.RemoteActionEvaluator", ".Libplanet.Extensions.RemoteActionEvaluator\Libplanet.Extensions.RemoteActionEvaluator.csproj", "{0ED5DBA2-C334-40F2-8EB6-2B4D15C1AB4B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Extensions.RemoteActionEvaluator.Tests", ".Libplanet.Extensions.RemoteActionEvaluator.Tests\Libplanet.Extensions.RemoteActionEvaluator.Tests.csproj", "{3608A63A-A52D-4EB5-A96D-36C8F11CE603}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.RemoteActionEvaluator.Tests", ".Libplanet.Extensions.RemoteActionEvaluator.Tests\Libplanet.Extensions.RemoteActionEvaluator.Tests.csproj", "{3608A63A-A52D-4EB5-A96D-36C8F11CE603}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Extensions.RemoteBlockChainStates", ".Libplanet.Extensions.RemoteBlockChainStates\Libplanet.Extensions.RemoteBlockChainStates.csproj", "{63544447-4FCD-48D1-898C-974FBA6834AD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.RemoteBlockChainStates", ".Libplanet.Extensions.RemoteBlockChainStates\Libplanet.Extensions.RemoteBlockChainStates.csproj", "{63544447-4FCD-48D1-898C-974FBA6834AD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c.StateService", ".Lib9c.StateService\Lib9c.StateService.csproj", "{EB97AB26-1C8F-48F5-97FF-8A6DF8FAB879}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.StateService", ".Lib9c.StateService\Lib9c.StateService.csproj", "{EB97AB26-1C8F-48F5-97FF-8A6DF8FAB879}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib9c.StateService.Shared", ".Lib9c.StateService.Shared\Lib9c.StateService.Shared.csproj", "{5D3489AE-A403-4ADD-94E9-48463A42643E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.StateService.Shared", ".Lib9c.StateService.Shared\Lib9c.StateService.Shared.csproj", "{5D3489AE-A403-4ADD-94E9-48463A42643E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.Plugin", ".Lib9c.Plugin\Lib9c.Plugin.csproj", "{484A5A5B-D610-42D4-9CAC-B19EA1A71281}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.Plugin.Shared", ".Lib9c.Plugin.Shared\Lib9c.Plugin.Shared.csproj", "{76F6C25E-94D2-4EA9-B88D-0249F44D1D16}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -208,6 +212,14 @@ Global {5D3489AE-A403-4ADD-94E9-48463A42643E}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D3489AE-A403-4ADD-94E9-48463A42643E}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D3489AE-A403-4ADD-94E9-48463A42643E}.Release|Any CPU.Build.0 = Release|Any CPU + {484A5A5B-D610-42D4-9CAC-B19EA1A71281}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {484A5A5B-D610-42D4-9CAC-B19EA1A71281}.Debug|Any CPU.Build.0 = Debug|Any CPU + {484A5A5B-D610-42D4-9CAC-B19EA1A71281}.Release|Any CPU.ActiveCfg = Release|Any CPU + {484A5A5B-D610-42D4-9CAC-B19EA1A71281}.Release|Any CPU.Build.0 = Release|Any CPU + {76F6C25E-94D2-4EA9-B88D-0249F44D1D16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76F6C25E-94D2-4EA9-B88D-0249F44D1D16}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76F6C25E-94D2-4EA9-B88D-0249F44D1D16}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76F6C25E-94D2-4EA9-B88D-0249F44D1D16}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE