text
stringlengths
0
601k
let snapshot_rolls_for_cycle ctxt cycle = Storage . Roll . Snapshot_for_cycle . get ctxt cycle >>=? fun index -> Storage . Roll . Snapshot_for_cycle . update ctxt cycle ( index + 1 ) >>=? fun ctxt -> Storage . Roll . Owner . snapshot ctxt ( cycle , index ) >>=? fun ctxt -> Storage . Roll . Next . get ctxt >>=? fun last...
let freeze_rolls_for_cycle ctxt cycle = Storage . Roll . Snapshot_for_cycle . get ctxt cycle >>=? fun max_index -> Storage . Seed . For_cycle . get ctxt cycle >>=? fun seed -> let rd = Seed_repr . initialize_new seed [ Bytes . of_string " roll_snapshot " ] in let seq = Seed_repr . sequence rd 0l in let selected_index =...
module Random = struct let int32_to_bytes i = let b = Bytes . make 4 ' 0 ' in TzEndian . set_int32 b 0 i ; b let level_random seed use ( level : Level_repr . t ) = let position = level . Level_repr . cycle_position in Seed_repr . initialize_new seed [ Bytes . of_string ( " level " ^ use ^ " " ) ; : int32_to_bytes posit...
let baking_rights_owner c level ~ priority = Random . owner c " baking " level priority
let endorsement_rights_owner c level ~ slot = Random . owner c " endorsement " level slot
let count_rolls ctxt delegate = Storage . Roll . Delegate_roll_list . find ctxt delegate >>=? function | None -> return 0 | Some head_roll -> let [ @ coq_struct " roll " ] rec loop acc roll = Storage . Roll . Successor . find ctxt roll >>=? function | None -> return acc | Some next -> loop ( succ acc ) next in loop 1 h...
let get_change ctxt delegate = Storage . Roll . Delegate_change . find ctxt delegate >|=? Option . value ~ default : Tez_repr . zero
module Delegate = struct let fresh_roll ctxt = Storage . Roll . Next . get ctxt >>=? fun roll -> Storage . Roll . Next . update ctxt ( Roll_repr . succ roll ) >|=? fun ctxt -> ( roll , ctxt ) let get_limbo_roll ctxt = Storage . Roll . Limbo . find ctxt >>=? function | None -> fresh_roll ctxt >>=? fun ( roll , ctxt ) ->...
module Contract = struct let add_amount c contract amount = get_contract_delegate c contract >>=? function | None -> return c | Some delegate -> Delegate . add_amount c delegate amount let remove_amount c contract amount = get_contract_delegate c contract >>=? function | None -> return c | Some delegate -> Delegate . r...
let init ctxt = Storage . Roll . Next . init ctxt Roll_repr . first
let init_first_cycles ctxt = let preserved = Constants_storage . preserved_cycles ctxt in List . fold_left_es ( fun ctxt c -> let cycle = Cycle_repr . of_int32_exn ( Int32 . of_int c ) in Storage . Roll . Snapshot_for_cycle . init ctxt cycle 0 >>=? fun ctxt -> snapshot_rolls_for_cycle ctxt cycle >>=? fun ctxt -> freeze...
let snapshot_rolls ctxt = let current_level = Raw_context . current_level ctxt in let preserved = Constants_storage . preserved_cycles ctxt in let cycle = Cycle_repr . add current_level . cycle ( preserved + 2 ) in snapshot_rolls_for_cycle ctxt cycle
let cycle_end ctxt last_cycle = let preserved = Constants_storage . preserved_cycles ctxt in ( match Cycle_repr . sub last_cycle preserved with | None -> return ctxt | Some cleared_cycle -> clear_cycle ctxt cleared_cycle ) >>=? fun ctxt -> let frozen_roll_cycle = Cycle_repr . add last_cycle ( preserved + 1 ) in freeze_...
let update_tokens_per_roll ctxt new_tokens_per_roll = let constants = Raw_context . constants ctxt in let old_tokens_per_roll = constants . tokens_per_roll in Raw_context . patch_constants ctxt ( fun constants -> { constants with Constants_repr . tokens_per_roll = new_tokens_per_roll } ) >>= fun ctxt -> let decrease = ...
type error += | Consume_roll_change | No_roll_for_delegate | No_stake_snapshot_for_cycle of Cycle_repr . t | Unregistered_delegate of Signature . Public_key_hash . t
let ( ) = let open Data_encoding in register_error_kind ` Permanent ~ id " : contract . manager . consume_roll_change " ~ title " : Consume roll change " ~ description " : Change is not enough to consume a roll . " ~ pp ( : fun ppf ( ) -> Format . fprintf ppf " Not enough change to consume a roll . " ) empty ( function...
let get_contract_delegate ctxt contract = Storage . Contract . Delegate . find ctxt contract
let delegate_pubkey ctxt delegate = Storage . Contract . Manager . find ctxt ( Contract_repr . implicit_contract delegate ) >>=? function | None | Some ( Manager_repr . Hash _ ) -> fail ( Unregistered_delegate delegate ) | Some ( Manager_repr . Public_key pk ) -> return pk
let fold ctxt ~ f init = Storage . Roll_legacy . Next . get ctxt >>=? fun last -> let [ @ coq_struct " roll " ] rec loop ctxt roll acc = if Roll_repr_legacy . ( roll = last ) then return acc else Storage . Roll_legacy . Owner . find ctxt roll >>=? function | None -> loop ctxt ( Roll_repr_legacy . succ roll ) acc | Some...
let get_change ctxt delegate = Storage . Roll_legacy . Delegate_change . find ctxt delegate >|=? Option . value ~ default : Tez_repr . zero
module Delegate = struct let fresh_roll ctxt = Storage . Roll_legacy . Next . get ctxt >>=? fun roll -> Storage . Roll_legacy . Next . update ctxt ( Roll_repr_legacy . succ roll ) >|=? fun ctxt -> ( roll , ctxt ) let get_limbo_roll ctxt = Storage . Roll_legacy . Limbo . find ctxt >>=? function | None -> fresh_roll ctxt...
module Contract = struct let add_amount c contract amount = get_contract_delegate c contract >>=? function | None -> return c | Some delegate -> Delegate . add_amount c delegate amount let remove_amount c contract amount = get_contract_delegate c contract >>=? function | None -> return c | Some delegate -> Delegate . r...
module Roman = struct exception BadNumeral of char let eval = function | ' I ' -> 1 | ' V ' -> 5 | ' X ' -> 10 | ' L ' -> 50 | ' C ' -> 100 | ' D ' -> 500 | ' M ' -> 1000 | c -> raise ( raiseBadNumeral ( raiseBadNumeralc ) raiseBadNumeralc ) raiseBadNumeralc let arabic ( x : string ) string : int = let n = String . len...
let of_roman s = try Ok ( arabic ( String . uppercase s ) s ) s with BadNumeral c -> error " invalid char in Roman numeral " c sexp_of_char
let of_arabic i = if i > 0 then Ok i else error " invalid non - positive Roman numeral " i sexp_of_int
module Visibility = struct type t = Public | Private let encoding = string_enum [ " public " , Public ; " private " , Private ] end
module Create = struct module Query = Empty . Query module Request = struct module Invite_3pid = struct type t = { id_server : string ; medium : string ; addresss : string } [ @@ deriving accessor ] let encoding = let to_tuple t = t . id_server , t . medium , t . addresss in let of_tuple v = let id_server , medium , ad...
module Create_alias = struct module Query = Empty . Query module Request = struct type t = { room_id : string } [ @@ deriving accessor ] let encoding = let to_tuple t = t . room_id in let of_tuple v = let room_id = v in { room_id } in let with_tuple = obj1 ( req " room_id " string ) in conv to_tuple of_tuple with_tuple...
module Resolve_alias = struct module Query = Empty . Query module Request = Empty . Json module Response = struct type t = { room_id : string option ; servers : string list option } [ @@ deriving accessor ] let encoding = let to_tuple t = t . room_id , t . servers in let of_tuple v = let room_id , servers = v in { room...
module Delete_alias = struct module Query = Empty . Query module Request = Empty . Json module Response = Empty . Json end
module Room_summary = struct type t = { heroes : string list option ; joined_member_count : int option ; invited_member_count : int option ; } [ @@ deriving accessor ] let encoding = let to_tuple t = t . heroes , t . joined_member_count , t . invited_member_count in let of_tuple v = let heroes , joined_member_count , i...
module Timeline = struct type t = { events : Events . Room_event . t list option ; limited : bool option ; prev_batch : string option ; } [ @@ deriving accessor ] let encoding = let to_tuple t = t . events , t . limited , t . prev_batch in let of_tuple v = let events , limited , prev_batch = v in { events ; limited ; p...
module Joined_room = struct module Unread_notifications = struct type t = { highlight_count : int option ; notification_count : int option } [ @@ deriving accessor ] let encoding = let to_tuple t = t . highlight_count , t . notification_count in let of_tuple v = let highlight_count , notification_count = v in { highlig...
module Invited_room = struct type t = { invite_state : Events . State_event . t list option } [ @@ deriving accessor ] let encoding = let to_tuple t = t . invite_state in let of_tuple v = let invite_state = v in { invite_state } in let with_tuple = obj1 ( opt " invite_state " ( obj1 ( req " events " ( list Events . Sta...
module Left_room = struct type t = { state : Events . State_event . t list option ; timeline : Timeline . t option ; account_data : Events . Room_event . t list option ; } [ @@ deriving accessor ] let encoding = let to_tuple t = t . state , t . timeline , t . account_data in let of_tuple v = let state , timeline , acco...
type t = { join : ( string * Joined_room . t ) list ; invite : ( string * Invited_room . t ) list ; leave : ( string * Left_room . t ) list ; }
let encoding = let to_tuple t = t . join , t . invite , t . leave in let of_tuple v = let join , invite , leave = v in { join ; invite ; leave } in let with_tuple = obj3 ( req " join " ( assoc Joined_room . encoding ) ) ( req " invite " ( assoc Invited_room . encoding ) ) ( req " leave " ( assoc Left_room . encoding ) ...
module Get = struct module Event = struct module Query = Empty . Query module Request = Empty . Json module Response = Events . Room_event end module State_key = struct module Query = Empty . Query module Request = Empty . Json module Response = struct type t = Ezjsonm . value let encoding = any end end module State = ...
module Put = struct module State_event = struct module Query = Empty . Query module Request = struct type t = { event : Events . Event_content . t } [ @@ deriving accessor ] let encoding = let to_tuple t = t . event in let of_tuple v = let event = v in { event } in let with_tuple = Events . Event_content . encoding in ...
module Get_visibility = struct module Query = Empty . Query module Response = struct type t = { visibility : Room . Visibility . t } [ @@ deriving accessor ] let encoding = let to_tuple t = t . visibility in let of_tuple v = let visibility = v in { visibility } in let with_tuple = obj1 ( req " visibility " Room . Visib...
module Set_visibility = struct module Query = Empty . Query module Request = struct type t = { visibility : Room . Visibility . t option } [ @@ deriving accessor ] let encoding = let to_tuple t = t . visibility in let of_tuple v = let visibility = v in { visibility } in let with_tuple = obj1 ( opt " visibility " Room ....
module Get_public_rooms = struct module Query = struct type t = { limit : int option ; since : string option ; server : string option } [ @@ deriving accessor ] let args t = let l = match t . limit with | None -> [ ] | Some limit -> [ " limit " , [ Int . to_string limit ] ] in let l = match t . since with None -> l | S...
module Filter_public_rooms = struct module Query = struct type t = { server : string option } [ @@ deriving accessor ] let args t = match t . server with None -> [ ] | Some server -> [ " server " , [ server ] ] end module Request = struct module Filter = struct type t = { generic_search_term : string option } [ @@ deri...
let contains_double_underscore s = let len = String . length s in let rec aux i = if i > len - 2 then false else if s . [ i ] = ' _ ' && s . [ i + 1 ] = ' _ ' then true else aux ( i + 1 ) in aux 0
module Package = struct type t = string module Table = Hashtbl . Make ( struct type nonrec t = t let equal : t -> t -> bool = ( = ) let hash : t -> int = Hashtbl . hash end ) end
module Odoc_file = struct type compilation_unit = { name : string ; hidden : bool } type t = Page of string | Compilation_unit of compilation_unit let create_unit ~ force_hidden name = let hidden = force_hidden || contains_double_underscore name in Compilation_unit { name ; hidden } let create_page name = Page name let...
type t = { id : Paths . Identifier . OdocId . t ; file : Odoc_file . t ; digest : Digest . t ; }
let equal : t -> t -> bool = ( = )
let hash : t -> int = Hashtbl . hash
let to_string t = let rec pp fmt ( id : Paths . Identifier . OdocId . t ) = match id with | ` LeafPage ( parent , name ) | ` Page ( parent , name ) -> ( match parent with | Some p -> Format . fprintf fmt " % a ::% a " pp ( p :> Paths . Identifier . OdocId . t ) Names . PageName . fmt name | None -> Format . fprintf fmt...
let compare x y = String . compare x . digest y . digest
module Hash_table = Hashtbl . Make ( struct type nonrec t = t let equal = equal let hash = hash end )
type t = { of_patterns : IntCollection . t Pattern . ObsMap . t ; of_unary_patterns : Mods . IntSet . t Mods . IntMap . t Pattern . ObsMap . t ; }
type mod_ccs_cache = ( int , unit ) Hashtbl . t
let empty env = { of_patterns = Pattern . Env . new_obs_map ( Model . domain env ) ( fun _ -> IntCollection . create 64 ) ; of_unary_patterns = Pattern . Env . new_obs_map ( Model . domain env ) ( fun _ -> Mods . IntMap . empty ) ; }
let incorporate_extra_pattern state pattern matchings = if IntCollection . is_empty ( Pattern . ObsMap . get state . of_patterns pattern ) then Pattern . ObsMap . set state . of_patterns pattern matchings
let add_intset_in_intmap id set map = if Mods . IntSet . is_empty set then Mods . IntMap . remove id map else Mods . IntMap . add id set map
let break_apart_cc state edges ? mod_connectivity_store = function | None -> ( ) | Some ( origin_cc , new_cc ) -> let ( ) = match mod_connectivity_store with | None -> ( ) | Some mod_conn -> let ( ) = Hashtbl . replace mod_conn new_cc ( ) in Hashtbl . replace mod_conn origin_cc ( ) in Pattern . ObsMap . iteri ( fun cc_...
let merge_cc state ? mod_connectivity_store = function | None -> ( ) | Some ( cc1 , cc2 ) -> let ( ) = match mod_connectivity_store with | None -> ( ) | Some mod_connectivity -> let ( ) = Hashtbl . replace mod_connectivity cc2 ( ) in Hashtbl . replace mod_connectivity cc1 ( ) in Pattern . ObsMap . iteri ( fun cc_id cc_...
let update_roots state is_add unary_ccs edges mod_connectivity pattern root = let va = Pattern . ObsMap . get state . of_patterns pattern in let ( ) = ( if is_add then IntCollection . add else IntCollection . remove ) root va in if Pattern . Set . mem pattern unary_ccs then let cc_map = Pattern . ObsMap . get state . o...
let number r pat = IntCollection . size ( Pattern . ObsMap . get r . of_patterns pat )
let print_injections ~ noCounters ? domain f roots_of_patterns = Format . fprintf f " [ @< v >% a ] " @ ( Pattern . ObsMap . print Pp . space ( fun pattern f roots -> if IntCollection . size roots > 0 then Format . fprintf f " [ @# [ @% a ] @ ==>@ [ @% a ] ] " @@ ( Pattern . print ~ noCounters ? domain ~ with_id : true...
let print_unary_injections ~ noCounters ? domain f roots_of_patterns = Format . fprintf f " [ @< hov >% a ] " @ ( Pattern . ObsMap . print Pp . space ( fun pattern f root_maps -> Format . fprintf f " [ @# [ @% a ] @ ==>@ [ @% a ] ] " @@ ( Pattern . print ~ noCounters ? domain ~ with_id : true ) pattern ( Pp . set Mods ...
let debug_print f state = let noCounters = true in let domain = None in let ( ) = print_injections ~ noCounters ? domain f state . of_patterns in print_unary_injections ~ noCounters ? domain f state . of_unary_patterns
let of_pattern pat_id state = try Pattern . ObsMap . get state . of_patterns pat_id with Not_found -> IntCollection . create 1
let of_unary_pattern pat_id state = try Pattern . ObsMap . get state . of_unary_patterns pat_id with Not_found -> Mods . IntMap . empty
let search_string_bnd text_w = let requester_w = Toplevel . create text_w [ ] in Wm . title_set requester_w " Search string " ; let from_index = ref ( TextIndex ( LineChar ( 1 , 1 ) , [ ] ) ) in let to_index = ref ( TextIndex ( End , [ ] ) ) in let entry0_w = Entry . create requester_w [ ] in let frame0_w = Frame . cre...
let create parent_w module_path module_source mode = let bookmarks = ref 0 in Wm . title_set parent_w ( Path . end_name module_path ) ; let frame0_w = Frame . create parent_w [ Relief Raised ; let frame1_w = Frame . create parent_w [ ] in let butt0_w = Button . create frame0_w [ Text " Close " ; let butt1_w = Button . ...
module Common = struct [ %% versioned module Stable = struct module V2 = struct type t = { scan_state : Staged_ledger . Scan_state . Stable . V2 . t ; pending_coinbase : Pending_coinbase . Stable . V2 . t } let to_latest = Fn . id let to_yojson { scan_state = _ ; pending_coinbase } = ` Assoc [ ( " scan_state " , ` Stri...
module Historical = struct [ %% versioned module Stable = struct module V3 = struct type t = { transition : External_transition . Validated . Stable . V3 . t ; common : Common . Stable . V2 . t ; staged_ledger_target_ledger_hash : Ledger_hash . Stable . V1 . t } let to_latest = Fn . id end end ] end let transition t = ...
module Limited = struct [ %% versioned module Stable = struct module V3 = struct type t = { transition : External_transition . Validated . Stable . V3 . t ; protocol_states : Mina_state . Protocol_state . Value . Stable . V2 . t Mina_base . State_hash . With_state_hashes . Stable . V1 . t list ; common : Common . Stabl...
module Minimal = struct [ %% versioned module Stable = struct [ @@@ no_toplevel_latest_type ] no_toplevel_latest_type module V2 = struct type t = { hash : State_hash . Stable . V1 . t ; common : Common . Stable . V2 . t } [ @@ driving to_yojson ] to_yojson let to_latest = Fn . id end end ] end type t = Stable . Latest ...
type t = { transition : External_transition . Validated . t ; staged_ledger : Staged_ledger . t ; protocol_states : Mina_state . Protocol_state . Value . t Mina_base . State_hash . With_state_hashes . t list }
let minimize { transition ; staged_ledger ; protocol_states = _ } = let scan_state = Staged_ledger . scan_state staged_ledger in let pending_coinbase = Staged_ledger . pending_coinbase_collection staged_ledger in let common = Common . create ~ scan_state ~ pending_coinbase in { Minimal . hash = Mina_block . Validated ....
let limit { transition ; staged_ledger ; protocol_states } = let scan_state = Staged_ledger . scan_state staged_ledger in let pending_coinbase = Staged_ledger . pending_coinbase_collection staged_ledger in let common = Common . create ~ scan_state ~ pending_coinbase in { Limited . transition ; common ; protocol_states ...
module Queue = Hash_queue . Make ( State_hash ) State_hash
module T = struct type t = { history : Root_data . Historical . t Queue . t ; capacity : int ; mutable current_root : Root_data . Historical . t ; mutable protocol_states_for_root_scan_state : Full_frontier . Protocol_states_for_root_scan_state . t } type view = t let create ~ logger : _ frontier = let capacity = 2 * F...
module Broadcasted = Functor . Make_broadcasted ( T ) T
let lookup { history ; _ } = Queue . lookup history
let mem { history ; _ } = Queue . mem history
let protocol_states_for_scan_state { history ; protocol_states_for_root_scan_state ; _ } state_hash = let open Option . Let_syntax in let open Root_data . Historical in let % bind data = Queue . lookup history state_hash in let required_state_hashes = Staged_ledger . Scan_state . required_state_hashes ( scan_state data...
let most_recent { history ; _ } = let open Option . Let_syntax in let % map state_hash , breadcrumb = Queue . dequeue_back_with_key history in assert ( [ % equal : [ ` Ok | ` Key_already_present ] ] ` Ok ( Queue . enqueue_back history state_hash breadcrumb ) breadcrumb ) ; breadcrumb
let oldest { history ; _ } = Queue . first history
let is_empty { history ; _ } = Queue . is_empty history
let to_list { history ; _ } = Queue . to_list history
let min i j = if ( i : int ) < j then i else j
let max i j = if ( i : int ) > j then i else j
type t = | Sub of string * int * int | Concat of int * int * t * int * t
let make_length = 1 lsl make_length_pow2
let extract_sub_length = small_rope_length / 2
let min_length , max_height = let d = ( 3 * Sys . word_size ) / 2 in let m = Array . make d max_int in let prev = ref 0 and last = ref 1 and i = ref 0 in try while ! i < d - 1 do let curr = ! last + ! prev in if curr < ! last then raise Exit ; m . ( ! i ) <- curr ; prev := ! last ; last := curr ; incr i done ; assert f...
let rebalancing_height = min ( max_height - 1 ) 60
let empty = Sub ( " " , 0 , 0 )
let length = function | Sub ( _ , _ , len ) -> len | Concat ( _ , len , _ , _ , _ ) -> len
let height = function | Sub ( _ , _ , _ ) -> 0 | Concat ( h , _ , _ , _ , _ ) -> h
let is_empty = function | Sub ( _ , _ , len ) -> len = 0 | _ -> false
let is_not_empty = function | Sub ( _ , _ , len ) -> len <> 0 | _ -> true
let print = let rec map_left = function | [ ] -> [ ] | [ x ] -> [ " " / ^ x ] | x :: tl -> ( " " ^ x ) :: map_left tl in let map_right = function | [ ] -> [ ] | x :: tl -> ( " " \\ ^ x ) :: List . map ( fun r -> " " ^ r ) tl in let rec leaves_list = function | Sub ( s , i0 , len ) -> [ String . sub s i0 len ] | Concat ...
let of_string s = Sub ( s , 0 , String . length s )
let rec unsafe_of_substring s i len = if len <= small_rope_length then Sub ( String . sub s i len , 0 , len ) else let len ' = len / 2 in let i ' = i + len ' in let left = unsafe_of_substring s i len ' and right = unsafe_of_substring s i ' ( len - len ' ) in let h = 1 + max ( height left ) ( height right ) in let ll = ...