text
stringlengths
0
601k
let axiom f x = let axiom f _ = pp f " [ @ axiom . . . ] " @ in spec axiom f x
let rec s_signature_item f x = let s_val_description f vd = let intro = if vd . vprim = [ ] then " val " else " external " in pp f " [ @< 2 >% s @ % a @ :@ % a ] @% a @\ n % a " intro protect_ident vd . vname . txt value_description vd ( item_attributes reset_ctxt ) vd . vattributes val_spec vd . vspec in let print_ope...
module Blake2 = Blake2 . Make ( )
type block_data = { block : string ; created_at : string ; peer_id : string ; snark_work : string option [ @ default None ] None }
module Proof_data = struct type t = { proof : Ledger_proof . Stable . Latest . t ; proof_time : Core_kernel . Time . Span . t ; snark_work_fee : Currency . Fee . Stable . Latest . t } [ @@ deriving bin_io_unversioned ] bin_io_unversioned end
let sign_blake2_hash ~ private_key s = let module Field = Snark_params . Tick . Field in let blake2 = Blake2 . digest_string s in let field_elements = [ ] || in let bitstrings = [ | Blake2 . to_raw_string blake2 |> Blake2 . string_to_bits |> Array . to_list ] | in let input : ( Field . t , bool ) bool Random_oracle . L...
let send_uptime_data ~ logger ~ interruptor ( ~ submitter_keypair : Keypair . t ) t ~ url ~ state_hash ~ produced block_data = let open Interruptible . Let_syntax in let make_interruptible f = Interruptible . lift f interruptor in let block_data_json = block_data_to_yojson block_data in let block_data_string = Yojson ....
let block_base64_of_breadcrumb breadcrumb = let external_transition = breadcrumb |> Transition_frontier . Breadcrumb . block |> External_transition . compose in let block_string = Binable . to_string ( module External_transition . Raw . Stable . Latest ) Latest external_transition in Base64 . encode_exn block_string
let send_produced_block_at ~ logger ~ interruptor ~ url ~ peer_id ( ~ submitter_keypair : Keypair . t ) t ~ block_produced_bvar tm = let open Interruptible . Let_syntax in let make_interruptible f = Interruptible . lift f interruptor in let timeout_min = 3 . 0 in let % bind ( ) = make_interruptible ( at tm ) tm in matc...
let send_block_and_transaction_snark ~ logger ~ interruptor ~ url ~ snark_worker ~ transition_frontier ~ peer_id ( ~ submitter_keypair : Keypair . t ) t ~ snark_work_fee = match Broadcast_pipe . Reader . peek transition_frontier with | None -> [ % log info ] info " Transition frontier not available to send a block to u...
let start ~ logger ~ uptime_url ~ snark_worker_opt ~ transition_frontier ~ time_controller ~ block_produced_bvar ~ uptime_submitter_keypair ~ get_next_producer_timing ~ get_snark_work_fee ~ get_peer = match uptime_url with | None -> [ % log info ] info " Not running uptime service , no URL given " ; ( ) | Some url -> [...
module Worker_state = struct module type S = sig val perform_single : Sok_message . t * Prod . single_spec -> ( Ledger_proof . t * Time . Span . t ) t Deferred . Or_error . t end type init_arg = Logger . Stable . Latest . t [ @@ deriving bin_io_unversioned ] bin_io_unversioned type t = ( module S ) S let create ~ logge...
module Worker = struct module T = struct module F = Rpc_parallel . Function type ' w functions = { perform_single : ( ' w , Sok_message . t * Prod . single_spec , ( Ledger_proof . t * Time . Span . t ) t Or_error . t ) F . t } module Worker_state = Worker_state module Connection_state = struct type init_arg = unit [ @@...
type t = { connection : Worker . Connection . t ; process : Process . t ; logger : Logger . Stable . Latest . t }
let create ~ logger ~ pids : t Deferred . t = let on_failure err = [ % log error ] error " Uptime service SNARK worker process failed with error $ err " ~ metadata [ : ( " err " , Error_json . error_to_yojson err ) err ] ; Error . raise err in [ % log info ] info " Starting a new uptime service SNARK worker process " ;...
let perform_single { connection ; _ } ( ( _message , _single_spec ) _single_spec as arg ) arg = Worker . Connection . run connection ~ f : Worker . functions . perform_single ~ arg
let root_dir = ref Sundials . RootDirs . Increasing
let args = [ ( " - e " , Arg . Unit ( fun ( ) -> root_dir := Sundials . RootDirs . IncreasingOrDecreasing ) , " Use either instead of up ( ) " ) ; ]
let _ = Arg . parse args ( fun _ -> ( ) ) " upvseither : test different types of root detection "
let print_with_time t v = Printf . printf " % e " t ; Sundials . RealArray . iter ( Printf . printf " \ t % e " ) v ; print_newline ( )
let f t_s y yd = yd . { x } <- - 1 . 0 ; Printf . printf " f ( % e , [ % e ] ) = [ % e ] \ n " t_s y . { x } yd . { x }
let g t_s y gout = gout . { 0 } <- y . { x } ; Printf . printf " g ( % e , [ % e ] ) = [ % e ] \ n " t_s y . { x } gout . { 0 }
let y = Sundials . RealArray . of_array [ | x_i ] |
let s = Cvode . ( init Adams default_tolerances f ~ roots ( : 1 , g ) 0 . y_nvec )
let rootdata = Sundials . Roots . create 1
let _ = Cvode . set_all_root_directions s ! root_dir
let _ = Cvode . set_stop_time s max_sim_t
let _ = Cvode . set_max_step s 5 . 0
let _ = Printf . printf " time \ t \ t t \ n " ; Printf . printf " ------------------------------------\ n " ; print_with_time 0 . 0 y ; try let i = ref 0 in while true do let ( t ' , result ) = Cvode . solve_one_step s max_sim_t y_nvec in Printf . printf " \ nstep % 3d . \ n " ! i ; incr i ; print_with_time t ' y ; Pr...
let get_file_size fd = Unix . handle_unix_error Unix . fstat fd |> fun { Unix . st_size ; _ } -> st_size
type t = { freelist : int Queue . t ; mutable insize : int ; mutable offset : Int63 . t ; mutable reads : int ; mutable writes : int ; mutable write_left : int ; mutable read_left : int ; block_size : int ; infd : Unix . file_descr ; outfd : Unix . file_descr ; }
let pp ppf { insize ; offset ; reads ; writes ; write_left ; read_left ; _ } = Fmt . pf ppf " insize % d offset % a reads % d writes % d rleft % d wleft % d " insize Int63 . pp offset reads writes read_left write_left
type req = { op : [ ` R | ` W ] ; fixed_off : int ; mutable len : int ; fileoff : Int63 . t ; mutable off : int ; t : t ; }
let pp_req ppf { op ; len ; off ; fixed_off ; fileoff ; t ; _ } = Fmt . pf ppf " [ % s fileoff % a len % d off % d fixedoff % d ] [ % a ] " ( match op with ` | R -> " r " ` | W -> " w " ) Int63 . pp fileoff len off fixed_off pp t
let queue_read uring t len = let fixed_off = Queue . pop t . freelist in let req = { op ` = R ; fixed_off ; fileoff = t . offset ; len ; off = 0 ; t } in Logs . debug ( fun l -> l " queue_read : % a " pp_req req ) ; let r = Uring . read_fixed uring ~ file_offset : t . offset t . infd ~ off : fixed_off ~ len req in asse...
let handle_read_completion uring req res = Logs . debug ( fun l -> l " read_completion : res =% d % a " res pp_req req ) ; let bytes_to_read = req . len - req . off in match res with | 0 -> Logs . debug ( fun l -> l " eof % a " pp_req req ) ; | n when n = eagain || n = eintr -> let r = Uring . read_fixed ~ file_offset ...
let handle_write_completion uring req res = Logs . debug ( fun l -> l " write_completion : res =% d % a " res pp_req req ) ; let bytes_to_write = req . len - req . off in match res with | 0 -> raise End_of_file | n when n = eagain || n = eintr -> let r = Uring . write_fixed ~ file_offset : req . fileoff uring req . t ....
let handle_completion uring req res = match req . op with ` | R -> handle_read_completion uring req res ` | W -> handle_write_completion uring req res
let copy_file uring t = while t . write_left > 0 || t . read_left > 0 do let rec submit_reads ( ) = if t . read_left > 0 then begin if t . reads + t . writes < ( Uring . queue_depth uring ) then begin let size = min t . block_size t . read_left in queue_read uring t size ; submit_reads ( ) end end ; in submit_reads ( )...
let run_cp block_size queue_depth infile outfile ( ) = let infd = Unix . ( handle_unix_error ( openfile infile [ O_RDONLY ] ) 0 ) in let outfd = Unix . ( handle_unix_error ( openfile outfile [ O_WRONLY ; O_CREAT ; O_TRUNC ] ) 0o644 ) in let insize = get_file_size infd in let freelist = Queue . create ( ) in for i = 0 t...
let get_file_size fd = Unix . handle_unix_error Unix . fstat fd |> fun { Unix . st_size ; _ } -> st_size
type t = { mutable insize : int ; mutable offset : Int63 . t ; mutable reads : int ; mutable writes : int ; mutable write_left : int ; mutable read_left : int ; block_size : int ; infd : Unix . file_descr ; outfd : Unix . file_descr ; }
let pp ppf { insize ; offset ; reads ; writes ; write_left ; read_left ; _ } = Fmt . pf ppf " insize % d offset % a reads % d writes % d rleft % d wleft % d " insize Int63 . pp offset reads writes read_left write_left
type iovec = { all : Cstruct . t list ; mutable next : Cstruct . t list ; }
type req = { op : [ ` R | ` W ] ; iov : iovec ; len : int ; fileoff : Int63 . t ; mutable off : int ; t : t ; }
let pp_req ppf { op ; len ; off ; fileoff ; t ; _ } = Fmt . pf ppf " [ % s fileoff % a len % d off % d ] [ % a ] " ( match op with ` | R -> " r " ` | W -> " w " ) Int63 . pp fileoff len off pp t
let queue_read uring t len = let all = [ Cstruct . create len ] in let iov = { all ; next = all } in let req = { op ` = R ; iov ; fileoff = t . offset ; len ; off = 0 ; t } in Logs . debug ( fun l -> l " queue_read : % a " pp_req req ) ; let r = Uring . readv uring ~ file_offset : t . offset t . infd iov . next req in ...
let handle_read_completion uring req res = Logs . debug ( fun l -> l " read_completion : res =% d % a " res pp_req req ) ; let bytes_to_read = req . len - req . off in match res with | 0 -> Logs . debug ( fun l -> l " eof % a " pp_req req ) ; | n when n = eagain || n = eintr -> let r = Uring . readv ~ file_offset : req...
let handle_write_completion uring req res = Logs . debug ( fun l -> l " write_completion : res =% d % a " res pp_req req ) ; let bytes_to_write = req . len - req . off in match res with | 0 -> raise End_of_file | n when n = eagain || n = eintr -> let r = Uring . writev ~ file_offset : req . fileoff uring req . t . infd...
let handle_completion uring req res = match req . op with ` | R -> handle_read_completion uring req res ` | W -> handle_write_completion uring req res
let copy_file uring t = while t . write_left > 0 || t . read_left > 0 do let rec submit_reads ( ) = if t . read_left > 0 then begin if t . reads + t . writes < ( Uring . queue_depth uring ) then begin let size = min t . block_size t . read_left in queue_read uring t size ; submit_reads ( ) end end ; in submit_reads ( )...
let run_cp block_size queue_depth infile outfile ( ) = let infd = Unix . ( handle_unix_error ( openfile infile [ O_RDONLY ] ) 0 ) in let outfd = Unix . ( handle_unix_error ( openfile outfile [ O_WRONLY ; O_CREAT ; O_TRUNC ] ) 0o644 ) in let insize = get_file_size infd in let t = { block_size ; insize ; offset = Int63 ....
type regexp = [ ` Alt of regexp * regexp | ` Seq of regexp * regexp | ` Rep of regexp | ` Repn of regexp * int * int option | ` After of regexp | ` Before of regexp | ` Epsilon | ` Group of regexp | ` OneChar | ` String of UChar . t list | ` Set of USet . t | ` BoS | ` EoS ]
type match_semantics = [ ` First | ` Shortest | ` Longest ]
let rec no_group = function ` Alt ( r1 , r2 ) r2 -> ` Alt ( no_group r1 , no_group r2 ) r2 | ` Seq ( r1 , r2 ) r2 -> ` Alt ( no_group r1 , no_group r2 ) r2 | ` Rep r -> ` Rep ( no_group r ) r | ` Group r -> r | r -> r
module type Type = sig type text type index type compiled_regexp module SubText : SubText . Type with type ur_text = text and type ur_index = index val compile : regexp -> compiled_regexp val regexp_match : ? sem : match_semantics -> compiled_regexp -> text -> index -> SubText . t option array option val string_match :...
module Make ( Text : UnicodeString . Type ) Type = struct type text = Text . t type index = Text . index module SubText = SubText . Make ( Text ) Text type instr = String of UChar . t list | OneChar | Set of USet . t | Par of instr * instr | Seq of instr * instr | Rep of instr | Repn of instr * int * int option | Epsil...
module type Interface = sig type regexp = URe . regexp val regexp : string -> regexp val quote : string -> string val regexp_string : string -> regexp module type Type = sig type text type index type compiled_regexp module SubText : SubText . Type with type ur_text = text and type ur_index = index val compile : regexp ...
module Configure ( Config : ConfigInt . Type ) Type = struct type regexp = URe . regexp module Unidata = Unidata . Make ( MakeConfig ) MakeConfig module UCharInfo = UCharInfo . Make ( MakeConfig ) MakeConfig module type Type = URe . Type let property_to_set name = if name = " Any " then USet . compl ( USet . empty ) em...
module URegexp = UReStr . Make ( UTF8 ) UTF8
let regexp_match_str r t i = let n = let p = Str . regexp_string ( " " \\ in let rec count i c = match try Some ( Str . search_forward p r i ) i with Not_found -> None with Some i -> count ( i + 1 ) 1 ( c + 1 ) 1 | None -> c in count i 0 in let g = Array . make ( n + 1 ) 1 None in if Str . string_match ( Str . regexp r...
let string_of_sub s = let s0 = URegexp . SubText . excerpt s in let _ , i , _ = URegexp . SubText . context s in sprintf ( " % d , " \% s ) " " \ i s0
let string_of_subs g = let b = Buffer . create 0 in Buffer . add_string b [ " " ; | for i = 0 to Array . length g - 1 do Buffer . add_string b ( match g ( . i ) i with Some s -> string_of_sub s | None -> " ) " ; Buffer . add_string b " ; " done ; Buffer . add_string b ] " " ; | Buffer . contents b
let printer = function Some g -> string_of_subs g | None -> " No match "
let eq_match ( ? pos = 0 ) 0 r t = let r ' = UReStr . regexp r in expect_equal_app ~ msg ( : lazy t ) t ~ printer ( fun ( ) -> regexp_match_str r t pos ) pos ( ) ( fun ( ) -> URegexp . regexp_match ( URegexp . compile r ' ) r ' t pos ) pos ( )
let eq_matched_string ( ? pos = 0 ) 0 ( ? sem ` = Longest ) Longest r t t0 = let r = UReStr . regexp r in let g = URegexp . regexp_match ~ sem ( URegexp . compile r ) r t pos in match g with None -> fail ( " No match : " ^ t ) t | Some g -> match g ( . 0 ) 0 with None -> assert false | Some s -> let t = URegexp . SubTe...
let expect_pass desc body = test ~ desc ~ body ( : fun ( ) -> expect_pass ~ body ) body
let expect_match r t = let r = UReStr . regexp r in let r = URegexp . compile r in expect_true ~ msg ( : lazy t ) t ( URegexp . string_match r t 0 ) 0
let expect_not_match r t = let r = UReStr . regexp r in let r = URegexp . compile r in expect_true ~ msg ( : lazy t ) t ( not ( URegexp . string_match r t 0 ) 0 ) 0
let _ = expect_pass " literal " ( fun ( ) -> eq_match " a " " a " ; eq_match " a " " b " ; ) ; expect_pass " alt " ( fun ( ) -> eq_match " a \\| b " " a " ; eq_match " a \\| b " " b " ; eq_match " a \\| b " " c " ; ) ; expect_pass " seq " ( fun ( ) -> eq_match " ab " " ab " ; eq_match " ab " " ac " ; ) ; expect_pass " ...
type component = [ | ` Scheme | ` Authority | ` Userinfo | ` Host | ` Path | ` Query | ` Query_key | ` Query_value | ` Fragment | ` Generic | ` Custom of ( component * string * string ) ]
type pct_encoder = { scheme : component ; userinfo : component ; host : component ; path : component ; query_key : component ; query_value : component ; fragment : component ; }
let rec iter_concat fn sep buf = function | last [ ] :: -> fn buf last | el :: rest -> fn buf el ; Buffer . add_string buf sep ; iter_concat fn sep buf rest | [ ] -> ( )
let rev_interject e lst = let rec aux acc = function | [ ] -> acc | x :: xs -> aux ( x :: e :: acc ) xs in match lst with | [ ] -> [ ] | h :: t -> aux [ h ] t
let compare_opt c t t ' = match t , t ' with | None , None -> 0 | Some _ , None -> 1 | None , Some _ -> - 1 | Some a , Some b -> c a b
let rec compare_list f t t ' = match t , t ' with | [ ] , [ ] -> 0 | _ :: _ , [ ] -> 1 | [ ] , _ :: _ -> - 1 | x :: xs , y :: ys -> match f x y with 0 -> compare_list f xs ys | c -> c
type safe_chars = bool array
module type Scheme = sig val safe_chars_for_component : component -> safe_chars val normalize_host : string option -> string option val canonicalize_port : int option -> int option val canonicalize_path : string list -> string list end
module Generic : Scheme = struct let sub_delims a = let subd = " ' ( ) , ; " !$&*+= in for i = 0 to String . length subd - 1 do let c = Char . code subd . [ i ] in a . ( c ) <- true done ; a let safe_chars : safe_chars = let a = Array . make 256 false in let always_safe = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs...
module Http : Scheme = struct include Generic let normalize_host = function | Some hs -> Some ( String . lowercase_ascii hs ) | None -> None let canonicalize_port = function | None -> None | Some 80 -> None | Some x -> Some x let canonicalize_path = function | [ ] -> [ " " ] / | x -> x end
module Https : Scheme = struct include Http let canonicalize_port = function | None -> None | Some 443 -> None | Some x -> Some x end
module File : Scheme = struct include Generic let normalize_host = function | Some hs -> let hs = String . lowercase_ascii hs in if hs " = localhost " then Some " " else Some hs | None -> None end
module Urn : Scheme = struct include Generic end
let module_of_scheme = function | Some s -> begin match String . lowercase_ascii s with | " http " -> ( module Http : Scheme ) | " https " -> ( module Https : Scheme ) | " file " -> ( module File : Scheme ) | " urn " -> ( module Urn : Scheme ) | _ -> ( module Generic : Scheme ) end | None -> ( module Generic : Scheme )
module Pct : sig type encoded type decoded val encode : ? scheme : string -> ? component : component -> decoded -> encoded val decode : encoded -> decoded val empty_decoded : decoded val cast_encoded : string -> encoded val cast_decoded : string -> decoded val uncast_encoded : encoded -> string val uncast_decoded : dec...
let pct_encode ? scheme ( ? component ` = Path ) s = Pct . ( uncast_encoded ( encode ? scheme ~ component ( cast_decoded s ) ) )
let pct_encoder ( ? scheme ` = Scheme ) ( ? userinfo ` = Userinfo ) ( ? host ` = Host ) ( ? path ` = Path ) ( ? query_key ` = Query_key ) ( ? query_value ` = Query_value ) ( ? fragment ` = Fragment ) ( ) = { scheme ; userinfo ; host ; path ; query_key ; query_value ; fragment }
let pct_decode s = Pct . ( uncast_decoded ( decode ( cast_encoded s ) ) )
module Userinfo = struct type t = string * string option let compare ( u , p ) ( u ' , p ' ) = match String . compare u u ' with | 0 -> compare_opt String . compare p p ' | c -> c let userinfo_of_encoded us = match Stringext . split ~ max : 2 ~ on ' ' :: us with | [ ] -> ( " " , None ) | [ u ] -> ( pct_decode u , None ...
let encoded_of_userinfo ? scheme ~ component = Userinfo . encoded_of_userinfo ? scheme ~ component
module Path = struct type t = string list let compare = compare_list String . compare let path_of_encoded ps = let tokl = Stringext . full_split ps ~ on ' ' :/ in List . map pct_decode tokl let remove_dot_segments p = let revp = List . rev p in let rec loop ascension outp = function | " " " . . " /:::: r | " . . " :: r...
let encoded_of_path ? scheme ~ component = Path . encoded_of_path ? scheme ~ component
module Query = struct type kv = ( string * string list ) list type t = | KV of kv | Raw of string option * kv Lazy . t let compare x y = match x , y with | KV kvl , KV kvl ' | Raw ( _ , lazy kvl ) , KV kvl ' | KV kvl , Raw ( _ , lazy kvl ' ) -> compare_list ( fun ( k , vl ) ( k ' , vl ' ) -> match String . compare k k ...
let encoded_of_query ? scheme = Query . encoded_of_query ? scheme
type t = { scheme : Pct . decoded option ; userinfo : Userinfo . t option ; host : Pct . decoded option ; port : int option ; path : Path . t ; query : Query . t ; fragment : Pct . decoded option ; }
let empty = { scheme = None ; userinfo = None ; host = None ; port = None ; path = [ ] ; query = Query . Raw ( None , Lazy . from_val [ ] ) ; fragment = None ; }
let compare_decoded = Pct . unlift_decoded2 String . compare
let compare_decoded_opt = compare_opt compare_decoded
let compare t t ' = ( match compare_decoded_opt t . host t ' . host with | 0 -> ( match compare_decoded_opt t . scheme t ' . scheme with | 0 -> ( match compare_opt ( fun p p ' -> if p < p ' then - 1 else if p > p ' then 1 else 0 ) t . port t ' . port with | 0 -> ( match compare_opt Userinfo . compare t . userinfo t ' ....
let equal t t ' = compare t t ' = 0