Skip to content

Commit

Permalink
add user fee split overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy committed Aug 4, 2023
1 parent f966c6d commit ecede35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
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

0 comments on commit ecede35

Please sign in to comment.