From ccb56e87109cff1f3dd9c37b99182e0573e0c8ab Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Sun, 14 Mar 2021 10:56:50 +0100 Subject: [PATCH] Update Master --- api.json | 4 +++- main.go | 2 +- payouts/payer.go | 14 ++++++------- payouts/unlocker.go | 49 +++++++++++++++++++++++---------------------- proxy/config.go | 1 + proxy/handlers.go | 4 ++-- proxy/miner.go | 19 +++++++++++++++--- 7 files changed, 55 insertions(+), 38 deletions(-) diff --git a/api.json b/api.json index bc17b13..016baac 100644 --- a/api.json +++ b/api.json @@ -2,7 +2,8 @@ "threads": 4, "coin": "etc", "name": "main", - "pplns": 9000, + "pplns": 9000, + "network": "classic", "proxy": { "enabled": true, @@ -16,6 +17,7 @@ "hashrateExpiration": "3h", "healthCheck": true, + "debug": true, "maxFails": 100, "stratum": { diff --git a/main.go b/main.go index e8921bc..f60ab57 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ func startApi() { } func startBlockUnlocker() { - u := payouts.NewBlockUnlocker(&cfg.BlockUnlocker, backend) + u := payouts.NewBlockUnlocker(&cfg.BlockUnlocker, backend, &cfg.Network) u.Start() } diff --git a/payouts/payer.go b/payouts/payer.go index a3e6f34..174325d 100644 --- a/payouts/payer.go +++ b/payouts/payer.go @@ -5,10 +5,10 @@ import ( "log" "math/big" "os" - "os/exec" + "os/exec" "strconv" + "sync" "time" - "sync" "github.com/ethereum/go-ethereum/common/hexutil" @@ -30,9 +30,9 @@ type PayoutsConfig struct { GasPrice string `json:"gasPrice"` AutoGas bool `json:"autoGas"` // In Shannon - Threshold int64 `json:"threshold"` - BgSave bool `json:"bgsave"` - ConcurrentTx int `json:"concurrentTx"` + Threshold int64 `json:"threshold"` + BgSave bool `json:"bgsave"` + ConcurrentTx int `json:"concurrentTx"` } func (self PayoutsConfig) GasHex() string { @@ -108,7 +108,7 @@ func (u *PayoutsProcessor) Start() { func (u *PayoutsProcessor) process() { if u.halt { log.Println("Payments suspended due to last critical error:", u.lastFail) - os.Exit(1) + os.Exit(1) return } mustPay := 0 @@ -233,7 +233,7 @@ func (u *PayoutsProcessor) process() { break } } - wg.Done() + wg.Done() }(txHash, login, &wg) if waitingCount > u.config.ConcurrentTx { diff --git a/payouts/unlocker.go b/payouts/unlocker.go index 60b06ac..d4d02f7 100644 --- a/payouts/unlocker.go +++ b/payouts/unlocker.go @@ -3,8 +3,8 @@ package payouts import ( "fmt" "log" - "os" "math/big" + "os" "strconv" "strings" "time" @@ -27,14 +27,12 @@ type UnlockerConfig struct { Interval string `json:"interval"` Daemon string `json:"daemon"` Timeout string `json:"timeout"` + Ecip1017FBlock int64 `json:"ecip1017FBlock"` + Ecip1017EraRounds *big.Int `json:"ecip1017EraRounds"` } 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 disinflationRateDivisor = big.NewInt(5) // Disinflation rate divisor for ECIP1017 var big32 = big.NewInt(32) @@ -50,7 +48,16 @@ type BlockUnlocker struct { lastFail error } -func NewBlockUnlocker(cfg *UnlockerConfig, backend *storage.RedisClient) *BlockUnlocker { +func NewBlockUnlocker(cfg *UnlockerConfig, backend *storage.RedisClient, network *string) *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) { log.Fatalln("Invalid poolFeeAddress", cfg.PoolFeeAddress) @@ -170,7 +177,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) if err != nil { u.halt = true u.lastFail = err @@ -220,7 +227,8 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage return err } candidate.Height = correctHeight - reward := getConstReward(candidate.Height) + era := GetBlockEra(big.NewInt(candidate.Height), u.config.Ecip1017EraRounds) + reward := getConstReward(era) // Add reward for including uncles uncleReward := getRewardForUncle(reward) @@ -244,12 +252,13 @@ 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, cfg *UnlockerConfig) error { uncleHeight, err := strconv.ParseInt(strings.Replace(uncle.Number, "0x", "", -1), 16, 64) if err != nil { return err } - reward := getUncleReward(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), getConstReward(height)) + era := GetBlockEra(big.NewInt(height), cfg.Ecip1017EraRounds) + reward := getUncleReward(new(big.Int).SetInt64(uncleHeight), new(big.Int).SetInt64(height), era, getConstReward(era)) candidate.Height = height candidate.UncleHeight = uncleHeight candidate.Orphan = false @@ -261,7 +270,7 @@ func handleUncle(height int64, uncle *rpc.GetBlockReply, candidate *storage.Bloc func (u *BlockUnlocker) unlockPendingBlocks() { if u.halt { log.Println("Unlocking suspended due to last critical error:", u.lastFail) - os.Exit(1) + os.Exit(1) return } @@ -347,7 +356,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) } @@ -496,9 +505,9 @@ func (u *BlockUnlocker) calculateRewards(block *storage.BlockData) (*big.Rat, *b return revenue, minersProfit, poolProfit, rewards, percents, nil } -func calculateRewardsForShares(shares map[string]int64, total int64, reward *big.Rat)(map[string]int64, map[string]*big.Rat) { +func calculateRewardsForShares(shares map[string]int64, total int64, reward *big.Rat) (map[string]int64, map[string]*big.Rat) { rewards := make(map[string]int64) - percents := make(map[string]*big.Rat) + percents := make(map[string]*big.Rat) for login, n := range shares { percents[login] = big.NewRat(n, total) @@ -560,15 +569,9 @@ func GetBlockEra(blockNum, eraLength *big.Int) *big.Int { return new(big.Int).Sub(d, dremainder) } -func getConstReward(height int64) *big.Int { +func getConstReward(era *big.Int) *big.Int { var blockReward = homesteadReward - var bigHeight = new(big.Int).SetInt64(height) - - // Ensure value 'era' is configured. - era := GetBlockEra(bigHeight, ecip1017EraRounds) wr := GetBlockWinnerRewardByEra(era, blockReward) - // wurs := GetBlockWinnerRewardForUnclesByEra(era, uncles, blockReward) // wurs "winner uncle rewards" - // wr.Add(wr, wurs) return wr } @@ -576,9 +579,7 @@ 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)) } -func getUncleReward(uHeight *big.Int, height *big.Int, reward *big.Int) *big.Int { - // Ensure value 'era' is configured. - era := GetBlockEra(height, ecip1017EraRounds) +func getUncleReward(uHeight *big.Int, height *big.Int, era *big.Int, reward *big.Int) *big.Int { // 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. if era.Cmp(big.NewInt(0)) == 0 { diff --git a/proxy/config.go b/proxy/config.go index 48dc7d1..a52f60c 100644 --- a/proxy/config.go +++ b/proxy/config.go @@ -16,6 +16,7 @@ type Config struct { Threads int `json:"threads"` + Network string `json:"network"` Coin string `json:"coin"` Pplns int64 `json:"pplns"` Redis storage.Config `json:"redis"` diff --git a/proxy/handlers.go b/proxy/handlers.go index 7cbcc0c..103935e 100644 --- a/proxy/handlers.go +++ b/proxy/handlers.go @@ -1,10 +1,10 @@ package proxy import ( + "errors" "log" "regexp" "strings" - "errors" "github.com/yuriy0803/open-etc-pool-friends/rpc" "github.com/yuriy0803/open-etc-pool-friends/util" @@ -91,7 +91,7 @@ func (s *ProxyServer) handleSubmitRPC(cs *Session, login, id string, params []st if !ok { cs.lastErr = errors.New("High rate of invalid shares") } - }(s, cs, login, id, params) + }(s, cs, login, id, params) return true, nil } diff --git a/proxy/miner.go b/proxy/miner.go index 115a0c8..3c0b28e 100644 --- a/proxy/miner.go +++ b/proxy/miner.go @@ -6,14 +6,27 @@ import ( "strconv" "strings" - "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/common" + "github.com/yuriy0803/go-etchash" ) -var hasher = ethash.New() +var ecip1099FBlockClassic uint64 = 11700000 // classic mainnet +var ecip1099FBlockMordor uint64 = 2520000 // mordor -func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, params []string) (bool, bool) { +var hasher *etchash.Etchash = nil +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] hashNoNonce := params[1] mixDigest := params[2]