-
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): Disallow invalid batch_then
Promise syntax
#410
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.
Reading the code for this, it was quite confusing why the drops are currently called in reverse order.
As explained here, promises implement RAII pattern, because of the RAII execution of drops is happening in the reverse order from the initialization, because this is how stack with local variables works -- it deallocates variables in reverse order from their initialization.
It is however irrelevant in what order contract calls are scheduled, since there is no notion of order for them. Dependencies between receipts form a DAG and not necessarily a sequence.
Instead of making the syntax mentioned in the issue work, we need to explicitly prohibit it, because it is hard to reason about the expected result from it.
I get this, I guess I was confused as to how the promises are queued through the blockchain interface.
Sounds good, I'll do that now, although I should definitely dig deeper into the internals of promise scheduling here. Would be ideal if this check could be done at compile-time, but I can just panic if the Promise is already to be queued. |
833ddb2
to
8dddbe8
Compare
51bcc3b
to
70d5251
Compare
near-sdk/src/promise.rs
Outdated
PromiseSubtype::Single(x) => { | ||
let mut after = x.after.borrow_mut(); | ||
if after.is_some() { | ||
panic!("Cannot callback promise which is already scheduled after another"); |
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.
Maybe we should replace this panic and the one below with env::panic
Just to update here, since the direction of this functionality is not in consensus, I will wait for the intentions and ideal API to be discussed in #263 and add information as I learn the internals better |
Fixed changes and Max is OOO
batch_then
Promise syntax
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.
Makes sense to disable this pattern for now
I assume we need final approval from @nearmax on this? |
I'll wait until after the weekend to merge but he's OOO and we went with the option he was proposing so probably not necessary. |
#263: The drops were inconsistent because when a promise was queued using
then
twice, the first would be dropped because it would be replaced with the other one, causing it to be queued through the blockchain interface before the other drop occurs.Reading the code for this, it was quite confusing why the drops are currently called in reverse order.
in the case of
p1.then(p2).then(p3)
, the drops are called inp3 -> p2 -> p1
and also the queues are also in that order, which means that thebatch_then
is called forp3
beforep2
then thebatch_create
is called withp1
. This is how they were queued before the change, so I avoided making a breaking change until I understand why everything is queued like this (do the actions get pulled off like a stack?).This change just makes it so that the combinations referred to in the issue now call all things through the blockchain interface consistently.
Closes #263