Browse Source

Add daemon debugging caught-up facility

master
Neil Booth 8 years ago
parent
commit
00e9c5a31d
  1. 6
      server/block_processor.py
  2. 2
      server/controller.py
  3. 14
      server/daemon.py
  4. 2
      server/env.py
  5. 2
      server/protocol.py

6
server/block_processor.py

@ -167,6 +167,7 @@ class MemPool(LoggedClass):
self.txs = {}
self.hash168s = defaultdict(set) # None can be a key
self.bp = bp
self.initial = True
async def update(self, hex_hashes):
'''Update state given the current mempool to the passed set of hashes.
@ -177,7 +178,8 @@ class MemPool(LoggedClass):
hex_hashes = set(hex_hashes)
touched = set()
if not self.txs:
if self.initial:
self.initial = False
self.logger.info('initial fetch of {:,d} daemon mempool txs'
.format(len(hex_hashes)))
@ -322,6 +324,8 @@ class BlockProcessor(LoggedClass):
self.height = self.db_height
self.tip = self.db_tip
self.daemon.debug_set_height(self.height)
# Caches to be flushed later. Headers and tx_hashes have one
# entry per block
self.history = defaultdict(partial(array.array, 'I'))

2
server/controller.py

@ -34,7 +34,7 @@ class Controller(LoggedClass):
self.loop = loop
self.env = env
self.coin = env.coin
self.daemon = Daemon(env.daemon_url)
self.daemon = Daemon(env.daemon_url, env.debug)
self.block_processor = BlockProcessor(env, self.daemon,
on_update=self.on_update)
JSONRPC.init(self.block_processor, self.daemon, self.coin,

14
server/daemon.py

@ -26,11 +26,18 @@ class Daemon(util.LoggedClass):
WARMING_UP = -28
def __init__(self, url):
def __init__(self, url, debug):
super().__init__()
self.url = url
self._height = None
self.logger.info('connecting to daemon at URL {}'.format(url))
self.debug_caught_up = 'caught_up' in debug
def debug_set_height(self, height):
if self.debug_caught_up:
self.logger.info('pretending to have caught up to height {}'
.format(height))
self._height = height
@classmethod
def is_warming_up(cls, err):
@ -103,6 +110,8 @@ class Daemon(util.LoggedClass):
async def mempool_hashes(self):
'''Return the hashes of the txs in the daemon's mempool.'''
if self.debug_caught_up:
return []
return await self.send_single('getrawmempool')
async def estimatefee(self, params):
@ -138,7 +147,8 @@ class Daemon(util.LoggedClass):
async def height(self):
'''Query the daemon for its current height.'''
self._height = await self.send_single('getblockcount')
if not self.debug_caught_up:
self._height = await self.send_single('getblockcount')
return self._height
def cached_height(self):

2
server/env.py

@ -43,6 +43,8 @@ class Env(LoggedClass):
# The electrum client takes the empty string as unspecified
self.donation_address = self.default('DONATION_ADDRESS', '')
self.db_engine = self.default('DB_ENGINE', 'leveldb')
self.debug = self.default('DEBUG', '')
self.debug = [item.lower() for item in self.debug.split()]
def default(self, envvar, default):
return environ.get(envvar, default)

2
server/protocol.py

@ -77,7 +77,7 @@ class JSONRPC(asyncio.Protocol, LoggedClass):
try:
message = json.loads(message.decode())
except Exception as e:
self.logger.info('error decoding JSON message'.format(e))
self.logger.info('error decoding JSON message: {}'.format(e))
else:
self.ADD_JOB(self.request_handler(message))

Loading…
Cancel
Save