From 149077fa905f3263dc4514d3fcfbb747936481ec Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 17 Oct 2023 18:00:47 +0200 Subject: [PATCH] Revert "alpha/baker: remove highwatermarks encoding that allow legacy" This reverts commit 5404e3b4f7991b067c2fa6009fe794984a4d7ea3. --- .../lib_delegate/baking_highwatermarks.ml | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_highwatermarks.ml b/src/proto_alpha/lib_delegate/baking_highwatermarks.ml index 695d348e3e79..d4e3201795c8 100644 --- a/src/proto_alpha/lib_delegate/baking_highwatermarks.ml +++ b/src/proto_alpha/lib_delegate/baking_highwatermarks.ml @@ -123,7 +123,7 @@ type highwatermarks = { type t = highwatermarks -let encoding = +let encoding ~use_legacy_attestation_name = let open Data_encoding in conv (fun {blocks; preattestations; attestations} -> @@ -132,8 +132,32 @@ let encoding = {blocks; preattestations; attestations}) (obj3 (req "blocks" highwatermark_delegate_map_encoding) - (req "preattestations" highwatermark_delegate_map_encoding) - (req "attestations" highwatermark_delegate_map_encoding)) + (req + (if use_legacy_attestation_name then "preendorsements" + else "preattestations") + highwatermark_delegate_map_encoding) + (req + (if use_legacy_attestation_name then "endorsements" + else "attestations") + highwatermark_delegate_map_encoding)) + +let load_encoding = + let open Data_encoding in + union + [ + case + ~title:"new" + (Tag 0) + (encoding ~use_legacy_attestation_name:false) + Option.some + Fun.id; + case + ~title:"old" + (Tag 1) + (encoding ~use_legacy_attestation_name:true) + Option.some + Fun.id; + ] let empty = { @@ -145,13 +169,16 @@ let empty = (* We do not lock these functions. The caller will be already locked. *) let load (cctxt : #Protocol_client_context.full) location : t tzresult Lwt.t = protect (fun () -> - cctxt#load (Baking_files.filename location) encoding ~default:empty) + cctxt#load (Baking_files.filename location) load_encoding ~default:empty) let save_highwatermarks (cctxt : #Protocol_client_context.full) filename highwatermarks : unit tzresult Lwt.t = protect (fun () -> (* TODO: improve the backend so we don't write partial informations *) - cctxt#write filename highwatermarks encoding) + cctxt#write + filename + highwatermarks + (encoding ~use_legacy_attestation_name:false)) let may_sign highwatermarks ~delegate ~level ~round = match DelegateMap.find delegate highwatermarks with -- GitLab