From 2cb9598b3c4da87ba22bcac76efd64c3b8cea0b1 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Wed, 15 Nov 2023 16:17:53 +0900 Subject: [PATCH] Cleanup --- .../Commands/MptCommand.cs | 20 ++++++++----------- Libplanet.Store/HashNodeCache.cs | 2 +- Libplanet.Store/Trie/MerkleTrie.cs | 10 ++++++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Libplanet.Extensions.Cocona/Commands/MptCommand.cs b/Libplanet.Extensions.Cocona/Commands/MptCommand.cs index 4dc7ac6a9b7..5d35c05e3da 100644 --- a/Libplanet.Extensions.Cocona/Commands/MptCommand.cs +++ b/Libplanet.Extensions.Cocona/Commands/MptCommand.cs @@ -69,14 +69,12 @@ public void Diff( kvStoreUri = ConvertKVStoreUri(kvStoreUri, toolConfiguration); otherKvStoreUri = ConvertKVStoreUri(otherKvStoreUri, toolConfiguration); - IKeyValueStore keyValueStore = LoadKVStoreFromURI(kvStoreUri); - IKeyValueStore otherKeyValueStore = LoadKVStoreFromURI(otherKvStoreUri); - var trie = new MerkleTrie( - keyValueStore, - HashDigest.FromString(stateRootHashHex)); - var otherTrie = new MerkleTrie( - otherKeyValueStore, - HashDigest.FromString(otherStateRootHashHex)); + IStateStore stateStore = new TrieStateStore(LoadKVStoreFromURI(kvStoreUri)); + IStateStore otherStateStore = new TrieStateStore(LoadKVStoreFromURI(otherKvStoreUri)); + var trie = + stateStore.GetStateRoot(HashDigest.FromString(stateRootHashHex)); + var otherTrie = + otherStateStore.GetStateRoot(HashDigest.FromString(otherStateRootHashHex)); var codec = new Codec(); HashDigest originRootHash = trie.Hash; @@ -113,10 +111,8 @@ public void Export( ToolConfiguration toolConfiguration = configurationService.Load(); kvStoreUri = ConvertKVStoreUri(kvStoreUri, toolConfiguration); - IKeyValueStore keyValueStore = LoadKVStoreFromURI(kvStoreUri); - var trie = new MerkleTrie( - keyValueStore, - HashDigest.FromString(stateRootHashHex)); + IStateStore stateStore = new TrieStateStore(LoadKVStoreFromURI(kvStoreUri)); + var trie = stateStore.GetStateRoot(HashDigest.FromString(stateRootHashHex)); var codec = new Codec(); // This assumes the original key was encoded from a sensible string. diff --git a/Libplanet.Store/HashNodeCache.cs b/Libplanet.Store/HashNodeCache.cs index cecb80fbea3..68167003953 100644 --- a/Libplanet.Store/HashNodeCache.cs +++ b/Libplanet.Store/HashNodeCache.cs @@ -20,7 +20,7 @@ public class HashNodeCache private int _hits; private object _reportLock; - public HashNodeCache() + internal HashNodeCache() { _cache = new LruCache, IValue>(_cahceSize); _stopwatch = new Stopwatch(); diff --git a/Libplanet.Store/Trie/MerkleTrie.cs b/Libplanet.Store/Trie/MerkleTrie.cs index 3645546e717..4dc5377e167 100644 --- a/Libplanet.Store/Trie/MerkleTrie.cs +++ b/Libplanet.Store/Trie/MerkleTrie.cs @@ -38,12 +38,12 @@ static MerkleTrie() /// nodes. /// The root of /// . - /// The to use as a cache. + /// The to use as cache. public MerkleTrie( IKeyValueStore keyValueStore, HashDigest rootHash, HashNodeCache? cache = null) - : this(keyValueStore, new HashNode(rootHash)) + : this(keyValueStore, new HashNode(rootHash), cache) { } @@ -54,9 +54,11 @@ public MerkleTrie( /// nodes. /// The root node of . If it is /// , it will be treated like empty trie. - /// The to use as a cache. + /// The to use as cache. public MerkleTrie( - IKeyValueStore keyValueStore, INode? root = null, HashNodeCache? cache = null) + IKeyValueStore keyValueStore, + INode? root = null, + HashNodeCache? cache = null) { // FIXME: It might be a good idea to have something like IReadOnlyKeyValueStore. KeyValueStore = keyValueStore;