stellar / go

Stellar's public monorepo of go code
https://stellar.org/developers
Apache License 2.0
1.29k stars 503 forks source link

Allow fetching multiple accounts using /accounts Horizon endpoint #760

Open orbitlens opened 5 years ago

orbitlens commented 5 years ago

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:

PedityOfficial commented 5 years ago

+1 on this one.

bartekn commented 5 years ago

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

abedalzain commented 5 years ago

+1

pselden commented 5 years ago

+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)

tomquisel commented 5 years ago

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

bartekn commented 5 years ago

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.