diff --git a/proxy/handlers.go b/proxy/handlers.go index 05874f8..9cc031c 100644 --- a/proxy/handlers.go +++ b/proxy/handlers.go @@ -1,6 +1,7 @@ package proxy import ( + "errors" "log" "regexp" "strings" @@ -21,6 +22,8 @@ func (s *ProxyServer) handleLoginRPC(cs *Session, params []string, id string) (b } login := strings.ToLower(params[0]) + login = strings.Split(login, ".")[0] + if !util.IsValidHexAddress(login) { return false, &ErrorReply{Code: -1, Message: "Invalid login"} } @@ -68,33 +71,36 @@ 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"} } - t := s.currentBlockTemplate() - exist, validShare := s.processShare(login, id, cs.ip, t, params) - ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare) + 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) - return false, &ErrorReply{Code: 22, Message: "Duplicate share"} - } + 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 { - return false, &ErrorReply{Code: 23, Message: "Invalid 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") + } } - return false, nil - } - if s.config.Proxy.Debug { - log.Printf("Valid share from %s@%s", login, cs.ip) - } + if s.config.Proxy.Debug { + log.Printf("Valid share from %s@%s", login, cs.ip) + } + + if !ok { + cs.lastErr = errors.New("High rate of invalid shares") + } + }(s, cs, login, id, params) - 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 diff --git a/proxy/miner.go b/proxy/miner.go index 5a2e1a5..2096a68 100644 --- a/proxy/miner.go +++ b/proxy/miner.go @@ -6,8 +6,8 @@ import ( "strconv" "strings" - "github.com/yuriy0803/poolhash" "github.com/ethereum/go-ethereum/common" + "github.com/yuriy0803/etchash" ) var ( @@ -19,6 +19,7 @@ var ( ) 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, nil) @@ -34,6 +35,7 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param return false, false } } + nonceHex := params[0] hashNoNonce := params[1] mixDigest := params[2] diff --git a/proxy/proxy.go b/proxy/proxy.go index b0f606d..412fb6e 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -43,8 +43,9 @@ type Session struct { // Stratum sync.Mutex - conn net.Conn - login string + conn net.Conn + login string + lastErr error } func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer { diff --git a/proxy/stratum.go b/proxy/stratum.go index c6568c7..6a77670 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -66,7 +66,7 @@ func (s *ProxyServer) ListenTCP() { accept <- n go func(cs *Session) { err = s.handleTCPClient(cs) - if err != nil { + if err != nil || cs.lastErr != nil { s.removeSession(cs) conn.Close() } @@ -222,7 +222,7 @@ func (s *ProxyServer) broadcastNewJobs() { go func(cs *Session) { err := cs.pushNewJob(&reply) <-bcast - if err != nil { + if err != nil || cs.lastErr != nil { log.Printf("Job transmit error to %v@%v: %v", cs.login, cs.ip, err) s.removeSession(cs) } else { diff --git a/www/app/controllers/account/payouts.js b/www/app/controllers/account/payouts.js index 8855053..4f3df5f 100644 --- a/www/app/controllers/account/payouts.js +++ b/www/app/controllers/account/payouts.js @@ -3,6 +3,7 @@ import Ember from 'ember'; export default Ember.Controller.extend({ applicationController: Ember.inject.controller('application'), stats: Ember.computed.reads('applicationController.model.stats'), + config: Ember.computed.reads('applicationController.config'), intl: Ember.inject.service(), chartPaymentText: Ember.computed('model', { @@ -64,7 +65,7 @@ export default Ember.Controller.extend({ }, tooltip: { formatter: function() { - return "" + Highcharts.dateFormat('%Y-%m-%d', new Date(this.x)) + "
Payment " + this.y.toFixed(8) + " ESN"; + return "" + Highcharts.dateFormat('%d-%m-%Y', new Date(this.x)) + "
Payment " + this.y.toFixed(8) + "
" + e.get('config.Unit'); }, useHTML: true }, diff --git a/www/config/environment.js b/www/config/environment.js index 9109053..a6d814f 100644 --- a/www/config/environment.js +++ b/www/config/environment.js @@ -27,6 +27,7 @@ module.exports = function(environment) { // The ETC network used (classic, mordor) Network: 'classic', + Unit: 'ETC', // Fee and payout details PoolFee: '1%',