Skip to content

Commit ef7b9fb

Browse files
karalabefjl
authored andcommitted
cmd/puppeth: v4/v5 boot separation, signer gas configs (#14453)
1 parent b0d0faf commit ef7b9fb

4 files changed

Lines changed: 73 additions & 8 deletions

File tree

‎cmd/puppeth/module_node.go‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ADD genesis.json /genesis.json
4040
RUN \
4141
echo '/geth init /genesis.json' > geth.sh && \{{if .Unlock}}
4242
echo 'mkdir -p /root/.ethereum/keystore/ && cp /signer.json /root/.ethereum/keystore/' >> geth.sh && \{{end}}
43-
echo $'/geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .Bootnodes}}--bootnodes {{.Bootnodes}}{{end}} {{if .Etherbase}}--etherbase {{.Etherbase}} --mine{{end}}{{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}}' >> geth.sh
43+
echo $'/geth --networkid {{.NetworkID}} --cache 512 --port {{.Port}} --maxpeers {{.Peers}} {{.LightFlag}} --ethstats \'{{.Ethstats}}\' {{if .BootV4}}--bootnodesv4 {{.BootV4}}{{end}} {{if .BootV5}}--bootnodesv5 {{.BootV5}}{{end}} {{if .Etherbase}}--etherbase {{.Etherbase}} --mine{{end}}{{if .Unlock}}--unlock 0 --password /signer.pass --mine{{end}} --targetgaslimit {{.GasTarget}} --gasprice {{.GasPrice}}' >> geth.sh
4444
4545
ENTRYPOINT ["/bin/sh", "geth.sh"]
4646
`
@@ -66,17 +66,20 @@ services:
6666
- LIGHT_PEERS={{.LightPeers}}
6767
- STATS_NAME={{.Ethstats}}
6868
- MINER_NAME={{.Etherbase}}
69+
- GAS_TARGET={{.GasTarget}}
70+
- GAS_PRICE={{.GasPrice}}
6971
restart: always
7072
`
7173

7274
// deployNode deploys a new Ethereum node container to a remote machine via SSH,
7375
// docker and docker-compose. If an instance with the specified network name
7476
// already exists there, it will be overwritten!
75-
func deployNode(client *sshClient, network string, bootnodes []string, config *nodeInfos) ([]byte, error) {
77+
func deployNode(client *sshClient, network string, bootv4, bootv5 []string, config *nodeInfos) ([]byte, error) {
7678
kind := "sealnode"
7779
if config.keyJSON == "" && config.etherbase == "" {
7880
kind = "bootnode"
79-
bootnodes = make([]string, 0)
81+
bootv4 = make([]string, 0)
82+
bootv5 = make([]string, 0)
8083
}
8184
// Generate the content to upload to the server
8285
workdir := fmt.Sprintf("%d", rand.Int63())
@@ -92,9 +95,12 @@ func deployNode(client *sshClient, network string, bootnodes []string, config *n
9295
"Port": config.portFull,
9396
"Peers": config.peersTotal,
9497
"LightFlag": lightFlag,
95-
"Bootnodes": strings.Join(bootnodes, ","),
98+
"BootV4": strings.Join(bootv4, ","),
99+
"BootV5": strings.Join(bootv5, ","),
96100
"Ethstats": config.ethstats,
97101
"Etherbase": config.etherbase,
102+
"GasTarget": uint64(1000000 * config.gasTarget),
103+
"GasPrice": uint64(1000000000 * config.gasPrice),
98104
"Unlock": config.keyJSON != "",
99105
})
100106
files[filepath.Join(workdir, "Dockerfile")] = dockerfile.Bytes()
@@ -111,6 +117,8 @@ func deployNode(client *sshClient, network string, bootnodes []string, config *n
111117
"LightPeers": config.peersLight,
112118
"Ethstats": config.ethstats[:strings.Index(config.ethstats, ":")],
113119
"Etherbase": config.etherbase,
120+
"GasTarget": config.gasTarget,
121+
"GasPrice": config.gasPrice,
114122
})
115123
files[filepath.Join(workdir, "docker-compose.yaml")] = composefile.Bytes()
116124

@@ -147,6 +155,8 @@ type nodeInfos struct {
147155
etherbase string
148156
keyJSON string
149157
keyPass string
158+
gasTarget float64
159+
gasPrice float64
150160
}
151161

152162
// String implements the stringer interface.
@@ -155,7 +165,8 @@ func (info *nodeInfos) String() string {
155165
if info.peersLight > 0 {
156166
discv5 = fmt.Sprintf(", portv5=%d", info.portLight)
157167
}
158-
return fmt.Sprintf("port=%d%s, datadir=%s, peers=%d, lights=%d, ethstats=%s", info.portFull, discv5, info.datadir, info.peersTotal, info.peersLight, info.ethstats)
168+
return fmt.Sprintf("port=%d%s, datadir=%s, peers=%d, lights=%d, ethstats=%s, gastarget=%0.3f MGas, gasprice=%0.3f GWei",
169+
info.portFull, discv5, info.datadir, info.peersTotal, info.peersLight, info.ethstats, info.gasTarget, info.gasPrice)
159170
}
160171

161172
// checkNode does a health-check against an boot or seal node server to verify
@@ -176,6 +187,8 @@ func checkNode(client *sshClient, network string, boot bool) (*nodeInfos, error)
176187
// Resolve a few types from the environmental variables
177188
totalPeers, _ := strconv.Atoi(infos.envvars["TOTAL_PEERS"])
178189
lightPeers, _ := strconv.Atoi(infos.envvars["LIGHT_PEERS"])
190+
gasTarget, _ := strconv.ParseFloat(infos.envvars["GAS_TARGET"], 64)
191+
gasPrice, _ := strconv.ParseFloat(infos.envvars["GAS_PRICE"], 64)
179192

180193
// Container available, retrieve its node ID and its genesis json
181194
var out []byte
@@ -213,6 +226,8 @@ func checkNode(client *sshClient, network string, boot bool) (*nodeInfos, error)
213226
etherbase: infos.envvars["MINER_NAME"],
214227
keyJSON: keyJSON,
215228
keyPass: keyPass,
229+
gasTarget: gasTarget,
230+
gasPrice: gasPrice,
216231
}
217232
stats.enodeFull = fmt.Sprintf("enode://%s@%s:%d", id, client.address, stats.portFull)
218233
if stats.portLight != 0 {

‎cmd/puppeth/wizard.go‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,48 @@ func (w *wizard) readDefaultInt(def int) int {
162162
}
163163
}
164164

