Go: Allow fetching multiple accounts using /accounts Horizon endpoint

Created on 13 Nov 2018  路  6Comments  路  Source: stellar/go

Many Stellar usage scenarios require fetching up-to-date information about more than one account from Horizon. Even for such simple things like an ordinal payment, the application needs to fetch both source (to get the sequence) and destination (to check whether it exists and has the required trustline) accounts. Smart contracts and other advanced use cases may require fetching more than two accounts from the Horizon.

Proposed query format:

GET /accounts?account={pub_key1}&account={pub_key2}&account={pub_key3}

Example:

GET https://horizon.stellar.org/accounts?account=GCBSNA7IGGUNY4LZDDIR2ICD6LSQXMT5DOQF76ELXCJGNNR5KMAVYTQC&account=GCRWGLWEMEJWV7WAASOYWUMB6UCUYYSRL6SFZZD6Z4NFO4DHUBPFX7LR

The result should be atomic. API should fetch current state of all requested accounts in one DB query which automatically returns consistent state despite any concurrent updates following the DB transaction isolation policy

Benefits:

  • CPU and bandwidth resources economy for both client and server.
  • Significant HTTP requests reduction for the /accounts endpoint.
  • Consistent state for returned accounts.
horizon-api

All 6 comments

+1 on this one.

Leaving this open but I think we should use something like GraphQL as it gives you better control of query and response.

+1

+1 on using GraphQL. You could also layer it on top of horizon as a separate service but then you still end up hitting horizon API multiple times (although possibly from the same datacenter so you'd get latency benefits for the client but no benefits for single queries and consistency)

I think it's worth adding this feature to the REST API before we do a full GraphQL implementation.

The main question here is: do you need this for consistency or speed?

If the answer is consistency, it would require a rearchitecture of Horizon's web module to support running batched HTTP requests in a REPEATABLE READ transaction. This has many implications like impact on stellar-core DB, rate limiting, good design for such API calls etc. In short: not trivial but we can run some experiments.

If the answer is speed, Horizon supports http/2 that has batching built-in so you should just use that.

Was this page helpful?
0 / 5 - 0 ratings