From 486821cf76813b829d04fbdbe7b43e4733784ac6 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 7 Nov 2018 19:40:43 -0500 Subject: [PATCH 1/5] Added Classic Rewards and Uncle Rewards --- config.example.json | 3 ++- payouts/unlocker.go | 47 +++++++++++++++++++++++++--------------- payouts/unlocker_test.go | 23 +++++++++++++++----- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/config.example.json b/config.example.json index 1a264b8cc..221e0739d 100644 --- a/config.example.json +++ b/config.example.json @@ -90,7 +90,8 @@ "keepTxFees": false, "interval": "10m", "daemon": "http://127.0.0.1:8545", - "timeout": "10s" + "timeout": "10s", + "classic": true }, "payouts": { diff --git a/payouts/unlocker.go b/payouts/unlocker.go index c073ef0b3..6094b197f 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -26,6 +26,7 @@ type UnlockerConfig struct { Interval string `json:"interval"` Daemon string `json:"daemon"` Timeout string `json:"timeout"` + Classic bool `json:"classic"` } const minDepth = 16 @@ -33,6 +34,7 @@ const byzantiumHardForkHeight = 4370000 var homesteadReward = math.MustParseBig256("5000000000000000000") var byzantiumReward = math.MustParseBig256("3000000000000000000") +var classicReward = math.MustParseBig256("4000000000000000000") // Donate 10% from pool fees to developers const donationFee = 10.0 @@ -159,7 +161,7 @@ func (u *BlockUnlocker) unlockCandidates(candidates []*storage.BlockData) (*Unlo orphan = false result.uncles++ - err := handleUncle(height, uncle, candidate) + err := handleUncle(height, uncle, candidate, u.config.Classic) if err != nil { u.halt = true u.lastFail = err @@ -209,7 +211,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage return err } candidate.Height = correctHeight - reward := getConstReward(candidate.Height) + reward := getConstReward(candidate.Height, u.config.Classic) // Add TX fees extraTxReward, err := u.getExtraRewardForTx(block) @@ -223,7 +225,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage } // Add reward for including uncles - uncleReward := getRewardForUncle(candidate.Height) + uncleReward := getRewardForUncle(candidate.Height, u.config.Classic) rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles)))) reward.Add(reward, rewardForUncles) @@ -233,12 +235,12 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage return nil } -func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.BlockData) error { +func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.BlockData, isClassic bool) error { uncleHeight, err := strconv.ParseInt(strings.Replace(uncle.Number, "0x", "", -1), 16, 64) if err != nil { return err } - reward := getUncleReward(uncleHeight, height) + reward := getUncleReward(uncleHeight, height, isClassic) candidate.Height = height candidate.UncleHeight = uncleHeight candidate.Orphan = false @@ -501,24 +503,35 @@ func weiToShannonInt64(wei *big.Rat) int64 { return value } -func getConstReward(height int64) *big.Int { - if height >= byzantiumHardForkHeight { - return new(big.Int).Set(byzantiumReward) +func getConstReward(height int64, isClassic bool) *big.Int { + if !isClassic { + if height >= byzantiumHardForkHeight { + return new(big.Int).Set(byzantiumReward) + } + return new(big.Int).Set(homesteadReward) + } else { + return new(big.Int).Set(classicReward) } - return new(big.Int).Set(homesteadReward) } -func getRewardForUncle(height int64) *big.Int { - reward := getConstReward(height) +func getRewardForUncle(height int64, isClassic bool) *big.Int { + reward := getConstReward(height, isClassic) return new(big.Int).Div(reward, new(big.Int).SetInt64(32)) } -func getUncleReward(uHeight, height int64) *big.Int { - reward := getConstReward(height) - k := height - uHeight - reward.Mul(big.NewInt(8-k), reward) - reward.Div(reward, big.NewInt(8)) - return reward +func getUncleReward(uHeight, height int64, isClassic bool) *big.Int { + if !isClassic { + reward := getConstReward(height, isClassic) + k := height - uHeight + reward.Mul(big.NewInt(8-k), reward) + reward.Div(reward, big.NewInt(8)) + return reward + } else { + reward := getConstReward(height, isClassic) + reward.Mul(reward, big.NewInt(3125)) + reward.Div(reward, big.NewInt(100000)) + return reward + } } func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int, error) { diff --git a/payouts/unlocker_test.go b/payouts/unlocker_test.go index 26bd980ef..f0af3de4d 100644 --- a/payouts/unlocker_test.go +++ b/payouts/unlocker_test.go @@ -65,7 +65,20 @@ func TestWeiToShannonInt64(t *testing.T) { t.Error("Must charge original value") } } - +func TestGetClassicUncleReward(t *testing.T) { + rewards := make(map[int64]string) + expectedRewards := map[int64]string{ + 1: "125000000000000000", + } + for i := int64(1); i < 2; i++ { + rewards[i] = getUncleReward(1, i+1, true).String() + } + for i, reward := range rewards { + if expectedRewards[i] != rewards[i] { + t.Errorf("Incorrect uncle reward for %v, expected %v vs %v", i, expectedRewards[i], reward) + } + } +} func TestGetUncleReward(t *testing.T) { rewards := make(map[int64]string) expectedRewards := map[int64]string{ @@ -78,7 +91,7 @@ func TestGetUncleReward(t *testing.T) { 7: "625000000000000000", } for i := int64(1); i < 8; i++ { - rewards[i] = getUncleReward(1, i+1).String() + rewards[i] = getUncleReward(1, i+1, false).String() } for i, reward := range rewards { if expectedRewards[i] != rewards[i] { @@ -99,7 +112,7 @@ func TestGetByzantiumUncleReward(t *testing.T) { 7: "375000000000000000", } for i := int64(1); i < 8; i++ { - rewards[i] = getUncleReward(byzantiumHardForkHeight, byzantiumHardForkHeight+i).String() + rewards[i] = getUncleReward(byzantiumHardForkHeight, byzantiumHardForkHeight+i, false).String() } for i, reward := range rewards { if expectedRewards[i] != rewards[i] { @@ -109,7 +122,7 @@ func TestGetByzantiumUncleReward(t *testing.T) { } func TestGetRewardForUngle(t *testing.T) { - reward := getRewardForUncle(1).String() + reward := getRewardForUncle(1, false).String() expectedReward := "156250000000000000" if expectedReward != reward { t.Errorf("Incorrect uncle bonus for height %v, expected %v vs %v", 1, expectedReward, reward) @@ -117,7 +130,7 @@ func TestGetRewardForUngle(t *testing.T) { } func TestGetByzantiumRewardForUngle(t *testing.T) { - reward := getRewardForUncle(byzantiumHardForkHeight).String() + reward := getRewardForUncle(byzantiumHardForkHeight, false).String() expectedReward := "93750000000000000" if expectedReward != reward { t.Errorf("Incorrect uncle bonus for height %v, expected %v vs %v", byzantiumHardForkHeight, expectedReward, reward) From 6bf1b4baae3718dfebe6cd29b9b6286f662fec08 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 19 Nov 2018 13:26:16 -0500 Subject: [PATCH 2/5] Added a few uses of the tranlation keys within the home page for localization --- www/app/templates/index.hbs | 26 ++++++++++++------------- www/translations/en-us.yaml | 38 ++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/www/app/templates/index.hbs b/www/app/templates/index.hbs index 4490ea1aa..fcf23fb39 100644 --- a/www/app/templates/index.hbs +++ b/www/app/templates/index.hbs @@ -5,22 +5,22 @@

Open Ethereum Pool

- Min. payout threshold: {{config.PayoutThreshold}}, Payouts run twice per day.
- PROP Stable and profitable pool with regular payouts. + {{t 'Payout.Minimum' htmlSafe=true}} {{config.PayoutThreshold}}, {{t 'Payout.Run' htmlSafe=true}}.
+ PROP {{t 'Payout.Description' htmlSafe=true}}.
-
Miners Online: {{format-number stats.model.minersTotal}}
-
Pool Hash Rate: {{format-hashrate stats.model.hashrate}}
-
Pool Fee: {{config.PoolFee}}
+
{{t 'Network.Difficulty' htmlSafe=true}}: {{format-number stats.model.minersTotal}}
+
{{t 'Pool.HashRate' htmlSafe=true}}: {{format-hashrate stats.model.hashrate}}
+
{{t 'Pool.Fee' htmlSafe=true}}: {{config.PoolFee}}
{{#if stats.model.stats.lastBlockFound}} -
Last Block Found: {{format-relative (seconds-to-ms stats.model.stats.lastBlockFound)}}
+
{{t 'Block.LastFound' htmlSafe=true}}: {{format-relative (seconds-to-ms stats.model.stats.lastBlockFound)}}
{{/if}}
-
Network Difficulty: {{with-metric-prefix stats.difficulty}}
-
Network Hash Rate: {{format-hashrate stats.hashrate}}
-
Blockchain Height: {{format-number stats.height}}
-
Current Round Variance: {{format-number stats.roundVariance style='percent'}}
+
{{t 'Network.Difficulty' htmlSafe=true}}: {{with-metric-prefix stats.difficulty}}
+
{{t 'Network.HashRate' htmlSafe=true}}: {{format-hashrate stats.hashrate}}
+
{{t 'Block.Height' htmlSafe=true}}: {{format-number stats.height}}
+
{{t 'Network.RoundVariance' htmlSafe=true}}: {{format-number stats.roundVariance style='percent'}}
@@ -28,12 +28,12 @@
-

Your Stats & Payment History

+

{{t 'Your.Stats' htmlSafe=true}} & {{t 'Your.PayHistory' htmlSafe=true}}

- {{input value=cachedLogin class="form-control" placeholder="Enter Your Ethereum Address"}} + {{input value=cachedLogin class="form-control" placeholder= (t 'Ethereum.AddressSearch') }}
diff --git a/www/translations/en-us.yaml b/www/translations/en-us.yaml index 5c7ef82c0..33de9bda5 100644 --- a/www/translations/en-us.yaml +++ b/www/translations/en-us.yaml @@ -1,5 +1,33 @@ -product: - info: '{product} will cost {price, number, USD} if ordered by {deadline, date, time}' - title: 'Hello world!' - html: - info: '{product} will cost {price, number, USD} if ordered by {deadline, date, time}' +# product: +# info: '{product} will cost {price, number, USD} if ordered by {deadline, date, time}' +# title: 'Hello world!' +# html: +# info: '{product} will cost {price, number, USD} if ordered by {deadline, date, time}' +Network: + Difficulty: 'Network Difficulty' + HashRate: 'Network Hash Rate' + RoundVariance: 'Current Round Variance' + +Pool: + HashRate: 'Pool Hash Rate' + Fee: 'Pool Fee' + +Block: + Height: 'Blockchain Height' + LastFound: 'Last Block Found' + +Miners: + Online: 'Miners Online' + +Your: + Stats: 'Your Stats' + PayHistory: 'Payment History' + +Payout: + Minimum: 'Min. payout threshold' + Run: 'Payouts run twicer per day' + Description: 'Stable and profitable pool with regular payouts' + +Search: + Address: 'Enter Your Ethereum Address' + Lookup: 'Lookup' \ No newline at end of file From 90e8337a13ccfb93e1f0b9cc3e53d157c7e5fe58 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 19 Nov 2018 13:32:22 -0500 Subject: [PATCH 3/5] Corrected use of wrong translation key --- www/app/templates/index.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/app/templates/index.hbs b/www/app/templates/index.hbs index fcf23fb39..ab482c8b9 100644 --- a/www/app/templates/index.hbs +++ b/www/app/templates/index.hbs @@ -30,10 +30,10 @@

{{t 'Your.Stats' htmlSafe=true}} & {{t 'Your.PayHistory' htmlSafe=true}}

- {{input value=cachedLogin class="form-control" placeholder= (t 'Ethereum.AddressSearch') }} + {{input value=cachedLogin class="form-control" placeholder= (t 'Search.Address') }}
From 59e49a6ce526c523a8dcde7226f24632a072c525 Mon Sep 17 00:00:00 2001 From: mphan6 Date: Mon, 19 Nov 2018 13:34:36 -0500 Subject: [PATCH 4/5] Update en-us.yaml --- www/translations/en-us.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/translations/en-us.yaml b/www/translations/en-us.yaml index 33de9bda5..dd504858d 100644 --- a/www/translations/en-us.yaml +++ b/www/translations/en-us.yaml @@ -30,4 +30,5 @@ Payout: Search: Address: 'Enter Your Ethereum Address' - Lookup: 'Lookup' \ No newline at end of file + Lookup: 'Lookup' + From 9b11993cf4f1776c5e4c22892c53f0ab6f8158ed Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 19 Nov 2018 14:13:00 -0500 Subject: [PATCH 5/5] Removed commits from other pr --- config.example.json | 3 +-- payouts/unlocker.go | 47 +++++++++++++++------------------------- payouts/unlocker_test.go | 23 +++++--------------- 3 files changed, 23 insertions(+), 50 deletions(-) diff --git a/config.example.json b/config.example.json index 221e0739d..1a264b8cc 100644 --- a/config.example.json +++ b/config.example.json @@ -90,8 +90,7 @@ "keepTxFees": false, "interval": "10m", "daemon": "http://127.0.0.1:8545", - "timeout": "10s", - "classic": true + "timeout": "10s" }, "payouts": { diff --git a/payouts/unlocker.go b/payouts/unlocker.go index 6094b197f..c073ef0b3 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -26,7 +26,6 @@ type UnlockerConfig struct { Interval string `json:"interval"` Daemon string `json:"daemon"` Timeout string `json:"timeout"` - Classic bool `json:"classic"` } const minDepth = 16 @@ -34,7 +33,6 @@ const byzantiumHardForkHeight = 4370000 var homesteadReward = math.MustParseBig256("5000000000000000000") var byzantiumReward = math.MustParseBig256("3000000000000000000") -var classicReward = math.MustParseBig256("4000000000000000000") // Donate 10% from pool fees to developers const donationFee = 10.0 @@ -161,7 +159,7 @@ func (u *BlockUnlocker) unlockCandidates(candidates []*storage.BlockData) (*Unlo orphan = false result.uncles++ - err := handleUncle(height, uncle, candidate, u.config.Classic) + err := handleUncle(height, uncle, candidate) if err != nil { u.halt = true u.lastFail = err @@ -211,7 +209,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage return err } candidate.Height = correctHeight - reward := getConstReward(candidate.Height, u.config.Classic) + reward := getConstReward(candidate.Height) // Add TX fees extraTxReward, err := u.getExtraRewardForTx(block) @@ -225,7 +223,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage } // Add reward for including uncles - uncleReward := getRewardForUncle(candidate.Height, u.config.Classic) + uncleReward := getRewardForUncle(candidate.Height) rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles)))) reward.Add(reward, rewardForUncles) @@ -235,12 +233,12 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage return nil } -func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.BlockData, isClassic bool) error { +func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.BlockData) error { uncleHeight, err := strconv.ParseInt(strings.Replace(uncle.Number, "0x", "", -1), 16, 64) if err != nil { return err } - reward := getUncleReward(uncleHeight, height, isClassic) + reward := getUncleReward(uncleHeight, height) candidate.Height = height candidate.UncleHeight = uncleHeight candidate.Orphan = false @@ -503,35 +501,24 @@ func weiToShannonInt64(wei *big.Rat) int64 { return value } -func getConstReward(height int64, isClassic bool) *big.Int { - if !isClassic { - if height >= byzantiumHardForkHeight { - return new(big.Int).Set(byzantiumReward) - } - return new(big.Int).Set(homesteadReward) - } else { - return new(big.Int).Set(classicReward) +func getConstReward(height int64) *big.Int { + if height >= byzantiumHardForkHeight { + return new(big.Int).Set(byzantiumReward) } + return new(big.Int).Set(homesteadReward) } -func getRewardForUncle(height int64, isClassic bool) *big.Int { - reward := getConstReward(height, isClassic) +func getRewardForUncle(height int64) *big.Int { + reward := getConstReward(height) return new(big.Int).Div(reward, new(big.Int).SetInt64(32)) } -func getUncleReward(uHeight, height int64, isClassic bool) *big.Int { - if !isClassic { - reward := getConstReward(height, isClassic) - k := height - uHeight - reward.Mul(big.NewInt(8-k), reward) - reward.Div(reward, big.NewInt(8)) - return reward - } else { - reward := getConstReward(height, isClassic) - reward.Mul(reward, big.NewInt(3125)) - reward.Div(reward, big.NewInt(100000)) - return reward - } +func getUncleReward(uHeight, height int64) *big.Int { + reward := getConstReward(height) + k := height - uHeight + reward.Mul(big.NewInt(8-k), reward) + reward.Div(reward, big.NewInt(8)) + return reward } func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int, error) { diff --git a/payouts/unlocker_test.go b/payouts/unlocker_test.go index f0af3de4d..26bd980ef 100644 --- a/payouts/unlocker_test.go +++ b/payouts/unlocker_test.go @@ -65,20 +65,7 @@ func TestWeiToShannonInt64(t *testing.T) { t.Error("Must charge original value") } } -func TestGetClassicUncleReward(t *testing.T) { - rewards := make(map[int64]string) - expectedRewards := map[int64]string{ - 1: "125000000000000000", - } - for i := int64(1); i < 2; i++ { - rewards[i] = getUncleReward(1, i+1, true).String() - } - for i, reward := range rewards { - if expectedRewards[i] != rewards[i] { - t.Errorf("Incorrect uncle reward for %v, expected %v vs %v", i, expectedRewards[i], reward) - } - } -} + func TestGetUncleReward(t *testing.T) { rewards := make(map[int64]string) expectedRewards := map[int64]string{ @@ -91,7 +78,7 @@ func TestGetUncleReward(t *testing.T) { 7: "625000000000000000", } for i := int64(1); i < 8; i++ { - rewards[i] = getUncleReward(1, i+1, false).String() + rewards[i] = getUncleReward(1, i+1).String() } for i, reward := range rewards { if expectedRewards[i] != rewards[i] { @@ -112,7 +99,7 @@ func TestGetByzantiumUncleReward(t *testing.T) { 7: "375000000000000000", } for i := int64(1); i < 8; i++ { - rewards[i] = getUncleReward(byzantiumHardForkHeight, byzantiumHardForkHeight+i, false).String() + rewards[i] = getUncleReward(byzantiumHardForkHeight, byzantiumHardForkHeight+i).String() } for i, reward := range rewards { if expectedRewards[i] != rewards[i] { @@ -122,7 +109,7 @@ func TestGetByzantiumUncleReward(t *testing.T) { } func TestGetRewardForUngle(t *testing.T) { - reward := getRewardForUncle(1, false).String() + reward := getRewardForUncle(1).String() expectedReward := "156250000000000000" if expectedReward != reward { t.Errorf("Incorrect uncle bonus for height %v, expected %v vs %v", 1, expectedReward, reward) @@ -130,7 +117,7 @@ func TestGetRewardForUngle(t *testing.T) { } func TestGetByzantiumRewardForUngle(t *testing.T) { - reward := getRewardForUncle(byzantiumHardForkHeight, false).String() + reward := getRewardForUncle(byzantiumHardForkHeight).String() expectedReward := "93750000000000000" if expectedReward != reward { t.Errorf("Incorrect uncle bonus for height %v, expected %v vs %v", byzantiumHardForkHeight, expectedReward, reward)