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

🔀 Merge libplanet-4.0 into development #2398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5ae6c55
bump: lib9c
limebell Dec 18, 2023
e30aa44
feat: apply API changes from lib9c
limebell Dec 28, 2023
1abe2fd
feat: add newly added graph types
limebell Dec 28, 2023
5d6fcbe
bump: lib9c
limebell Jan 5, 2024
9b751e5
bump: NineChronicles.RPC.Shared
limebell Jan 5, 2024
3dd4201
feat: adjust libplanet API changes
limebell Jan 5, 2024
7335644
Bump lib9c to a56d8ea52
greymistcube Jan 8, 2024
a41a8fd
Bump fix
greymistcube Jan 3, 2024
849e794
Linting
greymistcube Jan 8, 2024
b058fa0
Merge pull request #2374 from greymistcube/bump/lib9c-to-a56d8ea52
greymistcube Jan 8, 2024
874a52a
Fix MockTrie
greymistcube Jan 8, 2024
10edc32
Fix tests
greymistcube Jan 8, 2024
fa118c0
Merge pull request #2375 from greymistcube/chore/fix-tests
greymistcube Jan 8, 2024
61a2d46
Bump lib9c to 675aea0a
greymistcube Jan 9, 2024
31a8684
Bump rpc shared
greymistcube Jan 9, 2024
c809956
Refactor BlockChainService
greymistcube Jan 9, 2024
9f2d351
Additional API fixes
greymistcube Jan 9, 2024
0cabfa8
Removed local cache for replays
greymistcube Jan 9, 2024
12d1c44
Merge pull request #2376 from greymistcube/upgrade/bump-lib9c-to-675a…
greymistcube Jan 9, 2024
59092d0
Bump lib9c to b4c1fda61
greymistcube Jan 10, 2024
ebedb0c
Bump fix
greymistcube Jan 10, 2024
7f080c3
Fix mocks
greymistcube Jan 10, 2024
721217d
Merge pull request #2381 from greymistcube/upgrade/bump-lib9c-to-b4c1…
greymistcube Jan 10, 2024
c5f305a
bump: RPC.Shared
limebell Jan 11, 2024
bda532a
bump: lib9c
limebell Jan 11, 2024
d0b4d61
feat: fix BlockChainService
limebell Jan 11, 2024
9196135
Bump lib9c to 66ea3fdd9
greymistcube Jan 15, 2024
21ef500
Updated GraphQL API
greymistcube Jan 15, 2024
5b7d5d3
Merge pull request #2383 from greymistcube/upgrade/bump-lib9c-to-66ea…
greymistcube Jan 15, 2024
47a4fb2
bump: Lib9c
OnedgeLee Jan 17, 2024
5cdb26d
Match API of AEVs not to reveal stateRootHashBytes
OnedgeLee Jan 17, 2024
0928d3b
Merge pull request #2385 from OnedgeLee/revert/iactionevaluator-api
OnedgeLee Jan 17, 2024
6ea12ca
ci: Add upgrade/libplanet-4.0 branch on workflow to push docker image
OnedgeLee Jan 19, 2024
99281f6
Merge pull request #2387 from OnedgeLee/upgrade/libplanet-4.0
OnedgeLee Jan 19, 2024
535fe87
Bump lib9c to fb07bd824
greymistcube Jan 23, 2024
4b50746
Merge pull request #2388 from greymistcube/upgrade/bump-lib9c-to-fb07…
greymistcube Jan 23, 2024
eddeb74
bump: Bump Lib9c
OnedgeLee Jan 25, 2024
e0ffd6b
bump: Bump NineChronicles.RPC.Shared
OnedgeLee Jan 25, 2024
a44bb06
fix: Build fix from NineChronicles.RPC.Shared bump
OnedgeLee Jan 25, 2024
2b337bd
Merge pull request #2390 from OnedgeLee/upgrade/libplanet-4.0
OnedgeLee Jan 25, 2024
1c3aec2
fix: Fix NRE on byte encodings on BlockChainService
OnedgeLee Jan 26, 2024
1ac0ced
Merge pull request #2393 from OnedgeLee/upgrade/libplanet-4.0
OnedgeLee Jan 26, 2024
8552cee
chore: use given address byte as key in GetAgentState
limebell Jan 26, 2024
dfa50a3
Bump lib9c to 717f2cc8
greymistcube Jan 31, 2024
a129cc5
Merge pull request #2396 from greymistcube/upgrade/bump-lib9c-to-717f…
greymistcube Jan 31, 2024
af4a89f
Bump lib9c to 21a5f55b3
greymistcube Jan 31, 2024
e161fbb
Merge branch 'development' into upgrade/merge-285d5e95-into-libplanet…
greymistcube Jan 31, 2024
4c3c748
Merge pull request #2397 from greymistcube/upgrade/merge-285d5e95-int…
greymistcube Jan 31, 2024
d056cf4
Merge branch 'upgrade/libplanet-4.0' into merge/libplanet-4.0-into-de…
greymistcube Feb 1, 2024
953af4d
Bump lib9c to development (instead of upgrade/libplanet-4.0)
greymistcube Feb 1, 2024
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
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 330 files
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void CheckPairs()
class PostActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateroothash)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
return new ICommittedActionEvaluation[]
{
Expand All @@ -85,7 +86,8 @@ public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock bl
class PreActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
return new ICommittedActionEvaluation[]
{
Expand Down Expand Up @@ -113,7 +115,7 @@ public void LoadPlainValue(IValue plainValue)
{
}

public IAccount Execute(IActionContext context) => context.PreviousState;
public IWorld Execute(IActionContext context) => context.PreviousState;
}

class MockBlock : IPreEvaluationBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ public static IPluginActionEvaluator CreateActionEvaluator(Assembly assembly, st
public static IPluginActionEvaluator CreateActionEvaluator(string pluginPath, string typeName, IKeyValueStore keyValueStore)
=> CreateActionEvaluator(LoadPlugin(pluginPath), typeName, new PluginKeyValueStore(keyValueStore));

public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
=> _pluginActionEvaluator.Evaluate(
PreEvaluationBlockMarshaller.Serialize(block),
baseStateRootHash is { } srh ? srh.ToByteArray() : null)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block,
HashDigest<SHA256>? baseStateRootHash)
{
var evaluations = _pluginActionEvaluator.Evaluate(
PreEvaluationBlockMarshaller.Serialize(block),
baseStateRootHash is { } srh ? srh.ToByteArray() : null)
.Select(eval => ActionEvaluationMarshaller.Deserialize(eval)).ToList().AsReadOnly();
return evaluations;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private class DummyAction : IAction
{
IValue IAction.PlainValue => Dictionary.Empty;

IAccount IAction.Execute(IActionContext context)
IWorld IAction.Execute(IActionContext context)
{
return context.PreviousState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Libplanet.Common;
using Libplanet.Crypto;
using Nekoyume.Action;
using Nekoyume.Action.Factory;
using Nekoyume.Model;
using Nekoyume.Model.State;
using NineChronicles.Headless.Executable.Commands;
Expand Down Expand Up @@ -59,7 +58,6 @@ public void ActivateAccount(bool invalid, int expectedCode)
}
}


[Theory]
[InlineData(10, 0, "transfer asset test1.")]
[InlineData(100, 0, "transfer asset test2.")]
Expand Down Expand Up @@ -142,79 +140,6 @@ public void ClaimStakeReward(string addressString, int expectedCode)
}
}

