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

txnbuild: Add support for new CAP-21 preconditions. #4303

Merged
merged 19 commits into from
Mar 25, 2022

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Mar 23, 2022

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

Adds support for new CAP-21 preconditions. This starts with a very simple API change:

@@ -212,7 +212,7 @@ type Transaction struct {
     sourceAccount SimpleAccount
     operations    []Operation
     memo          Memo
-    timebounds    Timebounds
+    preconditions Preconditions
 }

@@ -799,23 +799,23 @@ type TransactionParams struct {
     BaseFee       int64
     Memo          Memo
-    Timebounds    Timebounds
+    Preconditions Preconditions
 }

and evolves into all of the changes necessary to make that happen: the new Preconditions structure (creation, validation, XDR encoding, etc.) and coalescing between V1 conditions (timebounds only) and V2 conditions (CAP-21, incl. timebounds).

Why

Closes #4282.

@Shaptic Shaptic added txnbuild 2nd-generation transaction build library for Go SDK Protocol 19 Support cap-21, cap-40 and sep-23 in Horizon & SDKs labels Mar 23, 2022
@Shaptic Shaptic requested review from leighmcculloch and a team March 23, 2022 19:50
@Shaptic Shaptic self-assigned this Mar 23, 2022
@Shaptic Shaptic marked this pull request as ready for review March 23, 2022 20:42
}

func (cond *Preconditions) ValidateSigners() bool {
return len(cond.ExtraSigners) <= 2
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 validation rule worth maintaining on client side, or let it get submitted and have core return txsub errors since it is source of truth on this aspect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will already blow up client-side because the XDR won't encode (not stellar core validation):

SignerKey extraSigners<2>;

this was just being a little friendlier about it, since it's not fixed to be 2 w/in Preconditions. no strong opinion on keeping it, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, on the java sdk side, I checked the generated java from xdrgen, PreconditionsV2.java, it doesn't capture the SignerKey extraSigners<2> size limit like it is on go with xdrmaxsize, I may need to hardcode that as a constant or just document that it's by default 2 and submission will be final validation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's interesting - seems like a limitation of the generator? 🤔 definitely think it's worth a better error message from the SDK if possible

Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

👏🏻. A few comments inline.

txnbuild/timebounds.go Outdated Show resolved Hide resolved
txnbuild/preconditions.go Outdated Show resolved Hide resolved
txnbuild/preconditions.go Outdated Show resolved Hide resolved
txnbuild/preconditions.go Outdated Show resolved Hide resolved
txnbuild/preconditions_test.go Outdated Show resolved Hide resolved
txnbuild/preconditions_test.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
txnbuild/transaction.go Outdated Show resolved Hide resolved
@Shaptic
Copy link
Contributor Author

Shaptic commented Mar 24, 2022

@leighmcculloch @sreuland I made the breaking change to move TransactionParams.Timebounds -> TransactionParams.Preconditions.Timebounds in 468e7de. Like I mentioned, it's simple but broad, so let me know what you guys think.

@Shaptic
Copy link
Contributor Author

Shaptic commented Mar 24, 2022

I've also forked off an alternative, non-breaking method. This one keeps Preconditions.timebounds private, but makes it a non-pointer. The branch diff is here: horizon-protocol-19...Shaptic:txnbuild-tx-conds-alternative, but the main change I think we all care about is here (no more coalescing or pointer voodoo).

Let me know which approach y'all like better 🕵️‍♂️ I personally think the latter (non-breaking) is not bad and an improvement over the issues everyone raised above. It aligns closely to (3) from #4303 (comment).

Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

🎉 I like the breaking change moving TimeBounds. While it is a breaking change, I think the alternatives all come with significant tradeoffs.

I left some requests (❗), and also some suggestions (💡).

txnbuild/preconditions.go Outdated Show resolved Hide resolved
txnbuild/preconditions.go Outdated Show resolved Hide resolved
txnbuild/preconditions_test.go Outdated Show resolved Hide resolved
txnbuild/preconditions_test.go Show resolved Hide resolved
return clone
}

