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

Shall getEvent min startLedger depth be equal to earliest accessible ledger entry? #260

Open
OlegJakushkin opened this issue Aug 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@OlegJakushkin
Copy link

What version are you using?

I am using Python on QuickNode REST RPC:

What did you do?

I want to query getEvent REST RPC method. I tried to call on two RPC endpoints:

import requests
import json
import pprint

SOROBAN_RPC_URL ="https://docs-demo.stellar-mainnet.quiknode.pro/" # "https://soroban-rpc.mainnet.stellar.gateway.fm" #"

def get_events(start_ledger, account_id, cursor=None, limit=100):
    payload = {
        "jsonrpc": "2.0",
        "id": 8675399,
        "method": "getEvents",
        "params": {
            "startLedger": start_ledger,
             "filters": [
                {
                    "contractIds": [account_id]
                }
            ],
            "pagination": {
                "limit": limit
            }
        }
    }
    headers = {
        'Content-Type': 'application/json'
    }

    response = requests.post(SOROBAN_RPC_URL, headers=headers, data=json.dumps(payload))
    pprint.pprint(response.json())
    return response.json()


if __name__ == "__main__":
    account_id = "CCO2A7ALFXZ3QIT3SUFJZRWCU5RVWG5E7AI4RCLTRXQIJEFIBEZP63JI"
    start_ledger = 52916217 # fails
                  #52936217 works
    get_events(start_ledger, account_id, None)

Yet it fails with: {'error': {'code': -32600, 'message': 'start is before oldest ledger'}, even though when I ask for the earliest node block, I get: 51379561 which is much less then 52916217:

import requests

HORIZON_URL = "https://docs-demo.stellar-mainnet.quiknode.pro/"  # Use the appropriate URL for your network (testnet/mainnet)

def get_earliest_ledger():
    params = {
        "order": "asc",
        "limit": 1
    }
    response = requests.get(f"{HORIZON_URL}/ledgers", params=params)
    if response.status_code == 200:
        return response.json()['_embedded']['records'][0]
    else:
        response.raise_for_status()

if __name__ == "__main__":
    earliest_ledger = get_earliest_ledger()
    print("Earliest accessible ledger entry:")
    print(earliest_ledger)

prints to me into on 51379561

What did you expect to see?

Events starting from the first block are known to the node.

What did you see instead?

Error {'error': {'code': -32600, 'message': 'start is before oldest ledger'},

Question

Is there some way to get a real minimal queriable node block?

@OlegJakushkin OlegJakushkin added the bug Something isn't working label Aug 8, 2024
@psheth9
Copy link
Contributor

psheth9 commented Aug 9, 2024

@OlegJakushkin it seems like you are fetching earliest ledger from Horizon node and not RPC node.

Can you try calling getHealth RPC endpoint instead to see the oldest and latest ledger.

res = requests.post('https://soroban-testnet.stellar.org', json={
    "jsonrpc": "2.0",
    "id": 8675309,
    "method": "getHealth"
})

Response should look like below:


{
    "jsonrpc": "2.0",
    "id": 8675309,
    "result": {
        "status": "healthy",
        "latestLedger": 969486,
        "oldestLedger": 952207,
        "ledgerRetentionWindow": 17280
    }
}



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants