@@ -31,76 +31,57 @@ trait StateStorage {
31
31
def forcePersist (reason : FlushSituation ): Boolean
32
32
}
33
33
34
- class ArchiveStateStorage (private val nodeStorage : NodeStorage , private val cachedNodeStorage : CachedNodeStorage )
35
- extends StateStorage {
34
+ class ArchiveStateStorage (private val nodeStorage : NodeStorage ) extends StateStorage {
36
35
37
- override def forcePersist (reason : FlushSituation ): Boolean = {
38
- cachedNodeStorage.forcePersist()
39
- true
40
- }
36
+ override def forcePersist (reason : FlushSituation ): Boolean = true
41
37
42
38
override def onBlockSave (bn : BigInt , currentBestSavedBlock : BigInt )(updateBestBlocksData : () => Unit ): Unit =
43
- if (cachedNodeStorage.persist()) {
44
- updateBestBlocksData()
45
- }
39
+ updateBestBlocksData()
46
40
47
41
override def onBlockRollback (bn : BigInt , currentBestSavedBlock : BigInt )(updateBestBlocksData : () => Unit ): Unit =
48
- if (cachedNodeStorage.persist()) {
49
- updateBestBlocksData()
50
- }
42
+ updateBestBlocksData()
51
43
52
44
override def getReadOnlyStorage : MptStorage =
53
- new SerializingMptStorage (ReadOnlyNodeStorage (new ArchiveNodeStorage (cachedNodeStorage )))
45
+ new SerializingMptStorage (ReadOnlyNodeStorage (new ArchiveNodeStorage (nodeStorage )))
54
46
55
47
override def getBackingStorage (bn : BigInt ): MptStorage =
56
- new SerializingMptStorage (new ArchiveNodeStorage (cachedNodeStorage ))
48
+ new SerializingMptStorage (new ArchiveNodeStorage (nodeStorage ))
57
49
58
50
override def saveNode (nodeHash : NodeHash , nodeEncoded : NodeEncoded , bn : BigInt ): Unit =
59
51
nodeStorage.put(nodeHash, nodeEncoded)
60
52
61
53
override def getNode (nodeHash : NodeHash ): Option [MptNode ] =
62
- cachedNodeStorage .get(nodeHash).map(_.toMptNode)
54
+ nodeStorage .get(nodeHash).map(_.toMptNode)
63
55
}
64
56
65
57
class ReferenceCountedStateStorage (
66
58
private val nodeStorage : NodeStorage ,
67
- private val cachedNodeStorage : CachedNodeStorage ,
68
59
private val pruningHistory : BigInt
69
60
) extends StateStorage {
70
- override def forcePersist (reason : FlushSituation ): Boolean = {
71
- cachedNodeStorage.forcePersist()
72
- true
73
- }
61
+ override def forcePersist (reason : FlushSituation ): Boolean = true
74
62
75
63
override def onBlockSave (bn : BigInt , currentBestSavedBlock : BigInt )(updateBestBlocksData : () => Unit ): Unit = {
76
64
val blockToPrune = bn - pruningHistory
77
-
78
- ReferenceCountNodeStorage .prune(blockToPrune, cachedNodeStorage, inMemory = blockToPrune > currentBestSavedBlock)
79
-
80
- if (cachedNodeStorage.persist()) {
81
- updateBestBlocksData()
82
- }
65
+ ReferenceCountNodeStorage .prune(blockToPrune, nodeStorage, inMemory = blockToPrune > currentBestSavedBlock)
66
+ updateBestBlocksData()
83
67
}
84
68
85
69
override def onBlockRollback (bn : BigInt , currentBestSavedBlock : BigInt )(updateBestBlocksData : () => Unit ): Unit = {
86
- ReferenceCountNodeStorage .rollback(bn, cachedNodeStorage, inMemory = bn > currentBestSavedBlock)
87
-
88
- if (cachedNodeStorage.persist()) {
89
- updateBestBlocksData()
90
- }
70
+ ReferenceCountNodeStorage .rollback(bn, nodeStorage, inMemory = bn > currentBestSavedBlock)
71
+ updateBestBlocksData()
91
72
}
92
73
93
74
override def getBackingStorage (bn : BigInt ): MptStorage =
94
- new SerializingMptStorage (new ReferenceCountNodeStorage (cachedNodeStorage , bn))
75
+ new SerializingMptStorage (new ReferenceCountNodeStorage (nodeStorage , bn))
95
76
96
77
override def getReadOnlyStorage : MptStorage =
97
- new SerializingMptStorage (ReadOnlyNodeStorage (new FastSyncNodeStorage (cachedNodeStorage , 0 )))
78
+ new SerializingMptStorage (ReadOnlyNodeStorage (new FastSyncNodeStorage (nodeStorage , 0 )))
98
79
99
80
override def saveNode (nodeHash : NodeHash , nodeEncoded : NodeEncoded , bn : BigInt ): Unit =
100
81
new FastSyncNodeStorage (nodeStorage, bn).update(Nil , Seq (nodeHash -> nodeEncoded))
101
82
102
83
override def getNode (nodeHash : NodeHash ): Option [MptNode ] =
103
- new FastSyncNodeStorage (cachedNodeStorage , 0 ).get(nodeHash).map(_.toMptNode)
84
+ new FastSyncNodeStorage (nodeStorage , 0 ).get(nodeHash).map(_.toMptNode)
104
85
}
105
86
106
87
class CachedReferenceCountedStateStorage (
@@ -159,12 +140,11 @@ object StateStorage {
159
140
def apply (
160
141
pruningMode : PruningMode ,
161
142
nodeStorage : NodeStorage ,
162
- cachedNodeStorage : CachedNodeStorage ,
163
143
lruCache : LruCache [NodeHash , HeapEntry ]
164
144
): StateStorage =
165
145
pruningMode match {
166
- case ArchivePruning => new ArchiveStateStorage (nodeStorage, cachedNodeStorage )
167
- case pruning.BasicPruning (history) => new ReferenceCountedStateStorage (nodeStorage, cachedNodeStorage, history)
146
+ case ArchivePruning => new ArchiveStateStorage (nodeStorage)
147
+ case pruning.BasicPruning (history) => new ReferenceCountedStateStorage (nodeStorage, history)
168
148
case pruning.InMemoryPruning (history) => new CachedReferenceCountedStateStorage (nodeStorage, history, lruCache)
169
149
}
170
150
@@ -185,8 +165,9 @@ object StateStorage {
185
165
}
186
166
val nodeStorage = new NodeStorage (source)
187
167
val cachedNodeStorage = new CachedNodeStorage (nodeStorage, MapCache .createTestCache(testCacheSize))
168
+
188
169
(
189
- StateStorage (pruningMode, nodeStorage, cachedNodeStorage, new LruCache [NodeHash , HeapEntry ](testCacheConfig)),
170
+ StateStorage (pruningMode, nodeStorage, new LruCache [NodeHash , HeapEntry ](testCacheConfig)),
190
171
nodeStorage,
191
172
cachedNodeStorage
192
173
)
0 commit comments