Browse Source

Danger

1. make clean all

2. redis-cli -n 0 flushdb
master
yuriy0803 3 years ago
parent
commit
b89def0b16
  1. 2
      Makefile
  2. 6
      proxy/handlers.go
  3. 16
      proxy/miner.go
  4. 21
      storage/redis.go
  5. 2
      www/app/helpers/format-hashrate.js
  6. 1
      www/app/templates/account.hbs
  7. 2
      www/app/templates/blocks/block.hbs
  8. 2
      www/app/templates/blocks/immature.hbs
  9. 2
      www/app/templates/blocks/index.hbs
  10. 2
      www/app/templates/blocks/pending.hbs
  11. 9
      www/app/templates/index.hbs

2
Makefile

@ -15,4 +15,4 @@ test: all
build/env.sh go test -v ./... build/env.sh go test -v ./...
clean: clean:
rm -fr build/_workspace/pkg/ $(GOBIN)/* rm -fr build/_workspace/ $(GOBIN)/*

6
proxy/handlers.go

@ -20,6 +20,7 @@ func (s *ProxyServer) handleLoginRPC(cs *Session, params []string, id string) (b
if len(params) == 0 { if len(params) == 0 {
return false, &ErrorReply{Code: -1, Message: "Invalid params"} return false, &ErrorReply{Code: -1, Message: "Invalid params"}
} }
//If login contain information about workers name "walletId.workerName" //If login contain information about workers name "walletId.workerName"
login := params[0] login := params[0]
if strings.Contains(login, ".") { 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) { if !s.policy.ApplyLoginPolicy(login, cs.ip) {
return false, &ErrorReply{Code: -1, Message: "You are blacklisted"} 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) { if !workerPattern.MatchString(id) {
id = "0" id = "0"

16
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. //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) s.backend.WriteWorkerShareStatus(login, id, false, false, true)
return false, false return false, false
} }
if hasher.Verify(block) { isBlock, _ := hasher.Verify(block)
if isBlock {
ok, err := s.rpc().SubmitBlock(params) ok, err := s.rpc().SubmitBlock(params)
if err != nil { if err != nil {
log.Printf("Block submission failure at height %v for %v: %v", h.height, t.Header, err) 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 return false, false
} else { } else {
s.fetchBlockTemplate() 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 { if exist {
return true, false 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) log.Printf("Block found by miner %v@%v at height %d", login, ip, h.height)
} }
} else { } 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 { if exist {
return true, false return true, false
} }

21
storage/redis.go

@ -77,6 +77,8 @@ type RewardData struct {
type BlockData struct { type BlockData struct {
Login string `json:"login"` Login string `json:"login"`
Worker string `json:"worker"`
ActualDiff int64 `json:"shareDiff"`
Height int64 `json:"height"` Height int64 `json:"height"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
Difficulty int64 `json:"difficulty"` Difficulty int64 `json:"difficulty"`
@ -129,7 +131,7 @@ func (b *BlockData) RoundKey() string {
} }
func (b *BlockData) key() 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 { type Miner struct {
@ -499,7 +501,7 @@ func (r *RedisClient) checkPoWExist(height uint64, params []string) (bool, error
return val == 0, err 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) exist, err := r.checkPoWExist(height, params)
if err != nil { if err != nil {
return false, err return false, err
@ -515,14 +517,14 @@ func (r *RedisClient) WriteShare(login, id string, params []string, diff int64,
ts := ms / 1000 ts := ms / 1000
_, err = tx.Exec(func() error { _, 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) tx.HIncrBy(r.formatKey("stats"), "roundShares", diff)
return nil return nil
}) })
return false, err 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) exist, err := r.checkPoWExist(height, params)
if err != nil { if err != nil {
return false, err return false, err
@ -538,7 +540,7 @@ func (r *RedisClient) WriteBlock(login, id string, params []string, diff, roundD
ts := ms / 1000 ts := ms / 1000
cmds, err := tx.Exec(func() error { 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.HSet(r.formatKey("stats"), "lastBlockFound", strconv.FormatInt(ts, 10))
tx.HDel(r.formatKey("stats"), "roundShares") tx.HDel(r.formatKey("stats"), "roundShares")
tx.HSet(r.formatKey("miners", login), "roundShares", strconv.FormatInt(0, 10)) 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 totalShares += n
} }
hashHex := strings.Join(params, ":") 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}) cmd := r.client.ZAdd(r.formatKey("blocks", "candidates"), redis.Z{Score: float64(height), Member: s})
return false, cmd.Err() 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) times := int(diff / 1000000000)
for i := 0; i < times; i++ { for i := 0; i < times; i++ {
tx.LPush(r.formatKey("lastshares"), login) 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.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.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), "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) { 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.Difficulty, _ = strconv.ParseInt(fields[4], 10, 64)
block.TotalShares, _ = strconv.ParseInt(fields[5], 10, 64) block.TotalShares, _ = strconv.ParseInt(fields[5], 10, 64)
block.Login = fields[6] block.Login = fields[6]
block.ActualDiff, _ = strconv.ParseInt(fields[7], 10, 64)
block.Worker = fields[8]
block.candidateKey = v.Member.(string) block.candidateKey = v.Member.(string)
result = append(result, &block) result = append(result, &block)
} }
@ -1465,6 +1470,8 @@ func convertBlockResults(rows ...*redis.ZSliceCmd) []*BlockData {
block.RewardString = fields[7] block.RewardString = fields[7]
block.ImmatureReward = fields[7] block.ImmatureReward = fields[7]
block.Login = fields[8] block.Login = fields[8]
block.ActualDiff, _ = strconv.ParseInt(fields[9], 10, 64)
block.Worker = fields[10]
block.immatureKey = v.Member.(string) block.immatureKey = v.Member.(string)
result = append(result, &block) result = append(result, &block)
} }

2
www/app/helpers/format-hashrate.js

@ -3,7 +3,7 @@ import Ember from 'ember';
export function formatHashrate(params/*, hash*/) { export function formatHashrate(params/*, hash*/) {
var hashrate = params[0]; var hashrate = params[0];
var i = 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) { while (hashrate > 1000) {
hashrate = hashrate / 1000; hashrate = hashrate / 1000;
i++; i++;

1
www/app/templates/account.hbs

@ -29,6 +29,7 @@
<div style="display: block;"><i class="fa fa-tachometer"></i> Hashrate (30m): <span>{{format-hashrate model.currentHashrate}}</span></div> <div style="display: block;"><i class="fa fa-tachometer"></i> Hashrate (30m): <span>{{format-hashrate model.currentHashrate}}</span></div>
<div style="display: block;"><i class="fa fa-tachometer"></i> Hashrate (3h): <span>{{format-hashrate model.hashrate}}</span></div> <div style="display: block;"><i class="fa fa-tachometer"></i> Hashrate (3h): <span>{{format-hashrate model.hashrate}}</span></div>
<div style="display: block;"><i class="fa fa-gears"></i> Personal Luck: <span>{{format-number PersonalLuck style='percent'}}</span></div> <div style="display: block;"><i class="fa fa-gears"></i> Personal Luck: <span>{{format-number PersonalLuck style='percent'}}</span></div>
<div style="display: block;"><i class="fa fa-gears"></i> Shares found: <span>{{format-hashrate model.stats.lastShareDiff}}</span></div>
</div> </div>
<div class="col-md-4 stats"> <div class="col-md-4 stats">

2
www/app/templates/blocks/block.hbs

@ -37,4 +37,6 @@
<span class="label label-primary">Block</span> <span class="label label-primary">Block</span>
{{/if}} {{/if}}
</td> </td>
<td>{{format-hashrate block.shareDiff}}</td>
<td>{{block.worker}}</td>
</tr> </tr>

2
www/app/templates/blocks/immature.hbs

@ -10,6 +10,8 @@
<th>Variance</th> <th>Variance</th>
<th>Reward</th> <th>Reward</th>
<th>Type</th> <th>Type</th>
<th>Shares/Diff</th>
<th>Worker ID</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

2
www/app/templates/blocks/index.hbs

@ -10,6 +10,8 @@
<th>Variance</th> <th>Variance</th>
<th>Reward</th> <th>Reward</th>
<th>Type</th> <th>Type</th>
<th>Shares/Diff</th>
<th>Worker ID</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

2
www/app/templates/blocks/pending.hbs

@ -8,6 +8,7 @@
<th>Login</th> <th>Login</th>
<th>Time Found</th> <th>Time Found</th>
<th>Variance</th> <th>Variance</th>
<th>Shares/Diff</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -23,6 +24,7 @@
<span class="label label-info">{{format-number block.variance style='percent'}}</span> <span class="label label-info">{{format-number block.variance style='percent'}}</span>
{{/if}} {{/if}}
</td> </td>
<td>{{format-hashrate block.shareDiff}}</td>
</tr> </tr>
{{/each}} {{/each}}
</tbody> </tbody>

9
www/app/templates/index.hbs

@ -54,7 +54,14 @@
<div class="container"> <div class="container">
{{high-charts mode=mode chartOptions=chartDiff content=chartData}} {{high-charts mode=mode chartOptions=chartDiff content=chartData}}
</div> </div>
{{#if (equals config.Network 'mordor')}}
<div class="bs-callout bs-callout-danger">
<h4>
Warning
</h4>
<p>This is an experimental pool running on the <strong>Mordor</strong> testnet! All mined coins are for testing purposes only.</p>
</div>
{{/if}}
<div class="jumbotron"> <div class="jumbotron">
<div class="container"> <div class="container">
<h3 class="text-center" style="padding: 0 0 5px 0; margin: 0 0 40px 0;"> Instructions</h3> <h3 class="text-center" style="padding: 0 0 5px 0; margin: 0 0 40px 0;"> Instructions</h3>

Loading…
Cancel
Save