8000 feat: Implement Postgres interfaces for KV and Logging by gonzalezzfelipe · Pull Request #65 · txpipe/balius · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Implement Postgres interfaces for KV and Logging #65

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

Closed

Conversation

gonzalezzfelipe
Copy link
Contributor
@gonzalezzfelipe gonzalezzfelipe commented May 22, 2025

No description provided.

@gonzalezzfelipe gonzalezzfelipe marked this pull request as ready for review May 22, 2025 19:50
Comment on lines 28 to 32
8000
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("connection error: {}", e);
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this here? Swallowing an error doesn't seem useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, do you think it would be better to panic if the connection is broken?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just tracing::error! instead? Didn't notice that there's no way for the logging API to surface errors

Copy link
Contributor Author
@gonzalezzfelipe gonzalezzfelipe May 23, 2025

Choose a reason for hiding this comment

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

I was thinking and the whole approach is kind of off. I'll refactor for the following:

  • use a connection pool to handle the connections in the bg, also to make it more resilient to heavy usage (particularly this one)
  • given that I would be adding dependencies, make it a optional feature of the runtime crate

I was trying to keep it minimal but I think it makes sense to be robust and optional instead of slim and brittle. Do you agree?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's a valid approach, but the right thing to do here probably depends on how @scarmuega wants balius-runtime consumers to work.

If the runtime is supposed to be "batteries included", then it makes sense to have a robust (and optional) postgres provider inside of it. If you really want it to be robust, I'd also recommend

  • Let the caller reuse connection pools. If the logger and KV store are both using postgres, they should probably be allowed to use the same set of postgres connections.
  • Provide some optional "init_db" method that the consumer can call to set up tables. Different software stacks manage DB schemas in different ways, and one of those ways is "the application sets up its own schema at startup/deploy time". Supporting that case is easy.
  • Let the caller choose the table name (or maybe make table name a function of the worker). The logs table will be really write-intensive, and the KV table could have lots of reads and writes depending on what the application is doing. You'll likely want sharding to run this in prod (otherwise, bad actors can spam KV writes/deletes and bloat the indexes for everyone), and "different workers use different tables" can be simpler to set up than DB-level sharding.

If it's more important for the runtime to be minimal, then you could make callers implement their own logging/KV solutions themselves. That's supported today; firefly-cardano is using a custom KV store which gives each worker its own table in a sqlite DB, and creates those tables as needed. You could provide implementations of these components in separate crates, and so could third-party consumers. There's not much advantage to that split today, but it makes more sense in a world where balius is multi-chain and you have devs providing their own signer implementations for their chain's cryptographic primitives.

Copy link
Contributor Author
@gonzalezzfelipe gonzalezzfelipe May 26, 2025

Choose a reason for hiding this comment

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

For what its worth, I'm friendlier with the idea of having this custom implementations outside of Balius. If that's what we want to do, then I would just delete this PR and create a new one that just contiains the KvProvider logic that allows to create scoped kv and logging interfaces per worker. Then have the pg implementations on ext-balius

Copy link
Contributor Author
@gonzalezzfelipe gonzalezzfelipe May 27, 2025

Choose a reason for hiding this comment

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

@SupernaviX after speaking with santi, I will close this PR with the idea of having the pg interfaces on the demeter extension repo

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
0