Skip to content

Commit

Permalink
Merge pull request #20 from warpdotgreen/improvs
Browse files Browse the repository at this point in the history
Improvs: Just one, aktually
  • Loading branch information
Yakuhito authored May 19, 2024
2 parents 27f4511 + 284b7fb commit 680d785
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions commands/followers/xch_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def getUnspentPortalId(self) -> bytes:
if coin_id is None:
await asyncio.sleep(0.1)
return coin_id


async def setUnspentPortalId(self, coin_id: bytes):
async with self.unspent_portal_id_lock:
Expand Down Expand Up @@ -217,15 +217,31 @@ async def messageSigner(self):
await asyncio.sleep(5)


async def get_coin_record_by_name(self, node: FullNodeRpcClient, coin_id: bytes, tries: int = -1) -> CoinRecord:
coin_record = await node.get_coin_record_by_name(coin_id)
while coin_record is None:
if tries == 0:
return None
elif tries > -1:
tries -= 1

logging.info(f"{self.chain_id.decode()}: Coin 0x{coin_id.hex()}: not found; waiting 5s")
await asyncio.sleep(5)
coin_record = await node.get_coin_record_by_name(coin_id)

return coin_record


async def syncPortal(
self,
db,
node: FullNodeRpcClient,
last_synced_portal: ChiaPortalState
) -> ChiaPortalState:
coin_record = await node.get_coin_record_by_name(last_synced_portal.coin_id)
coin_record = await self.get_coin_record_by_name(node, last_synced_portal.coin_id)

if coin_record.spent_block_index == 0:
parent_coin_record = await node.get_coin_record_by_name(last_synced_portal.parent_id)
parent_coin_record = await self.get_coin_record_by_name(node, last_synced_portal.parent_id)
if parent_coin_record.spent_block_index == 0:
logging.info(f"Portal coin {self.chain}-0x{last_synced_portal.coin_id.hex()}: parent is unspent; reverting.")
parent_state = db.query(ChiaPortalState).filter(
Expand Down Expand Up @@ -314,7 +330,7 @@ async def syncPortal(
await self.setUnspentPortalId(new_synced_portal.coin_id)

if self.syncing:
cr = await node.get_coin_record_by_name(new_synced_portal.coin_id)
cr = await self.get_coin_record_by_name(node, new_synced_portal.coin_id)
if cr.spent_block_index is None or cr.spent_block_index == 0:
self.syncing = False

Expand Down Expand Up @@ -346,7 +362,7 @@ async def portalFollower(self):

if last_synced_portal is None:
logging.info(f"{self.chain}: No last synced portal found, using launcher...")
launcher_coin_record = await node.get_coin_record_by_name(portal_launcher_id)
launcher_coin_record = await self.get_coin_record_by_name(node, portal_launcher_id)
assert launcher_coin_record.spent_block_index > 0

launcher_spend = await node.get_puzzle_and_solution(portal_launcher_id, launcher_coin_record.spent_block_index)
Expand Down Expand Up @@ -436,7 +452,7 @@ async def createMessageFromMemo(


async def processCoinRecord(self, db: any, node: FullNodeRpcClient, coin_record: CoinRecord):
parent_record = await node.get_coin_record_by_name(coin_record.coin.parent_coin_info)
parent_record = await self.get_coin_record_by_name(node, coin_record.coin.parent_coin_info)
parent_spend = await node.get_puzzle_and_solution(
coin_record.coin.parent_coin_info,
parent_record.spent_block_index
Expand Down Expand Up @@ -538,7 +554,7 @@ async def messageListener(self):
while earliest_unprocessed_coin_record.confirmed_block_index + self.sign_min_height > (await self.get_current_height(node)):
await asyncio.sleep(10)

coin_record_copy = await node.get_coin_record_by_name(earliest_unprocessed_coin_record.coin.name())
coin_record_copy = await self.get_coin_record_by_name(node, earliest_unprocessed_coin_record.coin.name(), 3)
if coin_record_copy is None or coin_record_copy.confirmed_block_index != earliest_unprocessed_coin_record.confirmed_block_index:
logging.info(f"{self.chain} message follower: Coin {self.chain}-0x{earliest_unprocessed_coin_record.coin.name().hex()}: possible reorg; re-processing")
reorg = True
Expand Down

0 comments on commit 680d785

Please sign in to comment.