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

Fix InvalidOperationException #3558

Merged
merged 5 commits into from
Oct 30, 2024
Merged

Fix InvalidOperationException #3558

merged 5 commits into from
Oct 30, 2024

Conversation

shargon
Copy link
Member

@shargon shargon commented Oct 29, 2024

Description

Close #3553

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • TestCyclicReference

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@shargon shargon requested review from Jim8y and AnnaShaleva October 29, 2024 08:27
@shargon
Copy link
Member Author

shargon commented Oct 29, 2024

@AnnaShaleva it seems that is not called inside the VM, could you also checked please?

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

A really nice catch and fix, especially for stackitem serialization, because it may affect contracts state. no fork required.

AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Oct 29, 2024
Inspired by neo-project/neo#3558, although this
PR fixes different implementation of stackitem serializatior that is
used outside of VM.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
json["value"] = new JArray(((IList<KeyValuePair<ContractParameter, ContractParameter>>)parameter.Value).Select(p =>
{
JObject item = new();
item["key"] = ToJson(p.Key, context);
item["value"] = ToJson(p.Value, context);
return item;
}));
context.Remove(parameter);
if (!context.Remove(parameter)) throw new InvalidOperationException("Circular reference.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this if statement needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should not happen, but always is a good practice checks the methods returns

@shargon shargon merged commit a42bc8d into master Oct 30, 2024
6 of 7 checks passed
@shargon shargon deleted the fix-circular-reference branch October 30, 2024 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected InvalidOperationException: Circular reference in Stackitem.ToJson
4 participants