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

Read only methods #1052

Closed
wants to merge 26 commits into from
Closed

Conversation

shargon
Copy link
Member

@shargon shargon commented Aug 24, 2019

Close #927

TODO:

@shargon shargon added feature Type: Large changes or new features neo3-preview1 labels Aug 24, 2019
@shargon shargon added this to the NEO 3.0 milestone Aug 24, 2019
@codecov-io
Copy link

codecov-io commented Aug 24, 2019

Codecov Report

Merging #1052 into master will increase coverage by 0.04%.
The diff coverage is 96.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1052      +/-   ##
==========================================
+ Coverage    61.3%   61.34%   +0.04%     
==========================================
  Files         196      196              
  Lines       13412    13420       +8     
==========================================
+ Hits         8222     8233      +11     
+ Misses       5190     5187       -3
Impacted Files Coverage Δ
neo/SmartContract/Native/Tokens/NeoToken.cs 53.21% <ø> (ø) ⬆️
neo/SmartContract/Native/Tokens/Nep5Token.cs 98.2% <ø> (ø) ⬆️
neo/SmartContract/Native/Tokens/GasToken.cs 48.78% <ø> (ø) ⬆️
neo/SmartContract/Native/PolicyContract.cs 94.23% <ø> (ø) ⬆️
neo/SmartContract/InteropService.NEO.cs 26.74% <100%> (ø) ⬆️
neo/SmartContract/ExecutionContextState.cs 100% <100%> (ø) ⬆️
...eo/SmartContract/Native/ContractMethodAttribute.cs 100% <100%> (ø) ⬆️
neo/SmartContract/Native/NativeContract.cs 84.04% <100%> (ø) ⬆️
neo/SmartContract/InteropDescriptor.cs 96.15% <100%> (+0.32%) ⬆️
neo/SmartContract/Manifest/ContractManifest.cs 84.05% <100%> (ø) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98173cf...e8ab57d. Read the comment docs.

Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

Code looks good, except for the Manifest null 'problem' you already mentioned

neo/SmartContract/InteropService.cs Show resolved Hide resolved
neo/SmartContract/InteropService.cs Outdated Show resolved Hide resolved
lock9
lock9 previously requested changes Aug 24, 2019
Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

Hi @shargon, can you add a few tests?

{
this.Method = method;
this.Hash = method.ToInteropMethodHash();
this.Handler = handler;
this.AllowedTriggers = allowedTriggers;
this.RequireWriteAccess = requireWriteAccess;
Copy link
Contributor

@igormcoelho igormcoelho Aug 26, 2019

Choose a reason for hiding this comment

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

I don't think this is a good idea @shargon... what is RequireWriteAccess? To Storage?
Could we remove this?
I thought that, if current ExecutionContextState is running on ReadOnly, then methods that require write access could simply fail (example: Storage.GetCurrentContext`).

Copy link
Member Author

Choose a reason for hiding this comment

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

We can rename the var, but not remove it, because is used for ban the syscall when is in readOnly mode

@@ -88,19 +88,21 @@ internal static bool Invoke(ApplicationEngine engine, uint method)
return false;
if (!descriptor.AllowedTriggers.HasFlag(engine.Trigger))
return false;
if (descriptor.RequireWriteAccess && engine.CurrentContext.GetState<ExecutionContextState>().ReadOnly)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to check this @shargon... if something really needs write access, you can invoke it, and let it fail naturally when it tries to access something that requires writing.
Only thing we need to ensure is: if current context is ReadOnly, then next invocations context will also be ReadOnly, but this is simple, as we can do this when loading new context into stack.

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to ban more syscalls like destroy and create, i think thats is better with this flag

Copy link
Contributor

@igormcoelho igormcoelho left a comment

Choose a reason for hiding this comment

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

Let's remove explicit InteropDescriptor for RequreWriteAccess, as it doesn't make sense on general...
We also don't need to check if invoking a readonly method, from a non-readonly, as the invoked method will naturally fail when it tries to access stuff that it can't.
We just need to ensure that, once the execution mode is invoked on ReadOnly mode, this is put into context, and all next invocations will also be ReadOnly forever.

@shargon
Copy link
Member Author

shargon commented Aug 26, 2019

InteropDescriptor contains the information required for allow or disallow the syscall and this is exactly what we want to do with readOnly methods , for me is good all this logic in the same place, feel free to rename the var @igormcoelho

@shargon
Copy link
Member Author

shargon commented Sep 9, 2019

Require update NEP-3 first

@shargon shargon requested a review from lock9 September 9, 2019 15:35
@lock9 lock9 removed their request for review November 17, 2019 23:50
@erikzhang
Copy link
Member

I think this is not needed now.

@shargon shargon closed this Dec 19, 2019
@erikzhang erikzhang removed this from the NEO 3.0 milestone Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Type: Large changes or new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

neo3 ABI readonly methods
5 participants