diff --git a/CHANGES.rst b/CHANGES.rst index f403c6c42a4ddf454d206a75c1ade095d71c600d..9cc0a5d73d6dfbf8fc1731c344d2b8f5fbbeac29 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -155,6 +155,8 @@ Baker - Emit event at Notice level when the delegate is not in the DAL committee, that is, it has no assigned shards at the current level. (:gl:`!15846`) +- A warning has been introduced in case it is observed that the DAL node lags + behind the L1 node. (MR :gl:`!15756`) Miscellaneous ------------- diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index b8acc7b12cc328a98bfce3a81e5f785c9a4e5a78..c7452d336591e1488f82a6d7bbe5d41384b539e5 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -341,6 +341,34 @@ module Profile_handlers = struct in Lwt.return_unit + let warn_if_lagging store ~attestation_level = + let open Lwt_result_syntax in + let*! last_processed_level = + Store.Last_processed_level.load store.Store.last_processed_level + in + match last_processed_level with + | Ok (Some lpl) -> + (* The L1 node's level is at least [current_level = lpl + 2], because the + DAL node processes blocks with a delay of two levels, to be sure that + processed blocks are final. *) + let current_level = Int32.add lpl 2l in + (* The baker's current level is the same as its L1 node and is the one + of the latest seen proposal (ie block). The baker asks for slots' + status when it has seen a proposal at [attestation_level - 1]. *) + let current_baker_level = Int32.sub attestation_level 1l in + (* We check that the baker is not in advance wrt the DAL node, which would + mean that the DAL node is lagging. We allow a slack of 1 level. *) + if Int32.succ current_level < current_baker_level then + Event.( + emit + get_attestable_slots_future_level_warning + (current_level, current_baker_level)) + else Lwt.return_unit + | _ -> + (* We simply don't do anything if we couldn't obtain the + [last_processed_level]. This should not happen though. *) + Lwt.return_unit + let get_attestable_slots ctxt pkh attested_level () () = let get_attestable_slots ~shard_indices store proto_parameters ~attested_level = @@ -393,12 +421,13 @@ module Profile_handlers = struct return (Types.Attestable_slots {slots = flags; published_level}) in call_handler1 (fun () -> + let open Lwt_result_syntax in let store = Node_context.get_store ctxt in + let attestation_level = Int32.pred attested_level in + let*! () = warn_if_lagging store ~attestation_level in (* For retrieving the assigned shard indexes, we consider the committee - at [attested_level - 1], because the (DAL) attestations in the blocks + at [attestation_level], because the (DAL) attestations in the blocks at level [attested_level] refer to the predecessor level. *) - let attestation_level = Int32.pred attested_level in - let open Lwt_result_syntax in let* shard_indices = Node_context.fetch_assigned_shard_indices ctxt diff --git a/src/bin_dal_node/event.ml b/src/bin_dal_node/event.ml index 4ed55ec5d42d68ca426347447a987f4d82f86cba..65dd16dce32faadcb255ffe703e698198a3c0b84 100644 --- a/src/bin_dal_node/event.ml +++ b/src/bin_dal_node/event.ml @@ -626,7 +626,7 @@ let get_attestable_slots_ok_notice = let get_attestable_slots_not_ok_warning = declare_4 ~section - ~name:"get_attestable_slots_warning" + ~name:"get_attestable_slots_missing_shards_warning" ~msg: "For slots {slots_indices} published at level {published_level}, \ {attester} missed shards:\n\ @@ -649,6 +649,18 @@ let get_attestable_slots_not_ok_warning = stored_shards expected_shards)) +let get_attestable_slots_future_level_warning = + declare_2 + ~section + ~name:"get_attestable_slots_future_level_warning" + ~msg: + "It looks like the DAL node is lagging (its current level is \ + {current_level}, while the Layer1 node's level is \ + {current_baker_level})." + ~level:Warning + ("current_level", Data_encoding.int32) + ("current_baker_level", Data_encoding.int32) + let warn_attester_not_dal_attesting = declare_2 ~section