From 04080632a7a52cec1a4620df8a81f31934684631 Mon Sep 17 00:00:00 2001 From: meows Date: Sun, 22 Dec 2019 10:45:15 -0600 Subject: [PATCH 1/8] params/types/genesisT: (noop) fix comment typo Signed-off-by: meows --- params/types/genesisT/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/types/genesisT/doc.go b/params/types/genesisT/doc.go index 51d69cd746b3..9887db65dadb 100644 --- a/params/types/genesisT/doc.go +++ b/params/types/genesisT/doc.go @@ -15,7 +15,7 @@ // along with the multi-geth library. If not, see . /* -Package genesis holds genesis data types and logic. +Package genesisT holds genesis data types and logic. */ package genesisT From 95a1c915991ac6a67f30351c05503783b36d734e Mon Sep 17 00:00:00 2001 From: meows Date: Sun, 22 Dec 2019 10:45:58 -0600 Subject: [PATCH 2/8] params: install missing checkpoint vals for foundation configs Signed-off-by: meows --- params/config.go | 110 ++++++++++++++------------ params/types/goethereum/goethereum.go | 1 + 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/params/config.go b/params/config.go index d856df0b626b..c0ff8a294224 100644 --- a/params/config.go +++ b/params/config.go @@ -53,20 +53,22 @@ var CheckpointOracles = map[common.Hash]*ctypes.CheckpointOracleConfig{ var ( // MainnetChainConfig is the chain parameters to run a node on the main network. MainnetChainConfig = &goethereum.ChainConfig{ - ChainID: big.NewInt(1), - HomesteadBlock: big.NewInt(1150000), - DAOForkBlock: big.NewInt(1920000), - DAOForkSupport: true, - EIP150Block: big.NewInt(2463000), - EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), - EIP155Block: big.NewInt(2675000), - EIP158Block: big.NewInt(2675000), - ByzantiumBlock: big.NewInt(4370000), - ConstantinopleBlock: big.NewInt(7280000), - PetersburgBlock: big.NewInt(7280000), - IstanbulBlock: big.NewInt(9069000), - MuirGlacierBlock: big.NewInt(9200000), - Ethash: new(ctypes.EthashConfig), + ChainID: big.NewInt(1), + HomesteadBlock: big.NewInt(1150000), + DAOForkBlock: big.NewInt(1920000), + DAOForkSupport: true, + EIP150Block: big.NewInt(2463000), + EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), + EIP155Block: big.NewInt(2675000), + EIP158Block: big.NewInt(2675000), + ByzantiumBlock: big.NewInt(4370000), + ConstantinopleBlock: big.NewInt(7280000), + PetersburgBlock: big.NewInt(7280000), + IstanbulBlock: big.NewInt(9069000), + MuirGlacierBlock: big.NewInt(9200000), + Ethash: new(ctypes.EthashConfig), + TrustedCheckpoint: MainnetTrustedCheckpoint, + TrustedCheckpointOracle: MainnetCheckpointOracle, } // MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network. @@ -92,20 +94,22 @@ var ( // TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network. TestnetChainConfig = &goethereum.ChainConfig{ - ChainID: big.NewInt(3), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: true, - EIP150Block: big.NewInt(0), - EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"), - EIP155Block: big.NewInt(10), - EIP158Block: big.NewInt(10), - ByzantiumBlock: big.NewInt(1700000), - ConstantinopleBlock: big.NewInt(4230000), - PetersburgBlock: big.NewInt(4939394), - IstanbulBlock: big.NewInt(6485846), - MuirGlacierBlock: big.NewInt(7117117), - Ethash: new(ctypes.EthashConfig), + ChainID: big.NewInt(3), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: true, + EIP150Block: big.NewInt(0), + EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"), + EIP155Block: big.NewInt(10), + EIP158Block: big.NewInt(10), + ByzantiumBlock: big.NewInt(1700000), + ConstantinopleBlock: big.NewInt(4230000), + PetersburgBlock: big.NewInt(4939394), + IstanbulBlock: big.NewInt(6485846), + MuirGlacierBlock: big.NewInt(7117117), + Ethash: new(ctypes.EthashConfig), + TrustedCheckpoint: TestnetTrustedCheckpoint, + TrustedCheckpointOracle: TestnetCheckpointOracle, } // TestnetTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network. @@ -131,18 +135,20 @@ var ( // RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network. RinkebyChainConfig = &goethereum.ChainConfig{ - ChainID: big.NewInt(4), - HomesteadBlock: big.NewInt(1), - DAOForkBlock: nil, - DAOForkSupport: true, - EIP150Block: big.NewInt(2), - EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"), - EIP155Block: big.NewInt(3), - EIP158Block: big.NewInt(3), - ByzantiumBlock: big.NewInt(1035301), - ConstantinopleBlock: big.NewInt(3660663), - PetersburgBlock: big.NewInt(4321234), - IstanbulBlock: big.NewInt(5435345), + ChainID: big.NewInt(4), + HomesteadBlock: big.NewInt(1), + DAOForkBlock: nil, + DAOForkSupport: true, + EIP150Block: big.NewInt(2), + EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"), + EIP155Block: big.NewInt(3), + EIP158Block: big.NewInt(3), + ByzantiumBlock: big.NewInt(1035301), + ConstantinopleBlock: big.NewInt(3660663), + PetersburgBlock: big.NewInt(4321234), + IstanbulBlock: big.NewInt(5435345), + TrustedCheckpoint: RinkebyTrustedCheckpoint, + TrustedCheckpointOracle: RinkebyCheckpointOracle, Clique: &ctypes.CliqueConfig{ Period: 15, Epoch: 30000, @@ -171,17 +177,19 @@ var ( // GoerliChainConfig contains the chain parameters to run a node on the Görli test network. GoerliChainConfig = &goethereum.ChainConfig{ - ChainID: big.NewInt(5), - HomesteadBlock: big.NewInt(0), - DAOForkBlock: nil, - DAOForkSupport: true, - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(1561651), + ChainID: big.NewInt(5), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: nil, + DAOForkSupport: true, + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(1561651), + TrustedCheckpoint: GoerliTrustedCheckpoint, + TrustedCheckpointOracle: GoerliCheckpointOracle, Clique: &ctypes.CliqueConfig{ Period: 15, Epoch: 30000, diff --git a/params/types/goethereum/goethereum.go b/params/types/goethereum/goethereum.go index e787bc137ec5..e43f3ba51d3c 100644 --- a/params/types/goethereum/goethereum.go +++ b/params/types/goethereum/goethereum.go @@ -62,6 +62,7 @@ type ChainConfig struct { Ethash *ctypes.EthashConfig `json:"ethash,omitempty"` Clique *ctypes.CliqueConfig `json:"clique,omitempty"` + // NOTE: These are not included in this type upstream. TrustedCheckpoint *ctypes.TrustedCheckpoint `json:"trustedCheckpoint"` TrustedCheckpointOracle *ctypes.CheckpointOracleConfig `json:"trustedCheckpointOracle"` } From 1e05d7f4c5cfdfef896fc81edb6e5c34b703f922 Mon Sep 17 00:00:00 2001 From: meows Date: Sun, 22 Dec 2019 13:06:45 -0600 Subject: [PATCH 3/8] params: install ecip1061 block activation numbers https://github.com/ethereumclassic/ECIPs/blob/master/_specs/ecip-1061.md Signed-off-by: meows --- core/forkid/forkid_test.go | 2 +- params/config_classic.go | 63 +++++++++------ params/config_kotti.go | 84 +++++++++++++------- params/config_mordor.go | 106 +++++++++++--------------- params/confp/internal/convert_test.go | 36 --------- 5 files changed, 142 insertions(+), 149 deletions(-) diff --git a/core/forkid/forkid_test.go b/core/forkid/forkid_test.go index 7b51e3b41140..f13ec3d49da9 100644 --- a/core/forkid/forkid_test.go +++ b/core/forkid/forkid_test.go @@ -239,7 +239,7 @@ func TestGatherForks(t *testing.T) { }{ { params.ClassicChainConfig, - []uint64{1150000, 2500000, 3000000, 5000000, 5900000, 8772000, 9573000}, + []uint64{1150000, 2500000, 3000000, 5000000, 5900000, 8772000, 9573000, 10500839}, }, { params.MainnetChainConfig, diff --git a/params/config_classic.go b/params/config_classic.go index a38e91bd50f9..5fdad6a92fea 100644 --- a/params/config_classic.go +++ b/params/config_classic.go @@ -26,31 +26,50 @@ import ( var ( // ClassicChainConfig is the chain parameters to run a node on the Classic main network. ClassicChainConfig = &multigeth.MultiGethChainConfig{ - NetworkID: 1, - Ethash: new(ctypes.EthashConfig), - ChainID: big.NewInt(61), + NetworkID: 1, + Ethash: new(ctypes.EthashConfig), + ChainID: big.NewInt(61), + EIP2FBlock: big.NewInt(1150000), EIP7FBlock: big.NewInt(1150000), + //DAOForkBlock: big.NewInt(1920000), - EIP150Block: big.NewInt(2500000), - EIP155Block: big.NewInt(3000000), - EIP160FBlock: big.NewInt(3000000), - EIP161FBlock: big.NewInt(8772000), - EIP170FBlock: big.NewInt(8772000), - EIP100FBlock: big.NewInt(8772000), - EIP140FBlock: big.NewInt(8772000), - EIP198FBlock: big.NewInt(8772000), - EIP211FBlock: big.NewInt(8772000), - EIP212FBlock: big.NewInt(8772000), - EIP213FBlock: big.NewInt(8772000), - EIP214FBlock: big.NewInt(8772000), - EIP658FBlock: big.NewInt(8772000), - EIP145FBlock: big.NewInt(9573000), - EIP1014FBlock: big.NewInt(9573000), - EIP1052FBlock: big.NewInt(9573000), - EIP1283FBlock: nil, - PetersburgBlock: nil, // Un1283 - EIP2200FBlock: nil, // RePetersburg (== re-1283) + + EIP150Block: big.NewInt(2500000), + + EIP155Block: big.NewInt(3000000), + EIP160FBlock: big.NewInt(3000000), + + // EIP158~ + EIP161FBlock: big.NewInt(8772000), + EIP170FBlock: big.NewInt(8772000), + + // Byzantium eq + EIP100FBlock: big.NewInt(8772000), + EIP140FBlock: big.NewInt(8772000), + EIP198FBlock: big.NewInt(8772000), + EIP211FBlock: big.NewInt(8772000), + EIP212FBlock: big.NewInt(8772000), + EIP213FBlock: big.NewInt(8772000), + EIP214FBlock: big.NewInt(8772000), + EIP658FBlock: big.NewInt(8772000), + + // Constantinople eq + EIP145FBlock: big.NewInt(9573000), + EIP1014FBlock: big.NewInt(9573000), + EIP1052FBlock: big.NewInt(9573000), + + // Istanbul eq + EIP152FBlock: big.NewInt(10500839), + EIP1108FBlock: big.NewInt(10500839), + EIP1344FBlock: big.NewInt(10500839), + EIP1884FBlock: nil, + EIP2028FBlock: big.NewInt(10500839), + EIP2200FBlock: big.NewInt(10500839), // RePetersburg (=~ re-1283) + + EIP1283FBlock: nil, + PetersburgBlock: nil, // Un1283 + DisposalBlock: big.NewInt(5900000), ECIP1017FBlock: big.NewInt(5000000), ECIP1017EraRounds: big.NewInt(5000000), diff --git a/params/config_kotti.go b/params/config_kotti.go index 103d3aef4e1a..0cb182b90c95 100644 --- a/params/config_kotti.go +++ b/params/config_kotti.go @@ -20,39 +20,65 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params/types/ctypes" - "github.com/ethereum/go-ethereum/params/types/goethereum" + "github.com/ethereum/go-ethereum/params/types/multigeth" ) var ( // Genesis hashes to enforce below configs on. KottiGenesisHash = common.HexToHash("0x14c2283285a88fe5fce9bf5c573ab03d6616695d717b12a127188bcacfc743c4") - KottiNetworkID uint64 = 6 - //KottiDisposalBlock = uint64(0) - //KottiECIP1017FBlock = uint64(5000000) - //KottiECIP1017EraRounds = uint64(5000000) - //KottiEIP160FBlock = uint64(0) - //KottiECIP1010PauseBlock = uint64(0) - //KottiECIP1010Length = uint64(2000000) - - KottiChainConfig = func() ctypes.ChainConfigurator { - c := &goethereum.ChainConfig{ - ChainID: big.NewInt(6), - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP150Hash: common.HexToHash("0x14c2283285a88fe5fce9bf5c573ab03d6616695d717b12a127188bcacfc743c4"), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(716617), - ByzantiumBlock: big.NewInt(716617), - ConstantinopleBlock: big.NewInt(1705549), - PetersburgBlock: big.NewInt(1705549), - Clique: &ctypes.CliqueConfig{ - Period: 15, - Epoch: 30000, - }, - } - c.SetNetworkID(&KottiNetworkID) - - return c - }() + KottiChainConfig = &multigeth.MultiGethChainConfig{ + NetworkID: 6, + ChainID: big.NewInt(6), + Clique: &ctypes.CliqueConfig{ + Period: 15, + Epoch: 30000, + }, + + EIP2FBlock: big.NewInt(0), + EIP7FBlock: big.NewInt(0), + + EIP150Block: big.NewInt(0), + + EIP155Block: big.NewInt(0), + + // EIP158 eq + EIP160FBlock: big.NewInt(0), + EIP161FBlock: big.NewInt(716617), + EIP170FBlock: big.NewInt(716617), + + // Byzantium eq + EIP100FBlock: big.NewInt(716617), + EIP140FBlock: big.NewInt(716617), + EIP198FBlock: big.NewInt(716617), + EIP211FBlock: big.NewInt(716617), + EIP212FBlock: big.NewInt(716617), + EIP213FBlock: big.NewInt(716617), + EIP214FBlock: big.NewInt(716617), + EIP658FBlock: big.NewInt(716617), + + // Constantinople eq + EIP145FBlock: big.NewInt(1705549), + EIP1014FBlock: big.NewInt(1705549), + EIP1052FBlock: big.NewInt(1705549), + + // Istanbul eq + EIP152FBlock: big.NewInt(2058191), + EIP1108FBlock: big.NewInt(2058191), + EIP1344FBlock: big.NewInt(2058191), + EIP1884FBlock: nil, + EIP2028FBlock: big.NewInt(2058191), + EIP2200FBlock: big.NewInt(2058191), // RePetersburg (== re-1283) + + ECIP1017FBlock: big.NewInt(5000000), + ECIP1017EraRounds: big.NewInt(5000000), + + DisposalBlock: big.NewInt(0), + ECIP1010PauseBlock: big.NewInt(0), + ECIP1010Length: big.NewInt(2000000), + + RequireBlockHashes: map[uint64]common.Hash{ + 0: KottiGenesisHash, + }, + } ) diff --git a/params/config_mordor.go b/params/config_mordor.go index 8e772c617719..d54e7eb7d55f 100644 --- a/params/config_mordor.go +++ b/params/config_mordor.go @@ -23,67 +23,51 @@ import ( ) var ( - //MordorNetworkID uint64 = 7 - //MordorDisposalBlock = uint64(0) - //MordorECIP1017FBlock = uint64(2000000) - //MordorECIP1017EraRounds = uint64(2000000) - //MordorEIP160FBlock = uint64(0) - // MordorChainConfig is the chain parameters to run a node on the Ethereum Classic Mordor test network (PoW). - MordorChainConfig = func() ctypes.ChainConfigurator { - //c := &goethereum.ChainConfig{ - // ChainID: big.NewInt(63), - // HomesteadBlock: big.NewInt(0), - // EIP150Block: big.NewInt(0), - // EIP155Block: big.NewInt(0), - // EIP158Block: big.NewInt(0), - // ByzantiumBlock: big.NewInt(0), - // ConstantinopleBlock: big.NewInt(301243), - // PetersburgBlock: big.NewInt(301243), - // Ethash: new(goethereum.EthashConfig), - //} - //cc := ¶mtypes.MultiGethChainConfig{} - //err := convert.Convert(c, cc) - //if err != nil { - // panic(err) - //} - // - //cc.SetNetworkID(&MordorNetworkID) - //cc.SetEthashECIP1041Transition(&MordorDisposalBlock) - //cc.SetEthashECIP1017Transition(&MordorECIP1017FBlock) - //cc.SetEthashECIP1017EraRounds(&MordorECIP1017EraRounds) + MordorChainConfig = &multigeth.MultiGethChainConfig{ + NetworkID: 7, + ChainID: big.NewInt(63), + Ethash: new(ctypes.EthashConfig), + + EIP2FBlock: big.NewInt(0), + EIP7FBlock: big.NewInt(0), + + EIP150Block: big.NewInt(0), + + EIP155Block: big.NewInt(0), + + // EIP158 eq + EIP160FBlock: big.NewInt(0), + EIP161FBlock: big.NewInt(0), + EIP170FBlock: big.NewInt(0), + + // Byzantium eq + EIP100FBlock: big.NewInt(0), + EIP140FBlock: big.NewInt(0), + EIP198FBlock: big.NewInt(0), + EIP211FBlock: big.NewInt(0), + EIP212FBlock: big.NewInt(0), + EIP213FBlock: big.NewInt(0), + EIP214FBlock: big.NewInt(0), + EIP658FBlock: big.NewInt(0), + + // Constantinople eq + EIP145FBlock: big.NewInt(301243), + EIP1014FBlock: big.NewInt(301243), + EIP1052FBlock: big.NewInt(301243), + + // Istanbul eq + EIP152FBlock: big.NewInt(778507), + EIP1108FBlock: big.NewInt(778507), + EIP1344FBlock: big.NewInt(778507), + EIP1884FBlock: nil, + EIP2028FBlock: big.NewInt(778507), + EIP2200FBlock: big.NewInt(778507), // RePetersburg (== re-1283) - return &multigeth.MultiGethChainConfig{ - NetworkID: 7, - ChainID: big.NewInt(63), - Ethash: new(ctypes.EthashConfig), - EIP2FBlock: big.NewInt(0), - EIP7FBlock: big.NewInt(0), - //DAOForkBlock: big.NewInt(1920000), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP160FBlock: big.NewInt(0), - EIP161FBlock: big.NewInt(0), - EIP170FBlock: big.NewInt(0), - EIP100FBlock: big.NewInt(0), - EIP140FBlock: big.NewInt(0), - EIP198FBlock: big.NewInt(0), - EIP211FBlock: big.NewInt(0), - EIP212FBlock: big.NewInt(0), - EIP213FBlock: big.NewInt(0), - EIP214FBlock: big.NewInt(0), - EIP658FBlock: big.NewInt(0), - EIP145FBlock: big.NewInt(301243), - EIP1014FBlock: big.NewInt(301243), - EIP1052FBlock: big.NewInt(301243), - EIP1283FBlock: nil, - PetersburgBlock: nil, // Disable 1283 - EIP2200FBlock: nil, // RePetersburg - DisposalBlock: big.NewInt(0), - ECIP1017FBlock: big.NewInt(0), - ECIP1017EraRounds: big.NewInt(2000000), - ECIP1010PauseBlock: nil, - ECIP1010Length: nil, - } - }() + DisposalBlock: big.NewInt(0), + ECIP1017FBlock: big.NewInt(0), + ECIP1017EraRounds: big.NewInt(2000000), + ECIP1010PauseBlock: nil, + ECIP1010Length: nil, + } ) diff --git a/params/confp/internal/convert_test.go b/params/confp/internal/convert_test.go index e26a3f4d96c8..77a28747e946 100644 --- a/params/confp/internal/convert_test.go +++ b/params/confp/internal/convert_test.go @@ -25,7 +25,6 @@ import ( "reflect" "testing" - "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params/confp" "github.com/ethereum/go-ethereum/params/confp/tconvert" "github.com/ethereum/go-ethereum/params/types/aleth" @@ -151,38 +150,3 @@ func TestCompatible(t *testing.T) { } t.Log(fns) } - -func TestGatherForks(t *testing.T) { - cases := []struct { - config *multigeth.MultiGethChainConfig - wantNs []uint64 - }{ - { - params.ClassicChainConfig, - []uint64{1150000, 2500000, 3000000, 5000000, 5900000, 8772000, 9573000}, - }, - } - sliceContains := func(sl []uint64, u uint64) bool { - for _, s := range sl { - if s == u { - return true - } - } - return false - } - for ci, c := range cases { - gotForkNs := confp.Forks(c.config) - if len(gotForkNs) != len(c.wantNs) { - for _, n := range c.wantNs { - if !sliceContains(gotForkNs, n) { - t.Errorf("config.i=%d missing wanted fork at block number: %d", ci, n) - } - } - for _, n := range gotForkNs { - if !sliceContains(c.wantNs, n) { - t.Errorf("config.i=%d gathered unwanted fork at block number: %d", ci, n) - } - } - } - } -} From e3533f8f874c20c342f8e04cbd89810090bc006b Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 23 Dec 2019 08:42:51 -0600 Subject: [PATCH 4/8] params/types/parity: ensure lexicographical order for colliding builting keys Parity data type for builtin pricing activation rules allow for duplicate keys, both in literal and decoded values. In case of duplicate decoded values (literally strings), according to JSON specification, lexicographically succeeding values should overwrite earlier ones. This implementation uses sort.Strings to take of this. Signed-off-by: meows --- params/types/parity/parity.go | 23 ++++-- params/types/parity/parity_test.go | 126 +++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 6 deletions(-) diff --git a/params/types/parity/parity.go b/params/types/parity/parity.go index fd6f3fe7f0c7..d5afd67e213e 100644 --- a/params/types/parity/parity.go +++ b/params/types/parity/parity.go @@ -21,6 +21,7 @@ import ( "encoding/json" "math/big" "reflect" + "sort" "strconv" "github.com/ethereum/go-ethereum/common" @@ -260,29 +261,39 @@ type ParityChainSpecPricingPrice struct { } func (p *ParityChainSpecPricingMaybe) UnmarshalJSON(input []byte) error { + + // If old schema structure with "pricing" field pricing := ParityChainSpecPricing{} err := json.Unmarshal(input, &pricing) if err == nil && !reflect.DeepEqual(pricing, ParityChainSpecPricing{}) { p.Pricing = &pricing return nil } - m := make(map[math.HexOrDecimal64]ParityChainSpecPricingPrice) - err = json.Unmarshal(input, &m) + + // Otherwise it's a map keyed on activation block numbers, + // where the keys are strings and could be duplicates. + // According to JSON specification we should use the last lexicographically + // ordered value in case of duplicates. + mm := make(map[string]ParityChainSpecPricingPrice) + err = json.Unmarshal(input, &mm) if err != nil { return err } - if len(m) == 0 { - panic("0 map, dragons") + sl := []string{} + for k := range mm { + sl = append(sl, k) } + sort.Strings(sl) p.Map = make(map[*math.HexOrDecimal256]ParityChainSpecPricingPrice) - for k, v := range m { - p.Map[math.NewHexOrDecimal256(int64(k))] = v + for _, s := range sl { + p.Map[(*math.HexOrDecimal256)(math.MustParseBig256(s))] = mm[s] } if len(p.Map) == 0 { panic("0map") } return nil } + func (p ParityChainSpecPricingMaybe) MarshalJSON() ([]byte, error) { if p.Map != nil { return json.Marshal(p.Map) diff --git a/params/types/parity/parity_test.go b/params/types/parity/parity_test.go index a7289009ab8f..0ce271e713e9 100644 --- a/params/types/parity/parity_test.go +++ b/params/types/parity/parity_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/davecgh/go-spew/spew" + "github.com/ethereum/go-ethereum/common" math2 "github.com/ethereum/go-ethereum/common/math" ) @@ -114,3 +115,128 @@ func TestParityChainSpec_UnmarshalJSON(t *testing.T) { t.Fatal(err) } } + +// TestParityChainSpec_GetPrecompile checks lexographical unmarshaling for maps which can +// have duplicate keys when unmarshaling builtin pricing. +func TestParityChainSpec_GetPrecompile(t *testing.T) { + pspec := &ParityChainSpec{} + err := json.Unmarshal([]byte(` +{ + "name": "Byzantium (Test)", + "engine": { + "Ethash": { + "params": { + "minimumDifficulty": "0x020000", + "difficultyBoundDivisor": "0x0800", + "durationLimit": "0x0d", + "blockReward": "0x29A2241AF62C0000", + "homesteadTransition": "0x0", + "eip100bTransition": "0x0", + "difficultyBombDelays": { + "0": 3000000 + } + } + } + }, + "params": { + "gasLimitBoundDivisor": "0x0400", + "registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b", + "accountStartNonce": "0x00", + "maximumExtraDataSize": "0x20", + "minGasLimit": "0x1388", + "networkID" : "0x1", + "maxCodeSize": 24576, + "maxCodeSizeTransition": "0x0", + "eip150Transition": "0x0", + "eip160Transition": "0x0", + "eip161abcTransition": "0x0", + "eip161dTransition": "0x0", + "eip140Transition": "0x0", + "eip211Transition": "0x0", + "eip214Transition": "0x0", + "eip155Transition": "0x0", + "eip658Transition": "0x0" + }, + "genesis": { + "seal": { + "ethereum": { + "nonce": "0x0000000000000042", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + }, + "difficulty": "0x400000000", + "author": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa", + "gasLimit": "0x1388" + }, + "accounts": { + "0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } }, + "0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, + "0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, + "0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }, + "0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "0x00", "pricing": { "modexp": { "divisor": 20 } } } }, + "0000000000000000000000000000000000000006": { + "builtin": { + "name": "alt_bn128_add", + "pricing": { + "0": { + "price": { "alt_bn128_const_operations": { "price": 500 }} + }, + "0x7fffffffffffff": { + "info": "EIP 1108 transition", + "price": { "alt_bn128_const_operations": { "price": 150 }} + } + } + } + }, + "0000000000000000000000000000000000000007": { + "builtin": { + "name": "alt_bn128_mul", + "pricing": { + "42": { + "price": { "alt_bn128_const_operations": { "price": 40000 }} + }, + "0x2a": { + "price": { "alt_bn128_const_operations": { "price": 30000 }} + }, + "0x02a": { + "price": { "alt_bn128_const_operations": { "price": 10000 }} + } + } + } + }, + "0000000000000000000000000000000000000008": { + "builtin": { + "name": "alt_bn128_pairing", + "pricing": { + "0": { + "price": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 }} + }, + "0x7fffffffffffff": { + "info": "EIP 1108 transition", + "price": { "alt_bn128_pairing": { "base": 45000, "pair": 34000 }} + } + } + } + } + } +} +`), pspec) + if err != nil { + t.Fatal(err) + } + + got := pspec.GetPrecompile(common.BytesToAddress([]byte{7}), + ParityChainSpecPricing{ + AltBnConstOperation: &ParityChainSpecAltBnConstOperationPricing{ + Price: 40000, // Want 40000 because "42" lexically comes after "0x2a", etc + }, + }).Uint64P() + want := uint64(42) + + if got == nil || *got != want { + t.Errorf("got: %v, want: %v", got, want) + } +} From 6020a14dbf6f05586e78a43bae031e9d8e1741c1 Mon Sep 17 00:00:00 2001 From: meows Date: Mon, 23 Dec 2019 09:01:12 -0600 Subject: [PATCH 5/8] params/types/parity: add extra test case for duplicate string keys Hoping for bottom-wins JSON unmarshaling of a map keyed on strings with duplicate fields, and not wanting to use string pointers to really get too far in to the thick of it. Signed-off-by: meows --- params/types/parity/parity_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/params/types/parity/parity_test.go b/params/types/parity/parity_test.go index 0ce271e713e9..f1a5b29f04d8 100644 --- a/params/types/parity/parity_test.go +++ b/params/types/parity/parity_test.go @@ -195,6 +195,9 @@ func TestParityChainSpec_GetPrecompile(t *testing.T) { "builtin": { "name": "alt_bn128_mul", "pricing": { + "42": { + "price": { "alt_bn128_const_operations": { "price": 50000 }} + }, "42": { "price": { "alt_bn128_const_operations": { "price": 40000 }} }, @@ -228,12 +231,18 @@ func TestParityChainSpec_GetPrecompile(t *testing.T) { t.Fatal(err) } + // Use 'alt_bn128_mul' as our test case. got := pspec.GetPrecompile(common.BytesToAddress([]byte{7}), ParityChainSpecPricing{ AltBnConstOperation: &ParityChainSpecAltBnConstOperationPricing{ - Price: 40000, // Want 40000 because "42" lexically comes after "0x2a", etc + // Want 40000 because "42" lexically comes after "0x2a" and "0x02a". + // And then we cross our fingers and hope that literal order is preserved + // for the map during JSON unmarshaling with the keys as strings, since "42" == "42". + // We want bottom-wins parsing. + Price: 40000, }, }).Uint64P() + want := uint64(42) if got == nil || *got != want { From 3ecfbe462aedd993560f4fd38869c8acd6231510 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 1 Jan 2020 11:04:00 -0600 Subject: [PATCH 6/8] params/types: rename global configurator method, minor refactor - Uses a throwaway method receiver var name for clarity that that value is not used - Renames 'One' method name to 'GlobalConfigurator' - Initializes a single pointer value for empty global configurator instead of allocating new for each use. Resolves https://github.com/etclabscore/multi-geth/pull/91#discussion_r362273045 Resolves https://github.com/etclabscore/multi-geth/pull/91#discussion_r362273810 Signed-off-by: meows --- .../goethereum/goethereum_configurator.go | 32 ++++++++-------- params/types/internal/vars_configurator.go | 38 ++++++++++--------- .../multigeth/chain_config_configurator.go | 32 ++++++++-------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/params/types/goethereum/goethereum_configurator.go b/params/types/goethereum/goethereum_configurator.go index 8ee9162e3b6c..f132b143ffb8 100644 --- a/params/types/goethereum/goethereum_configurator.go +++ b/params/types/goethereum/goethereum_configurator.go @@ -53,35 +53,35 @@ func setBig(i *big.Int, u *uint64) *big.Int { } func (c *ChainConfig) GetAccountStartNonce() *uint64 { - return internal.One().GetAccountStartNonce() + return internal.GlobalConfigurator().GetAccountStartNonce() } func (c *ChainConfig) SetAccountStartNonce(n *uint64) error { - return internal.One().SetAccountStartNonce(n) + return internal.GlobalConfigurator().SetAccountStartNonce(n) } func (c *ChainConfig) GetMaximumExtraDataSize() *uint64 { - return internal.One().GetMaximumExtraDataSize() + return internal.GlobalConfigurator().GetMaximumExtraDataSize() } func (c *ChainConfig) SetMaximumExtraDataSize(n *uint64) error { - return internal.One().SetMaximumExtraDataSize(n) + return internal.GlobalConfigurator().SetMaximumExtraDataSize(n) } func (c *ChainConfig) GetMinGasLimit() *uint64 { - return internal.One().GetMinGasLimit() + return internal.GlobalConfigurator().GetMinGasLimit() } func (c *ChainConfig) SetMinGasLimit(n *uint64) error { - return internal.One().SetMinGasLimit(n) + return internal.GlobalConfigurator().SetMinGasLimit(n) } func (c *ChainConfig) GetGasLimitBoundDivisor() *uint64 { - return internal.One().GetGasLimitBoundDivisor() + return internal.GlobalConfigurator().GetGasLimitBoundDivisor() } func (c *ChainConfig) SetGasLimitBoundDivisor(n *uint64) error { - return internal.One().SetGasLimitBoundDivisor(n) + return internal.GlobalConfigurator().SetGasLimitBoundDivisor(n) } // GetNetworkID and the following Set/Getters for ChainID too @@ -121,11 +121,11 @@ func (c *ChainConfig) SetChainID(n *big.Int) error { } func (c *ChainConfig) GetMaxCodeSize() *uint64 { - return internal.One().GetMaxCodeSize() + return internal.GlobalConfigurator().GetMaxCodeSize() } func (c *ChainConfig) SetMaxCodeSize(n *uint64) error { - return internal.One().SetMaxCodeSize(n) + return internal.GlobalConfigurator().SetMaxCodeSize(n) } func (c *ChainConfig) GetEIP7Transition() *uint64 { @@ -409,27 +409,27 @@ func (c *ChainConfig) MustSetConsensusEngineType(t ctypes.ConsensusEngineT) erro } func (c *ChainConfig) GetEthashMinimumDifficulty() *big.Int { - return internal.One().GetEthashMinimumDifficulty() + return internal.GlobalConfigurator().GetEthashMinimumDifficulty() } func (c *ChainConfig) SetEthashMinimumDifficulty(i *big.Int) error { - return internal.One().SetEthashMinimumDifficulty(i) + return internal.GlobalConfigurator().SetEthashMinimumDifficulty(i) } func (c *ChainConfig) GetEthashDifficultyBoundDivisor() *big.Int { - return internal.One().GetEthashDifficultyBoundDivisor() + return internal.GlobalConfigurator().GetEthashDifficultyBoundDivisor() } func (c *ChainConfig) SetEthashDifficultyBoundDivisor(i *big.Int) error { - return internal.One().SetEthashDifficultyBoundDivisor(i) + return internal.GlobalConfigurator().SetEthashDifficultyBoundDivisor(i) } func (c *ChainConfig) GetEthashDurationLimit() *big.Int { - return internal.One().GetEthashDurationLimit() + return internal.GlobalConfigurator().GetEthashDurationLimit() } func (c *ChainConfig) SetEthashDurationLimit(i *big.Int) error { - return internal.One().SetEthashDurationLimit(i) + return internal.GlobalConfigurator().SetEthashDurationLimit(i) } // NOTE: Checking for if c.Ethash == nil is a consideration. diff --git a/params/types/internal/vars_configurator.go b/params/types/internal/vars_configurator.go index e18e543b1dea..75f1b866341a 100644 --- a/params/types/internal/vars_configurator.go +++ b/params/types/internal/vars_configurator.go @@ -10,19 +10,21 @@ import ( type GlobalVarsConfigurator struct { } -func One() *GlobalVarsConfigurator { - return &GlobalVarsConfigurator{} +var gc = &GlobalVarsConfigurator{} + +func GlobalConfigurator() *GlobalVarsConfigurator { + return gc } func newU64(u uint64) *uint64 { return &u } -func (g GlobalVarsConfigurator) GetAccountStartNonce() *uint64 { +func (_ GlobalVarsConfigurator) GetAccountStartNonce() *uint64 { return newU64(0) } -func (g GlobalVarsConfigurator) SetAccountStartNonce(n *uint64) error { +func (_ GlobalVarsConfigurator) SetAccountStartNonce(n *uint64) error { if n == nil { return nil } @@ -32,38 +34,38 @@ func (g GlobalVarsConfigurator) SetAccountStartNonce(n *uint64) error { return nil } -func (g GlobalVarsConfigurator) GetMaximumExtraDataSize() *uint64 { +func (_ GlobalVarsConfigurator) GetMaximumExtraDataSize() *uint64 { return newU64(vars.MaximumExtraDataSize) } -func (g GlobalVarsConfigurator) SetMaximumExtraDataSize(n *uint64) error { +func (_ GlobalVarsConfigurator) SetMaximumExtraDataSize(n *uint64) error { vars.MaximumExtraDataSize = *n return nil } -func (g GlobalVarsConfigurator) GetMinGasLimit() *uint64 { +func (_ GlobalVarsConfigurator) GetMinGasLimit() *uint64 { return newU64(vars.MinGasLimit) } -func (g GlobalVarsConfigurator) SetMinGasLimit(n *uint64) error { +func (_ GlobalVarsConfigurator) SetMinGasLimit(n *uint64) error { vars.MinGasLimit = *n return nil } -func (g GlobalVarsConfigurator) GetGasLimitBoundDivisor() *uint64 { +func (_ GlobalVarsConfigurator) GetGasLimitBoundDivisor() *uint64 { return newU64(vars.GasLimitBoundDivisor) } -func (g GlobalVarsConfigurator) SetGasLimitBoundDivisor(n *uint64) error { +func (_ GlobalVarsConfigurator) SetGasLimitBoundDivisor(n *uint64) error { vars.GasLimitBoundDivisor = *n return nil } -func (g GlobalVarsConfigurator) GetMaxCodeSize() *uint64 { +func (_ GlobalVarsConfigurator) GetMaxCodeSize() *uint64 { return newU64(vars.MaxCodeSize) } -func (g GlobalVarsConfigurator) SetMaxCodeSize(n *uint64) error { +func (_ GlobalVarsConfigurator) SetMaxCodeSize(n *uint64) error { if n == nil { return nil } @@ -71,10 +73,10 @@ func (g GlobalVarsConfigurator) SetMaxCodeSize(n *uint64) error { return nil } -func (c GlobalVarsConfigurator) GetEthashMinimumDifficulty() *big.Int { +func (_ GlobalVarsConfigurator) GetEthashMinimumDifficulty() *big.Int { return vars.MinimumDifficulty } -func (c GlobalVarsConfigurator) SetEthashMinimumDifficulty(i *big.Int) error { +func (_ GlobalVarsConfigurator) SetEthashMinimumDifficulty(i *big.Int) error { if i == nil { return ctypes.ErrUnsupportedConfigFatal } @@ -82,11 +84,11 @@ func (c GlobalVarsConfigurator) SetEthashMinimumDifficulty(i *big.Int) error { return nil } -func (c GlobalVarsConfigurator) GetEthashDifficultyBoundDivisor() *big.Int { +func (_ GlobalVarsConfigurator) GetEthashDifficultyBoundDivisor() *big.Int { return vars.DifficultyBoundDivisor } -func (c GlobalVarsConfigurator) SetEthashDifficultyBoundDivisor(i *big.Int) error { +func (_ GlobalVarsConfigurator) SetEthashDifficultyBoundDivisor(i *big.Int) error { if i == nil { return ctypes.ErrUnsupportedConfigFatal } @@ -94,11 +96,11 @@ func (c GlobalVarsConfigurator) SetEthashDifficultyBoundDivisor(i *big.Int) erro return nil } -func (c GlobalVarsConfigurator) GetEthashDurationLimit() *big.Int { +func (_ GlobalVarsConfigurator) GetEthashDurationLimit() *big.Int { return vars.DurationLimit } -func (c GlobalVarsConfigurator) SetEthashDurationLimit(i *big.Int) error { +func (_ GlobalVarsConfigurator) SetEthashDurationLimit(i *big.Int) error { if i == nil { return ctypes.ErrUnsupportedConfigFatal } diff --git a/params/types/multigeth/chain_config_configurator.go b/params/types/multigeth/chain_config_configurator.go index c0e6e6c2da90..afa6002e1a9c 100644 --- a/params/types/multigeth/chain_config_configurator.go +++ b/params/types/multigeth/chain_config_configurator.go @@ -68,28 +68,28 @@ func (c *MultiGethChainConfig) ensureExistingDifficultySchedule() { } func (c *MultiGethChainConfig) GetAccountStartNonce() *uint64 { - return internal.One().GetAccountStartNonce() + return internal.GlobalConfigurator().GetAccountStartNonce() } func (c *MultiGethChainConfig) SetAccountStartNonce(n *uint64) error { - return internal.One().SetAccountStartNonce(n) + return internal.GlobalConfigurator().SetAccountStartNonce(n) } func (c *MultiGethChainConfig) GetMaximumExtraDataSize() *uint64 { - return internal.One().GetMaximumExtraDataSize() + return internal.GlobalConfigurator().GetMaximumExtraDataSize() } func (c *MultiGethChainConfig) SetMaximumExtraDataSize(n *uint64) error { - return internal.One().SetMaximumExtraDataSize(n) + return internal.GlobalConfigurator().SetMaximumExtraDataSize(n) } func (c *MultiGethChainConfig) GetMinGasLimit() *uint64 { - return internal.One().GetMinGasLimit() + return internal.GlobalConfigurator().GetMinGasLimit() } func (c *MultiGethChainConfig) SetMinGasLimit(n *uint64) error { - return internal.One().SetMinGasLimit(n) + return internal.GlobalConfigurator().SetMinGasLimit(n) } func (c *MultiGethChainConfig) GetGasLimitBoundDivisor() *uint64 { - return internal.One().GetGasLimitBoundDivisor() + return internal.GlobalConfigurator().GetGasLimitBoundDivisor() } func (c *MultiGethChainConfig) SetGasLimitBoundDivisor(n *uint64) error { - return internal.One().SetGasLimitBoundDivisor(n) + return internal.GlobalConfigurator().SetGasLimitBoundDivisor(n) } func (c *MultiGethChainConfig) GetNetworkID() *uint64 { @@ -114,10 +114,10 @@ func (c *MultiGethChainConfig) SetChainID(n *big.Int) error { } func (c *MultiGethChainConfig) GetMaxCodeSize() *uint64 { - return internal.One().GetMaxCodeSize() + return internal.GlobalConfigurator().GetMaxCodeSize() } func (c *MultiGethChainConfig) SetMaxCodeSize(n *uint64) error { - return internal.One().SetMaxCodeSize(n) + return internal.GlobalConfigurator().SetMaxCodeSize(n) } func (c *MultiGethChainConfig) GetEIP7Transition() *uint64 { @@ -401,26 +401,26 @@ func (c *MultiGethChainConfig) MustSetConsensusEngineType(t ctypes.ConsensusEngi } func (c *MultiGethChainConfig) GetEthashMinimumDifficulty() *big.Int { - return internal.One().GetEthashMinimumDifficulty() + return internal.GlobalConfigurator().GetEthashMinimumDifficulty() } func (c *MultiGethChainConfig) SetEthashMinimumDifficulty(i *big.Int) error { - return internal.One().SetEthashMinimumDifficulty(i) + return internal.GlobalConfigurator().SetEthashMinimumDifficulty(i) } func (c *MultiGethChainConfig) GetEthashDifficultyBoundDivisor() *big.Int { - return internal.One().GetEthashDifficultyBoundDivisor() + return internal.GlobalConfigurator().GetEthashDifficultyBoundDivisor() } func (c *MultiGethChainConfig) SetEthashDifficultyBoundDivisor(i *big.Int) error { - return internal.One().SetEthashDifficultyBoundDivisor(i) + return internal.GlobalConfigurator().SetEthashDifficultyBoundDivisor(i) } func (c *MultiGethChainConfig) GetEthashDurationLimit() *big.Int { - return internal.One().GetEthashDurationLimit() + return internal.GlobalConfigurator().GetEthashDurationLimit() } func (c *MultiGethChainConfig) SetEthashDurationLimit(i *big.Int) error { - return internal.One().SetEthashDurationLimit(i) + return internal.GlobalConfigurator().SetEthashDurationLimit(i) } func (c *MultiGethChainConfig) GetEthashHomesteadTransition() *uint64 { From f77ac726920704340646af32970acc268964e340 Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 1 Jan 2020 11:04:36 -0600 Subject: [PATCH 7/8] params/confp/tconvert: (noop) fix comment by finishing sentence Resolves https://github.com/etclabscore/multi-geth/pull/91#discussion_r362271756 Signed-off-by: meows --- params/confp/tconvert/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/confp/tconvert/doc.go b/params/confp/tconvert/doc.go index 14877f188cd3..1a63dde4e24b 100644 --- a/params/confp/tconvert/doc.go +++ b/params/confp/tconvert/doc.go @@ -21,6 +21,6 @@ It represents vestigial constructions for converting between chain configuration data types. I believe all functions are used only in the cmd/puppeth package. These functions should be replaced in their occurrences with `convert.Convert` logic instead, -and then this package can +and then this package can die. */ package tconvert From 651a2d1bc53547b0b4170abc1a3d59725b35ef6e Mon Sep 17 00:00:00 2001 From: meows Date: Wed, 1 Jan 2020 11:09:10 -0600 Subject: [PATCH 8/8] params/types/goethereum: (refactor,noop) simplify consensus engine return logic Resolves https://github.com/etclabscore/multi-geth/pull/91#discussion_r362272651 Signed-off-by: meows --- params/types/goethereum/goethereum_configurator.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/params/types/goethereum/goethereum_configurator.go b/params/types/goethereum/goethereum_configurator.go index f132b143ffb8..78c2dfe8f4b8 100644 --- a/params/types/goethereum/goethereum_configurator.go +++ b/params/types/goethereum/goethereum_configurator.go @@ -386,9 +386,6 @@ func (c *ChainConfig) GetForkCanonHashes() map[uint64]common.Hash { } func (c *ChainConfig) GetConsensusEngineType() ctypes.ConsensusEngineT { - if c.Ethash != nil { - return ctypes.ConsensusEngineT_Ethash - } if c.Clique != nil { return ctypes.ConsensusEngineT_Clique }