from twisted.python import log
import p2pool
-from p2pool import skiplists, namecoin, ixcoin, i0coin
+from p2pool import skiplists, namecoin, ixcoin, i0coin, solidcoin, litecoin
from p2pool.bitcoin import data as bitcoin_data, script
from p2pool.util import memoize, expiring_dict, math
gentx = share_info_to_gentx(self.share_info, self.header['target'], tracker, net)
if len(gentx['tx_ins'][0]['script']) > 100:
- raise ValueError('''coinbase too large!''')
+ raise ValueError('''coinbase too large! %i bytes''' % (len(gentx['tx_ins'][0]['script']),))
if check_merkle_branch(gentx, self.merkle_branch) != self.header['merkle_root']:
raise ValueError('''gentx doesn't match header via merkle_branch''')
target = bitcoin_data.FloatingInteger.from_target_upper_bound(net.MAX_TARGET)
else:
attempts_per_second = get_pool_attempts_per_second(tracker, previous_share_hash, net)
- pre_target = 2**256//(net.SHARE_PERIOD*attempts_per_second) - 1
previous_share = tracker.shares[previous_share_hash] if previous_share_hash is not None else None
+ pre_target = 2**256//(net.SHARE_PERIOD*attempts_per_second) - 1
pre_target2 = math.clip(pre_target, (previous_share.target*9//10, previous_share.target*11//10))
pre_target3 = math.clip(pre_target2, (0, net.MAX_TARGET))
target = bitcoin_data.FloatingInteger.from_target_upper_bound(pre_target3)
# decide best verified head
scores = sorted(self.verified.tails.get(best_tail, []), key=lambda h: (
self.verified.get_work(self.verified.get_nth_parent_hash(h, min(5, self.verified.get_height(h)))),
- ht.get_min_height(self.verified.shares[h].previous_block),
#self.verified.shares[h].peer is None,
+ ht.get_min_height(self.verified.shares[h].previous_block),
-self.verified.shares[h].time_seen
))
if p2pool.DEBUG:
- print len(self.verified.tails.get(best_tail, [])), '\\/\\/\\/\\/\\/'
+ print len(self.verified.tails), "chain tails and", len(self.verified.tails.get(best_tail, [])), 'chain heads. Top 10 tails:'
if len(scores) > 10:
print ' ...'
for h in scores[-10:]:
print ' ', format_hash(h), format_hash(self.verified.shares[h].previous_hash), (
self.verified.get_work(self.verified.get_nth_parent_hash(h, min(5, self.verified.get_height(h)))),
- ht.get_min_height(self.verified.shares[h].previous_block),
self.verified.shares[h].peer is None,
+ ht.get_min_height(self.verified.shares[h].previous_block),
-self.verified.shares[h].time_seen
)
# eat away at heads
if scores:
- while True:
+ for i in xrange(1000):
to_remove = set()
for share_hash, tail in self.heads.iteritems():
if share_hash in scores[-5:]:
#print "_________", to_remove
# drop tails
- while True:
+ for i in xrange(1000):
to_remove = set()
for tail, heads in self.tails.iteritems():
if min(self.get_height(head) for head in heads) < 2*self.net.CHAIN_LENGTH + 10:
if best is not None:
best_share = self.verified.shares[best]
- if ht.get_min_height(best_share.header['previous_block']) < ht.get_min_height(previous_block) and best_share.bitcoin_hash != previous_block: # and best_share.peer is not None:
+ if ht.get_min_height(best_share.header['previous_block']) < ht.get_min_height(previous_block) and best_share.bitcoin_hash != previous_block and best_share.peer is not None:
if p2pool.DEBUG:
print 'Stale detected! %x < %x' % (best_share.header['previous_block'], previous_block)
best = best_share.previous_hash
return [self.filename + str(suffix) for suffix in suffixes], self.filename + str(suffixes[-1] + 1) if suffixes else self.filename + str(0)
def forget_share(self, share_hash):
- to_remove = set()
for filename, (share_hashes, verified_hashes) in self.known.iteritems():
if share_hash in share_hashes:
share_hashes.remove(share_hash)
- if not share_hashes and not verified_hashes:
- to_remove.add(filename)
- for filename in to_remove:
- self.known.pop(filename)
- os.remove(filename)
- print "REMOVED", filename
+ self.check_remove()
def forget_verified_share(self, share_hash):
- to_remove = set()
for filename, (share_hashes, verified_hashes) in self.known.iteritems():
if share_hash in verified_hashes:
verified_hashes.remove(share_hash)
+ self.check_remove()
+
+ def check_remove(self):
+ to_remove = set()
+ for filename, (share_hashes, verified_hashes) in self.known.iteritems():
+ #print filename, len(share_hashes) + len(verified_hashes)
if not share_hashes and not verified_hashes:
to_remove.add(filename)
for filename in to_remove:
print "REMOVED", filename
class Mainnet(bitcoin_data.Mainnet):
- SHARE_PERIOD = 5 # seconds
+ SHARE_PERIOD = 10 # seconds
CHAIN_LENGTH = 24*60*60//5 # shares
TARGET_LOOKBEHIND = 200 # shares
SPREAD = 3 # blocks
PREFIX = '3f6057a15036f441'.decode('hex')
NAME = 'bitcoin_testnet'
P2P_PORT = 19333
- MAX_TARGET = 2**256//2**20 - 1
+ MAX_TARGET = 2**256//2**32 - 1
PERSIST = False
WORKER_PORT = 19332
PERSIST = False
WORKER_PORT = 19329
+class SolidcoinMainnet(solidcoin.SolidcoinMainnet):
+ SHARE_PERIOD = 10
+ CHAIN_LENGTH = 24*60*60//10 # shares
+ TARGET_LOOKBEHIND = 3600//10 # shares
+ SPREAD = 3 # blocks
+ SCRIPT = bitcoin_data.pubkey_hash_to_script2(bitcoin_data.address_to_pubkey_hash('sMKZ1yxHETxPYKh4Z2anWnwZDJZU7ztroy', solidcoin.SolidcoinMainnet))
+ IDENTIFIER = '9cc9c421cca258cd'.decode('hex')
+ PREFIX = 'c059125b8070f00a'.decode('hex')
+ NAME = 'solidcoin'
+ P2P_PORT = 9337
+ MAX_TARGET = 2**256//2**32 - 1
+ PERSIST = True
+ WORKER_PORT = 9328
+
+class LitecoinMainnet(litecoin.LitecoinMainnet):
+ SHARE_PERIOD = 10 # seconds
+ CHAIN_LENGTH = 24*60*60//5 # shares
+ TARGET_LOOKBEHIND = 200 # shares
+ SPREAD = 12 # blocks
+ SCRIPT = '410403ad3dee8ab3d8a9ce5dd2abfbe7364ccd9413df1d279bf1a207849310465b0956e5904b1155ecd17574778f9949589ebfd4fb33ce837c241474a225cf08d85dac'.decode('hex')
+ IDENTIFIER = 'e037d5b8c6923410'.decode('hex')
+ PREFIX = '7208c1a53ef629b0'.decode('hex')
+ NAME = 'litecoin'
+ P2P_PORT = 9338
+ MAX_TARGET = 2**256//2**32 - 1
+ PERSIST = True
+ WORKER_PORT = 9327
+
+class LitecoinTestnet(litecoin.LitecoinTestnet):
+ SHARE_PERIOD = 1 # seconds
+ CHAIN_LENGTH = 24*60*60//5 # shares
+ TARGET_LOOKBEHIND = 200 # shares
+ SPREAD = 12 # blocks
+ SCRIPT = '410403ad3dee8ab3d8a9ce5dd2abfbe7364ccd9413df1d279bf1a207849310465b0956e5904b1155ecd17574778f9949589ebfd4fb33ce837c241474a225cf08d85dac'.decode('hex')
+ IDENTIFIER = 'cca5e24ec6408b1e'.decode('hex')
+ PREFIX = 'ad9614f6466a39cf'.decode('hex')
+ NAME = 'litecoin_testnet'
+ P2P_PORT = 19338
+ MAX_TARGET = 2**256//2**20 - 1
+ PERSIST = False
+ WORKER_PORT = 19327
+
+nets = dict((net.NAME, net) for net in set([Mainnet, Testnet, NamecoinMainnet, NamecoinTestnet, IxcoinMainnet, IxcoinTestnet, I0coinMainnet, I0coinTestnet, SolidcoinMainnet, LitecoinMainnet, LitecoinTestnet]))