Skip to content

Commit

Permalink
XCH follower: less errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakuhito committed May 22, 2024
1 parent 586b31f commit 4544564
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions commands/followers/xch_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ async def get_coin_record_by_name(self, node: FullNodeRpcClient, coin_id: bytes,

return coin_record

async def get_puzzle_and_solution(self, node: FullNodeRpcClient, coin_id: bytes, height: int) -> CoinSpend:
spend = await node.get_puzzle_and_solution(coin_id, height)
while spend is None:
logging.info(f"Spend for coin {self.chain_id}-0x{coin_id} not found; retrying in 5s")
await asyncio.sleep(5)
spend = await node.get_puzzle_and_solution(coin_id, height)

return spend


async def syncPortal(
self,
Expand All @@ -259,7 +268,7 @@ async def syncPortal(
return last_synced_portal

# spent!
spend = await node.get_puzzle_and_solution(last_synced_portal.coin_id, coin_record.spent_block_index)
spend = await self.get_puzzle_and_solution(node, last_synced_portal.coin_id, coin_record.spent_block_index)
conds = conditions_dict_for_solution(spend.puzzle_reveal, spend.solution, INFINITE_COST)
create_coins = conds[ConditionOpcode.CREATE_COIN]
new_ph = None
Expand Down Expand Up @@ -367,7 +376,7 @@ async def portalFollower(self):
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)
launcher_spend = await self.get_puzzle_and_solution(node, portal_launcher_id, launcher_coin_record.spent_block_index)
conds = conditions_dict_for_solution(launcher_spend.puzzle_reveal, launcher_spend.solution, INFINITE_COST)
create_coins = conds[ConditionOpcode.CREATE_COIN]
assert len(create_coins) == 1 and create_coins[0].vars[1] == b'\x01'
Expand Down Expand Up @@ -459,7 +468,8 @@ async def createMessageFromMemo(

async def processCoinRecord(self, db: any, node: FullNodeRpcClient, coin_record: CoinRecord):
parent_record = await self.get_coin_record_by_name(node, coin_record.coin.parent_coin_info)
parent_spend = await node.get_puzzle_and_solution(
parent_spend = await self.get_puzzle_and_solution(
node,
coin_record.coin.parent_coin_info,
parent_record.spent_block_index
)
Expand Down

0 comments on commit 4544564

Please sign in to comment.