4

I want to understand algorithmically how the 1GB dataset is generated and how it is updated based on block data in Ethash. I also would like to see, where in the code it is implemented in Go-Etherum. It would be appreciated if the link for that part of the code is attached with the answer.

3

The algorithm

The algorithm is explained in detail, using (Python) pseudo-code, on the Ethash wiki page. There's also a related Design Rationale page.

Those pages are nicely written, concise, and should cover everything you need to know, so I won't rehash them here. (Pun not intended, but I'll pretend it was.) Instead I'll concentrate on the code locations, below.


The code

The code is located in the consensus/ethash directory of the go-ethereum repository.

The main file you'll be interested in is ethash.go. In here there are several places of interest.

Which does the following:

// New creates a full sized ethash PoW scheme.
func New(cachedir string, cachesinmem, cachesondisk int, dagdir string, dagsinmem, dagsondisk int) *Ethash {

Which does the following:

// dataset tries to retrieve a mining dataset for the specified block number
// by first checking against a list of in-memory datasets, then against DAGs
// stored on disk, and finally generating one if none can be found.
func (ethash *Ethash) dataset(block uint64) []uint32 {

You can follow this final function further to calls to both memoryMapAndGenerate() and the passed in generator() function.


Edit:

And the part of the code that actually ties the two sections, above, together - and makes my answer an actual answer, rather than two slightly disjointed paragraphs - can be found in algorithm.go. Credit goes to Péter, who actually knows what he's talking about. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.