[Theory]
[InlineData(0L, typeof(ClaimStakeReward2))]
[InlineData(ClaimStakeReward2.ObsoletedIndex, typeof(ClaimStakeReward2))]
[InlineData(ClaimStakeReward2.ObsoletedIndex + 1, typeof(ClaimStakeReward3))]
[InlineData(ClaimStakeReward3.ObsoleteBlockIndex, typeof(ClaimStakeReward3))]
[InlineData(ClaimStakeReward3.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward4))]
[InlineData(ClaimStakeReward4.ObsoleteBlockIndex, typeof(ClaimStakeReward4))]
[InlineData(ClaimStakeReward4.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward5))]
[InlineData(ClaimStakeReward5.ObsoleteBlockIndex, typeof(ClaimStakeReward5))]
[InlineData(ClaimStakeReward5.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward6))]
[InlineData(ClaimStakeReward6.ObsoleteBlockIndex, typeof(ClaimStakeReward6))]
[InlineData(ClaimStakeReward6.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward7))]
[InlineData(ClaimStakeReward7.ObsoleteBlockIndex, typeof(ClaimStakeReward7))]
[InlineData(ClaimStakeReward7.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward8))]
[InlineData(ClaimStakeReward8.ObsoleteBlockIndex, typeof(ClaimStakeReward8))]
[InlineData(ClaimStakeReward8.ObsoleteBlockIndex + 1, typeof(ClaimStakeReward))]
[InlineData(long.MaxValue, typeof(ClaimStakeReward))]
public void ClaimStakeRewardWithBlockIndex(long blockIndex, Type expectedActionType)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var addr = new PrivateKey().Address;
var resultCode = _command.ClaimStakeReward(
addr.ToHex(),
filePath,
blockIndex: blockIndex);
Assert.Equal(0, resultCode);

