Skip to content

Commit

Permalink
Merge pull request #2344 from greymistcube/bump/lib9c-to-c8247aaa
Browse files Browse the repository at this point in the history
  • Loading branch information
riemannulus authored Dec 5, 2023
2 parents ad2914b + eb26b33 commit db3c919
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 153 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 56 files
+0 −9 .Lib9c.StateService.Shared/Lib9c.StateService.Shared.csproj
+0 −8 .Lib9c.StateService.Shared/RemoteEvaluationRequest.cs
+0 −6 .Lib9c.StateService.Shared/RemoteEvaluationResponse.cs
+0 −62 .Lib9c.StateService/Controllers/RemoteEvaluationController.cs
+0 −21 .Lib9c.StateService/Lib9c.StateService.csproj
+0 −39 .Lib9c.StateService/Program.cs
+0 −41 .Lib9c.StateService/Properties/launchSettings.json
+0 −11 .Lib9c.StateService/appsettings-schema.json
+0 −8 .Lib9c.StateService/appsettings.Development.json
+0 −10 .Lib9c.StateService/appsettings.json
+62 −0 .Lib9c.Tests/AccountExtensions.cs
+1 −1 .Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs
+1 −1 .Lib9c.Tests/Action/BattleArena4Test.cs
+2 −2 .Lib9c.Tests/Action/Buy11Test.cs
+1 −1 .Lib9c.Tests/Action/CombinationEquipment11Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash10Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash11Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash12Test.cs
+4 −4 .Lib9c.Tests/Action/HackAndSlash13Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash15Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash16Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash17Test.cs
+4 −4 .Lib9c.Tests/Action/HackAndSlash18Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash19Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash20Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash21Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash6Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash7Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash8Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlash9Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep1Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep2Test.cs
+4 −4 .Lib9c.Tests/Action/HackAndSlashSweep3Test.cs
+4 −4 .Lib9c.Tests/Action/HackAndSlashSweep4Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep5Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep6Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep7Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep8Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashSweep9Test.cs
+3 −3 .Lib9c.Tests/Action/HackAndSlashTest14.cs
+1 −1 .Lib9c.Tests/Action/ItemEnhancement10Test.cs
+1 −1 .Lib9c.Tests/Action/ItemEnhancement11Test.cs
+1 −1 .Lib9c.Tests/Action/MimisbrunnrBattle10Test.cs
+152 −77 .Lib9c.Tests/Action/MockState.cs
+1 −1 .Lib9c.Tests/Action/RankingBattle11Test.cs
+4 −14 .Lib9c.Tests/Action/Snapshot/TransferAsset0SnapshotTest.cs
+1 −1 .Libplanet
+0 −29 .Libplanet.Extensions.RemoteActionEvaluator.Tests/Libplanet.Extensions.RemoteActionEvaluator.Tests.csproj
+0 −1 .Libplanet.Extensions.RemoteActionEvaluator.Tests/Usings.cs
+0 −3 .Libplanet.Extensions.RemoteActionEvaluator/AssemblyInfo.cs
+0 −15 .Libplanet.Extensions.RemoteActionEvaluator/Libplanet.Extensions.RemoteActionEvaluator.csproj
+0 −42 .Libplanet.Extensions.RemoteActionEvaluator/RemoteActionEvaluator.cs
+4 −0 .github/workflows/lib9c_plugin_build_and_push_s3.yaml
+0 −24 .github/workflows/publish.yml
+0 −31 Lib9c.MessagePack/AccountStateDelta.cs
+0 −24 Lib9c.sln
1 change: 0 additions & 1 deletion Libplanet.Headless/Hosting/ActionEvaluatorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ public enum ActionEvaluatorType
{
Default, // ActionEvaluator
ForkableActionEvaluator,
RemoteActionEvaluator,
PluggedActionEvaluator,
}
4 changes: 0 additions & 4 deletions Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Libplanet.Crypto;
using Libplanet.Extensions.ForkableActionEvaluator;
using Libplanet.Extensions.PluggedActionEvaluator;
using Libplanet.Extensions.RemoteActionEvaluator;
using Libplanet.Net;
using Libplanet.Net.Consensus;
using Libplanet.Net.Options;
Expand Down Expand Up @@ -128,9 +127,6 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
ResolvePluginPath(pluginActionEvaluatorConfiguration.PluginPath),
pluginActionEvaluatorConfiguration.TypeName,
keyValueStore),
RemoteActionEvaluatorConfiguration remoteActionEvaluatorConfiguration =>
new RemoteActionEvaluator(
new Uri(remoteActionEvaluatorConfiguration.StateServiceEndpoint)),
DefaultActionEvaluatorConfiguration _ =>
new ActionEvaluator(
_ => blockPolicy.BlockAction,
Expand Down

This file was deleted.

17 changes: 7 additions & 10 deletions NineChronicles.Headless.Executable.Tests/Commands/TxCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ private void Assert_Tx(long txNonce, string filePath, bool gas)
{
var timeStamp = DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.UtcNow.ToUnixTimeSeconds());
var hashHex = ByteUtil.Hex(_blockHash.ByteArray);
long? maxGasPrice = null;
if (gas)
{
maxGasPrice = 1L;
}
long? maxGasPrice = gas ? (long?)1L : null;
_command.Sign(ByteUtil.Hex(_privateKey.ByteArray), txNonce, hashHex, timeStamp.ToString(),
new[] { filePath }, maxGasPrice: maxGasPrice);
var output = _console.Out.ToString();
Expand All @@ -146,11 +142,12 @@ private void Assert_Tx(long txNonce, string filePath, bool gas)
Assert.Equal(_privateKey.Address, tx.Signer);
Assert.Equal(timeStamp, tx.Timestamp);
ActionBase action = (ActionBase)new NCActionLoader().LoadAction(1L, tx.Actions.Single());
long expectedGasLimit = 1L;
if (action is ITransferAsset || action is ITransferAssets)
{
expectedGasLimit = 4L;
}
long? expectedGasLimit = gas
? action is ITransferAsset || action is ITransferAssets
? (long?)4L
: (long?)1L
: null;

Assert.Equal(expectedGasLimit, tx.GasLimit);
if (gas)
{
Expand Down
40 changes: 0 additions & 40 deletions NineChronicles.Headless.Executable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Crypto", "Lib9c\.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents", "Lib9c\.Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj", "{A6922395-36E5-4B0A-BEBD-9BCE34D08722}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.StateService.Shared", "Lib9c\.Lib9c.StateService.Shared\Lib9c.StateService.Shared.csproj", "{6A410F06-134A-46D9-8B39-381FA2ED861F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.RemoteActionEvaluator", "Lib9c\.Libplanet.Extensions.RemoteActionEvaluator\Libplanet.Extensions.RemoteActionEvaluator.csproj", "{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.RemoteBlockChainStates", "Lib9c\.Libplanet.Extensions.RemoteBlockChainStates\Libplanet.Extensions.RemoteBlockChainStates.csproj", "{8F9E5505-C157-4DF3-A419-FF0108731397}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NineChronicles.Headless.AccessControlCenter", "NineChronicles.Headless.AccessControlCenter\NineChronicles.Headless.AccessControlCenter.csproj", "{162C0F4B-A1D9-4132-BC34-31F1247BC26B}"
Expand Down Expand Up @@ -655,42 +651,6 @@ Global
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x64.Build.0 = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x86.ActiveCfg = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x86.Build.0 = Release|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Debug|x64.ActiveCfg = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Debug|x64.Build.0 = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Debug|x86.ActiveCfg = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Debug|x86.Build.0 = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.DevEx|x64.ActiveCfg = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.DevEx|x64.Build.0 = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.DevEx|x86.ActiveCfg = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.DevEx|x86.Build.0 = Debug|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Release|Any CPU.Build.0 = Release|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Release|x64.ActiveCfg = Release|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Release|x64.Build.0 = Release|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Release|x86.ActiveCfg = Release|Any CPU
{6A410F06-134A-46D9-8B39-381FA2ED861F}.Release|x86.Build.0 = Release|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Debug|x64.ActiveCfg = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Debug|x64.Build.0 = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Debug|x86.ActiveCfg = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Debug|x86.Build.0 = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.DevEx|x64.ActiveCfg = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.DevEx|x64.Build.0 = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.DevEx|x86.ActiveCfg = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.DevEx|x86.Build.0 = Debug|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Release|Any CPU.Build.0 = Release|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Release|x64.ActiveCfg = Release|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Release|x64.Build.0 = Release|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Release|x86.ActiveCfg = Release|Any CPU
{C41BA817-5D5B-42A5-9CF8-E8F29D1B71EF}.Release|x86.Build.0 = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,8 @@ ActionContext CreateActionContext(
randomSeed: randomSeed);
}

byte[] hashedSignature;
using (var hasher = SHA1.Create())
{
hashedSignature = hasher.ComputeHash(signature);
}

byte[] preEvaluationHashBytes = preEvaluationHash.ToByteArray();
int seed = ActionEvaluator.GenerateRandomSeed(preEvaluationHashBytes, hashedSignature, signature, 0);
int seed = ActionEvaluator.GenerateRandomSeed(preEvaluationHashBytes, signature, 0);

IAccount states = previousStates;
foreach (IAction action in actions)
Expand Down
25 changes: 13 additions & 12 deletions NineChronicles.Headless.Executable/Commands/ReplayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,20 @@ public int Tx(
outputSw?.WriteLine(msg);
}

var inputState = actionEvaluation.InputContext.PreviousState;
var outputState = actionEvaluation.OutputState;
var accountDiff = AccountDiff.Create(inputState.Trie, outputState.Trie);

var states = actionEvaluation.OutputState;
var addressNum = 1;
foreach (var (updatedAddress, updatedState) in states.Delta.States)
foreach (var (updatedAddress, stateDiff) in accountDiff.StateDiffs)
{
if (verbose)
{
msg = $"- action #{actionNum} updated address #{addressNum}({updatedAddress}) beginning..";
_console.Out.WriteLine(msg);
outputSw?.WriteLine(msg);
msg = $"{updatedState}";
msg = $"- action #{actionNum} updated value at address #{addressNum} ({updatedAddress})";
_console.Out.WriteLine(msg);
outputSw?.WriteLine(msg);
msg = $"- action #{actionNum} updated address #{addressNum}({updatedAddress}) end..";
msg = $" from {stateDiff.Item1} to {stateDiff.Item2}";
_console.Out.WriteLine(msg);
outputSw?.WriteLine(msg);
}
Expand Down Expand Up @@ -643,13 +644,13 @@ private void PrintEvaluation(ActionEvaluation evaluation, int index)
_console.Out.WriteLine($"- action #{index + 1}: {type.Name}(\"{actionType}\")");
}

var states = evaluation.OutputState.Delta.States;
var indexedStates = states.Select((x, i) => (x.Key, x.Value, i: i));
foreach (var (updatedAddress, updatedState, addressIndex) in indexedStates)
var inputState = evaluation.InputContext.PreviousState;
var outputState = evaluation.OutputState;
var accountDiff = AccountDiff.Create(inputState.Trie, outputState.Trie);
foreach (var (updatedAddress, stateDiff, addressIndex) in accountDiff.StateDiffs.Select((x, i) => (x.Key, x.Value, i)))
{
_console.Out.WriteLine($"- action #{index + 1} updated address #{addressIndex + 1}({updatedAddress}) beginning...");
_console.Out.WriteLine(updatedState);
_console.Out.WriteLine($"- action #{index + 1} updated address #{addressIndex + 1}({updatedAddress}) end...");
_console.Out.WriteLine($"- action #{index + 1} updated value at address #{addressIndex + 1} ({updatedAddress})");
_console.Out.WriteLine($" from {stateDiff.Item1} to {stateDiff.Item2}");
}
}
}
Expand Down
63 changes: 0 additions & 63 deletions NineChronicles.Headless.Executable/Commands/StateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,69 +429,6 @@ IEnumerable<KeyBytes> IKeyValueStore.ListKeys() =>
_dictionary.Keys;
}

