Skip to content

Commit

Permalink
Merge pull request #2445 from s2quake/bump/lib9c-using-libplanet-4.2.0
Browse files Browse the repository at this point in the history
Bump Lib9c using libplanet 4.2.0
  • Loading branch information
greymistcube authored Apr 17, 2024
2 parents baf90d1 + 31b9c3b commit 6b0f40c
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 709 deletions.
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 30 files
+133 −0 .Lib9c.Tests/Action/CombinationConsumableTest.cs
+15 −0 .Lib9c.Tests/Action/Common/MockWorldState.cs
+280 −0 .Lib9c.Tests/Action/CreateAvatarTest.cs
+492 −0 .Lib9c.Tests/Action/EventDungeonBattleTest.cs
+712 −0 .Lib9c.Tests/Action/HackAndSlashSweepTest.cs
+366 −0 .Lib9c.Tests/Action/ItemEnhancementTest.cs
+626 −0 .Lib9c.Tests/Action/RaidTest.cs
+615 −0 .Lib9c.Tests/Action/RapidCombinationTest.cs
+4 −5 .Lib9c.Tests/Model/Skill/Arena/ArenaCombatTest.cs
+1 −1 .Lib9c.Tests/Model/Skill/Arena/ArenaShatterStrikeTest.cs
+3 −5 .Lib9c.Tests/Model/Skill/CombatTest.cs
+1 −1 .Lib9c.Tests/Model/Skill/ShatterStrikeTest.cs
+0 −1 .Lib9c.Tests/Policy/BlockPolicyTest.cs
+0 −2 .Lib9c.Tools/SubCommand/Account.cs
+1 −1 .Libplanet
+0 −9 .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccount.cs
+0 −169 .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs
+169 −0 .Libplanet.Extensions.RemoteBlockChainStates/RemoteWorldState.cs
+2 −0 Lib9c.MessagePack/Action/NCActionEvaluation.cs
+0 −1 Lib9c.Policy/Policy/BlockPolicySource.cs
+1 −2 Lib9c/Action/RewardGold.cs
+0 −33 Lib9c/Model/State/DeletedAvatarState.cs
+9 −68 Lib9c/Module/LegacyModule.cs
+201 −1 Lib9c/TableCSV/Cost/EnhancementCostSheetV3.csv
+4 −1 Lib9c/TableCSV/Item/ConsumableItemSheet.csv
+10 −0 Lib9c/TableCSV/Item/ItemRequirementSheet.csv
+22 −15 Lib9c/TableCSV/Item/MaterialItemSheet.csv
+1 −2 Lib9c/TableCSV/Skill/ActionBuffSheet.csv
+1 −2 Lib9c/TableCSV/Skill/SkillActionBuffSheet.csv
+175 −176 Lib9c/TableCSV/Skill/SkillSheet.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="..\NineChronicles.Headless.Executable\NineChronicles.Headless.Executable.csproj" />
<ProjectReference Include="..\Lib9c\.Libplanet\Libplanet.Mocks\Libplanet.Mocks.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public void Balance(
_console.Error.WriteLine("Scanning block #{0} {1}...", digest.Index, digest.Hash);
_console.Error.Flush();
IEnumerable<Address> addrs = digest.TxIds
.Select(txId => store.GetTransaction(new TxId(txId.ToArray())))
.Select(txId =>
{
return store.GetTransaction(new TxId(txId.ToArray())) ??
throw new InvalidOperationException($"Transaction #{txId} is not found in the store.");
})
.SelectMany(tx => tx.Actions is { } ca
? ca.Select(a => ToAction(a))
.SelectMany(a =>
Expand Down
56 changes: 41 additions & 15 deletions NineChronicles.Headless.Executable/Commands/ChainCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Tip(

BlockHash tipHash = store.IndexBlockHash(chainId, -1)
?? throw new CommandExitedException("The given chain seems empty.", -1);
Block tip = store.GetBlock(tipHash);
Block tip = GetBlock(store, tipHash);
_console.Out.WriteLine(CoconaUtils.SerializeHumanReadable(tip.Header));
store.Dispose();
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public void Inspect(
throw new CommandExitedException($"There is no genesis block: {storePath}", -1);
}

Block genesisBlock = store.GetBlock(gHash);
Block genesisBlock = GetBlock(store, gHash);
var blockChainStates = new BlockChainStates(store, stateStore);
var actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
Expand Down Expand Up @@ -163,8 +163,8 @@ public void Inspect(
foreach (var item in
store.IterateIndexes(chain.Id, offset + 1 ?? 1, limit).Select((value, i) => new { i, value }))
{
var block = store.GetBlock(item.value);
var previousBlock = store.GetBlock(
var block = GetBlock(store, item.value);
var previousBlock = GetBlock(store,
block.PreviousHash ?? block.Hash
);

Expand Down Expand Up @@ -270,7 +270,7 @@ public void Truncate(
-1);
}

var tip = store.GetBlock(tipHash);
var tip = GetBlock(store, tipHash);
var snapshotTipIndex = Math.Max(tipIndex - (blocksBefore + 1), 0);
BlockHash snapshotTipHash;

Expand All @@ -286,7 +286,7 @@ public void Truncate(
}

snapshotTipHash = hash;
} while (!stateStore.GetStateRoot(store.GetBlock(snapshotTipHash).StateRootHash).Recorded);
} while (!stateStore.GetStateRoot(GetBlock(store, snapshotTipHash).StateRootHash).Recorded);

var forkedId = Guid.NewGuid();

Expand Down Expand Up @@ -484,11 +484,11 @@ public void Snapshot(
);
var originalChain = new BlockChain(blockPolicy, stagePolicy, store, stateStore,
store.GetBlock(genesisHash), blockChainStates, actionEvaluator);
var tip = store.GetBlock(tipHash);
var tip = GetBlock(store, tipHash);

var potentialSnapshotTipIndex = tipIndex - blockBefore;
var potentialSnapshotTipHash = (BlockHash)store.IndexBlockHash(chainId, potentialSnapshotTipIndex)!;
var snapshotTip = store.GetBlock(potentialSnapshotTipHash);
var snapshotTip = GetBlock(store, potentialSnapshotTipHash);

_console.Out.WriteLine(
"Original Store Tip: #{0}\n1. LastCommit: {1}\n2. BlockCommit in Chain: {2}\n3. BlockCommit in Store: {3}",
Expand Down Expand Up @@ -520,24 +520,38 @@ public void Snapshot(
"There is no block commit associated with the potential snapshot tip: #{0}. Snapshot will automatically truncate 1 more block from the original chain tip.",
potentialSnapshotTipIndex);
blockBefore += 1;
potentialSnapshotTipBlockCommit = store
.GetBlock((BlockHash)store.IndexBlockHash(chainId, tip.Index - blockBefore + 1)!).LastCommit;
potentialSnapshotTipBlockCommit =
GetBlock(store, (BlockHash)store.IndexBlockHash(chainId, tip.Index - blockBefore + 1)!).LastCommit;
if (potentialSnapshotTipBlockCommit == null)
{
throw new CommandExitedException(
$"The block commit of the potential snapshot tip: #{potentialSnapshotTipIndex} doesn't exist.",
-1);
}

store.PutBlockCommit(tipBlockCommit);
store.PutChainBlockCommit(chainId, tipBlockCommit);
store.PutBlockCommit(potentialSnapshotTipBlockCommit);
store.PutChainBlockCommit(chainId, potentialSnapshotTipBlockCommit);
}

var blockCommitBlock = store.GetBlock(tipHash);
var blockCommitBlock = GetBlock(store, tipHash);

// Add last block commits to store from tip until --block-before + 5 or tip if too short for buffer
var blockCommitRange = blockBefore + 5 < tip.Index ? blockBefore + 5 : tip.Index - 1;
for (var i = 0; i < blockCommitRange; i++)
{
_console.Out.WriteLine("Adding block #{0}'s block commit to the store", blockCommitBlock.Index - 1);
if (blockCommitBlock.LastCommit == null)
{
throw new CommandExitedException(
$"The block commit of the block: #{blockCommitBlock.Index} doesn't exist.",
-1);
}

store.PutBlockCommit(blockCommitBlock.LastCommit);
store.PutChainBlockCommit(chainId, blockCommitBlock.LastCommit);
blockCommitBlock = store.GetBlock((BlockHash)blockCommitBlock.PreviousHash!);
blockCommitBlock = GetBlock(store, (BlockHash)blockCommitBlock.PreviousHash!);
}

var snapshotTipIndex = Math.Max(tipIndex - (blockBefore + 1), 0);
Expand All @@ -555,7 +569,7 @@ public void Snapshot(
}

snapshotTipHash = hash;
} while (!stateStore.GetStateRoot(store.GetBlock(snapshotTipHash).StateRootHash).Recorded);
} while (!stateStore.GetStateRoot(GetBlock(store, snapshotTipHash).StateRootHash).Recorded);

var forkedId = Guid.NewGuid();
Fork(chainId, forkedId, snapshotTipHash, tip, store);
Expand Down Expand Up @@ -745,6 +759,18 @@ public void Snapshot(
}
}

