Skip to content

Commit 086f679

Browse files
authored
Merge pull request #3 from GenYuanLian/third-party
Third party
2 parents fdde0e5 + 3f4fae5 commit 086f679

File tree

7 files changed

+343
-265
lines changed

7 files changed

+343
-265
lines changed

.idea/workspace.xml

Lines changed: 274 additions & 242 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

p2pool/bitcoin/networks/bitcoin_testnet.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@
77
from p2pool.util import pack
88

99

10-
P2P_PREFIX = '0b110907'.decode('hex')
10+
# P2P_PREFIX = '0b110907'.decode('hex')
11+
P2P_PREFIX = '0b110902'.decode('hex')
1112
P2P_PORT = 18333
1213
ADDRESS_VERSION = 111
1314
RPC_PORT = 18332
1415
RPC_CHECK = defer.inlineCallbacks(lambda bitcoind: defer.returnValue(
15-
'bitcoinaddress' in (yield bitcoind.rpc_help()) and
16+
# 'bitcoinaddress' in (yield bitcoind.rpc_help()) and
1617
(yield bitcoind.rpc_getblockchaininfo())['chain'] == 'test'
1718
))
1819
SUBSIDY_FUNC = lambda height: 50*100000000 >> (height + 1)//210000
19-
POW_FUNC = data.hash256
20+
# POW_FUNC = data.hash256
21+
POW_FUNC = lambda data: pack.IntType(256).unpack(__import__('Lyra2Z_scrypt').getPoWHash(data))
2022
BLOCK_PERIOD = 600 # s
21-
SYMBOL = 'tBTC'
23+
SYMBOL = 'BSTK'
2224
CONF_FILE_FUNC = lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'Bitcoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/Bitcoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.bitcoin'), 'bitcoin.conf')
2325
BLOCK_EXPLORER_URL_PREFIX = 'http://blockexplorer.com/testnet/block/'
2426
ADDRESS_EXPLORER_URL_PREFIX = 'http://blockexplorer.com/testnet/address/'
2527
TX_EXPLORER_URL_PREFIX = 'http://blockexplorer.com/testnet/tx/'
26-
SANE_TARGET_RANGE = (2**256//2**32//1000 - 1, 2**256//2**32 - 1)
28+
# SANE_TARGET_RANGE = (2**256//2**32//1000 - 1, 2**256//2**32 - 1)
29+
SANE_TARGET_RANGE = (2**256//2**32//1000000 - 1, 2**256//2**28 - 1) #scchain args
2730
DUMB_SCRYPT_DIFF = 1
28-
DUST_THRESHOLD = 1e8
31+
DUST_THRESHOLD = 0.001e8

p2pool/data.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from p2pool.bitcoin import data as bitcoin_data, script, sha256
1313
from p2pool.util import math, forest, pack
1414
from p2pool.bitcoin.data import pubkey_hash_to_script2
15+
from p2pool import global_var
1516

1617
def parse_bip0034(coinbase):
1718
_, opdata = script.parse(coinbase).next()
@@ -65,7 +66,8 @@ def is_segwit_activated(version, net):
6566
return version >= segwit_activation_version and segwit_activation_version > 0
6667

6768
# DONATION_SCRIPT = '4104ffd03de44a6e11b9917f3a29f9443283d9871c9d743ef30d5eddcd37094b64d1b3d8090496b53256786bf5c82932ec23c3b74d9f05a6f95a8b5529352656664bac'.decode('hex')
68-
DONATION_SCRIPT=pubkey_hash_to_script2(974143861276139069219601755531477429285430505615)
69+
DONATION_SCRIPT=pubkey_hash_to_script2(974143861276139069219601755531477429285430505615) #srcchain main
70+
# DONATION_SCRIPT=pubkey_hash_to_script2(519791236046945930428491375523868623218951526243) #srcchain testnet
6971

7072

7173
class BaseShare(object):
@@ -195,10 +197,11 @@ def generate_transaction(cls, tracker, share_data, block_target, desired_timesta
195197
)
196198
assert total_weight == sum(weights.itervalues()) + donation_weight, (total_weight, sum(weights.itervalues()) + donation_weight)
197199

198-
amounts = dict((script, share_data['subsidy']*(179*weight)//(200*total_weight)) for script, weight in weights.iteritems()) # 99.5% goes according to weights prior to this share
200+
amounts = dict((script, share_data['subsidy']*((197-global_var.get_value('reserve_percentage'))*weight)//(200*total_weight)) for script, weight in weights.iteritems()) # 99.5% goes according to weights prior to this share
199201
this_script = bitcoin_data.pubkey_hash_to_script2(share_data['pubkey_hash'])
200202
amounts[this_script] = amounts.get(this_script, 0) + share_data['subsidy']//200 # 0.5% goes to block finder
201-
amounts[DONATION_SCRIPT] = amounts.get(DONATION_SCRIPT, 0) + share_data['subsidy'] - sum(amounts.itervalues()) # all that's left over is the donation weight and some extra satoshis due to rounding
203+
amounts[DONATION_SCRIPT]=amounts.get(DONATION_SCRIPT,0)+share_data['subsidy']//100
204+
amounts[global_var.get_value('script')] = amounts.get(global_var.get_value('script'), 0) + share_data['subsidy'] - sum(amounts.itervalues()) # all that's left over is the donation weight and some extra satoshis due to rounding
202205

203206
if sum(amounts.itervalues()) != share_data['subsidy'] or any(x < 0 for x in amounts.itervalues()):
204207
raise ValueError()

p2pool/global_var.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
def _init(): # 初始化
4+
global _global_dict
5+
_global_dict = {}
6+
7+
8+
def set_value(key, value):
9+
_global_dict[key] = value
10+
11+
12+
def get_value(key, defValue=None):
13+
try:
14+
return _global_dict[key]
15+
except KeyError:
16+
return defValue

p2pool/main.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from util import fixargparse, jsonrpc, variable, deferral, math, logging, switchprotocol
2525
from . import networks, web, work
2626
import p2pool, p2pool.data as p2pool_data, p2pool.node as p2pool_node
27+
import global_var
28+
from p2pool.bitcoin.data import pubkey_hash_to_script2,address_to_pubkey_hash
2729

2830
class keypool():
2931
keys = []
@@ -99,6 +101,7 @@ def long():
99101
url = '%s://%s:%i/' % ('https' if args.bitcoind_rpc_ssl else 'http', args.bitcoind_address, args.bitcoind_rpc_port)
100102
print '''Testing bitcoind RPC connection to '%s' with username '%s'...''' % (url, args.bitcoind_rpc_username)
101103
bitcoind = jsonrpc.HTTPProxy(url, dict(Authorization='Basic ' + base64.b64encode(args.bitcoind_rpc_username + ':' + args.bitcoind_rpc_password)), timeout=30)
104+
print base64.b64encode(args.bitcoind_rpc_username + ':' + args.bitcoind_rpc_password)
102105
yield helper.check(bitcoind, net)
103106
temp_work = yield helper.getwork(bitcoind)
104107

@@ -114,7 +117,7 @@ def poll_warnings():
114117
print ' Current block height: %i' % (temp_work['height'] - 1,)
115118
print ' Current block bits : %s' % (temp_work['bits'],)
116119
print
117-
120+
118121
if not args.testnet:
119122
factory = yield connect_p2p()
120123

@@ -300,7 +303,10 @@ def upnp_thread():
300303

301304
print ' ...success!'
302305
print
303-
306+
307+
print args.reserve_address
308+
print args.reserve_percentage
309+
global_var.set_value('script',pubkey_hash_to_script2(address_to_pubkey_hash(global_var.get_value('reserve_address'),wb.net)))
304310

305311
# done!
306312
print 'Started successfully!'
@@ -511,30 +517,38 @@ def run():
511517
parser.add_argument('--disable-advertise',
512518
help='''don't advertise local IP address as being available for incoming connections. useful for running a dark node, along with multiple -n ADDR's and --outgoing-conns 0''',
513519
action='store_false', default=True, dest='advertise_ip')
520+
521+
parser.add_argument('--reserve-percentage', metavar='RESERVE_PERCENTAGE',
522+
help='the reserve percentage of coinbase for the pool owner',
523+
type=float, action='store', default=0, dest='reserve_percentage')
524+
parser.add_argument('--reserve-address', metavar='RESERVE_ADDRESS',
525+
help='the reserve address of coinbase for the pool owner',
526+
type=str, action='store', default='1R2Y45QymfK3Bg4shM26kuQKWYjQ4iQA8', dest='reserve_address')
527+
514528

515529
worker_group = parser.add_argument_group('worker interface')
516530
worker_group.add_argument('-w', '--worker-port', metavar='PORT or ADDR:PORT',
517531
help='listen on PORT on interface with ADDR for RPC connections from miners (default: all interfaces, %s)' % ', '.join('%s:%i' % (name, net.WORKER_PORT) for name, net in sorted(realnets.items())),
518532
type=str, action='store', default=None, dest='worker_endpoint')
519533
worker_group.add_argument('-f', '--fee', metavar='FEE_PERCENTAGE',
520-
help='''charge workers mining to their own bitcoin address (by setting their miner's username to a bitcoin address) this percentage fee to mine on your p2pool instance. Amount displayed at http://127.0.0.1:WORKER_PORT/fee (default: 0)''',
534+
help='''charge workers mining to their own bitcoin address (by setting their miner's username to a srcchain address) this percentage fee to mine on your p2pool instance. Amount displayed at http://127.0.0.1:WORKER_PORT/fee (default: 0)''',
521535
type=float, action='store', default=0, dest='worker_fee')
522536

523537
bitcoind_group = parser.add_argument_group('bitcoind interface')
524-
bitcoind_group.add_argument('--bitcoind-config-path', metavar='BITCOIND_CONFIG_PATH',
538+
bitcoind_group.add_argument('--srcchaind-config-path', metavar='BITCOIND_CONFIG_PATH',
525539
help='custom configuration file path (when bitcoind -conf option used)',
526540
type=str, action='store', default=None, dest='bitcoind_config_path')
527-
bitcoind_group.add_argument('--bitcoind-address', metavar='BITCOIND_ADDRESS',
541+
bitcoind_group.add_argument('--srcchaind-address', metavar='BITCOIND_ADDRESS',
528542
help='connect to this address (default: 127.0.0.1)',
529543
type=str, action='store', default='127.0.0.1', dest='bitcoind_address')
530-
bitcoind_group.add_argument('--bitcoind-rpc-port', metavar='BITCOIND_RPC_PORT',
531-
help='''connect to JSON-RPC interface at this port (default: %s <read from bitcoin.conf if password not provided>)''' % ', '.join('%s:%i' % (name, net.PARENT.RPC_PORT) for name, net in sorted(realnets.items())),
544+
bitcoind_group.add_argument('--srcchaind-rpc-port', metavar='BITCOIND_RPC_PORT',
545+
help='''connect to JSON-RPC interface at this port (default: %s <read from srcchain.conf if password not provided>)''' % ', '.join('%s:%i' % (name, net.PARENT.RPC_PORT) for name, net in sorted(realnets.items())),
532546
type=int, action='store', default=None, dest='bitcoind_rpc_port')
533-
bitcoind_group.add_argument('--bitcoind-rpc-ssl',
547+
bitcoind_group.add_argument('--srcchaind-rpc-ssl',
534548
help='connect to JSON-RPC interface using SSL',
535549
action='store_true', default=False, dest='bitcoind_rpc_ssl')
536-
bitcoind_group.add_argument('--bitcoind-p2p-port', metavar='BITCOIND_P2P_PORT',
537-
help='''connect to P2P interface at this port (default: %s <read from bitcoin.conf if password not provided>)''' % ', '.join('%s:%i' % (name, net.PARENT.P2P_PORT) for name, net in sorted(realnets.items())),
550+
bitcoind_group.add_argument('--srcchaind-p2p-port', metavar='BITCOIND_P2P_PORT',
551+
help='''connect to P2P interface at this port (default: %s <read from srcchain.conf if password not provided>)''' % ', '.join('%s:%i' % (name, net.PARENT.P2P_PORT) for name, net in sorted(realnets.items())),
538552
type=int, action='store', default=None, dest='bitcoind_p2p_port')
539553
bitcoind_group.add_argument(metavar='BITCOIND_RPCUSERPASS',
540554
help='bitcoind RPC interface username, then password, space-separated (only one being provided will cause the username to default to being empty, and none will cause P2Pool to read them from bitcoin.conf)',
@@ -621,7 +635,17 @@ def run():
621635
parser.error('error parsing address: ' + repr(e))
622636
else:
623637
args.pubkey_hash = None
624-
638+
639+
global_var._init()
640+
if args.reserve_address is not None:
641+
global_var.set_value('reserve_address',args.reserve_address)
642+
else:
643+
global_var.set_value('reserve_address','1R2Y45QymfK3Bg4shM26kuQKWYjQ4iQA8')
644+
if args.reserve_percentage is not None and 1<=args.reserve_percentage<=90:
645+
global_var.set_value('reserve_percentage',args.reserve_percentage*2)
646+
else:
647+
global_var.set_value('reserve_percentage',0)
648+
625649
def separate_url(url):
626650
s = urlparse.urlsplit(url)
627651
if '@' not in s.netloc:

p2pool/networks/bitcoin_testnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
MAX_TARGET = 2**256//2**32 - 1
1414
PERSIST = False
1515
WORKER_PORT = 19332
16-
BOOTSTRAP_ADDRS = 'forre.st vps.forre.st liteco.in 78.158.149.247'.split(' ')
16+
BOOTSTRAP_ADDRS = ''
1717
ANNOUNCE_CHANNEL = '#p2pool-alt'
1818
VERSION_CHECK = lambda v: None if 100000 <= v else 'Bitcoin version too old. Upgrade to 0.11.2 or newer!' # not a bug. BIP65 support is ensured by SOFTFORKS_REQUIRED
1919
VERSION_WARNING = lambda v: None

p2pool/web.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def decent_height():
226226
web_root.putChild('payout_addr', WebInterface(lambda: bitcoin_data.pubkey_hash_to_address(wb.my_pubkey_hash, node.net.PARENT)))
227227
web_root.putChild('payout_addrs', WebInterface(lambda: list(('%s' % bitcoin_data.pubkey_hash_to_address(add, node.net.PARENT)) for add in wb.pubkeys.keys)))
228228
web_root.putChild('recent_blocks', WebInterface(lambda: [dict(
229-
# ts=s.timestamp,
230-
ts=s.min_header.timestamp,
229+
ts=s.timestamp,
230+
# ts=s.min_header.timestamp,
231231
hash='%064x' % s.header_hash,
232232
number=p2pool_data.parse_bip0034(s.share_data['coinbase'])[0],
233233
share='%064x' % s.hash,

0 commit comments

Comments
 (0)