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

feat: use dlc-macros for async dlc-manager #236

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

Conversation

bennyhodl
Copy link
Contributor

Alternate to #235

bdk_macros uses old versions of syn and is no longer maintained so it might be useful to create a dlc_macros crate.

This PR gives an example of a different implementation to support async manager compared to copying functions.

@bennyhodl bennyhodl force-pushed the async-macros branch 3 times, most recently from ad64fea to b970675 Compare October 8, 2024 20:16
@bennyhodl
Copy link
Contributor Author

bdk-macros did not quite fit our use case because it compiles to wasm target. I took inspiration from it and updated to latest dependencies with dlc-macros.

It requires a dependency of async_trait but by updating all crates to 2021 then we could remove that dependency.

@bennyhodl bennyhodl changed the title feat: use bdk-macros for async dlc-manager feat: use dlc-macros for async dlc-manager Oct 8, 2024
@bennyhodl
Copy link
Contributor Author

There are conflicts with the macro expansion and the unit tests, so i made a script to ignore testing async with all features.

@Tibo-lg
Copy link
Contributor

Tibo-lg commented Oct 15, 2024

Sorry I need to take some time to review that but don't have it right now. But regarding testing, I don't think it's nice to have to run a script to be able to run unit tests. Also I think it'd be good to have the async feature tested in some way, AFAICT it's not the case?

@bennyhodl
Copy link
Contributor Author

I can write tests for the async.

I'm running into an issue with cargo that it tries compiling the non-async implementations. I'm not sure how we should get around this. Any ideas?

@Tibo-lg
Copy link
Contributor

Tibo-lg commented Oct 23, 2024

I'm running into an issue with cargo that it tries compiling the non-async implementations. I'm not sure how we should get around this. Any ideas?

Do you have more details on this? Like what error do you get?

@bennyhodl
Copy link
Contributor Author

I think running all features on the workspace it tries to compile the oracle clients with both async and sync even though those flags are provided in the p2pd-oracle-client and mocks.

$ cargo test --all-features

Checking p2pd-oracle-client v0.1.0 (/Users/ben/Development/rust-dlc/p2pd-oracle-client)
error[E0195]: lifetime parameters or bounds on method `get_announcement` do not match the trait declaration
   --> p2pd-oracle-client/src/lib.rs:152:24
    |
152 |     fn get_announcement(&self, event_id: &str) -> Result<OracleAnnouncement, DlcManagerError> {
    |                        ^ lifetimes do not match method in trait

error[E0195]: lifetime parameters or bounds on method `get_attestation` do not match the trait declaration
   --> p2pd-oracle-client/src/lib.rs:159:23
    |
159 |     fn get_attestation(
    |                       ^ lifetimes do not match method in trait

@bennyhodl bennyhodl force-pushed the async-macros branch 3 times, most recently from 6a38ba9 to 624bd86 Compare November 1, 2024 18:09
@bennyhodl
Copy link
Contributor Author

Updated and tests are passing now. I made the integration tests under a module that is under #[cfg(not(feature = "async"))] I did not add tests for the async implementation yet. I have been using the async branches for dlcdevkit.

I'm not sure about using the macro for async. I think the implementation is harder to reason about than the alternative PR.

Still works though ¯_(ツ)_/¯

@bennyhodl
Copy link
Contributor Author

Although, on second thought this might be a better solution with adding potentially an async blockchain interface.

@Tibo-lg
Copy link
Contributor

Tibo-lg commented Nov 5, 2024

Both approaches have pros and cons but I also prefer this one. I just need to find time to review your code, but if you find someone else that could review it as well it would be great.

To merge this I think I also want to have at least some integration tests using async otherwise we don't know whether it's actually working or not.

@bennyhodl bennyhodl force-pushed the async-macros branch 6 times, most recently from c92307b to 404cf82 Compare November 20, 2024 21:38
@bennyhodl bennyhodl force-pushed the async-macros branch 4 times, most recently from 4bf936f to 2ba6b52 Compare November 20, 2024 22:48
@bennyhodl
Copy link
Contributor Author

bennyhodl commented Nov 20, 2024

@Tibo-lg I have spent a few days trying to get the async tests running. I keep having play whack a mole with the testing dependencies.

I have been using this branch quite a bit in dlcdevkit. CI is passing and there is no code change to core functionality.

Can this get merged?

@Tibo-lg
Copy link
Contributor

Tibo-lg commented Nov 20, 2024

Sorry but I don't want to merge something that is not tested, because then we don't know first if it's actually working, and more importantly we won't know if it get broken by future changes.

I can try to help you get the tests working though, is there anything you have that is worth sharing or should I just start from scratch?

Also note as mentioned in DM that while I'm ok to merge it for now, I don't think that's the direction I want the library to take in the future, and I think it will be better to push async issues out of the library boundaries to avoid having to deal with the complexity.

@bennyhodl
Copy link
Contributor Author

This is a commit I had running async tests. 4bf936f

& the corresponding action https://github.com/p2pderivatives/rust-dlc/actions/runs/11942863204

Locally tests were passing but the tests failed with dropping a tokio runtime for blocking operations.

I believe I tracked it down to the Esplora client and the blocking operations with the Blockchain interface.

@Tibo-lg
Copy link
Contributor

Tibo-lg commented Nov 22, 2024

I get the same error when running locally. I guess it might be necessary to make the blockchain interface async as well?

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