var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
var plainValue = Assert.IsType<Dictionary>(decoded[1]);
var action = ClaimStakeRewardFactory.CreateByBlockIndex(blockIndex, addr);
Assert.NotNull(action);
var actionType = action.GetType();
Assert.Equal(expectedActionType, actionType);
action.LoadPlainValue(plainValue);
string type = (Text)decoded[0];
Assert.Equal(type, actionType.Name);
}

[Theory]
[InlineData(0, 0, -1)]
[InlineData(1, 9, 0)]
[InlineData(10, 10, -1)]
public void ClaimStakeRewardWithActionVersion(
int actionVersionMin,
int actionVersionMax,
int expectedCode)
{
for (var i = actionVersionMin; i < actionVersionMax + 1; i++)
{
var filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
var addr = new PrivateKey().Address;
var resultCode = _command.ClaimStakeReward(
addr.ToHex(),
filePath,
actionVersion: i);
Assert.Equal(expectedCode, resultCode);

if (expectedCode < 0)
{
continue;
}

var rawAction = Convert.FromBase64String(File.ReadAllText(filePath));
var decoded = (List)_codec.Decode(rawAction);
var plainValue = Assert.IsType<Dictionary>(decoded[1]);
var action = ClaimStakeRewardFactory.CreateByVersion(i, addr);
action.LoadPlainValue(plainValue);
string type = (Text)decoded[0];
Assert.Equal(action.GetType().Name, type);
}
}

