-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Proposal: add emit
keyword; make it the only way to emit events
#2877
Comments
I might be misunderstanding this, but events are marked
|
Oh you mean to have a |
Yes. :) Should have said "emit events" instead of "raise events". EDIT: Perhaps |
This sounds like a good proposal! I'm fine with either |
The (token) |
@elenadimitrova that is solved with #2683. |
I'd go with |
I would very much prefer 'log'. This will be more intuitive to client/web3 developers and is more clear that there is some data coming from the blockchain to be read ok the client. |
I have never liked |
I like this change, would also open the door to treating the event as a first-class object. i.e: var event = Transfer(to, value);
if (success)
emit event; An alternative that does not involve adding a new keyword is: Transfer(to, value).log(); |
log
keyword; make it the only way to emit eventsemit
keyword; make it the only way to emit events
Metaphorically, logging suggests putting an entry in a journal that can be later looked up by the logger - which is not the case. Emitting suggests sending a message out of the current context. (An event emitted by a contract is logged in the transaction receipt.) |
It would be a really good thing if people started using this recommendation, especially in standards propositions. |
ERC20 is pending again? |
@fulldecent Nope! This discusses Solidity syntax, ERC20 (as a standard/template) not affected. EDIT: I've edited the OP to not refer to ERC20 as "pending". |
Ok, I saw "The (currently pending) ERC20 token standard " in the original post. It was like a flashback. |
I first intended to implement this similar to
would be valid syntax at expression level?
|
Ah, @chriseth |
@fulldecent Looks like maybe IMO if you |
Thank you. Just in general I think people should be able to skip to the examples and learn best practices that way. Sort of like how I needed to decide between using |
Why do you think trigger is better? |
@axic because if you ask famous search engines:
So this means trigger verb for event is more popular and so will be more easily understood by computer science students because of that. Maybe the reason behind this popular conception is that an event is atomic. That means an event is so impulsive that its endurance tends to zero like triggering a gun shot. |
This is a good argument. Also "trigger log" is more prevalent than "emit log". Source: https://trends.google.com/trends/explore?q=trigger%20event,emit%20event |
There is one reasoning for The stress is on definitely, because there is no guarantee something/someone is listening for the events and that something will happen as a result. This reasoning may be too thin to justify the keyword, but explains the reasoning behind it. |
As events are impulsive (endurance tends to zero) it looks clear to me |
Indeed, what definitely happens is:
As the underlying technology is a blockchain, the dispatched event is registered on the ledger. So what becomes available to be picked up is not the event, but the event record.
An event could be lost by an intelligent agent which was sleeping at the time the event was triggered. But the agent can also look at the ledger when it wakes up to understand if while sleeping a relevant event happened. |
@ProphetDaniel curiously, I have the opposite impression: Note that emitting light and triggering a gun both send out something, but when triggering a gun, I implicitly include the mechanism of the gun. Compare with emitting the bullet, which is also just the single action. NB: I'm not a native speaker, so this might all be totally wrong. |
|
I don't know if this is the correct place but I would like to ask how the emit and subscribe cost gas? Is the number of subscriber will multiply in cost of emit? |
Subscribers are off-chain actors, only emitting the event costs gas once. See the documentation for more details. |
EDIT: Initially proposed
log
; changed later toemit
.See issue #3252 for another related change.
The issue
The ERC20 token standard describes a
Transfer
event, as well as atransfer()
method.Their "invocation" syntax is not identical:
... yet similar enough to cause confusion.
This highlights an issue for prospective Solidity programmers, where care must be taken to avoid accidentally "mapping" externally-callable functions to similarly-named events. (Sadly, I'm hard-pressed to pull actual examples of this resulting in security vulnerabilities out of my hat, but I do vaguely remember this having been an issue as recently as last year, around
TheDAO
hack.)For this reason, ConsenSys even suggests prefixing event names with
Log
, "to prevent the risk of confusion between functions and events".A solution
Propose introducing a new keyword, tentatively named
log
emit
. So, instead of:we would have:
This makes a (general) semantic differentiation between a function call and logging of an event. (It also renders Consensys' recommendation obsolete.)
The text was updated successfully, but these errors were encountered: