config.go 32 KB

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