Browse Source

Merge pull request #4 from yuriy0803/CODE-ETHASH

Available Code Ethash
master
yuriy0803 5 years ago committed by GitHub
parent
commit
c8ba5a2075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 7
      api.json
  3. 2
      main.go
  4. 39
      payouts/unlocker.go
  5. 1
      proxy/config.go
  6. 19
      proxy/miner.go

2
README.md

@ -3,7 +3,7 @@
Donations Donations
ETC: 0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6 ETC: 0xd92fa5a9732a0aec36dc8d5a6a1305dc2d3e09e6
### WARNING: This code is currently configured for the Ethereum Classic main network ### WARNING: This code is currently configured for the ETHASH main network
### Features ### Features

7
api.json

@ -1,9 +1,8 @@
{ {
"threads": 2, "threads": 4,
"coin": "etc", "coin": "etc",
"name": "main", "name": "main",
"pplns": 0, "pplns": 9000,
"network": "classic",
"proxy": { "proxy": {
"enabled": true, "enabled": true,
@ -93,7 +92,7 @@
"depth": 120, "depth": 120,
"immatureDepth": 20, "immatureDepth": 20,
"keepTxFees": false, "keepTxFees": false,
"interval": "1m", "interval": "10m",
"daemon": "http://192.168.178.26:8545", "daemon": "http://192.168.178.26:8545",
"timeout": "10s" "timeout": "10s"
}, },

2
main.go

@ -33,7 +33,7 @@ func startApi() {
} }
func startBlockUnlocker() { func startBlockUnlocker() {
u := payouts.NewBlockUnlocker(&cfg.BlockUnlocker, backend, &cfg.Network) u := payouts.NewBlockUnlocker(&cfg.BlockUnlocker, backend)
u.Start() u.Start()
} }

39
payouts/unlocker.go

@ -27,12 +27,14 @@ 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"`
Ecip1017FBlock int64 `json:"ecip1017FBlock"`
Ecip1017EraRounds *big.Int `json:"ecip1017EraRounds"`
} }
const minDepth = 16 const minDepth = 16
// const ecip1017FBlock = 0 // mordor
// var ecip1017EraRounds = big.NewInt(2000000) // mordor
const ecip1017FBlock = 5000000 // mainnet
var ecip1017EraRounds = big.NewInt(5000000) // mainnet
var disinflationRateQuotient = big.NewInt(4) // Disinflation rate quotient for ECIP1017 var disinflationRateQuotient = big.NewInt(4) // Disinflation rate quotient for ECIP1017
var disinflationRateDivisor = big.NewInt(5) // Disinflation rate divisor for ECIP1017 var disinflationRateDivisor = big.NewInt(5) // Disinflation rate divisor for ECIP1017
var big32 = big.NewInt(32) var big32 = big.NewInt(32)
@ -48,16 +50,7 @@ type BlockUnlocker struct {
lastFail error lastFail error
} }
func NewBlockUnlocker(cfg *UnlockerConfig, backend *storage.RedisClient, network *string) *BlockUnlocker { func NewBlockUnlocker(cfg *UnlockerConfig, backend *storage.RedisClient) *BlockUnlocker {
if *network == "classic" {
cfg.Ecip1017FBlock = 5000000
cfg.Ecip1017EraRounds = big.NewInt(5000000)
} else if *network == "mordor" {
cfg.Ecip1017FBlock = 0
cfg.Ecip1017EraRounds = big.NewInt(2000000)
} else {
log.Fatalln("Invalid network set", network)
}
if len(cfg.PoolFeeAddress) != 0 && !util.IsValidHexAddress(cfg.PoolFeeAddress) { if len(cfg.PoolFeeAddress) != 0 && !util.IsValidHexAddress(cfg.PoolFeeAddress) {
log.Fatalln("Invalid poolFeeAddress", cfg.PoolFeeAddress) log.Fatalln("Invalid poolFeeAddress", cfg.PoolFeeAddress)
@ -177,7 +170,7 @@ func (u *BlockUnlocker) unlockCandidates(candidates []*storage.BlockData) (*Unlo
orphan = false orphan = false
result.uncles++ result.uncles++
err := handleUncle(height, uncle, candidate, u.config) err := handleUncle(height, uncle, candidate)
if err != nil { if err != nil {
u.halt = true u.halt = true
u.lastFail = err u.lastFail = err
@ -227,8 +220,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage
return err return err
} }
candidate.Height = correctHeight candidate.Height = correctHeight
era := GetBlockEra(big.NewInt(candidate.Height), u.config.Ecip1017EraRounds) reward := getConstReward(candidate.Height)
reward := getConstReward(era)
// Add reward for including uncles // Add reward for including uncles
uncleReward := getRewardForUncle(reward) uncleReward := getRewardForUncle(reward)
@ -252,13 +244,12 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage
return nil return nil
} }
func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.BlockData, cfg *UnlockerConfig) error { func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.BlockData) 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
} }
era := GetBlockEra(big.NewInt(height), cfg.Ecip1017EraRounds) reward := getUncleReward(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstReward(height))
reward := getUncleReward(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), era, getConstReward(era))
candidate.Height = height candidate.Height = height
candidate.UncleHeight = uncleHeight candidate.UncleHeight = uncleHeight
candidate.Orphan = false candidate.Orphan = false
@ -569,9 +560,15 @@ func GetBlockEra(blockNum, eraLength *big.Int) *big.Int {
return new(big.Int).Sub(d, dremainder) return new(big.Int).Sub(d, dremainder)
} }
func getConstReward(era *big.Int) *big.Int { func getConstReward(height int64) *big.Int {
var blockReward = homesteadReward var blockReward = homesteadReward
var bigHeight = new(big.Int).SetInt64(height)
// Ensure value 'era' is configured.
era := GetBlockEra(bigHeight, ecip1017EraRounds)
wr := GetBlockWinnerRewardByEra(era, blockReward) wr := GetBlockWinnerRewardByEra(era, blockReward)
// wurs := GetBlockWinnerRewardForUnclesByEra(era, uncles, blockReward) // wurs "winner uncle rewards"
// wr.Add(wr, wurs)
return wr return wr
} }
@ -579,7 +576,9 @@ func getRewardForUncle(blockReward *big.Int) *big.Int {
return new(big.Int).Div(blockReward, big32) //return new(big.Int).Div(reward, new(big.Int).SetInt64(32)) return new(big.Int).Div(blockReward, big32) //return new(big.Int).Div(reward, new(big.Int).SetInt64(32))
} }
func getUncleReward(uHeight *big.Int, height *big.Int, era *big.Int, reward *big.Int) *big.Int { func getUncleReward(uHeight *big.Int, height *big.Int, reward *big.Int) *big.Int {
// Ensure value 'era' is configured.
era := GetBlockEra(height, ecip1017EraRounds)
// Era 1 (index 0): // Era 1 (index 0):
// An extra reward to the winning miner for including uncles as part of the block, in the form of an extra 1/32 (0.15625ETC) per uncle included, up to a maximum of two (2) uncles. // An extra reward to the winning miner for including uncles as part of the block, in the form of an extra 1/32 (0.15625ETC) per uncle included, up to a maximum of two (2) uncles.
if era.Cmp(big.NewInt(0)) == 0 { if era.Cmp(big.NewInt(0)) == 0 {

1
proxy/config.go

@ -16,7 +16,6 @@ type Config struct {
Threads int `json:"threads"` Threads int `json:"threads"`
Network string `json:"network"`
Coin string `json:"coin"` Coin string `json:"coin"`
Pplns int64 `json:"pplns"` Pplns int64 `json:"pplns"`
Redis storage.Config `json:"redis"` Redis storage.Config `json:"redis"`

19
proxy/miner.go

@ -6,27 +6,14 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/yuriy0803/go-etchash"
) )
var ecip1099FBlockClassic uint64 = 11700000 // classic mainnet var hasher = ethash.New()
var ecip1099FBlockMordor uint64 = 2520000 // mordor
var hasher *etchash.Etchash = nil
func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, params []string) (bool, bool) { func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, params []string) (bool, bool) {
if hasher == nil {
if s.config.Network == "classic" {
hasher = etchash.New(&ecip1099FBlockClassic)
} else if s.config.Network == "mordor" {
hasher = etchash.New(&ecip1099FBlockMordor)
} else {
// unknown network
log.Printf("Unknown network configuration %s", s.config.Network)
return false, false
}
}
nonceHex := params[0] nonceHex := params[0]
hashNoNonce := params[1] hashNoNonce := params[1]
mixDigest := params[2] mixDigest := params[2]

Loading…
Cancel
Save