text
stringlengths
0
601k
let a_2 ( x : field_var ) = a { Snarky . Types . Typ . store = ( fun x -> Snarky . Typ_monads . Store . return x ) ; Snarky . Types . Typ . read = ( fun x -> Snarky . Typ_monads . Read . return x ) ; Snarky . Types . Typ . alloc = ( let open Snarky . Typ_monads . Alloc in map alloc ~ f ( : fun _ -> failwith " cannot al...
module Impl = Snarky . Snark . Make ( Snarky . Backends . Mnt4 . Default )
module type P = sig include sig val x : int val f : bool -> bool end end
module P = struct include struct let x = 15 let f b = b end end
let f __implicit1__ = let typ x___1 = Typ . fn x___1 x___1 in Snarky . exists ( typ __implicit1__ ) ~ compute : ( let open As_prover in fun ( ) x -> x ) let g __implicit2__ x = ( let typ x___2 = Typ . fn x___2 x___2 in As_prover . read ( typ __implicit2__ ) ( f __implicit2__ ) ) x end
let h __implicit6__ __implicit5__ __implicit4__ x = let typ x___4 = x___4 in Snarky . exists ( typ __implicit6__ ) ~ compute : ( let open As_prover in fun ( ) -> g __implicit4__ ( let typ x___3 = x___3 in As_prover . read ( typ __implicit5__ ) x ) )
let i ( ) = let f __implicit7__ = let typ x___5 = Typ . fn x___5 x___5 in Snarky . exists ( typ __implicit7__ ) ~ compute : ( let open As_prover in fun ( ) x -> x ) in let i = let typ = Snarky . Typ . Internal . ref ( ) in Snarky . exists typ ~ compute : ( let open As_prover in fun ( ) -> ( let typ x___6 = Typ . fn x__...
type nonrec ( ' a , ' b ) either = Fst of ' a | Snd of ' b
let j __implicit12__ __implicit13__ __implicit14__ __implicit10__ b x = let f __implicit11__ = let typ x___10 = Typ . fn x___10 ( Snarky . Typ . Internal . ref ( ) ) in Snarky . exists ( typ __implicit11__ ) ~ compute : ( let open As_prover in fun ( ) x -> if let typ x___9 = x___9 in As_prover . read ( typ __implicit10...
let k ( f : field_var ) = j Typ . field Typ . field Typ . field { Snarky . Types . Typ . store = ( fun x -> Snarky . Typ_monads . Store . return x ) ; Snarky . Types . Typ . read = ( fun x -> Snarky . Typ_monads . Read . return x ) ; Snarky . Types . Typ . alloc = ( let open Snarky . Typ_monads . Alloc in map alloc ~ f...
let l ( b : boolean ) ( b ' : boolean ) = j Typ . boolean Typ . boolean Typ . boolean Typ . boolean b b '
type t = string let equal = ( ) = let hash = Hashtbl . hash end )
let inrange x low high = ( x >= low ) && ( x <= high )
let isupper c = inrange c ' A ' ' Z '
let islower c = inrange c ' a ' ' z '
let isnum c = inrange c ' 0 ' ' 9 '
let isalphanum c = isupper c || islower c || isnum c
let isvalstart c = islower c || isnum c
let isvalpart c = c = ' _ ' || isalphanum c
let isval string = String . length string > 0 && isvalstart ( string . [ 0 ] ) && let rec loop i = if i >= String . length string then true else if isvalpart ( string . [ i ] ) then loop ( i + 1 ) else false in loop 1
let print_value string = if isval string then print_string string else print_string ( Printf . sprintf " % S " string )
let print_term term = spreadterm print_string print_value term
let print_atom atom = let pred = getpred atom in let terms = getterms atom in match pred , terms with " " , = [ a ; b ] -> open_box 2 ; print_term a ; print_space ( ) ; print_string " = " ; print_term b ; close_box ( ) | _ -> print_string pred ; match terms with | term :: terms ->
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " ProvisionByoipCidr " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . ren...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " ProvisionByoipCidrResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp ProvisionByoipCidrResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed ProvisionByoipCidrResult . ...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
type ( ' a , ' v , ' role ) t = ( ' a , ' role ) Internal . proxy
type ( ' a , ' v , ' role ) proxy = ( ' a , ' v , ' role ) t
type ( ' v , ' role ) generic = Proxy : ( ' a , ' v , ' role ) t -> ( ' v , ' role ) generic
module type TRACE = sig type role val outbound : ( ' a , ' v , role ) t -> ( ' a , [ ` W ] ) Msg . t -> unit val inbound : ( ' a , ' v , role ) t -> ( ' a , [ ` R ] ) Msg . t -> unit end
let missing_dispatch _ = failwith " no handler registered " !
type ( _ , _ ) S . user_data += Missing_handler
let missing_handler metadata = object ( _ : _ handler ) method metadata = metadata method user_data = Missing_handler method dispatch = missing_dispatch end
let make_proxy ~ conn ~ version ~ handler id = { conn ; id ; version ; can_send = true ; can_recv = true ; handler = ( handler :> _ handler ) ; on_delete = Queue . create ( ) }
let accept_new t ~ version ~ handler id = let conn = t . conn in let is_service_allocated_id = ( Int32 . unsigned_compare id 0xFF000000l >= 0 ) in begin match conn . role with | ` Client -> assert is_service_allocated_id | ` Server -> assert ( not is_service_allocated_id ) end ; if Objects . mem id conn . objects then ...
let complete_accept t handler = assert ( t . handler # user_data == Missing_handler ) ; t . handler <- handler
let cast_version t = ( t : ( ' a , _ , ' role ) t :> ( ' a , _ , ' role ) t )
let version t = t . version
let metadata t = t . handler # metadata
let can_send t = t . can_send
let transport_up t = t . conn . transport # up
let ty ( type a ) t = let ( module M : Metadata . S with type t = a ) = metadata t in M . T
let interface ( type a ) t = let ( module M : Metadata . S with type t = a ) = metadata t in M . interface
module Handler = struct class type [ ' a , ' v , ' role ] t = object method user_data : ( ' a , ' role ) S . user_data method metadata : ( module Metadata . S with type t = ' a ) method dispatch : ( ' a , ' v , ' role ) proxy -> ( ' a , [ ` R ] ) Msg . t -> unit end let interface ( type a ) ( t : ( _ , _ , _ ) # t ) = ...
module Service_handler = struct class type [ ' a , ' v , ' role ] t = object inherit [ ' a , ' v , ' role ] Handler . t method min_version : int32 method max_version : int32 end let interface t = Handler . interface t let min_version t = t # min_version let cast_version t = ( t :> _ t ) let accept_new ( type a ) proxy ...
let id t = if t . can_send then t . id else Fmt . invalid_arg " Attempt to use % a after destroying it " pp t
let id_opt = function | None -> 0l | Some t -> id t
let alloc t = Msg . alloc ~ obj : t . id
let send ( type a ) ( t : _ t ) ( msg : ( a , [ ` W ] ) Msg . t ) = t . conn . trace . outbound t msg ; if t . can_send then enqueue t . conn ( Msg . cast msg ) else Fmt . failwith " Attempt to use object % a after calling destructor " ! pp t
let spawn_generic t ~ version ( handler : ( _ , _ , _ ) # Handler . t ) = let conn = t . conn in let id = get_unused_id conn in let t ' = make_proxy id ~ version ~ conn : t . conn ~ handler ( : handler :> _ handler ) in conn . objects <- Objects . add id ( Generic t ' ) conn . objects ; t '
let spawn t ( handler : ( _ , _ , _ ) # Handler . t ) = spawn_generic t ~ version : t . version handler
let spawn_bind ( t : ( _ , _ , ' role ) t ) ( ( handler : ( ' a , ' v , ' role ) # Service_handler . t ) , version ) : ( ' a , ' v , ' role ) t = let min_version = handler # min_version in let max_version = handler # max_version in if version < min_version then Fmt . failwith " Can ' t ask for % s version % ld when han...
let user_data ( t : _ t ) = t . handler # user_data
let shutdown_send t = if t . can_send then t . can_send <- false else Fmt . failwith " % a already shut down " ! pp t
let shutdown_recv t = if t . can_recv then t . can_recv <- false else Fmt . failwith " % a already shut down " ! pp t
let add_root conn ( handler : ( _ , _ , _ ) # Handler . t ) = let display_proxy = make_proxy 1l ~ version : 1l ~ conn ~ handler in conn . objects <- Objects . add display_proxy . id ( Generic display_proxy ) conn . objects ; display_proxy
let on_delete t fn = Queue . add fn t . on_delete
let delete t = let conn = t . conn in match Objects . find_opt t . id conn . objects with | Some ( Generic t ' ) when Obj . repr t == Obj . repr t ' -> t . can_recv <- false ; t . can_send <- false ; conn . objects <- Objects . remove t . id conn . objects ; Internal . free_id conn t . id ; begin match conn . role with...
let delete_other proxy id = let conn = proxy . conn in match Objects . find_opt id conn . objects with | None -> Fmt . failwith " Object % ld does not exist " ! id | Some ( Generic proxy ) -> proxy . can_recv <- false ; conn . objects <- Objects . remove id conn . objects ; Internal . free_id conn id ; Queue . iter ( f...
let unknown_event = Fmt . str " < unknown event % d " >
let unknown_request = Fmt . str " < unknown request % d " >
let lookup_other ( t : _ t ) id = match Objects . find_opt id t . conn . objects with | None -> Fmt . failwith " Proxy with ID % ld not found " ! id | Some ( Generic p ) -> if p . can_recv then Proxy p else Fmt . failwith " Message referred to object % a , which cannot receive further messages " pp p
let wrong_type ~ parent ~ expected t = Fmt . failwith " Object % a referenced object % a , which should be of type % S but isn ' t ' " pp parent pp t expected
let trace ( type r ) ( module T : TRACE with type role = r ) = { inbound = T . inbound ; outbound = T . outbound ; }
let pp_transport f t = t . conn . transport # pp f
module M = struct type key = Local . key type value = Local . value type tree = Local . tree module type ProxyDelegate = sig val proxy_dir_mem : key -> bool tzresult Lwt . t val proxy_get : key -> tree option tzresult Lwt . t val proxy_mem : key -> bool tzresult Lwt . t end type proxy_delegate = ( module ProxyDelegate ...
module C = struct type key = M . key type value = M . value type t = M . t type tree = { proxy : M . proxy_delegate option ; path : key ; tree : Local . tree } let pp_key ppf key = Format . pp_print_list ~ pp_sep ( : fun ppf _ -> Format . fprintf ppf " ; " ) Format . pp_print_string ppf key module L = struct module S =...
let empty proxy = let ctxt = M . { proxy ; local = Local . empty } in Context . make ~ ops ~ ctxt ~ kind : Context ~ equality_witness ~ impl_name : proxy_impl_name
type kind = Get | Mem
let kind_encoding : kind Data_encoding . t = let open Data_encoding in conv ( function Get -> true | Mem -> false ) ( function true -> Get | false -> Mem ) bool
let pp_kind fmt kind = Format . fprintf fmt " % s " ( match kind with Get -> " get " | Mem -> " mem " )
module Events = struct include Internal_event . Simple let section = [ " proxy_getter " ] let pp_key = let pp_sep fmt ( ) = Format . fprintf fmt " " / in Format . pp_print_list ~ pp_sep Format . pp_print_string let cache_hit = declare_2 ~ section ~ name " : cache_hit " ~ msg " : Cache hit ( { kind } ) : ( { key } ) " ~...
let rec raw_context_size = function | Tezos_shell_services . Block_services . Key _ | Cut -> 0 | Dir map -> TzString . Map . fold ( fun _key v acc -> acc + 1 + raw_context_size v ) map 0
let rec raw_context_to_tree ( raw : Tezos_shell_services . Block_services . raw_context ) : Local . tree option Lwt . t = match raw with | Key ( bytes : Bytes . t ) -> Lwt . return ( Some ( Local . Tree . of_raw ( ` Value bytes ) ) ) | Cut -> Lwt . return None | Dir map -> let open Lwt_syntax in let add_to_tree tree ( ...
module type M = sig val proxy_dir_mem : Proxy . proxy_getter_input -> Local . key -> bool tzresult Lwt . t val proxy_get : Proxy . proxy_getter_input -> Local . key -> Local . tree option tzresult Lwt . t val proxy_mem : Proxy . proxy_getter_input -> Local . key -> bool tzresult Lwt . t end
type proxy_m = ( module M )
module Tree : Proxy . TREE with type t = Local . tree with type key = Local . key = struct type t = Local . tree type key = Local . key let empty = Local . Tree . empty Local . empty let get = Local . Tree . find_tree let add_leaf tree key raw_context : t Proxy . update Lwt . t = let open Lwt_syntax in let * tree_opt =...
module type REQUESTS_TREE = sig type tree = Partial of tree StringMap . t | All val empty : tree val add : tree -> string list -> tree val find_opt : tree -> string list -> tree option end
module RequestsTree : REQUESTS_TREE = struct type tree = Partial of tree StringMap . t | All let empty = Partial StringMap . empty let rec add ( t : tree ) ( k : string list ) : tree = match ( t , k ) with | ( _ , [ ] ) | ( All , _ ) -> All | ( Partial map , k_hd :: k_tail ) -> ( let sub_t_opt = StringMap . find_opt k_...
module Core ( T : Proxy . TREE with type key = Local . key and type t = Local . tree ) ( X : Proxy_proto . PROTO_RPC ) : Proxy . CORE = struct let store = ref None let lazy_load_store ( ) = match ! store with | None -> let e = T . empty in store := Some e ; Lwt . return e | Some e -> Lwt . return e let get key = let op...
module Make ( C : Proxy . CORE ) ( X : Proxy_proto . PROTO_RPC ) : M = struct let requests = ref RequestsTree . empty let is_all k = match RequestsTree . find_opt ! requests k with Some All -> true | _ -> false let do_rpc ( pgi : Proxy . proxy_getter_input ) ( kind : kind ) ( requested_key : Local . key ) : unit tzresu...
module MakeProxy ( X : Proxy_proto . PROTO_RPC ) : M = Make ( Core ( Tree ) ( X ) ) ( X )
module Internal = struct module Tree = Tree let raw_context_to_tree = raw_context_to_tree end
module type PROTO_RPC = sig val split_key : Proxy . mode -> Proxy_context . M . key -> ( Proxy_context . M . key * Proxy_context . M . key ) option val failure_is_permanent : Proxy_context . M . key -> bool val do_rpc : Proxy . proxy_getter_input -> Proxy_context . M . key -> Tezos_shell_services . Block_services . raw...
type proto_rpc = ( module PROTO_RPC )
type argument = | Symbolic_block_caching_time of int
module Parameters = struct type persistent_state = { arguments : string list ; mutable pending_ready : unit option Lwt . u list ; rpc_port : int ; runner : Runner . t option ; } type session_state = { mutable ready : bool } let base_default_name = " proxy_server " let default_colors = Log . Color . [ | FG . gray ; BG ....
let trigger_ready t value = let pending = t . persistent_state . pending_ready in t . persistent_state . pending_ready <- [ ] ; List . iter ( fun pending -> Lwt . wakeup_later pending value ) pending
let set_ready t = ( match t . status with | Not_running -> ( ) | Running status -> status . session_state . ready <- true ) ; trigger_ready t ( Some ( ) )
let handle_event t ( { name ; _ } : event ) = match name with " starting_proxy_rpc_server . v0 " -> set_ready t | _ -> ( )
let create ? runner ? name ? rpc_port ( ? args = [ ] ) node = let path = Constant . tezos_proxy_server in let rpc_port = match rpc_port with None -> Port . fresh ( ) | Some port -> port in let user_arguments = List . map ( function | Symbolic_block_caching_time s -> [ " -- sym - block - caching - time " ; Int . to_stri...
let rpc_port ( { persistent_state ; _ } : t ) = persistent_state . rpc_port
let runner node = node . persistent_state . runner
let run ( ? on_terminate = fun _ -> ( ) ) ? event_level ? event_sections_levels endpoint arguments = let arguments = endpoint . persistent_state . arguments @ arguments in let on_terminate status = on_terminate status ; unit in run ? event_level ? event_sections_levels endpoint { ready = false } arguments ~ on_terminat...
let check_event ? where node name promise = let * result = promise in match result with | None -> raise ( Terminated_before_event { daemon = node . name ; event = name ; where } ) | Some x -> return x
let wait_for_ready t = match t . status with | Running { session_state = { ready = true } ; _ } -> unit | Not_running | Running { session_state = { ready = false } ; _ } -> let ( promise , resolver ) = Lwt . task ( ) in t . persistent_state . pending_ready <- resolver :: t . persistent_state . pending_ready ; check_eve...
let init ? runner ? name ? rpc_port ? event_level ? event_sections_levels ? args node = let * endpoint = create ? runner ? name ? rpc_port ? args node in let * ( ) = run ? event_level ? event_sections_levels endpoint [ ] in let * ( ) = wait_for_ready endpoint in return endpoint
type t = { endpoint : Uri . t option ; rpc_addr : Uri . t option ; rpc_tls : string option ; sym_block_caching_time : int option ; }
let pp ppf { endpoint ; rpc_addr ; rpc_tls ; sym_block_caching_time } = let pp_uri_opt = Format . pp_print_option Uri . pp in Format . fprintf ppf " [ @< v > endpoint =% a , @ rpc_addr =% a , @ rpc_tls =% a , @ sym_block_caching_time =% a ] " @ pp_uri_opt endpoint pp_uri_opt rpc_addr ( Format . pp_print_option Format ....
let example_config = { { " | endpoint " : " http :// 127 . 0 . 0 . 1 : 18731 " , " rpc_addr " : " http :// 127 . 0 . 0 . 1 : 18732 " , " sym_block_caching_time " : 60 } } |