forked from ethereum/hive
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinternal.go
60 lines (53 loc) · 1.51 KB
/
internal.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
package main
import (
"errors"
"os"
"os/signal"
"github.com/fsouza/go-dockerclient"
"gopkg.in/inconshreveable/log15.v2"
)
// makeGenesisDAG runs the ethash DAG generator to ensure that the genesis epochs
// DAG is created prior to it being needed by simulations.
func makeGenesisDAG(daemon *docker.Client) error {
// Build the image for the DAG generator
log15.Info("creating ethash container")
image, err := buildEthash(daemon)
if err != nil {
return err
}
// Create the ethash container container and make sure it's deleted afterwards
ethash, err := createEthashContainer(daemon, image)
if err != nil {
log15.Error("failed to create ethash container", "error", err)
return err
}
log15.Debug("created ethash container")
defer func() {
log15.Debug("deleting ethash container")
daemon.RemoveContainer(docker.RemoveContainerOptions{ID: ethash.ID, Force: true})
}()
// Start generating the genesis ethash DAG
log15.Info("generating genesis DAG")
waiter, err := runContainer(daemon, ethash.ID, log15.Root(), "", true)
if err != nil {
log15.Error("failed to execute ethash", "error", err)
return err
}
// Register an interrupt handler to cleanly tear ethash down
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
errc := make(chan error, 1)
go func() {
<-interrupt
errc <- errors.New("interrupted")
daemon.StopContainer(ethash.ID, 0)
}()
// Wait for container termination and return
waiter.Wait()
select {
case err := <-errc:
return err
default:
return nil
}
}