private static Block GetBlock(IStore store, BlockHash blockHash)
{
return store.GetBlock(blockHash) ??
throw new CommandExitedException($"The block of {blockHash} doesn't exist.", -1);
}

private static BlockCommit GetBlockCommit(IStore store, BlockHash blockHash)
{
return store.GetBlockCommit(blockHash) ??
throw new CommandExitedException($"The block commit of {blockHash} doesn't exist.", -1);
}

private string GetPartitionBaseFileName(
int currentMetadataBlockEpoch,
int currentMetadataTxEpoch,
Expand Down Expand Up @@ -1025,15 +1051,15 @@ private void Fork(
store.ForkBlockIndexes(src, dest, branchPointHash);
if (store.GetBlockCommit(branchPointHash) is { })
{
store.PutChainBlockCommit(dest, store.GetBlockCommit(branchPointHash));
store.PutChainBlockCommit(dest, GetBlockCommit(store, branchPointHash));
}
store.ForkTxNonces(src, dest);

for (
Block block = tip;
block.PreviousHash is { } hash
&& !block.Hash.Equals(branchPointHash);
block = store.GetBlock(hash))
block = GetBlock(store, hash))
{
IEnumerable<(Address, int)> signers = block
.Transactions
Expand Down
3 changes: 2 additions & 1 deletion NineChronicles.Headless.Executable/Commands/StateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ IStateStore stateStore
}

Block block =
store.GetBlock(blockHash);
store.GetBlock(blockHash) ??
throw new CommandExitedException($"The block of {blockHash} doesn't exist.", -1);
var preEvalBlock = new PreEvaluationBlock(
block,
block.Transactions
Expand Down
7 changes: 6 additions & 1 deletion NineChronicles.Headless.Executable/Store/StoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public static Block GetGenesisBlock(this IStore store)
}

BlockHash genesisBlockHash = store.IterateIndexes(chainId.Value).First();
Block genesisBlock = store.GetBlock(genesisBlockHash);
Block? genesisBlock = store.GetBlock(genesisBlockHash);
if (genesisBlock == null)
{
throw new InvalidOperationException("The store doesn't have genesis block.");
}

return genesisBlock;
}
}
Expand Down
3 changes: 2 additions & 1 deletion NineChronicles.Headless.Tests/ArenaParticipantsWorkerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Lib9c.Tests;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Mocks;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model.Arena;
Expand All @@ -25,7 +26,7 @@ public class ArenaParticipantsWorkerTest

public ArenaParticipantsWorkerTest()
{
_world = new MockWorld(new MockWorldState());
_world = new World(MockWorldState.CreateModern());
_sheets = TableSheetsImporter.ImportSheets();
}

Expand Down
Loading

0 comments on commit 6b0f40c

Please sign in to comment.