interface: introduce tip_lock
This commit is contained in:
@@ -117,11 +117,13 @@ class Interface(PrintError):
|
|||||||
self.port = int(self.port)
|
self.port = int(self.port)
|
||||||
self.config_path = config_path
|
self.config_path = config_path
|
||||||
self.cert_path = os.path.join(self.config_path, 'certs', self.host)
|
self.cert_path = os.path.join(self.config_path, 'certs', self.host)
|
||||||
self.tip_header = None
|
|
||||||
self.tip = 0
|
|
||||||
self.blockchain = None
|
self.blockchain = None
|
||||||
self.network = network
|
self.network = network
|
||||||
|
|
||||||
|
self.tip_header = None
|
||||||
|
self.tip = 0
|
||||||
|
self.tip_lock = asyncio.Lock()
|
||||||
|
|
||||||
# TODO combine?
|
# TODO combine?
|
||||||
self.fut = asyncio.get_event_loop().create_task(self.run())
|
self.fut = asyncio.get_event_loop().create_task(self.run())
|
||||||
self.group = CustomTaskGroup()
|
self.group = CustomTaskGroup()
|
||||||
@@ -308,8 +310,9 @@ class Interface(PrintError):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
new_header = await asyncio.wait_for(header_queue.get(), 300)
|
new_header = await asyncio.wait_for(header_queue.get(), 300)
|
||||||
self.tip_header = new_header
|
async with self.tip_lock:
|
||||||
self.tip = new_header['block_height']
|
self.tip_header = new_header
|
||||||
|
self.tip = new_header['block_height']
|
||||||
await copy_header_queue.put(new_header)
|
await copy_header_queue.put(new_header)
|
||||||
except concurrent.futures.TimeoutError:
|
except concurrent.futures.TimeoutError:
|
||||||
await self.session.send_request('server.ping', timeout=10)
|
await self.session.send_request('server.ping', timeout=10)
|
||||||
@@ -329,12 +332,12 @@ class Interface(PrintError):
|
|||||||
while True:
|
while True:
|
||||||
self.network.notify('updated')
|
self.network.notify('updated')
|
||||||
item = await replies.get()
|
item = await replies.get()
|
||||||
async with self.network.bhi_lock:
|
async with self.network.bhi_lock and self.tip_lock:
|
||||||
if self.blockchain.height() < item['block_height']-1:
|
if self.blockchain.height() < item['block_height']-1:
|
||||||
_, height = await self.sync_until(height, None)
|
_, height = await self.sync_until(height, None)
|
||||||
if self.blockchain.height() >= height and self.blockchain.check_header(item):
|
if self.blockchain.height() >= height and self.blockchain.check_header(item):
|
||||||
# another interface amended the blockchain
|
# another interface amended the blockchain
|
||||||
self.print_error("SKIPPING HEADER", height)
|
self.print_error("skipping header", height)
|
||||||
continue
|
continue
|
||||||
if self.tip < height:
|
if self.tip < height:
|
||||||
height = self.tip
|
height = self.tip
|
||||||
|
|||||||
Reference in New Issue
Block a user