-
Notifications
You must be signed in to change notification settings - Fork 39
/
config.go
128 lines (103 loc) · 3.09 KB
/
config.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package utils
import (
"math/big"
"os"
cli "gopkg.in/urfave/cli.v1"
ethUtils "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/consensus/ethash"
rpcClient "github.com/tendermint/tendermint/rpc/client"
"github.com/CyberMiles/travis/api"
"github.com/CyberMiles/travis/vm/ethereum"
)
const (
// Client identifier to advertise over the network
clientIdentifier = "vm"
// Environment variable for home dir
emHome = "EMHOME"
)
var (
// GenesisTargetGasLimit is the target gas limit of the Genesis block.
// #unstable
GenesisTargetGasLimit = big.NewInt(100000000)
)
type ethstatsConfig struct {
URL string `toml:",omitempty"`
}
type gethConfig struct {
Eth eth.Config
Node node.Config
Ethstats ethstatsConfig
}
// MakeFullNode creates a full go-ethereum node
// #unstable
func MakeFullNode(ctx *cli.Context) *ethereum.Node {
stack, cfg := makeConfigNode(ctx)
tendermintLAddr := ctx.GlobalString(TendermintAddrFlag.Name)
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return api.NewBackend(ctx, &cfg.Eth, rpcClient.NewHTTP(tendermintLAddr, "/websocket"))
}); err != nil {
ethUtils.Fatalf("Failed to register the ABCI application service: %v", err)
}
return stack
}
func makeConfigNode(ctx *cli.Context) (*ethereum.Node, gethConfig) {
cfg := gethConfig{
Eth: eth.DefaultConfig,
Node: DefaultNodeConfig(),
}
ethUtils.SetNodeConfig(ctx, &cfg.Node)
SetEthermintNodeConfig(&cfg.Node)
stack, err := ethereum.New(&cfg.Node)
if err != nil {
ethUtils.Fatalf("Failed to create the protocol stack: %v", err)
}
ethUtils.SetEthConfig(ctx, &stack.Node, &cfg.Eth)
SetEthermintEthConfig(&cfg.Eth)
return stack, cfg
}
// DefaultNodeConfig returns the default configuration for a go-ethereum node
// #unstable
func DefaultNodeConfig() node.Config {
cfg := node.DefaultConfig
cfg.Name = clientIdentifier
cfg.Version = params.Version
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
cfg.WSModules = append(cfg.WSModules, "eth")
cfg.IPCPath = "geth.ipc"
emHome := os.Getenv(emHome)
if emHome != "" {
cfg.DataDir = emHome
}
return cfg
}
// SetEthermintNodeConfig takes a node configuration and applies ethermint specific configuration
// #unstable
func SetEthermintNodeConfig(cfg *node.Config) {
cfg.P2P.MaxPeers = 0
cfg.P2P.NoDiscovery = true
}
// SetEthermintEthConfig takes a ethereum configuration and applies ethermint specific configuration
// #unstable
func SetEthermintEthConfig(cfg *eth.Config) {
//cfg.MaxPeers = 0
cfg.Ethash.PowMode = ethash.ModeFake
}
// MakeDataDir retrieves the currently requested data directory
// #unstable
func MakeDataDir(ctx *cli.Context) string {
path := node.DefaultDataDir()
emHome := os.Getenv(emHome)
if emHome != "" {
path = emHome
}
if ctx.GlobalIsSet(ethUtils.DataDirFlag.Name) {
path = ctx.GlobalString(ethUtils.DataDirFlag.Name)
}
if path == "" {
ethUtils.Fatalf("Cannot determine default data directory, please set manually (--datadir)")
}
return path
}