package tezos-protocol-020-PsParisC

  1. Overview
  2. Docs
Tezos protocol 020-PsParisC package

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65

doc/src/tezos_raw_protocol_020_PsParisC/already_denounced_storage.ml.html

Source file already_denounced_storage.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com>     *)
(* Copyright (c) 2021 Nomadic Labs, <contact@nomadic-labs.com>               *)
(* Copyright (c) 2022 G.B. Fefe, <gb.fefe@protonmail.com>                    *)
(*                                                                           *)
(*****************************************************************************)

let already_denounced_aux ctxt delegate (level : Level_repr.t) round kind =
  let open Lwt_result_syntax in
  let* denounced_opt =
    Storage.Already_denounced.find
      (ctxt, level.cycle)
      ((level.level, round), delegate)
  in
  match (denounced_opt, (kind : Misbehaviour_repr.kind)) with
  | None, _ -> return_false
  | Some denounced, Double_preattesting ->
      return denounced.for_double_preattesting
  | Some denounced, Double_attesting -> return denounced.for_double_attesting
  | Some denounced, Double_baking -> return denounced.for_double_baking

let already_denounced ctxt delegate level round kind =
  let open Lwt_result_syntax in
  let* answer = already_denounced_aux ctxt delegate level round kind in
  if answer || Round_repr.(round = zero) then return answer
  else
    let* first_level = Storage.Tenderbake.First_level_of_protocol.get ctxt in
    if Raw_level_repr.(level.level >= first_level) then return answer
    else
      (* Exception related to the migration from Oxford to P: because
         Oxford doesn't record the round of misbehaviours, all
         misbehaviours present in the storage at stitching time got
         assigned the round zero. So we also check with the round set
         to zero in the specific case where a misbehaviour:

         - is old enough to have potentially been denounced during
         Oxford (ie. its level is before the first level of P),

         - has a non-zero round (otherwise the new check is identical
         to the previous one anyway), and

         - has not been found in the storage under its own round
         (ie. [answer] is [false]).

         TODO #6957: This whole control flow should be removed from
         protocol Q. *)
      already_denounced_aux ctxt delegate level Round_repr.zero kind

let add_denunciation ctxt delegate (level : Level_repr.t) round kind =
  let open Lwt_result_syntax in
  let* denounced_opt =
    Storage.Already_denounced.find
      (ctxt, level.cycle)
      ((level.level, round), delegate)
  in
  let denounced =
    Option.value denounced_opt ~default:Storage.default_denounced
  in
  let already_denounced =
    match kind with
    | Misbehaviour_repr.Double_baking -> denounced.for_double_baking
    | Double_attesting -> denounced.for_double_attesting
    | Double_preattesting -> denounced.for_double_preattesting
  in
  let*! ctxt =
    if already_denounced then Lwt.return ctxt
    else
      Storage.Already_denounced.add
        (ctxt, level.cycle)
        ((level.level, round), delegate)
        (match kind with
        | Double_baking -> {denounced with for_double_baking = true}
        | Double_attesting -> {denounced with for_double_attesting = true}
        | Double_preattesting -> {denounced with for_double_preattesting = true})
  in
  return (ctxt, already_denounced)

let clear_outdated_cycle ctxt ~new_cycle =
  match Cycle_repr.(sub new_cycle Constants_repr.max_slashing_period) with
  | None -> Lwt.return ctxt
  | Some outdated_cycle -> Storage.Already_denounced.clear (ctxt, outdated_cycle)
OCaml

Innovation. Community. Security.