-
Notifications
You must be signed in to change notification settings - Fork 249
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(promise): PromiseOrValue sets should_return flag correctly on serialization #407
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can you confirm it. Probably can use cross-contract-high-level for this
Will do now. Question, why is serde serialize implemented for promise, but borsh serialize isn't? Seems weird that |
Okay so I've dug a bit deeper, the return was set during a |
So to be clear what has changed since your review is:
I've rebuilt and tested all examples, and can now look into writing tests to hit these other cases |
@@ -417,6 +417,18 @@ impl serde::Serialize for Promise { | |||
} | |||
} | |||
|
|||
impl borsh::BorshSerialize for Promise { | |||
fn serialize<W: Write>(&self, _writer: &mut W) -> Result<(), Error> { | |||
*self.should_return.borrow_mut() = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a drive by observer, this line of code (and the one for serde) looks reeeeeealy weird to me. I think it makes sense to at least write a comment here explaining what exactly are we doing here and why. I also have a very strong gut feeling that there should be a less magical way to achieve the desired effect, but I need to dig deeper into the code to confirm that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I'm just trying to make the least cost change to avoid breakage. This will definitely be a thing to keep in mind as evolving the API because this seems like it has the potential to be a footgun
Edit: And also I don't know if you see but there is this same pattern for the serde::Serialize, this just brings it inline with that to not have inconsistencies between serializations
Love to see these fixes for community-created issues. Thank you |
Looking through the code, this seems to be the change that fixes #285
I will go create a minimal repro or see if this can be done in a test to make sure this doesn't come back
closes #285