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

services/horizon/internal/expingest: Remove orderbook graph from ingestion system #2639

Merged
merged 5 commits into from
Jun 1, 2020

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented May 31, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    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

Follow-up to #2630 which removes orderbook graph ingestion.

Why

After #2630 , the horizon ingesting nodes no longer need to maintain an in memory order book. Instead, the request serving horizon instances will populate their order books by polling offers from the horizon db. This polling process is downstream of ingestion.

Known limitations

[ N/A]

@cla-bot cla-bot bot added the cla: yes label May 31, 2020
@tamirms tamirms force-pushed the orderbook-stream-followup branch 2 times, most recently from 490e9bc to f037b2e Compare May 31, 2020 11:39
@tamirms tamirms force-pushed the orderbook-stream-followup branch from f037b2e to fbd36c2 Compare June 1, 2020 13:45
@tamirms tamirms marked this pull request as ready for review June 1, 2020 15:31
Copy link
Contributor

@bartekn bartekn left a comment

Choose a reason for hiding this comment

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

LGTM! Just minor comments.

log.WithField("ingestLedger", ingestLedger).
WithField("lastIngestedLedger", lastIngestedLedger).
Info("bumping ingest ledger to next ledger after ingested ledger in db")
ingestLedger = lastIngestedLedger + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should transition state?

Suggested change
ingestLedger = lastIngestedLedger + 1
return resume(lastIngestedLedger), nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's better as is because at this moment in the code we have the select for update lock. if we transition to the state we need to release the select for update and the next node would need to acquire the select for update lock. I think by bumping the ingestLedger we reduce latency in the ingestion process

services/horizon/internal/expingest/orderbook.go Outdated Show resolved Hide resolved
const verificationFrequency = time.Hour
const (
verificationFrequency = time.Hour
updateFrequency = 30 * 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.

Can we change it to 5 sec. so it updates with every ledger (on average)?

Suggested change
updateFrequency = 30 * time.Second
updateFrequency = 5 * time.Second

services/horizon/internal/expingest/orderbook.go Outdated Show resolved Hide resolved
@tamirms tamirms merged commit 62103e5 into stellar:master Jun 1, 2020
@tamirms tamirms deleted the orderbook-stream-followup branch June 1, 2020 19:49
bartekn pushed a commit that referenced this pull request Jun 2, 2020
…ple ledgers (#2649)

Before #2639 we were updating the order book graph via ingestion on
every single ledger. The order book graph was implemented with the
expectation that you must apply changes for every single ledger and no
ledgers should be skipped.

However, we can no longer maintain that invariant because now we are
applying updates to the order book graph via the OrderBookStream. The
OrderBookStream periodically polls for new / updated offers from the
Horizon DB. It is possible that ingestion has advanced by more than one
ledger since the last time OrderBookStream updated the order book graph.

Therefore we must relax the restrictions for how updates are applied to
an order book graph. We still require ledgers to be strictly increasing
when applying updates to an order book graph. However, now we allow
updates to span multiple ledgers.

We also allow you to remove an offer which is not present in the order
book. Consider the case where you apply updates from ledger x. Let's say
the next time we update the order book graph ingestion has already
advanced to x+2. It is possible that an offer was created in ledger x+1
and in ledger x+2 we are removing the offer. However, our graph was last
updated at ledger x, so when we try to remove the offer which was
created in ledger x+1 we will panic unless we deliberately skip over
offers which are not present in the order book.
@tamirms tamirms added this to the Horizon 1.4.0 milestone Jun 5, 2020
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.

2 participants