DAG代表定向非循環(huán)圖。在Ethereum中奖年,每個epoch都會使用Dagger-Hashimoto算法,結(jié)合Vitalik Buterin的Dagger算法和Thaddeus Dryja的Hashimoto算法烙荷,創(chuàng)建DAG 系谐。
DAG定義的整理:
Ethereum yellow paper中有提到
在數(shù)學(xué)和計算機科學(xué)中,有向無環(huán)圖(DAG)是一個沒有定向循環(huán)的有限有向圖魂奥。也就是說菠剩,它由有限的多個頂點和邊組成,每個邊從一個頂點指向另一個頂點耻煤,這樣就沒有辦法從任何頂點v開始具壮,沿著一個連貫的邊緣序列,最終循環(huán)回到v 哈蝇。等價地棺妓,DAG是有向圖,其具有拓撲排序炮赦,頂點序列怜跑,使得每個邊緣從序列中的較早到較晚被引導(dǎo)。
在 [github上以太坊項目主頁]中說明(https://github.com/ethereum/wiki/wiki/Ethash-DAG):
...一個巨大的數(shù)據(jù)集稱為DAG ...
Ethash算法期望DAG是uint32s(4字節(jié)無符號整數(shù))的二維數(shù)組吠勘,尺寸(n×16)性芬,其中n是一個很大的數(shù)字。(n從16777186開始)在幻數(shù)之后剧防,DAG的行應(yīng)該順序地寫入文件植锉,在行之間沒有分隔符,每個unint32以little-endian格式編碼峭拘。
The Ethash algorithm expects the DAG as a two-dimensional array of uint32s (4-byte unsigned ints), with dimension (n × 16) where n is a large number. (n starts at 16777186 and grows from there.) Following the magic number, the rows of the DAG should be written sequentially into the file, with no delimiter between rows and each unint32 encoded in little-endian format.(我也不知道n汽煮,還有'幻數(shù)'是個啥)
而以太坊創(chuàng)始人Vitalik Buterin自己說的是
Dagger是基于適度連接的有向非循環(huán)圖(DAG,因此得名)的memory-hard proof of work棚唆,雖然遠不是最佳的暇赤,但其比現(xiàn)如今其他的工作具有更強的memory-hardness特性。
實質(zhì)上宵凌,Dagger算法的工作原理是創(chuàng)建一個有向無環(huán)圖(其實就是數(shù)據(jù)結(jié)構(gòu)里面 允許節(jié)點有多個父節(jié)點 的樹)鞋囊,共有十個級別,包括根和總共225-1個值瞎惫。
Dagger, a memory-hard proof of work based on moderately connected directed acyclic graphs (DAGs, hence the name), which, while far from optimal, has much stronger memory-hardness properties than anything else in use today.
Essentially, the Dagger algorithm works by creating a directed acyclic graph (the technical term for a tree where each node is allowed to have multiple parents) with ten levels including the root and a total of 225 - 1 values.
在github上以太坊項目里介紹挖礦里的DAG定義
...計算PoW(工作量證明)需要固定量resource的子集溜腐,量大小取決于隨機數(shù)和塊頭译株。這個resource(幾GB的大小的數(shù)據(jù))被稱為DAG。每30000塊的間隔之間(一個100小時的窗口挺益,稱為epoch)DAG是完全不同的歉糜,需要一段時間才能生成。
...calculating the PoW (Proof of Work) requires 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.
在github項目上mining中的ethash-dag
用于工作證明算法的DAG(有向無環(huán)圖)
在github項目中https://github.com/ethereum/wiki/wiki/Mining#the-algorithm
一個大的望众,暫時的匪补,隨機生成的數(shù)據(jù)庫
下面稍微總結(jié)一下:DAG是Ethash算法描述中的“數(shù)據(jù)集”
1 存在一個種子,可以通過掃描塊標題直到該點為每個塊計算烂翰。
2 從種子中夯缺,可以計算一個16 MB的偽隨機緩存。輕客戶端存儲緩存甘耿。
3 從緩存中踊兜,我們可以生成一個1 GB的數(shù)據(jù)集,其屬性是數(shù)據(jù)集中的每個項目僅依賴于緩存中的少量項目佳恬。完整的客戶和礦工存儲數(shù)據(jù)集捏境。數(shù)據(jù)集隨時間線性增長。
4 挖掘包括抓取數(shù)據(jù)集的隨機片段并將它們混合在一起毁葱。通過使用緩存重新生成所需數(shù)據(jù)集的特定片段垫言,可以使用低內(nèi)存完成驗證,因此您只需要存儲緩存头谜。1.There exists a seed which can be computed for each block by scanning through the block headers up until that point.
2.From the seed, one can compute a 16 MB pseudorandom cache. Light clients store the cache.
3.From the cache, we can generate a 1 GB dataset, with the property that each item in the dataset depends on only a small number of items from the cache. Full clients and miners store the dataset. The dataset grows linearly with time.
4.Mining involves grabbing random slices of the dataset and hashing them together. Verification can be done with low memory by using the cache to regenerate the specific pieces of the dataset that you need, so you only need to store the cache.