algorand / indexer

searchable history and current state
MIT License
114 stars 92 forks source link

Implement the endpoint `GET /v2/block-headers` #1638

Open agodnic opened 1 week ago

agodnic commented 1 week ago

Summary

This pull request implements the endpoint GET /v2/block-headers (ported from https://github.com/AlgoNode/indexer-api-cdb/pull/10).

In particular, this enables searching for blocks by different participation-related parameters (i.e.: proposer address, expired accounts, absent accounts).

Test Plan

The new endpoint has been tested manually, using the FNet dataset:

# no parameters
curl -Ss 'http://127.0.0.1:8980/v2/block-headers?limit=2' | jq

# filter by timestamp
curl -Ss 'http://127.0.0.1:8980/v2/block-headers?limit=2&after-time=2024-10-01T00:00:00Z' | jq

# filter by block proposer
curl -Ss 'http://127.0.0.1:8980/v2/block-headers?proposer=FNETC46DGTSSDHA6C54FWEGZ3Z5ADE4YAPYQTX5VEE2YGU5NFPAWTRANCE&limit=1' | jq

# filter by absent participation accounts
curl -Ss 'http://127.0.0.1:8980/v2/block-headers?absent=WXN65H5M7BRSABP545OES2NCMFGE7R7OICDZSXCTP5H5H2CHXCDKFQTF6U&limit=1' | jq

# filter by expired participation accounts
curl -Ss 'http://127.0.0.1:8980/v2/block-headers?expired=2D2HFM3EIYFNMBNLWZPK5E4SWVN6SR7RDSVCBQ4Z6HRHE26DBT6WQYO6XA&limit=1' | jq

So far there are no automated tests for this feature. Maybe the tests could look like these (mutatis mutandis):

Performance

The underlying SQL query has been optimized to create efficient execution plans in CockroachDB. This optimization made the code harder to comprehend, it could probably be simpler for the PostgreSQL case.

CLAassistant commented 1 week ago

CLA assistant check
All committers have signed the CLA.