Skip to content

Add tx order number and pagination#1930

Merged
OBorce merged 3 commits intomasterfrom
feature/api-server-tx-order-num
Jul 25, 2025
Merged

Add tx order number and pagination#1930
OBorce merged 3 commits intomasterfrom
feature/api-server-tx-order-num

Conversation

@OBorce
Copy link
Copy Markdown
Contributor

@OBorce OBorce commented Jun 19, 2025

Add order number to transactions based on the order inside the blocks.
Add new query parameter to the transactions endpoint to control the pagination based on the order number instead of an offset to get more stable pagination in the case of new txs being inserted.

Comment thread api-server/api-server-common/src/storage/impls/postgres/queries.rs Outdated
.collect()
}

pub async fn get_transactions_with_block_by_order_number(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function is confusing - it's unclear that it'll return transactions before the specified order number.

Plz at least rename it, so that the name reflects what it does.
(But I'd also suggest making it return txs starting from the specified order number and making the callers do the adjustment if needed)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed to include before. I am not sure starting will be good, as the main use case is fetching latest txs so you are starting from the last towards 0.

Comment thread api-server/api-server-common/src/storage/impls/postgres/queries.rs Outdated
Comment thread api-server/api-server-common/src/storage/impls/in_memory/mod.rs Outdated
len: u32,
offset: u32,
) -> Result<Vec<(BlockAuxData, TransactionInfo)>, ApiServerStorageError> {
) -> Result<Vec<TransactionWithBlockInfo>, ApiServerStorageError> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps the function should now be called "get_transactions_with_block_info"?
Same for get_transactions_with_block_by_order_number.

disconnect_tables_above_height(&mut db_tx, common_block_height)
.await
.expect("Unable to disconnect tables");
let mut next_order_number = db_tx.get_last_transaction_order_number().await? + 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Btw, this "order number" naming is confusing IMO, it looks like it's related to orders.
I'd suggest naming it differently (everywhere). Some alternatives:

  1. "global order number" - no longer feels like it's related to orders,
  2. "global ordering number",
  3. "global index".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed to tx global index

Comment thread api-server/web-server/src/api/v2.rs Outdated
Query(params): Query<BTreeMap<String, String>>,
State(state): State<ApiServerWebServerState<Arc<T>, Arc<impl TxSubmitClient>>>,
) -> Result<impl IntoResponse, ApiServerWebServerError> {
const BEFORE_ORDER_NUMBER: &str = "before_order_number";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this needed? Is this something you've discussed with Sergey?

IMO it'd be nicer if the endpoint remained the same, but with "offset" now referring to the global tx order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

offset is increasing and the order_number now global index is decreasing, and we don't want to make breaking changes so we keep both.

@OBorce OBorce force-pushed the feature/api-server-tx-order-num branch from e0256e6 to 909249f Compare June 30, 2025 18:57
@OBorce OBorce merged commit 36ed048 into master Jul 25, 2025
18 checks passed
@OBorce OBorce deleted the feature/api-server-tx-order-num branch July 25, 2025 09:04
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