From 3180921a7f1a900870097c828ba63ccafd16ead2 Mon Sep 17 00:00:00 2001 From: Sinh Vu Date: Tue, 23 Jul 2019 17:25:55 +0700 Subject: [PATCH 1/3] upgrade increase masternodes --- common/constants.go | 2 ++ contracts/validator/validator.go | 5 +++-- core/blockchain.go | 15 +++++++++++++-- internal/ethapi/api.go | 12 +++++++++--- params/config.go | 10 ++++++++-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/common/constants.go b/common/constants.go index 1bf32aa9f8..8d224b05a1 100644 --- a/common/constants.go +++ b/common/constants.go @@ -13,6 +13,7 @@ const ( EpocBlockOpening = 850 EpocBlockRandomize = 900 MaxMasternodes = 18 + MaxMasternodesV2 = 54 LimitPenaltyEpoch = 4 BlocksPerYear = uint64(15768000) LimitThresholdNonceInQueue = 10 @@ -25,6 +26,7 @@ const ( var TIP2019Block = big.NewInt(1) var TIPSigning = big.NewInt(3000000) var TIPRandomize = big.NewInt(3464000) +var TIPIncreaseMasternodes = big.NewInt(10000000) // example 10 milions var IsTestnet bool = false var StoreRewardFolder string var RollbackHash Hash diff --git a/contracts/validator/validator.go b/contracts/validator/validator.go index dadc328b7f..a9adf5d1f1 100644 --- a/contracts/validator/validator.go +++ b/contracts/validator/validator.go @@ -16,10 +16,11 @@ package validator import ( + "math/big" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/contracts/validator/contract" - "math/big" ) type Validator struct { @@ -52,7 +53,7 @@ func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.Contr // 150 masternodes // Candidate Delay Withdraw 30 days = 1296000 blocks // Voter Delay Withdraw 10 days = 432000 blocks - validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(18), big.NewInt(1296000), big.NewInt(432000)) + validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(54), big.NewInt(1296000), big.NewInt(432000)) if err != nil { return validatorAddr, nil, err } diff --git a/core/blockchain.go b/core/blockchain.go index 7482600d82..cf1eb23836 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -46,7 +46,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" - "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru" "gopkg.in/karalabe/cookiejar.v2/collections/prque" ) @@ -1870,8 +1870,19 @@ func (bc *BlockChain) UpdateM1() error { } // update masternodes log.Info("Updating new set of masternodes") + // get block header + header := bc.CurrentHeader() + var maxMasternodes int + // check if block number is increase ms checkpoint + if bc.chainConfig.IsTIPIncreaseMasternodes(header.Number) { + // using new masterndoes + maxMasternodes = common.MaxMasternodesV2 + } else { + // using old masterndoes + maxMasternodes = common.MaxMasternodes + } if len(ms) > common.MaxMasternodes { - err = engine.UpdateMasternodes(bc, bc.CurrentHeader(), ms[:common.MaxMasternodes]) + err = engine.UpdateMasternodes(bc, bc.CurrentHeader(), ms[:maxMasternodes]) } else { err = engine.UpdateMasternodes(bc, bc.CurrentHeader(), ms) } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 566c73e8f5..94487f7f27 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -32,8 +32,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" - "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/XDPoS" + "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/contracts" contractValidator "github.com/ethereum/go-ethereum/contracts/validator/contract" "github.com/ethereum/go-ethereum/core" @@ -747,7 +747,7 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd opts := new(bind.CallOpts) var ( candidateAddresses []common.Address - candidates []XDPoS.Masternode + candidates []XDPoS.Masternode ) candidateAddresses, err = validator.GetCandidates(opts) @@ -767,12 +767,18 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd sort.Slice(candidates, func(i, j int) bool { return candidates[i].Stake.Cmp(candidates[j].Stake) >= 0 }) + var maxMasternodes int + if s.b.ChainConfig().IsTIPIncreaseMasternodes(block.Number()) { + maxMasternodes = common.MaxMasternodesV2 + } else { + maxMasternodes = common.MaxMasternodes + } isTopCandidate := false // is candidates in top 150 status := "" for i := 0; i < len(candidates); i++ { if candidates[i].Address == coinbaseAddress { status = statusProposed - if i < common.MaxMasternodes { + if i < maxMasternodes { isTopCandidate = true } break diff --git a/params/config.go b/params/config.go index 74825d0543..ba343bc035 100644 --- a/params/config.go +++ b/params/config.go @@ -89,7 +89,7 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllXDPoSProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &XDPoSConfig{Period: 0, Epoch: 30000}} + AllXDPoSProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &XDPoSConfig{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), nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, 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), nil, new(EthashConfig), nil, nil} TestRules = TestChainConfig.Rules(new(big.Int)) @@ -121,7 +121,7 @@ type ChainConfig struct { // Various consensus engines Ethash *EthashConfig `json:"ethash,omitempty"` Clique *CliqueConfig `json:"clique,omitempty"` - XDPoS *XDPoSConfig `json:"XDPoS,omitempty"` + XDPoS *XDPoSConfig `json:"XDPoS,omitempty"` } // EthashConfig is the consensus engine configs for proof-of-work based sealing. @@ -225,6 +225,12 @@ func (c *ChainConfig) IsTIPRandomize(num *big.Int) bool { return isForked(common.TIPRandomize, num) } +// IsTIPIncreaseMasternodes using for increase masternodes from 18 to 40 +// Time update: 23-07-2019 +func (c *ChainConfig) IsTIPIncreaseMasternodes(num *big.Int) bool { + return isForked(common.TIPIncreaseMasternodes, num) +} + // GasTable returns the gas table corresponding to the current phase (homestead or homestead reprice). // // The returned GasTable's fields shouldn't, under any circumstances, be changed. From c52f31d2c44b7457797d8b2597e305cf0397cc22 Mon Sep 17 00:00:00 2001 From: Sinh Vu Date: Tue, 23 Jul 2019 17:45:29 +0700 Subject: [PATCH 2/3] update max masternodes --- core/blockchain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index cf1eb23836..99f561998e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1881,7 +1881,7 @@ func (bc *BlockChain) UpdateM1() error { // using old masterndoes maxMasternodes = common.MaxMasternodes } - if len(ms) > common.MaxMasternodes { + if len(ms) > maxMasternodes { err = engine.UpdateMasternodes(bc, bc.CurrentHeader(), ms[:maxMasternodes]) } else { err = engine.UpdateMasternodes(bc, bc.CurrentHeader(), ms) From 10af44cb935a5978910def3e994503118e3a6ebe Mon Sep 17 00:00:00 2001 From: Sinh Vu Date: Tue, 23 Jul 2019 18:10:27 +0700 Subject: [PATCH 3/3] revert validator.go --- contracts/validator/validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/validator/validator.go b/contracts/validator/validator.go index a9adf5d1f1..cd3c3a6fd1 100644 --- a/contracts/validator/validator.go +++ b/contracts/validator/validator.go @@ -53,7 +53,7 @@ func DeployValidator(transactOpts *bind.TransactOpts, contractBackend bind.Contr // 150 masternodes // Candidate Delay Withdraw 30 days = 1296000 blocks // Voter Delay Withdraw 10 days = 432000 blocks - validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(54), big.NewInt(1296000), big.NewInt(432000)) + validatorAddr, _, _, err := contract.DeployXDCValidator(transactOpts, contractBackend, validatorAddress, caps, ownerAddress, minDeposit, minVoterCap, big.NewInt(18), big.NewInt(1296000), big.NewInt(432000)) if err != nil { return validatorAddr, nil, err }