mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
consensus/ethash: use mmap even in test mode
This makes it possible to shorten the time taken for TestCacheFileEvict.
This commit is contained in:
parent
2b9665abbc
commit
15d0c9bcd7
2 changed files with 16 additions and 28 deletions
|
|
@ -181,7 +181,7 @@ func (lru *lru) get(epoch uint64) (item, future interface{}) {
|
||||||
}
|
}
|
||||||
log.Trace("Requiring new ethash "+lru.what, "epoch", epoch)
|
log.Trace("Requiring new ethash "+lru.what, "epoch", epoch)
|
||||||
item = lru.new(epoch)
|
item = lru.new(epoch)
|
||||||
lru.cache.Add(epoch, current)
|
lru.cache.Add(epoch, item)
|
||||||
}
|
}
|
||||||
// Update the 'future item' if epoch is larger than previously seen.
|
// Update the 'future item' if epoch is larger than previously seen.
|
||||||
if epoch < maxEpoch-1 && lru.future < epoch+1 {
|
if epoch < maxEpoch-1 && lru.future < epoch+1 {
|
||||||
|
|
@ -190,7 +190,7 @@ func (lru *lru) get(epoch uint64) (item, future interface{}) {
|
||||||
lru.future = epoch + 1
|
lru.future = epoch + 1
|
||||||
lru.futureItem = future
|
lru.futureItem = future
|
||||||
}
|
}
|
||||||
return current, future
|
return item, future
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache wraps an ethash cache with some metadata to allow easier concurrent use.
|
// cache wraps an ethash cache with some metadata to allow easier concurrent use.
|
||||||
|
|
@ -209,16 +209,12 @@ func newCache(epoch uint64) interface{} {
|
||||||
// generate ensures that the cache content is generated before use.
|
// generate ensures that the cache content is generated before use.
|
||||||
func (c *cache) generate(dir string, limit int, test bool) {
|
func (c *cache) generate(dir string, limit int, test bool) {
|
||||||
c.once.Do(func() {
|
c.once.Do(func() {
|
||||||
// If we have a testing cache, generate and return
|
|
||||||
if test {
|
|
||||||
c.cache = make([]uint32, 1024/4)
|
|
||||||
generateCache(c.cache, c.epoch, seedHash(c.epoch*epochLength+1))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// If we don't store anything on disk, generate and return
|
|
||||||
size := cacheSize(c.epoch*epochLength + 1)
|
size := cacheSize(c.epoch*epochLength + 1)
|
||||||
seed := seedHash(c.epoch*epochLength + 1)
|
seed := seedHash(c.epoch*epochLength + 1)
|
||||||
|
if test {
|
||||||
|
size = 1024
|
||||||
|
}
|
||||||
|
// If we don't store anything on disk, generate and return.
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
c.cache = make([]uint32, size/4)
|
c.cache = make([]uint32, size/4)
|
||||||
generateCache(c.cache, c.epoch, seed)
|
generateCache(c.cache, c.epoch, seed)
|
||||||
|
|
@ -287,21 +283,14 @@ func newDataset(epoch uint64) interface{} {
|
||||||
// generate ensures that the dataset content is generated before use.
|
// generate ensures that the dataset content is generated before use.
|
||||||
func (d *dataset) generate(dir string, limit int, test bool) {
|
func (d *dataset) generate(dir string, limit int, test bool) {
|
||||||
d.once.Do(func() {
|
d.once.Do(func() {
|
||||||
// If we have a testing dataset, generate and return
|
|
||||||
if test {
|
|
||||||
cache := make([]uint32, 1024/4)
|
|
||||||
generateCache(cache, d.epoch, seedHash(d.epoch*epochLength+1))
|
|
||||||
|
|
||||||
d.dataset = make([]uint32, 32*1024/4)
|
|
||||||
generateDataset(d.dataset, d.epoch, cache)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// If we don't store anything on disk, generate and return
|
|
||||||
csize := cacheSize(d.epoch*epochLength + 1)
|
csize := cacheSize(d.epoch*epochLength + 1)
|
||||||
dsize := datasetSize(d.epoch*epochLength + 1)
|
dsize := datasetSize(d.epoch*epochLength + 1)
|
||||||
seed := seedHash(d.epoch*epochLength + 1)
|
seed := seedHash(d.epoch*epochLength + 1)
|
||||||
|
if test {
|
||||||
|
csize = 1024
|
||||||
|
dsize = 32 * 1024
|
||||||
|
}
|
||||||
|
// If we don't store anything on disk, generate and return
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
cache := make([]uint32, csize/4)
|
cache := make([]uint32, csize/4)
|
||||||
generateCache(cache, d.epoch, seed)
|
generateCache(cache, d.epoch, seed)
|
||||||
|
|
|
||||||
|
|
@ -43,19 +43,18 @@ func TestTestMode(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This test checks that cache lru logic doesn't crash under load.
|
||||||
func TestCacheFileEvict(t *testing.T) {
|
func TestCacheFileEvict(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "ethash-test")
|
tmpdir, err := ioutil.TempDir("", "ethash-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
e := New(Config{CachesInMem: 3, CachesOnDisk: 10, CacheDir: tmpdir})
|
e := New(Config{CachesInMem: 3, CachesOnDisk: 10, CacheDir: tmpdir, PowMode: ModeTest})
|
||||||
|
|
||||||
var (
|
workers := 8
|
||||||
workers = 4
|
epochs := 100
|
||||||
epochs = 20
|
var wg sync.WaitGroup
|
||||||
wg sync.WaitGroup
|
|
||||||
)
|
|
||||||
wg.Add(workers)
|
wg.Add(workers)
|
||||||
for i := 0; i < workers; i++ {
|
for i := 0; i < workers; i++ {
|
||||||
go verifyTest(&wg, e, i, epochs)
|
go verifyTest(&wg, e, i, epochs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue