From fc97d92bdfdf4f36e4b1402efae908ae84623379 Mon Sep 17 00:00:00 2001
From: Albin Coquereau <albin.coquereau@nomadic-labs.com>
Date: Mon, 17 Jul 2023 09:39:20 +0200
Subject: [PATCH 1/4] alpha:remove and replace endorsement branch at stitching

replace it with attestation branch
---
 src/proto_alpha/lib_protocol/alpha_context.ml |  4 ++--
 src/proto_alpha/lib_protocol/init_storage.ml  |  4 ++++
 src/proto_alpha/lib_protocol/storage.ml       |  7 +++++++
 src/proto_alpha/lib_protocol/storage.mli      | 14 ++++++++++++--
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml
index e0a6d8b8dc63..c957640ea0ef 100644
--- a/src/proto_alpha/lib_protocol/alpha_context.ml
+++ b/src/proto_alpha/lib_protocol/alpha_context.ml
@@ -564,7 +564,7 @@ module Consensus = struct
   include Raw_context.Consensus
 
   let load_endorsement_branch ctxt =
-    Storage.Tenderbake.Endorsement_branch.find ctxt >>=? function
+    Storage.Tenderbake.Attestation_branch.find ctxt >>=? function
     | Some endorsement_branch ->
         Raw_context.Consensus.set_endorsement_branch ctxt endorsement_branch
         |> return
@@ -572,7 +572,7 @@ module Consensus = struct
 
   let store_endorsement_branch ctxt branch =
     let ctxt = set_endorsement_branch ctxt branch in
-    Storage.Tenderbake.Endorsement_branch.add ctxt branch
+    Storage.Tenderbake.Attestation_branch.add ctxt branch
 end
 
 let prepare_first_block = Init_storage.prepare_first_block
diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml
index a509de615a53..157283fc0fc4 100644
--- a/src/proto_alpha/lib_protocol/init_storage.ml
+++ b/src/proto_alpha/lib_protocol/init_storage.ml
@@ -242,6 +242,10 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract
       Raw_level_repr.of_int32 level >>?= fun level ->
       Storage.Tenderbake.First_level_of_protocol.update ctxt level
       >>=? fun ctxt ->
+      Storage.Tenderbake.Endorsement_branch.find ctxt >>=? fun opt ->
+      Storage.Tenderbake.Endorsement_branch.remove ctxt >>= fun ctxt ->
+      Storage.Tenderbake.Attestation_branch.add_or_remove ctxt opt
+      >>= fun ctxt ->
       Storage.Tenderbake.Forbidden_delegates.init
         ctxt
         Signature.Public_key_hash.Set.empty
diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml
index d9c43c30d27f..7e00c8c616f4 100644
--- a/src/proto_alpha/lib_protocol/storage.ml
+++ b/src/proto_alpha/lib_protocol/storage.ml
@@ -130,6 +130,13 @@ module Tenderbake = struct
       end)
       (Branch)
 
+  module Attestation_branch =
+    Make_single_data_storage (Registered) (Raw_context)
+      (struct
+        let name = ["attestation_branch"]
+      end)
+      (Branch)
+
   module Forbidden_delegates =
     Make_single_data_storage (Registered) (Raw_context)
       (struct
diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli
index 80400f4bd2e3..a91c88bf79af 100644
--- a/src/proto_alpha/lib_protocol/storage.mli
+++ b/src/proto_alpha/lib_protocol/storage.mli
@@ -789,10 +789,20 @@ module Tenderbake : sig
       with type t := Raw_context.t
        and type value = Raw_level_repr.t
 
-  (** [Endorsement_branch] stores a single value composed of the
+  (** [Attestation_branch] stores a single value composed of the
       grandparent hash and the predecessor's payload (computed with
       the grandparent hash) used to verify the validity of
-      endorsements. *)
+      attestations. *)
+  module Attestation_branch :
+    Single_data_storage
+      with type value = Block_hash.t * Block_payload_hash.t
+       and type t := Raw_context.t
+
+  (** Similar to [Attestation_branch] but only used for the stitching from
+      Nairobi.
+
+      TODO: https://gitlab.com/tezos/tezos/-/issues/6082
+      This should be removed once in the next protocol. *)
   module Endorsement_branch :
     Single_data_storage
       with type value = Block_hash.t * Block_payload_hash.t
-- 
GitLab


