Rollups: fetch DAL attestation status and lag from DAL nodes
For deps, see https://docs.google.com/spreadsheets/d/1rak6nBXnlNggnOnA5WTF7idHNXn0hsSCnVqrypHBew0/edit?usp=sharing
Handled item from original MR !19500 (merged):
- Adapt the Rollup node.
Some pseudo-code to show the decision diagram involved in deciding if a slot should be imported or not:
(* Simplified version; full version in Sc_rollup_proof_repr.ml at
https://gitlab.com/tezos/tezos/-/blame/master/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml?ref_type=heads#L241. *)
let import_level_is_valid ~attestation_lag ~inbox_level ~published_level =
let attested_level = published_level + attestation_lag in
attested_level <= inbox_level
let import_slot_content ~inbox_level slot_id =
let open Lwt_result_syntax in
let {published_level; index} = slot_id in
let* status =
(* This can return an error if the DAL node is down or does not have the
data, in which case the rollup currently crashes. *)
Dal_node.get_slot_status ~published_level ~index
in
match status with
| `Attested attestation_lag ->
if
not
@@ import_level_is_valid
~attestation_lag
~inbox_level
~published_level
then
(* This should not happen for honest operators. We cannot have a DAL
slot attested before its attested_level is baked, unless the kernel
tries to import data that would be attested in the future (could happen
with Etherlink if the import signal is sent too early?
This check is the same as the refutation games use to decide if it's
legit to import a page. *)
return_none
else
(* Importing the slot is legitimate; let's download its data. *)
let index = Sc_rollup_proto_types.Dal.Slot_index.to_octez index in
let* pages =
(* This can return an error if the DAL node is down or does not have
the slot and enough shards to reconstruct it, in which case the
rollup currently crashes. *)
DAL_node.download_confirmed_slot_pages ~published_level ~index
in
return (Some pages)
| `Unattested | `Unpublished ->
(* Here, we do not care about the lag because:
- If the import level is valid and the rollup asks to import the data,
we will provide an empty page (i.e., return None here).
- If the import level is not valid, it is safe to provide an empty page
as well, as refutation games do exactly the same thing. See:
https://gitlab.com/tezos/tezos/-/blame/master/src/proto_alpha/lib_protocol/sc_rollup_proof_repr.ml?ref_type=heads#L317. *)
return_none
| `Waiting_attestation ->
(* Here, we systematically fail when the status is
[`Waiting_attestation`]. But this can be due to at least two
different reasons:
- The DAL node is offline or lagging, or has not updated its state yet ->
in this case the rollup node will crash; however, it will eventually
get the final status (Attested or Unattested) and progress.
- The kernel requested the page too early. If we have a lag at hand,
the function import_level_is_valid would return false, in which case
we should return None. Fortunately, after some L1 levels, the “waiting
for attestation” status will turn to either Attested or Unattested.
If Attested with some lag, import_level_is_valid will detect that the
slot should not be imported because the import inbox_level is smaller
than the attested_level. If unattested, no slot data will be imported. *)
attestation_status_not_final published_level index
Edited by Mohamed IGUERNLALA