-
Notifications
You must be signed in to change notification settings - Fork 505
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
exp/services/captivecore/internal: Add HTTP server for managing a remote captive core instance #2896
Conversation
|
||
mux.Post("/prepare-range", func(w http.ResponseWriter, r *http.Request) { | ||
ledgerRange := ledgerbackend.Range{} | ||
if err := json.NewDecoder(r.Body).Decode(&ledgerRange); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think form urlencoded would be much simpler here. JSON is fine but we don't really need it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's slightly easier for the client code to use JSON because serializing to JSON would require less code than constructing an HTTP form. Also, it is nice to make the content type consistent between the request and response bodies.
// LedgerResponse is the response for the GetLedger command. | ||
type LedgerResponse struct { | ||
Present bool `json:"present"` | ||
Ledger xdr.LedgerCloseMeta `json:"ledger"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it render as base64? If not the value will be really hard to parse.
@bartekn can you take another look? I've added tests now |
Co-authored-by: Bartek Nowotarski <[email protected]>
…lient (#2918) This PR is a follow up to #2896 . In #2896 we added an http server wrapper around stellar core so that we could run a captive core instance on a separate machine from horizon. This PR adds the corresponding HTTP client for the captive core server. The client satisfies the LedgerBackend interface and can be plugged into Horizon's ingestion system.
PR Checklist
PR Structure
otherwise).
services/friendbot
, orall
ordoc
if the changes are broad or impact manypackages.
Thoroughness
.md
files, etc... affected by this change). Take a look in the
docs
folder for a given service,like this one.
Release planning
needed with deprecations, added features, breaking changes, and DB schema changes.
semver, or if it's mainly a patch change. The PR is targeted at the next
release branch if it's not a patch change.
What
Add HTTP server for managing a remote captive core instance.
Why
From #2841 :
The current implementation of Captive Stellar-Core streams meta stream using a filesystem pipe. This implies that both Horizon and Stellar-Core have to be deployed to the same server. One of the disadvantages of such requirement is a need for detailed per-process monitoring to be able to connect potential issues (like memory leaks) to the specific service.
To solve this we can build a thin wrapper around CaptiveStellarCore backend that exposes a simple RPC/HTTP API similar to LedgerBackend interface:
The full solution requires a server and a client that can consume the API.
A server can be a subcommand on horizon that exposes the CaptiveStellarCore object API using either the net/rpc package or HTTP. It has the same require params as CaptiveStellarCore. A server is a singleton, meaning it can start a single stellar-core process, thus should be used by a single Horizon instance.
A client, RemoteCaptiveStellarCore implementation of LedgerBackend interface is part of exp/ingest/ledgerbackend and accepts a connection params to a server.
Known limitations
I will add tests in a subsequent commit. Right now I'm looking for a preliminary review