go-ethereum/triedb/pathdb
rjl493456442 bc1ec69008
trie/pathdb: state iterator (snapshot integration pt 4) (#30654)
In this pull request, the state iterator is implemented. It's mostly a copy-paste
from the original state snapshot package, but still has some important changes
to highlight here:

(a) The iterator for the disk layer consists of a diff iterator and a disk iterator.

Originally, the disk layer in the state snapshot was a wrapper around the disk, 
and its corresponding iterator was also a wrapper around the disk iterator.
However, due to structural differences, the disk layer iterator is divided into
two parts:

- The disk iterator, which traverses the content stored on disk.
- The diff iterator, which traverses the aggregated state buffer.

Checkout `BinaryIterator` and `FastIterator` for more details.

(b) The staleness management is improved in the diffAccountIterator and
diffStorageIterator

Originally, in the `diffAccountIterator`, the layer’s staleness had to be checked 
within the Next function to ensure the iterator remained usable. Additionally, 
a read lock on the associated diff layer was required to first retrieve the account 
blob. This read lock protection is essential to prevent concurrent map read/write. 
Afterward, a staleness check was performed to ensure the retrieved data was 
not outdated.

The entire logic can be simplified as follows: a loadAccount callback is provided 
to retrieve account data. If the corresponding state is immutable (e.g., diff layers
in the path database), the staleness check can be skipped, and a single account 
data retrieval is sufficient. However, if the corresponding state is mutable (e.g., 
the disk layer in the path database), the callback can operate as follows:

```go
func(hash common.Hash) ([]byte, error) {
    dl.lock.RLock()
    defer dl.lock.RUnlock()

    if dl.stale {
        return nil, errSnapshotStale
    }
    return dl.buffer.states.mustAccount(hash)
}
```

The callback solution can eliminate the complexity for managing
concurrency with the read lock for atomic operation.
2024-12-16 21:10:08 +08:00
..
buffer.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
database.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
database_test.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
difflayer.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
difflayer_test.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
disklayer.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
errors.go all: remove duplicate word in comments (#29531) 2024-04-15 08:34:31 +02:00
execute.go core, trie, triedb: minor changes from snapshot integration (#30599) 2024-10-18 17:06:31 +02:00
flush.go core, trie, triedb: minor changes from snapshot integration (#30599) 2024-10-18 17:06:31 +02:00
history.go core, trie, triedb: minor changes from snapshot integration (#30599) 2024-10-18 17:06:31 +02:00
history_inspect.go core/rawdb: implement in-memory freezer (#29135) 2024-04-30 11:33:22 +02:00
history_test.go core, trie, triedb: minor changes from snapshot integration (#30599) 2024-10-18 17:06:31 +02:00
holdable_iterator.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
holdable_iterator_test.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
iterator.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
iterator_binary.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
iterator_fast.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
iterator_test.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
journal.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
layertree.go core, trie, triedb: minor changes from snapshot integration (#30599) 2024-10-18 17:06:31 +02:00
metrics.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
nodes.go triedb/pathdb: track flat state changes in pathdb (snapshot integration pt 2) (#30643) 2024-11-29 19:30:45 +08:00
reader.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
states.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00
states_test.go trie/pathdb: state iterator (snapshot integration pt 4) (#30654) 2024-12-16 21:10:08 +08:00