Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid user fee split overflow #1432

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions smartcontract/service/native/governance/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Loading