private static ImmutableDictionary<string, IValue> GetTotalDelta(
IReadOnlyList<IActionEvaluation> actionEvaluations,
Func<Address, string> toStateKey,
Func<(Address, Currency), string> toFungibleAssetKey,
Func<Currency, string> toTotalSupplyKey,
string validatorSetKey)
{
IImmutableSet<Address> stateUpdatedAddresses = actionEvaluations
.SelectMany(a => a.OutputState.Delta.StateUpdatedAddresses)
.ToImmutableHashSet();
IImmutableSet<(Address, Currency)> updatedFungibleAssets = actionEvaluations
.SelectMany(a => a.OutputState.Delta.UpdatedFungibleAssets)
.ToImmutableHashSet();
IImmutableSet<Currency> updatedTotalSupplies = actionEvaluations
.SelectMany(a => a.OutputState.Delta.UpdatedTotalSupplyCurrencies)
.ToImmutableHashSet();

if (actionEvaluations.Count == 0)
{
return ImmutableDictionary<string, IValue>.Empty;
}

IAccount lastStates = actionEvaluations[actionEvaluations.Count - 1].OutputState;

ImmutableDictionary<string, IValue> totalDelta =
stateUpdatedAddresses.ToImmutableDictionary(
toStateKey,
a => lastStates.GetState(a) ??
throw new InvalidOperationException(
"If it was updated well, the output states will include it also.")
).SetItems(
updatedFungibleAssets.Select(pair =>
new KeyValuePair<string, IValue>(
toFungibleAssetKey(pair),
new Bencodex.Types.Integer(
lastStates.GetBalance(pair.Item1, pair.Item2).RawValue
)
)
)
);

foreach (var currency in updatedTotalSupplies)
{
if (lastStates.GetTotalSupply(currency).RawValue is { } rawValue)
{
totalDelta = totalDelta.SetItem(
toTotalSupplyKey(currency),
new Bencodex.Types.Integer(rawValue)
);
}
}

if (lastStates.GetValidatorSet() is { } validatorSet && validatorSet.Validators.Any())
{
totalDelta = totalDelta.SetItem(
validatorSetKey,
validatorSet.Bencoded
);
}

return totalDelta;
}