[Theory]
[InlineData("0xab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", -1)]
[InlineData("ab1dce17dCE1Db1424BB833Af6cC087cd4F5CB6d", 0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void Sign_Stake(bool gas)
[InlineData(ClaimStakeReward2.ObsoletedIndex - 1, null, false)]
[InlineData(ClaimStakeReward2.ObsoletedIndex, null, true)]
[InlineData(ClaimStakeReward2.ObsoletedIndex + 1, null, false)]
[InlineData(ClaimStakeReward3.ObsoleteBlockIndex - 1, null, true)]
[InlineData(long.MaxValue, null, true)]
[InlineData(null, 1, false)]
[InlineData(null, 2, true)]
Expand All @@ -92,9 +91,7 @@ public void Sign_ClaimStakeReward(long? blockIndex, int? actionVersion, bool gas
var avatarAddress = new Address();
actionCommand.ClaimStakeReward(
avatarAddress.ToHex(),
filePath,
blockIndex,
actionVersion);
filePath);
Assert_Tx(1, filePath, gas);
}

Expand Down
9 changes: 6 additions & 3 deletions NineChronicles.Headless.Executable/Commands/AccountCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Bencodex;
using Cocona;
using Libplanet.Action.State;
using Libplanet.Blockchain;
using Libplanet.Crypto;
using Libplanet.Store;
Expand All @@ -11,6 +12,7 @@
using Libplanet.Types.Tx;
using Nekoyume.Action;
using Nekoyume.Model.State;
using Nekoyume.Module;
using NineChronicles.Headless.Executable.IO;
using Serilog.Core;
using static NineChronicles.Headless.NCActionUtils;
Expand Down Expand Up @@ -52,15 +54,16 @@ public void Balance(
Block offset = DevExUtils.ParseBlockOffset(chain, block);
_console.Error.WriteLine("The offset block: #{0} {1}.", offset.Index, offset.Hash);

IWorldState worldState = chain.GetWorldState(offset.Hash);
Bencodex.Types.Dictionary goldCurrencyStateDict = (Bencodex.Types.Dictionary)
chain.GetState(GoldCurrencyState.Address);
worldState.GetLegacyState(GoldCurrencyState.Address);
GoldCurrencyState goldCurrencyState = new GoldCurrencyState(goldCurrencyStateDict);
Currency gold = goldCurrencyState.Currency;

if (address is { } addrStr)
{
Address addr = DevExUtils.ParseAddress(addrStr);
FungibleAssetValue balance = chain.GetBalance(addr, gold, offset.Hash);
FungibleAssetValue balance = worldState.GetBalance(addr, gold);
_console.Out.WriteLine("{0}\t{1}", addr, balance);
return;
}
Expand Down Expand Up @@ -96,7 +99,7 @@ public void Balance(
{
if (!printed.Contains(addr))
{
FungibleAssetValue balance = chain.GetBalance(addr, gold, offset.Hash);
FungibleAssetValue balance = worldState.GetBalance(addr, gold);
_console.Out.WriteLine("{0}\t{1}", addr, balance);
printed.Add(addr);
}
Expand Down
35 changes: 2 additions & 33 deletions NineChronicles.Headless.Executable/Commands/ActionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action;
using Nekoyume.Action.Factory;
using Nekoyume.Model;
using NineChronicles.Headless.Executable.IO;

Expand Down Expand Up @@ -220,44 +219,14 @@ public int ClaimStakeReward(
[Argument("AVATAR-ADDRESS", Description = "A hex-encoded avatar address.")]
string encodedAddress,
[Argument("PATH", Description = "A file path of base64 encoded action.")]
string? filePath = null,
[Option("BLOCK-INDEX", Description = "A block index which is used to specifying the action version.")]
long? blockIndex = null,
[Option("ACTION-VERSION", Description = "A version of action.")]
int? actionVersion = null
string? filePath = null
)
{
try
{
if (blockIndex.HasValue && actionVersion.HasValue)
{
throw new CommandExitedException(
"You can't specify both block index and action version at the same time.",
-1);
}

Address avatarAddress = new Address(ByteUtil.ParseHex(encodedAddress));
IClaimStakeReward? action = null;
if (blockIndex.HasValue)
{
action = ClaimStakeRewardFactory.CreateByBlockIndex(
blockIndex.Value,
avatarAddress);
}
else if (actionVersion.HasValue)
{
action = ClaimStakeRewardFactory.CreateByVersion(
actionVersion.Value,
avatarAddress);
}

// NOTE: If neither block index nor action version is specified,
// it will be created by the type of the class.
// I considered to create action with max value of
// block index(i.e., long.MaxValue), but it is not good
// because the action of the next version may come along
// with the current version.
action ??= new ClaimStakeReward(avatarAddress);
action = new ClaimStakeReward(avatarAddress);

byte[] raw = Codec.Encode(new List(
new[]
Expand Down
3 changes: 2 additions & 1 deletion NineChronicles.Headless.Executable/Commands/MarketCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Libplanet.Types.Tx;
using Nekoyume.Action;
using Nekoyume.Model.Item;
using Nekoyume.Module;
using NineChronicles.Headless.Executable.IO;
using Serilog.Core;
using static NineChronicles.Headless.NCActionUtils;
Expand Down Expand Up @@ -130,7 +131,7 @@ public void Query(
{
int? quantity = null;
if (p.OrderId is { } oid &&
chain.GetState(GetOrderAddress(oid)) is Dictionary rawOrder)
chain.GetWorldState().GetLegacyState(GetOrderAddress(oid)) is Dictionary rawOrder)
{
if (OrderFactory.Deserialize(rawOrder) is FungibleOrder fo)
{
Expand Down
Loading
Loading