Alpha: fix endorsement rewards

It should be computed with the priority of the endorsed blocks,
not with the priority of the block where it is included.
This commit is contained in:
Grégoire Henry 2018-04-20 23:53:40 +02:00
parent c167d0eaae
commit 7d73605f5c
9 changed files with 41 additions and 20 deletions

View File

@ -106,6 +106,11 @@ module Commitment = struct
include Commitment_storage
end
module Global = struct
let get_last_block_priority = Storage.Last_block_priority.get
let set_last_block_priority = Storage.Last_block_priority.set
end
let prepare_first_block = Init_storage.prepare_first_block
let prepare = Init_storage.prepare

View File

@ -873,6 +873,13 @@ module Bootstrap : sig
end
module Global : sig
val get_last_block_priority: context -> int tzresult Lwt.t
val set_last_block_priority: context -> int -> context tzresult Lwt.t
end
val prepare_first_block:
Context.t ->
level:Int32.t ->

View File

@ -330,7 +330,7 @@ let () =
open Apply_operation_result
let apply_consensus_operation_content ctxt
pred_block block_priority operation = function
pred_block operation = function
| Endorsements { block ; level ; slots } ->
begin
match Level.pred ctxt (Level.current ctxt) with
@ -354,6 +354,7 @@ let apply_consensus_operation_content ctxt
let delegate = Signature.Public_key.hash delegate in
let ctxt = Fitness.increase ~gap:(List.length slots) ctxt in
Baking.freeze_endorsement_deposit ctxt delegate >>=? fun ctxt ->
Global.get_last_block_priority ctxt >>=? fun block_priority ->
Baking.endorsement_reward ctxt ~block_priority >>=? fun reward ->
Delegate.freeze_rewards ctxt delegate reward >>=? fun ctxt ->
return (ctxt, Endorsements_result (delegate, slots))
@ -538,7 +539,7 @@ let apply_manager_operations ctxt source ops =
apply ctxt applied rest in
apply ctxt [] ops
let apply_sourced_operation ctxt pred_block block_prio operation ops =
let apply_sourced_operation ctxt pred_block operation ops =
match ops with
| Manager_operations { source ; fee ; counter ; operations ; gas_limit } ->
let revealed_public_keys =
@ -575,7 +576,7 @@ let apply_sourced_operation ctxt pred_block block_prio operation ops =
operation_results })
| Consensus_operation content ->
apply_consensus_operation_content ctxt
pred_block block_prio operation content >>=? fun (ctxt, result) ->
pred_block operation content >>=? fun (ctxt, result) ->
return (ctxt, Consensus_operation_result result)
| Amendment_operation { source ; operation = content } ->
Roll.delegate_pubkey ctxt source >>=? fun delegate ->
@ -697,8 +698,7 @@ let apply_anonymous_operation ctxt kind =
Contract.(credit ctxt (implicit_contract (Signature.Ed25519 pkh)) amount) >>=? fun ctxt ->
return (ctxt, Activation_result [(* FIXME *)])
let apply_operation
ctxt pred_block block_prio hash operation =
let apply_operation ctxt pred_block hash operation =
let ctxt = Contract.init_origination_nonce ctxt hash in
begin match operation.contents with
| Anonymous_operations ops ->
@ -710,7 +710,7 @@ let apply_operation
>>=? fun (ctxt, results) ->
return (ctxt, Anonymous_operations_result (List.rev results))
| Sourced_operation ops ->
apply_sourced_operation ctxt pred_block block_prio operation ops
apply_sourced_operation ctxt pred_block operation ops
>>=? fun (ctxt, result) ->
return (ctxt, Sourced_operation_result result)
end >>=? fun (ctxt, result) ->
@ -791,6 +791,8 @@ let finalize_application ctxt protocol_data delegate =
Nonce.record_hash ctxt
{ nonce_hash ; delegate ; rewards ; fees }
end >>=? fun ctxt ->
Alpha_context.Global.set_last_block_priority
ctxt protocol_data.priority >>=? fun ctxt ->
(* end of cycle *)
may_snapshot_roll ctxt >>=? fun ctxt ->
may_start_new_cycle ctxt >>=? fun ctxt ->

View File

@ -141,8 +141,7 @@ module I = struct
| None -> Error_monad.fail Operation.Cannot_parse_operation
| Some (shell, contents) ->
let operation = { shell ; contents ; signature } in
let block_prio = 0 in
Apply.apply_operation ctxt pred_block block_prio hash operation
Apply.apply_operation ctxt pred_block hash operation
>>=? fun (_, result) -> return result
end

View File

@ -21,6 +21,7 @@ let prepare_first_block ctxt ~level ~timestamp ~fitness =
param.bootstrap_accounts >>=? fun ctxt ->
Roll_storage.init_first_cycles ctxt >>=? fun ctxt ->
Vote_storage.init ctxt >>=? fun ctxt ->
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
return ctxt
let prepare ctxt ~level ~timestamp ~fitness =

View File

@ -103,19 +103,15 @@ let begin_construction
return { mode ; ctxt ; op_count = 0 ; deposit }
let apply_operation ({ mode ; ctxt ; op_count ; _ } as data) operation =
let pred_block, block_prio =
let predecessor =
match mode with
| Partial_construction { predecessor } ->
predecessor, 0
| Partial_construction { predecessor }
| Application
{ block_header = { shell = { predecessor ; _ } ;
protocol_data ; _ } ; _ }
| Full_construction { predecessor ; protocol_data ; _ } ->
predecessor,
protocol_data.priority in
Apply.apply_operation ctxt pred_block block_prio
(Alpha_context.Operation.hash operation) operation
>>=? fun (ctxt, _) ->
{ block_header = { shell = { predecessor ; _ } ; _ } ; _ }
| Full_construction { predecessor ; _ } ->
predecessor in
Apply.apply_operation ctxt predecessor
(Alpha_context.Operation.hash operation) operation >>=? fun (ctxt, _) ->
let op_count = op_count + 1 in
return { data with ctxt ; op_count }

View File

@ -39,6 +39,12 @@ module String_index = struct
| [] | _ :: _ :: _ -> None
end
module Last_block_priority =
Make_single_data_storage
(Raw_context)
(struct let name = ["last_block_priority"] end)
(Make_value(Int))
(** Contracts handling *)
module Contract = struct

View File

@ -20,6 +20,12 @@
open Storage_sigs
module Last_block_priority : sig
val get : Raw_context.t -> int tzresult Lwt.t
val set : Raw_context.t -> int -> Raw_context.t tzresult Lwt.t
val init : Raw_context.t -> int -> Raw_context.t tzresult Lwt.t
end
module Roll : sig
(** Storage from this submodule must only be accessed through the

View File

@ -40,7 +40,6 @@ let operation
Proto_alpha.Apply.apply_operation
tc
pred_block_hash
0
hash
operation
>>=? bind_result