Skip to content

Commit bb33ce3

Browse files
committed
Add devnet support
1 parent 081a7ef commit bb33ce3

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import platform
3+
4+
from twisted.internet import defer
5+
6+
from .. import data, helper
7+
from p2pool.util import pack
8+
9+
10+
P2P_PREFIX = 'e2caffce'.decode('hex')
11+
P2P_PORT = 19799
12+
ADDRESS_VERSION = 140
13+
SCRIPT_ADDRESS_VERSION = 19
14+
RPC_PORT = 19798
15+
RPC_CHECK = defer.inlineCallbacks(lambda dashd: defer.returnValue(
16+
'== Dash ==' in (yield dashd.rpc_help()) and
17+
(yield dashd.rpc_getblockchaininfo())['chain'] == 'dev'
18+
))
19+
BLOCKHASH_FUNC = lambda data: pack.IntType(256).unpack(__import__('dash_hash').getPoWHash(data))
20+
POW_FUNC = lambda data: pack.IntType(256).unpack(__import__('dash_hash').getPoWHash(data))
21+
BLOCK_PERIOD = 150 # s
22+
SYMBOL = 'tDASH'
23+
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')
24+
BLOCK_EXPLORER_URL_PREFIX = 'https://dev.explorer.dash.org/block/' # TODO
25+
ADDRESS_EXPLORER_URL_PREFIX = 'https://dev.explorer.dash.org/address/' # TODO
26+
TX_EXPLORER_URL_PREFIX = 'https://dev.explorer.dash.org/tx/' # TODO
27+
SANE_TARGET_RANGE = (2**256//2**32//1000000 - 1, 2**256//2**20 - 1)
28+
DUST_THRESHOLD = 0.001e8

p2pool/dash/p2p.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from p2pool.util import deferral, p2protocol, pack, variable
1414

1515
class Protocol(p2protocol.Protocol):
16-
def __init__(self, net):
16+
def __init__(self, net, devnet):
1717
p2protocol.Protocol.__init__(self, net.P2P_PREFIX, 3145728, ignore_trailing_payload=True)
1818
self.net = net
19+
self.devnet = devnet
1920

2021
def connectionMade(self):
2122
self.send_version(
@@ -33,7 +34,7 @@ def connectionMade(self):
3334
port=self.transport.getHost().port,
3435
),
3536
nonce=random.randrange(2**64),
36-
sub_version_num='/P2Pool:%s/' % (p2pool.__version__,),
37+
sub_version_num='/P2Pool:%s%s/' % (p2pool.__version__, '(devnet=devnet-%s)' % self.devnet if self.devnet is not None else '',),
3738
start_height=0,
3839
)
3940

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

226227
maxDelay = 1
227228

228-
def __init__(self, net):
229+
def __init__(self, net, devnet):
229230
self.net = net
231+
self.devnet = devnet
230232
self.conn = variable.Variable(None)
231233

232234
self.new_block = variable.Event()
233235
self.new_tx = variable.Event()
234236
self.new_headers = variable.Event()
235237

236238
def buildProtocol(self, addr):
237-
p = self.protocol(self.net)
239+
p = self.protocol(self.net, self.devnet)
238240
p.factory = self
239241
return p
240242

p2pool/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
8282
def connect_p2p():
8383
# connect to dashd over dash-p2p
8484
print '''Testing dashd P2P connection to '%s:%s'...''' % (args.dashd_address, args.dashd_p2p_port)
85-
factory = dash_p2p.ClientFactory(net.PARENT)
85+
factory = dash_p2p.ClientFactory(net.PARENT, args.devnet)
8686
reactor.connectTCP(args.dashd_address, args.dashd_p2p_port, factory)
8787
def long():
8888
print ''' ...taking a while. Common reasons for this include all of dashd's connection slots being used...'''
@@ -93,7 +93,7 @@ def long():
9393
print
9494
defer.returnValue(factory)
9595

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

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

118-
if not args.testnet:
118+
if not args.testnet and args.devnet is None:
119119
factory = yield connect_p2p()
120120

121121
print 'Determining payout address...'
@@ -482,7 +482,7 @@ def run():
482482
print 'Pausing for 3 seconds...'
483483
time.sleep(3)
484484

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

487487
parser = fixargparse.FixedArgumentParser(description='p2pool (version %s)' % (p2pool.__version__,), fromfile_prefix_chars='@')
488488
parser.add_argument('--version', action='version', version=p2pool.__version__)
@@ -492,6 +492,9 @@ def run():
492492
parser.add_argument('--testnet',
493493
help='''use the network's testnet''',
494494
action='store_const', const=True, default=False, dest='testnet')
495+
parser.add_argument('--devnet',
496+
help='''use the network's devnet''',
497+
type=str, action='store', default=None, dest='devnet')
495498
parser.add_argument('--debug',
496499
help='enable debugging mode',
497500
action='store_const', const=True, default=False, dest='debug')
@@ -589,7 +592,7 @@ def run():
589592
else:
590593
p2pool.DEBUG = False
591594

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

595598
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)

p2pool/networks/dash_devnet.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from p2pool.dash import networks
2+
3+
PARENT = networks.nets['dash_devnet']
4+
SHARE_PERIOD = 20 # seconds
5+
CHAIN_LENGTH = 24*60*60//20 # shares
6+
REAL_CHAIN_LENGTH = 24*60*60//20 # shares
7+
TARGET_LOOKBEHIND = 100 # shares //with that the pools share diff is adjusting faster, important if huge hashing power comes to the pool
8+
SPREAD = 10 # blocks
9+
IDENTIFIER = '76deb1e543fe2427'.decode('hex')
10+
PREFIX = '798b644f6821e3b3'.decode('hex')
11+
COINBASEEXT = '0E2F5032506F6F6C2D74444153482F'.decode('hex')
12+
P2P_PORT = 18799
13+
MIN_TARGET = 0
14+
MAX_TARGET = 2**256//2**20 - 1
15+
PERSIST = False
16+
WORKER_PORT = 17703
17+
BOOTSTRAP_ADDRS = ''
18+
ANNOUNCE_CHANNEL = ''
19+
VERSION_CHECK = lambda v: True

0 commit comments

Comments
 (0)