snapshot.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. // Copyright 2019 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. // Package snapshot implements a journalled, dynamic state dump.
  17. package snapshot
  18. import (
  19. "bytes"
  20. "errors"
  21. "fmt"
  22. "io"
  23. "sync"
  24. "github.com/ethereum/go-ethereum/common"
  25. "github.com/ethereum/go-ethereum/core/rawdb"
  26. "github.com/ethereum/go-ethereum/ethdb"
  27. "github.com/ethereum/go-ethereum/log"
  28. "github.com/ethereum/go-ethereum/metrics"
  29. "github.com/ethereum/go-ethereum/trie"
  30. )
  31. var (
  32. snapshotCleanAccountHitMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/hit", nil)
  33. snapshotCleanAccountMissMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/miss", nil)
  34. snapshotCleanAccountReadMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/read", nil)
  35. snapshotCleanAccountWriteMeter = metrics.NewRegisteredMeter("state/snapshot/clean/account/write", nil)
  36. snapshotCleanStorageHitMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/hit", nil)
  37. snapshotCleanStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/miss", nil)
  38. snapshotCleanStorageReadMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/read", nil)
  39. snapshotCleanStorageWriteMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/write", nil)
  40. snapshotDirtyAccountHitMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/hit", nil)
  41. snapshotDirtyAccountMissMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/miss", nil)
  42. snapshotDirtyAccountReadMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/read", nil)
  43. snapshotDirtyAccountWriteMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/account/write", nil)
  44. snapshotDirtyStorageHitMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/hit", nil)
  45. snapshotDirtyStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/miss", nil)
  46. snapshotDirtyStorageReadMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/read", nil)
  47. snapshotDirtyStorageWriteMeter = metrics.NewRegisteredMeter("state/snapshot/dirty/storage/write", nil)
  48. snapshotFlushAccountItemMeter = metrics.NewRegisteredMeter("state/snapshot/flush/account/item", nil)
  49. snapshotFlushAccountSizeMeter = metrics.NewRegisteredMeter("state/snapshot/flush/account/size", nil)
  50. snapshotFlushStorageItemMeter = metrics.NewRegisteredMeter("state/snapshot/flush/storage/item", nil)
  51. snapshotFlushStorageSizeMeter = metrics.NewRegisteredMeter("state/snapshot/flush/storage/size", nil)
  52. snapshotBloomIndexTimer = metrics.NewRegisteredResettingTimer("state/snapshot/bloom/index", nil)
  53. snapshotBloomErrorGauge = metrics.NewRegisteredGaugeFloat64("state/snapshot/bloom/error", nil)
  54. snapshotBloomAccountTrueHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/account/truehit", nil)
  55. snapshotBloomAccountFalseHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/account/falsehit", nil)
  56. snapshotBloomAccountMissMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/account/miss", nil)
  57. snapshotBloomStorageTrueHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/truehit", nil)
  58. snapshotBloomStorageFalseHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/falsehit", nil)
  59. snapshotBloomStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/miss", nil)
  60. // ErrSnapshotStale is returned from data accessors if the underlying snapshot
  61. // layer had been invalidated due to the chain progressing forward far enough
  62. // to not maintain the layer's original state.
  63. ErrSnapshotStale = errors.New("snapshot stale")
  64. // ErrNotCoveredYet is returned from data accessors if the underlying snapshot
  65. // is being generated currently and the requested data item is not yet in the
  66. // range of accounts covered.
  67. ErrNotCoveredYet = errors.New("not covered yet")
  68. // errSnapshotCycle is returned if a snapshot is attempted to be inserted
  69. // that forms a cycle in the snapshot tree.
  70. errSnapshotCycle = errors.New("snapshot cycle")
  71. )
  72. // Snapshot represents the functionality supported by a snapshot storage layer.
  73. type Snapshot interface {
  74. // Root returns the root hash for which this snapshot was made.
  75. Root() common.Hash
  76. // Account directly retrieves the account associated with a particular hash in
  77. // the snapshot slim data format.
  78. Account(hash common.Hash) (*Account, error)
  79. // AccountRLP directly retrieves the account RLP associated with a particular
  80. // hash in the snapshot slim data format.
  81. AccountRLP(hash common.Hash) ([]byte, error)
  82. // Storage directly retrieves the storage data associated with a particular hash,
  83. // within a particular account.
  84. Storage(accountHash, storageHash common.Hash) ([]byte, error)
  85. }
  86. // snapshot is the internal version of the snapshot data layer that supports some
  87. // additional methods compared to the public API.
  88. type snapshot interface {
  89. Snapshot
  90. // Update creates a new layer on top of the existing snapshot diff tree with
  91. // the specified data items. Note, the maps are retained by the method to avoid
  92. // copying everything.
  93. Update(blockRoot common.Hash, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte) *diffLayer
  94. // Journal commits an entire diff hierarchy to disk into a single journal file.
  95. // This is meant to be used during shutdown to persist the snapshot without
  96. // flattening everything down (bad for reorgs).
  97. Journal(path string) (io.WriteCloser, common.Hash, error)
  98. // Stale return whether this layer has become stale (was flattened across) or
  99. // if it's still live.
  100. Stale() bool
  101. }
  102. // SnapshotTree is an Ethereum state snapshot tree. It consists of one persistent
  103. // base layer backed by a key-value store, on top of which arbitrarily many in-
  104. // memory diff layers are topped. The memory diffs can form a tree with branching,
  105. // but the disk layer is singleton and common to all. If a reorg goes deeper than
  106. // the disk layer, everything needs to be deleted.
  107. //
  108. // The goal of a state snapshot is twofold: to allow direct access to account and
  109. // storage data to avoid expensive multi-level trie lookups; and to allow sorted,
  110. // cheap iteration of the account/storage tries for sync aid.
  111. type Tree struct {
  112. diskdb ethdb.KeyValueStore // Persistent database to store the snapshot
  113. triedb *trie.Database // In-memory cache to access the trie through
  114. cache int // Megabytes permitted to use for read caches
  115. layers map[common.Hash]snapshot // Collection of all known layers
  116. lock sync.RWMutex
  117. }
  118. // New attempts to load an already existing snapshot from a persistent key-value
  119. // store (with a number of memory layers from a journal), ensuring that the head
  120. // of the snapshot matches the expected one.
  121. //
  122. // If the snapshot is missing or inconsistent, the entirety is deleted and will
  123. // be reconstructed from scratch based on the tries in the key-value store, on a
  124. // background thread.
  125. func New(diskdb ethdb.KeyValueStore, triedb *trie.Database, journal string, cache int, root common.Hash) *Tree {
  126. // Create a new, empty snapshot tree
  127. snap := &Tree{
  128. diskdb: diskdb,
  129. triedb: triedb,
  130. cache: cache,
  131. layers: make(map[common.Hash]snapshot),
  132. }
  133. // Attempt to load a previously persisted snapshot and rebuild one if failed
  134. head, err := loadSnapshot(diskdb, triedb, journal, cache, root)
  135. if err != nil {
  136. log.Warn("Failed to load snapshot, regenerating", "err", err)
  137. snap.Rebuild(root)
  138. return snap
  139. }
  140. // Existing snapshot loaded, seed all the layers
  141. for head != nil {
  142. snap.layers[head.Root()] = head
  143. switch self := head.(type) {
  144. case *diffLayer:
  145. head = self.parent
  146. case *diskLayer:
  147. head = nil
  148. default:
  149. panic(fmt.Sprintf("unknown data layer: %T", self))
  150. }
  151. }
  152. return snap
  153. }
  154. // Snapshot retrieves a snapshot belonging to the given block root, or nil if no
  155. // snapshot is maintained for that block.
  156. func (t *Tree) Snapshot(blockRoot common.Hash) Snapshot {
  157. t.lock.RLock()
  158. defer t.lock.RUnlock()
  159. return t.layers[blockRoot]
  160. }
  161. // Update adds a new snapshot into the tree, if that can be linked to an existing
  162. // old parent. It is disallowed to insert a disk layer (the origin of all).
  163. func (t *Tree) Update(blockRoot common.Hash, parentRoot common.Hash, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte) error {
  164. // Reject noop updates to avoid self-loops in the snapshot tree. This is a
  165. // special case that can only happen for Clique networks where empty blocks
  166. // don't modify the state (0 block subsidy).
  167. //
  168. // Although we could silently ignore this internally, it should be the caller's
  169. // responsibility to avoid even attempting to insert such a snapshot.
  170. if blockRoot == parentRoot {
  171. return errSnapshotCycle
  172. }
  173. // Generate a new snapshot on top of the parent
  174. parent := t.Snapshot(parentRoot).(snapshot)
  175. if parent == nil {
  176. return fmt.Errorf("parent [%#x] snapshot missing", parentRoot)
  177. }
  178. snap := parent.Update(blockRoot, accounts, storage)
  179. // Save the new snapshot for later
  180. t.lock.Lock()
  181. defer t.lock.Unlock()
  182. t.layers[snap.root] = snap
  183. return nil
  184. }
  185. // Cap traverses downwards the snapshot tree from a head block hash until the
  186. // number of allowed layers are crossed. All layers beyond the permitted number
  187. // are flattened downwards.
  188. func (t *Tree) Cap(root common.Hash, layers int) error {
  189. // Retrieve the head snapshot to cap from
  190. snap := t.Snapshot(root)
  191. if snap == nil {
  192. return fmt.Errorf("snapshot [%#x] missing", root)
  193. }
  194. diff, ok := snap.(*diffLayer)
  195. if !ok {
  196. return fmt.Errorf("snapshot [%#x] is disk layer", root)
  197. }
  198. // Run the internal capping and discard all stale layers
  199. t.lock.Lock()
  200. defer t.lock.Unlock()
  201. // Flattening the bottom-most diff layer requires special casing since there's
  202. // no child to rewire to the grandparent. In that case we can fake a temporary
  203. // child for the capping and then remove it.
  204. var persisted *diskLayer
  205. switch layers {
  206. case 0:
  207. // If full commit was requested, flatten the diffs and merge onto disk
  208. diff.lock.RLock()
  209. base := diffToDisk(diff.flatten().(*diffLayer))
  210. diff.lock.RUnlock()
  211. // Replace the entire snapshot tree with the flat base
  212. t.layers = map[common.Hash]snapshot{base.root: base}
  213. return nil
  214. case 1:
  215. // If full flattening was requested, flatten the diffs but only merge if the
  216. // memory limit was reached
  217. var (
  218. bottom *diffLayer
  219. base *diskLayer
  220. )
  221. diff.lock.RLock()
  222. bottom = diff.flatten().(*diffLayer)
  223. if bottom.memory >= aggregatorMemoryLimit {
  224. base = diffToDisk(bottom)
  225. }
  226. diff.lock.RUnlock()
  227. // If all diff layers were removed, replace the entire snapshot tree
  228. if base != nil {
  229. t.layers = map[common.Hash]snapshot{base.root: base}
  230. return nil
  231. }
  232. // Merge the new aggregated layer into the snapshot tree, clean stales below
  233. t.layers[bottom.root] = bottom
  234. default:
  235. // Many layers requested to be retained, cap normally
  236. persisted = t.cap(diff, layers)
  237. }
  238. // Remove any layer that is stale or links into a stale layer
  239. children := make(map[common.Hash][]common.Hash)
  240. for root, snap := range t.layers {
  241. if diff, ok := snap.(*diffLayer); ok {
  242. parent := diff.parent.Root()
  243. children[parent] = append(children[parent], root)
  244. }
  245. }
  246. var remove func(root common.Hash)
  247. remove = func(root common.Hash) {
  248. delete(t.layers, root)
  249. for _, child := range children[root] {
  250. remove(child)
  251. }
  252. delete(children, root)
  253. }
  254. for root, snap := range t.layers {
  255. if snap.Stale() {
  256. remove(root)
  257. }
  258. }
  259. // If the disk layer was modified, regenerate all the cummulative blooms
  260. if persisted != nil {
  261. var rebloom func(root common.Hash)
  262. rebloom = func(root common.Hash) {
  263. if diff, ok := t.layers[root].(*diffLayer); ok {
  264. diff.rebloom(persisted)
  265. }
  266. for _, child := range children[root] {
  267. rebloom(child)
  268. }
  269. }
  270. rebloom(persisted.root)
  271. }
  272. return nil
  273. }
  274. // cap traverses downwards the diff tree until the number of allowed layers are
  275. // crossed. All diffs beyond the permitted number are flattened downwards. If the
  276. // layer limit is reached, memory cap is also enforced (but not before).
  277. //
  278. // The method returns the new disk layer if diffs were persistend into it.
  279. func (t *Tree) cap(diff *diffLayer, layers int) *diskLayer {
  280. // Dive until we run out of layers or reach the persistent database
  281. for ; layers > 2; layers-- {
  282. // If we still have diff layers below, continue down
  283. if parent, ok := diff.parent.(*diffLayer); ok {
  284. diff = parent
  285. } else {
  286. // Diff stack too shallow, return without modifications
  287. return nil
  288. }
  289. }
  290. // We're out of layers, flatten anything below, stopping if it's the disk or if
  291. // the memory limit is not yet exceeded.
  292. switch parent := diff.parent.(type) {
  293. case *diskLayer:
  294. return nil
  295. case *diffLayer:
  296. // Flatten the parent into the grandparent. The flattening internally obtains a
  297. // write lock on grandparent.
  298. flattened := parent.flatten().(*diffLayer)
  299. t.layers[flattened.root] = flattened
  300. diff.lock.Lock()
  301. defer diff.lock.Unlock()
  302. diff.parent = flattened
  303. if flattened.memory < aggregatorMemoryLimit {
  304. // Accumulator layer is smaller than the limit, so we can abort, unless
  305. // there's a snapshot being generated currently. In that case, the trie
  306. // will move fron underneath the generator so we **must** merge all the
  307. // partial data down into the snapshot and restart the generation.
  308. if flattened.parent.(*diskLayer).genAbort == nil {
  309. return nil
  310. }
  311. }
  312. default:
  313. panic(fmt.Sprintf("unknown data layer: %T", parent))
  314. }
  315. // If the bottom-most layer is larger than our memory cap, persist to disk
  316. bottom := diff.parent.(*diffLayer)
  317. bottom.lock.RLock()
  318. base := diffToDisk(bottom)
  319. bottom.lock.RUnlock()
  320. t.layers[base.root] = base
  321. diff.parent = base
  322. return base
  323. }
  324. // diffToDisk merges a bottom-most diff into the persistent disk layer underneath
  325. // it. The method will panic if called onto a non-bottom-most diff layer.
  326. func diffToDisk(bottom *diffLayer) *diskLayer {
  327. var (
  328. base = bottom.parent.(*diskLayer)
  329. batch = base.diskdb.NewBatch()
  330. stats *generatorStats
  331. )
  332. // If the disk layer is running a snapshot generator, abort it
  333. if base.genAbort != nil {
  334. abort := make(chan *generatorStats)
  335. base.genAbort <- abort
  336. stats = <-abort
  337. }
  338. // Start by temporarily deleting the current snapshot block marker. This
  339. // ensures that in the case of a crash, the entire snapshot is invalidated.
  340. rawdb.DeleteSnapshotRoot(batch)
  341. // Mark the original base as stale as we're going to create a new wrapper
  342. base.lock.Lock()
  343. if base.stale {
  344. panic("parent disk layer is stale") // we've committed into the same base from two children, boo
  345. }
  346. base.stale = true
  347. base.lock.Unlock()
  348. // Push all the accounts into the database
  349. for hash, data := range bottom.accountData {
  350. // Skip any account not covered yet by the snapshot
  351. if base.genMarker != nil && bytes.Compare(hash[:], base.genMarker) > 0 {
  352. continue
  353. }
  354. if len(data) > 0 {
  355. // Account was updated, push to disk
  356. rawdb.WriteAccountSnapshot(batch, hash, data)
  357. base.cache.Set(hash[:], data)
  358. if batch.ValueSize() > ethdb.IdealBatchSize {
  359. if err := batch.Write(); err != nil {
  360. log.Crit("Failed to write account snapshot", "err", err)
  361. }
  362. batch.Reset()
  363. }
  364. } else {
  365. // Account was deleted, remove all storage slots too
  366. rawdb.DeleteAccountSnapshot(batch, hash)
  367. base.cache.Set(hash[:], nil)
  368. it := rawdb.IterateStorageSnapshots(base.diskdb, hash)
  369. for it.Next() {
  370. if key := it.Key(); len(key) == 65 { // TODO(karalabe): Yuck, we should move this into the iterator
  371. batch.Delete(key)
  372. base.cache.Del(key[1:])
  373. snapshotFlushStorageItemMeter.Mark(1)
  374. snapshotFlushStorageSizeMeter.Mark(int64(len(data)))
  375. }
  376. }
  377. it.Release()
  378. }
  379. snapshotFlushAccountItemMeter.Mark(1)
  380. snapshotFlushAccountSizeMeter.Mark(int64(len(data)))
  381. }
  382. // Push all the storage slots into the database
  383. for accountHash, storage := range bottom.storageData {
  384. // Skip any account not covered yet by the snapshot
  385. if base.genMarker != nil && bytes.Compare(accountHash[:], base.genMarker) > 0 {
  386. continue
  387. }
  388. // Generation might be mid-account, track that case too
  389. midAccount := base.genMarker != nil && bytes.Equal(accountHash[:], base.genMarker[:common.HashLength])
  390. for storageHash, data := range storage {
  391. // Skip any slot not covered yet by the snapshot
  392. if midAccount && bytes.Compare(storageHash[:], base.genMarker[common.HashLength:]) > 0 {
  393. continue
  394. }
  395. if len(data) > 0 {
  396. rawdb.WriteStorageSnapshot(batch, accountHash, storageHash, data)
  397. base.cache.Set(append(accountHash[:], storageHash[:]...), data)
  398. } else {
  399. rawdb.DeleteStorageSnapshot(batch, accountHash, storageHash)
  400. base.cache.Set(append(accountHash[:], storageHash[:]...), nil)
  401. }
  402. snapshotFlushStorageItemMeter.Mark(1)
  403. snapshotFlushStorageSizeMeter.Mark(int64(len(data)))
  404. }
  405. if batch.ValueSize() > ethdb.IdealBatchSize {
  406. if err := batch.Write(); err != nil {
  407. log.Crit("Failed to write storage snapshot", "err", err)
  408. }
  409. batch.Reset()
  410. }
  411. }
  412. // Update the snapshot block marker and write any remainder data
  413. rawdb.WriteSnapshotRoot(batch, bottom.root)
  414. if err := batch.Write(); err != nil {
  415. log.Crit("Failed to write leftover snapshot", "err", err)
  416. }
  417. res := &diskLayer{
  418. root: bottom.root,
  419. cache: base.cache,
  420. diskdb: base.diskdb,
  421. triedb: base.triedb,
  422. genMarker: base.genMarker,
  423. }
  424. // If snapshot generation hasn't finished yet, port over all the starts and
  425. // continue where the previous round left off.
  426. //
  427. // Note, the `base.genAbort` comparison is not used normally, it's checked
  428. // to allow the tests to play with the marker without triggering this path.
  429. if base.genMarker != nil && base.genAbort != nil {
  430. res.genMarker = base.genMarker
  431. res.genAbort = make(chan chan *generatorStats)
  432. go res.generate(stats)
  433. }
  434. return res
  435. }
  436. // Journal commits an entire diff hierarchy to disk into a single journal file.
  437. // This is meant to be used during shutdown to persist the snapshot without
  438. // flattening everything down (bad for reorgs).
  439. //
  440. // The method returns the root hash of the base layer that needs to be persisted
  441. // to disk as a trie too to allow continuing any pending generation op.
  442. func (t *Tree) Journal(root common.Hash, path string) (common.Hash, error) {
  443. // Retrieve the head snapshot to journal from var snap snapshot
  444. snap := t.Snapshot(root)
  445. if snap == nil {
  446. return common.Hash{}, fmt.Errorf("snapshot [%#x] missing", root)
  447. }
  448. // Run the journaling
  449. t.lock.Lock()
  450. defer t.lock.Unlock()
  451. writer, base, err := snap.(snapshot).Journal(path)
  452. if err != nil {
  453. return common.Hash{}, err
  454. }
  455. return base, writer.Close()
  456. }
  457. // Rebuild wipes all available snapshot data from the persistent database and
  458. // discard all caches and diff layers. Afterwards, it starts a new snapshot
  459. // generator with the given root hash.
  460. func (t *Tree) Rebuild(root common.Hash) {
  461. t.lock.Lock()
  462. defer t.lock.Unlock()
  463. // Track whether there's a wipe currently running and keep it alive if so
  464. var wiper chan struct{}
  465. // Iterate over and mark all layers stale
  466. for _, layer := range t.layers {
  467. switch layer := layer.(type) {
  468. case *diskLayer:
  469. // If the base layer is generating, abort it and save
  470. if layer.genAbort != nil {
  471. abort := make(chan *generatorStats)
  472. layer.genAbort <- abort
  473. if stats := <-abort; stats != nil {
  474. wiper = stats.wiping
  475. }
  476. }
  477. // Layer should be inactive now, mark it as stale
  478. layer.lock.Lock()
  479. layer.stale = true
  480. layer.lock.Unlock()
  481. case *diffLayer:
  482. // If the layer is a simple diff, simply mark as stale
  483. layer.lock.Lock()
  484. layer.stale = true
  485. layer.lock.Unlock()
  486. default:
  487. panic(fmt.Sprintf("unknown layer type: %T", layer))
  488. }
  489. }
  490. // Start generating a new snapshot from scratch on a backgroung thread. The
  491. // generator will run a wiper first if there's not one running right now.
  492. log.Info("Rebuilding state snapshot")
  493. t.layers = map[common.Hash]snapshot{
  494. root: generateSnapshot(t.diskdb, t.triedb, t.cache, root, wiper),
  495. }
  496. }