From 8a89e929f3b52514b21229751631f919f4f76ff1 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:03:54 +0200 Subject: [PATCH] ethereumPow unlocker unlocker --- payouts/unlocker.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/payouts/unlocker.go b/payouts/unlocker.go index 1ddf0a4..7080e25 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -36,7 +36,9 @@ type UnlockerConfig struct { const minDepth = 16 // params for ethereumPow -var constReward = math.MustParseBig256("2000000000000000000") // 2 ETHW block Reward +const byzantiumHardForkHeightethereumPow = 7280000 + +var byzantiumEthereumpow = math.MustParseBig256("2000000000000000000") // Donate 1% from pool fees to developers const donationFee = 1.0 @@ -313,7 +315,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage reward.Add(reward, rewardForUncles) } else if u.config.Network == "ethereumPow" { - reward := new(big.Int).Set(constReward) + reward = getConstRewardEthereumpow(candidate.Height) // Add reward for including uncles uncleReward := new(big.Int).Div(reward, big32) rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles)))) @@ -364,7 +366,7 @@ func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.Bloc } else if cfg.Network == "callisto" { reward = getUncleRewardEthereum(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstRewardcallisto(height)) } else if cfg.Network == "ethereumPow" { - reward = getUncleRewardEthereumPow(uncleHeight, height) + reward = getUncleRewardEthereumpow(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstRewardEthereumpow(height)) } else if cfg.Network == "ethereum" || cfg.Network == "ropsten" || cfg.Network == "ethereumFair" { reward = getUncleRewardEthereum(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstRewardUbiq(height)) } @@ -719,6 +721,13 @@ func getConstRewardExpanse(height int64) *big.Int { return new(big.Int).Set(byzantiumExpanseReward) } +func getConstRewardEthereumpow(height int64) *big.Int { + if height >= byzantiumHardForkHeight { + return new(big.Int).Set(byzantiumEthereumpow) + } + return new(big.Int).Set(byzantiumEthereumpow) +} + // ubqhash func getConstRewardUbiq(height int64) *big.Int { // Rewards @@ -837,9 +846,12 @@ func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int, return amount, nil } -func getUncleRewardEthereumPow(uHeight, height int64) *big.Int { - reward := new(big.Int).Set(constReward) - reward.Mul(big.NewInt(uHeight+8-height), reward) - reward.Div(reward, big.NewInt(8)) - return reward +func getUncleRewardEthereumpow(uHeight *big.Int, height *big.Int, reward *big.Int) *big.Int { + r := new(big.Int) + r.Add(uHeight, big8) + r.Sub(r, height) + r.Mul(r, reward) + r.Div(r, big8) + + return r }