mirror fixes
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from dexorder import config, blockchain, current_w3
|
from dexorder import config, blockchain, current_w3, now
|
||||||
from dexorder.bin.executable import execute
|
from dexorder.bin.executable import execute
|
||||||
from dexorder.blockchain.connection import create_w3
|
from dexorder.blockchain.connection import create_w3
|
||||||
from dexorder.blockstate import current_blockstate
|
from dexorder.blockstate import current_blockstate
|
||||||
@@ -90,6 +91,10 @@ async def await_mirror(tx, pool_addr, mirror_addr, mirror_inverted ):
|
|||||||
log.info(f'Updated {pool_addr} => {"1/" if mirror_inverted else ""}{mirror_addr}')
|
log.info(f'Updated {pool_addr} => {"1/" if mirror_inverted else ""}{mirror_addr}')
|
||||||
|
|
||||||
|
|
||||||
|
async def send_update(mirrorenv, pool, price):
|
||||||
|
tx = await mirrorenv.transact.updatePool(pool, price)
|
||||||
|
await tx.wait()
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
init_generating_metadata()
|
init_generating_metadata()
|
||||||
if config.metadata is None:
|
if config.metadata is None:
|
||||||
@@ -126,19 +131,25 @@ async def main():
|
|||||||
mirror_pools = []
|
mirror_pools = []
|
||||||
for pool in pools:
|
for pool in pools:
|
||||||
mirror_addr, mirror_inverted = await mirrorenv.pools(pool)
|
mirror_addr, mirror_inverted = await mirrorenv.pools(pool)
|
||||||
log.debug(f'\tmirror result {mirror_addr} {mirror_inverted}')
|
log.debug(f'\t{pool} => {mirror_addr} inverted={mirror_inverted}')
|
||||||
mirror_pools.append((mirror_addr, mirror_inverted))
|
mirror_pools.append((mirror_addr, mirror_inverted))
|
||||||
await write_metadata(pools, mirror_pools)
|
await write_metadata(pools, mirror_pools)
|
||||||
delay = config.polling if config.polling > 0 else 1
|
delay = config.polling if config.polling > 0 else 1
|
||||||
log.info(f'Mirroring pools every {delay} seconds')
|
log.info(f'Mirroring pools every {delay} seconds')
|
||||||
|
delay = timedelta(seconds=delay)
|
||||||
while True:
|
while True:
|
||||||
|
wake_up = now() + delay
|
||||||
prices = await asyncio.gather(*[get_pool_price(pool) for pool in pools])
|
prices = await asyncio.gather(*[get_pool_price(pool) for pool in pools])
|
||||||
try:
|
updates = [send_update(mirrorenv, pool, price) for pool, price in zip(pools, prices)]
|
||||||
await mirrorenv.transact.updatePools(list(zip(pools,prices)))
|
results = await asyncio.gather(*updates, return_exceptions=True)
|
||||||
except Exception as x:
|
for result, pool, price in zip(results,pools,prices):
|
||||||
log.exception(x)
|
if isinstance(result, Exception):
|
||||||
log.debug('Mirrored'+''.join(f'\n\t{pool} {price}' for pool, price in zip(pools,prices)))
|
log.debug(f'Could not update {pool}: {result}')
|
||||||
await asyncio.sleep(delay)
|
else:
|
||||||
|
log.debug(f'Mirrored {pool} {price}')
|
||||||
|
sleep = (wake_up - now()).total_seconds()
|
||||||
|
if sleep > 0:
|
||||||
|
await asyncio.sleep(sleep)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user