From b89def0b16e3d3ea6dfb45b0b3225a0388ca81dd Mon Sep 17 00:00:00 2001 From: yuriy0803 Date: Sun, 28 Aug 2022 21:31:18 +0200 Subject: [PATCH] Danger 1. make clean all 2. redis-cli -n 0 flushdb --- Makefile | 2 +- proxy/handlers.go | 6 +----- proxy/miner.go | 16 ++++++++++++---- storage/redis.go | 21 ++++++++++++++------- www/app/helpers/format-hashrate.js | 2 +- www/app/templates/account.hbs | 1 + www/app/templates/blocks/block.hbs | 2 ++ www/app/templates/blocks/immature.hbs | 2 ++ www/app/templates/blocks/index.hbs | 2 ++ www/app/templates/blocks/pending.hbs | 2 ++ www/app/templates/index.hbs | 9 ++++++++- 11 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 88aea63..349fd75 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ test: all build/env.sh go test -v ./... clean: - rm -fr build/_workspace/pkg/ $(GOBIN)/* + rm -fr build/_workspace/ $(GOBIN)/* diff --git a/proxy/handlers.go b/proxy/handlers.go index dce1d50..6c3fbcd 100644 --- a/proxy/handlers.go +++ b/proxy/handlers.go @@ -20,6 +20,7 @@ func (s *ProxyServer) handleLoginRPC(cs *Session, params []string, id string) (b if len(params) == 0 { return false, &ErrorReply{Code: -1, Message: "Invalid params"} } + //If login contain information about workers name "walletId.workerName" login := params[0] if strings.Contains(login, ".") { @@ -36,11 +37,6 @@ func (s *ProxyServer) handleLoginRPC(cs *Session, params []string, id string) (b if !s.policy.ApplyLoginPolicy(login, cs.ip) { return false, &ErrorReply{Code: -1, Message: "You are blacklisted"} } - //save for later, too broad right now, bans the ip the wallet comes from, (bad if more then one miner proxies there) - // if !s.policy.ApplyLoginWalletPolicy(login) { - // // check to see if this wallet login is blocked in json file - // return false, &ErrorReply{Code: -1, Message: "You are blacklisted"} - // } if !workerPattern.MatchString(id) { id = "0" diff --git a/proxy/miner.go b/proxy/miner.go index 50ecc5f..3e47a9d 100644 --- a/proxy/miner.go +++ b/proxy/miner.go @@ -74,12 +74,20 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param //return codes need work here, a lot of it. } - if !hasher.Verify(share) { + isShare, actualDiff := hasher.Verify(share) + + if s.config.Proxy.Debug { + log.Printf("Difficulty pool Port/Shares found/Block difficulty = %d / %d / %d from %v@%v", shareDiff, actualDiff, t.Difficulty, login, ip) + } + + if !isShare { s.backend.WriteWorkerShareStatus(login, id, false, false, true) return false, false } - if hasher.Verify(block) { + isBlock, _ := hasher.Verify(block) + + if isBlock { ok, err := s.rpc().SubmitBlock(params) if err != nil { log.Printf("Block submission failure at height %v for %v: %v", h.height, t.Header, err) @@ -88,7 +96,7 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param return false, false } else { s.fetchBlockTemplate() - exist, err := s.backend.WriteBlock(login, id, params, shareDiff, h.diff.Int64(), h.height, s.hashrateExpiration) + exist, err := s.backend.WriteBlock(login, id, params, shareDiff, actualDiff, h.diff.Int64(), h.height, s.hashrateExpiration) if exist { return true, false } @@ -100,7 +108,7 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param log.Printf("Block found by miner %v@%v at height %d", login, ip, h.height) } } else { - exist, err := s.backend.WriteShare(login, id, params, shareDiff, h.height, s.hashrateExpiration) + exist, err := s.backend.WriteShare(login, id, params, shareDiff, actualDiff, h.height, s.hashrateExpiration) if exist { return true, false } diff --git a/storage/redis.go b/storage/redis.go index 60d057e..8d761cf 100644 --- a/storage/redis.go +++ b/storage/redis.go @@ -77,6 +77,8 @@ type RewardData struct { type BlockData struct { Login string `json:"login"` + Worker string `json:"worker"` + ActualDiff int64 `json:"shareDiff"` Height int64 `json:"height"` Timestamp int64 `json:"timestamp"` Difficulty int64 `json:"difficulty"` @@ -129,7 +131,7 @@ func (b *BlockData) RoundKey() string { } func (b *BlockData) key() string { - return join(b.UncleHeight, b.Orphan, b.Nonce, b.serializeHash(), b.Timestamp, b.Difficulty, b.TotalShares, b.Reward, b.Login) + return join(b.UncleHeight, b.Orphan, b.Nonce, b.serializeHash(), b.Timestamp, b.Difficulty, b.TotalShares, b.Reward, b.Login, b.ActualDiff, b.Worker) } type Miner struct { @@ -499,7 +501,7 @@ func (r *RedisClient) checkPoWExist(height uint64, params []string) (bool, error return val == 0, err } -func (r *RedisClient) WriteShare(login, id string, params []string, diff int64, height uint64, window time.Duration) (bool, error) { +func (r *RedisClient) WriteShare(login, id string, params []string, diff int64, actualDiff int64, height uint64, window time.Duration) (bool, error) { exist, err := r.checkPoWExist(height, params) if err != nil { return false, err @@ -515,14 +517,14 @@ func (r *RedisClient) WriteShare(login, id string, params []string, diff int64, ts := ms / 1000 _, err = tx.Exec(func() error { - r.writeShare(tx, ms, ts, login, id, diff, window) + r.writeShare(tx, ms, ts, login, id, diff, actualDiff, window) tx.HIncrBy(r.formatKey("stats"), "roundShares", diff) return nil }) return false, err } -func (r *RedisClient) WriteBlock(login, id string, params []string, diff, roundDiff int64, height uint64, window time.Duration) (bool, error) { +func (r *RedisClient) WriteBlock(login, id string, params []string, diff, actualDiff int64, roundDiff int64, height uint64, window time.Duration) (bool, error) { exist, err := r.checkPoWExist(height, params) if err != nil { return false, err @@ -538,7 +540,7 @@ func (r *RedisClient) WriteBlock(login, id string, params []string, diff, roundD ts := ms / 1000 cmds, err := tx.Exec(func() error { - r.writeShare(tx, ms, ts, login, id, diff, window) + r.writeShare(tx, ms, ts, login, id, diff, actualDiff, window) tx.HSet(r.formatKey("stats"), "lastBlockFound", strconv.FormatInt(ts, 10)) tx.HDel(r.formatKey("stats"), "roundShares") tx.HSet(r.formatKey("miners", login), "roundShares", strconv.FormatInt(0, 10)) @@ -581,13 +583,13 @@ func (r *RedisClient) WriteBlock(login, id string, params []string, diff, roundD totalShares += n } hashHex := strings.Join(params, ":") - s := join(hashHex, ts, roundDiff, totalShares, login) + s := join(hashHex, ts, roundDiff, totalShares, login, actualDiff, id) cmd := r.client.ZAdd(r.formatKey("blocks", "candidates"), redis.Z{Score: float64(height), Member: s}) return false, cmd.Err() } } -func (r *RedisClient) writeShare(tx *redis.Multi, ms, ts int64, login, id string, diff int64, expire time.Duration) { +func (r *RedisClient) writeShare(tx *redis.Multi, ms, ts int64, login, id string, diff int64, actualDiff int64, expire time.Duration) { times := int(diff / 1000000000) for i := 0; i < times; i++ { tx.LPush(r.formatKey("lastshares"), login) @@ -599,6 +601,7 @@ func (r *RedisClient) writeShare(tx *redis.Multi, ms, ts int64, login, id string tx.ZAdd(r.formatKey("hashrate", login), redis.Z{Score: float64(ts), Member: join(diff, id, ms)}) tx.Expire(r.formatKey("hashrate", login), expire) // Will delete hashrates for miners that gone tx.HSet(r.formatKey("miners", login), "lastShare", strconv.FormatInt(ts, 10)) + tx.HSet(r.formatKey("miners", login), "lastShareDiff", strconv.FormatInt(actualDiff, 10)) } func (r *RedisClient) WriteBlocksFound(ms, ts int64, login, id, share string, diff int64) { @@ -1419,6 +1422,8 @@ func convertCandidateResults(raw *redis.ZSliceCmd) []*BlockData { block.Difficulty, _ = strconv.ParseInt(fields[4], 10, 64) block.TotalShares, _ = strconv.ParseInt(fields[5], 10, 64) block.Login = fields[6] + block.ActualDiff, _ = strconv.ParseInt(fields[7], 10, 64) + block.Worker = fields[8] block.candidateKey = v.Member.(string) result = append(result, &block) } @@ -1465,6 +1470,8 @@ func convertBlockResults(rows ...*redis.ZSliceCmd) []*BlockData { block.RewardString = fields[7] block.ImmatureReward = fields[7] block.Login = fields[8] + block.ActualDiff, _ = strconv.ParseInt(fields[9], 10, 64) + block.Worker = fields[10] block.immatureKey = v.Member.(string) result = append(result, &block) } diff --git a/www/app/helpers/format-hashrate.js b/www/app/helpers/format-hashrate.js index 73f75c5..11e4524 100644 --- a/www/app/helpers/format-hashrate.js +++ b/www/app/helpers/format-hashrate.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export function formatHashrate(params/*, hash*/) { var hashrate = params[0]; var i = 0; - var units = ['H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s']; + var units = ['H', 'KH', 'MH', 'GH', 'TH', 'PH']; while (hashrate > 1000) { hashrate = hashrate / 1000; i++; diff --git a/www/app/templates/account.hbs b/www/app/templates/account.hbs index b72791a..6b3594a 100644 --- a/www/app/templates/account.hbs +++ b/www/app/templates/account.hbs @@ -29,6 +29,7 @@
Hashrate (30m): {{format-hashrate model.currentHashrate}}
Hashrate (3h): {{format-hashrate model.hashrate}}
Personal Luck: {{format-number PersonalLuck style='percent'}}
+
Shares found: {{format-hashrate model.stats.lastShareDiff}}
diff --git a/www/app/templates/blocks/block.hbs b/www/app/templates/blocks/block.hbs index 3945c25..ac1925a 100644 --- a/www/app/templates/blocks/block.hbs +++ b/www/app/templates/blocks/block.hbs @@ -37,4 +37,6 @@ Block {{/if}} + {{format-hashrate block.shareDiff}} + {{block.worker}} diff --git a/www/app/templates/blocks/immature.hbs b/www/app/templates/blocks/immature.hbs index 2018491..9fd1ec2 100644 --- a/www/app/templates/blocks/immature.hbs +++ b/www/app/templates/blocks/immature.hbs @@ -10,6 +10,8 @@ Variance Reward Type + Shares/Diff + Worker ID diff --git a/www/app/templates/blocks/index.hbs b/www/app/templates/blocks/index.hbs index 69b99d0..622b08d 100644 --- a/www/app/templates/blocks/index.hbs +++ b/www/app/templates/blocks/index.hbs @@ -10,6 +10,8 @@ Variance Reward Type + Shares/Diff + Worker ID diff --git a/www/app/templates/blocks/pending.hbs b/www/app/templates/blocks/pending.hbs index ccd56f9..59b4c2e 100644 --- a/www/app/templates/blocks/pending.hbs +++ b/www/app/templates/blocks/pending.hbs @@ -8,6 +8,7 @@ Login Time Found Variance + Shares/Diff @@ -23,6 +24,7 @@ {{format-number block.variance style='percent'}} {{/if}} + {{format-hashrate block.shareDiff}} {{/each}} diff --git a/www/app/templates/index.hbs b/www/app/templates/index.hbs index a0b4cbd..f6f02b0 100644 --- a/www/app/templates/index.hbs +++ b/www/app/templates/index.hbs @@ -54,7 +54,14 @@
{{high-charts mode=mode chartOptions=chartDiff content=chartData}}
- + {{#if (equals config.Network 'mordor')}} +
+

+ Warning +

+

This is an experimental pool running on the Mordor testnet! All mined coins are for testing purposes only.

+
+ {{/if}}

Instructions