Browse Source

Added Classic Rewards and Uncle Rewards + config.json

master
yuriy0803 5 years ago
parent
commit
9362b303ab
  1. 5
      configs/api.json
  2. 11
      configs/payout.json
  3. 5
      configs/stratum2b.json
  4. 11
      configs/stratum4b.json
  5. 13
      configs/stratum8b.json
  6. 13
      configs/stratum9b.json
  7. 11
      configs/unlocker.json
  8. 62
      payouts/unlocker.go
  9. 59
      payouts/unlocker_test.go

5
configs/api.json

@ -65,7 +65,7 @@
"upstream": [
{
"name": "main",
"url": "http://40.121.105.44:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
},
{
@ -92,7 +92,8 @@
"keepTxFees": false,
"interval": "10m",
"daemon": "http://127.0.0.1:8545",
"timeout": "10s"
"timeout": "10s",
"classic": true
},
"payouts": {

11
configs/payout.json

@ -65,7 +65,7 @@
"upstream": [
{
"name": "main",
"url": "http://40.121.105.44:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
},
{
@ -91,17 +91,18 @@
"immatureDepth": 20,
"keepTxFees": false,
"interval": "10m",
"daemon": "http://127.0.0.1:8591",
"timeout": "10s"
"daemon": "http://127.0.0.1:8545",
"timeout": "10s",
"classic": true
},
"payouts": {
"enabled": true,
"requirePeers": 4,
"interval": "1h",
"daemon": "http://127.0.0.1:8501",
"daemon": "http://127.0.0.1:8545",
"timeout": "120s",
"address": "0x3f156afdb248618892cb5089ba5a5fcac8ee0b01",
"address": "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6",
"autoGas": true,
"gas": "21000",
"gasPrice": "50000000000",

5
configs/stratum2b.json

@ -19,7 +19,7 @@
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
"difficulty": 2000000000,
"stratumHostname": "perkle-pool.esprezzo.io",
"stratumHostname": "Domain name",
"healthCheck": true,
"maxFails": 100,
"hashrateExpiration": "3h",
@ -66,7 +66,7 @@
"upstream": [
{
"name": "backup",
"url": "http://127.0.0.1:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
}
],
@ -89,6 +89,7 @@
"interval": "10m",
"daemon": "http://127.0.0.1:8545",
"timeout": "10s"
"classic": true
},
"payouts": {

11
configs/stratum4b.json

@ -19,7 +19,7 @@
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
"difficulty": 4000000000,
"stratumHostname": "perkle-pool.esprezzo.io",
"stratumHostname": "Domain name",
"healthCheck": true,
"maxFails": 100,
"hashrateExpiration": "3h",
@ -66,7 +66,7 @@
"upstream": [
{
"name": "main",
"url": "http://40.121.105.44:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
},
{
@ -92,15 +92,16 @@
"immatureDepth": 20,
"keepTxFees": false,
"interval": "10m",
"daemon": "http://127.0.0.1:8501",
"timeout": "10s"
"daemon": "http://127.0.0.1:8545",
"timeout": "10s",
"classic": true
},
"payouts": {
"enabled": false,
"requirePeers": 5,
"interval": "3h",
"daemon": "http://127.0.0.1:8501",
"daemon": "http://127.0.0.1:8545",
"timeout": "10s",
"address": "0x",
"autoGas": true,

13
configs/stratum8b.json

@ -19,7 +19,7 @@
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
"difficulty": 8000000000,
"stratumHostname": "perkle-pool.esprezzo.io",
"stratumHostname": "Domain name",
"healthCheck": true,
"maxFails": 100,
"hashrateExpiration": "3h",
@ -66,12 +66,12 @@
"upstream": [
{
"name": "main",
"url": "http://40.121.105.44:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
},
{
"name": "backup",
"url": "http://127.0.0.2:8501",
"url": "http://127.0.0.2:8545",
"timeout": "10s"
}
],
@ -86,14 +86,15 @@
"unlocker": {
"enabled": false,
"poolFee": 0.5,
"poolFeeAddress": "0x0f31986d7a0d4f160acd97583e3c3b591dcb5dde",
"poolFeeAddress": "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6",
"donate": true,
"depth": 120,
"immatureDepth": 20,
"keepTxFees": false,
"interval": "10m",
"daemon": "http://127.0.0.1:8501",
"timeout": "10s"
"daemon": "http://127.0.0.1:8545",
"timeout": "10s",
"classic": true
},
"payouts": {

13
configs/stratum9b.json

@ -19,7 +19,7 @@
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
"difficulty": 9000000000,
"stratumHostname": "perkle-pool.esprezzo.io",
"stratumHostname": "Domain name",
"healthCheck": true,
"maxFails": 100,
"hashrateExpiration": "3h",
@ -66,12 +66,12 @@
"upstream": [
{
"name": "main",
"url": "http://40.121.105.44:8501",
"url": "http://127.0.01:8545",
"timeout": "10s"
},
{
"name": "backup",
"url": "http://127.0.0.2:8501",
"url": "http://127.0.0.2:8545",
"timeout": "10s"
}
],
@ -86,14 +86,15 @@
"unlocker": {
"enabled": false,
"poolFee": 0.5,
"poolFeeAddress": "0x0f31986d7a0d4f160acd97583e3c3b591dcb5dde",
"poolFeeAddress": "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6",
"donate": true,
"depth": 120,
"immatureDepth": 20,
"keepTxFees": false,
"interval": "10m",
"daemon": "http://127.0.0.1:8501",
"timeout": "10s"
"daemon": "http://127.0.0.1:8545",
"timeout": "10s",
"classic": true
},
"payouts": {

11
configs/unlocker.json

@ -65,12 +65,12 @@
"upstream": [
{
"name": "main",
"url": "http://40.121.105.44:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
},
{
"name": "backup",
"url": "http://127.0.0.1:8501",
"url": "http://127.0.0.1:8545",
"timeout": "10s"
}
],
@ -85,14 +85,15 @@
"unlocker": {
"enabled": true,
"poolFee": 0.5,
"poolFeeAddress": "0x0f31986d7a0d4f160acd97583e3c3b591dcb5dde",
"poolFeeAddress": "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6",
"donate": true,
"depth": 120,
"immatureDepth": 20,
"keepTxFees": false,
"interval": "10m",
"daemon": "http://127.0.0.1:8501",
"timeout": "120s"
"daemon": "http://127.0.0.1:8545",
"timeout": "120s",
"classic": true
},
"payouts": {

62
payouts/unlocker.go

@ -4,7 +4,7 @@ import (
"fmt"
"log"
"math/big"
"os"
"os"
"strconv"
"strings"
"time"
@ -27,15 +27,18 @@ type UnlockerConfig struct {
Interval string `json:"interval"`
Daemon string `json:"daemon"`
Timeout string `json:"timeout"`
Classic bool `json:"classic"`
}
const minDepth = 16
const byzantiumHardForkHeight = 4370000
var constReward = math.MustParseBig256("3200000000000000000")
var uncleReward = new(big.Int).Div(constReward, new(big.Int).SetInt64(32))
var homesteadReward = math.MustParseBig256("5000000000000000000")
var byzantiumReward = math.MustParseBig256("3200000000000000000")
var classicReward = math.MustParseBig256("3200000000000000000")
// Donate 5% from pool fees to developers
const donationFee = 5.0
// Donate 10% from pool fees to developers
const donationFee = 10
const donationAccount = "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6"
type BlockUnlocker struct {
@ -159,7 +162,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
@ -204,14 +207,12 @@ func matchCandidate(block *rpc.GetBlockReply, candidate *storage.BlockData) bool
}
func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage.BlockData) error {
// Initial 5 Ether static reward
reward := new(big.Int).Set(constReward)
correctHeight, err := strconv.ParseInt(strings.Replace(block.Number, "0x", "", -1), 16, 64)
if err != nil {
return err
}
candidate.Height = correctHeight
reward := getConstReward(candidate.Height, u.config.Classic)
// Add TX fees
extraTxReward, err := u.getExtraRewardForTx(block)
@ -225,6 +226,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage
}
// Add reward for including uncles
uncleReward := getRewardForUncle(candidate.Height, u.config.Classic)
rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles))))
reward.Add(reward, rewardForUncles)
@ -234,12 +236,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
@ -337,7 +339,7 @@ func (u *BlockUnlocker) unlockPendingBlocks() {
entries = append(entries, fmt.Sprintf("\tREWARD %v: %v: %v Shannon", block.RoundKey(), login, reward))
per := new(big.Rat)
if val, ok := percents[login]; ok {
per = val
per = val
}
u.backend.WriteReward(login, reward, per, true, block)
}
@ -519,11 +521,35 @@ func weiToShannonInt64(wei *big.Rat) int64 {
return value
}
func getUncleReward(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 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 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, 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) {
@ -542,4 +568,4 @@ func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int,
}
}
return amount, nil
}
}

59
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{
@ -75,9 +88,10 @@ func TestGetUncleReward(t *testing.T) {
4: "2500000000000000000",
5: "1875000000000000000",
6: "1250000000000000000",
7: "625000000000000000",
}
for i := int64(1); i < 7; i++ {
rewards[i] = getUncleReward(1, i+1).String()
for i := int64(1); i < 8; i++ {
rewards[i] = getUncleReward(1, i+1, false).String()
}
for i, reward := range rewards {
if expectedRewards[i] != rewards[i] {
@ -86,6 +100,43 @@ func TestGetUncleReward(t *testing.T) {
}
}
func TestGetByzantiumUncleReward(t *testing.T) {
rewards := make(map[int64]string)
expectedRewards := map[int64]string{
1: "2625000000000000000",
2: "2250000000000000000",
3: "1875000000000000000",
4: "1500000000000000000",
5: "1125000000000000000",
6: "750000000000000000",
7: "375000000000000000",
}
for i := int64(1); i < 8; i++ {
rewards[i] = getUncleReward(byzantiumHardForkHeight, byzantiumHardForkHeight+i, false).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 TestGetRewardForUngle(t *testing.T) {
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)
}
}
func TestGetByzantiumRewardForUngle(t *testing.T) {
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)
}
}
func TestMatchCandidate(t *testing.T) {
gethBlock := &rpc.GetBlockReply{Hash: "0x12345A", Nonce: "0x1A"}
parityBlock := &rpc.GetBlockReply{Hash: "0x12345A", SealFields: []string{"0x0A", "0x1A"}}
@ -110,4 +161,4 @@ func TestMatchCandidate(t *testing.T) {
if !matchCandidate(block, immature) {
t.Error("Must match with hash")
}
}
}
Loading…
Cancel
Save