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

API: Hotfix block endpoint #1397

Merged
merged 5 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 0 additions & 5 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,11 +1359,6 @@ func (si *ServerImplementation) fetchBlock(ctx context.Context, round uint64, op

results := make([]generated.Transaction, 0)
for _, txrow := range transactions {
// Do not include inner transactions.
if txrow.RootTxn != nil {
continue
}

tx, err := txnRowToTransaction(txrow)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions idb/idb.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ type TransactionFilter struct {
// instead of the root txn.
ReturnInnerTxnOnly bool

// If this flag is set to true, then the query returns only root txns
// and no inner txns
ReturnRootTxnsOnly bool

// If this flag is set to true, then the query returns the block excluding
// the transactions
HeaderOnly bool
Expand Down
7 changes: 5 additions & 2 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (db *IndexerDb) GetBlock(ctx context.Context, round uint64, options idb.Get

if options.Transactions {
out := make(chan idb.TxnRow, 1)
query, whereArgs, err := buildTransactionQuery(idb.TransactionFilter{Round: &round, Limit: options.MaxTransactionsLimit + 1})
query, whereArgs, err := buildTransactionQuery(idb.TransactionFilter{Round: &round, Limit: options.MaxTransactionsLimit + 1, ReturnRootTxnsOnly: true})
if err != nil {
err = fmt.Errorf("txn query err %v", err)
out <- idb.TxnRow{Error: err}
Expand Down Expand Up @@ -658,6 +658,9 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
if tf.RekeyTo != nil && (*tf.RekeyTo) {
whereParts = append(whereParts, "(t.txn -> 'txn' -> 'rekey') IS NOT NULL")
}
if tf.ReturnRootTxnsOnly {
whereParts = append(whereParts, "t.txid IS NOT NULL")
}

// If returnInnerTxnOnly flag is false, then return the root transaction
if !tf.ReturnInnerTxnOnly {
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 also needed to make sure we don't try to reference root:

Suggested change
if !tf.ReturnInnerTxnOnly {
if !tf.ReturnInnerTxnOnly && !tf.ReturnRootTxnsOnly {

Expand All @@ -671,7 +674,7 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
}

// join in the root transaction if the returnInnerTxnOnly flag is false
if !tf.ReturnInnerTxnOnly {
if !tf.ReturnInnerTxnOnly || tf.ReturnRootTxnsOnly {
query += " LEFT OUTER JOIN txn root ON t.round = root.round AND (t.extra->>'root-intra')::int = root.intra"
}

Expand Down