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
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c00ddae
Add cursor for getTransactions
aditya1702 Apr 12, 2024
2467dbe
Add validation of pagination and range
aditya1702 Apr 12, 2024
6aa348d
implement getTransactions handler - 1
aditya1702 Apr 15, 2024
7928c78
Add getLedgers
aditya1702 Apr 15, 2024
355b1e2
Read a single ledger instead of getting all ledgers
aditya1702 Apr 15, 2024
11baf9e
Add ParseCursor method for tx cursor
aditya1702 Apr 15, 2024
81eceff
Cursor changes - 1
aditya1702 Apr 15, 2024
83918f2
Cursor changes - 2
aditya1702 Apr 16, 2024
3d7f7d3
Cursor changes - 3
aditya1702 Apr 16, 2024
f509457
revert go-mod changes
aditya1702 Apr 16, 2024
f813d01
Use reader.Seek()
aditya1702 Apr 16, 2024
0e8b9da
Use reader.Seek() - 2
aditya1702 Apr 16, 2024
5156b9e
Add config-options for tx pagination limits
aditya1702 Apr 16, 2024
e4b34e5
Merge branch 'main' into get-transactions
aditya1702 Apr 16, 2024
35da2a5
Fix failing cursor test
aditya1702 Apr 16, 2024
35ed84d
Go mod changes
aditya1702 Apr 16, 2024
fce765b
Go mod changes - 2
aditya1702 Apr 16, 2024
60055da
Add unittests - 1
aditya1702 Apr 17, 2024
90f6b5b
Update go.mod and go.sum
aditya1702 Apr 17, 2024
36205ce
Merge branch 'main' into get-transactions
aditya1702 Apr 17, 2024
ba254f0
Add integration tests
aditya1702 Apr 18, 2024
18dbbd1
Merge branch 'main' into get-transactions
aditya1702 Apr 18, 2024
cb3eae9
Update go.mod and go.sum
aditya1702 Apr 18, 2024
a75205c
Add ledgerSeq to error string
aditya1702 Apr 18, 2024
65d2ab8
Add docstrings
aditya1702 Apr 18, 2024
dae0624
Change transactions limits
aditya1702 Apr 18, 2024
f1a0a87
add defensive check for error other than EOF
aditya1702 Apr 18, 2024
364ee92
add defensive check for error other than EOF - 2
aditya1702 Apr 18, 2024
aeb0a84
Change ledger sequence to uint32
aditya1702 Apr 18, 2024
2c5b2a4
Add comments/docstrings
aditya1702 Apr 18, 2024
95ce052
Include only cursor in response
aditya1702 Apr 18, 2024
c27d20c
Use toid instead of new cursor
aditya1702 Apr 22, 2024
6837f79
Revert cursor changes
aditya1702 Apr 22, 2024
9239dff
Merge branch 'main' into get-transactions
aditya1702 Apr 23, 2024
0f098fb
Return cursor as string in result
aditya1702 Apr 29, 2024
5f273a7
Merge branch 'main' into get-transactions
aditya1702 Apr 29, 2024
c9ddee4
Refactor reader.Seek error handling
aditya1702 Apr 29, 2024
d426361
Merge remote-tracking branch 'origin/get-transactions' into get-trans…
aditya1702 Apr 29, 2024
1c44f63
Small refactoring
aditya1702 Apr 30, 2024
850f208
Remove startLedger check
aditya1702 May 3, 2024
c45d333
Merge branch 'refs/heads/main' into get-transactions
aditya1702 May 3, 2024
be21a95
Remove endLedger
aditya1702 May 3, 2024
bd81a39
Merge branch 'refs/heads/database-backend' into get-transactions
aditya1702 May 3, 2024
088dff0
Import fix
aditya1702 May 3, 2024
74e2941
Fix failing tests
aditya1702 May 3, 2024
ca6c4ca
Refactor to use new transaction db
aditya1702 May 3, 2024
6d415dd
Refactor mocks
aditya1702 May 3, 2024
acaae61
Refactor unittests for using the new db changes
aditya1702 May 6, 2024
af41b32
Refactor integration test
aditya1702 May 6, 2024
90afd1e
Add config vars for max requests and request duration
aditya1702 May 6, 2024
31c80f7
Fix failing test
aditya1702 May 6, 2024
0a00590
Use transactionInfo struct instead of db.Transactions
aditya1702 May 8, 2024
0b19b17
Start indexing from 1 instead of 0 for toid
aditya1702 May 8, 2024
f85bdfb
Operation index from 1
aditya1702 May 9, 2024
4442348
Add lines to make sure structs implement interfaces
aditya1702 May 9, 2024
2d66084
Remove omitempty
aditya1702 May 9, 2024
f08dc00
rename test func
aditya1702 May 9, 2024
bc6cbba
make txInfo struct public and convert string cursor to int
aditya1702 May 10, 2024
68e45d5
Use sendSuccessfulTransaction helper func
aditya1702 May 10, 2024
21da905
Convert cursor to string in request
aditya1702 May 10, 2024
7e1a471
Change jrpc response codes
aditya1702 May 10, 2024
c63f8e1
Change ledger close meta code to invalid-params
aditya1702 May 13, 2024
a6a77b9
Revert back to InvalidParams error for reader.Read()
aditya1702 May 13, 2024
7509c6e
Refactor if-else statement
aditya1702 May 13, 2024
d4f9b54
Refactor if-else statement - 2
aditya1702 May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/soroban-rpc/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
CheckpointFrequency uint32
CoreRequestTimeout time.Duration
DefaultEventsLimit uint
DefaultTransactionsLimit uint
EventLedgerRetentionWindow uint32
FriendbotURL string
HistoryArchiveURLs []string
Expand All @@ -33,6 +34,7 @@ type Config struct {
LogFormat LogFormat
LogLevel logrus.Level
MaxEventsLimit uint
MaxTransactionsLimit uint
MaxHealthyLedgerLatency time.Duration
NetworkPassphrase string
PreflightWorkerCount uint
Expand All @@ -48,6 +50,7 @@ type Config struct {
RequestBacklogGetLatestLedgerQueueLimit uint
RequestBacklogGetLedgerEntriesQueueLimit uint
RequestBacklogGetTransactionQueueLimit uint
RequestBacklogGetTransactionsQueueLimit uint
RequestBacklogSendTransactionQueueLimit uint
RequestBacklogSimulateTransactionQueueLimit uint
RequestExecutionWarningThreshold time.Duration
Expand All @@ -59,6 +62,7 @@ type Config struct {
MaxGetLatestLedgerExecutionDuration time.Duration
MaxGetLedgerEntriesExecutionDuration time.Duration
MaxGetTransactionExecutionDuration time.Duration
MaxGetTransactionsExecutionDuration time.Duration
MaxSendTransactionExecutionDuration time.Duration
MaxSimulateTransactionExecutionDuration time.Duration

Expand Down
35 changes: 35 additions & 0 deletions cmd/soroban-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,28 @@ func (cfg *Config) options() ConfigOptions {
return nil
},
},
{
Name: "max-transactions-limit",
Usage: "Maximum amount of transactions allowed in a single getTransactions response",
ConfigKey: &cfg.MaxTransactionsLimit,
DefaultValue: uint(200),
},
{
Name: "default-transactions-limit",
Usage: "Default cap on the amount of transactions included in a single getTransactions response",
ConfigKey: &cfg.DefaultTransactionsLimit,
DefaultValue: uint(50),
Validate: func(co *ConfigOption) error {
if cfg.DefaultTransactionsLimit > cfg.MaxTransactionsLimit {
return fmt.Errorf(
"default-transactions-limit (%v) cannot exceed max-transactions-limit (%v)",
cfg.DefaultTransactionsLimit,
cfg.MaxTransactionsLimit,
)
}
return nil
},
},
{
Name: "max-healthy-ledger-latency",
Usage: "maximum ledger latency (i.e. time elapsed since the last known ledger closing time) considered to be healthy" +
Expand Down Expand Up @@ -334,6 +356,13 @@ func (cfg *Config) options() ConfigOptions {
DefaultValue: uint(1000),
Validate: positive,
},
{
TomlKey: strutils.KebabToConstantCase("request-backlog-get-transactions-queue-limit"),
Usage: "Maximum number of outstanding GetTransactions requests",
ConfigKey: &cfg.RequestBacklogGetTransactionsQueueLimit,
DefaultValue: uint(1000),
Validate: positive,
},
{
TomlKey: strutils.KebabToConstantCase("request-backlog-send-transaction-queue-limit"),
Usage: "Maximum number of outstanding SendTransaction requests",
Expand Down Expand Up @@ -402,6 +431,12 @@ func (cfg *Config) options() ConfigOptions {
ConfigKey: &cfg.MaxGetTransactionExecutionDuration,
DefaultValue: 5 * time.Second,
},
{
TomlKey: strutils.KebabToConstantCase("max-get-transactions-execution-duration"),
Usage: "The maximum duration of time allowed for processing a getTransactions request. When that time elapses, the rpc server would return -32001 and abort the request's execution",
ConfigKey: &cfg.MaxGetTransactionsExecutionDuration,
DefaultValue: 5 * time.Second,
},
{
TomlKey: strutils.KebabToConstantCase("max-send-transaction-execution-duration"),
Usage: "The maximum duration of time allowed for processing a sendTransaction request. When that time elapses, the rpc server would return -32001 and abort the request's execution",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ import (
type mockTransactionHandler struct {
passphrase string

ledgerRange ledgerbucketwindow.LedgerRange
txs map[string]ingest.LedgerTransaction
ledgers map[string]*xdr.LedgerCloseMeta
ledgerRange ledgerbucketwindow.LedgerRange
txs map[string]ingest.LedgerTransaction
txHashToMeta map[string]*xdr.LedgerCloseMeta
ledgerSeqToMeta map[uint32]*xdr.LedgerCloseMeta
}

func NewMockTransactionStore(passphrase string) *mockTransactionHandler {
return &mockTransactionHandler{
passphrase: passphrase,
txs: make(map[string]ingest.LedgerTransaction),
ledgers: make(map[string]*xdr.LedgerCloseMeta),
passphrase: passphrase,
txs: make(map[string]ingest.LedgerTransaction),
txHashToMeta: make(map[string]*xdr.LedgerCloseMeta),
ledgerSeqToMeta: make(map[uint32]*xdr.LedgerCloseMeta),
}
}

func (txn *mockTransactionHandler) InsertTransactions(lcm xdr.LedgerCloseMeta) error {
txn.ledgerSeqToMeta[lcm.LedgerSequence()] = &lcm

reader, err := ingest.NewLedgerTransactionReaderFromLedgerCloseMeta(txn.passphrase, lcm)
if err != nil {
return err
Expand All @@ -44,7 +48,7 @@ func (txn *mockTransactionHandler) InsertTransactions(lcm xdr.LedgerCloseMeta) e

h := tx.Result.TransactionHash.HexString()
txn.txs[h] = tx
txn.ledgers[h] = &lcm
txn.txHashToMeta[h] = &lcm
}

if lcmSeq := lcm.LedgerSequence(); lcmSeq < txn.ledgerRange.FirstLedger.Sequence ||
Expand Down Expand Up @@ -72,12 +76,35 @@ func (txn *mockTransactionHandler) GetTransaction(ctx context.Context, hash xdr.
if tx, ok := txn.txs[hash.HexString()]; !ok {
return Transaction{}, txn.ledgerRange, ErrNoTransaction
} else {
itx, err := ParseTransaction(*txn.ledgers[hash.HexString()], tx)
itx, err := ParseTransaction(*txn.txHashToMeta[hash.HexString()], tx)
return itx, txn.ledgerRange, err
}
}

func (txn *mockTransactionHandler) RegisterMetrics(_, _ prometheus.Observer) {}

type mockLedgerReader struct {
txn mockTransactionHandler
}

func NewMockLedgerReader(txn *mockTransactionHandler) *mockLedgerReader {
return &mockLedgerReader{
txn: *txn,
}
}

func (m *mockLedgerReader) GetLedger(ctx context.Context, sequence uint32) (xdr.LedgerCloseMeta, bool, error) {
lcm, ok := m.txn.ledgerSeqToMeta[sequence]
if !ok {
return xdr.LedgerCloseMeta{}, false, nil
}
return *lcm, true, nil
}

func (m *mockLedgerReader) StreamAllLedgers(ctx context.Context, f StreamLedgerFn) error {
return nil
}

var _ TransactionReader = &mockTransactionHandler{}
var _ TransactionWriter = &mockTransactionHandler{}
var _ LedgerReader = &mockLedgerReader{}
7 changes: 7 additions & 0 deletions cmd/soroban-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler {
queueLimit: cfg.RequestBacklogGetTransactionQueueLimit,
requestDurationLimit: cfg.MaxGetTransactionExecutionDuration,
},
{
methodName: "getTransactions",
underlyingHandler: methods.NewGetTransactionsHandler(params.Logger, params.LedgerReader, params.TransactionReader, cfg.MaxTransactionsLimit, cfg.DefaultTransactionsLimit, cfg.NetworkPassphrase),
longName: "get_transactions",
queueLimit: cfg.RequestBacklogGetTransactionsQueueLimit,
requestDurationLimit: cfg.MaxGetTransactionsExecutionDuration,
},
{
methodName: "sendTransaction",
underlyingHandler: methods.NewSendTransactionHandler(
Expand Down
Loading
Loading