oasis-sdk icon indicating copy to clipboard operation
oasis-sdk copied to clipboard

runtime-sdk: begin and end block during check batch

Open nhynes opened this issue 4 years ago • 5 comments

This PR makes it more straightforward to do setup/teardown actions without knowing whether the runtime is being invoked in check vs execute mode.

nhynes avatar Jun 13 '21 22:06 nhynes

Codecov Report

Merging #218 (57cd7fb) into main (bf9c3dc) will decrease coverage by 0.04%. The diff coverage is 0.00%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update bf9c3dc...57cd7fb. Read the comment docs.

codecov[bot] avatar Jun 13 '21 22:06 codecov[bot]

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.

nhynes avatar Jun 14 '21 13:06 nhynes

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.

kostko avatar Jun 15 '21 13:06 kostko

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.

nhynes avatar Jun 18 '21 12:06 nhynes

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?

kostko avatar Jun 18 '21 12:06 kostko