Reward float upgrade (#940)

* feat: use float type reward

* feat: add test of float reward
This commit is contained in:
wgr523 2025-04-16 17:03:41 +08:00 committed by GitHub
parent 4a8800674d
commit 6a38aa00aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 11 deletions

View file

@ -682,9 +682,6 @@ func PrepareXDCTestBlockChainWithProtectorObserver(t *testing.T, numOfBlocks int
}
block := CreateBlock(blockchain, chainConfig, currentBlock, i, roundNumber, blockCoinBase, signer, signFn, penalty, nil, "f11ec19df702aa6bd9b3b2186edbc66d6b50b06334455a4a2ae8d166f28a14ff")
if i == 900 {
fmt.Println(block.Penalties())
}
err = blockchain.InsertBlock(block)
if err != nil {
t.Fatal(err)

View file

@ -291,9 +291,9 @@ func TestHookRewardAfterUpgrade(t *testing.T) {
assert.Equal(t, addr, observer1Addr)
r := x.(map[common.Address]*big.Int)
owner := state.GetCandidateOwner(parentState, addr)
a, _ := big.NewInt(0).SetString("270000000000000000000", 10)
a, _ := big.NewInt(0).SetString("270112500000000000000", 10) // this value tests the float64 reward
assert.Zero(t, a.Cmp(r[owner]), "real reward is", r[owner])
b, _ := big.NewInt(0).SetString("30000000000000000000", 10)
b, _ := big.NewInt(0).SetString("30012500000000000000", 10) // this value tests the float64 reward
assert.Zero(t, b.Cmp(r[config.XDPoS.FoudationWalletAddr]), "real reward is", r[config.XDPoS.FoudationWalletAddr])
}
common.TIPUpgradeReward = backup

View file

@ -234,7 +234,7 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
rewardsMap["signersProtector"] = signers[ProtectorNodeBeneficiary]
rewardsMap["signersObserver"] = signers[ObserverNodeBeneficiary]
type rewardWithType struct {
r uint64
r float64
t Beneficiary
key string
}
@ -243,7 +243,8 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
{currentConfig.ProtectorReward, ProtectorNodeBeneficiary, "rewardsProtector"},
{currentConfig.ObserverReward, ObserverNodeBeneficiary, "rewardsObserver"},
} {
originalReward := new(big.Int).Mul(new(big.Int).SetUint64(rwt.r), new(big.Int).SetUint64(params.Ether))
originalRewardFloat := new(big.Float).Mul(new(big.Float).SetFloat64(rwt.r), new(big.Float).SetUint64(params.Ether))
originalReward, _ := originalRewardFloat.Int(nil)
chainReward := util.RewardInflation(chain, originalReward, number, common.BlocksPerYear)
rewardSigners, err := CalculateRewardForSignerFixed(chainReward, signers[rwt.t])
if err != nil {

View file

@ -180,7 +180,7 @@ var (
ExpTimeoutConfig: ExpTimeoutConfig{Base: 1.0, MaxExponent: 0},
MasternodeReward: 500, // double as Reward
ProtectorReward: 400,
ObserverReward: 300,
ObserverReward: 300.125,
},
}
@ -462,9 +462,9 @@ type V2Config struct {
TimeoutPeriod int `json:"timeoutPeriod"` // Duration in ms
CertThreshold float64 `json:"certificateThreshold"` // Necessary number of messages from master nodes to form a certificate
MasternodeReward uint64 `json:"masternodeReward"` // Block reward per master node (core validator) - unit Ether
ProtectorReward uint64 `json:"protectorReward"` // Block reward per protector - unit Ether
ObserverReward uint64 `json:"observerReward"` // Block reward per observer - unit Ether
MasternodeReward float64 `json:"masternodeReward"` // Block reward per master node (core validator) - unit Ether
ProtectorReward float64 `json:"protectorReward"` // Block reward per protector - unit Ether
ObserverReward float64 `json:"observerReward"` // Block reward per observer - unit Ether
ExpTimeoutConfig ExpTimeoutConfig `json:"expTimeoutConfig"`
}