public void Dispatcher_will_try_to_clear_memory() { TrieNode trieNode1 = new TrieNode(NodeType.Leaf, new byte[0]); trieNode1.ResolveKey(null !, true); TrieNode trieNode2 = new TrieNode(NodeType.Leaf, new byte[1]); trieNode2.ResolveKey(null !, true); TrieNode trieNode3 = new TrieNode(NodeType.Leaf, new byte[2]); trieNode3.ResolveKey(null !, true); TrieNode trieNode4 = new TrieNode(NodeType.Leaf, new byte[3]); trieNode4.ResolveKey(null !, true); TrieStore trieStore = new TrieStore(new MemDb(), new MemoryLimit(640), No.Persistence, _logManager); trieStore.CommitNode(1234, new NodeCommitInfo(trieNode1)); trieStore.CommitNode(1234, new NodeCommitInfo(trieNode2)); trieStore.FinishBlockCommit(TrieType.State, 1234, trieNode2); trieStore.CommitNode(1235, new NodeCommitInfo(trieNode3)); trieStore.CommitNode(1235, new NodeCommitInfo(trieNode4)); trieStore.FinishBlockCommit(TrieType.State, 1235, trieNode2); trieStore.FinishBlockCommit(TrieType.State, 1236, trieNode2); trieStore.MemoryUsedByDirtyCache.Should().Be( trieNode1.GetMemorySize(false) + trieNode2.GetMemorySize(false) + trieNode3.GetMemorySize(false) + trieNode4.GetMemorySize(false)); }
public void Dispatcher_will_save_to_db_everything_from_snapshot_blocks() { TrieNode a = new TrieNode(NodeType.Leaf, new byte[0]); // 192B a.ResolveKey(NullTrieNodeResolver.Instance, true); MemDb memDb = new MemDb(); TrieStore trieStore = new TrieStore(memDb, new MemoryLimit(16.MB()), new ConstantInterval(4), _logManager); trieStore.CommitNode(0, new NodeCommitInfo(a)); trieStore.FinishBlockCommit(TrieType.State, 0, a); trieStore.FinishBlockCommit(TrieType.State, 1, a); trieStore.FinishBlockCommit(TrieType.State, 2, a); trieStore.FinishBlockCommit(TrieType.State, 3, a); trieStore.FinishBlockCommit(TrieType.State, 4, a); memDb[a.Keccak !.Bytes].Should().NotBeNull();
public void Prunning_off_cache_should_not_change_commit_node() { TrieNode trieNode = new TrieNode(NodeType.Leaf, Keccak.Zero); TrieNode trieNode2 = new TrieNode(NodeType.Branch, TestItem.KeccakA); TrieNode trieNode3 = new TrieNode(NodeType.Branch, TestItem.KeccakB); TrieStore trieStore = new TrieStore(new MemDb(), No.Pruning, No.Persistence, _logManager); trieStore.CommitNode(1234, new NodeCommitInfo(trieNode)); trieStore.FinishBlockCommit(TrieType.State, 1234, trieNode); trieStore.CommitNode(124, new NodeCommitInfo(trieNode2)); trieStore.CommitNode(11234, new NodeCommitInfo(trieNode3)); trieStore.MemoryUsedByDirtyCache.Should().Be(0); }
public void Dispatcher_will_always_try_to_clear_memory() { TrieStore trieStore = new TrieStore(new MemDb(), new MemoryLimit(512), No.Persistence, _logManager); for (int i = 0; i < 1024; i++) { for (int j = 0; j < 1 + i % 3; j++) { TrieNode trieNode = new TrieNode(NodeType.Leaf, new byte[0]); // 192B trieNode.ResolveKey(NullTrieNodeResolver.Instance, true); trieStore.CommitNode(i, new NodeCommitInfo(trieNode)); } TrieNode fakeRoot = new TrieNode(NodeType.Leaf, new byte[0]); // 192B fakeRoot.ResolveKey(NullTrieNodeResolver.Instance, true); trieStore.FinishBlockCommit(TrieType.State, i, fakeRoot); } trieStore.MemoryUsedByDirtyCache.Should().BeLessThan(512 * 2); }
public void Memory_with_two_times_two_nodes_is_correct() { TrieNode trieNode1 = new TrieNode(NodeType.Leaf, TestItem.KeccakA); TrieNode trieNode2 = new TrieNode(NodeType.Leaf, TestItem.KeccakB); TrieNode trieNode3 = new TrieNode(NodeType.Leaf, TestItem.KeccakA); TrieNode trieNode4 = new TrieNode(NodeType.Leaf, TestItem.KeccakB); TrieStore trieStore = new TrieStore(new MemDb(), new TestPruningStrategy(true), No.Persistence, _logManager); trieStore.CommitNode(1234, new NodeCommitInfo(trieNode1)); trieStore.CommitNode(1234, new NodeCommitInfo(trieNode2)); trieStore.FinishBlockCommit(TrieType.State, 1234, trieNode2); trieStore.CommitNode(1235, new NodeCommitInfo(trieNode3)); trieStore.CommitNode(1235, new NodeCommitInfo(trieNode4)); // depending on whether the node gets resolved it gives different values here in debugging and run // needs some attention trieStore.MemoryUsedByDirtyCache.Should().BeLessOrEqualTo( trieNode1.GetMemorySize(false) + trieNode2.GetMemorySize(false)); }