X-Git-Url: https://git.novaco.in/?p=stratum-mining.git;a=blobdiff_plain;f=lib%2Fblock_updater.py;fp=lib%2Fblock_updater.py;h=fd03711c84913c844acfd364dec5aaa470db05b2;hp=b80a02443bd42253a1a5e87c0e4e4a933bdda886;hb=23ebc8506325ec4b8a60ce3c49cab96ae87c006b;hpb=8a7474eb0eefdbc68e9b57371a68c25f33427f0d diff --git a/lib/block_updater.py b/lib/block_updater.py index b80a024..fd03711 100644 --- a/lib/block_updater.py +++ b/lib/block_updater.py @@ -11,48 +11,48 @@ class BlockUpdater(object): ''' Polls upstream's getinfo() and detecting new block on the network. This will call registry.update_block when new prevhash appear. - + This is just failback alternative when something - with ./bitcoind -blocknotify will go wrong. + with ./bitcoind -blocknotify will go wrong. ''' - + def __init__(self, registry, bitcoin_rpc): self.bitcoin_rpc = bitcoin_rpc self.registry = registry self.clock = None self.schedule() - + def schedule(self): when = self._get_next_time() #log.debug("Next prevhash update in %.03f sec" % when) #log.debug("Merkle update in next %.03f sec" % \ # ((self.registry.last_update + settings.MERKLE_REFRESH_INTERVAL)-Interfaces.timestamper.time())) self.clock = reactor.callLater(when, self.run) - + def _get_next_time(self): when = settings.PREVHASH_REFRESH_INTERVAL - (Interfaces.timestamper.time() - self.registry.last_update) % \ settings.PREVHASH_REFRESH_INTERVAL - return when - + return when + @defer.inlineCallbacks def run(self): update = False - - try: + + try: if self.registry.last_block: current_prevhash = "%064x" % self.registry.last_block.hashPrevBlock else: current_prevhash = None - + prevhash = util.reverse_hash((yield self.bitcoin_rpc.prevhash())) if prevhash and prevhash != current_prevhash: log.info("New block! Prevhash: %s" % prevhash) update = True - + elif Interfaces.timestamper.time() - self.registry.last_update >= settings.MERKLE_REFRESH_INTERVAL: log.info("Merkle update! Prevhash: %s" % prevhash) update = True - + if update: self.registry.update_block() @@ -61,4 +61,4 @@ class BlockUpdater(object): finally: self.schedule() - \ No newline at end of file +