diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 79ac010..b97ee58 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -1,3 +1,17 @@ +version 0.8.2 +------------- + +- process new blocks in the asyncio executor; essentially a python thread. + This should eliminate latency during block processing that caused sessions + to be dropped. +- bandwith limit is restored incrementally to a session over the hour + rather than in a lump when one hour has passed. Also, only the + limit is refunded each hour; previously the entire usage would be + refunded. So if the session uses 30MB bandwidth and your limit is + 10MB, it will take 3 hrs before the session is considered to have + used none of its allotted bandwidth; previously it would happen after 1 + hour. + version 0.8.1 ------------- diff --git a/lib/jsonrpc.py b/lib/jsonrpc.py index f58cf6c..861b565 100644 --- a/lib/jsonrpc.py +++ b/lib/jsonrpc.py @@ -129,10 +129,12 @@ class JSONRPC(asyncio.Protocol, LoggedClass): def using_bandwidth(self, amount): now = time.time() - if now >= self.bandwidth_start + self.bandwidth_interval: - self.bandwidth_start = now - self.bandwidth_used = 0 - self.bandwidth_used += amount + # Reduce the recorded usage in proportion to the elapsed time + elapsed = now - self.bandwidth_start + self.bandwidth_start = now + refund = int(elapsed / self.bandwidth_interval * self.bandwidth_limit) + refund = min(refund, self.bandwidth_used) + self.bandwidth_used += amount - refund def data_received(self, data): '''Handle incoming data (synchronously). diff --git a/server/block_processor.py b/server/block_processor.py index fbe2c57..0ad73a9 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -201,6 +201,7 @@ class BlockProcessor(server.db.DB): self.first_caught_up() self.flush(True) + self.logger.info('shut down complete') def shutdown(self): '''Call to shut down the block processor.''' @@ -213,11 +214,16 @@ class BlockProcessor(server.db.DB): if self.height == -1: blocks[0] = blocks[0][:self.coin.HEADER_LEN] + bytes(1) - touched = set() - try: + def do_it(): for block in blocks: + if self._shutdown: + break self.advance_block(block, touched) - await asyncio.sleep(0) # Yield + + touched = set() + loop = asyncio.get_event_loop() + try: + await loop.run_in_executor(None, do_it) except ChainReorg: await self.handle_chain_reorg(touched) diff --git a/server/version.py b/server/version.py index 389d504..2b39ce5 100644 --- a/server/version.py +++ b/server/version.py @@ -1 +1 @@ -VERSION = "ElectrumX 0.8.1" +VERSION = "ElectrumX 0.8.2"