Mining -> Baking

This commit is contained in:
Arthur Breitman 2017-11-01 08:42:37 -07:00
parent 6dd9f2289a
commit 1bdae93ffd
16 changed files with 81 additions and 81 deletions

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
open Client_commands open Client_commands
open Logging.Client.Mining open Logging.Client.Baking
let run cctxt ?max_priority ~delay ?min_date delegates ~endorsement ~denunciation ~baking = let run cctxt ?max_priority ~delay ?min_date delegates ~endorsement ~denunciation ~baking =
(* TODO really detach... *) (* TODO really detach... *)

View File

@ -9,7 +9,7 @@
open Client_commands open Client_commands
open Logging.Client.Mining open Logging.Client.Baking
let generate_proof_of_work_nonce () = let generate_proof_of_work_nonce () =
Sodium.Random.Bigbytes.generate Constants.proof_of_work_nonce_size Sodium.Random.Bigbytes.generate Constants.proof_of_work_nonce_size
@ -32,7 +32,7 @@ let rec forge_block_header
let signed_header = let signed_header =
Environment.Ed25519.Signature.append delegate_sk unsigned_header in Environment.Ed25519.Signature.append delegate_sk unsigned_header in
let block_hash = Block_hash.hash_bytes [signed_header] in let block_hash = Block_hash.hash_bytes [signed_header] in
if Mining.check_hash block_hash stamp_threshold then if Baking.check_hash block_hash stamp_threshold then
signed_header signed_header
else else
loop () in loop () in
@ -146,7 +146,7 @@ let forge_block cctxt block
with Not_found -> with Not_found ->
failwith "No slot found at level %a" Raw_level.pp level failwith "No slot found at level %a" Raw_level.pp level
end >>=? fun (priority, minimal_timestamp) -> end >>=? fun (priority, minimal_timestamp) ->
(* lwt_log_info "Mining block at level %a prio %d" *) (* lwt_log_info "Baking block at level %a prio %d" *)
(* Raw_level.pp level priority >>= fun () -> *) (* Raw_level.pp level priority >>= fun () -> *)
begin begin
match timestamp, minimal_timestamp with match timestamp, minimal_timestamp with

View File

@ -53,7 +53,7 @@ val forge_block:
operations and add them to the block. Otherwise, provided operations and add them to the block. Otherwise, provided
operations will be used. In both cases, they will be validated. operations will be used. In both cases, they will be validated.
* Mining priority: If [`Auto] is used, it will be computed from * Baking priority: If [`Auto] is used, it will be computed from
the public key hash of the specified contract, optionally capped the public key hash of the specified contract, optionally capped
to a maximum value, and optionnaly restricting for free baking slot. to a maximum value, and optionnaly restricting for free baking slot.

View File

@ -46,7 +46,7 @@
"Script_ir_translator", "Script_ir_translator",
"Script_interpreter", "Script_interpreter",
"Mining", "Baking",
"Amendment", "Amendment",
"Apply", "Apply",

View File

