@@ -46,6 +46,27 @@ func DeleteStateHistoryIndexMetadata(db ethdb.KeyValueWriter) {
46
46
}
47
47
}
48
48
49
+ // ReadTrienodeHistoryIndexMetadata retrieves the metadata of trienode history index.
50
+ func ReadTrienodeHistoryIndexMetadata (db ethdb.KeyValueReader ) []byte {
51
+ data , _ := db .Get (headTrienodeHistoryIndexKey )
52
+ return data
53
+ }
54
+
55
+ // WriteTrienodeHistoryIndexMetadata stores the metadata of trienode history index
56
+ // into database.
57
+ func WriteTrienodeHistoryIndexMetadata (db ethdb.KeyValueWriter , blob []byte ) {
58
+ if err := db .Put (headTrienodeHistoryIndexKey , blob ); err != nil {
59
+ log .Crit ("Failed to store the metadata of trienode history index" , "err" , err )
60
+ }
61
+ }
62
+
63
+ // DeleteTrienodeHistoryIndexMetadata removes the metadata of trienode history index.
64
+ func DeleteTrienodeHistoryIndexMetadata (db ethdb.KeyValueWriter ) {
65
+ if err := db .Delete (headTrienodeHistoryIndexKey ); err != nil {
66
+ log .Crit ("Failed to delete the metadata of trienode history index" , "err" , err )
67
+ }
68
+ }
69
+
49
70
// ReadAccountHistoryIndex retrieves the account history index with the provided
50
71
// account address.
51
72
func ReadAccountHistoryIndex (db ethdb.KeyValueReader , addressHash common.Hash ) []byte {
@@ -95,6 +116,30 @@ func DeleteStorageHistoryIndex(db ethdb.KeyValueWriter, addressHash common.Hash,
95
116
}
96
117
}
97
118
119
+ // ReadTrienodeHistoryIndex retrieves the trienode history index with the provided
120
+ // account address and storage key hash.
121
+ func ReadTrienodeHistoryIndex (db ethdb.KeyValueReader , addressHash common.Hash , path []byte ) []byte {
122
+ data , err := db .Get (trienodeHistoryIndexKey (addressHash , path ))
123
+ if err != nil || len (data ) == 0 {
124
+ return nil
125
+ }
126
+ return data
127
+ }
128
+
129
+ // WriteTrienodeHistoryIndex writes the provided trienode history index into database.
130
+ func WriteTrienodeHistoryIndex (db ethdb.KeyValueWriter , addressHash common.Hash , path []byte , data []byte ) {
131
+ if err := db .Put (trienodeHistoryIndexKey (addressHash , path ), data ); err != nil {
132
+ log .Crit ("Failed to store trienode history index" , "err" , err )
133
+ }
134
+ }
135
+
136
+ // DeleteTrienodeHistoryIndex deletes the specified trienode index from the database.
137
+ func DeleteTrienodeHistoryIndex (db ethdb.KeyValueWriter , addressHash common.Hash , path []byte ) {
138
+ if err := db .Delete (trienodeHistoryIndexKey (addressHash , path )); err != nil {
139
+ log .Crit ("Failed to delete trienode history index" , "err" , err )
140
+ }
141
+ }
142
+
98
143
// ReadAccountHistoryIndexBlock retrieves the index block with the provided
99
144
// account address along with the block id.
100
145
func ReadAccountHistoryIndexBlock (db ethdb.KeyValueReader , addressHash common.Hash , blockID uint32 ) []byte {
@@ -143,6 +188,30 @@ func DeleteStorageHistoryIndexBlock(db ethdb.KeyValueWriter, addressHash common.
143
188
}
144
189
}
145
190
191
+ // ReadTrienodeHistoryIndexBlock retrieves the index block with the provided state
192
+ // identifier along with the block id.
193
+ func ReadTrienodeHistoryIndexBlock (db ethdb.KeyValueReader , addressHash common.Hash , path []byte , blockID uint32 ) []byte {
194
+ data , err := db .Get (trienodeHistoryIndexBlockKey (addressHash , path , blockID ))
195
+ if err != nil || len (data ) == 0 {
196
+ return nil
197
+ }
198
+ return data
199
+ }
200
+
201
+ // WriteTrienodeHistoryIndexBlock writes the provided index block into database.
202
+ func WriteTrienodeHistoryIndexBlock (db ethdb.KeyValueWriter , addressHash common.Hash , path []byte , id uint32 , data []byte ) {
203
+ if err := db .Put (trienodeHistoryIndexBlockKey (addressHash , path , id ), data ); err != nil {
204
+ log .Crit ("Failed to store trienode index block" , "err" , err )
205
+ }
206
+ }
207
+
208
+ // DeleteTrienodeHistoryIndexBlock deletes the specified index block from the database.
209
+ func DeleteTrienodeHistoryIndexBlock (db ethdb.KeyValueWriter , addressHash common.Hash , path []byte , id uint32 ) {
210
+ if err := db .Delete (trienodeHistoryIndexBlockKey (addressHash , path , id )); err != nil {
211
+ log .Crit ("Failed to delete trienode index block" , "err" , err )
212
+ }
213
+ }
214
+
146
215
// increaseKey increase the input key by one bit. Return nil if the entire
147
216
// addition operation overflows.
148
217
func increaseKey (key []byte ) []byte {
@@ -155,14 +224,26 @@ func increaseKey(key []byte) []byte {
155
224
return nil
156
225
}
157
226
158
- // DeleteStateHistoryIndex completely removes all history indexing data, including
227
+ // DeleteStateHistoryIndexes completely removes all history indexing data, including
159
228
// indexes for accounts and storages.
160
- //
161
- // Note, this method assumes the storage space with prefix `StateHistoryIndexPrefix`
162
- // is exclusively occupied by the history indexing data!
163
- func DeleteStateHistoryIndex (db ethdb.KeyValueRangeDeleter ) {
164
- start := StateHistoryIndexPrefix
165
- limit := increaseKey (bytes .Clone (StateHistoryIndexPrefix ))
229
+ func DeleteStateHistoryIndexes (db ethdb.KeyValueRangeDeleter ) {
230
+ DeleteHistoryByRange (db , StateHistoryAccountMetadataPrefix )
231
+ DeleteHistoryByRange (db , StateHistoryStorageMetadataPrefix )
232
+ DeleteHistoryByRange (db , StateHistoryAccountBlockPrefix )
233
+ DeleteHistoryByRange (db , StateHistoryStorageBlockPrefix )
234
+ }
235
+
236
+ // DeleteTrienodeHistoryIndexes completely removes all trienode history indexing data.
237
+ func DeleteTrienodeHistoryIndexes (db ethdb.KeyValueRangeDeleter ) {
238
+ DeleteHistoryByRange (db , TrienodeHistoryMetadataPrefix )
239
+ DeleteHistoryByRange (db , TrienodeHistoryBlockPrefix )
240
+ }
241
+
242
+ // DeleteHistoryByRange completely removes all database entries with the specific prefix.
243
+ // Note, this method assumes the space with the given prefix is exclusively occupied!
244
+ func DeleteHistoryByRange (db ethdb.KeyValueRangeDeleter , prefix []byte ) {
245
+ start := prefix
246
+ limit := increaseKey (bytes .Clone (prefix ))
166
247
167
248
// Try to remove the data in the range by a loop, as the leveldb
168
249
// doesn't support the native range deletion.
0 commit comments