37

Background on Events: https://github.com/ethereum/wiki/wiki/Solidity-Features

Events allow the convenient usage of the EVM logging facilities. Events are inheritable members of contracts. When they are called, they cause the arguments to be stored in the transaction's log. Up to three parameters can receive the attribute indexed which will cause the respective arguments to be treated as log topics instead of data. The hash of the signature of the event is always one of the topics. All non-indexed arguments will be stored in the data part of the log.

If not inside the smart contract container, where does the Log data reside?

35

Logs are part of the transaction receipts. They are generated by the clients when executing transactions and stored alongside the blockchain to allow retrieving them.

Logs are not part of the blockchain itself per se, since they are not required for consensus (they are just historical data), however they are verified by the blockchain as the transaction receipt hashes are stored inside the blocks.

  • 3
    Logs are stored in one node? or all nodes?, only client side? – Satoshi Nakanishi Feb 17 '16 at 4:41
  • 8
    All nodes currently (light nodes will probably not store them, but they will definitely have a way to retrieve them). There is no server/client concepts. All nodes are equal. – Péter Szilágyi Feb 17 '16 at 14:26
  • If you get the event logs from one node, it might be manipulated. How do you make sure if event logs are correct? – Satoshi Nakanishi Apr 27 '16 at 10:40
  • 3
    The hash of the event logs are recorded in the block header. If you have the header, you can simply gather all logs from that block, hash them and compare to the value stored in the header. If they match, no manipulation took place. – Péter Szilágyi Apr 27 '16 at 10:46
  • 2
    In practice, where do I find the logs ? – Teleporting Goat Oct 27 '16 at 14:14
15

To help with @Peter's answer, it helps to realize what are events and logs. Events, logs, and event logs are usually Ethereum terms that are interchangeable (in some contexts a particular term is favored, for example events in Solidity and web3.js, and logs as in the EVM and Yellow Paper).

Events/logs are the result of LOG opcodes being executed in the EVM. They are a part of "internal transactions" which are derived by executing transaction data through the EVM.

Thus, as long as you have the blockchain then you have all the events/logs. For efficiency, they are stored as @Peter describes, but conceptually they don't need to be stored since they could be recomputed from the blockchain (which by definition consists of all blocks and transaction data).

Finally, pruning has no effect on events/logs because pruning is done to the state trie and no blocks are lost.

0

From the official documentation: https://solidity.readthedocs.io/en/v0.4.24/contracts.html#events

Events are inheritable members of contracts. When they are called, they cause the arguments to be stored in the transaction’s log - a special data structure in the blockchain. These logs are associated with the address of the contract and will be incorporated into the blockchain and stay there as long as a block is accessible (forever as of Frontier and Homestead, but this might change with Serenity). Log and event data is not accessible from within contracts (not even from the contract that created them).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.