Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with using Solana Mainnet, might be about mapping key #56

Open
Steinadler177 opened this issue Mar 1, 2024 · 5 comments
Open

Comments

@Steinadler177
Copy link

Problem Description

I'm trying to read all price from solana by each time I call the function. When I set solana_network with devnet, it was working perfect. However, when I try to use mainet, testnet, or pythnet, it can't work anymore.

Calling method

solana_network="mainnet" 
use_program = True

async def SolanaPythClientPriceFunction():
    async with PythClient(
        first_mapping_account_key=get_key(solana_network, "mapping"),
        program_key=get_key(solana_network, "program") if use_program else None,
    ) as c:
        await c.refresh_all_prices()

Debug Console Output

.....venv\Lib\site-packages\pythclient\pythclient.py", line 185, in _refresh_mapping_accounts
    raise exceptions.MissingAccountException(f"need account {key} but missing in getProgramAccount response")
pythclient.exceptions.MissingAccountException: need account AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J but missing in getProgramAccount response

I checked the variables with debugger.

async def _refresh_mapping_accounts(self, *, account_json: Optional[Dict[str, Any]] = None, slot: Optional[int] = None) -> List[PythMappingAccount]:
key = self._first_mapping_account_key
existing_mappings = dict((mapping.key, mapping) for mapping in self._mapping_accounts) if self._mapping_accounts else {}
mapping_accounts: List[PythMappingAccount] = []
while key:
m = existing_mappings.get(key) or PythMappingAccount(key, self.solana)
if account_json is not None:
m_data = account_json.get(str(key))
if m_data is None:
raise exceptions.MissingAccountException(f"need account {key} but missing in getProgramAccount response")
assert slot
m.update_with_rpc_response(slot, m_data)
else:
await m.update()
mapping_accounts.append(m)
key = m.next_account_key
self._mapping_accounts = mapping_accounts
return self._mapping_accounts

Until L180, everything works fine. Both key was correctly assigned values. But then, at L183,
m_data = account_json.get(AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J )
it reads empty data.

Is this an error with mapping key? ( I checked with Pyth Network Website, the key is as same as here) Or with the method that I calling it?

@guibescos
Copy link

Hi thanks for reaching out. get_key allows you to get the right mapping address for each network.
AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J is the right address for mainnet.

I think perhaps the issue is the getProgramAccount response being empty? Some RPC nodes don't allow you to call this method. Can you check that the return value of getProgramAccount looks ok?

@Steinadler177
Copy link
Author

Steinadler177 commented Mar 1, 2024

Hi thanks for reaching out. get_key allows you to get the right mapping address for each network. AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J is the right address for mainnet.

I think perhaps the issue is the getProgramAccount response being empty? Some RPC nodes don't allow you to call this method. Can you check that the return value of getProgramAccount looks ok?

Thank you for helping! I put a breakpoint for solana.py L267 but it didn't reach there before broken...

for pythclient.py L179:
`mapping_accounts: List[PythMappingAccount] = []`
It is empty.
I'm stupid, it should be empty

I put a breapoint for pythclient.py L101, current variables looks like this:

image

Where exactly shall I look into?

@guibescos
Copy link

I think probably the best way to proceed here is if you can provide a reproducible code example that causes the error, for example as a Github repository.

@Steinadler177
Copy link
Author

I think probably the best way to proceed here is if you can provide a reproducible code example that causes the error, for example as a Github repository.

Sorry it took me some time to build a clean and simple repo. Here is it:

https://github.com/Steinadler177/PythClientTest

@bonlime
Copy link

bonlime commented May 28, 2024

The code hardcodes to using DEVNET solana http endpoint. you need to provide a correct mainnet/testnet endpoint to get into about mainnet accounts, this would solve the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants