From 114d8ea803730b43fb52b411ae492f9df167a95e Mon Sep 17 00:00:00 2001 From: Suho Lee Date: Fri, 15 Sep 2023 18:46:39 +0900 Subject: [PATCH] commit on aev --- Lib9c | 2 +- .../ForkableActionEvaluatorTest.cs | 8 ++++---- .../ForkableActionEvaluator.cs | 2 +- .../Commands/ReplayCommand.Privates.cs | 6 ++++++ .../Commands/ReplayCommand.cs | 6 +++--- .../Commands/StateCommand.cs | 13 ++++++++++--- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Lib9c b/Lib9c index 3bf5d8df2..6a6b248c8 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 3bf5d8df242f234af2c28b78ba535ade702b060f +Subproject commit 6a6b248c815a27287f871967a83913bcadefddaa diff --git a/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs b/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs index cd5714f01..49c2036ef 100644 --- a/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs +++ b/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs @@ -64,7 +64,7 @@ public void CheckPairs() class PostActionEvaluator : IActionEvaluator { public IActionLoader ActionLoader => throw new NotSupportedException(); - public IReadOnlyList Evaluate(IPreEvaluationBlock block) + public IReadOnlyList Evaluate(IPreEvaluationBlock block) { return new IActionEvaluation[] { @@ -84,14 +84,14 @@ public IReadOnlyList Evaluate(IPreEvaluationBlock block) false), new AccountStateDelta(), null) - }; + }.Select(x => new ActionResult(x)).ToArray(); } } class PreActionEvaluator : IActionEvaluator { public IActionLoader ActionLoader => throw new NotSupportedException(); - public IReadOnlyList Evaluate(IPreEvaluationBlock block) + public IReadOnlyList Evaluate(IPreEvaluationBlock block) { return new IActionEvaluation[] { @@ -111,7 +111,7 @@ public IReadOnlyList Evaluate(IPreEvaluationBlock block) false), new AccountStateDelta(), null) - }; + }.Select(x => new ActionResult(x)).ToArray(); } } diff --git a/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs b/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs index 13c60a5ea..93e92f9e1 100644 --- a/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs +++ b/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs @@ -15,7 +15,7 @@ public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Ran public IActionLoader ActionLoader => throw new NotSupportedException(); - public IReadOnlyList Evaluate(IPreEvaluationBlock block) + public IReadOnlyList Evaluate(IPreEvaluationBlock block) { var actionEvaluator = _router.GetEvaluator(block.Index); return actionEvaluator.Evaluate(block); diff --git a/NineChronicles.Headless.Executable/Commands/ReplayCommand.Privates.cs b/NineChronicles.Headless.Executable/Commands/ReplayCommand.Privates.cs index 9581815f3..2459d2824 100644 --- a/NineChronicles.Headless.Executable/Commands/ReplayCommand.Privates.cs +++ b/NineChronicles.Headless.Executable/Commands/ReplayCommand.Privates.cs @@ -147,6 +147,12 @@ public IAccountState GetAccountState(BlockHash? offset) { return new LocalCacheAccountState(_rocksDb, _source.GetAccountState, offset); } + + public IAccountState GetAccountState(HashDigest? stateRootHash) => + throw new NotImplementedException(); + + public ITrie Commit(ITrie trie) => + throw new NotImplementedException(); } private sealed class LocalCacheAccountState : IAccountState diff --git a/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs b/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs index 19ebea278..483cc4bb4 100644 --- a/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs @@ -271,7 +271,7 @@ public int Blocks( try { var rootHash = blockChain.DetermineBlockStateRootHash(block, - out IReadOnlyList actionEvaluations); + out IReadOnlyList actionEvaluations); if (verbose) { @@ -558,7 +558,7 @@ private void LoggingAboutIncompleteBlockStatesException( } private void LoggingActionEvaluations( - IReadOnlyList actionEvaluations, + IReadOnlyList actionEvaluations, TextWriter? textWriter) { var count = actionEvaluations.Count; @@ -593,7 +593,7 @@ private void LoggingActionEvaluations( var prefix = $"--- action evaluation {i + 1}/{count}:"; var msg = prefix + - $" tx-id({actionEvaluation.InputContext.TxId})" + + $" tx-id({actionEvaluation.TxId})" + $", action-type(\"{actionType}\")"; if (actionEvaluation.Exception is null) { diff --git a/NineChronicles.Headless.Executable/Commands/StateCommand.cs b/NineChronicles.Headless.Executable/Commands/StateCommand.cs index 235e7bbd8..0a1505125 100644 --- a/NineChronicles.Headless.Executable/Commands/StateCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/StateCommand.cs @@ -132,7 +132,7 @@ IStateStore stateStore block.Index, block.Hash ); - IReadOnlyList delta; + IReadOnlyList delta; HashDigest stateRootHash = block.Index < 1 ? BlockChain.DetermineGenesisStateRootHash( actionEvaluator, @@ -148,9 +148,16 @@ IStateStore stateStore block.MarshalBlock(), $"block_{block.Index}_{block.Hash}" ); + ITrie previous = blockChainStates.GetAccountState(delta.First().PreviousRootHash).Trie; + ITrie output = blockChainStates.GetAccountState(delta.Last().OutputRootHash).Trie; + var diff = output.Diff(previous); + Dictionary diffDict = Dictionary.Empty; + foreach (var item in diff) + { + diffDict = diffDict.Add(item.Path.Hex, item.SourceValue); + } string deltaDump = DumpBencodexToFile( - new Dictionary( - GetTotalDelta(delta, ToStateKey, ToFungibleAssetKey, ToTotalSupplyKey, ValidatorSetKey)), + diffDict, $"delta_{block.Index}_{block.Hash}" ); string message =