From 518d52d22176df63420e2d8496c8ee5b74a96579 Mon Sep 17 00:00:00 2001 From: "joe.kongrath" Date: Tue, 25 Jul 2023 18:19:23 +0700 Subject: [PATCH] testnet: add new improvement for updating new pos contracts --- consensus/clique/clique.go | 7 +++-- consensus/clique/contract/client.go | 18 ++++++++--- params/config.go | 46 ++++++++++++++++++----------- params/version.go | 2 +- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 6e0d7836e..e1bcd8249 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -161,9 +161,10 @@ var ( func (c *Clique) isToSystemContract(to common.Address, snap *Snapshot) bool { // Map system contracts systemContracts := map[common.Address]bool{ - c.config.Clique.ValidatorContract: true, - snap.SystemContracts.StakeManager: true, - snap.SystemContracts.SlashManager: true, + c.config.Clique.ValidatorContractV2: true, + c.config.Clique.ValidatorContract: true, + snap.SystemContracts.StakeManager: true, + snap.SystemContracts.SlashManager: true, } return systemContracts[to] } diff --git a/consensus/clique/contract/client.go b/consensus/clique/contract/client.go index fd65d96e4..282bded51 100644 --- a/consensus/clique/contract/client.go +++ b/consensus/clique/contract/client.go @@ -102,7 +102,7 @@ func (cc *ContractClient) GetCurrentSpan(ctx context.Context, header *types.Head } msgData := (hexutil.Bytes)(data) - toAddress := cc.config.Clique.ValidatorContract + toAddress := cc.getValidatorContract(header.Number) gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2)) result, err := cc.ethAPI.Call(ctx, ethapi.TransactionArgs{ Gas: &gas, @@ -147,8 +147,9 @@ func (cc *ContractClient) CommitSpan(val common.Address, state *state.StateDB, h log.Error("Unable to pack tx for commitspan", "error", err) return err } + validatorContract := cc.getValidatorContract(header.Number) // get system message - msg := getSystemMessage(header.Coinbase, cc.config.Clique.ValidatorContract, data, common.Big0) + msg := getSystemMessage(header.Coinbase, validatorContract, data, common.Big0) // apply message return cc.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining) } @@ -210,9 +211,10 @@ func (cc *ContractClient) GetCurrentValidators(headerHash common.Hash, blockNumb log.Error("Unable to pack tx for getValidators", "error", err) return nil, nil, err } + // call msgData := (hexutil.Bytes)(data) - toAddress := cc.config.Clique.ValidatorContract + toAddress := cc.getValidatorContract(blockNumber) gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2)) result, err := cc.ethAPI.Call(ctx, ethapi.TransactionArgs{ Gas: &gas, @@ -273,7 +275,7 @@ func (cc *ContractClient) GetEligibleValidators(headerHash common.Hash, blockNum // call msgData := (hexutil.Bytes)(data) - toAddress := cc.config.Clique.ValidatorContract + toAddress := cc.getValidatorContract(big.NewInt(int64(blockNumber))) gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2)) result, err := cc.ethAPI.Call(ctx, ethapi.TransactionArgs{ Gas: &gas, @@ -303,6 +305,14 @@ func (cc *ContractClient) GetEligibleValidators(headerHash common.Hash, blockNum return valz, nil } +func (cc *ContractClient) getValidatorContract(number *big.Int) common.Address { + validatorContract := cc.config.Clique.ValidatorContract + if cc.config.ChaophrayaBangkokBlock != nil && cc.config.IsChaophrayaBangkok(number) { + validatorContract = cc.config.Clique.ValidatorContractV2 + } + return validatorContract +} + // Transaction handler functions vvv // get system message diff --git a/params/config.go b/params/config.go index 330f283de..6dc4fe615 100644 --- a/params/config.go +++ b/params/config.go @@ -262,16 +262,16 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - 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), nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil} + 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), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil} // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Clique consensus. // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - 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), nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}} + 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), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}} - 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), nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(EthashConfig), nil} + 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), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, new(EthashConfig), nil} TestRules = TestChainConfig.Rules(new(big.Int), false) ) @@ -343,17 +343,18 @@ type ChainConfig struct { EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block - ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium) - ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) - PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) - IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) - ErawanBlock *big.Int `json:"erawanBlock,omitempty"` // IsErawan switch block (nil = no fork, 0 = already on Erawan) - ChaophrayaBlock *big.Int `json:"chaophrayaBlock,omitempty"` // IsChaophraya switch block (nil = no fork, 0 = already on Chaophraya) - MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) - BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin) - LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london) - ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated) - MergeForkBlock *big.Int `json:"mergeForkBlock,omitempty"` // EIP-3675 (TheMerge) switch block (nil = no fork, 0 = already in merge proceedings) + ByzantiumBlock *big.Int `json:"byzantiumBlock,omitempty"` // Byzantium switch block (nil = no fork, 0 = already on byzantium) + ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated) + PetersburgBlock *big.Int `json:"petersburgBlock,omitempty"` // Petersburg switch block (nil = same as Constantinople) + IstanbulBlock *big.Int `json:"istanbulBlock,omitempty"` // Istanbul switch block (nil = no fork, 0 = already on istanbul) + ErawanBlock *big.Int `json:"erawanBlock,omitempty"` // IsErawan switch block (nil = no fork, 0 = already on Erawan) + ChaophrayaBlock *big.Int `json:"chaophrayaBlock,omitempty"` // IsChaophraya switch block (nil = no fork, 0 = already on Chaophraya) + ChaophrayaBangkokBlock *big.Int `json:"chaophrayaBangkokBlock,omitempty"` // IsChaophraya Testnet switch block (nil = no fork, 0 = already on Chaophraya Testnet) + MuirGlacierBlock *big.Int `json:"muirGlacierBlock,omitempty"` // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated) + BerlinBlock *big.Int `json:"berlinBlock,omitempty"` // Berlin switch block (nil = no fork, 0 = already on berlin) + LondonBlock *big.Int `json:"londonBlock,omitempty"` // London switch block (nil = no fork, 0 = already on london) + ArrowGlacierBlock *big.Int `json:"arrowGlacierBlock,omitempty"` // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated) + MergeForkBlock *big.Int `json:"mergeForkBlock,omitempty"` // EIP-3675 (TheMerge) switch block (nil = no fork, 0 = already in merge proceedings) // TerminalTotalDifficulty is the amount of total difficulty reached by // the network that triggers the consensus upgrade. @@ -374,10 +375,11 @@ func (c *EthashConfig) String() string { // CliqueConfig is the consensus engine configs for proof-of-authority based sealing. type CliqueConfig struct { - Period uint64 `json:"period"` // Number of seconds between blocks to enforce - Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint - Span uint64 `json:"span"` // Size of each span in block - ValidatorContract common.Address `json:"validatorContract"` + Period uint64 `json:"period"` // Number of seconds between blocks to enforce + Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint + Span uint64 `json:"span"` // Size of each span in block + ValidatorContract common.Address `json:"validatorContract"` + ValidatorContractV2 common.Address `json:"validatorContractV2"` } // String implements the stringer interface, returning the consensus engine details. @@ -491,6 +493,11 @@ func (c *ChainConfig) IsChaophraya(num *big.Int) bool { return isForked(c.ChaophrayaBlock, num) } +// IsChaophrayaBangkok +func (c *ChainConfig) IsChaophrayaBangkok(num *big.Int) bool { + return isForked(c.ChaophrayaBangkokBlock, num) +} + // IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater. func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool { return isForked(c.ArrowGlacierBlock, num) @@ -614,6 +621,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi if isForkIncompatible(c.ChaophrayaBlock, newcfg.ChaophrayaBlock, head) { return newCompatError("ChaophrayaBlock fork block", c.ChaophrayaBlock, newcfg.ChaophrayaBlock) } + if isForkIncompatible(c.ChaophrayaBangkokBlock, newcfg.ChaophrayaBangkokBlock, head) { + return newCompatError("ChaophrayaBangkokBlock fork block", c.ChaophrayaBangkokBlock, newcfg.ChaophrayaBangkokBlock) + } if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) { return newCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock) } diff --git a/params/version.go b/params/version.go index c9f7cf7bc..39480ec0d 100644 --- a/params/version.go +++ b/params/version.go @@ -22,7 +22,7 @@ import ( const ( VersionMajor = 2 // Major version component of the current release - VersionMinor = 0 // Minor version component of the current release + VersionMinor = 1 // Minor version component of the current release VersionPatch = 0 // Patch version component of the current release VersionMeta = "stable" // Version metadata to append to the version string )