@@ -47,14 +47,16 @@ pub type ApplyResult = Result<ApplyOutcome, Error>;
47
47
/// Account modification state. Used to check if the account was
48
48
/// Modified in between commits and overall.
49
49
enum AccountState {
50
- /// Account was never modified in this state object.
51
- Clean ,
50
+ /// Account was loaded from disk and never modified in this state object.
51
+ CleanFresh ,
52
+ /// Account was loaded from the global cache and never modified.
53
+ CleanCached ,
52
54
/// Account has been modified and is not committed to the trie yet.
53
- /// This is set than any of the account data is changed, including
55
+ /// This is set if any of the account data is changed, including
54
56
/// storage and code.
55
57
Dirty ,
56
58
/// Account was modified and committed to the trie.
57
- Commited ,
59
+ Committed ,
58
60
}
59
61
60
62
#[ derive( Debug ) ]
@@ -105,7 +107,15 @@ impl AccountEntry {
105
107
fn new_clean ( account : Option < Account > ) -> AccountEntry {
106
108
AccountEntry {
107
109
account : account,
108
- state : AccountState :: Clean ,
110
+ state : AccountState :: CleanFresh ,
111
+ }
112
+ }
113
+
114
+ // Create a new account entry and mark it as clean and cached.
115
+ fn new_clean_cached ( account : Option < Account > ) -> AccountEntry {
116
+ AccountEntry {
117
+ account : account,
118
+ state : AccountState :: CleanCached ,
109
119
}
110
120
}
111
121
@@ -508,7 +518,7 @@ impl State {
508
518
{
509
519
let mut trie = factories. trie . from_existing ( db. as_hashdb_mut ( ) , root) . unwrap ( ) ;
510
520
for ( address, ref mut a) in accounts. iter_mut ( ) . filter ( |& ( _, ref a) | a. is_dirty ( ) ) {
511
- a. state = AccountState :: Commited ;
521
+ a. state = AccountState :: Committed ;
512
522
match a. account {
513
523
Some ( ref mut account) => {
514
524
try!( trie. insert ( address, & account. rlp ( ) ) ) ;
@@ -526,7 +536,7 @@ impl State {
526
536
fn commit_cache ( & mut self ) {
527
537
let mut addresses = self . cache . borrow_mut ( ) ;
528
538
trace ! ( "Committing cache {:?} entries" , addresses. len( ) ) ;
529
- for ( address, a) in addresses. drain ( ) . filter ( |& ( _, ref a) | !a . is_dirty ( ) ) {
539
+ for ( address, a) in addresses. drain ( ) . filter ( |& ( _, ref a) | a . state == AccountState :: Committed || a . state == AccountState :: CleanFresh ) {
530
540
self . db . cache_account ( address, a. account ) ;
531
541
}
532
542
}
@@ -638,10 +648,7 @@ impl State {
638
648
Self :: update_account_cache ( require, account, accountdb. as_hashdb ( ) ) ;
639
649
}
640
650
let r = f ( maybe_acc. as_ref ( ) ) ;
641
- match maybe_acc {
642
- Some ( account) => self . insert_cache ( a, AccountEntry :: new_clean ( Some ( account) ) ) ,
643
- None => self . insert_cache ( a, AccountEntry :: new_clean ( None ) ) ,
644
- }
651
+ self . insert_cache ( a, AccountEntry :: new_clean ( maybe_acc) ) ;
645
652
r
646
653
}
647
654
}
@@ -660,8 +667,7 @@ impl State {
660
667
let contains_key = self . cache . borrow ( ) . contains_key ( a) ;
661
668
if !contains_key {
662
669
match self . db . get_cached_account ( a) {
663
- Some ( Some ( acc) ) => self . insert_cache ( a, AccountEntry :: new_clean ( Some ( acc) ) ) ,
664
- Some ( None ) => self . insert_cache ( a, AccountEntry :: new_clean ( None ) ) ,
670
+ Some ( acc) => self . insert_cache ( a, AccountEntry :: new_clean_cached ( acc) ) ,
665
671
None => {
666
672
let maybe_acc = if self . db . check_account_bloom ( a) {
667
673
let db = self . factories . trie . readonly ( self . db . as_hashdb ( ) , & self . root ) . expect ( SEC_TRIE_DB_UNWRAP_STR ) ;
0 commit comments