core/state: lazy sorting, snapshot invalidation
This commit is contained in:
committed by
Péter Szilágyi
parent
542df8898e
commit
e146fbe4e7
@ -38,6 +38,11 @@ var (
|
||||
snapshotCleanMissMeter = metrics.NewRegisteredMeter("state/snapshot/clean/miss", nil)
|
||||
snapshotCleanReadMeter = metrics.NewRegisteredMeter("state/snapshot/clean/read", nil)
|
||||
snapshotCleanWriteMeter = metrics.NewRegisteredMeter("state/snapshot/clean/write", nil)
|
||||
|
||||
// ErrSnapshotStale is returned from data accessors if the underlying snapshot
|
||||
// layer had been invalidated due to the chain progressing forward far enough
|
||||
// to not maintain the layer's original state.
|
||||
ErrSnapshotStale = errors.New("snapshot stale")
|
||||
)
|
||||
|
||||
// Snapshot represents the functionality supported by a snapshot storage layer.
|
||||
@ -47,15 +52,15 @@ type Snapshot interface {
|
||||
|
||||
// Account directly retrieves the account associated with a particular hash in
|
||||
// the snapshot slim data format.
|
||||
Account(hash common.Hash) *Account
|
||||
Account(hash common.Hash) (*Account, error)
|
||||
|
||||
// AccountRLP directly retrieves the account RLP associated with a particular
|
||||
// hash in the snapshot slim data format.
|
||||
AccountRLP(hash common.Hash) []byte
|
||||
AccountRLP(hash common.Hash) ([]byte, error)
|
||||
|
||||
// Storage directly retrieves the storage data associated with a particular hash,
|
||||
// within a particular account.
|
||||
Storage(accountHash, storageHash common.Hash) []byte
|
||||
Storage(accountHash, storageHash common.Hash) ([]byte, error)
|
||||
}
|
||||
|
||||
// snapshot is the internal version of the snapshot data layer that supports some
|
||||
@ -80,7 +85,7 @@ type snapshot interface {
|
||||
}
|
||||
|
||||
// SnapshotTree is an Ethereum state snapshot tree. It consists of one persistent
|
||||
// base layer backed by a key-value store, on top of which arbitrarilly many in-
|
||||
// base layer backed by a key-value store, on top of which arbitrarily many in-
|
||||
// memory diff layers are topped. The memory diffs can form a tree with branching,
|
||||
// but the disk layer is singleton and common to all. If a reorg goes deeper than
|
||||
// the disk layer, everything needs to be deleted.
|
||||
@ -220,7 +225,7 @@ func loadSnapshot(db ethdb.KeyValueStore, journal string, headNumber uint64, hea
|
||||
if _, err := os.Stat(journal); os.IsNotExist(err) {
|
||||
// Journal doesn't exist, don't worry if it's not supposed to
|
||||
if number != headNumber || root != headRoot {
|
||||
return nil, fmt.Errorf("snapshot journal missing, head does't match snapshot: #%d [%#x] vs. #%d [%#x]",
|
||||
return nil, fmt.Errorf("snapshot journal missing, head doesn't match snapshot: #%d [%#x] vs. #%d [%#x]",
|
||||
headNumber, headRoot, number, root)
|
||||
}
|
||||
return base, nil
|
||||
@ -237,7 +242,7 @@ func loadSnapshot(db ethdb.KeyValueStore, journal string, headNumber uint64, hea
|
||||
// Journal doesn't exist, don't worry if it's not supposed to
|
||||
number, root = snapshot.Info()
|
||||
if number != headNumber || root != headRoot {
|
||||
return nil, fmt.Errorf("head does't match snapshot: #%d [%#x] vs. #%d [%#x]",
|
||||
return nil, fmt.Errorf("head doesn't match snapshot: #%d [%#x] vs. #%d [%#x]",
|
||||
headNumber, headRoot, number, root)
|
||||
}
|
||||
return snapshot, nil
|
||||
|
Reference in New Issue
Block a user