From 123cf11ff217293fefdaf842c454a9e8efb3ac83 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Wed, 14 Jun 2023 21:40:53 +0200 Subject: [PATCH] Universal block reward and Uncle ethash test Universal block reward and Uncle ethash --- payouts/unlocker.go | 54 +++++++++++++++++++++++++++++++++------------ proxy/miner.go | 2 +- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/payouts/unlocker.go b/payouts/unlocker.go index 3e7e9e9..ecf0b57 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -35,9 +35,9 @@ type UnlockerConfig struct { const minDepth = 16 -// Donate 1% from pool fees to developers -const donationFee = 1.0 -const donationAccount = "0xd97e0075Abe7dC9e12805345336340649b8658Df" +// Universal block reward ethash +var UniversalBlockReward = math.MustParseBig256("2000000000000000000") // 2.00 +var UniversalUncleReward = math.MustParseBig256("1750000000000000000") // 1.75 // params for etchash var homesteadReward = math.MustParseBig256("5000000000000000000") @@ -65,6 +65,10 @@ var big32 = big.NewInt(32) var big8 = big.NewInt(8) var big2 = big.NewInt(2) +// Donate 1% from pool fees to developers +const donationFee = 1.0 +const donationAccount = "0xd97e0075Abe7dC9e12805345336340649b8658Df" + type BlockUnlocker struct { config *UnlockerConfig backend *storage.RedisClient @@ -103,6 +107,8 @@ func NewBlockUnlocker(cfg *UnlockerConfig, backend *storage.RedisClient, network // nothing needs configuring here, simply proceed. } else if network == "octaspace" { // nothing needs configuring here, simply proceed. + } else if network == "universal" { + // nothing needs configuring here, simply proceed. } else { log.Fatalln("Invalid network set", network) } @@ -333,6 +339,12 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage uncleReward := new(big.Int).Div(reward, big32) rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles)))) reward.Add(reward, rewardForUncles) + } else if u.config.Network == "universal" { + reward = getConstRewardUniversal(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)))) + reward.Add(reward, rewardForUncles) } else { log.Fatalln("Invalid network set", u.config.Network) } @@ -394,7 +406,10 @@ func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.Bloc reward = getUncleRewardEthereum(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstRewardUbiq(height)) } else if cfg.Network == "octaspace" { reward = getUncleRewardOctaspace(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstRewardOctaspace(height)) + } else if cfg.Network == "universal" { + reward = getUncleRewardUniversal(uncleHeight, candidate.Height) } + candidate.Height = height candidate.UncleHeight = uncleHeight candidate.Orphan = false @@ -746,17 +761,6 @@ func getConstRewardExpanse(height int64) *big.Int { return new(big.Int).Set(homesteadExpanseReward) } -// expanse Uncle rw -func getUncleRewardExpanse(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 -} - func getConstRewardEthereumpow(height int64) *big.Int { // Rewards) // EthereumPow @@ -937,3 +941,25 @@ func getUncleRewardEthereumpow(uHeight *big.Int, height *big.Int, reward *big.In return r } + +// expanse Universal +func getConstRewardUniversal(height int64) *big.Int { + if big.NewInt(height).Cmp(UniversalBlockReward) >= 0 { + return new(big.Int).Set(UniversalBlockReward) + } + return new(big.Int).Set(UniversalBlockReward) +} +func getUncleRewardUniversal(uHeight, height int64) *big.Int { + return new(big.Int).Set(UniversalUncleReward) +} + +// expanse Uncle rw +func getUncleRewardExpanse(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 +} diff --git a/proxy/miner.go b/proxy/miner.go index b89350b..9b4a078 100644 --- a/proxy/miner.go +++ b/proxy/miner.go @@ -28,7 +28,7 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param hasher = etchash.New(&ecip1099FBlockMordor, nil) } else if s.config.Network == "ubiq" { hasher = etchash.New(nil, &uip1FEpoch) - } else if s.config.Network == "ethereum" || s.config.Network == "ropsten" || s.config.Network == "ethereumPow" || s.config.Network == "ethereumFair" || s.config.Network == "callisto" || s.config.Network == "etica" || s.config.Network == "expanse" || s.config.Network == "octaspace" { + } else if s.config.Network == "ethereum" || s.config.Network == "ropsten" || s.config.Network == "ethereumPow" || s.config.Network == "ethereumFair" || s.config.Network == "callisto" || s.config.Network == "etica" || s.config.Network == "expanse" || s.config.Network == "octaspace" || s.config.Network == "universal" { hasher = etchash.New(nil, nil) } else { // unknown network