From 9a135f4cafef07219eeadd8f6914df146f57a251 Mon Sep 17 00:00:00 2001
From: Albin Coquereau <albin.coquereau@nomadic-labs.com>
Date: Mon, 17 Jul 2023 09:44:29 +0200
Subject: [PATCH 2/4] alpha: rename for_double_endorsing context storage field

---
 docs/protocols/alpha.rst                | 4 ++++
 src/proto_alpha/lib_protocol/storage.ml | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst
index 6e2a80183e6d..caeab195def6 100644
--- a/docs/protocols/alpha.rst
+++ b/docs/protocols/alpha.rst
@@ -117,6 +117,10 @@ Breaking Changes
   baker's spendable balance to their frozen deposits. Bakers need to use the
   ``stake`` pseudo-operation to increase their frozen deposits. (MR :gl:`!8087`)
 
+- Field ``for_double_endorsing`` from context storage has been renamed into
+  ``for_double_attesting``. (MR :gl:`!9486`)
+
+
 RPC Changes
 -----------
 
diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml
index 7e00c8c616f4..492d24694a95 100644
--- a/src/proto_alpha/lib_protocol/storage.ml
+++ b/src/proto_alpha/lib_protocol/storage.ml
@@ -1107,7 +1107,7 @@ module Slashed_level = struct
         (for_double_attesting, for_double_baking))
       (fun (for_double_attesting, for_double_baking) ->
         {for_double_attesting; for_double_baking})
-      (obj2 (req "for_double_endorsing" bool) (req "for_double_baking" bool))
+      (obj2 (req "for_double_attestating" bool) (req "for_double_baking" bool))
 end
 
 module Cycle = struct
-- 
GitLab


From 05b7cbab5c68ac6dc53dc9e3c9bc0ce3a960d835 Mon Sep 17 00:00:00 2001
From: Albin Coquereau <albin.coquereau@nomadic-labs.com>
Date: Mon, 17 Jul 2023 09:47:43 +0200
Subject: [PATCH 3/4] alpha: rename endorsing_reward_per_slot in storage

---
 docs/protocols/alpha.rst                          |  2 ++
 src/proto_alpha/lib_protocol/bootstrap_storage.ml |  2 +-
 src/proto_alpha/lib_protocol/storage.ml           | 12 ++++++------
 src/proto_alpha/lib_protocol/storage.mli          |  2 +-
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst
index caeab195def6..82266468ac9a 100644
--- a/docs/protocols/alpha.rst
+++ b/docs/protocols/alpha.rst
@@ -120,6 +120,8 @@ Breaking Changes
 - Field ``for_double_endorsing`` from context storage has been renamed into
   ``for_double_attesting``. (MR :gl:`!9486`)
 
+- Field ``endorsing_reward_per_slot`` from rewards storage has been renamed into
+  ``attesting_reward_per_slot``. (MR :gl:`!9486`)
 
 RPC Changes
 -----------
diff --git a/src/proto_alpha/lib_protocol/bootstrap_storage.ml b/src/proto_alpha/lib_protocol/bootstrap_storage.ml
index 0669274352bc..64c270fd850f 100644
--- a/src/proto_alpha/lib_protocol/bootstrap_storage.ml
+++ b/src/proto_alpha/lib_protocol/bootstrap_storage.ml
@@ -199,7 +199,7 @@ let init ctxt ~typecheck_smart_contract ~typecheck_smart_rollup
             baking_reward_fixed_portion =
               constants.reward_weights.base_total_rewards_per_minute;
             baking_reward_bonus_per_slot = Tez_repr.zero;
-            endorsing_reward_per_slot = Tez_repr.zero;
+            attesting_reward_per_slot = Tez_repr.zero;
           }))
   >|=? fun ctxt -> (ctxt, balance_updates)
 
diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml
index 492d24694a95..951114624d8a 100644
--- a/src/proto_alpha/lib_protocol/storage.ml
+++ b/src/proto_alpha/lib_protocol/storage.ml
@@ -1567,7 +1567,7 @@ module Ramp_up = struct
   type reward = {
     baking_reward_fixed_portion : Tez_repr.t;
     baking_reward_bonus_per_slot : Tez_repr.t;
-    endorsing_reward_per_slot : Tez_repr.t;
+    attesting_reward_per_slot : Tez_repr.t;
   }
 
   module Rewards =