private static string ToStateKey(Address address) => ByteUtil.Hex(address.ByteArray);

private static string ToFungibleAssetKey(Address address, Currency currency) =>
Expand Down
9 changes: 6 additions & 3 deletions NineChronicles.Headless.Executable/Commands/TxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ public void Sign(
return action;
}).ToList();

#pragma warning disable S3358 // Extract ternary condition.
Transaction tx = Transaction.Create(
nonce: nonce,
privateKey: new PrivateKey(ByteUtil.ParseHex(privateKey)),
genesisHash: BlockHash.FromString(genesisHash),
timestamp: DateTimeOffset.Parse(timestamp),
gasLimit: parsedActions.Any(a => a is ITransferAssets or ITransferAsset) ? 4 : 1,
gasLimit: maxGasPrice.HasValue
? parsedActions.Any(a => a is ITransferAssets or ITransferAsset) ? 4 : 1
: null,
maxGasPrice: maxGasPrice.HasValue ? maxGasPrice.Value * Currencies.Mead : null,
actions: parsedActions.ToPlainValues()
);
actions: parsedActions.ToPlainValues());
#pragma warning restore S3358
byte[] raw = tx.Serialize();

if (bytes)
Expand Down
4 changes: 0 additions & 4 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ public async Task Run(
return actionEvaluatorType switch
{
ActionEvaluatorType.Default => new DefaultActionEvaluatorConfiguration(),
ActionEvaluatorType.RemoteActionEvaluator => new RemoteActionEvaluatorConfiguration
{
StateServiceEndpoint = configuration.GetValue<string>("StateServiceEndpoint"),
},
ActionEvaluatorType.ForkableActionEvaluator => new ForkableActionEvaluatorConfiguration
{
Pairs = (configuration.GetSection("Pairs") ??
Expand Down

0 comments on commit db3c919

Please sign in to comment.