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(dev-tools): Clean up excess Arc usage in sdk #2217

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

DaughterOfMars
Copy link
Contributor

@DaughterOfMars DaughterOfMars commented Sep 3, 2024

Description of change

The SDK APIs are overusing Arcs and can be simplified. Additionally, some places where dynamic dispatch is used unnecessarily can be replaced with static typing.

Reasoning

The extra Arc in IotaClient is there directly because of the signature of the TransactionBuilder::new fn, which takes an Arc<dyn DataReader>. DataReader is implemented on ReadApi and thus this constructor must be called with Arc<ReadApi>.

One alternative solution is to use the ReadApi directly in the client and wrap it in an Arc to pass to this fn. This would work, but still means that there is a double Arc used in the TransactionBuilder.

This PR opts to replace the dynamic dispatch with a static type to avoid these layers of indirection.

Related Issues

Closes #2187

@DaughterOfMars DaughterOfMars requested review from a team as code owners September 3, 2024 14:51
@thibault-martinez
Copy link
Member

Fixing the iota-sdk issue #2187 leaks outside of our crate. Moving forward with it or not will be at the discretion of the impacted crates owners.

@DaughterOfMars DaughterOfMars requested review from a team as code owners October 8, 2024 13:15
Thoralf-M
Thoralf-M previously approved these changes Oct 14, 2024
@alexsporn alexsporn added the dev-tools Issues related to the Developer Tools Team label Oct 23, 2024
samuel-rufi
samuel-rufi previously approved these changes Oct 28, 2024
crates/iota-open-rpc/src/generate_json_rpc_spec.rs Outdated Show resolved Hide resolved
pub struct TransactionBuilder(Arc<dyn DataReader + Sync + Send>);
#[async_trait]
impl<T: DataReader + Send + Sync + 'static> DataReader for Arc<T> {
async fn get_owned_objects(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change somehow related to the Arc cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was necessary because of the cleanup of one of the methods

@iota-ci iota-ci added the sc-platform Issues related to the Smart Contract Platform group. label Dec 9, 2024
@thibault-martinez thibault-martinez dismissed stale reviews from samuel-rufi and Thoralf-M December 10, 2024 08:52

Code changed too much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-tools Issues related to the Developer Tools Team sc-platform Issues related to the Smart Contract Platform group.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task (iota-sdk)]: IotaClient::read_api double Arc?
8 participants