Browse Source

update

master
yuriy0803 3 years ago
parent
commit
ae1acb3512
  1. 8
      payouts/unlocker.go
  2. 41
      proxy/handlers.go
  3. 37
      proxy/proxy.go
  4. 2
      proxy/stratum.go
  5. 1
      rpc/rpc.go
  6. 3
      storage/redis.go
  7. 15
      www/app/controllers/application.js

8
payouts/unlocker.go

@ -669,10 +669,10 @@ func getConstRewardUbiq(height int64) *big.Int {
reward = big.NewInt(4e+18)
// Year 4
}
// If Orion use new MP
if headerNumber.Cmp(big.NewInt(1791793)) >= 0 {
reward = big.NewInt(15e+17)
}
// If Orion use new MP
if headerNumber.Cmp(big.NewInt(1791793)) >= 0 {
reward = big.NewInt(15e+17)
}
return reward
}

41
proxy/handlers.go

@ -1,7 +1,6 @@
package proxy
import (
"errors"
"log"
"regexp"
"strings"
@ -69,36 +68,30 @@ func (s *ProxyServer) handleSubmitRPC(cs *Session, login, id string, params []st
log.Printf("Malformed PoW result from %s@%s %v", login, cs.ip, params)
return false, &ErrorReply{Code: -1, Message: "Malformed PoW result"}
}
go func(s *ProxyServer, cs *Session, login, id string, params []string) {
t := s.currentBlockTemplate()
exist, validShare := s.processShare(login, id, cs.ip, t, params)
ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare)
if exist {
log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params)
cs.lastErr = errors.New("Duplicate share")
}
if !validShare {
log.Printf("Invalid share from %s@%s", login, cs.ip)
// Bad shares limit reached, return error and close
if !ok {
cs.lastErr = errors.New("Invalid share")
}
}
t := s.currentBlockTemplate()
exist, validShare := s.processShare(login, id, cs.ip, t, params)
ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare)
if s.config.Proxy.Debug {
log.Printf("Valid share from %s@%s", login, cs.ip)
}
if exist {
log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params)
return false, &ErrorReply{Code: 22, Message: "Duplicate share"}
}
if !validShare {
log.Printf("Invalid share from %s@%s", login, cs.ip)
// Bad shares limit reached, return error and close
if !ok {
cs.lastErr = errors.New("High rate of invalid shares")
return false, &ErrorReply{Code: 23, Message: "Invalid share"}
}
}(s, cs, login, id, params)
return false, nil
}
log.Printf("Valid share from %s@%s", login, cs.ip)
if !ok {
return true, &ErrorReply{Code: -1, Message: "High rate of invalid shares"}
}
return true, nil
}
func (s *ProxyServer) handleGetBlockByNumberRPC() *rpc.GetBlockReplyPart {
t := s.currentBlockTemplate()
var reply *rpc.GetBlockReplyPart

37
proxy/proxy.go

@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
"strconv"
"strings"
"sync"
"sync/atomic"
@ -42,9 +43,8 @@ type Session struct {
// Stratum
sync.Mutex
conn net.Conn
login string
lastErr error
conn net.Conn
login string
}
func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer {
@ -108,12 +108,33 @@ func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer {
case <-stateUpdateTimer.C:
t := proxy.currentBlockTemplate()
if t != nil {
err := backend.WriteNodeState(cfg.Name, t.Height, t.Difficulty)
if err != nil {
log.Printf("Failed to write node state to backend: %v", err)
proxy.markSick()
rpc := proxy.rpc()
// get the latest block height
height := int64(t.Height) - 1
block, _ := rpc.GetBlockByHeight(height)
timestamp, _ := strconv.ParseInt(strings.Replace(block.Timestamp, "0x", "", -1), 16, 64)
prev := height - 100
if prev < 0 {
prev = 0
}
n := height - prev
if n > 0 {
prevblock, err := rpc.GetBlockByHeight(prev)
if err != nil || prevblock == nil {
log.Fatalf("Error while retrieving block from node: %v", err)
} else {
prevtime, _ := strconv.ParseInt(strings.Replace(prevblock.Timestamp, "0x", "", -1), 16, 64)
blocktime := float64(timestamp-prevtime) / float64(n)
err = backend.WriteNodeState(cfg.Name, t.Height, t.Difficulty, blocktime)
if err != nil {
log.Printf("Failed to write node state to backend: %v", err)
proxy.markSick()
} else {
proxy.markOk()
}
}
} else {
proxy.markOk()
proxy.markSick()
}
}
stateUpdateTimer.Reset(stateUpdateIntv)

2
proxy/stratum.go

@ -66,7 +66,7 @@ func (s *ProxyServer) ListenTCP() {
accept <- n
go func(cs *Session) {
err = s.handleTCPClient(cs)
if err != nil || cs.lastErr != nil {
if err != nil {
s.removeSession(cs)
conn.Close()
}

1
rpc/rpc.go

@ -35,6 +35,7 @@ type GetBlockReply struct {
Difficulty string `json:"difficulty"`
GasLimit string `json:"gasLimit"`
GasUsed string `json:"gasUsed"`
Timestamp string `json:"timestamp"`
Transactions []Tx `json:"transactions"`
Uncles []string `json:"uncles"`
// https://github.com/ethereum/EIPs/issues/95

3
storage/redis.go

@ -450,7 +450,7 @@ func (r *RedisClient) GetPaymentCharts(login string) (stats []*PaymentCharts, er
return stats, nil
}
func (r *RedisClient) WriteNodeState(id string, height uint64, diff *big.Int) error {
func (r *RedisClient) WriteNodeState(id string, height uint64, diff *big.Int, blocktime float64) error {
tx := r.client.Multi()
defer tx.Close()
@ -461,6 +461,7 @@ func (r *RedisClient) WriteNodeState(id string, height uint64, diff *big.Int) er
tx.HSet(r.formatKey("nodes"), join(id, "height"), strconv.FormatUint(height, 10))
tx.HSet(r.formatKey("nodes"), join(id, "difficulty"), diff.String())
tx.HSet(r.formatKey("nodes"), join(id, "lastBeat"), strconv.FormatInt(now, 10))
tx.HSet(r.formatKey("nodes"), join(id, "blocktime"), strconv.FormatFloat(blocktime, 'f', 4, 64))
return nil
})
return err

15
www/app/controllers/application.js

@ -43,10 +43,21 @@ export default Ember.Controller.extend({
return parseFloat(this.get('model.exchangedata.current_price'));
}
}),
blockTime: Ember.computed('model.nodes', {
get() {
var node = this.get('bestNode');
if (node && node.blocktime) {
return node.blocktime;
}
return config.APP.BlockTime;
}
}),
hashrate: Ember.computed('difficulty', {
get() {
return this.getWithDefault('difficulty', 0) / config.APP.BlockTime;
var blockTime = this.get('blockTime');
return this.getWithDefault('difficulty', 0) / blockTime;
}
}),
@ -89,7 +100,7 @@ export default Ember.Controller.extend({
nextEpoch: Ember.computed('height', {
get() {
var epochOffset = (60000 - (this.getWithDefault('height', 1) % 60000)) * 1000 * this.get('config').BlockTime;
var epochOffset = (60000 - (this.getWithDefault('height', 1) % 60000)) * 1000 * this.get('blockTime');
return Date.now() + epochOffset;
}
})

Loading…
Cancel
Save