auto-detect POS/POW

This commit is contained in:
Alan Penner 2014-01-19 08:40:47 -08:00
parent f7421df09b
commit b68b75d03d
4 changed files with 35 additions and 33 deletions

View File

@ -5,6 +5,8 @@ import struct
import util import util
import merkletree import merkletree
import halfnode import halfnode
from coinbasetx import CoinbaseTransactionPOW
from coinbasetx import CoinbaseTransactionPOS
from coinbasetx import CoinbaseTransaction from coinbasetx import CoinbaseTransaction
import lib.logger import lib.logger
log = lib.logger.get_logger('block_template') log = lib.logger.get_logger('block_template')
@ -55,10 +57,10 @@ class BlockTemplate(halfnode.CBlock):
txhashes = [None] + [ util.ser_uint256(int(t['hash'], 16)) for t in data['transactions'] ] txhashes = [None] + [ util.ser_uint256(int(t['hash'], 16)) for t in data['transactions'] ]
mt = merkletree.MerkleTree(txhashes) mt = merkletree.MerkleTree(txhashes)
if settings.COINDAEMON_Reward == 'POW': if settings.COINDAEMON_Reward == 'POW':
coinbase = self.coinbase_transaction_class(self.timestamper, self.coinbaser, data['coinbasevalue'], data['coinbaseaux']['flags'], data['height'], coinbase = CoinbaseTransactionPOW(self.timestamper, self.coinbaser, data['coinbasevalue'], data['coinbaseaux']['flags'], data['height'],
settings.COINBASE_EXTRAS) settings.COINBASE_EXTRAS)
else: else:
coinbase = self.coinbase_transaction_class(self.timestamper, self.coinbaser, data['coinbasevalue'], data['coinbaseaux']['flags'], data['height'], coinbase = CoinbaseTransactionPOS(self.timestamper, self.coinbaser, data['coinbasevalue'], data['coinbaseaux']['flags'], data['height'],
settings.COINBASE_EXTRAS, data['curtime']) settings.COINBASE_EXTRAS, data['curtime'])
self.height = data['height'] self.height = data['height']

View File

@ -6,8 +6,8 @@ import settings
import lib.logger import lib.logger
log = lib.logger.get_logger('coinbasetx') log = lib.logger.get_logger('coinbasetx')
if settings.COINDAEMON_Reward == 'POW': #if settings.COINDAEMON_Reward == 'POW':
class CoinbaseTransaction(halfnode.CTransaction): class CoinbaseTransactionPOW(halfnode.CTransaction):
'''Construct special transaction used for coinbase tx. '''Construct special transaction used for coinbase tx.
It also implements quick serialization using pre-cached It also implements quick serialization using pre-cached
scriptSig template.''' scriptSig template.'''
@ -17,7 +17,7 @@ if settings.COINDAEMON_Reward == 'POW':
extranonce_size = struct.calcsize(extranonce_type) extranonce_size = struct.calcsize(extranonce_type)
def __init__(self, timestamper, coinbaser, value, flags, height, data): def __init__(self, timestamper, coinbaser, value, flags, height, data):
super(CoinbaseTransaction, self).__init__() super(CoinbaseTransactionPOW, self).__init__()
log.debug("Got to CoinBaseTX") log.debug("Got to CoinBaseTX")
#self.extranonce = 0 #self.extranonce = 0
@ -45,7 +45,7 @@ if settings.COINDAEMON_Reward == 'POW':
self.vout.append(tx_out) self.vout.append(tx_out)
# Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx
self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder) self._serialized = super(CoinbaseTransactionPOW, self).serialize().split(self.extranonce_placeholder)
def set_extranonce(self, extranonce): def set_extranonce(self, extranonce):
if len(extranonce) != self.extranonce_size: if len(extranonce) != self.extranonce_size:
@ -53,8 +53,8 @@ if settings.COINDAEMON_Reward == 'POW':
(part1, part2) = self.vin[0]._scriptSig_template (part1, part2) = self.vin[0]._scriptSig_template
self.vin[0].scriptSig = part1 + extranonce + part2 self.vin[0].scriptSig = part1 + extranonce + part2
elif settings.COINDAEMON_Reward == 'POS': #elif settings.COINDAEMON_Reward == 'POS':
class CoinbaseTransaction(halfnode.CTransaction): class CoinbaseTransactionPOS(halfnode.CTransaction):
'''Construct special transaction used for coinbase tx. '''Construct special transaction used for coinbase tx.
It also implements quick serialization using pre-cached It also implements quick serialization using pre-cached
scriptSig template.''' scriptSig template.'''
@ -64,7 +64,7 @@ elif settings.COINDAEMON_Reward == 'POS':
extranonce_size = struct.calcsize(extranonce_type) extranonce_size = struct.calcsize(extranonce_type)
def __init__(self, timestamper, coinbaser, value, flags, height, data, ntime): def __init__(self, timestamper, coinbaser, value, flags, height, data, ntime):
super(CoinbaseTransaction, self).__init__() super(CoinbaseTransactionPOS, self).__init__()
log.debug("Got to CoinBaseTX") log.debug("Got to CoinBaseTX")
#self.extranonce = 0 #self.extranonce = 0
@ -93,7 +93,7 @@ elif settings.COINDAEMON_Reward == 'POS':
self.vout.append(tx_out) self.vout.append(tx_out)
# Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx # Two parts of serialized coinbase, just put part1 + extranonce + part2 to have final serialized tx
self._serialized = super(CoinbaseTransaction, self).serialize().split(self.extranonce_placeholder) self._serialized = super(CoinbaseTransactionPOS, self).serialize().split(self.extranonce_placeholder)
def set_extranonce(self, extranonce): def set_extranonce(self, extranonce):
if len(extranonce) != self.extranonce_size: if len(extranonce) != self.extranonce_size:
@ -101,7 +101,7 @@ elif settings.COINDAEMON_Reward == 'POS':
(part1, part2) = self.vin[0]._scriptSig_template (part1, part2) = self.vin[0]._scriptSig_template
self.vin[0].scriptSig = part1 + extranonce + part2 self.vin[0].scriptSig = part1 + extranonce + part2
else: #else:
class CoinbaseTransaction(halfnode.CTransaction): class CoinbaseTransaction(halfnode.CTransaction):
'''Construct special transaction used for coinbase tx. '''Construct special transaction used for coinbase tx.
It also implements quick serialization using pre-cached It also implements quick serialization using pre-cached

