2

Is it okay to emit event from hooks like on_initialize()? For example, I have ~1000 items in storage and in a loop in on_initialize() I want to emit an event if certain process is completed, then is it fine? Also, what is more efficient:

a) emit a burst of 1000 events, or

b) combine events information in a large Vec<> and then send it wrapping in an event?

1

1 Answer 1

1

It is perfectly fine to emit events from on_initialize/on_finalize. These events get tagged with a different phase. Normally events have phase ApplyExtrinsic(ext_id) but here they get Initialization and Finalization respectively. Just something to look out for in the frontend.

Also what is more efficient a) emit burst of 1000 events or b) combine events information in a large Vec<> and then send it wrapping in an event?

Efficient in what way? Events are a vector in storage to which each new one is appended.
I would probably just go with the standard approach of one event per event to keep the code simple, but I don't think there is a general downside of large events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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