Skip to content

Add tx order number and pagination #1930

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

OBorce
Copy link
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.

})
.collect()
}

pub async fn get_transactions_with_block_by_order_number(
Copy link
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
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.

@@ -92,10 +93,22 @@ impl ApiServerStorageRead for ApiServerInMemoryStorageTransactionalRo<'_> {
&self,
len: u32,
offset: u32,
) -> Result<Vec<(BlockAuxData, TransactionInfo)>, ApiServerStorageError> {
) -> Result<Vec<TransactionWithBlockInfo>, ApiServerStorageError> {
Copy link
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.

@@ -117,6 +117,7 @@ impl<S: ApiServerStorage + Send + Sync> LocalBlockchainState for BlockchainState
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
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
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

@@ -448,27 +448,59 @@ pub async fn transactions<T: ApiServerStorage>(
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
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
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
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