text stringlengths 12 786k |
|---|
module Cametallayer = struct type m type t = m Ctypes . structure let ctype : t Ctypes . typ = Ctypes . structure " CAmetallayer " let pp = Vk__helpers . Pp . abstract end |
type cametallayer = Cametallayer . t Ctypes . structure |
module type Config = sig val shift : int val char_of_digit : int -> char val digit_of_char : char -> int end |
module type S = sig val encode : Buffer . t -> int -> unit val decode : char Stream . t -> int end |
module Make ( C : Config ) = struct let vlq_base = 1 lsl C . shift let vlq_base_mask = vlq_base - 1 let vlq_continuation_bit = vlq_base let vlq_signed_of_int value = if value < 0 then ( ( - value ) lsl 1 ) + 1 else ( value lsl 1 ) + 0 let rec encode_vlq buf vlq = let digit = vlq la... |
module Base64 = Make ( struct let shift = 5 let base64 = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " +/ let char_of_digit digit = if 0 <= digit && digit < String . length base64 then base64 . [ digit ] else failwith ( Printf . sprintf " Must be between 0 and 63 : ... |
let code_rev = let a = Array . make 255 ( - 1 ) in for i = 0 to String . length code - 1 do a . ( Char . code code . [ i ] ) <- i done ; a |
let vlq_base = 1 lsl vlq_base_shift |
let vlq_base_mask = vlq_base - 1 |
let toVLQSigned v = if v < 0 then ( - v lsl 1 ) + 1 else v lsl 1 |
let fromVLQSigned v = let is_neg = v land 1 = 1 in let shift = v lsr 1 in if is_neg then - shift else shift |
let add_char buf x = Buffer . add_char buf code . [ x ] |
let rec encode ' buf x = let digit = x land vlq_base_mask in let rest = x lsr vlq_base_shift in if rest = 0 then add_char buf digit else ( add_char buf ( digit lor vlq_continuation_bit ) ; encode ' buf rest ) |
let encode b x = let vql = toVLQSigned x in encode ' b vql |
let encode_l b l = List . iter ~ f ( : encode b ) l |
let rec decode ' acc s start pos = let digit = code_rev . ( Char . code s . [ pos ] ) in if digit = - 1 then invalid_arg " Vql64 . decode ' " ; let cont = digit land vlq_continuation_bit = vlq_continuation_bit in let digit = digit land vlq_base_mask in let acc = acc + ( digit lsl (... |
let decode s p = let d , i = decode ' 0 s p p in fromVLQSigned d , i |
let decode_l s ~ pos ~ len = let rec aux pos acc len = if len = 0 then List . rev acc else if len < 0 then invalid_arg " Vlq64 . decode_l " else let d , i = decode s pos in let len = len - ( i - pos ) in aux i ( d :: acc ) len in aux pos [ ] len |
module Make ( V : HashCmp ) ( L : Lattice ) ( R : Result ) = struct type v = V . t * L . t type r = R . t type d = Leaf of r | Branch of V . t * L . t * t * t and t = { id : int ; d : d } let equal x y = x . id = y . id let rec to_string t = match t . d with | Leaf r... |
let network = [ " host " ] |
let download_cache = Obuilder_spec . Cache . v " opam - archives " ~ target " :/ home / opam . / opam / download - cache " |
let dune_cache = Obuilder_spec . Cache . v " opam - dune - cache " ~ target " :/ home / opam . / cache / dune " |
let cache = [ download_cache ; dune_cache ] |
type t0 = { voodoo_do : Git . Commit_id . t ; voodoo_prep : Git . Commit_id . t ; voodoo_gen : Git . Commit_id . t ; } |
module Op = struct type voodoo = t0 type t = No_context let id = " voodoo - repository " let pp f _ = Fmt . pf f " voodoo - repository " let auto_cancel = false module Key = struct type t = Git . Commit . t let digest = Git . Commit . hash end module Value = struct type t = voodoo let to... |
module VoodooCache = Current_cache . Make ( Op ) |
let v ( ) = let daily = Current_cache . Schedule . v ~ valid_for ( : Duration . of_day 1 ) ( ) in let git = Git . clone ~ schedule : daily ~ gref " : main " " https :// github . com / ocaml - doc / voodoo . git " in let open Current . Syntax in Current . component " v... |
type t = { voodoo_do : Git . Commit_id . t ; voodoo_prep : Git . Commit_id . t ; voodoo_gen : Git . Commit_id . t ; config : Config . t ; } |
let v config = let open Current . Syntax in let + { voodoo_do ; voodoo_prep ; voodoo_gen } = v ( ) in { voodoo_do ; voodoo_prep ; voodoo_gen ; config } |
let remote_uri commit = let repo = Git . Commit_id . repo commit in let commit = Git . Commit_id . hash commit in repo ^ " " # ^ commit |
let digest t = let key = Fmt . str " % s \ n % s \ n % s \ n % s \ n " ( Git . Commit_id . hash t . voodoo_prep ) ( Git . Commit_id . hash t . voodoo_do ) ( Git . Commit_id . hash t . voodoo_gen ) ( Config . odoc t . config ) in Digest . ( string key |> to_hex ... |
module Prep = struct type voodoo = t type t = Git . Commit_id . t let v { voodoo_prep ; _ } = voodoo_prep let spec ~ base t = let open Obuilder_spec in base |> Spec . add [ run ~ network " sudo apt - get update && sudo apt - get install - yy m4 pkg - config " ; run ~ network ~ cache ... |
module Do = struct type voodoo = t type t = { commit : Git . Commit_id . t ; config : Config . t } let v { voodoo_do ; config ; _ } = { commit = voodoo_do ; config } let spec ~ base t = let open Obuilder_spec in base |> Spec . add [ run ~ network " sudo apt - get update && ... |
module Gen = struct type voodoo = t type t = { commit : Git . Commit_id . t ; config : Config . t } let v { voodoo_gen ; config ; _ } = { commit = voodoo_gen ; config } let spec ~ base t = let open Obuilder_spec in base |> Spec . add [ run ~ network " sudo apt - get update ... |
type ballot = Yay | Nay | Pass |
let ballot_encoding = let of_int8 = function | 0 -> Yay | 1 -> Nay | 2 -> Pass | _ -> invalid_arg " ballot_of_int8 " in let to_int8 = function | Yay -> 0 | Nay -> 1 | Pass -> 2 in let open Data_encoding in splitted ~ binary : ( conv to_int8 of_int8 int8 ) ~ json : ( string_enum [ ... |
let recorded_proposal_count_for_delegate ctxt proposer = Storage . Vote . Proposals_count . find ctxt proposer >|=? Option . value ~ default : 0 |
let record_proposal ctxt proposal proposer = recorded_proposal_count_for_delegate ctxt proposer >>=? fun count -> Storage . Vote . Proposals_count . add ctxt proposer ( count + 1 ) >>= fun ctxt -> Storage . Vote . Proposals . add ctxt ( proposal , proposer ) >|= ok |
let get_proposals ctxt = Storage . Vote . Proposals . fold ctxt ~ order ` : Sorted ~ init ( : ok Protocol_hash . Map . empty ) ~ f ( : fun ( proposal , delegate ) acc -> Storage . Vote . Listings . get ctxt delegate >>=? fun weight -> Lwt . return ( acc >|? fun acc -> let p... |
let clear_proposals ctxt = Storage . Vote . Proposals_count . clear ctxt >>= fun ctxt -> Storage . Vote . Proposals . clear ctxt |
type ballots = { yay : int64 ; nay : int64 ; pass : int64 } |
let ballots_encoding = let open Data_encoding in conv ( fun { yay ; nay ; pass } -> ( yay , nay , pass ) ) ( fun ( yay , nay , pass ) -> { yay ; nay ; pass } ) @@ obj3 ( req " yay " int64 ) ( req " nay " int64 ) ( req " pass " int64 ) |
let get_ballots ctxt = Storage . Vote . Ballots . fold ctxt ~ order ` : Sorted ~ f ( : fun delegate ballot ( ballots : ballots tzresult ) -> Storage . Vote . Listings . get ctxt delegate >>=? fun weight -> let count = Int64 . add weight in Lwt . return ( ballots >|? fun ballots -> ... |
let listings_encoding = Data_encoding . ( list ( obj2 ( req " pkh " Signature . Public_key_hash . encoding ) ( req " voting_power " int64 ) ) ) |
let update_listings ctxt = Storage . Vote . Listings . clear ctxt >>= fun ctxt -> Stake_storage . fold ctxt ( ctxt , 0L ) ~ order ` : Sorted ~ f ( : fun ( delegate , stake ) ( ctxt , total ) -> let weight = Tez_repr . to_mutez stake in Storage . Vote . Listings . init ctx... |
let get_voting_power_free ctxt owner = Storage . Vote . Listings . find ctxt owner >|=? Option . value ~ default : 0L |
let get_voting_power ctxt owner = let open Raw_context in consume_gas ctxt ( Storage_costs . read_access ~ path_length : 4 ~ read_bytes : 8 ) >>?= fun ctxt -> Storage . Vote . Listings . find ctxt owner >|=? function | None -> ( ctxt , 0L ) | Some power -> ( ctxt , power ) |
let get_total_voting_power ctxt = let open Raw_context in consume_gas ctxt ( Storage_costs . read_access ~ path_length : 2 ~ read_bytes : 8 ) >>?= fun ctxt -> get_total_voting_power_free ctxt >|=? fun total_voting_power -> ( ctxt , total_voting_power ) |
let get_current_quorum ctxt = Storage . Vote . Participation_ema . get ctxt >|=? fun participation_ema -> let quorum_min = Constants_storage . quorum_min ctxt in let quorum_max = Constants_storage . quorum_max ctxt in let quorum_diff = Int32 . sub quorum_max quorum_min in Int32 . ( add quorum_min ... |
let init ctxt ~ start_position = let participation_ema = Constants_storage . quorum_max ctxt in Storage . Vote . Participation_ema . init ctxt participation_ema >>=? fun ctxt -> Voting_period_storage . init_first_period ctxt ~ start_position |
let test_proto_files = [ " main . ml " ; " main . mli " ] |
let test_proto_TEZOS_PROTOCOL = { { | " modules " : [ " Main " ] , " expected_env_version " : 3 } } | |
type period = { index : int ; kind : string ; start_position : int ; position : int ; remaining : int ; } |
let period_type : period Check . typ = Check . convert ( fun { index ; kind ; start_position ; position ; remaining } -> ( index , kind , start_position , position , remaining ) ) Check . ( tuple5 int string int int int ) |
let decode_period json = let index = JSON . ( json |-> " voting_period " |-> " index " |> as_int ) in let kind = JSON . ( json |-> " voting_period " |-> " kind " |> as_string ) in let start_position = JSON . ( json |-> " voting_period " |-> " start_position " |> as_i... |
let get_current_period client = let * json = RPC . Votes . get_current_period client in return ( decode_period json ) |
let get_successor_period client = let * json = RPC . Votes . get_successor_period client in return ( decode_period json ) |
let check_current_period client expected_period = let * period = get_current_period client in Check . ( ( period = expected_period ) period_type ) ~ error_msg " : expected current_period = % R , got % L " ; unit |
let check_successor_period client expected_period = let * period = get_successor_period client in Check . ( ( period = expected_period ) period_type ) ~ error_msg " : expected successor_period = % R , got % L " ; unit |
type level = { level : int ; level_position : int ; cycle : int ; cycle_position : int ; expected_commitment : bool ; } |
let level_type : level Check . typ = Check . convert ( fun { level ; level_position ; cycle ; cycle_position ; expected_commitment } -> ( level , level_position , cycle , cycle_position , expected_commitment ) ) Check . ( tuple5 int int int int bool ) |
let decode_level json = let level = JSON . ( json |-> " level " |> as_int ) in let level_position = JSON . ( json |-> " level_position " |> as_int ) in let cycle = JSON . ( json |-> " cycle " |> as_int ) in let cycle_position = JSON . ( json |-> " cycle_position " |> a... |
let get_current_level client = let * json = RPC . get_current_level client in return ( decode_level json ) |
let check_current_level client expected_level = let * level = get_current_level client in Check . ( ( level = expected_level ) level_type ) ~ error_msg " : expected current_period = % R , got % L " ; unit |
let get_proposals client = let * proposals = RPC . Votes . get_proposals client in JSON . as_list proposals |> List . map JSON . as_list |> List . map ( function | [ hash ; _ ] -> JSON . as_string hash | _ -> Test . fail " invalid proposal in JSON response : expected a list with 2 ... |
let get_current_proposal client = let * proposal = RPC . Votes . get_current_proposal client in if JSON . is_null proposal then return None else return ( Some JSON . ( proposal |> as_string ) ) |
let check_current_proposal client expected_proposal_hash = let * current_proposal = get_current_proposal client in Check . ( ( current_proposal = Some expected_proposal_hash ) ( option string ) ) ~ error_msg " : expected current_proposal = % R , got % L " ; unit |
let get_protocols client = let * block = RPC . get_block_metadata client in return ( JSON . ( block |-> " protocol " |> as_string ) , JSON . ( block |-> " next_protocol " |> as_string ) ) |
let check_protocols client expected_protocols = let * protocols = get_protocols client in Check . ( ( protocols = expected_protocols ) ( tuple2 string string ) ) ~ error_msg " : expected ( protocol , next_protocol ) = % R , got % L " ; unit |
let check_listings_not_empty client = let * listings = RPC . Votes . get_listings client in match JSON . as_list listings with | [ ] -> Test . fail " Expected GET . . . / votes / listing RPC to return a non - empty list " | _ :: _ -> unit |
type target_protocol = Known of Protocol . t | Injected_test |
let target_protocol_tag = function | Known protocol -> Protocol . tag protocol | Injected_test -> " injected_test " |
let register ~ from_protocol ( ~ to_protocol : target_protocol ) ~ loser_protocols = Test . register ~ __FILE__ ~ title : ( sf " amendment : % s -> % s ( losers : % s ) " ( Protocol . tag from_protocol ) ( target_protocol_tag to_protocol ) ( String . concat " , " ( L... |
type kind = Proposal | Exploration | Cooldown | Promotion | Adoption |
let string_of_kind = function | Proposal -> " proposal " | Exploration -> " exploration " | Cooldown -> " cooldown " | Promotion -> " promotion " | Adoption -> " adoption " |
let pp_kind ppf kind = Format . fprintf ppf " % s " @@ string_of_kind kind |
let kind_encoding = let open Data_encoding in union ~ tag_size ` : Uint8 [ case ( Tag 0 ) ~ title " : Proposal " ( constant " proposal " ) ( function Proposal -> Some ( ) | _ -> None ) ( fun ( ) -> Proposal ) ; case ( Tag 1 ) ~ title " : exploration " ( cons... |
let succ_kind = function | Proposal -> Exploration | Exploration -> Cooldown | Cooldown -> Promotion | Promotion -> Adoption | Adoption -> Proposal |
type voting_period = { index : int32 ; kind : kind ; start_position : int32 } |
type info = { voting_period : t ; position : int32 ; remaining : int32 } |
let root ~ start_position = { index = 0l ; kind = Proposal ; start_position } |
let pp ppf { index ; kind ; start_position } = Format . fprintf ppf " [ @< hv 2 > index : % ld , @ kind :% a , @ start_position : % ld ] " @ index pp_kind kind start_position |
let pp_info ppf { voting_period ; position ; remaining } = Format . fprintf ppf " [ @< hv 2 > voting_period : % a , @ position :% ld , @ remaining : % ld ] " @ pp voting_period position remaining |
let encoding = let open Data_encoding in conv ( fun { index ; kind ; start_position } -> ( index , kind , start_position ) ) ( fun ( index , kind , start_position ) -> { index ; kind ; start_position } ) ( obj3 ( req " index " ~ description : " The voting period ' ... |
let info_encoding = let open Data_encoding in conv ( fun { voting_period ; position ; remaining } -> ( voting_period , position , remaining ) ) ( fun ( voting_period , position , remaining ) -> { voting_period ; position ; remaining } ) ( obj3 ( req ~ description " : T... |
let raw_reset period ~ start_position = let index = Int32 . succ period . index in let kind = Proposal in { index ; kind ; start_position } |
let raw_succ period ~ start_position = let index = Int32 . succ period . index in let kind = succ_kind period . kind in { index ; kind ; start_position } |
let position_since ( level : Level_repr . t ) ( voting_period : t ) = Int32 . ( sub level . level_position voting_period . start_position ) |
let remaining_blocks ( level : Level_repr . t ) ( voting_period : t ) ~ blocks_per_voting_period = let position = position_since level voting_period in Int32 . ( sub blocks_per_voting_period ( succ position ) ) |
let init_first_period ctxt ~ start_position = init ctxt @@ Voting_period_repr . root ~ start_position >>=? fun ctxt -> Storage . Vote . Pred_period_kind . init ctxt Voting_period_repr . Proposal |
let common ctxt = get_current ctxt >>=? fun current_period -> Storage . Vote . Pred_period_kind . update ctxt current_period . kind >|=? fun ctxt -> let start_position = Int32 . succ ( Level_storage . current ctxt ) . level_position in ( ctxt , current_period , start_position ) |
let reset ctxt = common ctxt >>=? fun ( ctxt , current_period , start_position ) -> Voting_period_repr . raw_reset current_period ~ start_position |> set_current ctxt |
let succ ctxt = common ctxt >>=? fun ( ctxt , current_period , start_position ) -> Voting_period_repr . raw_succ current_period ~ start_position |> set_current ctxt |
let get_current_kind ctxt = get_current ctxt >|=? fun { kind ; _ } -> kind |
let get_current_info ctxt = get_current ctxt >|=? fun voting_period -> let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in let level = Level_storage . current ctxt in let position = Voting_period_repr . position_since level voting_period in let remaining = Voting_period_repr... |
let get_current_remaining ctxt = get_current ctxt >|=? fun voting_period -> let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in Voting_period_repr . remaining_blocks ( Level_storage . current ctxt ) voting_period ~ blocks_per_voting_period |
let is_last_block ctxt = get_current_remaining ctxt >|=? fun remaining -> Compare . Int32 . ( remaining = 0l ) |
let get_rpc_current_info ctxt = get_current_info ctxt >>=? fun ( { voting_period ; position ; _ } as voting_period_info ) -> if Compare . Int32 . ( position = Int32 . minus_one ) then let level = Level_storage . current ctxt in let blocks_per_voting_period = Constants_storage . blocks_p... |
let get_rpc_succ_info ctxt = Level_storage . from_raw_with_offset ctxt ~ offset : 1l ( Level_storage . current ctxt ) . level >>?= fun level -> get_current ctxt >|=? fun voting_period -> let blocks_per_voting_period = Constants_storage . blocks_per_voting_period ctxt in let position = Voting_perio... |
module S = struct let path = RPC_path . ( open_root / " votes " ) let ballots = RPC_service . get_service ~ description " : Sum of ballots casted so far during a voting period . " ~ query : RPC_query . empty ~ output : Vote . ballots_encoding RPC_path . ( path / " ballots " ) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.