X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=lib%2Fblock_updater.py;h=e4f27ccb9cdf3b56f35444cdcc4fe405e93d5152;hb=HEAD;hp=3ed44b8bdec2ccdd8e4347311d4e883626b3ecc2;hpb=1e086b3786e3708cb71205962d9db1684f2271f2;p=stratum-mining.git diff --git a/lib/block_updater.py b/lib/block_updater.py index 3ed44b8..e4f27cc 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 ./novacoind -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())) + #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 +