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

Add batch calls for faster deployment #62

Merged
merged 9 commits into from
Apr 26, 2023
Merged

Add batch calls for faster deployment #62

merged 9 commits into from
Apr 26, 2023

Conversation

Maar-io
Copy link
Contributor

@Maar-io Maar-io commented Apr 2, 2023

For some of the calls the block POV size limit is easily reached. Implement batch calls for all functions which need the bulk calls for configuration and deployment.
It should not be mandatory to include this trait.
The example use of this trait is in the example/equippable.
Integration test is in tests/batch.spec.ts.

Acceptance criteria:

  • cover add_asset_to_many_tokens- with integration test
  • cover add_many_children with integration test
  • cover transfer_many with integration test

@Maar-io
Copy link
Contributor Author

Maar-io commented Apr 22, 2023

#55

@Maar-io Maar-io linked an issue Apr 22, 2023 that may be closed by this pull request
use new message for each call

added reentrancy flag

spelling fix
@Maar-io Maar-io marked this pull request as ready for review April 25, 2023 10:38
RmrkError::InputVectorTooBig
);
for token_id in tokens {
_ = MultiAsset::add_asset_to_token(self, token_id.clone(), asset_id, None);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we handle errors instead of ignoring with an empty assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


pub const MAX_BATCH_TOKENS_PER_ASSET: usize = 50;
pub const MAX_BATCH_ADD_CHILDREN: usize = 50;
pub const MAX_BATCH_TOKEN_TRANSFERS: usize = 50;
Copy link
Contributor

@boyswan boyswan Apr 25, 2023

Choose a reason for hiding this comment

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

I'm inclined to say we remove max_batch limits as they are arbitrary and there's no way for the user to change this if we assume a wrong number.

There's no real danger here of the transaction trapping if the user provides an vec that is too large, as we are not storing anything. IMO we should leave this to the user to manage with dry-runs/etc rather than imposing an arbitrary limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -91,6 +94,13 @@ where
Ok(())
}

/// Assign metadata to specified token.
default fn transfer_token(&mut self, to: AccountId, id: Id, data: Vec<u8>) -> Result<()> {
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 required? The user can use PSP34::transfer directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was not reachable from ref call. Now it is calling psp34::internal

RmrkError::InputVectorTooBig
);
for (token_id, destination) in token_to_destination {
_ = Minting::transfer_token(self, destination, token_id, Vec::new());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use PSP34::transfer?

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

Comment on lines 97 to 98
/// Assign metadata to specified token.
default fn transfer_token(&mut self, to: AccountId, id: Id, data: Vec<u8>) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this function is required please update the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not needed

RmrkError::InputVectorTooBig
);
for (parent_id, child_id) in parent_child_pair {
_ = Nesting::add_child(self, parent_id, (child_contract, child_id));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ = Nesting::add_child(self, parent_id, (child_contract, child_id));
Nesting::add_child(self, parent_id, (child_contract, child_id))?;


for (let i = 0; i < sets; i++) {
var tokenList = new Array();
// console.log("addAssetToManyTokens, set=", i)
Copy link
Contributor

Choose a reason for hiding this comment

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

These commented-out logs should probably be removed.

Copy link
Contributor

@boyswan boyswan left a comment

Choose a reason for hiding this comment

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

LGTM

@Maar-io Maar-io merged commit 74e7289 into main Apr 26, 2023
@boyswan boyswan deleted the feature/batch2 branch July 24, 2023 08:03
@boyswan boyswan restored the feature/batch2 branch July 24, 2023 08:03
@boyswan boyswan deleted the feature/batch2 branch July 24, 2023 08:04
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.

Add assets to multiple tokens with single call
3 participants