Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4324925782 | ||
|
|
a98fbf6057 | ||
|
|
faebf8b2f7 |
@ -181,13 +181,15 @@ WORKER_BAN_TIME = 300 # How long we temporarily ban worker
|
||||
INVALID_SHARES_PERCENT = 50 # Allow average invalid shares vary this % before we ban
|
||||
|
||||
# ******************** E-Mail Notification Settings *********************
|
||||
NOTIFY_EMAIL_TO = '' # Where to send Start/Found block notifications
|
||||
NOTIFY_EMAIL_TO_DEADMINER = '' # Where to send dead miner notifications
|
||||
NOTIFY_ADMIN = 'admin@domain.com'
|
||||
NOTIFY_EMAIL_FROM = 'root@localhost' # Sender address
|
||||
NOTIFY_EMAIL_SERVER = 'localhost' # E-Mail Sender
|
||||
NOTIFY_EMAIL_USERNAME = '' # E-Mail server SMTP Logon
|
||||
NOTIFY_EMAIL_PASSWORD = ''
|
||||
NOTIFY_EMAIL_USETLS = True
|
||||
NOTIFY_EMAIL_SERVER = 'localhost' # SMTP Server
|
||||
NOTIFY_EMAIL_SERVER_PORT = '587' # SMTP Port
|
||||
NOTIFY_EMAIL_USERNAME = '' # SMTP Login
|
||||
NOTIFY_EMAIL_PASSWORD = '' # SMTP Password
|
||||
NOTIFY_EMAIL_USETLS = True # WIP
|
||||
NOTIFY_DEADMINER_INTERVAL = 600 # Notify Dead Miners every x seconds
|
||||
NOTIFY_MAX_EMAILS = 10 # Max emails sent per user
|
||||
|
||||
#### Memcache ####
|
||||
# Memcahce is a requirement. Enter the settings below
|
||||
@ -196,3 +198,9 @@ MEMCACHE_PORT = 11211 # Port
|
||||
MEMCACHE_TIMEOUT = 900 # Key timeout
|
||||
MEMCACHE_PREFIX = "stratum_" # Prefix for keys
|
||||
|
||||
######## IRC BOT ##################
|
||||
BOT_ENABLED = True
|
||||
BOT_NETWORK = "irc.freenode.net"
|
||||
BOT_PORT = 6667
|
||||
BOT_NICK = "StratumBot"
|
||||
BOT_CHANNEL = "#cryptopools"
|
||||
|
||||
63
lib/ircbot.py
Normal file
63
lib/ircbot.py
Normal file
@ -0,0 +1,63 @@
|
||||
import base64
|
||||
import gc
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
import signal
|
||||
import traceback
|
||||
import urlparse
|
||||
import twisted
|
||||
import settings
|
||||
#if settings.BOT_ENABLED:
|
||||
from twisted.words.protocols import irc
|
||||
class IRCClient(irc.IRCClient):
|
||||
nickname = settings.BOT_NICK
|
||||
channel = settings.BOT_CHANNEL
|
||||
|
||||
def lineReceived(self, line):
|
||||
log.debug(line)
|
||||
irc.IRCClient.lineReceived(self, line)
|
||||
|
||||
def signedOn(self):
|
||||
self.in_channel = False
|
||||
irc.IRCClient.signedOn(self)
|
||||
self.factory.resetDelay()
|
||||
self.join(self.channel)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def new_share(share):
|
||||
if not self.in_channel:
|
||||
return
|
||||
if share.pow_hash <= share.header['bits'].target and abs(share.timestamp - time.time()) < 10*60:
|
||||
yield deferral.sleep(random.expovariate(1/60))
|
||||
message = '\x02%s BLOCK FOUND by %s! %s%064x' % (net.NAME.upper(), bitcoin_data.script2_to_address(share.new_script, net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
|
||||
if all('%x' % (share.header_hash,) not in old_message for old_message in self.recent_messages):
|
||||
self.say(self.channel, message)
|
||||
self._remember_message(message)
|
||||
self.watch_id = node.tracker.verified.added.watch(new_share)
|
||||
self.recent_messages = []
|
||||
|
||||
def joined(self, channel):
|
||||
self.in_channel = True
|
||||
|
||||
def left(self, channel):
|
||||
self.in_channel = False
|
||||
|
||||
def _remember_message(self, message):
|
||||
self.recent_messages.append(message)
|
||||
while len(self.recent_messages) > 100:
|
||||
self.recent_messages.pop(0)
|
||||
|
||||
def privmsg(self, user, channel, message):
|
||||
if channel == self.channel:
|
||||
self._remember_message(message)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
node.tracker.verified.added.unwatch(self.watch_id)
|
||||
print 'IRC connection lost:', reason.getErrorMessage()
|
||||
|
||||
class IRCClientFactory(protocol.ReconnectingClientFactory):
|
||||
protocol = IRCClient
|
||||
reactor.connectTCP(settings.BOT_NETWORK,settings.BOT_PORT, IRCClientFactory())
|
||||
@ -5,7 +5,7 @@ import Queue
|
||||
import signal
|
||||
import Cache
|
||||
from sets import Set
|
||||
|
||||
import notify_email
|
||||
import lib.settings as settings
|
||||
|
||||
import lib.logger
|
||||
@ -17,18 +17,17 @@ class DBInterface():
|
||||
|
||||
def init_main(self):
|
||||
self.dbi.check_tables()
|
||||
|
||||
self.q = Queue.Queue()
|
||||
self.queueclock = None
|
||||
|
||||
self.cache = Cache.Cache()
|
||||
|
||||
self.email = notify_email.NOTIFY_EMAIL()
|
||||
self.nextStatsUpdate = 0
|
||||
|
||||
self.scheduleImport()
|
||||
|
||||
self.next_force_import_time = time.time() + settings.DB_LOADER_FORCE_TIME
|
||||
|
||||
self.next_force_notify_time = time.time() + settings.NOTIFY_DEADMINER_INTERVAL
|
||||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
|
||||
def signal_handler(self, signal, frame):
|
||||
|
||||
@ -80,7 +80,11 @@ class ShareManagerInterface(object):
|
||||
dbi.queue_share([worker_name, block_header, block_hash, difficulty, timestamp, is_valid, ip, self.block_height, self.prev_hash,
|
||||
invalid_reason, share_diff ])
|
||||
|
||||
def on_submit_block(self, is_accepted, worker_name, block_header, block_hash, timestamp, ip, share_diff):
|
||||
def on_submit_block(self, on_submit, worker_name, block_header, block_hash, timestamp, ip, share_diff):
|
||||
(is_accepted, valid_hash) = on_submit
|
||||
if (settings.SOLUTION_BLOCK_HASH):
|
||||
block_hash = valid_hash
|
||||
|
||||
log.info("Block %s %s" % (block_hash, 'ACCEPTED' if is_accepted else 'REJECTED'))
|
||||
dbi.found_block([worker_name, block_header, block_hash, -1, timestamp, is_accepted, ip, self.block_height, self.prev_hash, share_diff ])
|
||||
|
||||
|
||||
55
mining/notify_email.py
Normal file
55
mining/notify_email.py
Normal file
@ -0,0 +1,55 @@
|
||||
import os
|
||||
import smtplib
|
||||
import time
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from stratum import settings
|
||||
|
||||
import stratum.logger
|
||||
log = stratum.logger.get_logger('Notify_Email')
|
||||
|
||||
class NOTIFY_EMAIL():
|
||||
|
||||
def notify_start(self):
|
||||
subject = (' Stratum ALERT: Stratum started!')
|
||||
text = ('Stratum service has started!')
|
||||
message = MIMEText(text, 'plain')
|
||||
self.send_email(settings.NOTIFY_ADMIN,subject,message)
|
||||
|
||||
def notify_found_block(self,worker_name):
|
||||
subject = (' Stratum ALERT: Found Block by ' % worker_name)
|
||||
text = ('%s on Stratum server found a block!' % worker_name)
|
||||
message = MIMEText(text, 'plain')
|
||||
self.send_email(settings.NOTIFY_ADMIN,subject,message)
|
||||
|
||||
def notify_dead_coindaemon(self,worker_name):
|
||||
subject = (' Stratum ALERT: Stratum down!')
|
||||
text = ('Stratum is down!')
|
||||
message = MIMEText(text, 'plain')
|
||||
self.send_email(settings.NOTIFY_ADMIN,subject,message)
|
||||
|
||||
def notify_dead_miner(self,username,email):
|
||||
log.info("Attempting to send email to: %s" % username)
|
||||
subject = (' Stratum ALERT: ' + username + ' not authenticating properly!')
|
||||
text = (' Youre Miner is not authorising With Stratum correctly. please recheck youre worker details and retry')
|
||||
message = MIMEText(text, 'html')
|
||||
self.send_email(email,subject,message)
|
||||
log.info("Sent to %s" % email)
|
||||
|
||||
def send_email(self,to,subject,message):
|
||||
log.info("Send attempt to %s" % to)
|
||||
|
||||
msg = MIMEMultipart('alternative')
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = settings.NOTIFY_EMAIL_FROM
|
||||
msg['To'] = to
|
||||
msg.attach(message)
|
||||
try:
|
||||
s = smtplib.SMTP(settings.NOTIFY_EMAIL_SERVER,settings.NOTIFY_EMAIL_SERVER_PORT)
|
||||
s.login(settings.NOTIFY_EMAIL_USERNAME,settings.NOTIFY_EMAIL_PASSWORD)
|
||||
s.sendmail(msg['From'], msg['To'], msg.as_string())
|
||||
s.quit()
|
||||
except smtplib.SMTPAuthenticationError as e:
|
||||
log.error('Error sending Email: %s' % e[1])
|
||||
except Exception as e:
|
||||
log.error('Error sending Email: %s' % e[0])
|
||||
Loading…
Reference in New Issue
Block a user