package octez-shell-libs

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file client_admin_commands.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com>     *)
(* Copyright (c) 2019-2021 Nomadic Labs, <contact@nomadic-labs.com>          *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

let block_param ~name ~desc t =
  Tezos_clic.param
    ~name
    ~desc
    (Tezos_clic.parameter (fun _ str -> Lwt.return (Block_hash.of_b58check str)))
    t

let operation_param ~name ~desc t =
  Tezos_clic.param
    ~name
    ~desc
    (Tezos_clic.parameter (fun _ str ->
         Lwt.return (Operation_hash.of_b58check str)))
    t

let commands () =
  let open Lwt_result_syntax in
  let open Tezos_clic in
  let group =
    {
      name = "admin";
      title = "Commands to perform privileged operations on the node";
    }
  in
  [
    command
      ~group
      ~desc:"Make the node forget its decision of rejecting blocks."
      no_options
      (prefixes ["unmark"; "invalid"]
      @@ seq_of_param
           (block_param
              ~name:"block"
              ~desc:"blocks to remove from invalid list"))
      (fun () blocks (cctxt : #Client_context.full) ->
        List.iter_es
          (fun block ->
            let* () = Shell_services.Invalid_blocks.delete cctxt block in
            let*! () =
              cctxt#message
                "Block %a no longer marked invalid."
                Block_hash.pp
                block
            in
            return_unit)
          blocks);
    command
      ~group
      ~desc:"Make the node forget every decision of rejecting blocks."
      no_options
      (prefixes ["unmark"; "all"; "invalid"; "blocks"] @@ stop)
      (fun () (cctxt : #Client_context.full) ->
        let* invalid_blocks = Shell_services.Invalid_blocks.list cctxt () in
        List.iter_es
          (fun {Chain_services.hash; _} ->
            let* () = Shell_services.Invalid_blocks.delete cctxt hash in
            let*! () =
              cctxt#message
                "Block %a no longer marked invalid."
                Block_hash.pp_short
                hash
            in
            return_unit)
          invalid_blocks);
    command
      ~group
      ~desc:
        "Retrieve the current checkpoint and display it in a format compatible \
         with node argument `--checkpoint`."
      no_options
      (fixed ["show"; "current"; "checkpoint"])
      (fun () (cctxt : #Client_context.full) ->
        let* checkpoint_hash, checkpoint_level =
          Shell_services.Chain.Levels.checkpoint cctxt ~chain:cctxt#chain ()
        in
        let*! () =
          cctxt#message
            "@[<v 0>Checkpoint: %a@,Checkpoint level: %ld@]"
            Block_hash.pp
            checkpoint_hash
            checkpoint_level
        in
        return_unit);
    command
      ~group
      ~desc:
        "Remove an operation from the mempool if present, reverting its effect \
         if it was applied. Add it to the set of banned operations to prevent \
         it from being fetched/processed/injected in the future. Note: If the \
         baker has already received the operation, then it's necessary to \
         restart it to flush the operation from it."
      no_options
      (prefixes ["ban"; "operation"]
      @@ operation_param ~name:"operation" ~desc:"hash of operation to ban"
      @@ stop)
      (fun () op_hash (cctxt : #Client_context.full) ->
        let* () =
          Shell_services.Mempool.ban_operation cctxt ~chain:cctxt#chain op_hash
        in
        let*! () =
          cctxt#message "Operation %a is now banned." Operation_hash.pp op_hash
        in
        return_unit);
    command
      ~group
      ~desc:
        "Remove an operation from the set of banned operations (nothing \
         happens if it was not banned)."
      no_options
      (prefixes ["unban"; "operation"]
      @@ operation_param ~name:"operation" ~desc:"hash of operation to unban"
      @@ stop)
      (fun () op_hash (cctxt : #Client_context.full) ->
        let* () =
          Shell_services.Mempool.unban_operation
            cctxt
            ~chain:cctxt#chain
            op_hash
        in
        let*! () =
          cctxt#message
            "Operation %a is now unbanned."
            Operation_hash.pp
            op_hash
        in
        return_unit);
    command
      ~group
      ~desc:"Clear the set of banned operations."
      no_options
      (fixed ["unban"; "all"; "operations"])
      (fun () (cctxt : #Client_context.full) ->
        let* () =
          Shell_services.Mempool.unban_all_operations
            cctxt
            ~chain:cctxt#chain
            ()
        in
        let*! () = cctxt#message "All operations are now unbanned." in
        return_unit);
  ]
OCaml

Innovation. Community. Security.