Module sp_trie::cache

source ·
Expand description

Trie Cache

Provides an implementation of the TrieCache trait. The implementation is split into three types SharedTrieCache, LocalTrieCache and TrieCache. The SharedTrieCache is the instance that should be kept around for the entire lifetime of the node. It will store all cached trie nodes and values on a global level. Then there is the LocalTrieCache that should be kept around per state instance requested from the backend. As there are very likely multiple accesses to the state per instance, this LocalTrieCache is used to cache the nodes and the values before they are merged back to the shared instance. Last but not least there is the TrieCache that is being used per access to the state. It will use the SharedTrieCache and the LocalTrieCache to fulfill cache requests. If both of them don’t provide the requested data it will be inserted into the LocalTrieCache and then later into the SharedTrieCache.

The SharedTrieCache is bound to some maximum number of bytes. It is ensured that it never runs above this limit. However as long as data is cached inside a LocalTrieCache it isn’t taken into account when limiting the SharedTrieCache. This means that for the lifetime of a LocalTrieCache the actual memory usage could be above the allowed maximum.

Structs

The size of the shared cache.
A limiter for the local node cache. This makes sure the local cache doesn’t grow too big.
The local trie cache.
A limiter for the local value cache. This makes sure the local cache doesn’t grow too big.
The shared trie cache.
The actual TrieCache implementation.