-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethdag.go
81 lines (66 loc) · 1.92 KB
/
ethdag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"math"
"os"
"time"
eth "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/kkibria/ethdag/dataset"
"github.com/kkibria/kkutils"
)
var (
endian string
pStatsFlag *bool
pOutDir *string
seedhash []byte
)
func main() {
var err error
defer kkutils.TimeTrack(time.Now(), "ethdag")
pDatasetCnt := flag.Uint64("r", 1, "Number of datasets to generate. Maximum 16 datasets.")
pBlock := flag.Uint64("b", math.MaxUint64, "Block number. Epoch number must not be specified.")
pEpoch := flag.Uint64("e", math.MaxUint64, "Epoch number. Block number must not be specified.")
pStatsFlag = flag.Bool("s", false, "Stats only, does not generate dataset.")
pOutDir = flag.String("o", "eth-dataset", "Output directory.")
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
fmt.Printf(" -r [-b block|-e epoch] -s -o outDir\n")
flag.PrintDefaults()
os.Exit(1)
}
flag.Parse()
if (flag.NArg() != 0) || (*pBlock == *pEpoch) || (*pDatasetCnt < 1) || (*pDatasetCnt > 16) {
flag.Usage()
}
if (*pBlock == math.MaxUint64) && (*pEpoch == math.MaxUint64) {
flag.Usage()
}
if (*pBlock != math.MaxUint64) && (*pEpoch != math.MaxUint64) {
flag.Usage()
}
if *pEpoch != math.MaxUint64 {
*pBlock = *pEpoch * dataset.BlocksPerEpoch
} else {
*pEpoch = *pBlock / dataset.BlocksPerEpoch
}
fmt.Fprintf(os.Stdout, "Block = %v\n", *pBlock)
fmt.Fprintf(os.Stdout, "Epoch = %v\n", *pEpoch)
if !kkutils.IsLittleEndian() {
endian = ".be"
}
for i := uint64(0); i < *pDatasetCnt; i++ {
e := *pEpoch + i
b := e * dataset.BlocksPerEpoch
// sizes
seedhash = eth.SeedHash(b)
fmt.Fprintf(os.Stdout, "\nseedhash(%v) = %x\n", e, seedhash)
fmt.Fprintf(os.Stdout, "Cache size = %v\n", eth.CacheSize(b))
fmt.Fprintf(os.Stdout, "Dataset size = %v\n", eth.DatasetSize(b))
if !*pStatsFlag {
if err = dataset.Dataset(e, *pOutDir); err != nil {
fmt.Println(err)
}
}
}
}