misccmd.go 5.2 KB

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