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

fix: add pagination to deposit fetching #1252

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Jiloc
Copy link
Collaborator

@Jiloc Jiloc commented Jan 21, 2025

Description

Closes: #1148

Changes

  • add pagination handling to get_deposits
  • add pagination_timeout to EmilyClient - it causes the client to stop fetching deposits - but still return the ones alrealdy fetched - when the time passed > timeout.
  • added pagination_timeout to the configs - currently set to 30

Testing Information

  • Added integration tests to test pagination and timeout on get_deposits

Checklist:

  • I have performed a self-review of my code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

@Jiloc Jiloc added this to the sBTC: Key rotation milestone Jan 21, 2025
@Jiloc Jiloc self-assigned this Jan 21, 2025
@Jiloc
Copy link
Collaborator Author

Jiloc commented Jan 22, 2025

The idea of using the the BlockHeight to filter deposits already processed, may not work. The BlockHeight is not guaranteed to remain consistent in Emily (also currently they are returned from newest to oldest). In the event of a reorg, requests could be updated with a different associated block. This could result in requests being modified to have a lower height than the previous one. If we only consider requests with a BlockHeight greater than or equal to a certain value, it could lead to signers skipping requests after a reorg. A potential solution could be to add a created_at parameter to Dynamo and use that value for sorting and ignoring.

@Jiloc
Copy link
Collaborator Author

Jiloc commented Jan 22, 2025

I'd propose to decide on a strategy for sorting for Emily and implement a filtering mechanism on the signers side in a separate PR

@Jiloc Jiloc requested a review from djordon January 22, 2025 14:14
@Jiloc Jiloc marked this pull request as ready for review January 22, 2025 14:15
@Jiloc Jiloc marked this pull request as draft January 22, 2025 14:16
@Jiloc Jiloc marked this pull request as ready for review January 22, 2025 17:00
@Jiloc Jiloc requested review from matteojug and cylewitruk January 22, 2025 17:00
@cylewitruk
Copy link
Member

cylewitruk commented Jan 23, 2025

The idea of using the the BlockHeight to filter deposits already processed, may not work. The BlockHeight is not guaranteed to remain consistent in Emily (also currently they are returned from newest to oldest). In the event of a reorg, requests could be updated with a different associated block. This could result in requests being modified to have a lower height than the previous one. If we only consider requests with a BlockHeight greater than or equal to a certain value, it could lead to signers skipping requests after a reorg. A potential solution could be to add a created_at parameter to Dynamo and use that value for sorting and ignoring.

If I got to choose, I would probably have opted for a streaming protocol backed by durable topic subscriptions (at least that's what they're called in the message broker world..). For example MQTT over Websockets (AWS version), instead of polling. That would obsolete the above challenges.

@Jiloc
Copy link
Collaborator Author

Jiloc commented Jan 28, 2025

The idea of using the the BlockHeight to filter deposits already processed, may not work. The BlockHeight is not guaranteed to remain consistent in Emily (also currently they are returned from newest to oldest). In the event of a reorg, requests could be updated with a different associated block. This could result in requests being modified to have a lower height than the previous one. If we only consider requests with a BlockHeight greater than or equal to a certain value, it could lead to signers skipping requests after a reorg. A potential solution could be to add a created_at parameter to Dynamo and use that value for sorting and ignoring.

If I got to choose, I would probably have opted for a streaming protocol backed by durable topic subscriptions (at least that's what they're called in the message broker world..). For example MQTT over Websockets (AWS version), instead of polling. That would obsolete the above challenges.

I love the idea and believe this is the cleanest way to go for the signers. We'll have to design it for a future milestone though, it will require a different infra because of the usual limitations of the current setup...
We still need to support basic pagination, filtering and ordering in the REST API though. That will help in the short term with the signers and for every other user downstream (e.g. the bridge) for the long.

signer/src/config/mod.rs Show resolved Hide resolved
signer/src/config/mod.rs Outdated Show resolved Hide resolved
envs/signer-1.env Outdated Show resolved Hide resolved
signer/src/emily_client.rs Outdated Show resolved Hide resolved
signer/src/emily_client.rs Outdated Show resolved Hide resolved
signer/src/emily_client.rs Show resolved Hide resolved
signer/tests/integration/emily.rs Outdated Show resolved Hide resolved
signer/tests/integration/emily.rs Outdated Show resolved Hide resolved
emily/handler/tests/integration/deposit.rs Show resolved Hide resolved
signer/src/config/mod.rs Show resolved Hide resolved
Comment on lines +32 to +33
# The pagination timeout, in seconds, used to fetch deposits and withdrawals
# requests from Emily.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to use Emily for withdrawal requests, just for deposits. The plan was for the signers to just use the stacks node for withdrawals.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This one is missing the page_size config parameter. I think we should have it here, even if we have some parameters that we exclude from the docker/mainnet/sbtc-signer/signer-config.toml.in example.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Related to the page_size, is it supposed to specify a number of items or the number of bytes to return per page? Is there a maximum or minimum value enforced by AWS? And do we want this to be a config parameter at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the specific number of items. If the number is too big, Dynamo will always cap the query results to 1MB.

I needed to have access to it for testing purposes only, but I am unsure yet if we'll ever need to manually modify this value in the settings. I am open to remove it from the configs if you think it's better

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, probably best to remove it from the configs since we don't plan on having folks change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

[Bug]: Page through Emily deposit requests
5 participants