config.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser 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. // The go-ethereum library 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 Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package params
  17. import (
  18. "encoding/binary"
  19. "fmt"
  20. "math/big"
  21. "github.com/ethereum/go-ethereum/common"
  22. "golang.org/x/crypto/sha3"
  23. )
  24. // Genesis hashes to enforce below configs on.
  25. var (
  26. MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
  27. RopstenGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
  28. RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
  29. GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
  30. BSCGenesisHash = common.HexToHash("0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b")
  31. ChapelGenesisHash = common.HexToHash("0x6d3c66c5357ec91d5c43af47e234a939b22557cbb552dc45bebbceeed90fbe34")
  32. RialtoGenesisHash = common.HexToHash("0xaabe549bfa85c84f7aee9da7010b97453ad686f2c2d8ce00503d1a00c72cad54")
  33. YoloV3GenesisHash = common.HexToHash("0xf1f2876e8500c77afcc03228757b39477eceffccf645b734967fe3c7e16967b7")
  34. )
  35. // TrustedCheckpoints associates each known checkpoint with the genesis hash of
  36. // the chain it belongs to.
  37. var TrustedCheckpoints = map[common.Hash]*TrustedCheckpoint{
  38. MainnetGenesisHash: MainnetTrustedCheckpoint,
  39. RopstenGenesisHash: RopstenTrustedCheckpoint,
  40. RinkebyGenesisHash: RinkebyTrustedCheckpoint,
  41. GoerliGenesisHash: GoerliTrustedCheckpoint,
  42. }
  43. // CheckpointOracles associates each known checkpoint oracles with the genesis hash of
  44. // the chain it belongs to.
  45. var CheckpointOracles = map[common.Hash]*CheckpointOracleConfig{
  46. MainnetGenesisHash: MainnetCheckpointOracle,
  47. RopstenGenesisHash: RopstenCheckpointOracle,
  48. RinkebyGenesisHash: RinkebyCheckpointOracle,
  49. GoerliGenesisHash: GoerliCheckpointOracle,
  50. }
  51. var (
  52. // MainnetChainConfig is the chain parameters to run a node on the main network.
  53. MainnetChainConfig = &ChainConfig{
  54. ChainID: big.NewInt(1),
  55. HomesteadBlock: big.NewInt(1_150_000),
  56. DAOForkBlock: big.NewInt(1_920_000),
  57. DAOForkSupport: true,
  58. EIP150Block: big.NewInt(2_463_000),
  59. EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
  60. EIP155Block: big.NewInt(2_675_000),
  61. EIP158Block: big.NewInt(2_675_000),
  62. ByzantiumBlock: big.NewInt(4_370_000),
  63. ConstantinopleBlock: big.NewInt(7_280_000),
  64. PetersburgBlock: big.NewInt(7_280_000),
  65. IstanbulBlock: big.NewInt(9_069_000),
  66. MuirGlacierBlock: big.NewInt(9_200_000),
  67. RamanujanBlock: big.NewInt(0),
  68. NielsBlock: big.NewInt(0),
  69. MirrorSyncBlock: big.NewInt(0),
  70. BrunoBlock: big.NewInt(0),
  71. BerlinBlock: big.NewInt(12_244_000),
  72. Ethash: new(EthashConfig),
  73. }
  74. // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network.
  75. MainnetTrustedCheckpoint = &TrustedCheckpoint{
  76. SectionIndex: 371,
  77. SectionHead: common.HexToHash("0x50fd3cec5376ede90ef9129772022690cd1467f22c18abb7faa11e793c51e9c9"),
  78. CHTRoot: common.HexToHash("0xb57b4b22a77b5930847b1ca9f62daa11eae6578948cb7b18997f2c0fe5757025"),
  79. BloomRoot: common.HexToHash("0xa338f8a868a194fa90327d0f5877f656a9f3640c618d2a01a01f2e76ef9ef954"),
  80. }
  81. // MainnetCheckpointOracle contains a set of configs for the main network oracle.
  82. MainnetCheckpointOracle = &CheckpointOracleConfig{
  83. Address: common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"),
  84. Signers: []common.Address{
  85. common.HexToAddress("0x1b2C260efc720BE89101890E4Db589b44E950527"), // Peter
  86. common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
  87. common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
  88. common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
  89. common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume
  90. },
  91. Threshold: 2,
  92. }
  93. // RopstenChainConfig contains the chain parameters to run a node on the Ropsten test network.
  94. RopstenChainConfig = &ChainConfig{
  95. ChainID: big.NewInt(3),
  96. HomesteadBlock: big.NewInt(0),
  97. DAOForkBlock: nil,
  98. DAOForkSupport: true,
  99. EIP150Block: big.NewInt(0),
  100. EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
  101. EIP155Block: big.NewInt(10),
  102. EIP158Block: big.NewInt(10),
  103. ByzantiumBlock: big.NewInt(1_700_000),
  104. ConstantinopleBlock: big.NewInt(4_230_000),
  105. PetersburgBlock: big.NewInt(4_939_394),
  106. IstanbulBlock: big.NewInt(6_485_846),
  107. MuirGlacierBlock: big.NewInt(7_117_117),
  108. RamanujanBlock: big.NewInt(0),
  109. NielsBlock: big.NewInt(0),
  110. MirrorSyncBlock: big.NewInt(0),
  111. BrunoBlock: big.NewInt(0),
  112. BerlinBlock: big.NewInt(9_812_189),
  113. Ethash: new(EthashConfig),
  114. }
  115. // RopstenTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network.
  116. RopstenTrustedCheckpoint = &TrustedCheckpoint{
  117. SectionIndex: 279,
  118. SectionHead: common.HexToHash("0x4a4912848d4c06090097073357c10015d11c6f4544a0f93cbdd584701c3b7d58"),
  119. CHTRoot: common.HexToHash("0x9053b7867ae921e80a4e2f5a4b15212e4af3d691ca712fb33dc150e9c6ea221c"),
  120. BloomRoot: common.HexToHash("0x3dc04cb1be7ddc271f3f83469b47b76184a79d7209ef51d85b1539ea6d25a645"),
  121. }
  122. // RopstenCheckpointOracle contains a set of configs for the Ropsten test network oracle.
  123. RopstenCheckpointOracle = &CheckpointOracleConfig{
  124. Address: common.HexToAddress("0xEF79475013f154E6A65b54cB2742867791bf0B84"),
  125. Signers: []common.Address{
  126. common.HexToAddress("0x32162F3581E88a5f62e8A61892B42C46E2c18f7b"), // Peter
  127. common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
  128. common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
  129. common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
  130. common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume
  131. },
  132. Threshold: 2,
  133. }
  134. // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
  135. RinkebyChainConfig = &ChainConfig{
  136. ChainID: big.NewInt(4),
  137. HomesteadBlock: big.NewInt(1),
  138. DAOForkBlock: nil,
  139. DAOForkSupport: true,
  140. EIP150Block: big.NewInt(2),
  141. EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
  142. EIP155Block: big.NewInt(3),
  143. EIP158Block: big.NewInt(3),
  144. ByzantiumBlock: big.NewInt(1_035_301),
  145. ConstantinopleBlock: big.NewInt(3_660_663),
  146. PetersburgBlock: big.NewInt(4_321_234),
  147. IstanbulBlock: big.NewInt(5_435_345),
  148. MuirGlacierBlock: nil,
  149. RamanujanBlock: big.NewInt(0),
  150. NielsBlock: big.NewInt(0),
  151. MirrorSyncBlock: big.NewInt(0),
  152. BrunoBlock: big.NewInt(0),
  153. BerlinBlock: big.NewInt(8_290_928),
  154. Clique: &CliqueConfig{
  155. Period: 15,
  156. Epoch: 30000,
  157. },
  158. }
  159. // RinkebyTrustedCheckpoint contains the light client trusted checkpoint for the Rinkeby test network.
  160. RinkebyTrustedCheckpoint = &TrustedCheckpoint{
  161. SectionIndex: 254,
  162. SectionHead: common.HexToHash("0x0cba01dd71baa22ac8fa0b105bc908e94f9ecfbc79b4eb97427fe07b5851dd10"),
  163. CHTRoot: common.HexToHash("0x5673d8fc49c9c7d8729068640e4b392d46952a5a38798973bac1cf1d0d27ad7d"),
  164. BloomRoot: common.HexToHash("0x70e01232b66df9a7778ae3291c9217afb9a2d9f799f32d7b912bd37e7bce83a8"),
  165. }
  166. // RinkebyCheckpointOracle contains a set of configs for the Rinkeby test network oracle.
  167. RinkebyCheckpointOracle = &CheckpointOracleConfig{
  168. Address: common.HexToAddress("0xebe8eFA441B9302A0d7eaECc277c09d20D684540"),
  169. Signers: []common.Address{
  170. common.HexToAddress("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"), // Peter
  171. common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
  172. common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
  173. common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
  174. },
  175. Threshold: 2,
  176. }
  177. // GoerliChainConfig contains the chain parameters to run a node on the Görli test network.
  178. GoerliChainConfig = &ChainConfig{
  179. ChainID: big.NewInt(5),
  180. HomesteadBlock: big.NewInt(0),
  181. DAOForkBlock: nil,
  182. DAOForkSupport: true,
  183. EIP150Block: big.NewInt(0),
  184. EIP155Block: big.NewInt(0),
  185. EIP158Block: big.NewInt(0),
  186. ByzantiumBlock: big.NewInt(0),
  187. ConstantinopleBlock: big.NewInt(0),
  188. PetersburgBlock: big.NewInt(0),
  189. RamanujanBlock: big.NewInt(0),
  190. NielsBlock: big.NewInt(0),
  191. MirrorSyncBlock: big.NewInt(0),
  192. BrunoBlock: big.NewInt(0),
  193. IstanbulBlock: big.NewInt(1_561_651),
  194. MuirGlacierBlock: nil,
  195. BerlinBlock: big.NewInt(4_460_644),
  196. Clique: &CliqueConfig{
  197. Period: 15,
  198. Epoch: 30000,
  199. },
  200. }
  201. // GoerliTrustedCheckpoint contains the light client trusted checkpoint for the Görli test network.
  202. GoerliTrustedCheckpoint = &TrustedCheckpoint{
  203. SectionIndex: 138,
  204. SectionHead: common.HexToHash("0xb7ea0566abd7d0def5b3c9afa3431debb7bb30b65af35f106ca93a59e6c859a7"),
  205. CHTRoot: common.HexToHash("0x378c7ea9081242beb982e2e39567ba12f2ed3e59e5aba3f9db1d595646d7c9f4"),
  206. BloomRoot: common.HexToHash("0x523c169286cfca52e8a6579d8c35dc8bf093412d8a7478163bfa81ae91c2492d"),
  207. }
  208. // GoerliCheckpointOracle contains a set of configs for the Goerli test network oracle.
  209. GoerliCheckpointOracle = &CheckpointOracleConfig{
  210. Address: common.HexToAddress("0x18CA0E045F0D772a851BC7e48357Bcaab0a0795D"),
  211. Signers: []common.Address{
  212. common.HexToAddress("0x4769bcaD07e3b938B7f43EB7D278Bc7Cb9efFb38"), // Peter
  213. common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
  214. common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
  215. common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
  216. common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume
  217. },
  218. Threshold: 2,
  219. }
  220. BSCChainConfig = &ChainConfig{
  221. ChainID: big.NewInt(56),
  222. HomesteadBlock: big.NewInt(0),
  223. EIP150Block: big.NewInt(0),
  224. EIP155Block: big.NewInt(0),
  225. EIP158Block: big.NewInt(0),
  226. ByzantiumBlock: big.NewInt(0),
  227. ConstantinopleBlock: big.NewInt(0),
  228. PetersburgBlock: big.NewInt(0),
  229. IstanbulBlock: big.NewInt(0),
  230. MuirGlacierBlock: big.NewInt(0),
  231. RamanujanBlock: big.NewInt(0),
  232. NielsBlock: big.NewInt(0),
  233. MirrorSyncBlock: big.NewInt(5184000),
  234. BrunoBlock: big.NewInt(13082000),
  235. Parlia: &ParliaConfig{
  236. Period: 3,
  237. Epoch: 200,
  238. },
  239. }
  240. ChapelChainConfig = &ChainConfig{
  241. ChainID: big.NewInt(97),
  242. HomesteadBlock: big.NewInt(0),
  243. EIP150Block: big.NewInt(0),
  244. EIP155Block: big.NewInt(0),
  245. EIP158Block: big.NewInt(0),
  246. ByzantiumBlock: big.NewInt(0),
  247. ConstantinopleBlock: big.NewInt(0),
  248. PetersburgBlock: big.NewInt(0),
  249. IstanbulBlock: big.NewInt(0),
  250. MuirGlacierBlock: big.NewInt(0),
  251. RamanujanBlock: big.NewInt(1010000),
  252. NielsBlock: big.NewInt(1014369),
  253. MirrorSyncBlock: big.NewInt(5582500),
  254. BrunoBlock: big.NewInt(13837000),
  255. Parlia: &ParliaConfig{
  256. Period: 3,
  257. Epoch: 200,
  258. },
  259. }
  260. RialtoChainConfig = &ChainConfig{
  261. ChainID: big.NewInt(1417),
  262. HomesteadBlock: big.NewInt(0),
  263. EIP150Block: big.NewInt(0),
  264. EIP155Block: big.NewInt(0),
  265. EIP158Block: big.NewInt(0),
  266. ByzantiumBlock: big.NewInt(0),
  267. ConstantinopleBlock: big.NewInt(0),
  268. PetersburgBlock: big.NewInt(0),
  269. IstanbulBlock: big.NewInt(0),
  270. MuirGlacierBlock: big.NewInt(0),
  271. RamanujanBlock: big.NewInt(400),
  272. NielsBlock: big.NewInt(0),
  273. MirrorSyncBlock: big.NewInt(400),
  274. BrunoBlock: big.NewInt(400),
  275. Parlia: &ParliaConfig{
  276. Period: 3,
  277. Epoch: 200,
  278. },
  279. }
  280. // YoloV3ChainConfig contains the chain parameters to run a node on the YOLOv3 test network.
  281. YoloV3ChainConfig = &ChainConfig{
  282. ChainID: new(big.Int).SetBytes([]byte("yolov3x")),
  283. HomesteadBlock: big.NewInt(0),
  284. DAOForkBlock: nil,
  285. DAOForkSupport: true,
  286. EIP150Block: big.NewInt(0),
  287. EIP155Block: big.NewInt(0),
  288. EIP158Block: big.NewInt(0),
  289. ByzantiumBlock: big.NewInt(0),
  290. ConstantinopleBlock: big.NewInt(0),
  291. PetersburgBlock: big.NewInt(0),
  292. IstanbulBlock: big.NewInt(0),
  293. RamanujanBlock: big.NewInt(0),
  294. NielsBlock: big.NewInt(0),
  295. MirrorSyncBlock: big.NewInt(0),
  296. BrunoBlock: big.NewInt(0),
  297. MuirGlacierBlock: nil,
  298. BerlinBlock: nil, // Don't enable Berlin directly, we're YOLOing it
  299. YoloV3Block: big.NewInt(0),
  300. Clique: &CliqueConfig{
  301. Period: 15,
  302. Epoch: 30000,
  303. },
  304. }
  305. // AllEthashProtocolChanges contains every protocol change (EIPs) introduced
  306. // and accepted by the Ethereum core developers into the Ethash consensus.
  307. //
  308. // This configuration is intentionally not using keyed fields to force anyone
  309. // adding flags to the config to also have to set these fields.
  310. AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
  311. // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
  312. // and accepted by the Ethereum core developers into the Clique consensus.
  313. //
  314. // This configuration is intentionally not using keyed fields to force anyone
  315. // adding flags to the config to also have to set these fields.
  316. AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
  317. TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
  318. TestRules = TestChainConfig.Rules(new(big.Int))
  319. )
  320. // TrustedCheckpoint represents a set of post-processed trie roots (CHT and
  321. // BloomTrie) associated with the appropriate section index and head hash. It is
  322. // used to start light syncing from this checkpoint and avoid downloading the
  323. // entire header chain while still being able to securely access old headers/logs.
  324. type TrustedCheckpoint struct {
  325. SectionIndex uint64 `json:"sectionIndex"`
  326. SectionHead common.Hash `json:"sectionHead"`
  327. CHTRoot common.Hash `json:"chtRoot"`
  328. BloomRoot common.Hash `json:"bloomRoot"`
  329. }
  330. // HashEqual returns an indicator comparing the itself hash with given one.
  331. func (c *TrustedCheckpoint) HashEqual(hash common.Hash) bool {
  332. if c.Empty() {
  333. return hash == common.Hash{}
  334. }
  335. return c.Hash() == hash
  336. }
  337. // Hash returns the hash of checkpoint's four key fields(index, sectionHead, chtRoot and bloomTrieRoot).
  338. func (c *TrustedCheckpoint) Hash() common.Hash {
  339. var sectionIndex [8]byte
  340. binary.BigEndian.PutUint64(sectionIndex[:], c.SectionIndex)
  341. w := sha3.NewLegacyKeccak256()
  342. w.Write(sectionIndex[:])
  343. w.Write(c.SectionHead[:])
  344. w.Write(c.CHTRoot[:])
  345. w.Write(c.BloomRoot[:])
  346. var h common.Hash
  347. w.Sum(h[:0])
  348. return h
  349. }
  350. // Empty returns an indicator whether the checkpoint is regarded as empty.
  351. func (c *TrustedCheckpoint) Empty() bool {
  352. return c.SectionHead == (common.Hash{}) || c.CHTRoot == (common.Hash{}) || c.BloomRoot == (common.Hash{})
  353. }
  354. // CheckpointOracleConfig represents a set of checkpoint contract(which acts as an oracle)
  355. // config which used for light client checkpoint syncing.
  356. type CheckpointOracleConfig struct {
  357. Address common.Address `json:"address"`
  358. Signers []common.Address `json:"signers"`
  359. Threshold uint64 `json:"threshold"`
  360. }
  361. // ChainConfig is the core config which determines the blockchain settings.
  362. //
  363. // ChainConfig is stored in the database on a per block basis. This means
  364. // that any network, identified by its genesis block, can have its own
  365. // set of configuration options.
  366. type ChainConfig struct {
  367. ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection
  368. HomesteadBlock *big.Int `json:"homesteadBlock,omitempty" toml:",omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead)
  369. DAOForkBlock *big.Int `json:"daoForkBlock,omitempty" toml:",omitempty"` // TheDAO hard-fork switch block (nil = no fork)
  370. DAOForkSupport bool `json:"daoForkSupport,omitempty" toml:",omitempty"` // Whether the nodes supports or opposes the DAO hard-fork
  371. // EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150)
  372. EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork)
  373. EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (needed for header only clients as only gas pricing changed)
  374. EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block
  375. EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block
  376. ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium)
  377. ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated)
  378. PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople)
  379. IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul)
  380. MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
  381. BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin)
  382. YoloV3Block *big.Int `json:"yoloV3Block,omitempty"` // YOLO v3: Gas repricings TODO @holiman add EIP references
  383. EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated) RamanujanBlock *big.Int `json:"ramanujanBlock,omitempty" toml:",omitempty"` // ramanujanBlock switch block (nil = no fork, 0 = already activated)
  384. CatalystBlock *big.Int `json:"catalystBlock,omitempty"` // Catalyst switch block (nil = no fork, 0 = already on catalyst)
  385. RamanujanBlock *big.Int `json:"ramanujanBlock,omitempty" toml:",omitempty"` // ramanujanBlock switch block (nil = no fork, 0 = already activated)
  386. NielsBlock *big.Int `json:"nielsBlock,omitempty" toml:",omitempty"` // nielsBlock switch block (nil = no fork, 0 = already activated)
  387. MirrorSyncBlock *big.Int `json:"mirrorSyncBlock,omitempty" toml:",omitempty"` // mirrorSyncBlock switch block (nil = no fork, 0 = already activated)
  388. BrunoBlock *big.Int `json:"brunoBlock,omitempty" toml:",omitempty"` // brunoBlock switch block (nil = no fork, 0 = already activated)
  389. // Various consensus engines
  390. Ethash *EthashConfig `json:"ethash,omitempty" toml:",omitempty"`
  391. Clique *CliqueConfig `json:"clique,omitempty" toml:",omitempty"`
  392. Parlia *ParliaConfig `json:"parlia,omitempty" toml:",omitempty"`
  393. }
  394. // EthashConfig is the consensus engine configs for proof-of-work based sealing.
  395. type EthashConfig struct{}
  396. // String implements the stringer interface, returning the consensus engine details.
  397. func (c *EthashConfig) String() string {
  398. return "ethash"
  399. }
  400. // CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
  401. type CliqueConfig struct {
  402. Period uint64 `json:"period"` // Number of seconds between blocks to enforce
  403. Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
  404. }
  405. // String implements the stringer interface, returning the consensus engine details.
  406. func (c *CliqueConfig) String() string {
  407. return "clique"
  408. }
  409. // ParliaConfig is the consensus engine configs for proof-of-staked-authority based sealing.
  410. type ParliaConfig struct {
  411. Period uint64 `json:"period"` // Number of seconds between blocks to enforce
  412. Epoch uint64 `json:"epoch"` // Epoch length to update validatorSet
  413. }
  414. // String implements the stringer interface, returning the consensus engine details.
  415. func (b *ParliaConfig) String() string {
  416. return "parlia"
  417. }
  418. // String implements the fmt.Stringer interface.
  419. func (c *ChainConfig) String() string {
  420. var engine interface{}
  421. switch {
  422. case c.Ethash != nil:
  423. engine = c.Ethash
  424. case c.Clique != nil:
  425. engine = c.Clique
  426. case c.Parlia != nil:
  427. engine = c.Parlia
  428. default:
  429. engine = "unknown"
  430. }
  431. return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, Engine: %v}",
  432. c.ChainID,
  433. c.HomesteadBlock,
  434. c.DAOForkBlock,
  435. c.DAOForkSupport,
  436. c.EIP150Block,
  437. c.EIP155Block,
  438. c.EIP158Block,
  439. c.ByzantiumBlock,
  440. c.ConstantinopleBlock,
  441. c.PetersburgBlock,
  442. c.IstanbulBlock,
  443. c.MuirGlacierBlock,
  444. c.RamanujanBlock,
  445. c.NielsBlock,
  446. c.MirrorSyncBlock,
  447. c.BrunoBlock,
  448. c.BerlinBlock,
  449. c.YoloV3Block,
  450. engine,
  451. )
  452. }
  453. // IsHomestead returns whether num is either equal to the homestead block or greater.
  454. func (c *ChainConfig) IsHomestead(num *big.Int) bool {
  455. return isForked(c.HomesteadBlock, num)
  456. }
  457. // IsDAOFork returns whether num is either equal to the DAO fork block or greater.
  458. func (c *ChainConfig) IsDAOFork(num *big.Int) bool {
  459. return isForked(c.DAOForkBlock, num)
  460. }
  461. // IsEIP150 returns whether num is either equal to the EIP150 fork block or greater.
  462. func (c *ChainConfig) IsEIP150(num *big.Int) bool {
  463. return isForked(c.EIP150Block, num)
  464. }
  465. // IsEIP155 returns whether num is either equal to the EIP155 fork block or greater.
  466. func (c *ChainConfig) IsEIP155(num *big.Int) bool {
  467. return isForked(c.EIP155Block, num)
  468. }
  469. // IsEIP158 returns whether num is either equal to the EIP158 fork block or greater.
  470. func (c *ChainConfig) IsEIP158(num *big.Int) bool {
  471. return isForked(c.EIP158Block, num)
  472. }
  473. // IsByzantium returns whether num is either equal to the Byzantium fork block or greater.
  474. func (c *ChainConfig) IsByzantium(num *big.Int) bool {
  475. return isForked(c.ByzantiumBlock, num)
  476. }
  477. // IsConstantinople returns whether num is either equal to the Constantinople fork block or greater.
  478. func (c *ChainConfig) IsConstantinople(num *big.Int) bool {
  479. return isForked(c.ConstantinopleBlock, num)
  480. }
  481. // IsRamanujan returns whether num is either equal to the IsRamanujan fork block or greater.
  482. func (c *ChainConfig) IsRamanujan(num *big.Int) bool {
  483. return isForked(c.RamanujanBlock, num)
  484. }
  485. // IsOnRamanujan returns whether num is equal to the Ramanujan fork block
  486. func (c *ChainConfig) IsOnRamanujan(num *big.Int) bool {
  487. return configNumEqual(c.RamanujanBlock, num)
  488. }
  489. // IsNiels returns whether num is either equal to the Niels fork block or greater.
  490. func (c *ChainConfig) IsNiels(num *big.Int) bool {
  491. return isForked(c.NielsBlock, num)
  492. }
  493. // IsOnNiels returns whether num is equal to the IsNiels fork block
  494. func (c *ChainConfig) IsOnNiels(num *big.Int) bool {
  495. return configNumEqual(c.NielsBlock, num)
  496. }
  497. // IsMirrorSync returns whether num is either equal to the MirrorSync fork block or greater.
  498. func (c *ChainConfig) IsMirrorSync(num *big.Int) bool {
  499. return isForked(c.MirrorSyncBlock, num)
  500. }
  501. // IsOnMirrorSync returns whether num is equal to the MirrorSync fork block
  502. func (c *ChainConfig) IsOnMirrorSync(num *big.Int) bool {
  503. return configNumEqual(c.MirrorSyncBlock, num)
  504. }
  505. // IsBruno returns whether num is either equal to the Burn fork block or greater.
  506. func (c *ChainConfig) IsBruno(num *big.Int) bool {
  507. return isForked(c.BrunoBlock, num)
  508. }
  509. // IsOnBruno returns whether num is equal to the Burn fork block
  510. func (c *ChainConfig) IsOnBruno(num *big.Int) bool {
  511. return configNumEqual(c.BrunoBlock, num)
  512. }
  513. // IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater.
  514. func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool {
  515. return isForked(c.MuirGlacierBlock, num)
  516. }
  517. // IsPetersburg returns whether num is either
  518. // - equal to or greater than the PetersburgBlock fork block,
  519. // - OR is nil, and Constantinople is active
  520. func (c *ChainConfig) IsPetersburg(num *big.Int) bool {
  521. return isForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && isForked(c.ConstantinopleBlock, num)
  522. }
  523. // IsIstanbul returns whether num is either equal to the Istanbul fork block or greater.
  524. func (c *ChainConfig) IsIstanbul(num *big.Int) bool {
  525. return isForked(c.IstanbulBlock, num)
  526. }
  527. // IsBerlin returns whether num is either equal to the Berlin fork block or greater.
  528. func (c *ChainConfig) IsBerlin(num *big.Int) bool {
  529. return isForked(c.BerlinBlock, num) || isForked(c.YoloV3Block, num)
  530. }
  531. // IsCatalyst returns whether num is either equal to the Merge fork block or greater.
  532. func (c *ChainConfig) IsCatalyst(num *big.Int) bool {
  533. return isForked(c.CatalystBlock, num)
  534. }
  535. // IsEWASM returns whether num represents a block number after the EWASM fork
  536. func (c *ChainConfig) IsEWASM(num *big.Int) bool {
  537. return isForked(c.EWASMBlock, num)
  538. }
  539. // CheckCompatible checks whether scheduled fork transitions have been imported
  540. // with a mismatching chain configuration.
  541. func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
  542. bhead := new(big.Int).SetUint64(height)
  543. // Iterate checkCompatible to find the lowest conflict.
  544. var lasterr *ConfigCompatError
  545. for {
  546. err := c.checkCompatible(newcfg, bhead)
  547. if err == nil || (lasterr != nil && err.RewindTo == lasterr.RewindTo) {
  548. break
  549. }
  550. lasterr = err
  551. bhead.SetUint64(err.RewindTo)
  552. }
  553. return lasterr
  554. }
  555. // CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough
  556. // to guarantee that forks can be implemented in a different order than on official networks
  557. func (c *ChainConfig) CheckConfigForkOrder() error {
  558. type fork struct {
  559. name string
  560. block *big.Int
  561. optional bool // if true, the fork may be nil and next fork is still allowed
  562. }
  563. var lastFork fork
  564. for _, cur := range []fork{
  565. {name: "mirrorSyncBlock", block: c.MirrorSyncBlock},
  566. {name: "brunoBlock", block: c.BrunoBlock},
  567. {name: "berlinBlock", block: c.BerlinBlock},
  568. } {
  569. if lastFork.name != "" {
  570. // Next one must be higher number
  571. if lastFork.block == nil && cur.block != nil {
  572. return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at %v",
  573. lastFork.name, cur.name, cur.block)
  574. }
  575. if lastFork.block != nil && cur.block != nil {
  576. if lastFork.block.Cmp(cur.block) > 0 {
  577. return fmt.Errorf("unsupported fork ordering: %v enabled at %v, but %v enabled at %v",
  578. lastFork.name, lastFork.block, cur.name, cur.block)
  579. }
  580. }
  581. }
  582. // If it was optional and not set, then ignore it
  583. if !cur.optional || cur.block != nil {
  584. lastFork = cur
  585. }
  586. }
  587. return nil
  588. }
  589. func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *ConfigCompatError {
  590. if isForkIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, head) {
  591. return newCompatError("Homestead fork block", c.HomesteadBlock, newcfg.HomesteadBlock)
  592. }
  593. if isForkIncompatible(c.DAOForkBlock, newcfg.DAOForkBlock, head) {
  594. return newCompatError("DAO fork block", c.DAOForkBlock, newcfg.DAOForkBlock)
  595. }
  596. if c.IsDAOFork(head) && c.DAOForkSupport != newcfg.DAOForkSupport {
  597. return newCompatError("DAO fork support flag", c.DAOForkBlock, newcfg.DAOForkBlock)
  598. }
  599. if isForkIncompatible(c.EIP150Block, newcfg.EIP150Block, head) {
  600. return newCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block)
  601. }
  602. if isForkIncompatible(c.EIP155Block, newcfg.EIP155Block, head) {
  603. return newCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block)
  604. }
  605. if isForkIncompatible(c.EIP158Block, newcfg.EIP158Block, head) {
  606. return newCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block)
  607. }
  608. if c.IsEIP158(head) && !configNumEqual(c.ChainID, newcfg.ChainID) {
  609. return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block)
  610. }
  611. if isForkIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, head) {
  612. return newCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock)
  613. }
  614. if isForkIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, head) {
  615. return newCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock)
  616. }
  617. if isForkIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, head) {
  618. // the only case where we allow Petersburg to be set in the past is if it is equal to Constantinople
  619. // mainly to satisfy fork ordering requirements which state that Petersburg fork be set if Constantinople fork is set
  620. if isForkIncompatible(c.ConstantinopleBlock, newcfg.PetersburgBlock, head) {
  621. return newCompatError("Petersburg fork block", c.PetersburgBlock, newcfg.PetersburgBlock)
  622. }
  623. }
  624. if isForkIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, head) {
  625. return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock)
  626. }
  627. if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) {
  628. return newCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock)
  629. }
  630. if isForkIncompatible(c.BerlinBlock, newcfg.BerlinBlock, head) {
  631. return newCompatError("Berlin fork block", c.BerlinBlock, newcfg.BerlinBlock)
  632. }
  633. if isForkIncompatible(c.YoloV3Block, newcfg.YoloV3Block, head) {
  634. return newCompatError("YOLOv3 fork block", c.YoloV3Block, newcfg.YoloV3Block)
  635. }
  636. if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) {
  637. return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock)
  638. }
  639. if isForkIncompatible(c.RamanujanBlock, newcfg.RamanujanBlock, head) {
  640. return newCompatError("ramanujan fork block", c.RamanujanBlock, newcfg.RamanujanBlock)
  641. }
  642. if isForkIncompatible(c.MirrorSyncBlock, newcfg.MirrorSyncBlock, head) {
  643. return newCompatError("mirrorSync fork block", c.MirrorSyncBlock, newcfg.MirrorSyncBlock)
  644. }
  645. if isForkIncompatible(c.BrunoBlock, newcfg.BrunoBlock, head) {
  646. return newCompatError("bruno fork block", c.BrunoBlock, newcfg.BrunoBlock)
  647. }
  648. return nil
  649. }
  650. // isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
  651. // block s2 because head is already past the fork.
  652. func isForkIncompatible(s1, s2, head *big.Int) bool {
  653. return (isForked(s1, head) || isForked(s2, head)) && !configNumEqual(s1, s2)
  654. }
  655. // isForked returns whether a fork scheduled at block s is active at the given head block.
  656. func isForked(s, head *big.Int) bool {
  657. if s == nil || head == nil {
  658. return false
  659. }
  660. return s.Cmp(head) <= 0
  661. }
  662. func configNumEqual(x, y *big.Int) bool {
  663. if x == nil {
  664. return y == nil
  665. }
  666. if y == nil {
  667. return x == nil
  668. }
  669. return x.Cmp(y) == 0
  670. }
  671. // ConfigCompatError is raised if the locally-stored blockchain is initialised with a
  672. // ChainConfig that would alter the past.
  673. type ConfigCompatError struct {
  674. What string
  675. // block numbers of the stored and new configurations
  676. StoredConfig, NewConfig *big.Int
  677. // the block number to which the local chain must be rewound to correct the error
  678. RewindTo uint64
  679. }
  680. func newCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatError {
  681. var rew *big.Int
  682. switch {
  683. case storedblock == nil:
  684. rew = newblock
  685. case newblock == nil || storedblock.Cmp(newblock) < 0:
  686. rew = storedblock
  687. default:
  688. rew = newblock
  689. }
  690. err := &ConfigCompatError{what, storedblock, newblock, 0}
  691. if rew != nil && rew.Sign() > 0 {
  692. err.RewindTo = rew.Uint64() - 1
  693. }
  694. return err
  695. }
  696. func (err *ConfigCompatError) Error() string {
  697. return fmt.Sprintf("mismatching %s in database (have %d, want %d, rewindto %d)", err.What, err.StoredConfig, err.NewConfig, err.RewindTo)
  698. }
  699. // Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions
  700. // that do not have or require information about the block.
  701. //
  702. // Rules is a one time interface meaning that it shouldn't be used in between transition
  703. // phases.
  704. type Rules struct {
  705. ChainID *big.Int
  706. IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
  707. IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
  708. IsBerlin, IsCatalyst bool
  709. }
  710. // Rules ensures c's ChainID is not nil.
  711. func (c *ChainConfig) Rules(num *big.Int) Rules {
  712. chainID := c.ChainID
  713. if chainID == nil {
  714. chainID = new(big.Int)
  715. }
  716. return Rules{
  717. ChainID: new(big.Int).Set(chainID),
  718. IsHomestead: c.IsHomestead(num),
  719. IsEIP150: c.IsEIP150(num),
  720. IsEIP155: c.IsEIP155(num),
  721. IsEIP158: c.IsEIP158(num),
  722. IsByzantium: c.IsByzantium(num),
  723. IsConstantinople: c.IsConstantinople(num),
  724. IsPetersburg: c.IsPetersburg(num),
  725. IsIstanbul: c.IsIstanbul(num),
  726. IsBerlin: c.IsBerlin(num),
  727. IsCatalyst: c.IsCatalyst(num),
  728. }
  729. }