runtime-sdk: begin and end block during check batch
This PR makes it more straightforward to do setup/teardown actions without knowing whether the runtime is being invoked in check vs execute mode.
Codecov Report
Merging #218 (57cd7fb) into main (bf9c3dc) will decrease coverage by
0.04%. The diff coverage is0.00%.
@@ Coverage Diff @@
## main #218 +/- ##
==========================================
- Coverage 71.76% 71.71% -0.05%
==========================================
Files 54 54
Lines 3127 3129 +2
==========================================
Hits 2244 2244
- Misses 863 865 +2
Partials 20 20
| Impacted Files | Coverage Δ | |
|---|---|---|
| runtime-sdk/src/dispatcher.rs | 6.20% <0.00%> (-0.09%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update bf9c3dc...57cd7fb. Read the comment docs.
can you explain what the use case is?
I load a database before a batch, and sync the db after a batch. It's not feasible to create the database in the middle of the batch, and is actually unsafe to do so because the state being passed in lives no longer than the batch, so must be destroyed afterward.
It doesn't need to be begin_block but it needs to happen in about the same place. This patch is working well for me so far, though.
My concern is that this could result in erroneous CheckTx execution due to the handlers being invoked multiple times on the same state for the same round.
Shall I add another lifecycle hook roughly named before_handlers/after_handlers? I needed to add the same begin/end_batch invocation to the queries handler, too, for the same reason.
Yeah I think a separate hook would make sense with the explicit mention what the difference to the block hooks is. Because this seems more like some "prepare context" and "teardown context" or something?