Skip to content

Commit

Permalink
Add devnet support
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Jan 9, 2020
1 parent 081a7ef commit bb33ce3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
28 changes: 28 additions & 0 deletions p2pool/dash/networks/dash_devnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import platform

from twisted.internet import defer

from .. import data, helper
from p2pool.util import pack


P2P_PREFIX = 'e2caffce'.decode('hex')
P2P_PORT = 19799
ADDRESS_VERSION = 140
SCRIPT_ADDRESS_VERSION = 19
RPC_PORT = 19798
RPC_CHECK = defer.inlineCallbacks(lambda dashd: defer.returnValue(
'== Dash ==' in (yield dashd.rpc_help()) and
(yield dashd.rpc_getblockchaininfo())['chain'] == 'dev'
))
BLOCKHASH_FUNC = lambda data: pack.IntType(256).unpack(__import__('dash_hash').getPoWHash(data))
POW_FUNC = lambda data: pack.IntType(256).unpack(__import__('dash_hash').getPoWHash(data))
BLOCK_PERIOD = 150 # s
SYMBOL = 'tDASH'
CONF_FILE_FUNC = lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'DashCore') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/DashCore/') if platform.system() == 'Darwin' else os.path.expanduser('~/.dashcore'), 'dash.conf')
BLOCK_EXPLORER_URL_PREFIX = 'https://dev.explorer.dash.org/block/' # TODO
ADDRESS_EXPLORER_URL_PREFIX = 'https://dev.explorer.dash.org/address/' # TODO
TX_EXPLORER_URL_PREFIX = 'https://dev.explorer.dash.org/tx/' # TODO
SANE_TARGET_RANGE = (2**256//2**32//1000000 - 1, 2**256//2**20 - 1)
DUST_THRESHOLD = 0.001e8
10 changes: 6 additions & 4 deletions p2pool/dash/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from p2pool.util import deferral, p2protocol, pack, variable

class Protocol(p2protocol.Protocol):
def __init__(self, net):
def __init__(self, net, devnet):
p2protocol.Protocol.__init__(self, net.P2P_PREFIX, 3145728, ignore_trailing_payload=True)
self.net = net
self.devnet = devnet

def connectionMade(self):
self.send_version(
Expand All @@ -33,7 +34,7 @@ def connectionMade(self):
port=self.transport.getHost().port,
),
nonce=random.randrange(2**64),
sub_version_num='/P2Pool:%s/' % (p2pool.__version__,),
sub_version_num='/P2Pool:%s%s/' % (p2pool.__version__, '(devnet=devnet-%s)' % self.devnet if self.devnet is not None else '',),
start_height=0,
)

Expand Down Expand Up @@ -225,16 +226,17 @@ class ClientFactory(protocol.ReconnectingClientFactory):

maxDelay = 1

def __init__(self, net):
def __init__(self, net, devnet):
self.net = net
self.devnet = devnet
self.conn = variable.Variable(None)

self.new_block = variable.Event()
self.new_tx = variable.Event()
self.new_headers = variable.Event()

def buildProtocol(self, addr):
p = self.protocol(self.net)
p = self.protocol(self.net, self.devnet)
p.factory = self
return p

Expand Down
13 changes: 8 additions & 5 deletions p2pool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
def connect_p2p():
# connect to dashd over dash-p2p
print '''Testing dashd P2P connection to '%s:%s'...''' % (args.dashd_address, args.dashd_p2p_port)
factory = dash_p2p.ClientFactory(net.PARENT)
factory = dash_p2p.ClientFactory(net.PARENT, args.devnet)
reactor.connectTCP(args.dashd_address, args.dashd_p2p_port, factory)
def long():
print ''' ...taking a while. Common reasons for this include all of dashd's connection slots being used...'''
Expand All @@ -93,7 +93,7 @@ def long():
print
defer.returnValue(factory)

if args.testnet: # establish p2p connection first if testnet so dashd can work without connections
if args.testnet or args.devnet is not None: # establish p2p connection first if testnet or devnet so dashd can work without connections
factory = yield connect_p2p()

# connect to dashd over JSON-RPC and do initial getmemorypool
Expand All @@ -115,7 +115,7 @@ def poll_warnings():
print ' Current block height: %i' % (temp_work['height'] - 1,)
print

if not args.testnet:
if not args.testnet and args.devnet is None:
factory = yield connect_p2p()

print 'Determining payout address...'
Expand Down Expand Up @@ -482,7 +482,7 @@ def run():
print 'Pausing for 3 seconds...'
time.sleep(3)

realnets = dict((name, net) for name, net in networks.nets.iteritems() if '_testnet' not in name)
realnets = dict((name, net) for name, net in networks.nets.iteritems() if ('_testnet' not in name and '_devnet' not in name))

parser = fixargparse.FixedArgumentParser(description='p2pool (version %s)' % (p2pool.__version__,), fromfile_prefix_chars='@')
parser.add_argument('--version', action='version', version=p2pool.__version__)
Expand All @@ -492,6 +492,9 @@ def run():
parser.add_argument('--testnet',
help='''use the network's testnet''',
action='store_const', const=True, default=False, dest='testnet')
parser.add_argument('--devnet',
help='''use the network's devnet''',
type=str, action='store', default=None, dest='devnet')
parser.add_argument('--debug',
help='enable debugging mode',
action='store_const', const=True, default=False, dest='debug')
Expand Down Expand Up @@ -589,7 +592,7 @@ def run():
else:
p2pool.DEBUG = False

net_name = args.net_name + ('_testnet' if args.testnet else '')
net_name = args.net_name + ('_testnet' if args.testnet else '') + ('_devnet' if args.devnet is not None else '')
net = networks.nets[net_name]

datadir_path = os.path.join((os.path.join(os.path.dirname(sys.argv[0]), 'data') if args.datadir is None else args.datadir), net_name)
Expand Down
19 changes: 19 additions & 0 deletions p2pool/networks/dash_devnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from p2pool.dash import networks

PARENT = networks.nets['dash_devnet']
SHARE_PERIOD = 20 # seconds
CHAIN_LENGTH = 24*60*60//20 # shares
REAL_CHAIN_LENGTH = 24*60*60//20 # shares
TARGET_LOOKBEHIND = 100 # shares //with that the pools share diff is adjusting faster, important if huge hashing power comes to the pool
SPREAD = 10 # blocks
IDENTIFIER = '76deb1e543fe2427'.decode('hex')
PREFIX = '798b644f6821e3b3'.decode('hex')
COINBASEEXT = '0E2F5032506F6F6C2D74444153482F'.decode('hex')
P2P_PORT = 18799
MIN_TARGET = 0
MAX_TARGET = 2**256//2**20 - 1
PERSIST = False
WORKER_PORT = 17703
BOOTSTRAP_ADDRS = ''
ANNOUNCE_CHANNEL = ''
VERSION_CHECK = lambda v: True

0 comments on commit bb33ce3

Please sign in to comment.