From 7c4115818a2731dbde4dd6ee0570ae9b3470e45e Mon Sep 17 00:00:00 2001 From: donSchoe Date: Wed, 12 Feb 2014 23:38:54 +0100 Subject: [PATCH] added cachecoin new staging tree (experimental) --- p2pool/bitcoin/networks.py | 27 ++++++++++++++++++++++-- p2pool/bitcoin/p2p.py | 42 +++++++++++++++++++------------------- p2pool/networks.py | 33 +++++++++++++++++++++++------- 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/p2pool/bitcoin/networks.py b/p2pool/bitcoin/networks.py index 7bd61c0a..10c88e3a 100644 --- a/p2pool/bitcoin/networks.py +++ b/p2pool/bitcoin/networks.py @@ -58,7 +58,7 @@ def check_genesis_block(bitcoind, genesis_block_hash): DUMB_SCRYPT_DIFF=1, DUST_THRESHOLD=1e8, ), - + namecoin=math.Object( P2P_PREFIX='f9beb4fe'.decode('hex'), P2P_PORT=8334, @@ -101,7 +101,7 @@ def check_genesis_block(bitcoind, genesis_block_hash): DUMB_SCRYPT_DIFF=1, DUST_THRESHOLD=1e8, ), - + litecoin=math.Object( P2P_PREFIX='fbc0b6db'.decode('hex'), P2P_PORT=9333, @@ -209,6 +209,29 @@ def check_genesis_block(bitcoind, genesis_block_hash): DUMB_SCRYPT_DIFF=2**16, DUST_THRESHOLD=0.03e8, ), + + cachecoin=math.Object( + P2P_PREFIX='5c394226'.decode('hex'), + P2P_PORT=2225, + ADDRESS_VERSION=28, + RPC_PORT=2224, + RPC_CHECK=defer.inlineCallbacks(lambda bitcoind: defer.returnValue( + 'cachecoinaddress' in (yield bitcoind.rpc_help()) and + not (yield bitcoind.rpc_getinfo())['testnet'] + )), + SUBSIDY_FUNC=lambda target: get_subsidy(6, 100, target), + BLOCKHASH_FUNC=lambda header: pack.IntType(256).unpack(__import__('yac_scrypt').getPoWHash(header, data.block_header_type.unpack(header)['timestamp'])), + POW_FUNC=lambda header: pack.IntType(256).unpack(__import__('yac_scrypt').getPoWHash(header, data.block_header_type.unpack(header)['timestamp'])), + BLOCK_PERIOD=900, # s + SYMBOL='CACH', + CONF_FILE_FUNC=lambda: os.path.join(os.path.join(os.environ['APPDATA'], 'cachecoin') if platform.system() == 'Windows' else os.path.expanduser('~/Library/Application Support/cachecoin/') if platform.system() == 'Darwin' else os.path.expanduser('~/.cachecoin'), 'cachecoin.conf'), + BLOCK_EXPLORER_URL_PREFIX='http://explorer.cachecoin.org/block/', + ADDRESS_EXPLORER_URL_PREFIX='http://explorer.cachecoin.org/address/', + TX_EXPLORER_URL_PREFIX='http://explorer.cachecoin.org/tx/', + SANE_TARGET_RANGE=(2**256//2**20//1000 - 1, 2**256//2**20 - 1), + DUMB_SCRYPT_DIFF=2**16, + DUST_THRESHOLD=0.03e8, + ), ) for net_name, net in nets.iteritems(): net.NAME = net_name diff --git a/p2pool/bitcoin/p2p.py b/p2pool/bitcoin/p2p.py index d6f50c22..f44c4cd2 100644 --- a/p2pool/bitcoin/p2p.py +++ b/p2pool/bitcoin/p2p.py @@ -15,7 +15,7 @@ class Protocol(p2protocol.Protocol): def __init__(self, net): p2protocol.Protocol.__init__(self, net.P2P_PREFIX, 1000000, ignore_trailing_payload=True) - + def connectionMade(self): self.send_version( version=70002, @@ -35,7 +35,7 @@ def connectionMade(self): sub_version_num='/P2Pool:%s/' % (p2pool.__version__,), start_height=0, ) - + message_version = pack.ComposedType([ ('version', pack.IntType(32)), ('services', pack.IntType(64)), @@ -48,20 +48,20 @@ def connectionMade(self): ]) def handle_version(self, version, services, time, addr_to, addr_from, nonce, sub_version_num, start_height): self.send_verack() - + message_verack = pack.ComposedType([]) def handle_verack(self): self.get_block = deferral.ReplyMatcher(lambda hash: self.send_getdata(requests=[dict(type='block', hash=hash)])) self.get_block_header = deferral.ReplyMatcher(lambda hash: self.send_getheaders(version=1, have=[], last=hash)) - + if hasattr(self.factory, 'resetDelay'): self.factory.resetDelay() if hasattr(self.factory, 'gotConnection'): self.factory.gotConnection(self) - + self.pinger = deferral.RobustLoopingCall(self.send_ping, nonce=1234) self.pinger.start(30) - + message_inv = pack.ComposedType([ ('invs', pack.ListType(pack.ComposedType([ ('type', pack.EnumType(pack.IntType(32), {1: 'tx', 2: 'block'})), @@ -76,7 +76,7 @@ def handle_inv(self, invs): self.factory.new_block.happened(inv['hash']) else: print 'Unknown inv type', inv - + message_getdata = pack.ComposedType([ ('requests', pack.ListType(pack.ComposedType([ ('type', pack.EnumType(pack.IntType(32), {1: 'tx', 2: 'block'})), @@ -94,7 +94,7 @@ def handle_inv(self, invs): ('last', pack.PossiblyNoneType(0, pack.IntType(256))), ]) message_getaddr = pack.ComposedType([]) - + message_addr = pack.ComposedType([ ('addrs', pack.ListType(pack.ComposedType([ ('timestamp', pack.IntType(32)), @@ -104,13 +104,13 @@ def handle_inv(self, invs): def handle_addr(self, addrs): for addr in addrs: pass - + message_tx = pack.ComposedType([ ('tx', bitcoin_data.tx_type), ]) def handle_tx(self, tx): self.factory.new_tx.happened(tx) - + message_block = pack.ComposedType([ ('block', bitcoin_data.block_type), ]) @@ -118,7 +118,7 @@ def handle_block(self, block): block_hash = bitcoin_data.hash256(bitcoin_data.block_header_type.pack(block['header'])) self.get_block.got_response(block_hash, block) self.get_block_header.got_response(block_hash, block['header']) - + message_headers = pack.ComposedType([ ('headers', pack.ListType(bitcoin_data.block_type)), ]) @@ -127,26 +127,26 @@ def handle_headers(self, headers): header = header['header'] self.get_block_header.got_response(bitcoin_data.hash256(bitcoin_data.block_header_type.pack(header)), header) self.factory.new_headers.happened([header['header'] for header in headers]) - + message_ping = pack.ComposedType([ ('nonce', pack.IntType(64)), ]) def handle_ping(self, nonce): self.send_pong(nonce=nonce) - + message_pong = pack.ComposedType([ ('nonce', pack.IntType(64)), ]) def handle_pong(self, nonce): pass - + message_alert = pack.ComposedType([ ('message', pack.VarStrType()), ('signature', pack.VarStrType()), ]) def handle_alert(self, message, signature): pass # print 'ALERT:', (message, signature) - + def connectionLost(self, reason): if hasattr(self.factory, 'gotConnection'): self.factory.gotConnection(None) @@ -157,24 +157,24 @@ def connectionLost(self, reason): class ClientFactory(protocol.ReconnectingClientFactory): protocol = Protocol - + maxDelay = 1 - + def __init__(self, net): self.net = net 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.factory = self return p - + def gotConnection(self, conn): self.conn.set(conn) - + def getProtocol(self): return self.conn.get_not_none() diff --git a/p2pool/networks.py b/p2pool/networks.py index 31fd029b..1cf34344 100644 --- a/p2pool/networks.py +++ b/p2pool/networks.py @@ -18,7 +18,7 @@ IDENTIFIER='fc70035c7a81bc6f'.decode('hex'), PREFIX='2472ef181efcd37b'.decode('hex'), P2P_PORT=9333, - MIN_TARGET=0, + MIN_TARGET=4, MAX_TARGET=2**256//2**32 - 1, PERSIST=True, WORKER_PORT=9332, @@ -37,7 +37,7 @@ IDENTIFIER='5fc2be2d4f0d6bfb'.decode('hex'), PREFIX='3f6057a15036f441'.decode('hex'), P2P_PORT=19333, - MIN_TARGET=0, + MIN_TARGET=4, MAX_TARGET=2**256//2**32 - 1, PERSIST=False, WORKER_PORT=19332, @@ -56,7 +56,7 @@ IDENTIFIER='e037d5b8c6923410'.decode('hex'), PREFIX='7208c1a53ef629b0'.decode('hex'), P2P_PORT=9338, - MIN_TARGET=0, + MIN_TARGET=4, MAX_TARGET=2**256//2**20 - 1, PERSIST=True, WORKER_PORT=9327, @@ -75,7 +75,7 @@ IDENTIFIER='cca5e24ec6408b1e'.decode('hex'), PREFIX='ad9614f6466a39cf'.decode('hex'), P2P_PORT=19338, - MIN_TARGET=2**256//50 - 1, + MIN_TARGET=4, MAX_TARGET=2**256//50 - 1, PERSIST=False, WORKER_PORT=19327, @@ -94,7 +94,7 @@ IDENTIFIER='a41b2356a1b7d46e'.decode('hex'), PREFIX='5623b62178d2b9b3'.decode('hex'), P2P_PORT=9323, - MIN_TARGET=0, + MIN_TARGET=4, MAX_TARGET=2**256//2**32 - 1, PERSIST=True, WORKER_PORT=9322, @@ -113,7 +113,7 @@ IDENTIFIER='b41b2356a5b7d35d'.decode('hex'), PREFIX='1623b92172d2b8a2'.decode('hex'), P2P_PORT=19323, - MIN_TARGET=0, + MIN_TARGET=4, MAX_TARGET=2**256//2**32 - 1, PERSIST=False, WORKER_PORT=19322, @@ -133,7 +133,7 @@ IDENTIFIER='a06a81c827cab973'.decode('hex'), PREFIX='7c3614a6bcdcf794'.decode('hex'), P2P_PORT=9346, - MIN_TARGET=0, + MIN_TARGET=4, MAX_TARGET=2**256//2**20 - 1, PERSIST=False, WORKER_PORT=9171, @@ -141,6 +141,25 @@ ANNOUNCE_CHANNEL='#p2pool-vtc', VERSION_CHECK=lambda v: True, ), + + cachecoin=math.Object( + PARENT=networks.nets['cachecoin'], + SHARE_PERIOD=120, # seconds + CHAIN_LENGTH=12*60*60//120, # shares + REAL_CHAIN_LENGTH=12*60*60//120, # shares + TARGET_LOOKBEHIND=30, # shares + SPREAD=36, # blocks + IDENTIFIER='65375c4f7a4d584f'.decode('hex'), + PREFIX='642a2c6524364268'.decode('hex'), + P2P_PORT=2226, + MIN_TARGET=4, + MAX_TARGET=2**256//2**20 - 1, + PERSIST=False, + WORKER_PORT=8336, + BOOTSTRAP_ADDRS='207.30.158.106 p2cache.syware.de q39.qhor.net q30.qhor.net'.split(' '), + ANNOUNCE_CHANNEL='#cachecoin-bots', + VERSION_CHECK=lambda v: True, + ), ) for net_name, net in nets.iteritems(): net.NAME = net_name