@@ -1586,23 +1586,23 @@ module Ramp_up = struct
               (fun {
                      baking_reward_fixed_portion;
                      baking_reward_bonus_per_slot;
-                     endorsing_reward_per_slot;
+                     attesting_reward_per_slot;
                    } ->
                 ( baking_reward_fixed_portion,
                   baking_reward_bonus_per_slot,
-                  endorsing_reward_per_slot ))
+                  attesting_reward_per_slot ))
               (fun ( baking_reward_fixed_portion,
                      baking_reward_bonus_per_slot,
-                     endorsing_reward_per_slot ) ->
+                     attesting_reward_per_slot ) ->
                 {
                   baking_reward_fixed_portion;
                   baking_reward_bonus_per_slot;
-                  endorsing_reward_per_slot;
+                  attesting_reward_per_slot;
                 })
               (obj3
                  (req "baking_reward_fixed_portion" Tez_repr.encoding)
                  (req "baking_reward_bonus_per_slot" Tez_repr.encoding)
-                 (req "endorsing_reward_per_slot" Tez_repr.encoding)))
+                 (req "attesting_reward_per_slot" Tez_repr.encoding)))
       end)
 end
 
diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli
index a91c88bf79af..45531a7575a7 100644
--- a/src/proto_alpha/lib_protocol/storage.mli
+++ b/src/proto_alpha/lib_protocol/storage.mli
@@ -687,7 +687,7 @@ module Ramp_up : sig
   type reward = {
     baking_reward_fixed_portion : Tez_repr.t;
     baking_reward_bonus_per_slot : Tez_repr.t;
-    endorsing_reward_per_slot : Tez_repr.t;
+    attesting_reward_per_slot : Tez_repr.t;
   }
 
   module Rewards :
-- 
GitLab


From e99657b59028b797899d70bea130160a860551f4 Mon Sep 17 00:00:00 2001
From: Albin Coquereau <albin.coquereau@nomadic-labs.com>
Date: Mon, 17 Jul 2023 09:53:04 +0200
Subject: [PATCH 4/4] alpha: rename missed_endorsement in contract storage

---
 docs/protocols/alpha.rst                           |  3 +++
 .../delegate_missed_endorsements_storage.ml        | 12 ++++++------
 src/proto_alpha/lib_protocol/storage.ml            | 12 ++++++------
 src/proto_alpha/lib_protocol/storage.mli           | 14 +++++++-------
 4 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst
index 82266468ac9a..23cbf54ae870 100644
--- a/docs/protocols/alpha.rst
+++ b/docs/protocols/alpha.rst
@@ -123,6 +123,9 @@ Breaking Changes
 - Field ``endorsing_reward_per_slot`` from rewards storage has been renamed into
   ``attesting_reward_per_slot``. (MR :gl:`!9486`)
 
+- Field ``missed_endorsements`` from contract storage has been renamed into
+  ``missed_attestations``. (MR :gl:`!9486`)
+
 RPC Changes
 -----------
 
diff --git a/src/proto_alpha/lib_protocol/delegate_missed_endorsements_storage.ml b/src/proto_alpha/lib_protocol/delegate_missed_endorsements_storage.ml
index 0895efb5357b..f52df13743e0 100644
--- a/src/proto_alpha/lib_protocol/delegate_missed_endorsements_storage.ml
+++ b/src/proto_alpha/lib_protocol/delegate_missed_endorsements_storage.ml
@@ -53,10 +53,10 @@ let record_endorsing_participation ctxt ~delegate ~participation
   | Participated -> Stake_storage.set_active ctxt delegate
   | Didn't_participate -> (
       let contract = Contract_repr.Implicit delegate in
-      Storage.Contract.Missed_endorsements.find ctxt contract >>=? function
+      Storage.Contract.Missed_attestations.find ctxt contract >>=? function
       | Some {remaining_slots; missed_levels} ->
           let remaining_slots = remaining_slots - endorsing_power in
-          Storage.Contract.Missed_endorsements.update
+          Storage.Contract.Missed_attestations.update
             ctxt
             contract
             {remaining_slots; missed_levels = missed_levels + 1}
@@ -96,7 +96,7 @@ let record_endorsing_participation ctxt ~delegate ~participation
               let minimal_activity = expected_slots * numerator / denominator in
               let maximal_inactivity = expected_slots - minimal_activity in
               let remaining_slots = maximal_inactivity - endorsing_power in
-              Storage.Contract.Missed_endorsements.init
+              Storage.Contract.Missed_attestations.init
                 ctxt
                 contract
                 {remaining_slots; missed_levels = 1}))
@@ -139,11 +139,11 @@ let record_baking_activity_and_pay_rewards_and_fees ctxt ~payload_producer
 
 let check_and_reset_delegate_participation ctxt delegate =
   let contract = Contract_repr.Implicit delegate in
-  Storage.Contract.Missed_endorsements.find ctxt contract >>=? fun missed ->
+  Storage.Contract.Missed_attestations.find ctxt contract >>=? fun missed ->
   match missed with
   | None -> return (ctxt, true)
   | Some missed_endorsements ->
-      Storage.Contract.Missed_endorsements.remove ctxt contract >>= fun ctxt ->
+      Storage.Contract.Missed_attestations.remove ctxt contract >>= fun ctxt ->
       return (ctxt, Compare.Int.(missed_endorsements.remaining_slots >= 0))
 
 type participation_info = {
@@ -208,7 +208,7 @@ let participation_info ctxt delegate =
         Tez_repr.mul_exn endorsing_reward_per_slot expected_cycle_activity
       in
       let contract = Contract_repr.Implicit delegate in
-      Storage.Contract.Missed_endorsements.find ctxt contract
+      Storage.Contract.Missed_attestations.find ctxt contract
       >>=? fun missed_endorsements ->
       let missed_slots, missed_levels, remaining_allowed_missed_slots =
         match missed_endorsements with
diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml
index 951114624d8a..ea6d406475ec 100644
--- a/src/proto_alpha/lib_protocol/storage.ml
+++ b/src/proto_alpha/lib_protocol/storage.ml
@@ -147,10 +147,10 @@ end
 
 (** Contracts handling *)
 
-type missed_endorsements_info = {remaining_slots : int; missed_levels : int}
+type missed_attestations_info = {remaining_slots : int; missed_levels : int}
 
-module Missed_endorsements_info = struct
-  type t = missed_endorsements_info
+module Missed_attestations_info = struct
+  type t = missed_attestations_info
 
   let encoding =
     let open Data_encoding in
@@ -270,13 +270,13 @@ module Contract = struct
       end)
       (Tez_repr)
 
-  module Missed_endorsements =
+  module Missed_attestations =
     Indexed_context.Make_map
       (Registered)
       (struct
-        let name = ["missed_endorsements"]
+        let name = ["missed_attestations"]
       end)
-      (Missed_endorsements_info)
+      (Missed_attestations_info)
 
   module Manager =
     Indexed_context.Make_map
diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli
index 45531a7575a7..27486dbcd4af 100644
--- a/src/proto_alpha/lib_protocol/storage.mli
+++ b/src/proto_alpha/lib_protocol/storage.mli
@@ -49,7 +49,7 @@ end
 
 module Block_round : Simple_single_data_storage with type value = Round_repr.t
 
-type missed_endorsements_info = {remaining_slots : int; missed_levels : int}
+type missed_attestations_info = {remaining_slots : int; missed_levels : int}
 
 module Slashed_deposits_history : sig
   type slashed_percentage = int
@@ -114,22 +114,22 @@ module Contract : sig
        and type t := Raw_context.t
        and type local_context := local_context
 
-  (** If the value is not set, the delegate didn't miss any endorsing
+  (** If the value is not set, the delegate didn't miss any attesting
      opportunity.  If it is set, this value is a record of type
-     [missed_endorsements_info], where:
+     [missed_attestations_info], where:
    - [remaining_slots] is the difference between the maximum number of
      slots that can be missed and the number of missed slots;
      therefore, when the number is positive, it represents the number
      of slots that a delegate can still miss before forfeiting its
-     endorsing rewards for the current cycle; when the number is zero
+     attesting rewards for the current cycle; when the number is zero
      it means rewards are not lost, but no further slots can be
      missed anymore;
    - [missed_levels] represents the number of missed levels (for
-     endorsing). *)
-  module Missed_endorsements :
+     attesting). *)
+  module Missed_attestations :
     Indexed_data_storage
       with type key = Contract_repr.t
-       and type value = missed_endorsements_info
+       and type value = missed_attestations_info
        and type t := Raw_context.t
 
   (** The manager of a contract *)
-- 
GitLab