From c52459e9601e4eddb933efad05c7de823be55539 Mon Sep 17 00:00:00 2001 From: laizy Date: Tue, 8 Aug 2023 14:47:18 +0800 Subject: [PATCH] add user fee split overflow (#1432) --- common/config/config.go | 13 +++++++++++-- common/constants/constants.go | 5 ++++- smartcontract/service/native/governance/method.go | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/common/config/config.go b/common/config/config.go index 9c35536902..10440e5f2a 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -250,6 +250,17 @@ func GetTrackDestroyedContractHeight() uint32 { } } +func GetUserFeeSplitHeight() uint32 { + switch DefConfig.P2PNode.NetworkId { + case NETWORK_ID_MAIN_NET: + return constants.USER_FEE_SPLIT_OVERFLOW_MAINNET + case NETWORK_ID_POLARIS_NET: + return constants.USER_FEE_SPLIT_OVERFLOW_POLARIS + default: + return 0 + } +} + func GetAddDecimalsHeight() uint32 { switch DefConfig.P2PNode.NetworkId { case NETWORK_ID_MAIN_NET: @@ -447,9 +458,7 @@ func NewGenesisConfig() *GenesisConfig { } } -// // VBFT genesis config, from local config file -// type VBFTConfig struct { N uint32 `json:"n"` // network size C uint32 `json:"c"` // consensus quorum diff --git a/common/constants/constants.go b/common/constants/constants.go index 90c73c354f..52721a34e2 100644 --- a/common/constants/constants.go +++ b/common/constants/constants.go @@ -108,13 +108,16 @@ const BLOCKHEIGHT_ONTFS_POLARIS = 12250000 const BLOCKHEIGHT_CC_POLARIS = 13130000 -//new node cost height +// new node cost height const BLOCKHEIGHT_NEW_PEER_COST_MAINNET = 9400000 const BLOCKHEIGHT_NEW_PEER_COST_POLARIS = 13400000 const BLOCKHEIGHT_TRACK_DESTROYED_CONTRACT_MAINNET = 11700000 const BLOCKHEIGHT_TRACK_DESTROYED_CONTRACT_POLARIS = 14100000 +const USER_FEE_SPLIT_OVERFLOW_MAINNET = 16490000 +const USER_FEE_SPLIT_OVERFLOW_POLARIS = 17550000 + var ( BLOCKHEIGHT_ADD_DECIMALS_MAINNET = uint32(13920000) BLOCKHEIGHT_ADD_DECIMALS_POLARIS = uint32(0) diff --git a/smartcontract/service/native/governance/method.go b/smartcontract/service/native/governance/method.go index aa4f82c56b..e4616186e8 100644 --- a/smartcontract/service/native/governance/method.go +++ b/smartcontract/service/native/governance/method.go @@ -27,6 +27,7 @@ import ( "github.com/ontio/ontology/common" "github.com/ontio/ontology/common/config" "github.com/ontio/ontology/common/constants" + "github.com/ontio/ontology/common/log" cstates "github.com/ontio/ontology/core/states" "github.com/ontio/ontology/smartcontract/service/native" "github.com/ontio/ontology/smartcontract/service/native/utils" @@ -1058,7 +1059,7 @@ func executeSplit2(native *native.NativeService, contract common.Address, view u return splitSum, nil } -func executeAddressSplit(native *native.NativeService, contract common.Address, authorizeInfo *AuthorizeInfo, preIfConsensus, ifConsensus bool, totalPos uint64, totalAmount uint64, peerAddress common.Address) (uint64, error) { +func executeAddressSplit(native *native.NativeService, contract common.Address, authorizeInfo *AuthorizeInfo, preIfConsensus, ifConsensus bool, totalPos uint64, totalAmount uint64, peerAddress common.Address, peerPubkey string) (uint64, error) { var validatePos uint64 if ifConsensus || preIfConsensus { validatePos = authorizeInfo.ConsensusPos + authorizeInfo.WithdrawConsensusPos @@ -1070,6 +1071,16 @@ func executeAddressSplit(native *native.NativeService, contract common.Address, return 0, nil } amount := validatePos * totalAmount / totalPos + amountReal := new(big.Int).Div( + new(big.Int).Mul(new(big.Int).SetUint64(validatePos), new(big.Int).SetUint64(totalAmount)), + new(big.Int).SetUint64(totalPos)).Uint64() + if native.Height > config.GetUserFeeSplitHeight() { + amount = amountReal + } + if amount != amountReal { + log.Errorf("address split overflow: preexec:%v, node: %s, pubkey: %s, user:%s, amount: %d, real: %d, diff: %d", + native.PreExec, peerAddress.ToBase58(), peerPubkey, authorizeInfo.Address.ToBase58(), amount, amountReal, amountReal-amount) + } splitFeeAddress, err := getSplitFeeAddress(native, contract, authorizeInfo.Address) if err != nil { return 0, fmt.Errorf("getSplitFeeAddress, getSplitFeeAddress error: %v", err) @@ -1438,7 +1449,7 @@ func splitNodeFee(native *native.NativeService, contract common.Address, peerPub } //fee split - splitAmount, err := executeAddressSplit(native, contract, &authorizeInfo, preIfConsensus, ifConsensus, totalPos, amount, peerAddress) + splitAmount, err := executeAddressSplit(native, contract, &authorizeInfo, preIfConsensus, ifConsensus, totalPos, amount, peerAddress, peerPubkey) if err != nil { return fmt.Errorf("excuteAddressSplit, excuteAddressSplit error: %v", err) }