misccmd.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "fmt"
  19. "os"
  20. "runtime"
  21. "strconv"
  22. "strings"
  23. "github.com/ethereum/go-ethereum/cmd/utils"
  24. "github.com/ethereum/go-ethereum/consensus/ethash"
  25. "github.com/ethereum/go-ethereum/eth/ethconfig"
  26. "github.com/ethereum/go-ethereum/params"
  27. "gopkg.in/urfave/cli.v1"
  28. )
  29. var (
  30. VersionCheckUrlFlag = cli.StringFlag{
  31. Name: "check.url",
  32. Usage: "URL to use when checking vulnerabilities",
  33. Value: "https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json",
  34. }
  35. VersionCheckVersionFlag = cli.StringFlag{
  36. Name: "check.version",
  37. Usage: "Version to check",
  38. Value: fmt.Sprintf("Geth/v%v/%v-%v/%v",
  39. params.VersionWithCommit(gitCommit, gitDate),
  40. runtime.GOOS, runtime.GOARCH, runtime.Version()),
  41. }
  42. makecacheCommand = cli.Command{
  43. Action: utils.MigrateFlags(makecache),
  44. Name: "makecache",
  45. Usage: "Generate ethash verification cache (for testing)",
  46. ArgsUsage: "<blockNum> <outputDir>",
  47. Category: "MISCELLANEOUS COMMANDS",
  48. Description: `
  49. The makecache command generates an ethash cache in <outputDir>.
  50. This command exists to support the system testing project.
  51. Regular users do not need to execute it.
  52. `,
  53. }
  54. makedagCommand = cli.Command{
  55. Action: utils.MigrateFlags(makedag),
  56. Name: "makedag",
  57. Usage: "Generate ethash mining DAG (for testing)",
  58. ArgsUsage: "<blockNum> <outputDir>",
  59. Category: "MISCELLANEOUS COMMANDS",
  60. Description: `
  61. The makedag command generates an ethash DAG in <outputDir>.
  62. This command exists to support the system testing project.
  63. Regular users do not need to execute it.
  64. `,
  65. }
  66. versionCommand = cli.Command{
  67. Action: utils.MigrateFlags(version),
  68. Name: "version",
  69. Usage: "Print version numbers",
  70. ArgsUsage: " ",
  71. Category: "MISCELLANEOUS COMMANDS",
  72. Description: `
  73. The output of this command is supposed to be machine-readable.
  74. `,
  75. }
  76. versionCheckCommand = cli.Command{
  77. Action: utils.MigrateFlags(versionCheck),
  78. Flags: []cli.Flag{
  79. VersionCheckUrlFlag,
  80. VersionCheckVersionFlag,
  81. },
  82. Name: "version-check",
  83. Usage: "Checks (online) whether the current version suffers from any known security vulnerabilities",
  84. ArgsUsage: "<versionstring (optional)>",
  85. Category: "MISCELLANEOUS COMMANDS",
  86. Description: `
  87. The version-check command fetches vulnerability-information from https://geth.ethereum.org/docs/vulnerabilities/vulnerabilities.json,
  88. and displays information about any security vulnerabilities that affect the currently executing version.
  89. `,
  90. }
  91. licenseCommand = cli.Command{
  92. Action: utils.MigrateFlags(license),
  93. Name: "license",
  94. Usage: "Display license information",
  95. ArgsUsage: " ",
  96. Category: "MISCELLANEOUS COMMANDS",
  97. }
  98. )
  99. // makecache generates an ethash verification cache into the provided folder.
  100. func makecache(ctx *cli.Context) error {
  101. args := ctx.Args()
  102. if len(args) != 2 {
  103. utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`)
  104. }
  105. block, err := strconv.ParseUint(args[0], 0, 64)
  106. if err != nil {
  107. utils.Fatalf("Invalid block number: %v", err)
  108. }
  109. ethash.MakeCache(block, args[1])
  110. return nil
  111. }
  112. // makedag generates an ethash mining DAG into the provided folder.
  113. func makedag(ctx *cli.Context) error {
  114. args := ctx.Args()
  115. if len(args) != 2 {
  116. utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
  117. }
  118. block, err := strconv.ParseUint(args[0], 0, 64)
  119. if err != nil {
  120. utils.Fatalf("Invalid block number: %v", err)
  121. }
  122. ethash.MakeDataset(block, args[1])
  123. return nil
  124. }
  125. func version(ctx *cli.Context) error {
  126. fmt.Println(strings.Title(clientIdentifier))
  127. fmt.Println("Version:", params.VersionWithMeta)
  128. if gitCommit != "" {
  129. fmt.Println("Git Commit:", gitCommit)
  130. }
  131. if gitDate != "" {
  132. fmt.Println("Git Commit Date:", gitDate)
  133. }
  134. fmt.Println("Quorum Version:", params.QuorumVersion)
  135. fmt.Println("Architecture:", runtime.GOARCH)
  136. fmt.Println("Network Id:", ethconfig.Defaults.NetworkId)
  137. fmt.Println("Go Version:", runtime.Version())
  138. fmt.Println("Operating System:", runtime.GOOS)
  139. fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
  140. fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
  141. return nil
  142. }
  143. func license(_ *cli.Context) error {
  144. fmt.Println(`Geth is free software: you can redistribute it and/or modify
  145. it under the terms of the GNU General Public License as published by
  146. the Free Software Foundation, either version 3 of the License, or
  147. (at your option) any later version.
  148. Geth is distributed in the hope that it will be useful,
  149. but WITHOUT ANY WARRANTY; without even the implied warranty of
  150. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  151. GNU General Public License for more details.
  152. You should have received a copy of the GNU General Public License
  153. along with geth. If not, see <http://www.gnu.org/licenses/>.`)
  154. return nil
  155. }