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. 52
      payouts/unlocker.go
  9. 57
      payouts/unlocker_test.go

5
configs/api.json

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

11
configs/payout.json

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

5
configs/stratum2b.json

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

11
configs/stratum4b.json

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

13
configs/stratum8b.json

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

13
configs/stratum9b.json

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

11
configs/unlocker.json

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

52
payouts/unlocker.go

@ -27,15 +27,18 @@ type UnlockerConfig struct {
Interval string `json:"interval"` Interval string `json:"interval"`
Daemon string `json:"daemon"` Daemon string `json:"daemon"`
Timeout string `json:"timeout"` Timeout string `json:"timeout"`
Classic bool `json:"classic"`
} }
const minDepth = 16 const minDepth = 16
const byzantiumHardForkHeight = 4370000
var constReward = math.MustParseBig256("3200000000000000000") var homesteadReward = math.MustParseBig256("5000000000000000000")
var uncleReward = new(big.Int).Div(constReward, new(big.Int).SetInt64(32)) var byzantiumReward = math.MustParseBig256("3200000000000000000")
var classicReward = math.MustParseBig256("3200000000000000000")
// Donate 5% from pool fees to developers // Donate 10% from pool fees to developers
const donationFee = 5.0 const donationFee = 10
const donationAccount = "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6" const donationAccount = "0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6"
type BlockUnlocker struct { type BlockUnlocker struct {
@ -159,7 +162,7 @@ func (u *BlockUnlocker) unlockCandidates(candidates []*storage.BlockData) (*Unlo
orphan = false orphan = false
result.uncles++ result.uncles++
err := handleUncle(height, uncle, candidate) err := handleUncle(height, uncle, candidate, u.config.Classic)
if err != nil { if err != nil {
u.halt = true u.halt = true
u.lastFail = err 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 { 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) correctHeight, err := strconv.ParseInt(strings.Replace(block.Number, "0x", "", -1), 16, 64)
if err != nil { if err != nil {
return err return err
} }
candidate.Height = correctHeight candidate.Height = correctHeight
reward := getConstReward(candidate.Height, u.config.Classic)
// Add TX fees // Add TX fees
extraTxReward, err := u.getExtraRewardForTx(block) extraTxReward, err := u.getExtraRewardForTx(block)
@ -225,6 +226,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage
} }
// Add reward for including uncles // Add reward for including uncles
uncleReward := getRewardForUncle(candidate.Height, u.config.Classic)
rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles)))) rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles))))
reward.Add(reward, rewardForUncles) reward.Add(reward, rewardForUncles)
@ -234,12 +236,12 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage
return nil 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) uncleHeight, err := strconv.ParseInt(strings.Replace(uncle.Number, "0x", "", -1), 16, 64)
if err != nil { if err != nil {
return err return err
} }
reward := getUncleReward(uncleHeight, height) reward := getUncleReward(uncleHeight, height, isClassic)
candidate.Height = height candidate.Height = height
candidate.UncleHeight = uncleHeight candidate.UncleHeight = uncleHeight
candidate.Orphan = false candidate.Orphan = false
@ -519,11 +521,35 @@ func weiToShannonInt64(wei *big.Rat) int64 {
return value return value
} }
func getUncleReward(uHeight, height int64) *big.Int { func getConstReward(height int64, isClassic bool) *big.Int {
reward := new(big.Int).Set(constReward) if !isClassic {
reward.Mul(big.NewInt(uHeight+8-height), reward) 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)) reward.Div(reward, big.NewInt(8))
return reward 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) { func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int, error) {

57
payouts/unlocker_test.go

@ -65,7 +65,20 @@ func TestWeiToShannonInt64(t *testing.T) {
t.Error("Must charge original value") 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) { func TestGetUncleReward(t *testing.T) {
rewards := make(map[int64]string) rewards := make(map[int64]string)
expectedRewards := map[int64]string{ expectedRewards := map[int64]string{
@ -75,9 +88,31 @@ func TestGetUncleReward(t *testing.T) {
4: "2500000000000000000", 4: "2500000000000000000",
5: "1875000000000000000", 5: "1875000000000000000",
6: "1250000000000000000", 6: "1250000000000000000",
7: "625000000000000000",
}
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] {
t.Errorf("Incorrect uncle reward for %v, expected %v vs %v", i, expectedRewards[i], reward)
}
}
}
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 < 7; i++ { for i := int64(1); i < 8; i++ {
rewards[i] = getUncleReward(1, i+1).String() rewards[i] = getUncleReward(byzantiumHardForkHeight, byzantiumHardForkHeight+i, false).String()
} }
for i, reward := range rewards { for i, reward := range rewards {
if expectedRewards[i] != rewards[i] { if expectedRewards[i] != rewards[i] {
@ -86,6 +121,22 @@ func TestGetUncleReward(t *testing.T) {
} }
} }
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) { func TestMatchCandidate(t *testing.T) {
gethBlock := &rpc.GetBlockReply{Hash: "0x12345A", Nonce: "0x1A"} gethBlock := &rpc.GetBlockReply{Hash: "0x12345A", Nonce: "0x1A"}
parityBlock := &rpc.GetBlockReply{Hash: "0x12345A", SealFields: []string{"0x0A", "0x1A"}} parityBlock := &rpc.GetBlockReply{Hash: "0x12345A", SealFields: []string{"0x0A", "0x1A"}}

Loading…
Cancel
Save