text
stringlengths
12
786k
let await_timeout cb = if is_expired cb then Deferred . return ( ) else match cb . expiration with | None -> Deferred . never ( ) | Some expires_at -> after ( Time_ns . Span . to_span_float_round_nearest @@ Time_ns . diff expires_at ( Time_ns . now ( ) ) )
let await cb = if is_expired cb then ( record_timeout_metrics cb ; Deferred . return None ) None else match cb . expiration with | None -> Ivar . read cb . signal >>| Option . some | Some expires_at -> ( match % map Timeout . await ( ) ~ timeout_duration ( : Time_ns . diff expires_at ( ...
let await_exn cb = match % map await cb with None -> failwith " timeout " | Some result -> result
let fire_if_not_already_fired cb result = if not ( is_expired cb ) cb then ( if Ivar . is_full cb . signal then [ % log ' error ( Logger . create ( ) ) ] " Ivar . fill bug is here " ! ; Ivar . fill cb . signal result )
let set_message_type t x = t . message_type <- x
type error += Oversized_operation of { size : int ; max : int }
type error += | Future_block_header of { block : Block_hash . t ; block_time : Time . Protocol . t ; time : Time . System . t ; }
let ( ) = register_error_kind ` Permanent ~ id " : node . prevalidation . parse_error " ~ title " : Parsing error in prevalidation " ~ description : " Raised when an operation has not been parsed correctly during \ prevalidation . " ~ pp ( : fun ppf ( ) -> Format . fprintf ppf...
type error += Unknown_chain of Chain_id . t
type error += Block_not_invalid of Block_hash . t
let ( ) = register_error_kind ` Permanent ~ id " : node . state . unknown_chain " ~ title " : Unknown chain " ~ description : " The chain identifier could not be found in the chain identifiers table . " ~ pp ( : fun ppf id -> Format . fprintf ppf " Unknown chain % a " Chain_id...
type error += Inconsistent_hash of Context_hash . t * Context_hash . t
type error += Missing_block_metadata_hash of Block_hash . t
type error += Missing_operation_metadata_hashes of Block_hash . t
let ( ) = register_error_kind ` Permanent ~ id " : node . state . block . inconsistent_context_hash " ~ title " : Inconsistent commit hash " ~ description : " When committing the context of a block , the announced context hash was \ not the one computed at commit time . " ~ pp ( ...
type error += Invalid_locator of P2p_peer . Id . t * Block_locator . t
type error += Too_short_locator of P2p_peer . Id . t * Block_locator . t
let ( ) = register_error_kind ` Permanent ~ id " : node . bootstrap_pipeline . invalid_locator " ~ title " : Invalid block locator " ~ description " : Block locator is invalid . " ~ pp ( : fun ppf ( id , locator ) -> Format . fprintf ppf " Invalid block locator on peer % a...
type protocol_error = Compilation_failed | Dynlinking_failed
type error += | Invalid_protocol of { hash : Protocol_hash . t ; error : protocol_error }
let protocol_error_encoding = let open Data_encoding in union [ case ( Tag 0 ) ~ title " : Compilation failed " ( obj1 ( req " error " ( constant " compilation_failed " ) ) ) ( function Compilation_failed -> Some ( ) | _ -> None ) ( fun ( ) -> Compilation_failed ) ...
let pp_protocol_error ppf = function | Compilation_failed -> Format . fprintf ppf " compilation error " | Dynlinking_failed -> Format . fprintf ppf " dynlinking error "
let ( ) = register_error_kind ` Permanent ~ id " : node . protocol_validator . invalid_protocol " ~ title " : Invalid protocol " ~ description " : Invalid protocol . " ~ pp ( : fun ppf ( protocol , error ) -> Format . fprintf ppf " [ @< v 2 > Invalid protocol % a @ ...
type error += Cannot_load_protocol of Protocol_hash . t
let ( ) = register_error_kind ` Permanent ~ id " : node . protocol_validator . cannot_load_protocol " ~ title " : Cannot load protocol " ~ description " : Cannot load protocol from disk " ~ pp ( : fun ppf protocol -> Format . fprintf ppf " Failed to load the protocol % a from disk...
type error += Unknown_ancestor | Known_invalid
let ( ) = register_error_kind ` Permanent ~ id " : node . peer_validator . unknown_ancestor " ~ title " : Unknown ancestor " ~ description " : Unknown ancestor block found in the peer ' s chain " ~ pp ( : fun ppf ( ) -> Format . fprintf ppf " Unknown ancestor " ) Data_enc...
type error += Inactive_chain of Chain_id . t
type error += Checkpoint_error of Block_hash . t * P2p_peer . Id . t option
let ( ) = register_error_kind ` Branch ~ id " : node . validator . inactive_chain " ~ title " : Inactive chain " ~ description " : Attempted validation of a block from an inactive chain . " ~ pp ( : fun ppf chain -> Format . fprintf ppf " Tried to validate a block from chain % a...
type ( ' time_received , ' genesis_state , ' proof , ' delta_block_chain , ' frontier_dependencies , ' staged_ledger_diff , ' protocol_versions ) t = ' time_received * ' genesis_state * ' proof * ' delta_block_chain * ' frontier_dependencies * ' staged_ledger_diff * ' protocol_versio...
type fully_invalid = ( [ ` Time_received ] * unit Truth . false_t , [ ` Genesis_state ] * unit Truth . false_t , [ ` Proof ] * unit Truth . false_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . false_t , [ ` Frontier_dependencies ] * unit Truth...
type initial_valid = ( [ ` Time_received ] * unit Truth . true_t , [ ` Genesis_state ] * unit Truth . true_t , [ ` Proof ] * unit Truth . true_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . true_t , [ ` Frontier_dependencies ] * unit Truth . f...
type almost_valid = ( [ ` Time_received ] * unit Truth . true_t , [ ` Genesis_state ] * unit Truth . true_t , [ ` Proof ] * unit Truth . true_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . true_t , [ ` Frontier_dependencies ] * unit Truth . tr...
type fully_valid = ( [ ` Time_received ] * unit Truth . true_t , [ ` Genesis_state ] * unit Truth . true_t , [ ` Proof ] * unit Truth . true_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . true_t , [ ` Frontier_dependencies ] * unit Truth . tru...
type ( ' time_received , ' genesis_state , ' proof , ' delta_block_chain , ' frontier_dependencies , ' staged_ledger_diff , ' protocol_versions ) with_block = Block . with_hash * ( ' time_received , ' genesis_state , ' proof , ' delta_block_chain , ' frontier_dependencies , ' ...
type fully_invalid_with_block = ( [ ` Time_received ] * unit Truth . false_t , [ ` Genesis_state ] * unit Truth . false_t , [ ` Proof ] * unit Truth . false_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . false_t , [ ` Frontier_dependencies ] *...
type initial_valid_with_block = ( [ ` Time_received ] * unit Truth . true_t , [ ` Genesis_state ] * unit Truth . true_t , [ ` Proof ] * unit Truth . true_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . true_t , [ ` Frontier_dependencies ] * uni...
type almost_valid_with_block = ( [ ` Time_received ] * unit Truth . true_t , [ ` Genesis_state ] * unit Truth . true_t , [ ` Proof ] * unit Truth . true_t , [ ` Delta_block_chain ] * State_hash . t Non_empty_list . t Truth . true_t , [ ` Frontier_dependencies ] * unit...
type fully_valid_with_block = Block . with_hash * fully_valid
let fully_invalid : fully_invalid = ( ( ` Time_received , Truth . False ) False , ( ` Genesis_state , Truth . False ) False , ( ` Proof , Truth . False ) False , ( ` Delta_block_chain , Truth . False ) False , ( ` Frontier_dependencies , Truth . False ) Fals...
type t = { state : Store . t ; db : Distributed_db . t ; block_validator : Block_validator . t ; chain_validator_limits : Chain_validator . limits ; peer_validator_limits : Peer_validator . limits ; block_validator_limits : Block_validator . limits ; prevalidator_limits : Prevalidator ...
let create state db peer_validator_limits block_validator_limits block_validator_kind prevalidator_limits chain_validator_limits ~ start_testchain = Block_validator . create block_validator_limits db block_validator_kind ~ start_testchain >>=? fun block_validator -> let valid_block_input = Lwt_watcher . creat...
let activate v ~ start_prevalidator ~ validator_process chain_store = let chain_id = Store . Chain . chain_id chain_store in Validator_event . ( emit activate_chain ) chain_id >>= fun ( ) -> match Chain_id . Table . find v . active_chains chain_id with | Some chain -> return chain | None -...
let get { active_chains ; _ } chain_id = match Chain_id . Table . find active_chains chain_id with | Some nv -> Ok nv | None -> error ( Validation_errors . Inactive_chain chain_id )
let get_active_chains { active_chains ; _ } = let l = Chain_id . Table . fold ( fun c _ acc -> c :: acc ) active_chains [ ] in List . rev l
let read_block store h = Store . all_chain_stores store >>= fun chain_stores -> Lwt_utils . find_map_s ( fun chain_store -> Store . Block . read_block_opt chain_store h >|= Option . map ( fun b -> ( Store . Chain . chain_id chain_store , b ) ) ) chain_stores
let read_block_header db h = read_block ( Distributed_db . store db ) h >|= Option . map ( fun ( chain_id , block ) -> ( chain_id , Store . Block . header block ) )
let validate_block v ( ? force = false ) ? chain_id bytes operations = let hash = Block_hash . hash_bytes [ bytes ] in match Block_header . of_bytes bytes with | None -> failwith " Cannot parse block header . " | Some block -> if not ( Clock_drift . is_not_too_far_in_the_future block . ...
let shutdown { active_chains ; block_validator ; _ } = let chain_validator_jobs = List . of_seq @@ Seq . map ( fun ( id , nv ) -> Validator_event . ( emit shutdown_chain_validator ) id >>= fun ( ) -> Chain_validator . shutdown nv ) ( Chain_id . Table . to_seq active_chains...
let watcher { valid_block_input ; _ } = Lwt_watcher . create_stream valid_block_input
let chains_watcher { chains_input ; _ } = Lwt_watcher . create_stream chains_input
let inject_operation v ? chain_id ~ force op = let inject_operation_on nv ~ handle_missing_prevalidator = match Chain_validator . prevalidator nv with | Some pv -> Prevalidator . inject_operation pv ~ force op | None -> handle_missing_prevalidator in let handle_missing_prevalidator = failwith " Prevali...
let distributed_db { db ; _ } = db
let section = [ " node " ; " validator " ]
let activate_chain = declare_1 ~ section ~ name " : activate_chain " ~ msg " : activate chain { chain } " ~ level : Notice ( " chain " , Chain_id . encoding )
let shutdown_block_validator = declare_0 ~ section ~ name " : shutdown_block_validator " ~ msg " : shutting down the block validator " ~ level : Notice ( )
let shutdown_chain_validator = declare_1 ~ section ~ name " : shutdown_chain_validator " ~ msg " : shutting down the chain validator { chain } " ~ level : Notice ( " chain " , Chain_id . encoding )
type t = | Empty | Node of t * key * t * int * Int64 . t
let height = function | Empty -> 0 | Node ( _ , _ , _ , h , _ ) -> h
let accval = function | Empty -> 0L | Node ( _ , _ , _ , _ , acc ) -> acc
let weight = function | Empty -> 0L | Node ( l , _ , r , _ , acc ) -> Int64 . sub ( Int64 . sub acc ( accval l ) ) ( accval r )
let rec print f = function | Empty -> Pp . empty_set f | Node ( l , k , r , _ , acc ) as x -> Format . fprintf f " [ @< hov 2 ><% d , % Li ( % Li ) , [ >@% a , @|% a , ] " @ k acc ( weight x ) print l print r
let create l key acc r = let hl = height l in let hr = height r in Node ( l , key , r , succ ( min hl hr ) , acc )
let bal l x w r = let hl = height l in let hr = height r in if hl > hr + 2 then begin match l with | Empty -> invalid_arg " Val_map . bal " | Node ( ll , lv , lr , _ , acc_l ) -> let acc_r = accval r in if height ll >= height lr then create ll lv ( Int64 . add ( Int64 . add acc_l ...
let is_empty = function Empty -> true | Node _ -> false
let rec add key weight = function | Empty -> Node ( Empty , key , Empty , 1 , Int64 . of_int weight ) | Node ( l , key ' , r , h , acc ) -> if key = key ' then Node ( l , key , r , h , Int64 . add ( Int64 . add ( Int64 . of_int weight ) ( accval l ) ) ( ...
let rec find_acc aim_acc = function | Empty -> raise Not_found | Node ( l , key , r , _ , acc ) -> if aim_acc >= acc then raise Not_found else let acc_l = accval l in let acc_r = accval r in if acc_l > aim_acc then find_acc aim_acc l else if Int64 . add acc_r acc_l > aim_acc then find_acc ( I...
let rec mem key = function | Empty -> false | Node ( l , key ' , r , _ , _ ) -> let c = Mods . int_compare key key ' in c = 0 || ( mem key ( if c < 0 then l else r ) )
let rec min_binding = function | Empty -> raise Not_found | Node ( Empty , x , r , _ , acc ) -> ( x , Int64 . sub acc ( accval r ) ) | Node ( l , _ , _ , _ , _ ) -> min_binding l
let rec remove_min_binding = function | Empty -> invalid_arg " Val_map . remove_min_elt " | Node ( Empty , _ , r , _ , _ ) -> r | Node ( l , x , r , _ , acc ) -> let weight = Int64 . sub ( Int64 . sub acc ( accval l ) ) ( accval r ) in bal ( remove_min_binding...
let merge t1 t2 = match ( t1 , t2 ) with | ( Empty , t ) -> t | ( t , Empty ) -> t | ( Node _ , Node _ ) -> let ( x , w ) = min_binding t2 in bal t1 x w ( remove_min_binding t2 )
let rec remove x = function | Empty -> Empty | Node ( l , v , r , _ , acc ) -> let c = compare x v in if c = 0 then merge l r else let weight = Int64 . sub ( Int64 . sub acc ( accval l ) ) ( accval r ) in if c < 0 then bal ( remove x l ) v weight r else bal l v weight ( rem...
let random state m = try let r = Random . State . int64 state ( accval m ) in find_acc r m with | Invalid_argument _ -> invalid_arg " Val_map . random_val "
module type DFA = sig type states val states : states Fin . set type transitions val transitions : transitions Fin . set type label val label : transitions Fin . elt -> label val source : transitions Fin . elt -> states Fin . elt val target : transitions Fin . elt -> states Fin . elt end
module type INPUT = sig include DFA val initials : ( states Fin . elt -> unit ) -> unit val finals : ( states Fin . elt -> unit ) -> unit val refinements : refine ( : iter ( ( : states Fin . elt -> unit ) -> unit ) -> unit ) -> unit end
let index_transitions ( type state ) ( type transition ) ( states : state Fin . set ) ( transitions : transition Fin . set ) ( target : transition Fin . elt -> state Fin . elt ) : state Fin . elt -> ( transition Fin . elt -> unit ) -> unit = let f = Array . make ( Fin ....
let discard_unreachable ( type state ) ( type transition ) ( blocks : state Partition . t ) ( transitions_of : state Fin . elt -> ( transition Fin . elt -> unit ) -> unit ) ( target : transition Fin . elt -> state Fin . elt ) = Partition . iter_marked_elements blocks 0 ( f...
module Minimize ( Label : Map . OrderedType ) ( In : INPUT with type label := Label . t ) : sig include DFA with type label = Label . t val initials : states Fin . elt array val finals : states Fin . elt array val transport_state : In . states Fin . elt -> states Fin . elt option val tr...
type t = | Int of int | Int32 of Int32 . t | Int64 of Int64 . t | Nativeint of Nativeint . t | Float of float | Float_array of float array | String of string | Object of t array | Block of int * t array
let rec bprint buf value = let open Printf in match value with | Int n -> bprintf buf " % d " n | Int32 n -> bprintf buf " % ldl " n | Int64 n -> bprintf buf " % LdL " n | Nativeint n -> bprintf buf " % ndn " n | Float f -> bprintf buf " % F " f | Float_array t -> bprint_mlarray ( ...
let to_string value = let buf = Buffer . create 16 in bprint buf value ; Buffer . contents buf
let rec of_obj obj = let tag = Obj . tag obj in if tag = Obj . lazy_tag then fail " unexpected lazy block " ; if tag = Obj . closure_tag then fail " unexpected closure " ; if tag = Obj . infix_tag then fail " unexpected closure " ; if tag = Obj . abstract_tag then fail " unexpected a...
let make_to_obj ( ) = let float_htbl = Hashtbl . create 16 in let int32_htbl = Hashtbl . create 16 in let int64_htbl = Hashtbl . create 16 in let nativeint_htbl = Hashtbl . create 16 in let unify htbl v = try Hashtbl . find htbl v with Not_found -> let o = Obj . repr v in Hashtbl . add htb...
module type Value = sig type t val zero : t val zero_of_type : type_t -> t val compare : t -> t -> int val to_string : t -> string end
module type Valuation = functor ( V : Value ) -> sig type key = string type value_t = V . t type t val make : string list -> V . t list -> t val vars : t -> string list val bound : string -> t -> bool val value : string -> t -> V . t val consistent : t -> t -> bool val add : t -> string ...
module AbstractValuation : Valuation = functor ( V : Value ) -> struct module StringMap = Map . Make ( String ) type key = StringMap . key type value_t = V . t type t = V . t StringMap . t let make vars values = List . fold_left ( fun acc ( k , v ) -> StringMap . add k v acc ) ...
module rec K3Value : sig type single_map_t = t K3ValuationMap . t and map_t = single_map_t K3ValuationMap . t and t = | Unit | BaseValue of Constants . const_t | Tuple of t list | Fun of ( t -> t ) | SingleMap of single_map_t | DoubleMap of map_t | FloatList of t list | TupleList of t list | Sin...
module Make ( D : Debugger . S ) = struct module V = D . Value let rec copy0 ( v : V . t ) : ' a = if debug then begin Format . printf " Value_copier . copy0 % a \ n " %! V . print v end ; if V . is_int v then begin if debug then begin Format . printf " Value is an immediate ....
module type Make_subtype_arg = sig type value val here : Source_code_position . t val name : string val is_in_subtype : value -> bool end
type ' a funcall = ? should_profile : bool -> ' a
module type Funcall = sig type t type value val funcall0 : ( t -> value ) funcall val funcall1 : ( t -> value -> value ) funcall val funcall2 : ( t -> value -> value -> value ) funcall val funcall3 : ( t -> value -> value -> value -> value ) funcall val funcall4 : ( t -> value -> val...
module type Subtype = sig type value type t = private value [ @@ deriving sexp_of ] val eq : t -> t -> bool val is_in_subtype : value -> bool include Valueable0 . S with type t := t end
module type Type = sig type value type ' a t val create : Sexp . t -> ( ' a -> Sexp . t ) -> ( value -> ' a ) -> ( ' a -> value ) -> ' a t val with_of_value_exn : ' a t -> ( value -> ' a ) -> ' a t val to_sexp : ' a t -> ' a -> Sexp . t val bool : bool t val fl...
module type Value = sig type t = Value0 . t [ @@ deriving sexp_of ] include Funcall with type t := t with type value := t val intern : string -> t val nil : t val t : t val list : t list -> t val cons : t -> t -> t val car_exn : t -> t val cdr_exn : t -> t val to_list_exn : t -> f ( : t ->...
module Make ( D : Debugger . S ) ( Cmt_cache : Cmt_cache_intf . S ) ( Type_helper : Type_helper_intf . S with module Cmt_cache := Cmt_cache with module D := D ) ( Type_printer : Type_printer_intf . S with module Cmt_cache := Cmt_cache ) = struct module Our_type_oracle = Type_oracle . ...
type ' a t = { symbol : Symbol . t ; type_ : ' a Value . Type . t }
let sexp_of_t _ { symbol ; type_ } = [ % message " " ~ _ ( : symbol : Symbol . t ) ~ _ ( : type_ : _ Value . Type . t ) ] ; ;
type ' a var = ' a t [ @@ deriving sexp_of ]
let create symbol type_ = { symbol ; type_ = Value . Type . with_of_value_exn type_ ( fun value -> try Value . Type . of_value_exn type_ value with | exn -> raise_s [ % message " " ~ _ ( : concat [ " invalid value for variable : " ; symbol |> Symbol . name ] ) ~ _ ( :...