Cannot cement a commitment if a staker on the old LCC is withdrawn
- Description:
(from an internal Slack discussion)
We may have a problem in the l1 scoru cementing logic. Basically I wrote a test to check that for a staker staker1 to cement a commitment, we first need to withdraw the staker2 at the old lcc. However, when trying to cement the commitment, I get that the call fails with error No stakers . If I attempt to cement the commitment without withdrawing the stake at the old lcc, then I get an error Attempted to cement a disputed commitment , which is as expected. If I try to refine the stake for the first staker again, this fails with error commitment_backtracked Even if (after the withdrawal of staker_2) staker_2 tries again to deposit and refine the stake, I get an error attempted to cement a disputed commitment If I refine the stake for staker2 without withdrawing and depositing again, cementing the commitment succeeds.
- steps to reproduce:
Apply the following patch:
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 d93dbec4a8..d4520a201a 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
@@ -301,6 +301,31 @@ let test_publish () =
in
assert_true ctxt
+let test_withdraw_and_cement () =
+ let* (ctxt, rollup, staker1, staker2) =
+ originate_rollup_and_deposit_with_two_stakers ()
+ in
+ let challenge_window =
+ Constants_storage.sc_rollup_challenge_window_in_blocks ctxt
+ in
+ let commitment =
+ Sc_rollup_repr.Commitment.
+ {
+ predecessor = Sc_rollup_repr.Commitment_hash.zero;
+ inbox_level = Raw_level_repr.of_int32_exn 21l;
+ number_of_messages = number_of_messages_exn 3l;
+ number_of_ticks = number_of_ticks_exn 1232909l;
+ compressed_state = Sc_rollup_repr.State_hash.zero;
+ }
+ in
+ let* (c1, ctxt) =
+ lift @@ Sc_rollup_storage.refine_stake ctxt rollup staker1 commitment
+ in
+ let* ctxt = lift @@ Sc_rollup_storage.withdraw_stake ctxt rollup staker2 in
+ let ctxt = Raw_context.Internal_for_tests.add_level ctxt challenge_window in
+ let* ctxt = lift @@ Sc_rollup_storage.cement_commitment ctxt rollup c1 in
+ assert_true ctxt
+
let test_deposit_then_publish () =
let* ctxt = new_context () in
lift
@@ -1605,6 +1630,10 @@ let tests =
test_deposit_then_refine_bad_inbox;
Tztest.tztest "stake on existing node" `Quick test_stake_on_existing_node;
Tztest.tztest "publish commitment" `Quick test_publish;
+ Tztest.tztest
+ "withdraw stake of another staker before cementing"
+ `Quick
+ test_withdraw_and_cement;
Tztest.tztest "stake then publish" `Quick test_deposit_then_publish;
Tztest.tztest "publish with no rollup" `Quick test_publish_missing_rollup;
Tztest.tztest
Run:
dune exec src/proto_alpha/lib_protocol/test/unit/main.exe \
-- test "^\[Unit\] Sc_rollup_storage.ml$"