func clonePreconditions(precond Preconditions) Preconditions {
Copy link
Member

Choose a reason for hiding this comment

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

💡 The way this set of tests work by cloning things is particularly complicated. How about just writing out each input verbosely? It would be much easier to understand and maintain.

The inspiration for why I'm suggesting this is that DRY tests are often harder to maintain:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obviously your perspective has a lot of weight, so I'm trying to maximize my own edification here by offering counterarguments. I feel like I should write my own blog post in response 😂 so a couple of thoughts follow.


How is it easier to understand? More than once I've opened a test file for a complex piece of code, and seen what appeared to be a lot of duplication across tests. It begged a really important question, though: are they actually the same? If you're reading page after page of code for related tests, you need to read each test really carefully to identify where it differs. If the "setup" is kept in one place, the tests can focus exclusively on their differences. That makes it easier to understand, not harder, imo.

Small case study: Take a look at the various operation tests in txnbuild/transaction_test.go. Different test groups have different authors, so irrelevant deltas get introduced. Why do the sequence numbers differ across the tests? Is it just an author change, or does it impact the test somehow? Some of them use NewTransaction, while others use newSignedTransaction. Does that make a difference, and why? Should I pay attention to each test's TransactionParams, or are they just copy-pasted across all test cases?

All of these questions are overhead to understanding the tests. If there was a single method that prepared the common parts of the test case, each one could focus on the differences between them. That's the goal of the "modifier" design I threw in: it's very clear (though I will admit I'm biased as the author and reader) that the only difference between each subtest is the fields set on the two preconditions.


Then there's the aspect of maintainability. How does that get easier? Within this PR itself, we had a breaking change re: timebounds that resulted in many lines changing. If there was a common place for the tests to prepare things (like for transaction_test.go as I mentioned above), there'd be a single delta of Timebounds: NewInfiniteTimeout() -> Preconditions: Preconditions{Timebounds: NewInfiniteTimeout()}, because that line is common to all of the tests. Now, as a reviewer I'd have to look at each line that changed and make sure it was updated correctly and no copy-paste or search&replace error snuck in.

Adding tests becomes a chore, too. Like I mentioned earlier (#4303 (comment)), there are a lot of ways to combine preconditions, now. We want all of them to be possible, and of course we can't exhaust them all (or can rely on bug reports for ones that somehow aren't possible), but it'd be nice to get the basics covered. Adding a new combination is a few LoC. Furthermore, extending the tests (like you suggested above to add a round-trip, #4303 (comment)) is so much easier when they're all testing common functionality. That extension took ~7 LoC in cf15638. If the tests were split out, that'd be N copy-pastes and 7*N lines of testing code that all do the same thing.


I guess I just... don't really get it? Yes, there's some degree of "cleverness" when reading the current code for the first time, but it comes at the (to me, huge) benefit of very clearly isolating the differences between each subtest case and allowing simple extensibility to add new combinations of preconditions.

As a final, disjoint thought: Something that makes even more sense than my current list of subtests is just "fuzzing" the fields on Precondition to ensure they all work. That's the ultimate goal here, anyway: answering the question of "Can all valid preconditions be created?"

Copy link
Member

Choose a reason for hiding this comment

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

It's a tradeoff for sure. Even if DRY tests look good on day one, imx they are harder to maintain over time, because the way they are structured are making assumptions about the tests we'll have to write in the future or the ways we'll need to modify these tests, requiring test refactors, etc. My comment was a suggestion, not a request.

If you are going to keep the cloning, might I suggest replacing it with a helper that creates the original structure. This way you don't need to write cloning code. (Cloning code is unavoidably brittle code.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point about test evolution. Cross that bridge when we get to it, then? 😆 Either way, just want to reiterate that I really appreciate the feedback and suggestions, as it makes me challenge my own assumptions and get a better understanding of the trade-offs I may be making w/o realizing.

You're on the money about cloning: I hated that aspect of it. I opted to make "test fixtures" with a helper function in 84c882e8c9bd52ef93954392619d2e686f503882; I think it's much less brittle now overall!

@Shaptic
Copy link
Contributor Author

Shaptic commented Mar 24, 2022

Last round of feedback, I hope, @leighmcculloch and @stellar/horizon-committers? 🙏

To make reviews easier, here are the files with relevant (i.e. not just adapting to the breaking TransactionParams delta) changes:

  • new files: txnbuild/ledgerbounds.go, txnbuild/preconditions.go, txnbuild/preconditions_test.go
  • most of txnbuild/transaction.go
  • the top of txnbuild/transaction_test.go
  • txnbuild/timebounds.go
  • xdr/transaction_envelope.go
  • txnbuild/CHANGELOG.md

@Shaptic Shaptic requested a review from a team March 24, 2022 21:55
Comment on lines 5 to 8
// Ledgerbounds represent a transaction precondition that controls the ledger
// range for which a transaction is valid. Setting MaxLedger = 0 indicates there
// is no maximum ledger.
type Ledgerbounds struct {
Copy link
Member

Choose a reason for hiding this comment

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

Typo: Ledgerbounds => LedgerBounds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency with txnbuild.Timebounds? 🤔

Copy link
Member

@leighmcculloch leighmcculloch Mar 24, 2022

Choose a reason for hiding this comment

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

You know, we could safely fix the Timebounds typo as part of this protocol release. By doing these things:

  • We're already moving the Timebounds field, so simply name the new field TimeBounds.
  • We can rename txnbuild.Timebounds to txnbuild.TimeBounds.
  • We can use a type alias to specify that txnbuild.Timebounds is the same type as txnbuild.TimeBounds. Just add this:
    type Timebounds = TimeBounds
    The = will make it so that whenever the compiler sees Timebounds it'll pretend it saw TimeBounds. All the functions will be automatically lifted. No type casting required because they are one type, not two. Note this is different to type definitions that do not have the equals.

Copy link
Contributor Author

@Shaptic Shaptic Mar 24, 2022

Choose a reason for hiding this comment

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

I'm good with that! We still have inconsistencies (see #4297 (comment)), and we can't rename the constructors w/o more breaking changes (e.g. NewTimebounds), but it's still progress 👷‍♂️. Both renames done in latest push 👍

Co-authored-by: Leigh McCulloch <[email protected]>
@Shaptic Shaptic merged commit 649016c into stellar:horizon-protocol-19 Mar 25, 2022
)

// Preconditions is a container for all transaction preconditions.
type Preconditions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the benefit for using this abstraction model rather than using xdr.PreconditionsV2 direct? This and TimeBounds and LedgerBounds appear to be 1-1 proxy of their xdr counterparts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, didn't see this comment for some reason. They're 1-to-1 now, but the txnbuild package in general avoids exposing XDR to SDK consumers.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, see that de-coupling at top level, sounds good, there are nested references from here into xdr types such as SignerKey and Duration, and was looking at it from bottom up, thanks!

Shaptic added a commit that referenced this pull request Apr 19, 2022
* all: Add Protocol 19 XDR and update StrKey to support Signed Payloads (#4279)
* services/horizon: Support new account fields for protocol-19. (#4294)
* xdr, keypair: Add helpers to create CAP-40 decorated signatures (#4302)
* services/horizon: Update txsub queue to account for new CAP-21 preconditions (#4301)
* txnbuild: Add support for new CAP-21 preconditions. (#4303)

Adds support for new CAP-21 preconditions with a simple, but breaking API
change:

TransactionParams.Timebounds -> TransactionParams.Preconditions.TimeBounds

You can now pass a lot more preconditions to a Transaction (including
timebounds), and these are managed by the new Preconditions object. All of the
XDR abstractions are hidden away behind this object.

* services/horizon: Support new CAP-21 transaction conditions (#4297)
* txnbuild: Complete rename, avoid using XDR types in `TransactionParams`. (#4307)
* all: Update Protocol 19 XDR to the latest (#4308)
* horizon: Set up protocol 19 integration tests infrastructure (#4312)
* horizon: Test new protocol 19 account fields (#4322)
* horizon: Add integration test for extra signers using tx preconditions (#4305)
* horizon: Add transaction submission test for Protocol 19 (#4327)
* services/horizon: Use `bigint` over `timestamp` to accommodate large years (#4337)

This is necessary because PostgreSQL puts "reasonable" limitations
on how dates can be represented. Because the state verifier test
will generate random int64s for the V3 account extension field
introduced in CAP-21, this will blow up on inserting into the DB
with errors like:

    pq: date/time field value out of range: "120911623444-02-01 21:35:20Z"

because PostgreSQL only allows years up to 5874897
(https://stackoverflow.com/a/36446977).

Technically, since this field is not user-controlled and comes
directly from Stellar Core, we would not see this in practice.

However, it's a more durable fix to stop the extra layer of
"interpretation" of this value and just treat it like it is:
a 64-bit integer that happens to represent a UNIX timestamp.

* services/horizon: Change `min_account_sequence_age` column from `bigint` to string (#4339)
* Add changelog details and prep v10.0.0 SDK release

Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: erika-sdf <[email protected]>
Co-authored-by: Paul Bellamy <[email protected]>
Co-authored-by: Shawn Reuland <[email protected]>
Co-authored-by: shawn <[email protected]>
Co-authored-by: George <[email protected]>
Shaptic added a commit that referenced this pull request May 24, 2022
* services/ticker: ingest assets optimizations (#4218)
* Add CHANGELOG entry for Horizon 2.14.0 release (#4208) (#4220)
* Make sure we test reingestion for all possible operations (#4231)
* services/horizon: Allow captive core to run with sqlite database (#4092)
* services/horizon: Release DB connection in /paths when no longer needed (#4228)
* services/horizon: Exclude trades with >10% rounding slippage from trade aggregations (#4178)
* all: staticcheck fixes (#4239)
* Migrate Horizon integration tests to GitHub Actions (#4242)
* Fix StreamAllLiquidityPools and StreamAllOffers (#4236)
* all: run builds and tests with go1.18rc1 (#4143)
* all: cache go module downloads and other build and test artifacts (#3727)
* services/horizon: Add LedgerHashStore to Captive-Core config (#4251)
* all: migrate the rest of the CircleCI jobs to GitHub Actions (#4250)
* horizon: Fix GitHub action problem with verify-range push in master (#4253)
* all: fix ci ref_protected check for caching (#4254)
* Switch over from CircleCI to GitHub A tions (#4256)
* all: [GitHub actions] Reset the module and build cache in master/protected (#4266)
* Forgot to add sudo in #4266 (#4270)
* all: More go-setup github action fixes (#4274)
* xdr: add instructions for generating xdr (#4280)
* services/ticker: cache tomls during scraping (#4286)
* services/ticker: use log fields during asset ingestion (#4288)
* services/ticker: reduce size of toml cache in memory (#4289)
* historyarchive: add --skip-optional flag (#3906)
* all: Add Protocol 19 XDR and update StrKey to support Signed Payloads (#4279)
* Replace keybase with publicnode in the stellar core config (#4291)
* Fix captive core tests to write to /tmp, instead of polluting the repo (#4296)
* all: remove go1.16 add go1.18 (#4284)
* Rename methods and functions in submission system (#4298)
* PR feedback (#4300)
* Support new account fields for protocol-19. (#4294)
* xdr, keypair: Add helpers to create CAP-40 decorated signatures (#4302)
* services/horizon: Update txsub queue to account for new CAP-21 preconditions (#4301)
* Uncomment StateVerifier test that generates account v3 extensions now that they are implemented. (#4304)
* txnbuild: Add support for new CAP-21 preconditions. (#4303)
* services/horizon: Support new CAP-21 transaction conditions (#4297)
* txnbuild: Complete rename, avoid using XDR types in `TransactionParams`. (#4307)
* all: Update Protocol 19 XDR to the latest (#4308)
* services/horizon: Add a rate limit for path finding requests. (#4310)
* clients/horizonclient: fix multi-parameter url for claimable balance query (#4248)
* all: Fix Horizon integration tests (#4292)
* horizon: Fix integration tests (#4314)
* horizon: Set up protocol 19 integration tests infrastructure (#4312)
* all: Change outdated CircleCI build badge (#4324)
* horizon: Test new protocol 19 account fields (#4322)
* all: update staticcheck to 2022.1 (#4326)
* all: remove go.list and related docs (#4328)
* horizon: Add transaction submission test for Protocol 19 (#4327)
* Horizon v2.16.1 CHANGELOG (#4333)
* Revert "Pin go versions temporarily" (#4338)
* services/horizon: Use `bigint` over `timestamp` to accommodate large years (#4337)
* xdr: Update xdrgen (#4341)
* services/horizon: Change `min_account_sequence_age` column from `bigint` to string (#4339)
* services/horizon: Bump stellar-core to v19.0.0rc1 for Horizon tests (#4345)
* services/horizon: expose supported protocol version on root endpoint (#4347)
* horizon: Small transaction submission refactoring (#4344)
* services/horizon: Pass through nil ExtraSigners to avoid nil pointer deref (#4349)
* doc: rename license file (#4350)
* all: upgrade dep github.com/valyala/fasthttp (#4351)
* services/horizon: Promote Stellar Core to v19.0.0 stable. (#4353)
* services/horizon/integration: Precondition edge cases and V18->19 upgrade boundary. (#4354)
* xdr: Synchronizes monorepo XDR with Stellar Core (#4355)
* services/horizon: Properly allow nullable Protocol 19 account fields (#4357)
* services/friendbot: include txhash in logs (#4359)
* services/horizon: Improve transaction precondition `omitempty` behavior (#4360)
* tools/horizon-cmp: Improve panic error message (#4365)
* services/horizon: Merge stable v2.17.0 back into master: (#4363)
* Use UNIX timestamps instead of RFC3339 strings for timebounds. (#4361)
* xdrgen: remove gemfile and rakefile to just use docker for the xdrgen (#4366)
* Conservatively limit the number of DB connections of integration tests (#4368)
* internal/integrations: db_test should drop test db instances when finished (#4185)
* GHA: Bump Core version to v19.0.1 in Horizon workflows. (#4378)
* services/horizon, clients/horizonclient: Allow filtering ingested transactions by account or asset. (#4277)
* Push stellar/ledger-state-diff images from Github actions (#4380)
* services/horizon: Fixes copy-paste typo in `--help` text (#4383)
* tools/alb-replay: Add new features to alb-replay (#4384)
* services/horizon: Optimize claimable balances query to limit records earlier (#4385)
* support/db, services/horizon/internal: Configure postgres client connection timeouts for read only db (#4390)
* Refactor trade aggregation query. (#4389)
* services/horizon/internal/db2/history: Implement StreamAllOffers using batches (#4397)
* Add flag to disable path finding endpoints (#4399)

Co-authored-by: stfung77 <[email protected]>
Co-authored-by: Leigh McCulloch <[email protected]>
Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: Paul Bellamy <[email protected]>
Co-authored-by: Bartek Nowotarski <[email protected]>
Co-authored-by: tamirms <[email protected]>
Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: Graydon Hoare <[email protected]>
Co-authored-by: Satyam Zode <[email protected]>
Co-authored-by: Satyam Zode <[email protected]>
Co-authored-by: erika-sdf <[email protected]>
Co-authored-by: iateadonut <[email protected]>
Co-authored-by: Shawn Reuland <[email protected]>
Co-authored-by: shawn <[email protected]>
Co-authored-by: Shivendra Mishra <[email protected]>
Co-authored-by: Jacek Nykis <[email protected]>
Co-authored-by: jacekn <[email protected]>
Shaptic added a commit that referenced this pull request Jan 9, 2024
* exp/lighthorizon: Add initial support for XDR serialization (#4369)
* exp/lighthorizon: Improve trie tests to avoid raw comparisons/outputs. (#4373)
* exp/lighthorizon: Add XDR marshalling for the `TrieNode` structure. (#4375)
* Add encoding stdlib interfaces
* lighthorizon: Sync with upstream master branch (#4404)
* services/ticker: ingest assets optimizations (#4218)
* Add CHANGELOG entry for Horizon 2.14.0 release (#4208) (#4220)
* Make sure we test reingestion for all possible operations (#4231)
* services/horizon: Allow captive core to run with sqlite database (#4092)
* services/horizon: Release DB connection in /paths when no longer needed (#4228)
* services/horizon: Exclude trades with >10% rounding slippage from trade aggregations (#4178)
* all: staticcheck fixes (#4239)
* Migrate Horizon integration tests to GitHub Actions (#4242)
* Fix StreamAllLiquidityPools and StreamAllOffers (#4236)
* all: run builds and tests with go1.18rc1 (#4143)
* all: cache go module downloads and other build and test artifacts (#3727)
* services/horizon: Add LedgerHashStore to Captive-Core config (#4251)
* all: migrate the rest of the CircleCI jobs to GitHub Actions (#4250)
* horizon: Fix GitHub action problem with verify-range push in master (#4253)
* all: fix ci ref_protected check for caching (#4254)
* Switch over from CircleCI to GitHub A tions (#4256)
* all: [GitHub actions] Reset the module and build cache in master/protected (#4266)
* Forgot to add sudo in #4266 (#4270)
* all: More go-setup github action fixes (#4274)
* xdr: add instructions for generating xdr (#4280)
* services/ticker: cache tomls during scraping (#4286)
* services/ticker: use log fields during asset ingestion (#4288)
* services/ticker: reduce size of toml cache in memory (#4289)
* historyarchive: add --skip-optional flag (#3906)
* all: Add Protocol 19 XDR and update StrKey to support Signed Payloads (#4279)
* Replace keybase with publicnode in the stellar core config (#4291)
* Fix captive core tests to write to /tmp, instead of polluting the repo (#4296)
* all: remove go1.16 add go1.18 (#4284)
* Rename methods and functions in submission system (#4298)
* PR feedback (#4300)
* Support new account fields for protocol-19. (#4294)
* xdr, keypair: Add helpers to create CAP-40 decorated signatures (#4302)
* services/horizon: Update txsub queue to account for new CAP-21 preconditions (#4301)
* Uncomment StateVerifier test that generates account v3 extensions now that they are implemented. (#4304)
* txnbuild: Add support for new CAP-21 preconditions. (#4303)
* services/horizon: Support new CAP-21 transaction conditions (#4297)
* txnbuild: Complete rename, avoid using XDR types in `TransactionParams`. (#4307)
* all: Update Protocol 19 XDR to the latest (#4308)
* services/horizon: Add a rate limit for path finding requests. (#4310)
* clients/horizonclient: fix multi-parameter url for claimable balance query (#4248)
* all: Fix Horizon integration tests (#4292)
* horizon: Fix integration tests (#4314)
* horizon: Set up protocol 19 integration tests infrastructure (#4312)
* all: Change outdated CircleCI build badge (#4324)
* horizon: Test new protocol 19 account fields (#4322)
* all: update staticcheck to 2022.1 (#4326)
* all: remove go.list and related docs (#4328)
* horizon: Add transaction submission test for Protocol 19 (#4327)
* Horizon v2.16.1 CHANGELOG (#4333)
* Revert "Pin go versions temporarily" (#4338)
* services/horizon: Use `bigint` over `timestamp` to accommodate large years (#4337)
* xdr: Update xdrgen (#4341)
* services/horizon: Change `min_account_sequence_age` column from `bigint` to string (#4339)
* services/horizon: Bump stellar-core to v19.0.0rc1 for Horizon tests (#4345)
* services/horizon: expose supported protocol version on root endpoint (#4347)
* horizon: Small transaction submission refactoring (#4344)
* services/horizon: Pass through nil ExtraSigners to avoid nil pointer deref (#4349)
* doc: rename license file (#4350)
* all: upgrade dep github.com/valyala/fasthttp (#4351)
* services/horizon: Promote Stellar Core to v19.0.0 stable. (#4353)
* services/horizon/integration: Precondition edge cases and V18->19 upgrade boundary. (#4354)
* xdr: Synchronizes monorepo XDR with Stellar Core (#4355)
* services/horizon: Properly allow nullable Protocol 19 account fields (#4357)
* services/friendbot: include txhash in logs (#4359)
* services/horizon: Improve transaction precondition `omitempty` behavior (#4360)
* tools/horizon-cmp: Improve panic error message (#4365)
* services/horizon: Merge stable v2.17.0 back into master: (#4363)
* Use UNIX timestamps instead of RFC3339 strings for timebounds. (#4361)
* xdrgen: remove gemfile and rakefile to just use docker for the xdrgen (#4366)
* Conservatively limit the number of DB connections of integration tests (#4368)
* internal/integrations: db_test should drop test db instances when finished (#4185)
* GHA: Bump Core version to v19.0.1 in Horizon workflows. (#4378)
* services/horizon, clients/horizonclient: Allow filtering ingested transactions by account or asset. (#4277)
* Push stellar/ledger-state-diff images from Github actions (#4380)
* services/horizon: Fixes copy-paste typo in `--help` text (#4383)
* tools/alb-replay: Add new features to alb-replay (#4384)
* services/horizon: Optimize claimable balances query to limit records earlier (#4385)
* support/db, services/horizon/internal: Configure postgres client connection timeouts for read only db (#4390)
* Refactor trade aggregation query. (#4389)
* services/horizon/internal/db2/history: Implement StreamAllOffers using batches (#4397)
* Add flag to disable path finding endpoints (#4399)

Co-authored-by: stfung77 <[email protected]>
Co-authored-by: Leigh McCulloch <[email protected]>
Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: Paul Bellamy <[email protected]>
Co-authored-by: Bartek Nowotarski <[email protected]>
Co-authored-by: tamirms <[email protected]>
Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: Graydon Hoare <[email protected]>
Co-authored-by: Satyam Zode <[email protected]>
Co-authored-by: Satyam Zode <[email protected]>
Co-authored-by: erika-sdf <[email protected]>
Co-authored-by: iateadonut <[email protected]>
Co-authored-by: Shawn Reuland <[email protected]>
Co-authored-by: shawn <[email protected]>
Co-authored-by: Shivendra Mishra <[email protected]>
Co-authored-by: Jacek Nykis <[email protected]>
Co-authored-by: jacekn <[email protected]>

* Explain map and reduce commands

* exp/lighthorizon: Refactor single-process index builder. (#4410)

* Refactor index builder:
 - allow worker count to be a command line parameter
 - split work by checkpoints rather than ledgers
 - move actual index insertion work to helpers
 - move progress bar into helpers
 - simplify participants code, payments vs. all
* Properly work on a checkpoint range at a time:
 - previously, it was just arbitrary 64-ledger chunks which is not as helpful
* Define a generic module processing function
* Move index building into a separate object
* Fix off-by-one error in checkpoint index builder:
  - Keeping this as-is would mean that the first chunk of ledgers
    will be "Checkpoint 0" which doesn't make sense in the bitmap
  - Calling index.setActive(0) is essentially a no-op, because no
    bit will ever be set.
  - In the case of an empty index in which the only active account
    checkpoint is the first one, this is indistinguishable from an
    index with no activity.

* exp/services/ledgerexporter: Extend tool to support lower ledger bound. (#4405)

* exp/lighthorizon: Refactor and repair the reduce job (#4424)

* Use envvars for every configurable thing, incl. index sources and final merged
  index target:

    This removes any hard dependency on S3 and lets you use any supported
    backend for the map-reduce operation. It was done specifically with local
    filesystem-based testing in mind, but naturally opens up other backends as
    well.

* Add lots of helper functions:

    Specifically, helpers now exist for both merging two sets of named indices
    together and partitioning work based on the account/transaction hashes into
    separate jobs/routines.

* Lots more logging! For progress tracking, debugging, etc.

* Create a thread-safe string set abstraction for tracking completed work.

* Better error handling: 

    `os.IsNotExist(err)` is much more reliable over a direct equality check to
    `ErrNotExist`. This also ties in to backend-independence. 

    We can also log and return an error rather than immediately panicking on its
    occurrence.

* Transaction flushes need to be thread-safe if they're going to be done from
  different goroutines during reduction.

    Otherwise, you get panics from concurrent writes to its maps.

* The "account list" (aka the file containing a list of all accounts in the
  partitioned index) needs to be flushed at the same time as the index itself:

    If this isn't done, then `FlushAccounts()` will do absolutely nothing after
    a `Flush()`, because the previous `Flush()` will clear the map of indices
    out of memory. Since the account list comes from memory, it becomes a no-op.

* Split work across multiple channels rather than just one

    If the work comes from a single channel, accounts can get skipped overall
    because they aren't put back on the queue if they're skipped by a single
    worker.

    It makes more sense to make each worker have its own channel, partitioning
    the work *before* it gets to the worker rather than after.

* exp/lighthorizon: Unify map-reduce and single-process index builders (#4423)

* Main thing: `./index/cmd/single` and `./index/cmd/batch/map` now leverage the
  same index building code (i.e. `BuildIndices`)

* This also extends the map-reduce builder to take the txmeta source / index
  destination URLs from envvars rather:

    This eliminates a hard dependency on S3, and it's done here because
    splitting that out from the giga-PR was difficult.

* We can infer checkpoints from `ledger.LedgerSequence()` rather than passing
  them in as a parameter, which cleans up modules.

* This finally adds a new `ProcessAccountsWithoutBackend` module for the Map job

* exp/lighthorizon: Thread-safe support for reading account list via FileBackend (#4422)

Three key changes:

    - actually read the account list when using a filesystem backend
    - using `O_APPEND` on the file to support concurrent writes
    - ensure that the read list is a unique set of accounts

* exp/lighthorizon: Restructure index package into sensible sub-packages (#4427)

* exp/lighthorizon: Merge on-disk index with in-memory one on load. (#4435)

* Add test for single-process index builder
* Merge in-memory index with on-disk one when loading
* Add fixture of unpacked ledgers for fast local testing
* Isolate the index we need to merge
* Use a ByteReader so that multiple indices in one file work 🤦
* Add to/from XDR support to bitmap index
* Fix and extend gzip tests to handle the bytereader bug
* Simplify participant processing code

* exp/lighthorizon: Allow indexer to continually update as new txmeta appears (#4432)

* exp/lighthorizon: enforce the limit from request on the response size  (#4431)

* Dockerize ledgerexport to run in AWS Batch

This Change:

1. Creates docker image (stellar/horizon-ledgerexporter) which works in a similar fashion to stellar/horizon-verify-rage
   and is tested and pushed as part of the Horizon GitHub workflow.
2. Adds two more parameters to ledgerexporter
   * --end-ledger: which indicates at what ledger to stop the export
   * --write-latest-path: which indicates whether to udpate the /latest path of the target

Latest path writing is disabled in the container by default in order to avoid race-conditions between parallel jobs

* exp/lighthorizon: Add test for batch index building map job (#4440)

* Modify single-process test to generalize to whatever fixture data exists
This also adds a test to check that single-process works on a non-checkpoint
starting point which is important.

* Fix map program to properly build sub-paths depending on its job index
Previously, this only happened for explicitly S3 backends.

* Make map job default to using all CPUs
* Stop clearing indices from memory if using unbacked module
* Use historyarchive.CheckpointManager for all checkpoint math
* Update lastBuiltLedger w/ safely concurrent writes

* Refactor bound preparation and add --continue flag

* Address review feedback and rework env variable names

* Run gofmt -w (I don't know why those files were changed)

* Add proper logging to indicate what range is being exported

* Add clarification about end ledger

* Fix boolean argument passing

* Address review feedback

* Address feedback

* Use sqlite for captive core

* exp/lighthorizon: Add basic scaffolding for metrics. (#4456)

* Use correct network passphrase when populating transaction
* Add scaffolding for Prom/log metrics and some example ones
* Misc. clarifications and fixes to the index builder

* lighthorizon: Prepend version to ledger files (#4450)

* Prepend version to ledger files

* Encode versioning in XDR

* Regenerate fixtures

* Fix ledger fixtures

* Appease govet

* Move all lighthorizon types to /xdr

* exp/lighthorizon/index: More testing for batch indexing and off-by-one bugfix. (#4442)

* Add reduce test to ensure combining map jobs works
* Actually test that TOIDs are correct
* Bugfix: Transaction prefix loop should be inclusive
* Isolate loggers to individual processing "sections"

* Minor ledgerexporter infrastructure improvements (#4461)

* Push the stellar/horizon-ledgerexporter docker image when pushing to the lighthorizon branch
* Fix the ledger exporter aws batch jobs when running on the first batch

* Forgot to add login step to ledgerexporter workflow

* exp/lighthorizon: Set a default number of workers. (#4465)

* Default to the number of CPUs if worker count isn't specified
* Set a timeout on the reduce job to avoid test suite hanging indefinitely

* exp/lighthorizon: Fix the single-process index builder data race. (#4470)

* Add synchronization for the work submission routine. Thank you @sreuland!

Co-authored-by: shawn <[email protected]>

* /exp/lighthorizon: new endpoints for tx and ops paged listing by account id (#4453)

* exp/lighthorizon: Add an on-disk cache for frequently accessed ledgers. (#4457)

* Replace custom LRU solution with an off-the-shelf data structure.
* Add a filesystem cache in front of the ledger backend to lower latency
* Add cache size parameter; only setup cache if not file://
* Extract S3 region from the archive URL if it's applicable.

* exp/lighthorizon/index: Drop building indices for successful transactions. (#4482)

* Add metrics middleware to collect request duration metrics (#4486)

* exp/lighthorizon: Isolate cursor advancement code to its own interface (#4484)

* Move cursor manipulation code to a separate interface
* Small test refactor to improve readability and long-running lines
* Combine tx and op tests into subtests
* Fix how IndexStore is mocked out

* exp/lighthorizon/index: Parse network passphrase from the env. (#4491)

* Refactor access to meta archive (#4488)

Refactor `historyarchive` and `ledgerbackend` to allow better access to the new meta archives:
* Created `metaarchive` package that connects to the new meta archives (and
  allows accessing `xdr.SerializedLedgerCloseMeta`).
* Extracted `ArchiveBackend` to the new `support/storage` package as it contains
  only storage related methods. New package is used in both `historyarchive` and
  `metaarchive`.

* exp/lighthorizon: Add response age prometheus metrics (#4492)

* exp/lighthorizon/index: Allow accounts to be indexed by ledger. (#4495)

* Add builders to make account indices by ledger
* Add `MODULE` parameter to map job in batch builder
* Don't build transaction indices by default

* services/horizon/docker/ledgerexporter: deploy ledgerexporter image as service (#4490)

* Make indexing s3 bucket configurable (#4507)

* exp/lighthorizon: Add duration metrics for on-the-fly ingestion elements. (#4476)

Add basic aggregate metrics for request fulfillment:
 - how long did ledger downloads take, on average?
 - how long did ledger processing take, on average?
 - how long did index lookups take, on average?
 - how many ledgers were needed?
 - how long did the entire request take, in total?

* exp/lighthorizon: Add JSON content type to responses. (#4509)

* exp/lighthorizon: *Correctly* set `Content-Type`, plus JSONify errors (#4513)

* exp/lighthorizon/services: Move service-specific stuff to its own file. (#4502)

* exp/lighthorizon, xdr: Rename `CheckpointIndex` to better reflect its capabilty. (#4510)

* Rename NextActive -> NextActiveBit to be descriptive

* exp/lighthorizon: Add a suite of tools to manage the on-disk ledger cache. (#4522)

* Run 'go mod tidy' after merge

* exp/lighthorizon: add horizon web docker/k8s deployment (#4519)

* It seems like the merge caused some deleted files to stay in:

  The commit b3407fd from
  PR #4418 deleted these files, so we just do the same.

  A quick manual inspection showed us that the deltas
  transferred over, just not the deletions, for some reason.
Idk why these changes ended up in the code, kinda sus...

More deleted files snuck in?

* One more that didn't get removed 🤔

* all: Incorporate generics into Light Horizon code. (#4537)

* bump go version to 18 on lighthorizon docker images, they need it now (#4541)

* exp/lighthorizon/actions: use standard Problem model on API error responses (#4542)

* exp/lighthorizon/build/index-batch: carry over map/reduce updates to latest docker layout on feature branch (#4543)

* exp/lighthorizon: Properly transform transactions into JSON. (#4531)

* exp/lighthorizon: Add a set of tools to aide in index inspection. (#4561)

* exp/lighthorizon/cmd: index batch fix s3 sub paths in reduce (#4552)

* exp/lighthorzon: Add a generic, thread-safe `SafeSet`. (#4572)

* support/storage: Make the on-disk cache thread-safe. (#4575)

* exp/lighthorizon: Incorporate tool subcommands into the webserver. (#4579)

* exp/lighthorizon/index/cmd: Fix index single watch, slow down the retry on not-found ledgers  (#4582)

* exp/lighthorizon: Refactor archive interface and support parallel ledger downloads. (#4548)
- Refactor and simplify Archive abstraction to incorporate MetaArchive
- Actually add & use parallel downloads, preparing checkpoint chunks
- Fix test structures and mocking
- Fix cache to ignore on-disk if lockfile present

* exp/lighthorizon: Minor error-handling and deployment improvements. (#4599)
- actually set the PARALLEL_DOWNLOADS parameter to use #4468
- return a 404 rather than a 500 if a ledger is missing as its more descriptive
- handle `count = 0` in average metric calculations
* exp/lighthorizon/index: Add ability to disable bits in index. (#4601)
* exp/lighthorizon: Add parameters to preload ledger cache. (#4615)
* Add ability to preload cache in parallel after launching webserver
* Default to 1 day of ledgers @ 6s each

---------

Co-authored-by: Bartek Nowotarski <[email protected]>
Co-authored-by: Paul Bellamy <[email protected]>
Co-authored-by: Bartek <[email protected]>
Co-authored-by: Bartek <[email protected]>
Co-authored-by: tamirms <[email protected]>
Co-authored-by: George <[email protected]>
Co-authored-by: stfung77 <[email protected]>
Co-authored-by: Leigh McCulloch <[email protected]>
Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: Alfonso Acosta <[email protected]>
Co-authored-by: Graydon Hoare <[email protected]>
Co-authored-by: Satyam Zode <[email protected]>
Co-authored-by: Satyam Zode <[email protected]>
Co-authored-by: erika-sdf <[email protected]>
Co-authored-by: iateadonut <[email protected]>
Co-authored-by: Shawn Reuland <[email protected]>
Co-authored-by: shawn <[email protected]>
Co-authored-by: Shivendra Mishra <[email protected]>
Co-authored-by: Jacek Nykis <[email protected]>
Co-authored-by: jacekn <[email protected]>
Co-authored-by: George Kudrayvtsev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Protocol 19 Support cap-21, cap-40 and sep-23 in Horizon & SDKs txnbuild 2nd-generation transaction build library for Go SDK
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants