flags.go 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682
  1. // Copyright 2015 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 utils contains internal helper functions for go-ethereum commands.
  17. package utils
  18. import (
  19. "crypto/ecdsa"
  20. "encoding/json"
  21. "fmt"
  22. "io"
  23. "io/ioutil"
  24. "math"
  25. "math/big"
  26. "net/url"
  27. "os"
  28. "path/filepath"
  29. godebug "runtime/debug"
  30. "strconv"
  31. "strings"
  32. "text/tabwriter"
  33. "text/template"
  34. "time"
  35. "github.com/ethereum/go-ethereum/accounts"
  36. "github.com/ethereum/go-ethereum/accounts/keystore"
  37. "github.com/ethereum/go-ethereum/common"
  38. "github.com/ethereum/go-ethereum/common/fdlimit"
  39. http2 "github.com/ethereum/go-ethereum/common/http"
  40. "github.com/ethereum/go-ethereum/consensus"
  41. "github.com/ethereum/go-ethereum/consensus/clique"
  42. "github.com/ethereum/go-ethereum/consensus/ethash"
  43. "github.com/ethereum/go-ethereum/consensus/istanbul"
  44. istanbulBackend "github.com/ethereum/go-ethereum/consensus/istanbul/backend"
  45. "github.com/ethereum/go-ethereum/core"
  46. "github.com/ethereum/go-ethereum/core/rawdb"
  47. "github.com/ethereum/go-ethereum/core/vm"
  48. "github.com/ethereum/go-ethereum/crypto"
  49. "github.com/ethereum/go-ethereum/eth"
  50. "github.com/ethereum/go-ethereum/eth/downloader"
  51. "github.com/ethereum/go-ethereum/eth/ethconfig"
  52. "github.com/ethereum/go-ethereum/eth/gasprice"
  53. "github.com/ethereum/go-ethereum/eth/tracers"
  54. "github.com/ethereum/go-ethereum/ethclient"
  55. "github.com/ethereum/go-ethereum/ethdb"
  56. "github.com/ethereum/go-ethereum/ethstats"
  57. "github.com/ethereum/go-ethereum/extension"
  58. "github.com/ethereum/go-ethereum/graphql"
  59. "github.com/ethereum/go-ethereum/internal/ethapi"
  60. "github.com/ethereum/go-ethereum/internal/flags"
  61. "github.com/ethereum/go-ethereum/les"
  62. "github.com/ethereum/go-ethereum/log"
  63. "github.com/ethereum/go-ethereum/metrics"
  64. "github.com/ethereum/go-ethereum/metrics/exp"
  65. "github.com/ethereum/go-ethereum/metrics/influxdb"
  66. "github.com/ethereum/go-ethereum/miner"
  67. "github.com/ethereum/go-ethereum/node"
  68. "github.com/ethereum/go-ethereum/p2p"
  69. "github.com/ethereum/go-ethereum/p2p/enode"
  70. "github.com/ethereum/go-ethereum/p2p/nat"
  71. "github.com/ethereum/go-ethereum/p2p/netutil"
  72. "github.com/ethereum/go-ethereum/params"
  73. "github.com/ethereum/go-ethereum/permission"
  74. "github.com/ethereum/go-ethereum/permission/core/types"
  75. "github.com/ethereum/go-ethereum/plugin"
  76. "github.com/ethereum/go-ethereum/private"
  77. "github.com/ethereum/go-ethereum/raft"
  78. pcsclite "github.com/gballet/go-libpcsclite"
  79. gopsutil "github.com/shirou/gopsutil/mem"
  80. "gopkg.in/urfave/cli.v1"
  81. )
  82. func init() {
  83. cli.AppHelpTemplate = `{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
  84. VERSION:
  85. {{.Version}}
  86. COMMANDS:
  87. {{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
  88. {{end}}{{if .Flags}}
  89. GLOBAL OPTIONS:
  90. {{range .Flags}}{{.}}
  91. {{end}}{{end}}
  92. `
  93. cli.CommandHelpTemplate = flags.CommandHelpTemplate
  94. cli.HelpPrinter = printHelp
  95. }
  96. func printHelp(out io.Writer, templ string, data interface{}) {
  97. funcMap := template.FuncMap{"join": strings.Join}
  98. t := template.Must(template.New("help").Funcs(funcMap).Parse(templ))
  99. w := tabwriter.NewWriter(out, 38, 8, 2, ' ', 0)
  100. err := t.Execute(w, data)
  101. if err != nil {
  102. panic(err)
  103. }
  104. w.Flush()
  105. }
  106. // These are all the command line flags we support.
  107. // If you add to this list, please remember to include the
  108. // flag in the appropriate command definition.
  109. //
  110. // The flags are defined here so their names and help texts
  111. // are the same for all commands.
  112. var (
  113. // General settings
  114. DataDirFlag = DirectoryFlag{
  115. Name: "datadir",
  116. Usage: "Data directory for the databases and keystore",
  117. Value: DirectoryString(node.DefaultDataDir()),
  118. }
  119. RaftLogDirFlag = DirectoryFlag{
  120. Name: "raftlogdir",
  121. Usage: "Raft log directory for the raft-state, raft-snap and raft-wal folders",
  122. Value: DirectoryString(node.DefaultDataDir()),
  123. }
  124. AncientFlag = DirectoryFlag{
  125. Name: "datadir.ancient",
  126. Usage: "Data directory for ancient chain segments (default = inside chaindata)",
  127. }
  128. MinFreeDiskSpaceFlag = DirectoryFlag{
  129. Name: "datadir.minfreedisk",
  130. Usage: "Minimum free disk space in MB, once reached triggers auto shut down (default = --cache.gc converted to MB, 0 = disabled)",
  131. }
  132. KeyStoreDirFlag = DirectoryFlag{
  133. Name: "keystore",
  134. Usage: "Directory for the keystore (default = inside the datadir)",
  135. }
  136. NoUSBFlag = cli.BoolFlag{
  137. Name: "nousb",
  138. Usage: "Disables monitoring for and managing USB hardware wallets (deprecated)",
  139. }
  140. USBFlag = cli.BoolFlag{
  141. Name: "usb",
  142. Usage: "Enable monitoring and management of USB hardware wallets",
  143. }
  144. SmartCardDaemonPathFlag = cli.StringFlag{
  145. Name: "pcscdpath",
  146. Usage: "Path to the smartcard daemon (pcscd) socket file",
  147. Value: pcsclite.PCSCDSockName,
  148. }
  149. NetworkIdFlag = cli.Uint64Flag{
  150. Name: "networkid",
  151. Usage: "Explicitly set network id (integer)(For testnets: use --ropsten, --rinkeby, --goerli instead)",
  152. Value: ethconfig.Defaults.NetworkId,
  153. }
  154. MainnetFlag = cli.BoolFlag{
  155. Name: "mainnet",
  156. Usage: "Ethereum mainnet",
  157. }
  158. GoerliFlag = cli.BoolFlag{
  159. Name: "goerli",
  160. Usage: "Görli network: pre-configured proof-of-authority test network",
  161. }
  162. YoloV3Flag = cli.BoolFlag{
  163. Name: "yolov3",
  164. Usage: "YOLOv3 network: pre-configured proof-of-authority shortlived test network.",
  165. }
  166. RinkebyFlag = cli.BoolFlag{
  167. Name: "rinkeby",
  168. Usage: "Rinkeby network: pre-configured proof-of-authority test network",
  169. }
  170. RopstenFlag = cli.BoolFlag{
  171. Name: "ropsten",
  172. Usage: "Ropsten network: pre-configured proof-of-work test network",
  173. }
  174. DeveloperFlag = cli.BoolFlag{
  175. Name: "dev",
  176. Usage: "Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled",
  177. }
  178. DeveloperPeriodFlag = cli.IntFlag{
  179. Name: "dev.period",
  180. Usage: "Block period to use in developer mode (0 = mine only if transaction pending)",
  181. }
  182. IdentityFlag = cli.StringFlag{
  183. Name: "identity",
  184. Usage: "Custom node name",
  185. }
  186. DocRootFlag = DirectoryFlag{
  187. Name: "docroot",
  188. Usage: "Document Root for HTTPClient file scheme",
  189. Value: DirectoryString(HomeDir()),
  190. }
  191. ExitWhenSyncedFlag = cli.BoolFlag{
  192. Name: "exitwhensynced",
  193. Usage: "Exits after block synchronisation completes",
  194. }
  195. IterativeOutputFlag = cli.BoolFlag{
  196. Name: "iterative",
  197. Usage: "Print streaming JSON iteratively, delimited by newlines",
  198. }
  199. ExcludeStorageFlag = cli.BoolFlag{
  200. Name: "nostorage",
  201. Usage: "Exclude storage entries (save db lookups)",
  202. }
  203. IncludeIncompletesFlag = cli.BoolFlag{
  204. Name: "incompletes",
  205. Usage: "Include accounts for which we don't have the address (missing preimage)",
  206. }
  207. ExcludeCodeFlag = cli.BoolFlag{
  208. Name: "nocode",
  209. Usage: "Exclude contract code (save db lookups)",
  210. }
  211. defaultSyncMode = ethconfig.Defaults.SyncMode
  212. SyncModeFlag = TextMarshalerFlag{
  213. Name: "syncmode",
  214. Usage: `Blockchain sync mode ("fast", "full", "snap" or "light")`,
  215. Value: &defaultSyncMode,
  216. }
  217. GCModeFlag = cli.StringFlag{
  218. Name: "gcmode",
  219. Usage: `Blockchain garbage collection mode ("full", "archive")`,
  220. Value: "full",
  221. }
  222. SnapshotFlag = cli.BoolTFlag{
  223. Name: "snapshot",
  224. Usage: `Enables snapshot-database mode (default = enable)`,
  225. }
  226. TxLookupLimitFlag = cli.Uint64Flag{
  227. Name: "txlookuplimit",
  228. Usage: "Number of recent blocks to maintain transactions index for (default = about one year, 0 = entire chain)",
  229. Value: ethconfig.Defaults.TxLookupLimit,
  230. }
  231. LightKDFFlag = cli.BoolFlag{
  232. Name: "lightkdf",
  233. Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
  234. }
  235. DeprecatedAuthorizationListFlag = cli.StringFlag{
  236. Name: "whitelist",
  237. Usage: "[DEPRECATED: will be replaced by 'authorizationlist'] Comma separated block number-to-hash mappings to authorize (<number>=<hash>)",
  238. }
  239. AuthorizationListFlag = cli.StringFlag{
  240. Name: "authorizationlist",
  241. Usage: "Comma separated block number-to-hash mappings to authorize (<number>=<hash>)",
  242. }
  243. BloomFilterSizeFlag = cli.Uint64Flag{
  244. Name: "bloomfilter.size",
  245. Usage: "Megabytes of memory allocated to bloom-filter for pruning",
  246. Value: 2048,
  247. }
  248. OverrideBerlinFlag = cli.Uint64Flag{
  249. Name: "override.berlin",
  250. Usage: "Manually specify Berlin fork-block, overriding the bundled setting",
  251. }
  252. // Light server and client settings
  253. LightServeFlag = cli.IntFlag{
  254. Name: "light.serve",
  255. Usage: "Maximum percentage of time allowed for serving LES requests (multi-threaded processing allows values over 100)",
  256. Value: ethconfig.Defaults.LightServ,
  257. }
  258. LightIngressFlag = cli.IntFlag{
  259. Name: "light.ingress",
  260. Usage: "Incoming bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited)",
  261. Value: ethconfig.Defaults.LightIngress,
  262. }
  263. LightEgressFlag = cli.IntFlag{
  264. Name: "light.egress",
  265. Usage: "Outgoing bandwidth limit for serving light clients (kilobytes/sec, 0 = unlimited)",
  266. Value: ethconfig.Defaults.LightEgress,
  267. }
  268. LightMaxPeersFlag = cli.IntFlag{
  269. Name: "light.maxpeers",
  270. Usage: "Maximum number of light clients to serve, or light servers to attach to",
  271. Value: ethconfig.Defaults.LightPeers,
  272. }
  273. UltraLightServersFlag = cli.StringFlag{
  274. Name: "ulc.servers",
  275. Usage: "List of trusted ultra-light servers",
  276. Value: strings.Join(ethconfig.Defaults.UltraLightServers, ","),
  277. }
  278. UltraLightFractionFlag = cli.IntFlag{
  279. Name: "ulc.fraction",
  280. Usage: "Minimum % of trusted ultra-light servers required to announce a new head",
  281. Value: ethconfig.Defaults.UltraLightFraction,
  282. }
  283. UltraLightOnlyAnnounceFlag = cli.BoolFlag{
  284. Name: "ulc.onlyannounce",
  285. Usage: "Ultra light server sends announcements only",
  286. }
  287. LightNoPruneFlag = cli.BoolFlag{
  288. Name: "light.nopruning",
  289. Usage: "Disable ancient light chain data pruning",
  290. }
  291. LightNoSyncServeFlag = cli.BoolFlag{
  292. Name: "light.nosyncserve",
  293. Usage: "Enables serving light clients before syncing",
  294. }
  295. // Ethash settings
  296. EthashCacheDirFlag = DirectoryFlag{
  297. Name: "ethash.cachedir",
  298. Usage: "Directory to store the ethash verification caches (default = inside the datadir)",
  299. }
  300. EthashCachesInMemoryFlag = cli.IntFlag{
  301. Name: "ethash.cachesinmem",
  302. Usage: "Number of recent ethash caches to keep in memory (16MB each)",
  303. Value: ethconfig.Defaults.Ethash.CachesInMem,
  304. }
  305. EthashCachesOnDiskFlag = cli.IntFlag{
  306. Name: "ethash.cachesondisk",
  307. Usage: "Number of recent ethash caches to keep on disk (16MB each)",
  308. Value: ethconfig.Defaults.Ethash.CachesOnDisk,
  309. }
  310. EthashCachesLockMmapFlag = cli.BoolFlag{
  311. Name: "ethash.cacheslockmmap",
  312. Usage: "Lock memory maps of recent ethash caches",
  313. }
  314. EthashDatasetDirFlag = DirectoryFlag{
  315. Name: "ethash.dagdir",
  316. Usage: "Directory to store the ethash mining DAGs",
  317. Value: DirectoryString(ethconfig.Defaults.Ethash.DatasetDir),
  318. }
  319. EthashDatasetsInMemoryFlag = cli.IntFlag{
  320. Name: "ethash.dagsinmem",
  321. Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
  322. Value: ethconfig.Defaults.Ethash.DatasetsInMem,
  323. }
  324. EthashDatasetsOnDiskFlag = cli.IntFlag{
  325. Name: "ethash.dagsondisk",
  326. Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
  327. Value: ethconfig.Defaults.Ethash.DatasetsOnDisk,
  328. }
  329. EthashDatasetsLockMmapFlag = cli.BoolFlag{
  330. Name: "ethash.dagslockmmap",
  331. Usage: "Lock memory maps for recent ethash mining DAGs",
  332. }
  333. // Transaction pool settings
  334. TxPoolLocalsFlag = cli.StringFlag{
  335. Name: "txpool.locals",
  336. Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)",
  337. }
  338. TxPoolNoLocalsFlag = cli.BoolFlag{
  339. Name: "txpool.nolocals",
  340. Usage: "Disables price exemptions for locally submitted transactions",
  341. }
  342. TxPoolJournalFlag = cli.StringFlag{
  343. Name: "txpool.journal",
  344. Usage: "Disk journal for local transaction to survive node restarts",
  345. Value: core.DefaultTxPoolConfig.Journal,
  346. }
  347. TxPoolRejournalFlag = cli.DurationFlag{
  348. Name: "txpool.rejournal",
  349. Usage: "Time interval to regenerate the local transaction journal",
  350. Value: core.DefaultTxPoolConfig.Rejournal,
  351. }
  352. TxPoolPriceLimitFlag = cli.Uint64Flag{
  353. Name: "txpool.pricelimit",
  354. Usage: "Minimum gas price limit to enforce for acceptance into the pool",
  355. Value: ethconfig.Defaults.TxPool.PriceLimit,
  356. }
  357. TxPoolPriceBumpFlag = cli.Uint64Flag{
  358. Name: "txpool.pricebump",
  359. Usage: "Price bump percentage to replace an already existing transaction",
  360. Value: ethconfig.Defaults.TxPool.PriceBump,
  361. }
  362. TxPoolAccountSlotsFlag = cli.Uint64Flag{
  363. Name: "txpool.accountslots",
  364. Usage: "Minimum number of executable transaction slots guaranteed per account",
  365. Value: ethconfig.Defaults.TxPool.AccountSlots,
  366. }
  367. TxPoolGlobalSlotsFlag = cli.Uint64Flag{
  368. Name: "txpool.globalslots",
  369. Usage: "Maximum number of executable transaction slots for all accounts",
  370. Value: ethconfig.Defaults.TxPool.GlobalSlots,
  371. }
  372. TxPoolAccountQueueFlag = cli.Uint64Flag{
  373. Name: "txpool.accountqueue",
  374. Usage: "Maximum number of non-executable transaction slots permitted per account",
  375. Value: ethconfig.Defaults.TxPool.AccountQueue,
  376. }
  377. TxPoolGlobalQueueFlag = cli.Uint64Flag{
  378. Name: "txpool.globalqueue",
  379. Usage: "Maximum number of non-executable transaction slots for all accounts",
  380. Value: ethconfig.Defaults.TxPool.GlobalQueue,
  381. }
  382. TxPoolLifetimeFlag = cli.DurationFlag{
  383. Name: "txpool.lifetime",
  384. Usage: "Maximum amount of time non-executable transaction are queued",
  385. Value: ethconfig.Defaults.TxPool.Lifetime,
  386. }
  387. // Performance tuning settings
  388. CacheFlag = cli.IntFlag{
  389. Name: "cache",
  390. Usage: "Megabytes of memory allocated to internal caching (default = 4096 mainnet full node, 128 light mode)",
  391. Value: 1024,
  392. }
  393. CacheDatabaseFlag = cli.IntFlag{
  394. Name: "cache.database",
  395. Usage: "Percentage of cache memory allowance to use for database io",
  396. Value: 50,
  397. }
  398. CacheTrieFlag = cli.IntFlag{
  399. Name: "cache.trie",
  400. Usage: "Percentage of cache memory allowance to use for trie caching (default = 15% full mode, 30% archive mode)",
  401. Value: 15,
  402. }
  403. CacheTrieJournalFlag = cli.StringFlag{
  404. Name: "cache.trie.journal",
  405. Usage: "Disk journal directory for trie cache to survive node restarts",
  406. Value: ethconfig.Defaults.TrieCleanCacheJournal,
  407. }
  408. CacheTrieRejournalFlag = cli.DurationFlag{
  409. Name: "cache.trie.rejournal",
  410. Usage: "Time interval to regenerate the trie cache journal",
  411. Value: ethconfig.Defaults.TrieCleanCacheRejournal,
  412. }
  413. CacheGCFlag = cli.IntFlag{
  414. Name: "cache.gc",
  415. Usage: "Percentage of cache memory allowance to use for trie pruning (default = 25% full mode, 0% archive mode)",
  416. Value: 25,
  417. }
  418. CacheSnapshotFlag = cli.IntFlag{
  419. Name: "cache.snapshot",
  420. Usage: "Percentage of cache memory allowance to use for snapshot caching (default = 10% full mode, 20% archive mode)",
  421. Value: 10,
  422. }
  423. CacheNoPrefetchFlag = cli.BoolFlag{
  424. Name: "cache.noprefetch",
  425. Usage: "Disable heuristic state prefetch during block import (less CPU and disk IO, more time waiting for data)",
  426. }
  427. CachePreimagesFlag = cli.BoolFlag{
  428. Name: "cache.preimages",
  429. Usage: "Enable recording the SHA3/keccak preimages of trie keys",
  430. }
  431. // Miner settings
  432. MiningEnabledFlag = cli.BoolFlag{
  433. Name: "mine",
  434. Usage: "Enable mining",
  435. }
  436. MinerThreadsFlag = cli.IntFlag{
  437. Name: "miner.threads",
  438. Usage: "Number of CPU threads to use for mining",
  439. Value: 0,
  440. }
  441. MinerNotifyFlag = cli.StringFlag{
  442. Name: "miner.notify",
  443. Usage: "Comma separated HTTP URL list to notify of new work packages",
  444. }
  445. MinerNotifyFullFlag = cli.BoolFlag{
  446. Name: "miner.notify.full",
  447. Usage: "Notify with pending block headers instead of work packages",
  448. }
  449. MinerGasTargetFlag = cli.Uint64Flag{
  450. Name: "miner.gastarget",
  451. Usage: "Target gas floor for mined blocks",
  452. Value: ethconfig.Defaults.Miner.GasFloor,
  453. }
  454. MinerGasLimitFlag = cli.Uint64Flag{
  455. Name: "miner.gaslimit",
  456. Usage: "Target gas ceiling for mined blocks",
  457. Value: ethconfig.Defaults.Miner.GasCeil,
  458. }
  459. MinerGasPriceFlag = BigFlag{
  460. Name: "miner.gasprice",
  461. Usage: "Minimum gas price for mining a transaction",
  462. Value: ethconfig.Defaults.Miner.GasPrice,
  463. }
  464. MinerEtherbaseFlag = cli.StringFlag{
  465. Name: "miner.etherbase",
  466. Usage: "Public address for block mining rewards (default = first account)",
  467. Value: "0",
  468. }
  469. MinerExtraDataFlag = cli.StringFlag{
  470. Name: "miner.extradata",
  471. Usage: "Block extra data set by the miner (default = client version)",
  472. }
  473. MinerRecommitIntervalFlag = cli.DurationFlag{
  474. Name: "miner.recommit",
  475. Usage: "Time interval to recreate the block being mined",
  476. Value: ethconfig.Defaults.Miner.Recommit,
  477. }
  478. MinerNoVerfiyFlag = cli.BoolFlag{
  479. Name: "miner.noverify",
  480. Usage: "Disable remote sealing verification",
  481. }
  482. // Account settings
  483. UnlockedAccountFlag = cli.StringFlag{
  484. Name: "unlock",
  485. Usage: "Comma separated list of accounts to unlock",
  486. Value: "",
  487. }
  488. PasswordFileFlag = cli.StringFlag{
  489. Name: "password",
  490. Usage: "Password file to use for non-interactive password input",
  491. Value: "",
  492. }
  493. ExternalSignerFlag = cli.StringFlag{
  494. Name: "signer",
  495. Usage: "External signer (url or path to ipc file)",
  496. Value: "",
  497. }
  498. VMEnableDebugFlag = cli.BoolFlag{
  499. Name: "vmdebug",
  500. Usage: "Record information useful for VM and contract debugging",
  501. }
  502. InsecureUnlockAllowedFlag = cli.BoolFlag{
  503. Name: "allow-insecure-unlock",
  504. Usage: "Allow insecure account unlocking when account-related RPCs are exposed by http",
  505. }
  506. RPCGlobalGasCapFlag = cli.Uint64Flag{
  507. Name: "rpc.gascap",
  508. Usage: "Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)",
  509. Value: ethconfig.Defaults.RPCGasCap,
  510. }
  511. RPCGlobalTxFeeCapFlag = cli.Float64Flag{
  512. Name: "rpc.txfeecap",
  513. Usage: "Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap)",
  514. Value: ethconfig.Defaults.RPCTxFeeCap,
  515. }
  516. // Logging and debug settings
  517. EthStatsURLFlag = cli.StringFlag{
  518. Name: "ethstats",
  519. Usage: "Reporting URL of a ethstats service (nodename:secret@host:port)",
  520. }
  521. FakePoWFlag = cli.BoolFlag{
  522. Name: "fakepow",
  523. Usage: "Disables proof-of-work verification",
  524. }
  525. NoCompactionFlag = cli.BoolFlag{
  526. Name: "nocompaction",
  527. Usage: "Disables db compaction after import",
  528. }
  529. // Quorum
  530. // RPC Client Settings
  531. RPCClientToken = cli.StringFlag{
  532. Name: "rpcclitoken",
  533. Usage: "RPC Client access token",
  534. }
  535. RPCClientTLSCert = cli.StringFlag{
  536. Name: "rpcclitls.cert",
  537. Usage: "Server's TLS certificate PEM file on connection by client",
  538. }
  539. RPCClientTLSCaCert = cli.StringFlag{
  540. Name: "rpcclitls.cacert",
  541. Usage: "CA certificate PEM file for provided server's TLS certificate on connection by client",
  542. }
  543. RPCClientTLSCipherSuites = cli.StringFlag{
  544. Name: "rpcclitls.ciphersuites",
  545. Usage: "Customize supported cipher suites when using TLS connection. Value is a comma-separated cipher suite string",
  546. }
  547. RPCClientTLSInsecureSkipVerify = cli.BoolFlag{
  548. Name: "rpcclitls.insecureskipverify",
  549. Usage: "Disable verification of server's TLS certificate on connection by client",
  550. }
  551. // End Quorum
  552. // RPC settings
  553. IPCDisabledFlag = cli.BoolFlag{
  554. Name: "ipcdisable",
  555. Usage: "Disable the IPC-RPC server",
  556. }
  557. IPCPathFlag = DirectoryFlag{
  558. Name: "ipcpath",
  559. Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
  560. }
  561. HTTPEnabledFlag = cli.BoolFlag{
  562. Name: "http",
  563. Usage: "Enable the HTTP-RPC server",
  564. }
  565. HTTPListenAddrFlag = cli.StringFlag{
  566. Name: "http.addr",
  567. Usage: "HTTP-RPC server listening interface",
  568. Value: node.DefaultHTTPHost,
  569. }
  570. HTTPPortFlag = cli.IntFlag{
  571. Name: "http.port",
  572. Usage: "HTTP-RPC server listening port",
  573. Value: node.DefaultHTTPPort,
  574. }
  575. HTTPCORSDomainFlag = cli.StringFlag{
  576. Name: "http.corsdomain",
  577. Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
  578. Value: "",
  579. }
  580. HTTPVirtualHostsFlag = cli.StringFlag{
  581. Name: "http.vhosts",
  582. Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
  583. Value: strings.Join(node.DefaultConfig.HTTPVirtualHosts, ","),
  584. }
  585. HTTPApiFlag = cli.StringFlag{
  586. Name: "http.api",
  587. Usage: "API's offered over the HTTP-RPC interface",
  588. Value: "",
  589. }
  590. HTTPPathPrefixFlag = cli.StringFlag{
  591. Name: "http.rpcprefix",
  592. Usage: "HTTP path path prefix on which JSON-RPC is served. Use '/' to serve on all paths.",
  593. Value: "",
  594. }
  595. GraphQLEnabledFlag = cli.BoolFlag{
  596. Name: "graphql",
  597. Usage: "Enable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well.",
  598. }
  599. GraphQLCORSDomainFlag = cli.StringFlag{
  600. Name: "graphql.corsdomain",
  601. Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
  602. Value: "",
  603. }
  604. GraphQLVirtualHostsFlag = cli.StringFlag{
  605. Name: "graphql.vhosts",
  606. Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
  607. Value: strings.Join(node.DefaultConfig.GraphQLVirtualHosts, ","),
  608. }
  609. WSEnabledFlag = cli.BoolFlag{
  610. Name: "ws",
  611. Usage: "Enable the WS-RPC server",
  612. }
  613. WSListenAddrFlag = cli.StringFlag{
  614. Name: "ws.addr",
  615. Usage: "WS-RPC server listening interface",
  616. Value: node.DefaultWSHost,
  617. }
  618. WSPortFlag = cli.IntFlag{
  619. Name: "ws.port",
  620. Usage: "WS-RPC server listening port",
  621. Value: node.DefaultWSPort,
  622. }
  623. WSApiFlag = cli.StringFlag{
  624. Name: "ws.api",
  625. Usage: "API's offered over the WS-RPC interface",
  626. Value: "",
  627. }
  628. WSAllowedOriginsFlag = cli.StringFlag{
  629. Name: "ws.origins",
  630. Usage: "Origins from which to accept websockets requests",
  631. Value: "",
  632. }
  633. WSPathPrefixFlag = cli.StringFlag{
  634. Name: "ws.rpcprefix",
  635. Usage: "HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths.",
  636. Value: "",
  637. }
  638. ExecFlag = cli.StringFlag{
  639. Name: "exec",
  640. Usage: "Execute JavaScript statement",
  641. }
  642. PreloadJSFlag = cli.StringFlag{
  643. Name: "preload",
  644. Usage: "Comma separated list of JavaScript files to preload into the console",
  645. }
  646. AllowUnprotectedTxs = cli.BoolFlag{
  647. Name: "rpc.allow-unprotected-txs",
  648. Usage: "Allow for unprotected (non EIP155 signed) transactions to be submitted via RPC",
  649. }
  650. // Network Settings
  651. MaxPeersFlag = cli.IntFlag{
  652. Name: "maxpeers",
  653. Usage: "Maximum number of network peers (network disabled if set to 0)",
  654. Value: node.DefaultConfig.P2P.MaxPeers,
  655. }
  656. MaxPendingPeersFlag = cli.IntFlag{
  657. Name: "maxpendpeers",
  658. Usage: "Maximum number of pending connection attempts (defaults used if set to 0)",
  659. Value: node.DefaultConfig.P2P.MaxPendingPeers,
  660. }
  661. ListenPortFlag = cli.IntFlag{
  662. Name: "port",
  663. Usage: "Network listening port",
  664. Value: 30303,
  665. }
  666. BootnodesFlag = cli.StringFlag{
  667. Name: "bootnodes",
  668. Usage: "Comma separated enode URLs for P2P discovery bootstrap",
  669. Value: "",
  670. }
  671. NodeKeyFileFlag = cli.StringFlag{
  672. Name: "nodekey",
  673. Usage: "P2P node key file",
  674. }
  675. NodeKeyHexFlag = cli.StringFlag{
  676. Name: "nodekeyhex",
  677. Usage: "P2P node key as hex (for testing)",
  678. }
  679. NATFlag = cli.StringFlag{
  680. Name: "nat",
  681. Usage: "NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>)",
  682. Value: "any",
  683. }
  684. NoDiscoverFlag = cli.BoolFlag{
  685. Name: "nodiscover",
  686. Usage: "Disables the peer discovery mechanism (manual peer addition)",
  687. }
  688. DiscoveryV5Flag = cli.BoolFlag{
  689. Name: "v5disc",
  690. Usage: "Enables the experimental RLPx V5 (Topic Discovery) mechanism",
  691. }
  692. NetrestrictFlag = cli.StringFlag{
  693. Name: "netrestrict",
  694. Usage: "Restricts network communication to the given IP networks (CIDR masks)",
  695. }
  696. DNSDiscoveryFlag = cli.StringFlag{
  697. Name: "discovery.dns",
  698. Usage: "Sets DNS discovery entry points (use \"\" to disable DNS)",
  699. }
  700. // ATM the url is left to the user and deployment to
  701. JSpathFlag = cli.StringFlag{
  702. Name: "jspath",
  703. Usage: "JavaScript root path for `loadScript`",
  704. Value: ".",
  705. }
  706. // Gas price oracle settings
  707. GpoBlocksFlag = cli.IntFlag{
  708. Name: "gpo.blocks",
  709. Usage: "Number of recent blocks to check for gas prices",
  710. Value: ethconfig.Defaults.GPO.Blocks,
  711. }
  712. GpoPercentileFlag = cli.IntFlag{
  713. Name: "gpo.percentile",
  714. Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
  715. Value: ethconfig.Defaults.GPO.Percentile,
  716. }
  717. GpoMaxGasPriceFlag = cli.Int64Flag{
  718. Name: "gpo.maxprice",
  719. Usage: "Maximum gas price will be recommended by gpo",
  720. Value: ethconfig.Defaults.GPO.MaxPrice.Int64(),
  721. }
  722. // Metrics flags
  723. MetricsEnabledFlag = cli.BoolFlag{
  724. Name: "metrics",
  725. Usage: "Enable metrics collection and reporting",
  726. }
  727. MetricsEnabledExpensiveFlag = cli.BoolFlag{
  728. Name: "metrics.expensive",
  729. Usage: "Enable expensive metrics collection and reporting",
  730. }
  731. // MetricsHTTPFlag defines the endpoint for a stand-alone metrics HTTP endpoint.
  732. // Since the pprof service enables sensitive/vulnerable behavior, this allows a user
  733. // to enable a public-OK metrics endpoint without having to worry about ALSO exposing
  734. // other profiling behavior or information.
  735. MetricsHTTPFlag = cli.StringFlag{
  736. Name: "metrics.addr",
  737. Usage: "Enable stand-alone metrics HTTP server listening interface",
  738. Value: metrics.DefaultConfig.HTTP,
  739. }
  740. MetricsPortFlag = cli.IntFlag{
  741. Name: "metrics.port",
  742. Usage: "Metrics HTTP server listening port",
  743. Value: metrics.DefaultConfig.Port,
  744. }
  745. MetricsEnableInfluxDBFlag = cli.BoolFlag{
  746. Name: "metrics.influxdb",
  747. Usage: "Enable metrics export/push to an external InfluxDB database",
  748. }
  749. MetricsInfluxDBEndpointFlag = cli.StringFlag{
  750. Name: "metrics.influxdb.endpoint",
  751. Usage: "InfluxDB API endpoint to report metrics to",
  752. Value: metrics.DefaultConfig.InfluxDBEndpoint,
  753. }
  754. MetricsInfluxDBDatabaseFlag = cli.StringFlag{
  755. Name: "metrics.influxdb.database",
  756. Usage: "InfluxDB database name to push reported metrics to",
  757. Value: metrics.DefaultConfig.InfluxDBDatabase,
  758. }
  759. MetricsInfluxDBUsernameFlag = cli.StringFlag{
  760. Name: "metrics.influxdb.username",
  761. Usage: "Username to authorize access to the database",
  762. Value: metrics.DefaultConfig.InfluxDBUsername,
  763. }
  764. MetricsInfluxDBPasswordFlag = cli.StringFlag{
  765. Name: "metrics.influxdb.password",
  766. Usage: "Password to authorize access to the database",
  767. Value: metrics.DefaultConfig.InfluxDBPassword,
  768. }
  769. // Tags are part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
  770. // For example `host` tag could be used so that we can group all nodes and average a measurement
  771. // across all of them, but also so that we can select a specific node and inspect its measurements.
  772. // https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
  773. MetricsInfluxDBTagsFlag = cli.StringFlag{
  774. Name: "metrics.influxdb.tags",
  775. Usage: "Comma-separated InfluxDB tags (key/values) attached to all measurements",
  776. Value: metrics.DefaultConfig.InfluxDBTags,
  777. }
  778. EWASMInterpreterFlag = cli.StringFlag{
  779. Name: "vm.ewasm",
  780. Usage: "External ewasm configuration (default = built-in interpreter)",
  781. Value: "",
  782. }
  783. EVMInterpreterFlag = cli.StringFlag{
  784. Name: "vm.evm",
  785. Usage: "External EVM configuration (default = built-in interpreter)",
  786. Value: "",
  787. }
  788. CatalystFlag = cli.BoolFlag{
  789. Name: "catalyst",
  790. Usage: "Catalyst mode (eth2 integration testing)",
  791. }
  792. // Quorum - added configurable call timeout for execution of calls
  793. EVMCallTimeOutFlag = cli.IntFlag{
  794. Name: "vm.calltimeout",
  795. Usage: "Timeout duration in seconds for message call execution without creating a transaction. Value 0 means no timeout.",
  796. Value: 5,
  797. }
  798. // Quorum
  799. // immutability threshold which can be passed as a parameter at geth start
  800. QuorumImmutabilityThreshold = cli.IntFlag{
  801. Name: "immutabilitythreshold",
  802. Usage: "overrides the default immutability threshold for Quorum nodes. Its the threshold beyond which block data will be moved to ancient db",
  803. Value: 3162240,
  804. }
  805. // Raft flags
  806. RaftModeFlag = cli.BoolFlag{
  807. Name: "raft",
  808. Usage: "If enabled, uses Raft instead of Quorum Chain for consensus",
  809. }
  810. RaftBlockTimeFlag = cli.IntFlag{
  811. Name: "raftblocktime",
  812. Usage: "Amount of time between raft block creations in milliseconds",
  813. Value: 50,
  814. }
  815. RaftJoinExistingFlag = cli.IntFlag{
  816. Name: "raftjoinexisting",
  817. Usage: "The raft ID to assume when joining an pre-existing cluster",
  818. Value: 0,
  819. }
  820. EmitCheckpointsFlag = cli.BoolFlag{
  821. Name: "emitcheckpoints",
  822. Usage: "If enabled, emit specially formatted logging checkpoints",
  823. }
  824. RaftPortFlag = cli.IntFlag{
  825. Name: "raftport",
  826. Usage: "The port to bind for the raft transport",
  827. Value: 50400,
  828. }
  829. RaftDNSEnabledFlag = cli.BoolFlag{
  830. Name: "raftdnsenable",
  831. Usage: "Enable DNS resolution of peers",
  832. }
  833. // Permission
  834. EnableNodePermissionFlag = cli.BoolFlag{
  835. Name: "permissioned",
  836. Usage: "If enabled, the node will allow only a defined list of nodes to connect",
  837. }
  838. AllowedFutureBlockTimeFlag = cli.Uint64Flag{
  839. Name: "allowedfutureblocktime",
  840. Usage: "Max time (in seconds) from current time allowed for blocks, before they're considered future blocks",
  841. Value: 0,
  842. }
  843. // Plugins settings
  844. PluginSettingsFlag = cli.StringFlag{
  845. Name: "plugins",
  846. Usage: "The URI of configuration which describes plugins being used. E.g.: file:///opt/geth/plugins.json",
  847. }
  848. PluginLocalVerifyFlag = cli.BoolFlag{
  849. Name: "plugins.localverify",
  850. Usage: "If enabled, verify plugin integrity from local file system. This requires plugin signature file and PGP public key file to be available",
  851. }
  852. PluginPublicKeyFlag = cli.StringFlag{
  853. Name: "plugins.publickey",
  854. Usage: fmt.Sprintf("The URI of PGP public key for local plugin verification. E.g.: file:///opt/geth/pubkey.pgp.asc. This flag is only valid if --%s is set (default = file:///<pluginBaseDir>/%s)", PluginLocalVerifyFlag.Name, plugin.DefaultPublicKeyFile),
  855. }
  856. PluginSkipVerifyFlag = cli.BoolFlag{
  857. Name: "plugins.skipverify",
  858. Usage: "If enabled, plugin integrity is NOT verified",
  859. }
  860. // account plugin flags
  861. AccountPluginNewAccountConfigFlag = cli.StringFlag{
  862. Name: "plugins.account.config",
  863. Usage: "Value will be passed to an account plugin if being used. See the account plugin implementation's documentation for further details",
  864. }
  865. // Istanbul settings
  866. IstanbulRequestTimeoutFlag = cli.Uint64Flag{
  867. Name: "istanbul.requesttimeout",
  868. Usage: "[Deprecated] Timeout for each Istanbul round in milliseconds",
  869. Value: ethconfig.Defaults.Istanbul.RequestTimeout,
  870. }
  871. IstanbulBlockPeriodFlag = cli.Uint64Flag{
  872. Name: "istanbul.blockperiod",
  873. Usage: "[Deprecated] Default minimum difference between two consecutive block's timestamps in seconds",
  874. Value: ethconfig.Defaults.Istanbul.BlockPeriod,
  875. }
  876. // Multitenancy setting
  877. MultitenancyFlag = cli.BoolFlag{
  878. Name: "multitenancy",
  879. Usage: "Enable multitenancy support for this node. This requires RPC Security Plugin to also be configured.",
  880. }
  881. // Revert Reason
  882. RevertReasonFlag = cli.BoolFlag{
  883. Name: "revertreason",
  884. Usage: "Enable saving revert reason in the transaction receipts for this node.",
  885. }
  886. QuorumEnablePrivateTrieCache = cli.BoolFlag{
  887. Name: "privatetriecache.enable",
  888. Usage: "Enable use of private trie cache for this node.",
  889. }
  890. QuorumEnablePrivacyMarker = cli.BoolFlag{
  891. Name: "privacymarker.enable",
  892. Usage: "Enable use of privacy marker transactions (PMT) for this node.",
  893. }
  894. // Quorum Private Transaction Manager connection options
  895. QuorumPTMUnixSocketFlag = DirectoryFlag{
  896. Name: "ptm.socket",
  897. Usage: "Path to the ipc file when using unix domain socket for the private transaction manager connection",
  898. }
  899. QuorumPTMUrlFlag = cli.StringFlag{
  900. Name: "ptm.url",
  901. Usage: "URL when using http connection to private transaction manager",
  902. }
  903. QuorumPTMTimeoutFlag = cli.UintFlag{
  904. Name: "ptm.timeout",
  905. Usage: "Timeout (seconds) for the private transaction manager connection. Zero value means timeout disabled.",
  906. Value: http2.DefaultConfig.Timeout,
  907. }
  908. QuorumPTMDialTimeoutFlag = cli.UintFlag{
  909. Name: "ptm.dialtimeout",
  910. Usage: "Dial timeout (seconds) for the private transaction manager connection. Zero value means timeout disabled.",
  911. Value: http2.DefaultConfig.DialTimeout,
  912. }
  913. QuorumPTMHttpIdleTimeoutFlag = cli.UintFlag{
  914. Name: "ptm.http.idletimeout",
  915. Usage: "Idle timeout (seconds) for the private transaction manager connection. Zero value means timeout disabled.",
  916. Value: http2.DefaultConfig.HttpIdleConnTimeout,
  917. }
  918. QuorumPTMHttpWriteBufferSizeFlag = cli.IntFlag{
  919. Name: "ptm.http.writebuffersize",
  920. Usage: "Size of the write buffer (bytes) for the private transaction manager connection. Zero value uses http.Transport default.",
  921. Value: 0,
  922. }
  923. QuorumPTMHttpReadBufferSizeFlag = cli.IntFlag{
  924. Name: "ptm.http.readbuffersize",
  925. Usage: "Size of the read buffer (bytes) for the private transaction manager connection. Zero value uses http.Transport default.",
  926. Value: 0,
  927. }
  928. QuorumPTMTlsModeFlag = cli.StringFlag{
  929. Name: "ptm.tls.mode",
  930. Usage: `If "off" then TLS disabled (default). If "strict" then will use TLS for http connection to private transaction manager`,
  931. }
  932. QuorumPTMTlsRootCaFlag = DirectoryFlag{
  933. Name: "ptm.tls.rootca",
  934. Usage: "Path to file containing root CA certificate for TLS connection to private transaction manager (defaults to host's certificates)",
  935. }
  936. QuorumPTMTlsClientCertFlag = DirectoryFlag{
  937. Name: "ptm.tls.clientcert",
  938. Usage: "Path to file containing client certificate (or chain of certs) for TLS connection to private transaction manager",
  939. }
  940. QuorumPTMTlsClientKeyFlag = DirectoryFlag{
  941. Name: "ptm.tls.clientkey",
  942. Usage: "Path to file containing client's private key for TLS connection to private transaction manager",
  943. }
  944. QuorumPTMTlsInsecureSkipVerify = cli.BoolFlag{
  945. Name: "ptm.tls.insecureskipverify",
  946. Usage: "Disable verification of server's TLS certificate on connection to private transaction manager",
  947. }
  948. QuorumLightServerFlag = cli.BoolFlag{
  949. Name: "qlight.server",
  950. Usage: "If enabled, the quorum light P2P protocol is started in addition to the other P2P protocols",
  951. }
  952. QuorumLightServerP2PListenPortFlag = cli.IntFlag{
  953. Name: "qlight.server.p2p.port",
  954. Usage: "QLight Network listening port",
  955. Value: 30305,
  956. }
  957. QuorumLightServerP2PMaxPeersFlag = cli.IntFlag{
  958. Name: "qlight.server.p2p.maxpeers",
  959. Usage: "Maximum number of qlight peers",
  960. Value: 10,
  961. }
  962. QuorumLightServerP2PNetrestrictFlag = cli.StringFlag{
  963. Name: "qlight.server.p2p.netrestrict",
  964. Usage: "Restricts network communication to the given IP networks (CIDR masks)",
  965. }
  966. QuorumLightServerP2PPermissioningFlag = cli.BoolFlag{
  967. Name: "qlight.server.p2p.permissioning",
  968. Usage: "If enabled, the qlight peers are checked against a permissioned list and a disallowed list.",
  969. }
  970. QuorumLightServerP2PPermissioningPrefixFlag = cli.StringFlag{
  971. Name: "qlight.server.p2p.permissioning.prefix",
  972. Usage: "The prefix for the permissioned-nodes.json and disallowed-nodes.json files.",
  973. }
  974. QuorumLightClientFlag = cli.BoolFlag{
  975. Name: "qlight.client",
  976. Usage: "If enabled, the quorum light client P2P protocol is started (only)",
  977. }
  978. QuorumLightClientPSIFlag = cli.StringFlag{
  979. Name: "qlight.client.psi",
  980. Usage: "The PSI this client will use to connect to a server node.",
  981. }
  982. QuorumLightClientTokenEnabledFlag = cli.BoolFlag{
  983. Name: "qlight.client.token.enabled",
  984. Usage: "Whether the client uses a token when connecting to the qlight server.",
  985. }
  986. QuorumLightClientTokenValueFlag = cli.StringFlag{
  987. Name: "qlight.client.token.value",
  988. Usage: "The token this client will use to connect to a server node.",
  989. }
  990. QuorumLightClientTokenManagementFlag = cli.StringFlag{
  991. Name: "qlight.client.token.management",
  992. Usage: "The mechanism used to refresh the token. Possible values: none (developer mode)/external (new token must be injected via the qlight RPC API)/client-security-plugin (the client security plugin must be deployed/configured).",
  993. }
  994. QuorumLightClientRPCTLSFlag = cli.BoolFlag{
  995. Name: "qlight.client.rpc.tls",
  996. Usage: "If enabled, the quorum light client RPC connection will be configured to use TLS",
  997. }
  998. QuorumLightClientRPCTLSInsecureSkipVerifyFlag = cli.BoolFlag{
  999. Name: "qlight.client.rpc.tls.insecureskipverify",
  1000. Usage: "If enabled, the quorum light client RPC connection skips TLS verification",
  1001. }
  1002. QuorumLightClientRPCTLSCACertFlag = cli.StringFlag{
  1003. Name: "qlight.client.rpc.tls.cacert",
  1004. Usage: "The quorum light client RPC client certificate authority.",
  1005. }
  1006. QuorumLightClientRPCTLSCertFlag = cli.StringFlag{
  1007. Name: "qlight.client.rpc.tls.cert",
  1008. Usage: "The quorum light client RPC client certificate.",
  1009. }
  1010. QuorumLightClientRPCTLSKeyFlag = cli.StringFlag{
  1011. Name: "qlight.client.rpc.tls.key",
  1012. Usage: "The quorum light client RPC client certificate private key.",
  1013. }
  1014. QuorumLightClientServerNodeFlag = cli.StringFlag{
  1015. Name: "qlight.client.serverNode",
  1016. Usage: "The node ID of the target server node",
  1017. }
  1018. QuorumLightClientServerNodeRPCFlag = cli.StringFlag{
  1019. Name: "qlight.client.serverNodeRPC",
  1020. Usage: "The RPC URL of the target server node",
  1021. }
  1022. QuorumLightTLSFlag = cli.BoolFlag{
  1023. Name: "qlight.tls",
  1024. Usage: "If enabled, the quorum light client P2P protocol will use tls",
  1025. }
  1026. QuorumLightTLSCertFlag = cli.StringFlag{
  1027. Name: "qlight.tls.cert",
  1028. Usage: "The certificate file to use for the qlight P2P connection",
  1029. }
  1030. QuorumLightTLSKeyFlag = cli.StringFlag{
  1031. Name: "qlight.tls.key",
  1032. Usage: "The key file to use for the qlight P2P connection",
  1033. }
  1034. QuorumLightTLSCACertsFlag = cli.StringFlag{
  1035. Name: "qlight.tls.cacerts",
  1036. Usage: "The certificate authorities file to use for validating P2P connection",
  1037. }
  1038. QuorumLightTLSClientAuthFlag = cli.IntFlag{
  1039. Name: "qlight.tls.clientauth",
  1040. Usage: "The way the client is authenticated. Possible values: 0=NoClientCert(default) 1=RequestClientCert 2=RequireAnyClientCert 3=VerifyClientCertIfGiven 4=RequireAndVerifyClientCert",
  1041. Value: 0,
  1042. }
  1043. QuorumLightTLSCipherSuitesFlag = cli.StringFlag{
  1044. Name: "qlight.tls.ciphersuites",
  1045. Usage: "The cipher suites to use for the qlight P2P connection",
  1046. }
  1047. )
  1048. // MakeDataDir retrieves the currently requested data directory, terminating
  1049. // if none (or the empty string) is specified. If the node is starting a testnet,
  1050. // then a subdirectory of the specified datadir will be used.
  1051. func MakeDataDir(ctx *cli.Context) string {
  1052. if path := ctx.GlobalString(DataDirFlag.Name); path != "" {
  1053. if ctx.GlobalBool(RopstenFlag.Name) {
  1054. // Maintain compatibility with older Geth configurations storing the
  1055. // Ropsten database in `testnet` instead of `ropsten`.
  1056. return filepath.Join(path, "ropsten")
  1057. }
  1058. if ctx.GlobalBool(RinkebyFlag.Name) {
  1059. return filepath.Join(path, "rinkeby")
  1060. }
  1061. if ctx.GlobalBool(GoerliFlag.Name) {
  1062. return filepath.Join(path, "goerli")
  1063. }
  1064. if ctx.GlobalBool(YoloV3Flag.Name) {
  1065. return filepath.Join(path, "yolo-v3")
  1066. }
  1067. return path
  1068. }
  1069. Fatalf("Cannot determine default data directory, please set manually (--datadir)")
  1070. return ""
  1071. }
  1072. // setNodeKey creates a node key from set command line flags, either loading it
  1073. // from a file or as a specified hex value. If neither flags were provided, this
  1074. // method returns nil and an emphemeral key is to be generated.
  1075. func setNodeKey(ctx *cli.Context, cfg *p2p.Config) {
  1076. var (
  1077. hex = ctx.GlobalString(NodeKeyHexFlag.Name)
  1078. file = ctx.GlobalString(NodeKeyFileFlag.Name)
  1079. key *ecdsa.PrivateKey
  1080. err error
  1081. )
  1082. switch {
  1083. case file != "" && hex != "":
  1084. Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)
  1085. case file != "":
  1086. if key, err = crypto.LoadECDSA(file); err != nil {
  1087. Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err)
  1088. }
  1089. cfg.PrivateKey = key
  1090. case hex != "":
  1091. if key, err = crypto.HexToECDSA(hex); err != nil {
  1092. Fatalf("Option %q: %v", NodeKeyHexFlag.Name, err)
  1093. }
  1094. cfg.PrivateKey = key
  1095. }
  1096. }
  1097. // setNodeUserIdent creates the user identifier from CLI flags.
  1098. func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
  1099. if identity := ctx.GlobalString(IdentityFlag.Name); len(identity) > 0 {
  1100. cfg.UserIdent = identity
  1101. }
  1102. }
  1103. // setBootstrapNodes creates a list of bootstrap nodes from the command line
  1104. // flags, reverting to pre-configured ones if none have been specified.
  1105. func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
  1106. urls := params.MainnetBootnodes
  1107. switch {
  1108. case ctx.GlobalIsSet(BootnodesFlag.Name):
  1109. urls = SplitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
  1110. case ctx.GlobalBool(RopstenFlag.Name):
  1111. urls = params.RopstenBootnodes
  1112. case ctx.GlobalBool(RinkebyFlag.Name):
  1113. urls = params.RinkebyBootnodes
  1114. case ctx.GlobalBool(GoerliFlag.Name):
  1115. urls = params.GoerliBootnodes
  1116. case ctx.GlobalBool(YoloV3Flag.Name):
  1117. urls = params.YoloV3Bootnodes
  1118. case cfg.BootstrapNodes != nil:
  1119. return // already set, don't apply defaults.
  1120. }
  1121. cfg.BootstrapNodes = make([]*enode.Node, 0, len(urls))
  1122. for _, url := range urls {
  1123. if url != "" {
  1124. node, err := enode.Parse(enode.ValidSchemes, url)
  1125. if err != nil {
  1126. log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
  1127. continue
  1128. }
  1129. cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
  1130. }
  1131. }
  1132. }
  1133. // setBootstrapNodesV5 creates a list of bootstrap nodes from the command line
  1134. // flags, reverting to pre-configured ones if none have been specified.
  1135. func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
  1136. urls := params.V5Bootnodes
  1137. switch {
  1138. case ctx.GlobalIsSet(BootnodesFlag.Name):
  1139. urls = SplitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
  1140. case cfg.BootstrapNodesV5 != nil:
  1141. return // already set, don't apply defaults.
  1142. }
  1143. cfg.BootstrapNodesV5 = make([]*enode.Node, 0, len(urls))
  1144. for _, url := range urls {
  1145. if url != "" {
  1146. node, err := enode.Parse(enode.ValidSchemes, url)
  1147. if err != nil {
  1148. log.Error("Bootstrap URL invalid", "enode", url, "err", err)
  1149. continue
  1150. }
  1151. cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
  1152. }
  1153. }
  1154. }
  1155. // setListenAddress creates a TCP listening address string from set command
  1156. // line flags.
  1157. func setListenAddress(ctx *cli.Context, cfg *p2p.Config) {
  1158. if ctx.GlobalIsSet(ListenPortFlag.Name) {
  1159. cfg.ListenAddr = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name))
  1160. }
  1161. }
  1162. // setNAT creates a port mapper from command line flags.
  1163. func setNAT(ctx *cli.Context, cfg *p2p.Config) {
  1164. if ctx.GlobalIsSet(NATFlag.Name) {
  1165. natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
  1166. if err != nil {
  1167. Fatalf("Option %s: %v", NATFlag.Name, err)
  1168. }
  1169. cfg.NAT = natif
  1170. }
  1171. }
  1172. // SplitAndTrim splits input separated by a comma
  1173. // and trims excessive white space from the substrings.
  1174. func SplitAndTrim(input string) (ret []string) {
  1175. l := strings.Split(input, ",")
  1176. for _, r := range l {
  1177. if r = strings.TrimSpace(r); r != "" {
  1178. ret = append(ret, r)
  1179. }
  1180. }
  1181. return ret
  1182. }
  1183. // setHTTP creates the HTTP RPC listener interface string from the set
  1184. // command line flags, returning empty if the HTTP endpoint is disabled.
  1185. func setHTTP(ctx *cli.Context, cfg *node.Config) {
  1186. if ctx.GlobalBool(LegacyRPCEnabledFlag.Name) && cfg.HTTPHost == "" {
  1187. log.Warn("The flag --rpc is deprecated and will be removed in the future, please use --http")
  1188. cfg.HTTPHost = "127.0.0.1"
  1189. if ctx.GlobalIsSet(LegacyRPCListenAddrFlag.Name) {
  1190. cfg.HTTPHost = ctx.GlobalString(LegacyRPCListenAddrFlag.Name)
  1191. log.Warn("The flag --rpcaddr is deprecated and will be removed in the future, please use --http.addr")
  1192. }
  1193. }
  1194. if ctx.GlobalBool(HTTPEnabledFlag.Name) && cfg.HTTPHost == "" {
  1195. cfg.HTTPHost = "127.0.0.1"
  1196. if ctx.GlobalIsSet(HTTPListenAddrFlag.Name) {
  1197. cfg.HTTPHost = ctx.GlobalString(HTTPListenAddrFlag.Name)
  1198. }
  1199. }
  1200. if ctx.GlobalIsSet(LegacyRPCPortFlag.Name) {
  1201. cfg.HTTPPort = ctx.GlobalInt(LegacyRPCPortFlag.Name)
  1202. log.Warn("The flag --rpcport is deprecated and will be removed in the future, please use --http.port")
  1203. }
  1204. if ctx.GlobalIsSet(HTTPPortFlag.Name) {
  1205. cfg.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
  1206. }
  1207. if ctx.GlobalIsSet(LegacyRPCCORSDomainFlag.Name) {
  1208. cfg.HTTPCors = SplitAndTrim(ctx.GlobalString(LegacyRPCCORSDomainFlag.Name))
  1209. log.Warn("The flag --rpccorsdomain is deprecated and will be removed in the future, please use --http.corsdomain")
  1210. }
  1211. if ctx.GlobalIsSet(HTTPCORSDomainFlag.Name) {
  1212. cfg.HTTPCors = SplitAndTrim(ctx.GlobalString(HTTPCORSDomainFlag.Name))
  1213. }
  1214. if ctx.GlobalIsSet(LegacyRPCApiFlag.Name) {
  1215. cfg.HTTPModules = SplitAndTrim(ctx.GlobalString(LegacyRPCApiFlag.Name))
  1216. log.Warn("The flag --rpcapi is deprecated and will be removed in the future, please use --http.api")
  1217. }
  1218. if ctx.GlobalIsSet(HTTPApiFlag.Name) {
  1219. cfg.HTTPModules = SplitAndTrim(ctx.GlobalString(HTTPApiFlag.Name))
  1220. }
  1221. if ctx.GlobalIsSet(LegacyRPCVirtualHostsFlag.Name) {
  1222. cfg.HTTPVirtualHosts = SplitAndTrim(ctx.GlobalString(LegacyRPCVirtualHostsFlag.Name))
  1223. log.Warn("The flag --rpcvhosts is deprecated and will be removed in the future, please use --http.vhosts")
  1224. }
  1225. if ctx.GlobalIsSet(HTTPVirtualHostsFlag.Name) {
  1226. cfg.HTTPVirtualHosts = SplitAndTrim(ctx.GlobalString(HTTPVirtualHostsFlag.Name))
  1227. }
  1228. if ctx.GlobalIsSet(HTTPPathPrefixFlag.Name) {
  1229. cfg.HTTPPathPrefix = ctx.GlobalString(HTTPPathPrefixFlag.Name)
  1230. }
  1231. if ctx.GlobalIsSet(AllowUnprotectedTxs.Name) {
  1232. cfg.AllowUnprotectedTxs = ctx.GlobalBool(AllowUnprotectedTxs.Name)
  1233. }
  1234. }
  1235. // setGraphQL creates the GraphQL listener interface string from the set
  1236. // command line flags, returning empty if the GraphQL endpoint is disabled.
  1237. func setGraphQL(ctx *cli.Context, cfg *node.Config) {
  1238. if ctx.GlobalIsSet(GraphQLCORSDomainFlag.Name) {
  1239. cfg.GraphQLCors = SplitAndTrim(ctx.GlobalString(GraphQLCORSDomainFlag.Name))
  1240. }
  1241. if ctx.GlobalIsSet(GraphQLVirtualHostsFlag.Name) {
  1242. cfg.GraphQLVirtualHosts = SplitAndTrim(ctx.GlobalString(GraphQLVirtualHostsFlag.Name))
  1243. }
  1244. }
  1245. // setWS creates the WebSocket RPC listener interface string from the set
  1246. // command line flags, returning empty if the HTTP endpoint is disabled.
  1247. func setWS(ctx *cli.Context, cfg *node.Config) {
  1248. if ctx.GlobalBool(WSEnabledFlag.Name) && cfg.WSHost == "" {
  1249. cfg.WSHost = "127.0.0.1"
  1250. if ctx.GlobalIsSet(WSListenAddrFlag.Name) {
  1251. cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name)
  1252. }
  1253. }
  1254. if ctx.GlobalIsSet(WSPortFlag.Name) {
  1255. cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
  1256. }
  1257. if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) {
  1258. cfg.WSOrigins = SplitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name))
  1259. }
  1260. if ctx.GlobalIsSet(WSApiFlag.Name) {
  1261. cfg.WSModules = SplitAndTrim(ctx.GlobalString(WSApiFlag.Name))
  1262. }
  1263. if ctx.GlobalIsSet(WSPathPrefixFlag.Name) {
  1264. cfg.WSPathPrefix = ctx.GlobalString(WSPathPrefixFlag.Name)
  1265. }
  1266. }
  1267. // setIPC creates an IPC path configuration from the set command line flags,
  1268. // returning an empty string if IPC was explicitly disabled, or the set path.
  1269. func setIPC(ctx *cli.Context, cfg *node.Config) {
  1270. CheckExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
  1271. switch {
  1272. case ctx.GlobalBool(IPCDisabledFlag.Name):
  1273. cfg.IPCPath = ""
  1274. case ctx.GlobalIsSet(IPCPathFlag.Name):
  1275. cfg.IPCPath = ctx.GlobalString(IPCPathFlag.Name)
  1276. }
  1277. }
  1278. // setLes configures the les server and ultra light client settings from the command line flags.
  1279. func setLes(ctx *cli.Context, cfg *ethconfig.Config) {
  1280. if ctx.GlobalIsSet(LightServeFlag.Name) {
  1281. cfg.LightServ = ctx.GlobalInt(LightServeFlag.Name)
  1282. }
  1283. if ctx.GlobalIsSet(LightIngressFlag.Name) {
  1284. cfg.LightIngress = ctx.GlobalInt(LightIngressFlag.Name)
  1285. }
  1286. if ctx.GlobalIsSet(LightEgressFlag.Name) {
  1287. cfg.LightEgress = ctx.GlobalInt(LightEgressFlag.Name)
  1288. }
  1289. if ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
  1290. cfg.LightPeers = ctx.GlobalInt(LightMaxPeersFlag.Name)
  1291. }
  1292. if ctx.GlobalIsSet(UltraLightServersFlag.Name) {
  1293. cfg.UltraLightServers = strings.Split(ctx.GlobalString(UltraLightServersFlag.Name), ",")
  1294. }
  1295. if ctx.GlobalIsSet(UltraLightFractionFlag.Name) {
  1296. cfg.UltraLightFraction = ctx.GlobalInt(UltraLightFractionFlag.Name)
  1297. }
  1298. if cfg.UltraLightFraction <= 0 && cfg.UltraLightFraction > 100 {
  1299. log.Error("Ultra light fraction is invalid", "had", cfg.UltraLightFraction, "updated", ethconfig.Defaults.UltraLightFraction)
  1300. cfg.UltraLightFraction = ethconfig.Defaults.UltraLightFraction
  1301. }
  1302. if ctx.GlobalIsSet(UltraLightOnlyAnnounceFlag.Name) {
  1303. cfg.UltraLightOnlyAnnounce = ctx.GlobalBool(UltraLightOnlyAnnounceFlag.Name)
  1304. }
  1305. if ctx.GlobalIsSet(LightNoPruneFlag.Name) {
  1306. cfg.LightNoPrune = ctx.GlobalBool(LightNoPruneFlag.Name)
  1307. }
  1308. if ctx.GlobalIsSet(LightNoSyncServeFlag.Name) {
  1309. cfg.LightNoSyncServe = ctx.GlobalBool(LightNoSyncServeFlag.Name)
  1310. }
  1311. }
  1312. // MakeDatabaseHandles raises out the number of allowed file handles per process
  1313. // for Geth and returns half of the allowance to assign to the database.
  1314. func MakeDatabaseHandles() int {
  1315. limit, err := fdlimit.Maximum()
  1316. if err != nil {
  1317. Fatalf("Failed to retrieve file descriptor allowance: %v", err)
  1318. }
  1319. raised, err := fdlimit.Raise(uint64(limit))
  1320. if err != nil {
  1321. Fatalf("Failed to raise file descriptor allowance: %v", err)
  1322. }
  1323. return int(raised / 2) // Leave half for networking and other stuff
  1324. }
  1325. // MakeAddress converts an account specified directly as a hex encoded string or
  1326. // a key index in the key store to an internal account representation.
  1327. func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error) {
  1328. // If the specified account is a valid address, return it
  1329. if common.IsHexAddress(account) {
  1330. return accounts.Account{Address: common.HexToAddress(account)}, nil
  1331. }
  1332. // Otherwise try to interpret the account as a keystore index
  1333. index, err := strconv.Atoi(account)
  1334. if err != nil || index < 0 {
  1335. return accounts.Account{}, fmt.Errorf("invalid account address or index %q", account)
  1336. }
  1337. log.Warn("-------------------------------------------------------------------")
  1338. log.Warn("Referring to accounts by order in the keystore folder is dangerous!")
  1339. log.Warn("This functionality is deprecated and will be removed in the future!")
  1340. log.Warn("Please use explicit addresses! (can search via `geth account list`)")
  1341. log.Warn("-------------------------------------------------------------------")
  1342. accs := ks.Accounts()
  1343. if len(accs) <= index {
  1344. return accounts.Account{}, fmt.Errorf("index %d higher than number of accounts %d", index, len(accs))
  1345. }
  1346. return accs[index], nil
  1347. }
  1348. // setEtherbase retrieves the etherbase either from the directly specified
  1349. // command line flags or from the keystore if CLI indexed.
  1350. func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *ethconfig.Config) {
  1351. // Extract the current etherbase
  1352. var etherbase string
  1353. if ctx.GlobalIsSet(MinerEtherbaseFlag.Name) {
  1354. etherbase = ctx.GlobalString(MinerEtherbaseFlag.Name)
  1355. }
  1356. // Convert the etherbase into an address and configure it
  1357. if etherbase != "" {
  1358. if ks != nil {
  1359. account, err := MakeAddress(ks, etherbase)
  1360. if err != nil {
  1361. Fatalf("Invalid miner etherbase: %v", err)
  1362. }
  1363. cfg.Miner.Etherbase = account.Address
  1364. } else {
  1365. Fatalf("No etherbase configured")
  1366. }
  1367. }
  1368. }
  1369. // MakePasswordList reads password lines from the file specified by the global --password flag.
  1370. func MakePasswordList(ctx *cli.Context) []string {
  1371. path := ctx.GlobalString(PasswordFileFlag.Name)
  1372. if path == "" {
  1373. return nil
  1374. }
  1375. text, err := ioutil.ReadFile(path)
  1376. if err != nil {
  1377. Fatalf("Failed to read password file: %v", err)
  1378. }
  1379. lines := strings.Split(string(text), "\n")
  1380. // Sanitise DOS line endings.
  1381. for i := range lines {
  1382. lines[i] = strings.TrimRight(lines[i], "\r")
  1383. }
  1384. return lines
  1385. }
  1386. func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
  1387. setNodeKey(ctx, cfg)
  1388. setNAT(ctx, cfg)
  1389. setListenAddress(ctx, cfg)
  1390. setBootstrapNodes(ctx, cfg)
  1391. setBootstrapNodesV5(ctx, cfg)
  1392. lightClient := ctx.GlobalString(SyncModeFlag.Name) == "light"
  1393. lightServer := (ctx.GlobalInt(LightServeFlag.Name) != 0)
  1394. lightPeers := ctx.GlobalInt(LightMaxPeersFlag.Name)
  1395. if lightClient && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
  1396. // dynamic default - for clients we use 1/10th of the default for servers
  1397. lightPeers /= 10
  1398. }
  1399. if ctx.GlobalIsSet(MaxPeersFlag.Name) {
  1400. cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
  1401. if lightServer && !ctx.GlobalIsSet(LightMaxPeersFlag.Name) {
  1402. cfg.MaxPeers += lightPeers
  1403. }
  1404. } else {
  1405. if lightServer {
  1406. cfg.MaxPeers += lightPeers
  1407. }
  1408. if lightClient && ctx.GlobalIsSet(LightMaxPeersFlag.Name) && cfg.MaxPeers < lightPeers {
  1409. cfg.MaxPeers = lightPeers
  1410. }
  1411. }
  1412. if !(lightClient || lightServer) {
  1413. lightPeers = 0
  1414. }
  1415. ethPeers := cfg.MaxPeers - lightPeers
  1416. if lightClient {
  1417. ethPeers = 0
  1418. }
  1419. log.Info("Maximum peer count", "ETH", ethPeers, "LES", lightPeers, "total", cfg.MaxPeers)
  1420. if ctx.GlobalIsSet(MaxPendingPeersFlag.Name) {
  1421. cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name)
  1422. }
  1423. if ctx.GlobalIsSet(NoDiscoverFlag.Name) || lightClient {
  1424. cfg.NoDiscovery = true
  1425. }
  1426. // if we're running a light client or server, force enable the v5 peer discovery
  1427. // unless it is explicitly disabled with --nodiscover note that explicitly specifying
  1428. // --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
  1429. forceV5Discovery := (lightClient || lightServer) && !ctx.GlobalBool(NoDiscoverFlag.Name)
  1430. if ctx.GlobalIsSet(DiscoveryV5Flag.Name) {
  1431. cfg.DiscoveryV5 = ctx.GlobalBool(DiscoveryV5Flag.Name)
  1432. } else if forceV5Discovery {
  1433. cfg.DiscoveryV5 = true
  1434. }
  1435. if netrestrict := ctx.GlobalString(NetrestrictFlag.Name); netrestrict != "" {
  1436. list, err := netutil.ParseNetlist(netrestrict)
  1437. if err != nil {
  1438. Fatalf("Option %q: %v", NetrestrictFlag.Name, err)
  1439. }
  1440. cfg.NetRestrict = list
  1441. }
  1442. if ctx.GlobalBool(DeveloperFlag.Name) || ctx.GlobalBool(CatalystFlag.Name) {
  1443. // --dev mode can't use p2p networking.
  1444. cfg.MaxPeers = 0
  1445. cfg.ListenAddr = ""
  1446. cfg.NoDial = true
  1447. cfg.NoDiscovery = true
  1448. cfg.DiscoveryV5 = false
  1449. }
  1450. }
  1451. func SetQP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
  1452. setNodeKey(ctx, cfg)
  1453. //setNAT(ctx, cfg)
  1454. cfg.NAT = nil
  1455. if ctx.GlobalIsSet(QuorumLightServerP2PListenPortFlag.Name) {
  1456. cfg.ListenAddr = fmt.Sprintf(":%d", ctx.GlobalInt(QuorumLightServerP2PListenPortFlag.Name))
  1457. }
  1458. cfg.EnableNodePermission = ctx.GlobalIsSet(QuorumLightServerP2PPermissioningFlag.Name)
  1459. cfg.MaxPeers = 10
  1460. if ctx.GlobalIsSet(QuorumLightServerP2PMaxPeersFlag.Name) {
  1461. cfg.MaxPeers = ctx.GlobalInt(QuorumLightServerP2PMaxPeersFlag.Name)
  1462. }
  1463. if netrestrict := ctx.GlobalString(QuorumLightServerP2PNetrestrictFlag.Name); netrestrict != "" {
  1464. list, err := netutil.ParseNetlist(netrestrict)
  1465. if err != nil {
  1466. Fatalf("Option %q: %v", QuorumLightServerP2PNetrestrictFlag.Name, err)
  1467. }
  1468. cfg.NetRestrict = list
  1469. }
  1470. cfg.MaxPendingPeers = 0
  1471. cfg.NoDiscovery = true
  1472. cfg.DiscoveryV5 = false
  1473. cfg.NoDial = true
  1474. }
  1475. // SetNodeConfig applies node-related command line flags to the config.
  1476. func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
  1477. SetP2PConfig(ctx, &cfg.P2P)
  1478. if cfg.QP2P != nil {
  1479. SetQP2PConfig(ctx, cfg.QP2P)
  1480. }
  1481. setIPC(ctx, cfg)
  1482. setHTTP(ctx, cfg)
  1483. setGraphQL(ctx, cfg)
  1484. setWS(ctx, cfg)
  1485. setNodeUserIdent(ctx, cfg)
  1486. setDataDir(ctx, cfg)
  1487. setRaftLogDir(ctx, cfg)
  1488. setSmartCard(ctx, cfg)
  1489. if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
  1490. cfg.ExternalSigner = ctx.GlobalString(ExternalSignerFlag.Name)
  1491. }
  1492. if ctx.GlobalIsSet(KeyStoreDirFlag.Name) {
  1493. cfg.KeyStoreDir = ctx.GlobalString(KeyStoreDirFlag.Name)
  1494. }
  1495. if ctx.GlobalIsSet(LightKDFFlag.Name) {
  1496. cfg.UseLightweightKDF = ctx.GlobalBool(LightKDFFlag.Name)
  1497. }
  1498. if ctx.GlobalIsSet(NoUSBFlag.Name) || cfg.NoUSB {
  1499. log.Warn("Option nousb is deprecated and USB is deactivated by default. Use --usb to enable")
  1500. }
  1501. if ctx.GlobalIsSet(USBFlag.Name) {
  1502. cfg.USB = ctx.GlobalBool(USBFlag.Name)
  1503. }
  1504. if ctx.GlobalIsSet(InsecureUnlockAllowedFlag.Name) {
  1505. cfg.InsecureUnlockAllowed = ctx.GlobalBool(InsecureUnlockAllowedFlag.Name)
  1506. }
  1507. // Quorum
  1508. if ctx.GlobalIsSet(EnableNodePermissionFlag.Name) {
  1509. cfg.EnableNodePermission = ctx.GlobalBool(EnableNodePermissionFlag.Name)
  1510. }
  1511. if ctx.GlobalIsSet(MultitenancyFlag.Name) {
  1512. cfg.EnableMultitenancy = ctx.GlobalBool(MultitenancyFlag.Name)
  1513. }
  1514. }
  1515. func setSmartCard(ctx *cli.Context, cfg *node.Config) {
  1516. // Skip enabling smartcards if no path is set
  1517. path := ctx.GlobalString(SmartCardDaemonPathFlag.Name)
  1518. if path == "" {
  1519. return
  1520. }
  1521. // Sanity check that the smartcard path is valid
  1522. fi, err := os.Stat(path)
  1523. if err != nil {
  1524. log.Info("Smartcard socket not found, disabling", "err", err)
  1525. return
  1526. }
  1527. if fi.Mode()&os.ModeType != os.ModeSocket {
  1528. log.Error("Invalid smartcard daemon path", "path", path, "type", fi.Mode().String())
  1529. return
  1530. }
  1531. // Smartcard daemon path exists and is a socket, enable it
  1532. cfg.SmartCardDaemonPath = path
  1533. }
  1534. func setDataDir(ctx *cli.Context, cfg *node.Config) {
  1535. switch {
  1536. case ctx.GlobalIsSet(DataDirFlag.Name):
  1537. cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
  1538. case ctx.GlobalBool(DeveloperFlag.Name):
  1539. cfg.DataDir = "" // unless explicitly requested, use memory databases
  1540. case ctx.GlobalBool(RopstenFlag.Name) && cfg.DataDir == node.DefaultDataDir():
  1541. // Maintain compatibility with older Geth configurations storing the
  1542. // Ropsten database in `testnet` instead of `ropsten`.
  1543. legacyPath := filepath.Join(node.DefaultDataDir(), "testnet")
  1544. if _, err := os.Stat(legacyPath); !os.IsNotExist(err) {
  1545. log.Warn("Using the deprecated `testnet` datadir. Future versions will store the Ropsten chain in `ropsten`.")
  1546. cfg.DataDir = legacyPath
  1547. } else {
  1548. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "ropsten")
  1549. }
  1550. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "ropsten")
  1551. case ctx.GlobalBool(RinkebyFlag.Name) && cfg.DataDir == node.DefaultDataDir():
  1552. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
  1553. case ctx.GlobalBool(GoerliFlag.Name) && cfg.DataDir == node.DefaultDataDir():
  1554. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "goerli")
  1555. case ctx.GlobalBool(YoloV3Flag.Name) && cfg.DataDir == node.DefaultDataDir():
  1556. cfg.DataDir = filepath.Join(node.DefaultDataDir(), "yolo-v3")
  1557. }
  1558. if err := SetPlugins(ctx, cfg); err != nil {
  1559. Fatalf(err.Error())
  1560. }
  1561. }
  1562. func setRaftLogDir(ctx *cli.Context, cfg *node.Config) {
  1563. if ctx.GlobalIsSet(RaftLogDirFlag.Name) {
  1564. cfg.RaftLogDir = ctx.GlobalString(RaftLogDirFlag.Name)
  1565. } else {
  1566. cfg.RaftLogDir = cfg.DataDir
  1567. }
  1568. }
  1569. // Quorum
  1570. //
  1571. // Read plugin settings from --plugins flag. Overwrite settings defined in --config if any
  1572. func SetPlugins(ctx *cli.Context, cfg *node.Config) error {
  1573. if ctx.GlobalIsSet(PluginSettingsFlag.Name) {
  1574. // validate flag combination
  1575. if ctx.GlobalBool(PluginSkipVerifyFlag.Name) && ctx.GlobalBool(PluginLocalVerifyFlag.Name) {
  1576. return fmt.Errorf("only --%s or --%s must be set", PluginSkipVerifyFlag.Name, PluginLocalVerifyFlag.Name)
  1577. }
  1578. if !ctx.GlobalBool(PluginLocalVerifyFlag.Name) && ctx.GlobalIsSet(PluginPublicKeyFlag.Name) {
  1579. return fmt.Errorf("--%s is required for setting --%s", PluginLocalVerifyFlag.Name, PluginPublicKeyFlag.Name)
  1580. }
  1581. pluginSettingsURL, err := url.Parse(ctx.GlobalString(PluginSettingsFlag.Name))
  1582. if err != nil {
  1583. return fmt.Errorf("plugins: Invalid URL for --%s due to %s", PluginSettingsFlag.Name, err)
  1584. }
  1585. var pluginSettings plugin.Settings
  1586. r, err := urlReader(pluginSettingsURL)
  1587. if err != nil {
  1588. return fmt.Errorf("plugins: unable to create reader due to %s", err)
  1589. }
  1590. defer func() {
  1591. _ = r.Close()
  1592. }()
  1593. if err := json.NewDecoder(r).Decode(&pluginSettings); err != nil {
  1594. return fmt.Errorf("plugins: unable to parse settings due to %s", err)
  1595. }
  1596. pluginSettings.SetDefaults()
  1597. cfg.Plugins = &pluginSettings
  1598. }
  1599. return nil
  1600. }
  1601. func urlReader(u *url.URL) (io.ReadCloser, error) {
  1602. s := u.Scheme
  1603. switch s {
  1604. case "file":
  1605. return os.Open(filepath.Join(u.Host, u.Path))
  1606. }
  1607. return nil, fmt.Errorf("unsupported scheme %s", s)
  1608. }
  1609. func setGPO(ctx *cli.Context, cfg *gasprice.Config, light bool) {
  1610. // If we are running the light client, apply another group
  1611. // settings for gas oracle.
  1612. if light {
  1613. cfg.Blocks = ethconfig.LightClientGPO.Blocks
  1614. cfg.Percentile = ethconfig.LightClientGPO.Percentile
  1615. }
  1616. if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
  1617. cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
  1618. }
  1619. if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
  1620. cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
  1621. }
  1622. if ctx.GlobalIsSet(GpoMaxGasPriceFlag.Name) {
  1623. cfg.MaxPrice = big.NewInt(ctx.GlobalInt64(GpoMaxGasPriceFlag.Name))
  1624. }
  1625. }
  1626. func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
  1627. if ctx.GlobalIsSet(TxPoolLocalsFlag.Name) {
  1628. locals := strings.Split(ctx.GlobalString(TxPoolLocalsFlag.Name), ",")
  1629. for _, account := range locals {
  1630. if trimmed := strings.TrimSpace(account); !common.IsHexAddress(trimmed) {
  1631. Fatalf("Invalid account in --txpool.locals: %s", trimmed)
  1632. } else {
  1633. cfg.Locals = append(cfg.Locals, common.HexToAddress(account))
  1634. }
  1635. }
  1636. }
  1637. if ctx.GlobalIsSet(TxPoolNoLocalsFlag.Name) {
  1638. cfg.NoLocals = ctx.GlobalBool(TxPoolNoLocalsFlag.Name)
  1639. }
  1640. if ctx.GlobalIsSet(TxPoolJournalFlag.Name) {
  1641. cfg.Journal = ctx.GlobalString(TxPoolJournalFlag.Name)
  1642. }
  1643. if ctx.GlobalIsSet(TxPoolRejournalFlag.Name) {
  1644. cfg.Rejournal = ctx.GlobalDuration(TxPoolRejournalFlag.Name)
  1645. }
  1646. if ctx.GlobalIsSet(TxPoolPriceLimitFlag.Name) {
  1647. cfg.PriceLimit = ctx.GlobalUint64(TxPoolPriceLimitFlag.Name)
  1648. }
  1649. if ctx.GlobalIsSet(TxPoolPriceBumpFlag.Name) {
  1650. cfg.PriceBump = ctx.GlobalUint64(TxPoolPriceBumpFlag.Name)
  1651. }
  1652. if ctx.GlobalIsSet(TxPoolAccountSlotsFlag.Name) {
  1653. cfg.AccountSlots = ctx.GlobalUint64(TxPoolAccountSlotsFlag.Name)
  1654. }
  1655. if ctx.GlobalIsSet(TxPoolGlobalSlotsFlag.Name) {
  1656. cfg.GlobalSlots = ctx.GlobalUint64(TxPoolGlobalSlotsFlag.Name)
  1657. }
  1658. if ctx.GlobalIsSet(TxPoolAccountQueueFlag.Name) {
  1659. cfg.AccountQueue = ctx.GlobalUint64(TxPoolAccountQueueFlag.Name)
  1660. }
  1661. if ctx.GlobalIsSet(TxPoolGlobalQueueFlag.Name) {
  1662. cfg.GlobalQueue = ctx.GlobalUint64(TxPoolGlobalQueueFlag.Name)
  1663. }
  1664. if ctx.GlobalIsSet(TxPoolLifetimeFlag.Name) {
  1665. cfg.Lifetime = ctx.GlobalDuration(TxPoolLifetimeFlag.Name)
  1666. }
  1667. }
  1668. func setEthash(ctx *cli.Context, cfg *ethconfig.Config) {
  1669. if ctx.GlobalIsSet(EthashCacheDirFlag.Name) {
  1670. cfg.Ethash.CacheDir = ctx.GlobalString(EthashCacheDirFlag.Name)
  1671. }
  1672. if ctx.GlobalIsSet(EthashDatasetDirFlag.Name) {
  1673. cfg.Ethash.DatasetDir = ctx.GlobalString(EthashDatasetDirFlag.Name)
  1674. }
  1675. if ctx.GlobalIsSet(EthashCachesInMemoryFlag.Name) {
  1676. cfg.Ethash.CachesInMem = ctx.GlobalInt(EthashCachesInMemoryFlag.Name)
  1677. }
  1678. if ctx.GlobalIsSet(EthashCachesOnDiskFlag.Name) {
  1679. cfg.Ethash.CachesOnDisk = ctx.GlobalInt(EthashCachesOnDiskFlag.Name)
  1680. }
  1681. if ctx.GlobalIsSet(EthashCachesLockMmapFlag.Name) {
  1682. cfg.Ethash.CachesLockMmap = ctx.GlobalBool(EthashCachesLockMmapFlag.Name)
  1683. }
  1684. if ctx.GlobalIsSet(EthashDatasetsInMemoryFlag.Name) {
  1685. cfg.Ethash.DatasetsInMem = ctx.GlobalInt(EthashDatasetsInMemoryFlag.Name)
  1686. }
  1687. if ctx.GlobalIsSet(EthashDatasetsOnDiskFlag.Name) {
  1688. cfg.Ethash.DatasetsOnDisk = ctx.GlobalInt(EthashDatasetsOnDiskFlag.Name)
  1689. }
  1690. if ctx.GlobalIsSet(EthashDatasetsLockMmapFlag.Name) {
  1691. cfg.Ethash.DatasetsLockMmap = ctx.GlobalBool(EthashDatasetsLockMmapFlag.Name)
  1692. }
  1693. }
  1694. func setMiner(ctx *cli.Context, cfg *miner.Config) {
  1695. if ctx.GlobalIsSet(MinerNotifyFlag.Name) {
  1696. cfg.Notify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",")
  1697. }
  1698. cfg.NotifyFull = ctx.GlobalBool(MinerNotifyFullFlag.Name)
  1699. if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
  1700. cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
  1701. }
  1702. if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
  1703. cfg.GasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
  1704. }
  1705. if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
  1706. cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
  1707. }
  1708. if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
  1709. cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
  1710. }
  1711. if ctx.GlobalIsSet(MinerRecommitIntervalFlag.Name) {
  1712. cfg.Recommit = ctx.GlobalDuration(MinerRecommitIntervalFlag.Name)
  1713. }
  1714. if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
  1715. cfg.Noverify = ctx.GlobalBool(MinerNoVerfiyFlag.Name)
  1716. }
  1717. if ctx.GlobalIsSet(AllowedFutureBlockTimeFlag.Name) {
  1718. cfg.AllowedFutureBlockTime = ctx.GlobalUint64(AllowedFutureBlockTimeFlag.Name) //Quorum
  1719. }
  1720. }
  1721. func setAuthorizationList(ctx *cli.Context, cfg *ethconfig.Config) {
  1722. authorizationList := ctx.GlobalString(AuthorizationListFlag.Name)
  1723. if authorizationList == "" {
  1724. authorizationList = ctx.GlobalString(DeprecatedAuthorizationListFlag.Name)
  1725. if authorizationList != "" {
  1726. log.Warn("The flag --whitelist is deprecated and will be removed in the future, please use --authorizationlist")
  1727. }
  1728. }
  1729. if authorizationList == "" {
  1730. return
  1731. }
  1732. cfg.AuthorizationList = make(map[uint64]common.Hash)
  1733. for _, entry := range strings.Split(authorizationList, ",") {
  1734. parts := strings.Split(entry, "=")
  1735. if len(parts) != 2 {
  1736. Fatalf("Invalid authorized entry: %s", entry)
  1737. }
  1738. number, err := strconv.ParseUint(parts[0], 0, 64)
  1739. if err != nil {
  1740. Fatalf("Invalid authorized block number %s: %v", parts[0], err)
  1741. }
  1742. var hash common.Hash
  1743. if err = hash.UnmarshalText([]byte(parts[1])); err != nil {
  1744. Fatalf("Invalid authorized hash %s: %v", parts[1], err)
  1745. }
  1746. cfg.AuthorizationList[number] = hash
  1747. }
  1748. }
  1749. // Quorum
  1750. func setIstanbul(ctx *cli.Context, cfg *eth.Config) {
  1751. if ctx.GlobalIsSet(IstanbulRequestTimeoutFlag.Name) {
  1752. log.Warn("WARNING: The flag --istanbul.requesttimeout is deprecated and will be removed in the future, please use ibft.requesttimeoutseconds on genesis file")
  1753. cfg.Istanbul.RequestTimeout = ctx.GlobalUint64(IstanbulRequestTimeoutFlag.Name)
  1754. }
  1755. if ctx.GlobalIsSet(IstanbulBlockPeriodFlag.Name) {
  1756. log.Warn("WARNING: The flag --istanbul.blockperiod is deprecated and will be removed in the future, please use ibft.blockperiodseconds on genesis file")
  1757. cfg.Istanbul.BlockPeriod = ctx.GlobalUint64(IstanbulBlockPeriodFlag.Name)
  1758. }
  1759. }
  1760. func setRaft(ctx *cli.Context, cfg *eth.Config) {
  1761. cfg.RaftMode = ctx.GlobalBool(RaftModeFlag.Name)
  1762. }
  1763. func setQuorumConfig(ctx *cli.Context, cfg *eth.Config) error {
  1764. cfg.EVMCallTimeOut = time.Duration(ctx.GlobalInt(EVMCallTimeOutFlag.Name)) * time.Second
  1765. cfg.QuorumChainConfig = core.NewQuorumChainConfig(ctx.GlobalBool(MultitenancyFlag.Name),
  1766. ctx.GlobalBool(RevertReasonFlag.Name), ctx.GlobalBool(QuorumEnablePrivacyMarker.Name),
  1767. ctx.GlobalBool(QuorumEnablePrivateTrieCache.Name))
  1768. setIstanbul(ctx, cfg)
  1769. setRaft(ctx, cfg)
  1770. return nil
  1771. }
  1772. // CheckExclusive verifies that only a single instance of the provided flags was
  1773. // set by the user. Each flag might optionally be followed by a string type to
  1774. // specialize it further.
  1775. func CheckExclusive(ctx *cli.Context, args ...interface{}) {
  1776. set := make([]string, 0, 1)
  1777. for i := 0; i < len(args); i++ {
  1778. // Make sure the next argument is a flag and skip if not set
  1779. flag, ok := args[i].(cli.Flag)
  1780. if !ok {
  1781. panic(fmt.Sprintf("invalid argument, not cli.Flag type: %T", args[i]))
  1782. }
  1783. // Check if next arg extends current and expand its name if so
  1784. name := flag.GetName()
  1785. if i+1 < len(args) {
  1786. switch option := args[i+1].(type) {
  1787. case string:
  1788. // Extended flag check, make sure value set doesn't conflict with passed in option
  1789. if ctx.GlobalString(flag.GetName()) == option {
  1790. name += "=" + option
  1791. set = append(set, "--"+name)
  1792. }
  1793. // shift arguments and continue
  1794. i++
  1795. continue
  1796. case cli.Flag:
  1797. default:
  1798. panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1]))
  1799. }
  1800. }
  1801. // Mark the flag if it's set
  1802. if ctx.GlobalIsSet(flag.GetName()) {
  1803. set = append(set, "--"+name)
  1804. }
  1805. }
  1806. if len(set) > 1 {
  1807. Fatalf("Flags %v can't be used at the same time", strings.Join(set, ", "))
  1808. }
  1809. }
  1810. func SetQLightConfig(ctx *cli.Context, nodeCfg *node.Config, ethCfg *ethconfig.Config) {
  1811. if ctx.GlobalIsSet(QuorumLightServerFlag.Name) {
  1812. ethCfg.QuorumLightServer = ctx.GlobalBool(QuorumLightServerFlag.Name)
  1813. }
  1814. if ethCfg.QuorumLightServer {
  1815. if nodeCfg.QP2P == nil {
  1816. nodeCfg.QP2P = &p2p.Config{
  1817. ListenAddr: ":30305",
  1818. MaxPeers: 10,
  1819. NAT: nil,
  1820. NoDial: true,
  1821. NoDiscovery: true,
  1822. }
  1823. SetQP2PConfig(ctx, nodeCfg.QP2P)
  1824. }
  1825. } else {
  1826. nodeCfg.QP2P = nil
  1827. }
  1828. ethCfg.QuorumLightClient = &ethconfig.QuorumLightClient{}
  1829. if ctx.GlobalIsSet(QuorumLightClientFlag.Name) {
  1830. ethCfg.QuorumLightClient.Use = ctx.GlobalBool(QuorumLightClientFlag.Name)
  1831. }
  1832. if len(ethCfg.QuorumLightClient.PSI) == 0 {
  1833. ethCfg.QuorumLightClient.PSI = "private"
  1834. }
  1835. if ctx.GlobalIsSet(QuorumLightClientPSIFlag.Name) {
  1836. ethCfg.QuorumLightClient.PSI = ctx.GlobalString(QuorumLightClientPSIFlag.Name)
  1837. }
  1838. if ctx.GlobalIsSet(QuorumLightClientTokenEnabledFlag.Name) {
  1839. ethCfg.QuorumLightClient.TokenEnabled = ctx.GlobalBool(QuorumLightClientTokenEnabledFlag.Name)
  1840. }
  1841. if ctx.GlobalIsSet(QuorumLightClientTokenValueFlag.Name) {
  1842. ethCfg.QuorumLightClient.TokenValue = ctx.GlobalString(QuorumLightClientTokenValueFlag.Name)
  1843. }
  1844. if len(ethCfg.QuorumLightClient.TokenManagement) == 0 {
  1845. ethCfg.QuorumLightClient.TokenManagement = "client-security-plugin"
  1846. }
  1847. if ctx.GlobalIsSet(QuorumLightClientTokenManagementFlag.Name) {
  1848. ethCfg.QuorumLightClient.TokenManagement = ctx.GlobalString(QuorumLightClientTokenManagementFlag.Name)
  1849. }
  1850. if !isValidTokenManagement(ethCfg.QuorumLightClient.TokenManagement) {
  1851. Fatalf("Invalid value specified '%s' for flag '%s'.", ethCfg.QuorumLightClient.TokenManagement, QuorumLightClientTokenManagementFlag.Name)
  1852. }
  1853. if ctx.GlobalIsSet(QuorumLightClientRPCTLSFlag.Name) {
  1854. ethCfg.QuorumLightClient.RPCTLS = ctx.GlobalBool(QuorumLightClientRPCTLSFlag.Name)
  1855. }
  1856. if ctx.GlobalIsSet(QuorumLightClientRPCTLSCACertFlag.Name) {
  1857. ethCfg.QuorumLightClient.RPCTLSCACert = ctx.GlobalString(QuorumLightClientRPCTLSCACertFlag.Name)
  1858. }
  1859. if ctx.GlobalIsSet(QuorumLightClientRPCTLSInsecureSkipVerifyFlag.Name) {
  1860. ethCfg.QuorumLightClient.RPCTLSInsecureSkipVerify = ctx.GlobalBool(QuorumLightClientRPCTLSInsecureSkipVerifyFlag.Name)
  1861. }
  1862. if ctx.GlobalIsSet(QuorumLightClientRPCTLSCertFlag.Name) && ctx.GlobalIsSet(QuorumLightClientRPCTLSKeyFlag.Name) {
  1863. ethCfg.QuorumLightClient.RPCTLSCert = ctx.GlobalString(QuorumLightClientRPCTLSCertFlag.Name)
  1864. ethCfg.QuorumLightClient.RPCTLSKey = ctx.GlobalString(QuorumLightClientRPCTLSKeyFlag.Name)
  1865. } else if ctx.GlobalIsSet(QuorumLightClientRPCTLSCertFlag.Name) {
  1866. Fatalf("'%s' specified without specifying '%s'", QuorumLightClientRPCTLSCertFlag.Name, QuorumLightClientRPCTLSKeyFlag.Name)
  1867. } else if ctx.GlobalIsSet(QuorumLightClientRPCTLSKeyFlag.Name) {
  1868. Fatalf("'%s' specified without specifying '%s'", QuorumLightClientRPCTLSKeyFlag.Name, QuorumLightClientRPCTLSCertFlag.Name)
  1869. }
  1870. if ctx.GlobalIsSet(QuorumLightClientServerNodeRPCFlag.Name) {
  1871. ethCfg.QuorumLightClient.ServerNodeRPC = ctx.GlobalString(QuorumLightClientServerNodeRPCFlag.Name)
  1872. }
  1873. if ctx.GlobalIsSet(QuorumLightClientServerNodeFlag.Name) {
  1874. ethCfg.QuorumLightClient.ServerNode = ctx.GlobalString(QuorumLightClientServerNodeFlag.Name)
  1875. // This is already done in geth/config - before the node.New invocation (at which point the StaticNodes is already copied)
  1876. //stack.Config().P2P.StaticNodes = []*enode.Node{enode.MustParse(ethCfg.QuorumLightClientServerNode)}
  1877. }
  1878. if ethCfg.QuorumLightClient.Enabled() {
  1879. if ctx.GlobalBool(MiningEnabledFlag.Name) {
  1880. Fatalf("QLight clients do not support mining")
  1881. }
  1882. if len(ethCfg.QuorumLightClient.ServerNode) == 0 {
  1883. Fatalf("Please specify the '%s' when running a qlight client.", QuorumLightClientServerNodeFlag.Name)
  1884. }
  1885. if len(ethCfg.QuorumLightClient.ServerNodeRPC) == 0 {
  1886. Fatalf("Please specify the '%s' when running a qlight client.", QuorumLightClientServerNodeRPCFlag.Name)
  1887. }
  1888. nodeCfg.P2P.StaticNodes = []*enode.Node{enode.MustParse(ethCfg.QuorumLightClient.ServerNode)}
  1889. log.Info("The node is configured to run as a qlight client. 'maxpeers' is overridden to `1` and the P2P listener is disabled.")
  1890. nodeCfg.P2P.MaxPeers = 1
  1891. // force the qlight client node to disable the local P2P listener
  1892. nodeCfg.P2P.ListenAddr = ""
  1893. }
  1894. }
  1895. // SetEthConfig applies eth-related command line flags to the config.
  1896. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
  1897. // Avoid conflicting network flags
  1898. CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, YoloV3Flag)
  1899. CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
  1900. CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
  1901. if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 {
  1902. ctx.GlobalSet(TxLookupLimitFlag.Name, "0")
  1903. log.Warn("Disable transaction unindexing for archive node")
  1904. }
  1905. if ctx.GlobalIsSet(LightServeFlag.Name) && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 {
  1906. log.Warn("LES server cannot serve old transaction status and cannot connect below les/4 protocol version if transaction lookup index is limited")
  1907. }
  1908. var ks *keystore.KeyStore
  1909. if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 {
  1910. ks = keystores[0].(*keystore.KeyStore)
  1911. }
  1912. setEtherbase(ctx, ks, cfg)
  1913. setGPO(ctx, &cfg.GPO, ctx.GlobalString(SyncModeFlag.Name) == "light")
  1914. setTxPool(ctx, &cfg.TxPool)
  1915. setEthash(ctx, cfg)
  1916. setMiner(ctx, &cfg.Miner)
  1917. setAuthorizationList(ctx, cfg)
  1918. setLes(ctx, cfg)
  1919. // Cap the cache allowance and tune the garbage collector
  1920. mem, err := gopsutil.VirtualMemory()
  1921. if err == nil {
  1922. if 32<<(^uintptr(0)>>63) == 32 && mem.Total > 2*1024*1024*1024 {
  1923. log.Warn("Lowering memory allowance on 32bit arch", "available", mem.Total/1024/1024, "addressable", 2*1024)
  1924. mem.Total = 2 * 1024 * 1024 * 1024
  1925. }
  1926. allowance := int(mem.Total / 1024 / 1024 / 3)
  1927. if cache := ctx.GlobalInt(CacheFlag.Name); cache > allowance {
  1928. log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
  1929. ctx.GlobalSet(CacheFlag.Name, strconv.Itoa(allowance))
  1930. }
  1931. }
  1932. // Ensure Go's GC ignores the database cache for trigger percentage
  1933. cache := ctx.GlobalInt(CacheFlag.Name)
  1934. gogc := math.Max(20, math.Min(100, 100/(float64(cache)/1024)))
  1935. log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
  1936. godebug.SetGCPercent(int(gogc))
  1937. // Quorum
  1938. err = setQuorumConfig(ctx, cfg)
  1939. if err != nil {
  1940. Fatalf("Quorum configuration has an error: %v", err)
  1941. }
  1942. if ctx.GlobalIsSet(SyncModeFlag.Name) {
  1943. cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
  1944. }
  1945. // Quorum
  1946. if cfg.QuorumLightClient.Enabled() && cfg.SyncMode != downloader.FullSync {
  1947. Fatalf("Only the 'full' syncmode is supported for the qlight client.")
  1948. }
  1949. if private.IsQuorumPrivacyEnabled() && cfg.SyncMode != downloader.FullSync {
  1950. Fatalf("Only the 'full' syncmode is supported when quorum privacy is enabled.")
  1951. }
  1952. // End Quorum
  1953. if ctx.GlobalIsSet(NetworkIdFlag.Name) {
  1954. cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
  1955. }
  1956. if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
  1957. cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
  1958. }
  1959. cfg.DatabaseHandles = MakeDatabaseHandles()
  1960. if ctx.GlobalIsSet(AncientFlag.Name) {
  1961. cfg.DatabaseFreezer = ctx.GlobalString(AncientFlag.Name)
  1962. }
  1963. if gcmode := ctx.GlobalString(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
  1964. Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
  1965. }
  1966. if ctx.GlobalIsSet(GCModeFlag.Name) {
  1967. cfg.NoPruning = ctx.GlobalString(GCModeFlag.Name) == "archive"
  1968. }
  1969. if ctx.GlobalIsSet(CacheNoPrefetchFlag.Name) {
  1970. cfg.NoPrefetch = ctx.GlobalBool(CacheNoPrefetchFlag.Name)
  1971. }
  1972. // Read the value from the flag no matter if it's set or not.
  1973. cfg.Preimages = ctx.GlobalBool(CachePreimagesFlag.Name)
  1974. if true || cfg.NoPruning && !cfg.Preimages { // TODO: Quorum; force preimages for contract extension and dump of states compatibility, until a fix is found
  1975. cfg.Preimages = true
  1976. log.Info("Enabling recording of key preimages since archive mode is used")
  1977. }
  1978. if ctx.GlobalIsSet(TxLookupLimitFlag.Name) {
  1979. cfg.TxLookupLimit = ctx.GlobalUint64(TxLookupLimitFlag.Name)
  1980. }
  1981. if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheTrieFlag.Name) {
  1982. cfg.TrieCleanCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheTrieFlag.Name) / 100
  1983. }
  1984. if ctx.GlobalIsSet(CacheTrieJournalFlag.Name) {
  1985. cfg.TrieCleanCacheJournal = ctx.GlobalString(CacheTrieJournalFlag.Name)
  1986. }
  1987. if ctx.GlobalIsSet(CacheTrieRejournalFlag.Name) {
  1988. cfg.TrieCleanCacheRejournal = ctx.GlobalDuration(CacheTrieRejournalFlag.Name)
  1989. }
  1990. if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
  1991. cfg.TrieDirtyCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
  1992. }
  1993. if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheSnapshotFlag.Name) {
  1994. cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100
  1995. }
  1996. if !ctx.GlobalBool(SnapshotFlag.Name) {
  1997. // If snap-sync is requested, this flag is also required
  1998. if cfg.SyncMode == downloader.SnapSync {
  1999. log.Info("Snap sync requested, enabling --snapshot")
  2000. } else {
  2001. cfg.TrieCleanCache += cfg.SnapshotCache
  2002. cfg.SnapshotCache = 0 // Disabled
  2003. }
  2004. }
  2005. if ctx.GlobalIsSet(DocRootFlag.Name) {
  2006. cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
  2007. }
  2008. if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
  2009. // TODO(fjl): force-enable this in --dev mode
  2010. cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
  2011. }
  2012. if ctx.GlobalIsSet(EWASMInterpreterFlag.Name) {
  2013. cfg.EWASMInterpreter = ctx.GlobalString(EWASMInterpreterFlag.Name)
  2014. }
  2015. if ctx.GlobalIsSet(EVMInterpreterFlag.Name) {
  2016. cfg.EVMInterpreter = ctx.GlobalString(EVMInterpreterFlag.Name)
  2017. }
  2018. if ctx.GlobalIsSet(RPCGlobalGasCapFlag.Name) {
  2019. cfg.RPCGasCap = ctx.GlobalUint64(RPCGlobalGasCapFlag.Name)
  2020. }
  2021. if cfg.RPCGasCap != 0 {
  2022. log.Info("Set global gas cap", "cap", cfg.RPCGasCap)
  2023. } else {
  2024. log.Info("Global gas cap disabled")
  2025. }
  2026. if ctx.GlobalIsSet(RPCGlobalTxFeeCapFlag.Name) {
  2027. cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCapFlag.Name)
  2028. }
  2029. if ctx.GlobalIsSet(NoDiscoverFlag.Name) {
  2030. cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{}
  2031. } else if ctx.GlobalIsSet(DNSDiscoveryFlag.Name) {
  2032. urls := ctx.GlobalString(DNSDiscoveryFlag.Name)
  2033. if urls == "" {
  2034. cfg.EthDiscoveryURLs = []string{}
  2035. } else {
  2036. cfg.EthDiscoveryURLs = SplitAndTrim(urls)
  2037. }
  2038. }
  2039. // set immutability threshold in config
  2040. params.SetQuorumImmutabilityThreshold(ctx.GlobalInt(QuorumImmutabilityThreshold.Name))
  2041. // Override any default configs for hard coded networks.
  2042. switch {
  2043. case ctx.GlobalBool(MainnetFlag.Name):
  2044. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  2045. cfg.NetworkId = 1
  2046. }
  2047. cfg.Genesis = core.DefaultGenesisBlock()
  2048. SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
  2049. case ctx.GlobalBool(RopstenFlag.Name):
  2050. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  2051. cfg.NetworkId = 3
  2052. }
  2053. cfg.Genesis = core.DefaultRopstenGenesisBlock()
  2054. SetDNSDiscoveryDefaults(cfg, params.RopstenGenesisHash)
  2055. case ctx.GlobalBool(RinkebyFlag.Name):
  2056. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  2057. cfg.NetworkId = 4
  2058. }
  2059. cfg.Genesis = core.DefaultRinkebyGenesisBlock()
  2060. SetDNSDiscoveryDefaults(cfg, params.RinkebyGenesisHash)
  2061. case ctx.GlobalBool(GoerliFlag.Name):
  2062. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  2063. cfg.NetworkId = 5
  2064. }
  2065. cfg.Genesis = core.DefaultGoerliGenesisBlock()
  2066. SetDNSDiscoveryDefaults(cfg, params.GoerliGenesisHash)
  2067. case ctx.GlobalBool(YoloV3Flag.Name):
  2068. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  2069. cfg.NetworkId = new(big.Int).SetBytes([]byte("yolov3x")).Uint64() // "yolov3x"
  2070. }
  2071. cfg.Genesis = core.DefaultYoloV3GenesisBlock()
  2072. case ctx.GlobalBool(DeveloperFlag.Name):
  2073. if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
  2074. cfg.NetworkId = 1337
  2075. }
  2076. // Create new developer account or reuse existing one
  2077. var (
  2078. developer accounts.Account
  2079. passphrase string
  2080. err error
  2081. )
  2082. if list := MakePasswordList(ctx); len(list) > 0 {
  2083. // Just take the first value. Although the function returns a possible multiple values and
  2084. // some usages iterate through them as attempts, that doesn't make sense in this setting,
  2085. // when we're definitely concerned with only one account.
  2086. passphrase = list[0]
  2087. }
  2088. // setEtherbase has been called above, configuring the miner address from command line flags.
  2089. if cfg.Miner.Etherbase != (common.Address{}) {
  2090. developer = accounts.Account{Address: cfg.Miner.Etherbase}
  2091. } else if accs := ks.Accounts(); len(accs) > 0 {
  2092. developer = ks.Accounts()[0]
  2093. } else {
  2094. developer, err = ks.NewAccount(passphrase)
  2095. if err != nil {
  2096. Fatalf("Failed to create developer account: %v", err)
  2097. }
  2098. }
  2099. if err := ks.Unlock(developer, passphrase); err != nil {
  2100. Fatalf("Failed to unlock developer account: %v", err)
  2101. }
  2102. log.Info("Using developer account", "address", developer.Address)
  2103. // Create a new developer genesis block or reuse existing one
  2104. cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
  2105. if ctx.GlobalIsSet(DataDirFlag.Name) {
  2106. // Check if we have an already initialized chain and fall back to
  2107. // that if so. Otherwise we need to generate a new genesis spec.
  2108. chaindb := MakeChainDatabase(ctx, stack, true)
  2109. if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
  2110. cfg.Genesis = nil // fallback to db content
  2111. }
  2112. chaindb.Close()
  2113. }
  2114. if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
  2115. cfg.Miner.GasPrice = big.NewInt(1)
  2116. }
  2117. default:
  2118. if cfg.NetworkId == 1 {
  2119. SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
  2120. }
  2121. }
  2122. }
  2123. // SetDNSDiscoveryDefaults configures DNS discovery with the given URL if
  2124. // no URLs are set.
  2125. func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
  2126. if cfg.EthDiscoveryURLs != nil {
  2127. return // already set through flags/config
  2128. }
  2129. protocol := "all"
  2130. if cfg.SyncMode == downloader.LightSync {
  2131. protocol = "les"
  2132. }
  2133. if url := params.KnownDNSNetwork(genesis, protocol); url != "" {
  2134. cfg.EthDiscoveryURLs = []string{url}
  2135. cfg.SnapDiscoveryURLs = cfg.EthDiscoveryURLs
  2136. }
  2137. }
  2138. // RegisterEthService adds an Ethereum client to the stack.
  2139. // Quorum => returns also the ethereum service which is used by the raft service
  2140. // The second return value is the full node instance, which may be nil if the
  2141. // node is running as a light client.
  2142. func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend, *eth.Ethereum) {
  2143. if cfg.SyncMode == downloader.LightSync {
  2144. backend, err := les.New(stack, cfg)
  2145. if err != nil {
  2146. Fatalf("Failed to register the Ethereum service: %v", err)
  2147. }
  2148. stack.RegisterAPIs(tracers.APIs(backend.ApiBackend))
  2149. return backend.ApiBackend, nil
  2150. }
  2151. // Quorum
  2152. client, err := stack.Attach()
  2153. if err != nil {
  2154. Fatalf("Failed to attach to self: %v", err)
  2155. }
  2156. cfg.Istanbul.Client = ethclient.NewClient(client)
  2157. // End Quorum
  2158. backend, err := eth.New(stack, cfg)
  2159. if err != nil {
  2160. Fatalf("Failed to register the Ethereum service: %v", err)
  2161. }
  2162. if cfg.LightServ > 0 {
  2163. _, err := les.NewLesServer(stack, backend, cfg)
  2164. if err != nil {
  2165. Fatalf("Failed to create the LES server: %v", err)
  2166. }
  2167. }
  2168. stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
  2169. return backend.APIBackend, backend
  2170. }
  2171. // RegisterEthStatsService configures the Ethereum Stats daemon and adds it to
  2172. // the given node.
  2173. func RegisterEthStatsService(stack *node.Node, backend ethapi.Backend, url string) {
  2174. if err := ethstats.New(stack, backend, backend.Engine(), url); err != nil {
  2175. Fatalf("Failed to register the Ethereum Stats service: %v", err)
  2176. }
  2177. }
  2178. // RegisterGraphQLService is a utility function to construct a new service and register it against a node.
  2179. func RegisterGraphQLService(stack *node.Node, backend ethapi.Backend, cfg node.Config) {
  2180. if err := graphql.New(stack, backend, cfg.GraphQLCors, cfg.GraphQLVirtualHosts); err != nil {
  2181. Fatalf("Failed to register the GraphQL service: %v", err)
  2182. }
  2183. }
  2184. // Quorum
  2185. //
  2186. // Register plugin manager as a service in geth
  2187. func RegisterPluginService(stack *node.Node, cfg *node.Config, skipVerify bool, localVerify bool, publicKey string) {
  2188. // ricardolyn: I can't adapt this Plugin Service construction to the new approach as there are circular dependencies between Node and Plugin
  2189. if err := cfg.ResolvePluginBaseDir(); err != nil {
  2190. Fatalf("plugins: unable to resolve plugin base dir due to %s", err)
  2191. }
  2192. pluginManager, err := plugin.NewPluginManager(cfg.UserIdent, cfg.Plugins, skipVerify, localVerify, publicKey)
  2193. if err != nil {
  2194. Fatalf("plugins: Failed to register the Plugins service: %v", err)
  2195. }
  2196. stack.SetPluginManager(pluginManager)
  2197. stack.RegisterAPIs(pluginManager.APIs())
  2198. stack.RegisterLifecycle(pluginManager)
  2199. log.Info("plugin service registered")
  2200. }
  2201. // Configure smart-contract-based permissioning service
  2202. func RegisterPermissionService(stack *node.Node, useDns bool, chainID *big.Int) {
  2203. permissionConfig, err := types.ParsePermissionConfig(stack.DataDir())
  2204. if err != nil {
  2205. Fatalf("loading of %s failed due to %v", params.PERMISSION_MODEL_CONFIG, err)
  2206. }
  2207. // start the permissions management service
  2208. _, err = permission.NewQuorumPermissionCtrl(stack, &permissionConfig, useDns, chainID)
  2209. if err != nil {
  2210. Fatalf("failed to load the permission contracts as given in %s due to %v", params.PERMISSION_MODEL_CONFIG, err)
  2211. }
  2212. log.Info("permission service registered")
  2213. }
  2214. func RegisterRaftService(stack *node.Node, ctx *cli.Context, nodeCfg *node.Config, ethService *eth.Ethereum) {
  2215. blockTimeMillis := ctx.GlobalInt(RaftBlockTimeFlag.Name)
  2216. raftLogDir := nodeCfg.RaftLogDir // default value is set either 'datadir' or 'raftlogdir'
  2217. joinExistingId := ctx.GlobalInt(RaftJoinExistingFlag.Name)
  2218. useDns := ctx.GlobalBool(RaftDNSEnabledFlag.Name)
  2219. raftPort := uint16(ctx.GlobalInt(RaftPortFlag.Name))
  2220. privkey := nodeCfg.NodeKey()
  2221. strId := enode.PubkeyToIDV4(&privkey.PublicKey).String()
  2222. blockTimeNanos := time.Duration(blockTimeMillis) * time.Millisecond
  2223. peers := nodeCfg.StaticNodes()
  2224. var myId uint16
  2225. var joinExisting bool
  2226. if joinExistingId > 0 {
  2227. myId = uint16(joinExistingId)
  2228. joinExisting = true
  2229. } else if len(peers) == 0 {
  2230. Fatalf("Raft-based consensus requires either (1) an initial peers list (in static-nodes.json) including this enode hash (%v), or (2) the flag --raftjoinexisting RAFT_ID, where RAFT_ID has been issued by an existing cluster member calling `raft.addPeer(ENODE_ID)` with an enode ID containing this node's enode hash.", strId)
  2231. } else {
  2232. peerIds := make([]string, len(peers))
  2233. for peerIdx, peer := range peers {
  2234. if !peer.HasRaftPort() {
  2235. Fatalf("raftport querystring parameter not specified in static-node enode ID: %v. please check your static-nodes.json file.", peer.String())
  2236. }
  2237. peerId := peer.ID().String()
  2238. peerIds[peerIdx] = peerId
  2239. if peerId == strId {
  2240. myId = uint16(peerIdx) + 1
  2241. }
  2242. }
  2243. if myId == 0 {
  2244. Fatalf("failed to find local enode ID (%v) amongst peer IDs: %v", strId, peerIds)
  2245. }
  2246. }
  2247. _, err := raft.New(stack, ethService.BlockChain().Config(), myId, raftPort, joinExisting, blockTimeNanos, ethService, peers, raftLogDir, useDns)
  2248. if err != nil {
  2249. Fatalf("raft: Failed to register the Raft service: %v", err)
  2250. }
  2251. log.Info("raft service registered")
  2252. }
  2253. func RegisterExtensionService(stack *node.Node, ethService *eth.Ethereum) {
  2254. _, err := extension.NewServicesFactory(stack, private.P, ethService)
  2255. if err != nil {
  2256. Fatalf("Failed to register the Extension service: %v", err)
  2257. }
  2258. log.Info("extension service registered")
  2259. }
  2260. func SetupMetrics(ctx *cli.Context) {
  2261. if metrics.Enabled {
  2262. log.Info("Enabling metrics collection")
  2263. var (
  2264. enableExport = ctx.GlobalBool(MetricsEnableInfluxDBFlag.Name)
  2265. endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
  2266. database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
  2267. username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
  2268. password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
  2269. )
  2270. if enableExport {
  2271. tagsMap := SplitTagsFlag(ctx.GlobalString(MetricsInfluxDBTagsFlag.Name))
  2272. log.Info("Enabling metrics export to InfluxDB")
  2273. go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "geth.", tagsMap)
  2274. }
  2275. if ctx.GlobalIsSet(MetricsHTTPFlag.Name) {
  2276. address := fmt.Sprintf("%s:%d", ctx.GlobalString(MetricsHTTPFlag.Name), ctx.GlobalInt(MetricsPortFlag.Name))
  2277. log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
  2278. exp.Setup(address)
  2279. }
  2280. }
  2281. }
  2282. func SplitTagsFlag(tagsFlag string) map[string]string {
  2283. tags := strings.Split(tagsFlag, ",")
  2284. tagsMap := map[string]string{}
  2285. for _, t := range tags {
  2286. if t != "" {
  2287. kv := strings.Split(t, "=")
  2288. if len(kv) == 2 {
  2289. tagsMap[kv[0]] = kv[1]
  2290. }
  2291. }
  2292. }
  2293. return tagsMap
  2294. }
  2295. // MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
  2296. func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.Database {
  2297. var (
  2298. cache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
  2299. handles = MakeDatabaseHandles()
  2300. err error
  2301. chainDb ethdb.Database
  2302. )
  2303. if ctx.GlobalString(SyncModeFlag.Name) == "light" {
  2304. name := "lightchaindata"
  2305. chainDb, err = stack.OpenDatabase(name, cache, handles, "", readonly)
  2306. } else {
  2307. name := "chaindata"
  2308. chainDb, err = stack.OpenDatabaseWithFreezer(name, cache, handles, ctx.GlobalString(AncientFlag.Name), "", readonly)
  2309. }
  2310. if err != nil {
  2311. Fatalf("Could not open database: %v", err)
  2312. }
  2313. return chainDb
  2314. }
  2315. func MakeGenesis(ctx *cli.Context) *core.Genesis {
  2316. var genesis *core.Genesis
  2317. switch {
  2318. case ctx.GlobalBool(MainnetFlag.Name):
  2319. genesis = core.DefaultGenesisBlock()
  2320. case ctx.GlobalBool(RopstenFlag.Name):
  2321. genesis = core.DefaultRopstenGenesisBlock()
  2322. case ctx.GlobalBool(RinkebyFlag.Name):
  2323. genesis = core.DefaultRinkebyGenesisBlock()
  2324. case ctx.GlobalBool(GoerliFlag.Name):
  2325. genesis = core.DefaultGoerliGenesisBlock()
  2326. case ctx.GlobalBool(YoloV3Flag.Name):
  2327. genesis = core.DefaultYoloV3GenesisBlock()
  2328. case ctx.GlobalBool(DeveloperFlag.Name):
  2329. Fatalf("Developer chains are ephemeral")
  2330. }
  2331. return genesis
  2332. }
  2333. func MakeChain(ctx *cli.Context, stack *node.Node, useExist bool) (chain *core.BlockChain, chainDb ethdb.Database) {
  2334. var err error
  2335. var config *params.ChainConfig
  2336. chainDb = MakeChainDatabase(ctx, stack, false) // TODO(rjl493456442) support read-only database
  2337. if useExist {
  2338. stored := rawdb.ReadCanonicalHash(chainDb, 0)
  2339. if (stored == common.Hash{}) {
  2340. Fatalf("No existing genesis")
  2341. }
  2342. config = rawdb.ReadChainConfig(chainDb, stored)
  2343. } else {
  2344. config, _, err = core.SetupGenesisBlock(chainDb, MakeGenesis(ctx))
  2345. if err != nil {
  2346. Fatalf("%v", err)
  2347. }
  2348. }
  2349. var engine consensus.Engine
  2350. client, err := stack.Attach()
  2351. if err != nil {
  2352. Fatalf("Failed to attach to self: %v", err)
  2353. }
  2354. // Lazy logic
  2355. if config.Clique == nil && config.QBFT == nil && config.IBFT == nil && config.Istanbul == nil {
  2356. config.GetTransitionValue(big.NewInt(0), func(t params.Transition) {
  2357. if strings.EqualFold(t.Algorithm, params.QBFT) {
  2358. config.QBFT = &params.QBFTConfig{}
  2359. }
  2360. if strings.EqualFold(t.Algorithm, params.IBFT) {
  2361. config.IBFT = &params.IBFTConfig{}
  2362. }
  2363. })
  2364. }
  2365. if config.Clique != nil {
  2366. engine = clique.New(config.Clique, chainDb)
  2367. } else if config.Istanbul != nil {
  2368. log.Warn("WARNING: The attribute config.istanbul is deprecated and will be removed in the future, please use config.ibft on genesis file")
  2369. // for IBFT
  2370. istanbulConfig := istanbul.DefaultConfig
  2371. if config.Istanbul.Epoch != 0 {
  2372. istanbulConfig.Epoch = config.Istanbul.Epoch
  2373. }
  2374. istanbulConfig.ProposerPolicy = istanbul.NewProposerPolicy(istanbul.ProposerPolicyId(config.Istanbul.ProposerPolicy))
  2375. istanbulConfig.Ceil2Nby3Block = config.Istanbul.Ceil2Nby3Block
  2376. istanbulConfig.TestQBFTBlock = config.Istanbul.TestQBFTBlock
  2377. istanbulConfig.Transitions = config.Transitions
  2378. istanbulConfig.Client = ethclient.NewClient(client)
  2379. engine = istanbulBackend.New(istanbulConfig, stack.GetNodeKey(), chainDb)
  2380. } else if config.IBFT != nil {
  2381. ibftConfig := setBFTConfig(config.IBFT.BFTConfig)
  2382. ibftConfig.TestQBFTBlock = nil
  2383. ibftConfig.Transitions = config.Transitions
  2384. ibftConfig.Client = ethclient.NewClient(client)
  2385. engine = istanbulBackend.New(ibftConfig, stack.GetNodeKey(), chainDb)
  2386. } else if config.QBFT != nil {
  2387. qbftConfig := setBFTConfig(config.QBFT.BFTConfig)
  2388. qbftConfig.BlockReward = config.QBFT.BlockReward
  2389. qbftConfig.BeneficiaryMode = config.QBFT.BeneficiaryMode // beneficiary mode: list, besu, validators
  2390. qbftConfig.MiningBeneficiary = config.QBFT.MiningBeneficiary // auto (undefined mode) and besu mode
  2391. qbftConfig.TestQBFTBlock = big.NewInt(0)
  2392. qbftConfig.Transitions = config.Transitions
  2393. qbftConfig.ValidatorContract = config.QBFT.ValidatorContractAddress
  2394. qbftConfig.ValidatorSelectionMode = config.QBFT.ValidatorSelectionMode
  2395. qbftConfig.Validators = config.QBFT.Validators
  2396. qbftConfig.Client = ethclient.NewClient(client)
  2397. engine = istanbulBackend.New(qbftConfig, stack.GetNodeKey(), chainDb)
  2398. } else if config.IsQuorum {
  2399. // for Raft
  2400. engine = ethash.NewFullFaker()
  2401. } else {
  2402. engine = ethash.NewFaker()
  2403. if !ctx.GlobalBool(FakePoWFlag.Name) {
  2404. engine = ethash.New(ethash.Config{
  2405. CacheDir: stack.ResolvePath(ethconfig.Defaults.Ethash.CacheDir),
  2406. CachesInMem: ethconfig.Defaults.Ethash.CachesInMem,
  2407. CachesOnDisk: ethconfig.Defaults.Ethash.CachesOnDisk,
  2408. CachesLockMmap: ethconfig.Defaults.Ethash.CachesLockMmap,
  2409. DatasetDir: stack.ResolvePath(ethconfig.Defaults.Ethash.DatasetDir),
  2410. DatasetsInMem: ethconfig.Defaults.Ethash.DatasetsInMem,
  2411. DatasetsOnDisk: ethconfig.Defaults.Ethash.DatasetsOnDisk,
  2412. DatasetsLockMmap: ethconfig.Defaults.Ethash.DatasetsLockMmap,
  2413. }, nil, false)
  2414. }
  2415. }
  2416. if gcmode := ctx.GlobalString(GCModeFlag.Name); gcmode != "full" && gcmode != "archive" {
  2417. Fatalf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
  2418. }
  2419. cache := &core.CacheConfig{
  2420. TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
  2421. TrieCleanNoPrefetch: ctx.GlobalBool(CacheNoPrefetchFlag.Name),
  2422. TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,
  2423. TrieDirtyDisabled: ctx.GlobalString(GCModeFlag.Name) == "archive",
  2424. TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
  2425. SnapshotLimit: ethconfig.Defaults.SnapshotCache,
  2426. Preimages: ctx.GlobalBool(CachePreimagesFlag.Name),
  2427. }
  2428. if true || cache.TrieDirtyDisabled && !cache.Preimages { // TODO: Quorum; force preimages for contract extension and dump of states compatibility, until a fix is found
  2429. cache.Preimages = true
  2430. log.Info("Enabling recording of key preimages since archive mode is used")
  2431. }
  2432. if !ctx.GlobalBool(SnapshotFlag.Name) {
  2433. cache.SnapshotLimit = 0 // Disabled
  2434. }
  2435. if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheTrieFlag.Name) {
  2436. cache.TrieCleanLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheTrieFlag.Name) / 100
  2437. }
  2438. if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
  2439. cache.TrieDirtyLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
  2440. }
  2441. vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)}
  2442. // Quorum
  2443. var limit *uint64
  2444. if ctx.GlobalIsSet(TxLookupLimitFlag.Name) {
  2445. l := ctx.GlobalUint64(TxLookupLimitFlag.Name)
  2446. limit = &l
  2447. }
  2448. // End Quorum
  2449. // TODO(rjl493456442) disable snapshot generation/wiping if the chain is read only.
  2450. // Disable transaction indexing/unindexing by default.
  2451. // TODO should multiple private states work with import/export/inspect commands
  2452. chain, err = core.NewBlockChain(chainDb, cache, config, engine, vmcfg, nil, limit, nil)
  2453. if err != nil {
  2454. Fatalf("Can't create BlockChain: %v", err)
  2455. }
  2456. return chain, chainDb
  2457. }
  2458. func setBFTConfig(bftConfig *params.BFTConfig) *istanbul.Config {
  2459. istanbulConfig := istanbul.DefaultConfig
  2460. if bftConfig.BlockPeriodSeconds != 0 {
  2461. istanbulConfig.BlockPeriod = bftConfig.BlockPeriodSeconds
  2462. }
  2463. if bftConfig.EmptyBlockPeriodSeconds != nil {
  2464. istanbulConfig.EmptyBlockPeriod = *bftConfig.EmptyBlockPeriodSeconds
  2465. }
  2466. if bftConfig.RequestTimeoutSeconds != 0 {
  2467. istanbulConfig.RequestTimeout = bftConfig.RequestTimeoutSeconds * 1000
  2468. }
  2469. if bftConfig.EpochLength != 0 {
  2470. istanbulConfig.Epoch = bftConfig.EpochLength
  2471. }
  2472. if bftConfig.ProposerPolicy != 0 {
  2473. istanbulConfig.ProposerPolicy = istanbul.NewProposerPolicy(istanbul.ProposerPolicyId(bftConfig.ProposerPolicy))
  2474. }
  2475. if bftConfig.Ceil2Nby3Block != nil {
  2476. istanbulConfig.Ceil2Nby3Block = bftConfig.Ceil2Nby3Block
  2477. }
  2478. return istanbulConfig
  2479. }
  2480. // MakeConsolePreloads retrieves the absolute paths for the console JavaScript
  2481. // scripts to preload before starting.
  2482. func MakeConsolePreloads(ctx *cli.Context) []string {
  2483. // Skip preloading if there's nothing to preload
  2484. if ctx.GlobalString(PreloadJSFlag.Name) == "" {
  2485. return nil
  2486. }
  2487. // Otherwise resolve absolute paths and return them
  2488. var preloads []string
  2489. for _, file := range strings.Split(ctx.GlobalString(PreloadJSFlag.Name), ",") {
  2490. preloads = append(preloads, strings.TrimSpace(file))
  2491. }
  2492. return preloads
  2493. }
  2494. // MigrateFlags sets the global flag from a local flag when it's set.
  2495. // This is a temporary function used for migrating old command/flags to the
  2496. // new format.
  2497. //
  2498. // e.g. geth account new --keystore /tmp/mykeystore --lightkdf
  2499. //
  2500. // is equivalent after calling this method with:
  2501. //
  2502. // geth --keystore /tmp/mykeystore --lightkdf account new
  2503. //
  2504. // This allows the use of the existing configuration functionality.
  2505. // When all flags are migrated this function can be removed and the existing
  2506. // configuration functionality must be changed that is uses local flags
  2507. func MigrateFlags(action func(ctx *cli.Context) error) func(*cli.Context) error {
  2508. return func(ctx *cli.Context) error {
  2509. for _, name := range ctx.FlagNames() {
  2510. if ctx.IsSet(name) {
  2511. ctx.GlobalSet(name, ctx.String(name))
  2512. }
  2513. }
  2514. return action(ctx)
  2515. }
  2516. }
  2517. func isValidTokenManagement(value string) bool {
  2518. switch value {
  2519. case
  2520. "none",
  2521. "external",
  2522. "client-security-plugin":
  2523. return true
  2524. }
  2525. return false
  2526. }