[go: up one dir, main page]

EVM Node: Fix off-by-one in the stream RPC for blueprints

Context

When an observer starts, it connects to another EVM node to fetch blueprints,
starting from `next_blueprint_number'.

If (1) it was in sync with its EVM node endpoint, and (2) it is just stops and
restarted, then from the current implementation of the stream RPC, it is
requesting a blueprint from the future, and the RPC fails with

    [
      {
        "kind": "temporary",
        "id": "failure",
        "msg": "Cannot start watching from a level in the future"
      }
    ]

This patch changes the behavior to allow an observer node to wait for the next
level.

It is not clear why the observer node was not failing without this patch...

Manually testing the MR

Applies this patch

diff --git a/etherlink/bin_node/lib_dev/evm_services.ml b/etherlink/bin_node/lib_dev/evm_services.ml
index 6dcdd95835..5e2213a481 100644
--- a/etherlink/bin_node/lib_dev/evm_services.ml
+++ b/etherlink/bin_node/lib_dev/evm_services.ml
@@ -41,9 +41,10 @@ let create_blueprint_watcher_service from_level =
   (* input source block creating a stream to observe the events *)
   let* head_info = Evm_context.head_info () in
   let (Qty next) = head_info.next_blueprint_number in
+  let head_level = Z.pred next in
   let* () =
-    if Z.(Compare.(next < of_int64 from_level)) then
-      Stdlib.failwith "Cannot start watching from a level too far in the future"
+    if Z.(Compare.(head_level < of_int64 from_level)) then
+      Stdlib.failwith "Cannot start watching from a level in the future"
     else return_unit
   in
 
@@ -51,7 +52,7 @@ let create_blueprint_watcher_service from_level =
   let next =
     let next_level_requested = ref Z.(of_int64 from_level) in
     fun () ->
-      if Z.Compare.(!next_level_requested < next) then (
+      if Z.Compare.(!next_level_requested <= head_level) then (
         let current_request = !next_level_requested in
         (next_level_requested := Z.(succ current_request)) ;
         let* blueprint = Evm_context.blueprint (Qty current_request) in

and witness, powerless, that the test does not pass anymore.

dune exec -- etherlink/tezt/tests/main.exe --file evm_sequencer.ml --title 'Alpha: Can restart an Observer node' --verbose

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Thomas Letan

Merge request reports

Loading