@ -65,10 +65,10 @@ let apply_delegate_operation_content
fail_unless fail_unless
(Block_hash.equal block pred_block) (Block_hash.equal block pred_block)
(Wrong_endorsement_predecessor (pred_block, block)) >>=? fun () -> (Wrong_endorsement_predecessor (pred_block, block)) >>=? fun () ->
Mining.check_signing_rights ctxt slot delegate >>=? fun () -> Baking.check_signing_rights ctxt slot delegate >>=? fun () ->
let ctxt = Fitness.increase ctxt in let ctxt = Fitness.increase ctxt in
Mining.pay_endorsement_bond ctxt delegate >>=? fun (ctxt, bond) -> Baking.pay_endorsement_bond ctxt delegate >>=? fun (ctxt, bond) ->
Mining.endorsement_reward ~block_priority >>=? fun reward -> Baking.endorsement_reward ~block_priority >>=? fun reward ->
let { cycle = current_cycle } : Level.t = Level.current ctxt in let { cycle = current_cycle } : Level.t = Level.current ctxt in
Lwt.return Tez.(reward +? bond) >>=? fun full_reward -> Lwt.return Tez.(reward +? bond) >>=? fun full_reward ->
Reward.record ctxt delegate current_cycle full_reward Reward.record ctxt delegate current_cycle full_reward
@ -249,7 +249,7 @@ let apply_operation
return (ctxt, Contract.originated_contracts origination_nonce, err) return (ctxt, Contract.originated_contracts origination_nonce, err)
let may_start_new_cycle ctxt = let may_start_new_cycle ctxt =
Mining.dawn_of_a_new_cycle ctxt >>=? function Baking.dawn_of_a_new_cycle ctxt >>=? function
| None -> return ctxt | None -> return ctxt
| Some last_cycle -> | Some last_cycle ->
let new_cycle = Cycle.succ last_cycle in let new_cycle = Cycle.succ last_cycle in
@ -269,9 +269,9 @@ let begin_full_construction ctxt pred_timestamp proto_header =
Lwt.return Lwt.return
(Block_header.parse_unsigned_proto_header (Block_header.parse_unsigned_proto_header
proto_header) >>=? fun proto_header -> proto_header) >>=? fun proto_header ->
Mining.check_baking_rights Baking.check_baking_rights
ctxt proto_header pred_timestamp >>=? fun miner -> ctxt proto_header pred_timestamp >>=? fun miner ->
Mining.pay_baking_bond ctxt proto_header miner >>=? fun ctxt -> Baking.pay_baking_bond ctxt proto_header miner >>=? fun ctxt ->
let ctxt = Fitness.increase ctxt in let ctxt = Fitness.increase ctxt in
return (ctxt, proto_header, miner) return (ctxt, proto_header, miner)
@ -280,19 +280,19 @@ let begin_partial_construction ctxt =
return ctxt return ctxt
let begin_application ctxt block_header pred_timestamp = let begin_application ctxt block_header pred_timestamp =
Mining.check_proof_of_work_stamp ctxt block_header >>=? fun () -> Baking.check_proof_of_work_stamp ctxt block_header >>=? fun () ->
Mining.check_fitness_gap ctxt block_header >>=? fun () -> Baking.check_fitness_gap ctxt block_header >>=? fun () ->
Mining.check_baking_rights Baking.check_baking_rights
ctxt block_header.proto pred_timestamp >>=? fun miner -> ctxt block_header.proto pred_timestamp >>=? fun miner ->
Mining.check_signature ctxt block_header miner >>=? fun () -> Baking.check_signature ctxt block_header miner >>=? fun () ->
Mining.pay_baking_bond ctxt block_header.proto miner >>=? fun ctxt -> Baking.pay_baking_bond ctxt block_header.proto miner >>=? fun ctxt ->
let ctxt = Fitness.increase ctxt in let ctxt = Fitness.increase ctxt in
return (ctxt, miner) return (ctxt, miner)
let finalize_application ctxt block_proto_header miner = let finalize_application ctxt block_proto_header miner =
(* end of level (from this point nothing should fail) *) (* end of level (from this point nothing should fail) *)
let priority = block_proto_header.Block_header.priority in let priority = block_proto_header.Block_header.priority in
let reward = Mining.base_baking_reward ctxt ~priority in let reward = Baking.base_baking_reward ctxt ~priority in
Nonce.record_hash ctxt Nonce.record_hash ctxt
miner reward block_proto_header.seed_nonce_hash >>=? fun ctxt -> miner reward block_proto_header.seed_nonce_hash >>=? fun ctxt ->
Reward.pay_due_rewards ctxt >>=? fun ctxt -> Reward.pay_due_rewards ctxt >>=? fun ctxt ->

View File

@ -54,7 +54,7 @@ module Header = struct
let priority custom_root = let priority custom_root =
RPC.service RPC.service
~description: "Mining priority of the block." ~description: "Baking priority of the block."
~input: empty ~input: empty
~output: (wrap_tzerror uint16) ~output: (wrap_tzerror uint16)
RPC.Path.(custom_root / "header" / "priority") RPC.Path.(custom_root / "header" / "priority")

View File

