package tezos-protocol-011-PtHangz2
Tezos protocol 011-PtHangz2 package
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/src/tezos_raw_protocol_011_PtHangz2/init_storage.ml.html
Source file init_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 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *) (* Copyright (c) 2019-2020 Nomadic Labs <contact@nomadic-labs.com> *) (* Copyright (c) 2021 DaiLambda, Inc. <contact@dailambda.jp> *) (* *) (* 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 log fmt = Logging.log Notice fmt (* Remove me after protocol H *) module Flatten_storage_for_H = struct (* /tree_abs_key/key/*/*/*/*/* => /tree_abs_key/key/rename( */*/*/*/* ) *) let flatten ~tree ~key ~depth ~rename ~init = Raw_context.Tree.fold tree key ~depth:(`Eq depth) ~init ~f:(fun old_key tree dst_tree -> let new_key = rename old_key in Raw_context.Tree.add_tree dst_tree new_key tree) >>= fun dst_tree -> (* rm -rf $index_key mv $tmp_index_key $index_key *) Raw_context.Tree.add_tree tree key dst_tree (* /abs_key/*(depth')/mid_key/*(depth) => /abs_key/*(depth')/mid_key/rename( *(depth) ) *) let fold_flatten ctxt abs_key depth' mid_key ~depth ~rename = Raw_context.fold ~depth:(`Eq depth') ctxt abs_key ~init:ctxt ~f:(fun key tree ctxt -> (* tree at /abs_key/*(depth') *) flatten ~tree ~key:mid_key ~depth ~rename ~init:(Raw_context.Tree.empty ctxt) >>= fun tree -> Raw_context.add_tree ctxt (abs_key @ key) tree) let flatten_storage ctxt = log "flattening the context storage: this operation may take several minutes" ; let rec drop n xs = match (n, xs) with | (0, _) -> xs | (_, []) -> assert false | (_, _ :: xs) -> drop (n - 1) xs in let rename_blake2b = function | n1 :: n2 :: n3 :: n4 :: n5 :: n6 :: rest -> String.concat "" [n1; n2; n3; n4; n5; n6] :: rest | _ -> assert false in let rename_public_key_hash = function | (("ed25519" | "secp256k1" | "p256") as k) :: n1 :: n2 :: n3 :: n4 :: n5 :: n6 :: rest -> k :: String.concat "" [n1; n2; n3; n4; n5; n6] :: rest | _ -> assert false in (* /contracts/index/xx/xx/xx/xx/xx/xx/yyyyyyyyyy => /contracts/index/yyyyyyyyyy *) fold_flatten ctxt ["contracts"; "index"] 0 [] ~depth:7 ~rename:(drop 6) >>= fun ctxt -> (* *) (* /contracts/index/yyyyyyyyyy/delegated/xx/xx/xx/xx/xx/xx/zzzzzzzzzz => /contracts/index/yyyyyyyyyy/delegated/zzzzzzzzzz *) fold_flatten ctxt ["contracts"; "index"] 1 ["delegated"] ~depth:7 ~rename:(drop 6) >>= fun ctxt -> (* *) (* /big_maps/index/xx/xx/xx/xx/xx/xx/n => /big_maps/index/n *) fold_flatten ctxt ["big_maps"; "index"] 0 [] ~depth:7 ~rename:(drop 6) >>= fun ctxt -> (* *) (* /big_maps/index/n/contents/yy/yy/yy/yy/yy/yyyyyyyy => /big_maps/index/n/contents/yyyyyyyyyyyyyyyyyy *) fold_flatten ctxt ["big_maps"; "index"] 1 ["contents"] ~depth:6 ~rename:rename_blake2b >>= fun ctxt -> (* *) (* /rolls/index/x/y/n => /rolls/index/n *) fold_flatten ctxt ["rolls"; "index"] 0 [] ~depth:3 ~rename:(drop 2) >>= fun ctxt -> (* *) (* /rolls/owner/current/x/y/n => /rolls/owner/current/n *) fold_flatten ctxt ["rolls"; "owner"; "current"] 0 [] ~depth:3 ~rename:(drop 2) >>= fun ctxt -> (* *) (* /rolls/owner/snapshot/n1/n2/x/y/n3 => /rolls/owner/snapshot/n1/n2/n3 *) fold_flatten ctxt ["rolls"; "owner"; "snapshot"] 2 [] ~depth:3 ~rename:(drop 2) >>= fun ctxt -> (* *) (* /commitments/xx/xx/xx/xx/xx/xxxxxx => /commitments/xxxxxxxxxxxxxxxx *) fold_flatten ctxt ["commitments"] 0 [] ~depth:6 ~rename:rename_blake2b >>= fun ctxt -> (* *) (* /votes/listings/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /votes/listings/kk/xxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["votes"; "listings"] 0 [] ~depth:7 ~rename:rename_public_key_hash >>= fun ctxt -> (* *) (* /votes/ballots/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /votes/ballots/KK/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["votes"; "ballots"] 0 [] ~depth:7 ~rename:rename_public_key_hash >>= fun ctxt -> (* *) (* /votes/proposals_count/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /votes/proposals_count/kk/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["votes"; "proposals_count"] 0 [] ~depth:7 ~rename:rename_public_key_hash >>= fun ctxt -> (* *) (* /votes/proposals/xx/xx/xx/xx/xx/xx/xxxxxxxx => /votes/proposals/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["votes"; "proposals"] 0 [] ~depth:6 ~rename:rename_blake2b >>= fun ctxt -> (* *) (* /votes/proposals/yyyyyyyyyyyyyyyyyyyy/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /votes/proposals/yyyyyyyyyyyyyyyyyyyy/KK/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["votes"; "proposals"] 1 [] ~depth:7 ~rename:rename_public_key_hash >>= fun ctxt -> (* *) (* /delegates/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /delegates/KK/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["delegates"] 0 [] ~depth:7 ~rename:rename_public_key_hash >>= fun ctxt -> (* *) (* /active_delegates_with_rolls/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /active_delegates_with_rolls/KK/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["active_delegates_with_rolls"] 0 [] ~depth:7 ~rename:rename_public_key_hash >>= fun ctxt -> (* *) (* /delegates_with_frozen_balance/n/kk/xx/xx/xx/xx/xx/xx/xxxxxxxx => /delegates_with_frozen_balance/n/KK/xxxxxxxxxxxxxxxxxxxx *) fold_flatten ctxt ["delegates_with_frozen_balance"] 1 [] ~depth:7 ~rename:rename_public_key_hash >|= fun ctxt -> log "context storage flattening completed" ; ctxt end (* To add invoices, you can use a helper function like this one: (** Invoice a contract at a given address with a given amount. Returns the updated context and a balance update receipt (singleton list). The address must be a valid base58 hash, otherwise this is no-op and returns an empty receipts list. Do not fail if something goes wrong. *) let invoice_contract ctxt ~address ~amount_mutez = match Tez_repr.of_mutez amount_mutez with | None -> Lwt.return (ctxt, []) | Some amount -> ( Contract_repr.of_b58check address >>?= (fun recipient -> Contract_storage.credit ctxt recipient amount >|=? fun ctxt -> ( ctxt, Receipt_repr. [(Contract recipient, Credited amount, Protocol_migration)] )) >|= function Ok res -> res | Error _ -> (ctxt, []) ) *) let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness = Raw_context.prepare_first_block ~level ~timestamp ~fitness ctxt >>=? fun (previous_protocol, ctxt) -> match previous_protocol with | Genesis param -> (* This is the genesis protocol: initialise the state *) Commitment_storage.init ctxt param.commitments >>=? fun ctxt -> Roll_storage.init ctxt >>=? fun ctxt -> Seed_storage.init ctxt >>=? fun ctxt -> Contract_storage.init ctxt >>=? fun ctxt -> Bootstrap_storage.init ctxt ~typecheck ?ramp_up_cycles:param.security_deposit_ramp_up_cycles ?no_reward_cycles:param.no_reward_cycles param.bootstrap_accounts param.bootstrap_contracts >>=? fun ctxt -> Roll_storage.init_first_cycles ctxt >>=? fun ctxt -> Vote_storage.init ctxt ~start_position:(Level_storage.current ctxt).level_position >>=? fun ctxt -> Storage.Block_priority.init ctxt 0 >>=? fun ctxt -> Vote_storage.update_listings ctxt >>=? fun ctxt -> (* Must be called after other originations since it unsets the origination nonce.*) Liquidity_baking_migration.init ctxt ~typecheck >>=? fun (ctxt, operation_results) -> Storage.Pending_migration.Operation_results.init ctxt operation_results | Granada_010 -> Flatten_storage_for_H.flatten_storage ctxt >>= return let prepare ctxt ~level ~predecessor_timestamp ~timestamp ~fitness = Raw_context.prepare ~level ~predecessor_timestamp ~timestamp ~fitness ctxt >>=? fun ctxt -> Storage.Pending_migration.remove ctxt
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>