I am using Ubuntu 14.04 and running go-ethereum in it. In the ~/.ethash/ folder, I see that there are two DAG files created when mining begins. The first one is created immediately after mining starts and the second one after some time.I am interested in knowing the reason for it.
-
3One is a future DAG, pregenerated so that switching between the current and future DAGs can be done quickly. I think this has been asked before... Let me check.– Richard HorrocksApr 26, 2017 at 13:45
-
2(I couldn't see that this exact question had been asked before, so I'll add an answer.)– Richard HorrocksApr 26, 2017 at 16:18
1 Answer
Every 30,000 blocks - where 30,000 blocks is called an epoch - a new DAG file is generated. This mechanism provides the Ethash algorithm something fresh to work on.
At the end of 30,000 blocks, clients want to switch from their current DAG to the next one as quickly as possible. To this end, the next DAG file is generated in advance.
From the documentation:
Ethash PoW is memory hard, making it basically ASIC resistant. This basically means that calculating the PoW requires choosing subsets of a fixed resource dependent on the nonce and block header. This resource (a few gigabyte size data) is called a DAG. The DAG is totally different every 30000 blocks (a 100 hour window, called an epoch) and takes a while to generate. Since the DAG only depends on block height, it can be pregenerated but if its not, the client need to wait the end of this process to produce a block.
If you want to prevent the pregeneration (I can't see why you would, but it's your network... ), then you can do so on the command line.
-
1
-
2Yes, the old DAG is removed to prevent you ending up with lots of large files. May 1, 2017 at 7:42
-
1Also, I guess a new DAG file will be created to be used after the next 30,000 blocks. Is it true?– spharishMay 1, 2017 at 8:11
-
2Yep, correct. Every 30,000 blocks the same thing will happen. May 1, 2017 at 8:17