@ -231,7 +231,7 @@ let () =
let minimal_timestamp ctxt prio = let minimal_timestamp ctxt prio =
let prio = match prio with None -> 0 | Some p -> p in let prio = match prio with None -> 0 | Some p -> p in
Mining.minimal_time ctxt prio Baking.minimal_time ctxt prio
let () = register1 let () = register1
Services.Helpers.minimal_timestamp Services.Helpers.minimal_timestamp
@ -250,7 +250,7 @@ let () =
| Some (shell, contents) -> | Some (shell, contents) ->
let operation = { hash ; shell ; contents ; signature } in let operation = { hash ; shell ; contents ; signature } in
let level = Tezos_context.Level.current ctxt in let level = Tezos_context.Level.current ctxt in
Mining.baking_priorities ctxt level >>=? fun (Misc.LCons (miner_pkh, _)) -> Baking.baking_priorities ctxt level >>=? fun (Misc.LCons (miner_pkh, _)) ->
let miner_contract = Contract.default_contract miner_pkh in let miner_contract = Contract.default_contract miner_pkh in
let block_prio = 0 in let block_prio = 0 in
Apply.apply_operation Apply.apply_operation
@ -335,7 +335,7 @@ let default_max_baking_priority ctxt arg =
let baking_rights ctxt level max = let baking_rights ctxt level max =
let max = default_max_baking_priority ctxt max in let max = default_max_baking_priority ctxt max in
Mining.baking_priorities ctxt level >>=? fun contract_list -> Baking.baking_priorities ctxt level >>=? fun contract_list ->
let rec loop l n = let rec loop l n =
match n with match n with
| 0 -> return [] | 0 -> return []
@ -358,7 +358,7 @@ let () =
List.mapi List.mapi
(fun prio c -> (fun prio c ->
let timestamp = Timestamp.current ctxt in let timestamp = Timestamp.current ctxt in
Mining.minimal_time ctxt prio timestamp >>= function Baking.minimal_time ctxt prio timestamp >>= function
| Error _ -> Lwt.return None | Error _ -> Lwt.return None
| Ok minimal_timestamp -> Lwt.return (Some (c, minimal_timestamp))) | Ok minimal_timestamp -> Lwt.return (Some (c, minimal_timestamp)))
slots slots
@ -389,13 +389,13 @@ let baking_rights_for_delegate
then return [] then return []
else else
loop (Level.succ ctxt level) >>=? fun t -> loop (Level.succ ctxt level) >>=? fun t ->
Mining.first_baking_priorities Baking.first_baking_priorities
ctxt ~max_priority contract level >>=? fun priorities -> ctxt ~max_priority contract level >>=? fun priorities ->
let raw_level = level.level in let raw_level = level.level in
Error_monad.map_s Error_monad.map_s
(fun priority -> (fun priority ->
let timestamp = Timestamp.current ctxt in let timestamp = Timestamp.current ctxt in
Mining.minimal_time ctxt priority timestamp >>=? fun time -> Baking.minimal_time ctxt priority timestamp >>=? fun time ->
return (raw_level, priority, time)) return (raw_level, priority, time))
priorities >>=? fun priorities -> priorities >>=? fun priorities ->
return (priorities @ t) return (priorities @ t)
@ -414,7 +414,7 @@ let default_max_endorsement_priority ctxt arg =
let endorsement_rights ctxt level max = let endorsement_rights ctxt level max =
let max = default_max_endorsement_priority ctxt max in let max = default_max_endorsement_priority ctxt max in
Mining.endorsement_priorities ctxt level >>=? fun contract_list -> Baking.endorsement_priorities ctxt level >>=? fun contract_list ->
let rec loop l n = let rec loop l n =
match n with match n with
| 0 -> return [] | 0 -> return []
@ -453,7 +453,7 @@ let endorsement_rights_for_delegate
then return [] then return []
else else
loop (Level.succ ctxt level) >>=? fun t -> loop (Level.succ ctxt level) >>=? fun t ->
Mining.first_endorsement_slots Baking.first_endorsement_slots
ctxt ~max_priority contract level >>=? fun slots -> ctxt ~max_priority contract level >>=? fun slots ->
let raw_level = level.level in let raw_level = level.level in
let slots = List.rev_map (fun slot -> (raw_level, slot)) slots in let slots = List.rev_map (fun slot -> (raw_level, slot)) slots in

View File

@ -84,7 +84,7 @@ module Node = struct
end end
module Client = struct module Client = struct
module Blocks = Make(struct let name = "client.blocks" end) module Blocks = Make(struct let name = "client.blocks" end)
module Mining = Make(struct let name = "client.baking" end) module Baking = Make(struct let name = "client.baking" end)
module Endorsement = Make(struct let name = "client.endorsement" end) module Endorsement = Make(struct let name = "client.endorsement" end)
module Revelation = Make(struct let name = "client.revealation" end) module Revelation = Make(struct let name = "client.revealation" end)
module Denunciation = Make(struct let name = "client.denunciation" end) module Denunciation = Make(struct let name = "client.denunciation" end)

View File

@ -39,7 +39,7 @@ module Node : sig
end end
module Client : sig module Client : sig
module Blocks : LOG module Blocks : LOG
module Mining : LOG module Baking : LOG
module Endorsement : LOG module Endorsement : LOG
module Revelation : LOG module Revelation : LOG
module Denunciation : LOG module Denunciation : LOG

View File

@ -388,7 +388,7 @@ module Assert = struct
let wrong_delegate ~msg = let wrong_delegate ~msg =
Assert.contain_error ~msg ~f:begin ecoproto_error (function Assert.contain_error ~msg ~f:begin ecoproto_error (function
| Mining.Wrong_delegate _ -> true | Baking.Wrong_delegate _ -> true
| _ -> false) | _ -> false)
end end
@ -409,7 +409,7 @@ module Assert = struct
end end
module Mining = struct module Baking = struct
let mine block (contract: Account.t) operations = let mine block (contract: Account.t) operations =
let operations = List.map (fun op -> Client_node_rpcs.Blob op) operations in let operations = List.map (fun op -> Client_node_rpcs.Blob op) operations in
@ -433,7 +433,7 @@ module Mining = struct
let endorsement_reward block = let endorsement_reward block =
Client_proto_rpcs.Header.priority !rpc_config block >>=? fun prio -> Client_proto_rpcs.Header.priority !rpc_config block >>=? fun prio ->
Mining.endorsement_reward ~block_priority:prio >|= Baking.endorsement_reward ~block_priority:prio >|=
Environment.wrap_error >>|? Environment.wrap_error >>|?
Tez.to_cents Tez.to_cents

View File

@ -92,7 +92,7 @@ module Account : sig
end end
module Mining : sig module Baking : sig
val mine: val mine:
Client_node_rpcs.Blocks.block -> Client_node_rpcs.Blocks.block ->

View File

