Skip to content

Draft: Prevalidator: close operation stream on close

While developing & testing Explorus, in particular, protocol migration handling, we noticed that the monitor_operations streamed RPCs don't receive a termination event when called against the transition block.

After some investigations, we noticed that the way a new mempool/prevalidator is started for the new protocol and shut down for the old one doesn't allow closing the RPC's stream. In fact, contrary to the usual new heads processing in the same protocol: pushing a Flush request, which triggers on_flush, which in turn resets the stream, among other things, switching to a new protocol doesn't trigger a Flush but rather a worker shut down.

After some attempts to fix the issues, we ended up with the immediate fix done in this MR. The two lines-path extends the on_close function provided by the prevalidator's handler to close monitor_operations stream. In fact, A worker shutdown triggers the worker loop's termination, which triggers a call to on_close handler.

How to test

  • Start a flextesa with adequate parameters to switch from protocol Kathmandu to protocol Lima at level 10
flextesa --protocol-kind=Kathmandu --hard-fork=10:Lima: --until-level=20 --base-port=1234 
  • (Quickly) start a monitor_operations streams in a loop
for i in `seq 1 20`; do
  echo # i = $i
  curl http://127.0.0.1:1234/chains/main/mempool/monitor_operations
done

We should observe that:

  • Without the patch, the for loop will hang at 'i = 9' because of the behavior described above
  • With the patch, the for loop runs correctly until i = 20
Edited by Palmer Sébastien

Merge request reports