Skip to content

Commit 221459b

Browse files
committed
Merge branch 'feature/01/puppeth-static-enode-url' into 'release/1.9'
Feature/01/puppeth static enode url Closes ethereum#1 and ethereum#4 See merge request silesiacoin-dev/go-ethereum!10
2 parents d3a398d + 135bc2f commit 221459b

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

cmd/puppeth/module_node.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ADD genesis.json /genesis.json
4242
RUN \
4343
echo 'geth --cache 512 init /genesis.json' > geth.sh && \{{if .Unlock}}
4444
echo 'mkdir -p /root/.ethereum/keystore/ && cp /signer.json /root/.ethereum/keystore/' >> geth.sh && \{{end}}
45-
echo $'exec geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --nat extip:{{.IP}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .Bootnodes}}--bootnodes {{.Bootnodes}}{{end}} {{if .Etherbase}}--miner.etherbase {{.Etherbase}} --mine --miner.threads 1{{end}} {{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --miner.gastarget {{.GasTarget}} --miner.gaslimit {{.GasLimit}} --miner.gasprice {{.GasPrice}}' >> geth.sh
45+
echo $'exec geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --nat extip:{{.IP}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .Bootnodes}}--bootnodes {{.Bootnodes}}{{end}} {{if .Etherbase}}--miner.etherbase {{.Etherbase}} --mine --miner.threads 1{{end}} {{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --miner.gastarget {{.GasTarget}} --miner.gaslimit {{.GasLimit}} --miner.gasprice {{.GasPrice}} {{if .NodeKeyHex}} --nodekeyhex {{.NodeKeyHex}} {{end}}{{if .Testnet}} --testnet{{end}}' >> geth.sh
4646
4747
ENTRYPOINT ["/bin/sh", "geth.sh"]
4848
`
@@ -98,18 +98,20 @@ func deployNode(client *sshClient, network string, bootnodes []string, config *n
9898
}
9999
dockerfile := new(bytes.Buffer)
100100
template.Must(template.New("").Parse(nodeDockerfile)).Execute(dockerfile, map[string]interface{}{
101-
"NetworkID": config.network,
102-
"Port": config.port,
103-
"IP": client.address,
104-
"Peers": config.peersTotal,
105-
"LightFlag": lightFlag,
106-
"Bootnodes": strings.Join(bootnodes, ","),
107-
"Ethstats": config.ethstats,
108-
"Etherbase": config.etherbase,
109-
"GasTarget": uint64(1000000 * config.gasTarget),
110-
"GasLimit": uint64(1000000 * config.gasLimit),
111-
"GasPrice": uint64(1000000000 * config.gasPrice),
112-
"Unlock": config.keyJSON != "",
101+
"NetworkID": config.network,
102+
"Port": config.port,
103+
"IP": client.address,
104+
"Peers": config.peersTotal,
105+
"LightFlag": lightFlag,
106+
"Bootnodes": strings.Join(bootnodes, ","),
107+
"Ethstats": config.ethstats,
108+
"Etherbase": config.etherbase,
109+
"GasTarget": uint64(1000000 * config.gasTarget),
110+
"GasLimit": uint64(1000000 * config.gasLimit),
111+
"GasPrice": uint64(1000000000 * config.gasPrice),
112+
"Unlock": config.keyJSON != "",
113+
"NodeKeyHex": config.nodeKeyHex,
114+
"Testnet": config.testNet,
113115
})
114116
files[filepath.Join(workdir, "Dockerfile")] = dockerfile.Bytes()
115117

@@ -167,6 +169,8 @@ type nodeInfos struct {
167169
gasTarget float64
168170
gasLimit float64
169171
gasPrice float64
172+
nodeKeyHex string
173+
testNet bool
170174
}
171175

172176
// Report converts the typed struct into a plain string->string map, containing

cmd/puppeth/module_node_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"html/template"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func TestParsingNodeTemplate(t *testing.T) {
12+
bootnodes := []string{
13+
"enode://dummyEnode",
14+
"enode://dummyEnode",
15+
}
16+
17+
dockerfile := new(bytes.Buffer)
18+
template.Must(template.New("").Parse(nodeDockerfile)).Execute(dockerfile, map[string]interface{}{
19+
"NetworkID": "48",
20+
"Port": "30303",
21+
"IP": "49.34.12.10",
22+
"Peers": "10",
23+
"LightFlag": "",
24+
"Bootnodes": strings.Join(bootnodes, ","),
25+
"Ethstats": "ethstatsDummyUrl",
26+
"Etherbase": "etherbaseDummyUrl",
27+
"GasTarget": uint64(1000000 * 10),
28+
"GasLimit": uint64(1000000 * 10),
29+
"GasPrice": uint64(1000000000 * 10),
30+
"Unlock": true,
31+
"NodeKeyHex": "dummyNodeKeyHex",
32+
"Testnet": true,
33+
})
34+
35+
dockerFileString := strings.TrimSpace(fmt.Sprintf("%s", dockerfile))
36+
37+
// This is only for concrete implementation. If you somehow want to change it do it.
38+
// I have not time right now to write better test.
39+
if len(dockerFileString) > 751 {
40+
t.Error(len(dockerFileString))
41+
t.Error("Template parsing has changed. Check if you really want to do it.")
42+
}
43+
}

cmd/puppeth/wizard_node.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ func (w *wizard) deployNode(boot bool) {
7777
infos.ethashdir = w.readDefaultString(infos.ethashdir)
7878
}
7979
}
80+
81+
fmt.Println()
82+
fmt.Printf("What is the nodekeyhex for node? 'default' will generate random enode address \n")
83+
infos.nodeKeyHex = w.readDefaultString("default")
84+
85+
if "default" == infos.nodeKeyHex {
86+
infos.nodeKeyHex = ""
87+
}
88+
89+
fmt.Println()
90+
fmt.Printf("Do you want to pass testnet as an argument?. Type 'yes' if so. \n")
91+
infos.testNet = w.readDefaultString("no") != "no"
92+
8093
// Figure out which port to listen on
8194
fmt.Println()
8295
fmt.Printf("Which TCP/UDP port to listen on? (default = %d)\n", infos.port)

0 commit comments

Comments
 (0)