@ -19,27 +19,27 @@ let default_account =
let test_double_endorsement contract block = let test_double_endorsement contract block =
(* Double endorsement for the same level *) (* Double endorsement for the same level *)
Helpers.Mining.mine block contract [] >>=? fun b1 -> Helpers.Baking.mine block contract [] >>=? fun b1 ->
(* branch root *) (* branch root *)
Helpers.Mining.mine (`Hash b1) contract [] >>=? fun b2 -> Helpers.Baking.mine (`Hash b1) contract [] >>=? fun b2 ->
(* changing branch *) (* changing branch *)
Helpers.Mining.mine (`Hash b1) contract [] >>=? fun b2' -> Helpers.Baking.mine (`Hash b1) contract [] >>=? fun b2' ->
(* branch root *) (* branch root *)
Helpers.Endorse.endorse contract (`Hash b2) >>=? fun op -> Helpers.Endorse.endorse contract (`Hash b2) >>=? fun op ->
Helpers.Mining.mine (`Hash b2) contract [ op ] >>=? fun _b3 -> Helpers.Baking.mine (`Hash b2) contract [ op ] >>=? fun _b3 ->
Helpers.Endorse.endorse contract (`Hash b2') >>=? fun op -> Helpers.Endorse.endorse contract (`Hash b2') >>=? fun op ->
Helpers.Mining.mine (`Hash b2') contract [ op ] >>=? fun b3' -> Helpers.Baking.mine (`Hash b2') contract [ op ] >>=? fun b3' ->
Helpers.Endorse.endorse contract (`Hash b3') >>=? fun op -> Helpers.Endorse.endorse contract (`Hash b3') >>=? fun op ->
Helpers.Mining.mine (`Hash b3') contract [ op ] >>=? fun b4' -> Helpers.Baking.mine (`Hash b3') contract [ op ] >>=? fun b4' ->
(* TODO: Inject double endorsement op ! *) (* TODO: Inject double endorsement op ! *)
Helpers.Mining.mine (`Hash b4') contract [] Helpers.Baking.mine (`Hash b4') contract []
(* FIXME: Mining.Invalid_signature is unclassified *) (* FIXME: Baking.Invalid_signature is unclassified *)
let test_invalid_signature block = let test_invalid_signature block =
let public_key = let public_key =
Environment.Ed25519.Public_key.of_b58check_exn Environment.Ed25519.Public_key.of_b58check_exn
@ -50,7 +50,7 @@ let test_invalid_signature block =
DYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi" in DYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi" in
let account = let account =
Helpers.Account.create ~keys:(secret_key, public_key) "WRONG SIGNATURE" in Helpers.Account.create ~keys:(secret_key, public_key) "WRONG SIGNATURE" in
Helpers.Mining.mine block account [] >>= fun res -> Helpers.Baking.mine block account [] >>= fun res ->
Assert.generic_economic_error ~msg:__LOC__ res ; Assert.generic_economic_error ~msg:__LOC__ res ;
return () return ()
@ -64,34 +64,34 @@ let contain_tzerror ?(msg="") ~f t =
let test_wrong_delegate ~miner contract block = let test_wrong_delegate ~miner contract block =
begin begin
Helpers.Endorse.endorse ~slot:1 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:1 contract block >>=? fun op ->
Helpers.Mining.mine block miner [ op ] >>=? fun _ -> Helpers.Baking.mine block miner [ op ] >>=? fun _ ->
Helpers.Endorse.endorse ~slot:2 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:2 contract block >>=? fun op ->
Helpers.Mining.mine block miner [ op ] >>=? fun _ -> Helpers.Baking.mine block miner [ op ] >>=? fun _ ->
Helpers.Endorse.endorse ~slot:3 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:3 contract block >>=? fun op ->
Helpers.Mining.mine block miner [ op ] >>=? fun _ -> Helpers.Baking.mine block miner [ op ] >>=? fun _ ->
Helpers.Endorse.endorse ~slot:4 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:4 contract block >>=? fun op ->
Helpers.Mining.mine block miner [ op ] >>=? fun _ -> Helpers.Baking.mine block miner [ op ] >>=? fun _ ->
Helpers.Endorse.endorse ~slot:5 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:5 contract block >>=? fun op ->
Helpers.Mining.mine block miner [ op ] >>=? fun _ -> Helpers.Baking.mine block miner [ op ] >>=? fun _ ->
return () return ()
end >>= fun res -> end >>= fun res ->
Assert.failed_to_preapply ~msg:__LOC__ begin function Assert.failed_to_preapply ~msg:__LOC__ begin function
| Mining.Wrong_delegate _ -> true | Baking.Wrong_delegate _ -> true
| _ -> false | _ -> false
end res ; end res ;
Lwt.return_unit Lwt.return_unit
let test_invalid_endorsement_slot contract block = let test_invalid_endorsement_slot contract block =
Helpers.Endorse.endorse ~slot:~-1 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:~-1 contract block >>=? fun op ->
Helpers.Mining.mine block contract [ op ] >>= fun res -> Helpers.Baking.mine block contract [ op ] >>= fun res ->
Assert.failed_to_preapply ~msg:__LOC__ ~op:(Blob op) begin function Assert.failed_to_preapply ~msg:__LOC__ ~op:(Blob op) begin function
| Mining.Invalid_endorsement_slot _ -> true | Baking.Invalid_endorsement_slot _ -> true
| _ -> false | _ -> false
end res ; end res ;
Helpers.Endorse.endorse ~slot:16 contract block >>=? fun op -> Helpers.Endorse.endorse ~slot:16 contract block >>=? fun op ->
Helpers.Mining.mine block contract [ op ] >>= fun res -> Helpers.Baking.mine block contract [ op ] >>= fun res ->
Assert.failed_to_preapply ~msg:__LOC__ ~op:(Blob op) begin function Assert.failed_to_preapply ~msg:__LOC__ ~op:(Blob op) begin function
| Mining.Invalid_endorsement_slot _ -> true | Baking.Invalid_endorsement_slot _ -> true
| _ -> false | _ -> false
end res ; end res ;
return () return ()
@ -114,7 +114,7 @@ let test_endorsement_rewards block0 =
get_endorser_except [ b1 ] accounts >>=? fun (account0, slot0) -> get_endorser_except [ b1 ] accounts >>=? fun (account0, slot0) ->
Helpers.Account.balance ~block:block0 account0 >>=? fun balance0 -> Helpers.Account.balance ~block:block0 account0 >>=? fun balance0 ->
Helpers.Endorse.endorse ~slot:slot0 account0 block0 >>=? fun op -> Helpers.Endorse.endorse ~slot:slot0 account0 block0 >>=? fun op ->
Helpers.Mining.mine block0 b1 [ op ] >>=? fun hash1 -> Helpers.Baking.mine block0 b1 [ op ] >>=? fun hash1 ->
Helpers.display_level (`Hash hash1) >>=? fun () -> Helpers.display_level (`Hash hash1) >>=? fun () ->
Assert.balance_equal ~block:(`Hash hash1) ~msg:__LOC__ account0 Assert.balance_equal ~block:(`Hash hash1) ~msg:__LOC__ account0
(Int64.sub (Tez.to_cents balance0) bond) >>=? fun () -> (Int64.sub (Tez.to_cents balance0) bond) >>=? fun () ->
@ -125,31 +125,31 @@ let test_endorsement_rewards block0 =
get_endorser_except [ b1 ; account0 ] accounts >>=? fun (account1, slot1) -> get_endorser_except [ b1 ; account0 ] accounts >>=? fun (account1, slot1) ->
Helpers.Account.balance ~block:block1 account1 >>=? fun balance1 -> Helpers.Account.balance ~block:block1 account1 >>=? fun balance1 ->
Helpers.Endorse.endorse ~slot:slot1 account1 block1 >>=? fun op -> Helpers.Endorse.endorse ~slot:slot1 account1 block1 >>=? fun op ->
Helpers.Mining.mine block1 b1 [ op ] >>=? fun hash2 -> Helpers.Baking.mine block1 b1 [ op ] >>=? fun hash2 ->
Helpers.display_level (`Hash hash2) >>=? fun () -> Helpers.display_level (`Hash hash2) >>=? fun () ->
Assert.balance_equal ~block:(`Hash hash2) ~msg:__LOC__ account1 Assert.balance_equal ~block:(`Hash hash2) ~msg:__LOC__ account1
(Int64.sub (Tez.to_cents balance1) bond) >>=? fun () -> (Int64.sub (Tez.to_cents balance1) bond) >>=? fun () ->
(* Check rewards after one cycle for account0 *) (* Check rewards after one cycle for account0 *)
Helpers.Mining.mine (`Hash hash2) b1 [] >>=? fun hash3 -> Helpers.Baking.mine (`Hash hash2) b1 [] >>=? fun hash3 ->
Helpers.display_level (`Hash hash3) >>=? fun () -> Helpers.display_level (`Hash hash3) >>=? fun () ->
Helpers.Mining.mine (`Hash hash3) b1 [] >>=? fun hash4 -> Helpers.Baking.mine (`Hash hash3) b1 [] >>=? fun hash4 ->
Helpers.display_level (`Hash hash4) >>=? fun () -> Helpers.display_level (`Hash hash4) >>=? fun () ->
Helpers.Mining.mine (`Hash hash4) b1 [] >>=? fun hash5 -> Helpers.Baking.mine (`Hash hash4) b1 [] >>=? fun hash5 ->
Helpers.display_level (`Hash hash5) >>=? fun () -> Helpers.display_level (`Hash hash5) >>=? fun () ->
Helpers.Mining.endorsement_reward block1 >>=? fun rw0 -> Helpers.Baking.endorsement_reward block1 >>=? fun rw0 ->
Assert.balance_equal ~block:(`Hash hash5) ~msg:__LOC__ account0 Assert.balance_equal ~block:(`Hash hash5) ~msg:__LOC__ account0
(Int64.add (Tez.to_cents balance0) rw0) >>=? fun () -> (Int64.add (Tez.to_cents balance0) rw0) >>=? fun () ->
(* Check rewards after one cycle for account1 *) (* Check rewards after one cycle for account1 *)
Helpers.Mining.endorsement_reward (`Hash hash2) >>=? fun rw1 -> Helpers.Baking.endorsement_reward (`Hash hash2) >>=? fun rw1 ->
Assert.balance_equal ~block:(`Hash hash5) ~msg:__LOC__ account1 Assert.balance_equal ~block:(`Hash hash5) ~msg:__LOC__ account1
(Int64.add (Tez.to_cents balance1) rw1) >>=? fun () -> (Int64.add (Tez.to_cents balance1) rw1) >>=? fun () ->
(* #2 endorse and check reward only on the good chain *) (* #2 endorse and check reward only on the good chain *)
Helpers.Mining.mine (`Hash hash5) b1 []>>=? fun hash6a -> Helpers.Baking.mine (`Hash hash5) b1 []>>=? fun hash6a ->
Helpers.display_level (`Hash hash6a) >>=? fun () -> Helpers.display_level (`Hash hash6a) >>=? fun () ->
Helpers.Mining.mine (`Hash hash5) b1 [] >>=? fun hash6b -> Helpers.Baking.mine (`Hash hash5) b1 [] >>=? fun hash6b ->
Helpers.display_level (`Hash hash6b) >>=? fun () -> Helpers.display_level (`Hash hash6b) >>=? fun () ->
(* working on head *) (* working on head *)
@ -158,7 +158,7 @@ let test_endorsement_rewards block0 =
Helpers.Account.balance ~block:(`Hash hash6a) account3 >>=? fun balance3 -> Helpers.Account.balance ~block:(`Hash hash6a) account3 >>=? fun balance3 ->
Helpers.Endorse.endorse Helpers.Endorse.endorse
~slot:slot3 account3 (`Hash hash6a) >>=? fun ops -> ~slot:slot3 account3 (`Hash hash6a) >>=? fun ops ->
Helpers.Mining.mine (`Hash hash6a) b1 [ ops ] >>=? fun hash7a -> Helpers.Baking.mine (`Hash hash6a) b1 [ ops ] >>=? fun hash7a ->
Helpers.display_level (`Hash hash7a) >>=? fun () -> Helpers.display_level (`Hash hash7a) >>=? fun () ->
(* working on fork *) (* working on fork *)
@ -166,17 +166,17 @@ let test_endorsement_rewards block0 =
get_endorser_except [ b1 ] accounts >>=? fun (account4, slot4) -> get_endorser_except [ b1 ] accounts >>=? fun (account4, slot4) ->
Helpers.Account.balance ~block:(`Hash hash7a) account4 >>=? fun _balance4 -> Helpers.Account.balance ~block:(`Hash hash7a) account4 >>=? fun _balance4 ->
Helpers.Endorse.endorse ~slot:slot4 account4 (`Hash hash6b) >>=? fun ops -> Helpers.Endorse.endorse ~slot:slot4 account4 (`Hash hash6b) >>=? fun ops ->
Helpers.Mining.mine (`Hash hash6b) b1 [ ops ] >>=? fun _new_fork -> Helpers.Baking.mine (`Hash hash6b) b1 [ ops ] >>=? fun _new_fork ->
Helpers.display_level (`Hash _new_fork) >>=? fun () -> Helpers.display_level (`Hash _new_fork) >>=? fun () ->
Helpers.Account.balance ~block:(`Hash hash7a) account4 >>=? fun balance4 -> Helpers.Account.balance ~block:(`Hash hash7a) account4 >>=? fun balance4 ->
Helpers.Mining.mine (`Hash hash7a) b1 [] >>=? fun hash8a -> Helpers.Baking.mine (`Hash hash7a) b1 [] >>=? fun hash8a ->
Helpers.display_level (`Hash hash8a) >>=? fun () -> Helpers.display_level (`Hash hash8a) >>=? fun () ->
Helpers.Mining.mine (`Hash hash8a) b1 [] >>=? fun hash9a -> Helpers.Baking.mine (`Hash hash8a) b1 [] >>=? fun hash9a ->
Helpers.display_level (`Hash hash9a) >>=? fun () -> Helpers.display_level (`Hash hash9a) >>=? fun () ->
(* Check rewards after one cycle *) (* Check rewards after one cycle *)
Helpers.Mining.endorsement_reward (`Hash hash7a) >>=? fun reward -> Helpers.Baking.endorsement_reward (`Hash hash7a) >>=? fun reward ->
Assert.balance_equal ~block:(`Hash hash9a) ~msg:__LOC__ account3 Assert.balance_equal ~block:(`Hash hash9a) ~msg:__LOC__ account3
(Int64.add (Tez.to_cents balance3) reward) >>=? fun () -> (Int64.add (Tez.to_cents balance3) reward) >>=? fun () ->
@ -226,7 +226,7 @@ let run genesis =
(* Endorse with a wrong slot : -1 and max (16) *) (* Endorse with a wrong slot : -1 and max (16) *)
test_invalid_endorsement_slot b3 genesis >>=? fun () -> test_invalid_endorsement_slot b3 genesis >>=? fun () ->
(* FIXME: Mining.Invalid_signature is still unclassified *) (* FIXME: Baking.Invalid_signature is still unclassified *)
test_invalid_signature genesis >>=? fun _ -> test_invalid_signature genesis >>=? fun _ ->
(* FIXME: cannot inject double endorsement operation yet, but the (* FIXME: cannot inject double endorsement operation yet, but the

View File

@ -12,7 +12,7 @@ module Assert = Helpers.Assert
let run blkid ({ b1 ; b2 ; _ } : Helpers.Account.bootstrap_accounts) = let run blkid ({ b1 ; b2 ; _ } : Helpers.Account.bootstrap_accounts) =
Helpers.Mining.mine blkid b1 [] >>=? fun blkh -> Helpers.Baking.mine blkid b1 [] >>=? fun blkh ->
let foo = Helpers.Account.create "foo" in let foo = Helpers.Account.create "foo" in
(* Origination with amount = 0 tez *) (* Origination with amount = 0 tez *)

View File

@ -12,7 +12,7 @@ module Assert = Helpers.Assert
let run blkid ({ b1 ; b2 ; b3 ; _ } : Helpers.Account.bootstrap_accounts) = let run blkid ({ b1 ; b2 ; b3 ; _ } : Helpers.Account.bootstrap_accounts) =
Helpers.Mining.mine blkid b1 [] >>=? fun blkh -> Helpers.Baking.mine blkid b1 [] >>=? fun blkh ->
let foo = Helpers.Account.create "foo" in let foo = Helpers.Account.create "foo" in
let bar = Helpers.Account.create "bar" in let bar = Helpers.Account.create "bar" in

View File

@ -20,11 +20,11 @@ let print_level head =
let run_change_to_demo_proto block let run_change_to_demo_proto block
({ b1 ; b2 ; b3 ; b4 ; b5 } : Account.bootstrap_accounts) = ({ b1 ; b2 ; b3 ; b4 ; b5 } : Account.bootstrap_accounts) =
Mining.mine block b1 [] >>=? fun head -> Baking.mine block b1 [] >>=? fun head ->
Format.eprintf "Entering `Proposal` voting period@."; Format.eprintf "Entering `Proposal` voting period@.";
Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head) Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head)
Voting_period.Proposal >>=? fun () -> Voting_period.Proposal >>=? fun () ->
Mining.mine (`Hash head) b2 [] >>=? fun head -> Baking.mine (`Hash head) b2 [] >>=? fun head ->
(* 1. Propose the 'demo' protocol as b1 (during the Proposal period) *) (* 1. Propose the 'demo' protocol as b1 (during the Proposal period) *)
Protocol.proposals Protocol.proposals
@ -33,9 +33,9 @@ let run_change_to_demo_proto block
[demo_protocol] >>=? fun op -> [demo_protocol] >>=? fun op ->
(* Mine blocks to switch to next vote period (Testing_vote) *) (* Mine blocks to switch to next vote period (Testing_vote) *)
Mining.mine (`Hash head) b3 [op] >>=? fun head -> Baking.mine (`Hash head) b3 [op] >>=? fun head ->
Format.eprintf "Entering `Testing_vote` voting period@."; Format.eprintf "Entering `Testing_vote` voting period@.";
Mining.mine (`Hash head) b4 [] >>=? fun head -> Baking.mine (`Hash head) b4 [] >>=? fun head ->
Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head) Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head)
Voting_period.Testing_vote >>=? fun () -> Voting_period.Testing_vote >>=? fun () ->
@ -54,18 +54,18 @@ let run_change_to_demo_proto block
all_accounts >>=? fun operations -> all_accounts >>=? fun operations ->
(* Mine blocks to switch to next vote period (Testing) *) (* Mine blocks to switch to next vote period (Testing) *)
Mining.mine (`Hash head) b5 operations >>=? fun head -> Baking.mine (`Hash head) b5 operations >>=? fun head ->
Format.eprintf "Entering `Testing` voting period@."; Format.eprintf "Entering `Testing` voting period@.";
Mining.mine (`Hash head) b1 [] >>=? fun head -> Baking.mine (`Hash head) b1 [] >>=? fun head ->
Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head) Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head)
Voting_period.Testing >>=? fun () -> Voting_period.Testing >>=? fun () ->
(* 3. Test the proposed protocol *) (* 3. Test the proposed protocol *)
(* Mine blocks to switch to next vote period (Promote_vote) *) (* Mine blocks to switch to next vote period (Promote_vote) *)
Mining.mine (`Hash head) b2 [] >>=? fun head -> Baking.mine (`Hash head) b2 [] >>=? fun head ->
Format.eprintf "Entering `Promote_vote` voting period@."; Format.eprintf "Entering `Promote_vote` voting period@.";
Mining.mine (`Hash head) b3 [] >>=? fun head -> Baking.mine (`Hash head) b3 [] >>=? fun head ->
Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head) Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head)
Voting_period.Promotion_vote >>=? fun () -> Voting_period.Promotion_vote >>=? fun () ->
@ -75,8 +75,8 @@ let run_change_to_demo_proto block
(* Mine blocks to switch to end the vote cycle (back to Proposal) *) (* Mine blocks to switch to end the vote cycle (back to Proposal) *)
Format.eprintf "Switching to `demo` protocol@."; Format.eprintf "Switching to `demo` protocol@.";
Mining.mine (`Hash head) b4 operations >>=? fun head -> Baking.mine (`Hash head) b4 operations >>=? fun head ->
Mining.mine (`Hash head) b5 [] >>=? fun head -> Baking.mine (`Hash head) b5 [] >>=? fun head ->
Assert.check_protocol Assert.check_protocol
~msg:__LOC__ ~block:(`Hash head) demo_protocol >>=? fun () -> ~msg:__LOC__ ~block:(`Hash head) demo_protocol >>=? fun () ->

