config.go 29 KB

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