Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Multi-dag LRU caching in Light, support per-instance caches#81

Merged
obscuren merged 1 commit intoethereum:masterfrom
karalabe:perinstance-vefitication-cache
Feb 24, 2016
Merged

Multi-dag LRU caching in Light, support per-instance caches#81
obscuren merged 1 commit intoethereum:masterfrom
karalabe:perinstance-vefitication-cache

Conversation

@karalabe
Copy link
Copy Markdown
Member

Ethash in its current state contains two issues, the combination of which makes epoch transitions very expensive:

  • A single verification DAG cache is used ever, always being replaced whenever a different epoch is requested. This is problematic during epoch transitions since the block is in the new epoch while the uncle is in the old. Similarly this causes trouble when processing blocks in parallel, since they trash the cache.
  • A single global light DAG was shared between all instances of Ethash. This was done to allow reusing underlying caches between test runs. Although this is beneficial in some scenarios, it will cause trouble later if a process uses 2+ instances of Ethash (e.g. connected simultaneously to main net and test net), as it will introduce the same cache trashing.

This PR fixes both of these scenarios, while maintaining the existing feature set:

  • The Light structure was expanded with a simple LRU cache implementation, that accumulates a maximum of 3 verification DAGs before starting to evict old ones (least recently retrieved). Although during normal operation 2 DAGs should suffice, the reason the 3rd one was inserted is to avoid cache trashing when older blocks also circulate the network.
  • Regarding the shared light structure: during normal mode of operation the user would expect Ethash instances to be independent of each other, so the plain ethash.New method was fixed to use its own Light struct. However, to keep the ability to reuse caches during tests, I've added a NewShared method to ethash, which is essentially the old New, reusing the same shared Light cache.

@karalabe karalabe changed the title Don't share verification cache (thrashes the cache during epoch switch) Multi-dag LRU caching in Light, support per-instance caches Feb 24, 2016
Comment thread ethash.go Outdated
// TODO: keep multiple caches.
test bool // if set use a smaller cache size
mu sync.Mutex // protects the per-epoch map of DAGs
dags map[uint64]*cache // currently cached verification DAGs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to "caches"? Ethash terminology distinguishes cache (for verification) and DAG (for mining).

@karalabe
Copy link
Copy Markdown
Member Author

@fjl PTAL

@fjl
Copy link
Copy Markdown
Contributor

fjl commented Feb 24, 2016

👍

@obscuren
Copy link
Copy Markdown
Contributor

👍

obscuren added a commit that referenced this pull request Feb 24, 2016
Multi-dag LRU caching in Light, support per-instance caches
@obscuren obscuren merged commit a524c9f into ethereum:master Feb 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants