diff --git a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml index 0e66e086f5368ef56c2a52d56c96bc8eb62792b4..af122706389f5019eb558518a0a4b1bcbf5429a7 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_errors.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_errors.ml @@ -35,7 +35,11 @@ type error += | (* `Temporary *) Sc_rollup_remove_lcc | (* `Temporary *) Sc_rollup_staker_backtracked | (* `Temporary *) Sc_rollup_too_far_ahead - | (* `Temporary *) Sc_rollup_too_recent + | (* `Temporary *) + Sc_rollup_commitment_too_recent of { + current_level : Raw_level_repr.t; + min_level : Raw_level_repr.t; + } | (* `Temporary *) Sc_rollup_unknown_commitment of Sc_rollup_commitment_repr.Hash.t @@ -303,13 +307,28 @@ let () = in register_error_kind `Temporary - ~id:"Sc_rollup_too_recent" + ~id:"Sc_rollup_commitment_too_recent" ~title:"Commitment too recent" ~description - ~pp:(fun ppf () -> Format.fprintf ppf "%s" description) - Data_encoding.empty - (function Sc_rollup_too_recent -> Some () | _ -> None) - (fun () -> Sc_rollup_too_recent) ; + ~pp:(fun ppf (current_level, min_level) -> + Format.fprintf + ppf + "%s@ Current level: %a,@ minimal level: %a" + description + Raw_level_repr.pp + current_level + Raw_level_repr.pp + min_level) + Data_encoding.( + obj2 + (req "current_level" Raw_level_repr.encoding) + (req "min_level" Raw_level_repr.encoding)) + (function + | Sc_rollup_commitment_too_recent {current_level; min_level} -> + Some (current_level, min_level) + | _ -> None) + (fun (current_level, min_level) -> + Sc_rollup_commitment_too_recent {current_level; min_level}) ; let description = "Unknown commitment." in register_error_kind `Temporary diff --git a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml index 959c564df0ad34965deef6f9a0c87182d6828a1c..0c24a69dc6c855674541a4ad17c13d81340a47b5 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.ml @@ -355,10 +355,13 @@ let cement_commitment ctxt rollup new_lcc = Store.Commitment_added.get (ctxt, rollup) new_lcc in let* () = + let current_level = (Raw_context.current_level ctxt).level in + let min_level = + Raw_level_repr.add new_lcc_added refutation_deadline_blocks + in fail_when - (let level = (Raw_context.current_level ctxt).level in - Raw_level_repr.(level < add new_lcc_added refutation_deadline_blocks)) - Sc_rollup_too_recent + Raw_level_repr.(current_level < min_level) + (Sc_rollup_commitment_too_recent {current_level; min_level}) in (* update LCC *) let* ctxt, lcc_size_diff = diff --git a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli index b5481e05849a85037351b06b7ba2389708dff0f5..172e1d9155b9aa943c194f94b868207902139360 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_stake_storage.mli @@ -103,7 +103,7 @@ val publish_commitment : {li [Sc_rollup_does_not_exist] if [rollup] does not exist} {li [Sc_rollup_unknown_commitment] if [commitment] does not exist} {li [Sc_rollup_parent_not_lcc] if [commitment] is not the child of the last cemented commitment} - {li [Sc_rollup_too_recent] if [commitment] has not passed its deadline} + {li [Sc_rollup_commitment_too_recent] if [commitment] has not passed its deadline} {li [Sc_rollup_no_stakers] if there are zero stakers} {li [Sc_rollup_disputed] if at least one staker is not staked on [commitment]} } *) diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index e6b0457ae9ac5f1eba69c4a371cb33dfc0f9885a..b3dbf2c441ab432d0ebc5fe8d58923613050cb0c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -694,11 +694,14 @@ let test_challenge_window_period_boundaries () = challenge window period. *) let* () = let expect_apply_failure = function - | Environment.Ecoproto_error (Sc_rollup_errors.Sc_rollup_too_recent as e) + | Environment.Ecoproto_error + (Sc_rollup_errors.Sc_rollup_commitment_too_recent _ as e) :: _ -> Assert.test_error_encodings e ; return_unit - | _ -> failwith "It should have failed with [Sc_rollup_too_recent]" + | _ -> + failwith + "It should have failed with [Sc_rollup_commitment_too_recent]" in commit_and_cement_after_n_bloc ~expect_apply_failure diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml index cd6c41e770d8eac5f769a2848f637b33120cf4e4..e03b309adb360bdc57c17d0478bb0a3b84e6f19a 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_storage.ml @@ -930,7 +930,7 @@ let test_cement_fail_too_recent () = compressed_state = Sc_rollup_repr.State_hash.zero; } in - let* c1, _level, ctxt = + let* c1, level, ctxt = lift @@ Sc_rollup_stake_storage.Internal_for_tests.refine_stake ctxt @@ -938,20 +938,24 @@ let test_cement_fail_too_recent () = staker commitment in + let min_cementation_level = Raw_level_repr.add level challenge_window in let* () = assert_fails_with ~loc:__LOC__ (Sc_rollup_stake_storage.cement_commitment ctxt rollup c1) - Sc_rollup_errors.Sc_rollup_too_recent + (Sc_rollup_errors.Sc_rollup_commitment_too_recent + {current_level = level; min_level = min_cementation_level}) in let ctxt = Raw_context.Internal_for_tests.add_level ctxt (challenge_window - 1) in + let level = (Raw_context.current_level ctxt).level in let* () = assert_fails_with ~loc:__LOC__ (Sc_rollup_stake_storage.cement_commitment ctxt rollup c1) - Sc_rollup_errors.Sc_rollup_too_recent + (Sc_rollup_errors.Sc_rollup_commitment_too_recent + {current_level = level; min_level = min_cementation_level}) in assert_true ctxt