View File

@ -337,10 +337,10 @@ init_with_transfer $CONTRACT_PATH/transfer_to.tz $key2 Unit 1000 bootstrap1
assert_balance test_transfer_account1 "100.00 ꜩ" assert_balance test_transfer_account1 "100.00 ꜩ"
$client transfer 100 from bootstrap1 to transfer_to \ $client transfer 100 from bootstrap1 to transfer_to \
-arg "\"$(get_contract_addr test_transfer_account1)\"" -arg "\"$(get_contract_addr test_transfer_account1)\""
assert_balance test_transfer_account1 "200.00 ꜩ" # Why isn't this 200 ꜩ? Mining fee? assert_balance test_transfer_account1 "200.00 ꜩ" # Why isn't this 200 ꜩ? Baking fee?
$client transfer 100 from bootstrap1 to transfer_to \ $client transfer 100 from bootstrap1 to transfer_to \
-arg "\"$(get_contract_addr test_transfer_account2)\"" -arg "\"$(get_contract_addr test_transfer_account2)\""
assert_balance test_transfer_account2 "120.00 ꜩ" # Why isn't this 120 ꜩ? Mining fee? assert_balance test_transfer_account2 "120.00 ꜩ" # Why isn't this 120 ꜩ? Baking fee?
# Tests create_account # Tests create_account
init_with_transfer $CONTRACT_PATH/create_account.tz $key2 \ init_with_transfer $CONTRACT_PATH/create_account.tz $key2 \