165+
// readFloat reads a single line from stdin, trimming if from spaces, enforcing it
166+
// to parse into a float.
167+
func (w *wizard) readFloat() float64 {
168+
for {
169+
fmt.Printf("> ")
170+
text, err := w.in.ReadString('\n')
171+
if err != nil {
172+
log.Crit("Failed to read user input", "err", err)
173+
}
174+
if text = strings.TrimSpace(text); text == "" {
175+
continue
176+
}
177+
val, err := strconv.ParseFloat(strings.TrimSpace(text), 64)
178+
if err != nil {
179+
log.Error("Invalid input, expected float", "err", err)
180+
continue
181+
}
182+
return val
183+
}
184+
}
185+
186+
// readDefaultFloat reads a single line from stdin, trimming if from spaces, enforcing
187+
// it to parse into a float. If an empty line is entered, the default value is returned.
188+
func (w *wizard) readDefaultFloat(def float64) float64 {
189+
for {
190+
fmt.Printf("> ")
191+
text, err := w.in.ReadString('\n')
192+
if err != nil {
193+
log.Crit("Failed to read user input", "err", err)
194+
}
195+
if text = strings.TrimSpace(text); text == "" {
196+
return def
197+
}
198+
val, err := strconv.ParseFloat(strings.TrimSpace(text), 64)
199+
if err != nil {
200+
log.Error("Invalid input, expected float", "err", err)
201+
continue
202+
}
203+
return val
204+
}
205+
}
206+
165207
// readPassword reads a single line from stdin, trimming it from the trailing new
166208
// line and returns it. The input will not be echoed.
167209
func (w *wizard) readPassword() string {

‎cmd/puppeth/wizard_netstats.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (w *wizard) networkStats(tips bool) {
3939
// Iterate over all the specified hosts and check their status
4040
stats := tablewriter.NewWriter(os.Stdout)
4141
stats.SetHeader([]string{"Server", "IP", "Status", "Service", "Details"})
42-
stats.SetColWidth(128)
42+
stats.SetColWidth(100)
4343

4444
for server, pubkey := range w.conf.Servers {
4545
client := w.servers[server]

‎cmd/puppeth/wizard_node.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (w *wizard) deployNode(boot bool) {
5050
if boot {
5151
infos = &nodeInfos{portFull: 30303, peersTotal: 512, peersLight: 256}
5252
} else {
53-
infos = &nodeInfos{portFull: 30303, peersTotal: 50, peersLight: 0}
53+
infos = &nodeInfos{portFull: 30303, peersTotal: 50, peersLight: 0, gasTarget: 4.7, gasPrice: 18}
5454
}
5555
}
5656
infos.genesis, _ = json.MarshalIndent(w.conf.genesis, "", " ")
@@ -136,9 +136,17 @@ func (w *wizard) deployNode(boot bool) {
136136
}
137137
}
138138
}
139+
// Establish the gas dynamics to be enforced by the signer
140+
fmt.Println()
141+
fmt.Printf("What gas limit should empty blocks target (MGas)? (default = %0.3f)\n", infos.gasTarget)
142+
infos.gasTarget = w.readDefaultFloat(infos.gasTarget)
143+
144+
fmt.Println()
145+
fmt.Printf("What gas price should the signer require (GWei)? (default = %0.3f)\n", infos.gasPrice)
146+
infos.gasPrice = w.readDefaultFloat(infos.gasPrice)
139147
}
140148
// Try to deploy the full node on the host
141-
if out, err := deployNode(client, w.network, w.conf.bootFull, infos); err != nil {
149+
if out, err := deployNode(client, w.network, w.conf.bootFull, w.conf.bootLight, infos); err != nil {
142150
log.Error("Failed to deploy Ethereum node container", "err", err)
143151
if len(out) > 0 {
144152
fmt.Printf("%s\n", out)

0 commit comments

Comments
 (0)