misccmd.go 4.9 KB

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