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

Add getTransactions endpoint #136

Merged
merged 65 commits into from
May 13, 2024

Conversation

aditya1702
Copy link
Contributor

@aditya1702 aditya1702 commented Apr 15, 2024

What

Implement the getTransactions endpoint. It reads the ledger close meta stored in sqlite and decodes the necessary transaction information.

A quick summary of what is added in the PR:

  • RPC handler for getTransactions
  • Pagination support on the new endpoint
  • Unit tests
  • Integration tests

Why

See #110

Known limitations

N/A

Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

just a quick first pass

cmd/soroban-rpc/internal/db/ledger.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/methods/get_transactions.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/methods/get_transactions.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/methods/get_transactions.go Outdated Show resolved Hide resolved
@aditya1702 aditya1702 changed the title [WIP] Add getTransactions [WIP] Add getTransactions endpoint Apr 16, 2024
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

Super close 👏 couple more minor comments and this should be ready to merge

cmd/soroban-rpc/internal/db/mocks.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/methods/get_transactions.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/methods/get_transactions.go Outdated Show resolved Hide resolved
@aditya1702 aditya1702 requested a review from Shaptic May 9, 2024 15:48
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

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

LGTM, nice work 👏 but wait for another look from @tamirms before merging

LedgerLoop:
for ledgerSeq := start.LedgerSequence; ledgerSeq <= int32(ledgerRange.LastLedger.Sequence); ledgerSeq++ {
// Get ledger close meta from db
ledger, found, err := h.ledgerReader.GetLedger(ctx, uint32(ledgerSeq))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a thought for the future: we should probably do something more like getLedgers() and then process ledgers in batches so that we don't have to have one SQL query for each iteration (while still respecting limit, of course, but a little extra memory is worth saving queries).

We can include this as part of (or after, at the very least) the getLedgers work in #111.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Shaptic Yeah I agree. We should do the batch processing as its more efficient.

@aditya1702 aditya1702 requested a review from tamirms May 10, 2024 13:19
@@ -135,7 +144,7 @@ LedgerLoop:
err = errors.Errorf("ledger close meta not found: %d", ledgerSeq)
}
return GetTransactionsResponse{}, &jrpc2.Error{
Code: jrpc2.InvalidParams,
Code: jrpc2.InternalError,
Copy link
Contributor

Choose a reason for hiding this comment

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

why internal now? if it's not in the DB then their request is out of bounds

Copy link
Contributor

Choose a reason for hiding this comment

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

same comment for all of the below error changes imo

Copy link
Contributor Author

@aditya1702 aditya1702 May 13, 2024

Choose a reason for hiding this comment

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

@Shaptic Yeah you are correct. I refactored this code again to use InvalidParams for "ledger close meta not found" or for any other db related error, use the InternalError code.

However, for these 3 errors:

InternalError would make more sense dont you think? Since they are generated due to some internal parsing issues?

@aditya1702 aditya1702 requested a review from tamirms May 13, 2024 14:15
@aditya1702 aditya1702 merged commit 7eaaf61 into stellar:database-backend May 13, 2024
20 checks passed
aditya1702 added a commit that referenced this pull request May 23, 2024
…ons (#174)

* Increase `getTransaction` window via ingestion into a local database (#141)

* Add common interface between in-memory and on-disk transaction storage

* Revert "Add common interface between in-memory and on-disk transaction storage"

This reverts commit 3196ade.

* Add initial implementation of DB-backed tx store

* Drop all references to the in-memory transaction store

* Actually filter for the tx hash you want 🤦

* Drop remaining reference to transaction store

* Update stellar/go to latest master

* Add a bunch of logging/verbose errors, another column to DB

* Propogate contexts, fix all bugs; e2e flow works!

* Add metric for tx ingestion

* Split TransactionHandler into separate readers and writers

* Move tx reads into their own isolated, read-only db tx

* Add in-memory cache for ledger ranges

* Remove cache: read/write are separate so it doesn't work

* Add trimming of transactions table based on retention window

* Tests work (but dont pass)! Plus some fixes based on test cases 👍

* Tidy up the go.mod file

* Fixup the way ledger ranges are handled

* Add prometheus metrics back

* Drop columns and logging that aren't useful

* Incorporate errors into ledger range retrieval

* Return instead of log errors in getTransaction

* Fixup tests: an empty db isn't a fetch error

* Make 24hr the new default transaction retention window, fixup errors

* Expect the correct retention window in tests

* Use raw byte hash over hex for 1/2 the column space

* Rename interfaces to avoid overloading 'Transaction' term

* PR feedback: variable rename

* Separate tx parsing into its own function

* Modify queries to not use transactions

* Pass around the logger rather than using the global

* Fixup all of the tests to pass a logger

* Use subqueries to get around () sqlite limitations

* Use .Select() to simplify querying

* Add db unit test but it's failing :(

* Prefer custom error over EOF or DB nonsense

* Prepare randoms in advance, writer for the ledger as well

* Pass daemon to db to hook in metrics

* Check another error in e2e test

* Feedback: use no-op interface, drop metric

* Refactor method tests to use 'fake' tx/ledger backend

* Simplify code a bit

* Fixup mocking interface

* Move test function back, fixup metrics and tests

* Add `getTransactions` endpoint (#136)

* Add cursor for getTransactions

* Add validation of pagination and range

* implement getTransactions handler - 1

* Add getLedgers

* Read a single ledger instead of getting all ledgers

* Add ParseCursor method for tx cursor

* Cursor changes - 1

* Cursor changes - 2

* Cursor changes - 3

* revert go-mod changes

* Use reader.Seek()

* Use reader.Seek() - 2

* Add config-options for tx pagination limits

* Fix failing cursor test

* Go mod changes

* Go mod changes - 2

* Add unittests - 1

* Update go.mod and go.sum

* Add integration tests

* Update go.mod and go.sum

* Add ledgerSeq to error string

* Add docstrings

* Change transactions limits

* add defensive check for error other than EOF

* add defensive check for error other than EOF - 2

* Change ledger sequence to uint32

* Add comments/docstrings

* Include only cursor in response

* Use toid instead of new cursor

* Revert cursor changes

* Return cursor as string in result

* Refactor reader.Seek error handling

* Small refactoring

* Remove startLedger check

* Remove endLedger

* Import fix

* Fix failing tests

* Refactor to use new transaction db

* Refactor mocks

* Refactor unittests for using the new db changes

* Refactor integration test

* Add config vars for max requests and request duration

* Fix failing test

* Use transactionInfo struct instead of db.Transactions

* Start indexing from 1 instead of 0 for toid

* Operation index from 1

* Add lines to make sure structs implement interfaces

* Remove omitempty

* rename test func

* make txInfo struct public and convert string cursor to int

* Use sendSuccessfulTransaction helper func

* Convert cursor to string in request

* Change jrpc response codes

* Change ledger close meta code to invalid-params

* Revert back to InvalidParams error for reader.Read()

* Refactor if-else statement

* Refactor if-else statement - 2

* Add documentation on opting into the new db backend (#182)

* Refactor getFeeStats changes to add db changes

* Remove code making `GetLedgerRange` conform to interface (#186)

It's unnecessary because we aren't using that interface anymore.

* Add changelog entry for `getTransactions` (#183)

* Add more changelog details on new endpoint

* Fixup spacing

---------

Co-authored-by: George <[email protected]>
Co-authored-by: George Kudrayvtsev <[email protected]>
@aditya1702 aditya1702 deleted the get-transactions branch May 28, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants