@@ -21,17 +21,17 @@ use super::cache;
21
21
#[ derive( Clone ) ]
22
22
pub struct GeneralizedDatabase {
23
23
pub store : Arc < dyn Database > ,
24
- pub cache : CacheDB ,
25
- pub immutable_cache : HashMap < Address , Account > ,
24
+ pub current_accounts_state : CacheDB ,
25
+ pub initial_accounts_state : HashMap < Address , Account > ,
26
26
pub tx_backup : Option < CallFrameBackup > ,
27
27
}
28
28
29
29
impl GeneralizedDatabase {
30
- pub fn new ( store : Arc < dyn Database > , cache : CacheDB ) -> Self {
30
+ pub fn new ( store : Arc < dyn Database > , current_accounts_state : CacheDB ) -> Self {
31
31
Self {
32
32
store,
33
- cache : cache . clone ( ) ,
34
- immutable_cache : cache ,
33
+ current_accounts_state : current_accounts_state . clone ( ) ,
34
+ initial_accounts_state : current_accounts_state ,
35
35
tx_backup : None ,
36
36
}
37
37
}
@@ -40,11 +40,12 @@ impl GeneralizedDatabase {
40
40
/// Gets account, first checking the cache and then the database
41
41
/// (caching in the second case)
42
42
pub fn get_account ( & mut self , address : Address ) -> Result < & Account , InternalError > {
43
- if !cache:: account_is_cached ( & self . cache , & address) {
43
+ if !cache:: account_is_cached ( & self . current_accounts_state , & address) {
44
44
let account = self . get_account_from_database ( address) ?;
45
- cache:: insert_account ( & mut self . cache , address, account) ;
45
+ cache:: insert_account ( & mut self . current_accounts_state , address, account) ;
46
46
}
47
- cache:: get_account ( & self . cache , & address) . ok_or ( InternalError :: AccountNotFound )
47
+ cache:: get_account ( & self . current_accounts_state , & address)
48
+ . ok_or ( InternalError :: AccountNotFound )
48
49
}
49
50
50
51
/// **Accesses to an account's information.**
@@ -62,25 +63,25 @@ impl GeneralizedDatabase {
62
63
Ok ( ( account, address_was_cold) )
63
64
}
64
65
65
- /// Gets account from storage, storing in Immutable Cache for efficiency when getting AccountUpdates.
66
+ /// Gets account from storage, storing in initial_accounts_state for efficiency when getting AccountUpdates.
66
67
pub fn get_account_from_database (
67
68
& mut self ,
68
69
address : Address ,
69
70
) -> Result < Account , InternalError > {
70
71
let account = self . store . get_account ( address) ?;
71
- self . immutable_cache . insert ( address, account. clone ( ) ) ;
72
+ self . initial_accounts_state . insert ( address, account. clone ( ) ) ;
72
73
Ok ( account)
73
74
}
74
75
75
- /// Gets storage slot from Database, storing in Immutable Cache for efficiency when getting AccountUpdates.
76
+ /// Gets storage slot from Database, storing in initial_accounts_state for efficiency when getting AccountUpdates.
76
77
pub fn get_value_from_database (
77
78
& mut self ,
78
79
address : Address ,
79
80
key : H256 ,
80
81
) -> Result < U256 , InternalError > {
81
82
let value = self . store . get_storage_value ( address, key) ?;
82
- // Account must already be in immutable_cache
83
- match self . immutable_cache . get_mut ( & address) {
83
+ // Account must already be in initial_accounts_state
84
+ match self . initial_accounts_state . get_mut ( & address) {
84
85
Some ( account) => {
85
86
account. storage . insert ( key, value) ;
86
87
}
@@ -133,15 +134,15 @@ impl<'a> VM<'a> {
133
134
134
135
*/
135
136
pub fn get_account_mut ( & mut self , address : Address ) -> Result < & mut Account , InternalError > {
136
- if cache:: is_account_cached ( & self . db . cache , & address) {
137
+ if cache:: is_account_cached ( & self . db . current_accounts_state , & address) {
137
138
self . backup_account_info ( address) ?;
138
- cache:: get_account_mut ( & mut self . db . cache , & address)
139
+ cache:: get_account_mut ( & mut self . db . current_accounts_state , & address)
139
140
. ok_or ( InternalError :: AccountNotFound )
140
141
} else {
141
142
let acc = self . db . get_account_from_database ( address) ?;
142
- cache:: insert_account ( & mut self . db . cache , address, acc) ;
143
+ cache:: insert_account ( & mut self . db . current_accounts_state , address, acc) ;
143
144
self . backup_account_info ( address) ?;
144
- cache:: get_account_mut ( & mut self . db . cache , & address)
145
+ cache:: get_account_mut ( & mut self . db . current_accounts_state , & address)
145
146
. ok_or ( InternalError :: AccountNotFound )
146
147
}
147
148
}
@@ -214,7 +215,7 @@ impl<'a> VM<'a> {
214
215
account : Account ,
215
216
) -> Result < ( ) , InternalError > {
216
217
self . backup_account_info ( address) ?;
217
- let _ = cache:: insert_account ( & mut self . db . cache , address, account) ;
218
+ let _ = cache:: insert_account ( & mut self . db . current_accounts_state , address, account) ;
218
219
219
220
Ok ( ( ) )
220
221
}
@@ -226,19 +227,12 @@ impl<'a> VM<'a> {
226
227
address : Address ,
227
228
key : H256 ,
228
229
) -> Result < U256 , InternalError > {
229
- if let Some ( value) = self
230
- . storage_original_values
231
- . get ( & address)
232
- . and_then ( |account_storage| account_storage. get ( & key) )
233
- {
230
+ if let Some ( value) = self . storage_original_values . get ( & ( address, key) ) {
234
231
return Ok ( * value) ;
235
232
}
236
233
237
234
let value = self . get_storage_value ( address, key) ?;
238
- self . storage_original_values
239
- . entry ( address)
240
- . or_default ( )
241
- . insert ( key, value) ;
235
+ self . storage_original_values . insert ( ( address, key) , value) ;
242
236
Ok ( value)
243
237
}
244
238
@@ -270,7 +264,7 @@ impl<'a> VM<'a> {
270
264
address : Address ,
271
265
key : H256 ,
272
266
) -> Result < U256 , InternalError > {
273
- if let Some ( account) = cache:: get_account ( & self . db . cache , & address) {
267
+ if let Some ( account) = cache:: get_account ( & self . db . current_accounts_state , & address) {
274
268
if let Some ( value) = account. storage . get ( & key) {
275
269
return Ok ( * value) ;
276
270
}
@@ -333,7 +327,7 @@ impl<'a> VM<'a> {
333
327
. contains_key ( & address) ;
334
328
335
329
if is_not_backed_up {
336
- let account = cache:: get_account ( & self . db . cache , & address)
330
+ let account = cache:: get_account ( & self . db . current_accounts_state , & address)
337
331
. ok_or ( InternalError :: AccountNotFound ) ?;
338
332
let info = account. info . clone ( ) ;
339
333
let code = account. code . clone ( ) ;
0 commit comments