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

seal_reentrant_count #5

Merged
merged 5 commits into from
May 29, 2022
Merged

seal_reentrant_count #5

merged 5 commits into from
May 29, 2022

Conversation

yarikbratashchuk
Copy link

@yarikbratashchuk yarikbratashchuk commented May 18, 2022

seal_reentrant_count, seal_account_entrance_count
paritytech#11018

@yarikbratashchuk yarikbratashchuk self-assigned this May 18, 2022
@yarikbratashchuk yarikbratashchuk changed the title Add logic, test, broken benchmark seal_reentrant_count May 19, 2022
@yarikbratashchuk yarikbratashchuk added enhancement New feature or request question Further information is requested labels May 19, 2022
@xgreenx
Copy link

xgreenx commented May 19, 2022

Should we pass contract address (account id) into the call, so we don't read it from the memory? @xgreenx

We can do that but better as a separate function to not affect the size of the contract.

@yarikbratashchuk
Copy link
Author

Should we pass contract address (account id) into the call, so we don't read it from the memory? @xgreenx

We can do that but better as a separate function to not affect the size of the contract.

didn't get it

@yarikbratashchuk
Copy link
Author

@xgreenx, please take a look

self.reentrant_count.push(12u8);
12
}
fn account_entrance_count(&mut self, _account_id: AccountIdOf<Self::T>) -> u32 { unimplemented!() }
Copy link

Choose a reason for hiding this comment

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

Why it is unimplemented?

Copy link
Author

Choose a reason for hiding this comment

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

don't see a good reason to test this

// to the calling instance. A value of 0 means no reentrancy.
[__unstable__] seal_reentrant_count(ctx) -> u32 => {
ctx.charge_gas(RuntimeCosts::ReentrantCount)?;
Ok(ctx.ext.reentrant_count() as u32)
Copy link

Choose a reason for hiding this comment

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

You can use ctx.ext.account_entrance_count here and only add charging for reading of the data.

Copy link
Author

@yarikbratashchuk yarikbratashchuk May 29, 2022

Choose a reason for hiding this comment

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

ctx.ext.reentrant_count uses ctx.ext.account_entrance_count

}

fn account_entrance_count(&mut self, account_id: AccountIdOf<Self::T>) -> u32 {
self.frames().filter_map(|f| Some(f.delegate_caller.is_none() && &f.account_id == &account_id)).count() as u32
Copy link

Choose a reason for hiding this comment

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

I guess you can do that in a cheaper way without filtering.

Copy link
Author

Choose a reason for hiding this comment

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

i have no idea why filtering is considered not cheap enough

frame/contracts/src/exec.rs Outdated Show resolved Hide resolved
params: vec![],
return_type: Some(ValueType::I32),
}],
call_body: Some(body::repeated(r * API_BENCHMARK_BATCH_SIZE, &[
Copy link

Choose a reason for hiding this comment

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

I think the right will be to calculate how much we need gas for one iteration over frames. And in the functions charge exactly for the count of frames. But we can leave it for official review from the contract-pallet team if you wish=)

Copy link
Author

Choose a reason for hiding this comment

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

Good idea actually. I propose to move forward with it as it is for now.

@yarikbratashchuk yarikbratashchuk merged commit 523a683 into master May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-pleasereview enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants