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

Call RPC getHealth during ingestion #77

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Conversation

aditya1702
Copy link

@aditya1702 aditya1702 commented Nov 15, 2024

Closes #62

This PR introduces the following:

  • Spin up a goroutine that keeps checking RPC health every 5 seconds.
  • Use this new health check service within the wallet-backend ingestion process to make sure RPC is always healthy. The ingestion will wait if RPC becomes unhealthy at any point and will resume from the last ingested ledger.
  • Add a way for ingestion to be in sync with RPC's ledger range:
    • If the wallet-backend is behind RPC's oldest ledger, then it will start ingestion from that ledger sequence.
    • If RPC is behind, then ingestion will wait for it to catch up with wallet-backend.
  • Add unittests for the new features.

@aditya1702 aditya1702 marked this pull request as ready for review November 18, 2024 20:51
@aditya1702 aditya1702 changed the title [WIP] Call RPC getHealth during ingestion Call RPC getHealth during ingestion Nov 19, 2024
@@ -49,7 +56,7 @@ type Transaction struct {
ResultXDR string `json:"resultXdr"`
ResultMetaXDR string `json:"resultMetaXdr"`
Ledger int64 `json:"ledger"`
DiagnosticEventsXDR string `json:"diagnosticEventsXdr"`
DiagnosticEventsXDR []string `json:"diagnosticEventsXdr"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this an array now?

Copy link
Author

@aditya1702 aditya1702 Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gouthamp-stellar Ummm, this has always been an array since the time I added the GetTransactions endpoint - https://github.com/stellar/stellar-rpc/pull/174/files#diff-5276db8001730f32b267cab637b316958b69aef6f8184343338855fdc118b700R66

I was actually confused when I got a parsing error in wallet-backend when it was just a string. And also the fact that it has been working fine before too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

case ingestLedger > resp.LatestLedger:
log.Debugf("waiting for RPC to catchup to ledger %d (latest: %d)",
ingestLedger, resp.LatestLedger)
time.Sleep(5 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this sleep of 5 seconds necessary? What happens if you remove it?

@gouthamp-stellar
Copy link
Contributor

This mostly looks good, just one observation - once getHealth returns an actual healthy response, the expectation is that the ingestor should never get a "ledger out of range" type error when calling getTransactions. We just need to be sure that this implementation supports that

Comment on lines +103 to +108
case resp := <-rpcHeartbeat:
switch {
// Case-1: wallet-backend is running behind rpc's oldest ledger. In this case, we start
// ingestion from rpc's oldest ledger.
case ingestLedger < resp.OldestLedger:
ingestLedger = resp.OldestLedger

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the desired functionality? Wouldn't a gap in the wallet backend's history be created if it was behind RPC's oldest ledger?

Comment on lines +125 to +128
err = m.ingestPayments(ctx, ledgerTransactions)
if err != nil {
return fmt.Errorf("error ingesting payments: %w", err)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming ingestPayments is a function that ingests all inbound payments, since we have another function processTSSTransactions that I assume ingests all outbound payments? Maybe we should update the function names to make that more clear?

Actually, I'm assuming both functions commit changes to the DB, which means that its possible to process inbound payments for a ledger and fail to process the outbound payments. If thats true, wouldn't this result in a bad state where we wouldn't be able to reingest the ledger, since retries would fail at the inbound processing step?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have the wallet backend's ingestor / api services call RPC's getHealth endpoint before calling RPC methods
3 participants