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(wallet)!: make LoadParams implicitly satisfy Send #1562

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

evanlinjin
Copy link
Member

Description

Make LoadParams implicitly satisfy Send. This will hopefully make AsyncWalletPersister easier to implement.

Refer to the conversation on Discord.

cc. @matthiasdebernardini

Notes to the reviewers

This is a breaking change, since we are tightening the bounds to some methods.

Changelog notice

  • Change LoadParams to implicitly satisfy Send.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

@evanlinjin evanlinjin self-assigned this Aug 16, 2024
@evanlinjin evanlinjin added this to the 1.0.0-beta milestone Aug 16, 2024
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

Concept ACK, but unsure how to properly test it w/o an async persist implementation 😅.

@matthiasdebernardini
Copy link

@oleonardolima I'm working on it, but I can't get it to compile due to lifetime issues

evanlinjin#11

Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

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

ACK 295b979

@LLFourn
Copy link
Contributor

LLFourn commented Aug 19, 2024

Concept ACK, but unsure how to properly test it w/o an async persist implementation 😅.

You can just create a function:

fn test_send<T: Send>() { }

and call it with the thing inside a test. May want to consider doing that here.

@evanlinjin
Copy link
Member Author

@oleonardolima I'm working on it, but I can't get it to compile due to lifetime issues

evanlinjin#11

@matthiasdebernardini added to my mental todo list.

@matthiasdebernardini
Copy link

@evanlinjin @ValuedMammal helped me out and we got something going, but I still need to modify the AsyncWalletPersister trait so that I can pass the name of the wallet that I am querying like so

I was going to bring it up in our weekly meeting today to see if the rest are allright with it.

@evanlinjin
Copy link
Member Author

evanlinjin commented Aug 21, 2024

@evanlinjin @ValuedMammal helped me out and we got something going, but I still need to modify the AsyncWalletPersister trait so that I can pass the name of the wallet that I am querying like so

I was going to bring it up in our weekly meeting today to see if the rest are allright with it.

In general it's a bad idea to introduce an implementation-specific parameter to a trait that is meant to be for multiple implementations. I think a better idea would be to introduce a generic type parameter to the persistence traits. I'll create a draft commit soon.


Edit: However, I'm wondering whether the better option would be for implementations to have a wrapped ...Persister type if they want some custom config.

I.e.

type NamedWalletConnection<'c> {
    wallet_name: String,
    conn: sqlx::Connection<'c>,
}

impl<'c> AsyncWalletPersister for NamedWalletConnection<'c> {
    // ... stuff ...
}

@matthiasdebernardini what do you think? Draft PR for ...Persister trait modifications incoming anyway.

@matthiasdebernardini
Copy link

Hey! I actually got it working like this

#[derive(Debug)]
pub struct Store {
    pool: PgPool,
    wallet_name: String,
}

impl Store {
    /// Construct a new [`Store`].
    pub async fn new(pool: Pool<Postgres>, wallet_name:String) -> Result<Self, Error> {
         Ok(Self { pool, wallet_name})
    }
}

and that seems to work quite well, so that wrapper is not needed for me. Though it might make it more obvious to the next person to implement this.

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

ACK 295b979

I'm not sure if @matthiasdebernardini still needs this change for his postgres store but tightening up the type bounds still looks like the right thing to do.

@evanlinjin evanlinjin merged commit 6008897 into bitcoindevkit:master Aug 22, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants