@@ -76,30 +76,28 @@ func (dl *diskLayer) Stale() bool {
76
76
77
77
// Account directly retrieves the account associated with a particular hash in
78
78
// the snapshot slim data format.
79
- func (dl * diskLayer ) Account (hash common.Hash ) (* types.SlimAccount , error ) {
80
- data , err := dl .AccountRLP (hash )
79
+ func (dl * diskLayer ) account (hash common.Hash , evenIfStale bool ) (* types.SlimAccount , error ) {
80
+ data , err := dl .accountRLP (hash , evenIfStale )
81
81
if err != nil {
82
82
return nil , err
83
83
}
84
84
if len (data ) == 0 { // can be both nil and []byte{}
85
85
return nil , nil
86
86
}
87
87
account := new (types.SlimAccount )
88
- if err := rlp .DecodeBytes (data , account ); err != nil {
89
- panic (err )
90
- }
91
- return account , nil
88
+ err = rlp .DecodeBytes (data , account )
89
+ return account , err
92
90
}
93
91
94
92
// AccountRLP directly retrieves the account RLP associated with a particular
95
93
// hash in the snapshot slim data format.
96
- func (dl * diskLayer ) AccountRLP (hash common.Hash ) ([]byte , error ) {
94
+ func (dl * diskLayer ) accountRLP (hash common.Hash , evenIfStale bool ) ([]byte , error ) {
97
95
dl .lock .RLock ()
98
96
defer dl .lock .RUnlock ()
99
97
100
98
// If the layer was flattened into, consider it invalid (any live reference to
101
99
// the original should be marked as unusable).
102
- if dl .stale {
100
+ if dl .stale && ! evenIfStale {
103
101
return nil , ErrSnapshotStale
104
102
}
105
103
// If the layer is being generated, ensure the requested hash has already been
@@ -121,7 +119,9 @@ func (dl *diskLayer) AccountRLP(hash common.Hash) ([]byte, error) {
121
119
if err != nil {
122
120
return nil , err
123
121
}
124
- dl .cache .Set (hash [:], blob )
122
+ if ! dl .stale {
123
+ dl .cache .Set (hash [:], blob )
124
+ }
125
125
126
126
snapshotCleanAccountMissMeter .Mark (1 )
127
127
if n := len (blob ); n > 0 {
@@ -132,6 +132,14 @@ func (dl *diskLayer) AccountRLP(hash common.Hash) ([]byte, error) {
132
132
return blob , nil
133
133
}
134
134
135
+ func (dl * diskLayer ) Account (hash common.Hash ) (* types.SlimAccount , error ) {
136
+ return dl .account (hash , false )
137
+ }
138
+
139
+ func (dl * diskLayer ) AccountRLP (hash common.Hash ) ([]byte , error ) {
140
+ return dl .accountRLP (hash , false )
141
+ }
142
+
135
143
// Storage directly retrieves the storage data associated with a particular hash,
136
144
// within a particular account.
137
145
func (dl * diskLayer ) Storage (accountHash , storageHash common.Hash ) ([]byte , error ) {
0 commit comments