View File

@ -21,27 +21,27 @@ log = lib.logger.get_logger('halfnode')
log.debug("Got to Halfnode") log.debug("Got to Halfnode")
if settings.COINDAEMON_ALGO == 'scrypt': if settings.COINDAEMON_ALGO == 'scrypt':
log.debug("########################################### Loading LTC Scrypt #########################################################") log.debug("########################################### Loading LTC Scrypt #########################################################")
import ltc_scrypt import ltc_scrypt
elif settings.COINDAEMON_ALGO == 'quark': elif settings.COINDAEMON_ALGO == 'quark':
log.debug("########################################### Loading Quark Support #########################################################") log.debug("########################################### Loading Quark Support #########################################################")
import quark_hash import quark_hash
else: else:
log.debug("########################################### Loading SHA256 Support ######################################################") log.debug("########################################### Loading SHA256 Support ######################################################")
if settings.COINDAEMON_Reward == 'POS': #if settings.COINDAEMON_Reward == 'POS':
log.debug("########################################### Loading POS Support #########################################################") # log.debug("########################################### Loading POS Support #########################################################")
pass # pass
else: #else:
log.debug("########################################### Loading POW Support ######################################################") # log.debug("########################################### Loading POW Support ######################################################")
pass # pass
if settings.COINDAEMON_TX == 'yes': if settings.COINDAEMON_TX == 'yes':
log.debug("########################################### Loading SHA256 Transaction Message Support #########################################################") log.debug("########################################### Loading SHA256 Transaction Message Support #########################################################")
pass pass
else: else:
log.debug("########################################### NOT Loading SHA256 Transaction Message Support ######################################################") log.debug("########################################### NOT Loading SHA256 Transaction Message Support ######################################################")
pass pass
MY_VERSION = 31402 MY_VERSION = 31402

View File

@ -46,15 +46,15 @@ def setup(on_startup):
if result['version'] >= 1: if result['version'] >= 1:
result = (yield bitcoin_rpc.getinfo()) result = (yield bitcoin_rpc.getinfo())
if isinstance(result,dict): if isinstance(result,dict):
if 'stake' in result and settings.COINDAEMON_Reward == 'POS': if 'stake' in result: # and settings.COINDAEMON_Reward == 'POS':
log.info("CoinD looks to be a POS Coin, Config for POS looks correct") settings.COINDAEMON_Reward = 'POS'
break break
elif 'stake' not in result and settings.COINDAEMON_Reward == 'POW': elif 'stake' not in result: # and settings.COINDAEMON_Reward == 'POW':
log.info("CoinD looks to be a POW Coin, Config looks to be correct") settings.COINDAEMON_Reward = 'POW'
break break
else: # else:
log.error("Wrong Algo Selected, Switch to appropriate POS/POW in config.py!") # log.error("Wrong Algo Selected, Switch to appropriate POS/POW in config.py!")
reactor.stop() # reactor.stop()
else: else:
log.error("Block Version mismatch: %s" % result['version']) log.error("Block Version mismatch: %s" % result['version'])