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:
parent
c167d0eaae
commit
7d73605f5c
@ -106,6 +106,11 @@ module Commitment = struct
|
|||||||
include Commitment_storage
|
include Commitment_storage
|
||||||
end
|
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_first_block = Init_storage.prepare_first_block
|
||||||
let prepare = Init_storage.prepare
|
let prepare = Init_storage.prepare
|
||||||
|
|
||||||
|
@ -873,6 +873,13 @@ module Bootstrap : sig
|
|||||||
|
|
||||||
end
|
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:
|
val prepare_first_block:
|
||||||
Context.t ->
|
Context.t ->
|
||||||
level:Int32.t ->
|
level:Int32.t ->
|
||||||
|
@ -330,7 +330,7 @@ let () =
|
|||||||
open Apply_operation_result
|
open Apply_operation_result
|
||||||
|
|
||||||
let apply_consensus_operation_content ctxt
|
let apply_consensus_operation_content ctxt
|
||||||
pred_block block_priority operation = function
|
pred_block operation = function
|
||||||
| Endorsements { block ; level ; slots } ->
|
| Endorsements { block ; level ; slots } ->
|
||||||
begin
|
begin
|
||||||
match Level.pred ctxt (Level.current ctxt) with
|
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 delegate = Signature.Public_key.hash delegate in
|
||||||
let ctxt = Fitness.increase ~gap:(List.length slots) ctxt in
|
let ctxt = Fitness.increase ~gap:(List.length slots) ctxt in
|
||||||
Baking.freeze_endorsement_deposit ctxt delegate >>=? fun ctxt ->
|
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 ->
|
Baking.endorsement_reward ctxt ~block_priority >>=? fun reward ->
|
||||||
Delegate.freeze_rewards ctxt delegate reward >>=? fun ctxt ->
|
Delegate.freeze_rewards ctxt delegate reward >>=? fun ctxt ->
|
||||||
return (ctxt, Endorsements_result (delegate, slots))
|
return (ctxt, Endorsements_result (delegate, slots))
|
||||||
@ -538,7 +539,7 @@ let apply_manager_operations ctxt source ops =
|
|||||||
apply ctxt applied rest in
|
apply ctxt applied rest in
|
||||||
apply ctxt [] ops
|
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
|
match ops with
|
||||||
| Manager_operations { source ; fee ; counter ; operations ; gas_limit } ->
|
| Manager_operations { source ; fee ; counter ; operations ; gas_limit } ->
|
||||||
let revealed_public_keys =
|
let revealed_public_keys =
|
||||||
@ -575,7 +576,7 @@ let apply_sourced_operation ctxt pred_block block_prio operation ops =
|
|||||||
operation_results })
|
operation_results })
|
||||||
| Consensus_operation content ->
|
| Consensus_operation content ->
|
||||||
apply_consensus_operation_content ctxt
|
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)
|
return (ctxt, Consensus_operation_result result)
|
||||||
| Amendment_operation { source ; operation = content } ->
|
| Amendment_operation { source ; operation = content } ->
|
||||||
Roll.delegate_pubkey ctxt source >>=? fun delegate ->
|
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 ->
|
Contract.(credit ctxt (implicit_contract (Signature.Ed25519 pkh)) amount) >>=? fun ctxt ->
|
||||||
return (ctxt, Activation_result [(* FIXME *)])
|
return (ctxt, Activation_result [(* FIXME *)])
|
||||||
|
|
||||||
let apply_operation
|
let apply_operation ctxt pred_block hash operation =
|
||||||
ctxt pred_block block_prio hash operation =
|
|
||||||
let ctxt = Contract.init_origination_nonce ctxt hash in
|
let ctxt = Contract.init_origination_nonce ctxt hash in
|
||||||
begin match operation.contents with
|
begin match operation.contents with
|
||||||
| Anonymous_operations ops ->
|
| Anonymous_operations ops ->
|
||||||
@ -710,7 +710,7 @@ let apply_operation
|
|||||||
>>=? fun (ctxt, results) ->
|
>>=? fun (ctxt, results) ->
|
||||||
return (ctxt, Anonymous_operations_result (List.rev results))
|
return (ctxt, Anonymous_operations_result (List.rev results))
|
||||||
| Sourced_operation ops ->
|
| Sourced_operation ops ->
|
||||||
apply_sourced_operation ctxt pred_block block_prio operation ops
|
apply_sourced_operation ctxt pred_block operation ops
|
||||||
>>=? fun (ctxt, result) ->
|
>>=? fun (ctxt, result) ->
|
||||||
return (ctxt, Sourced_operation_result result)
|
return (ctxt, Sourced_operation_result result)
|
||||||
end >>=? fun (ctxt, result) ->
|
end >>=? fun (ctxt, result) ->
|
||||||
@ -791,6 +791,8 @@ let finalize_application ctxt protocol_data delegate =
|
|||||||
Nonce.record_hash ctxt
|
Nonce.record_hash ctxt
|
||||||
{ nonce_hash ; delegate ; rewards ; fees }
|
{ nonce_hash ; delegate ; rewards ; fees }
|
||||||
end >>=? fun ctxt ->
|
end >>=? fun ctxt ->
|
||||||
|
Alpha_context.Global.set_last_block_priority
|
||||||
|
ctxt protocol_data.priority >>=? fun ctxt ->
|
||||||
(* end of cycle *)
|
(* end of cycle *)
|
||||||
may_snapshot_roll ctxt >>=? fun ctxt ->
|
may_snapshot_roll ctxt >>=? fun ctxt ->
|
||||||
may_start_new_cycle ctxt >>=? fun ctxt ->
|
may_start_new_cycle ctxt >>=? fun ctxt ->
|
||||||
|
@ -141,8 +141,7 @@ module I = struct
|
|||||||
| None -> Error_monad.fail Operation.Cannot_parse_operation
|
| None -> Error_monad.fail Operation.Cannot_parse_operation
|
||||||
| Some (shell, contents) ->
|
| Some (shell, contents) ->
|
||||||
let operation = { shell ; contents ; signature } in
|
let operation = { shell ; contents ; signature } in
|
||||||
let block_prio = 0 in
|
Apply.apply_operation ctxt pred_block hash operation
|
||||||
Apply.apply_operation ctxt pred_block block_prio hash operation
|
|
||||||
>>=? fun (_, result) -> return result
|
>>=? fun (_, result) -> return result
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -21,6 +21,7 @@ let prepare_first_block ctxt ~level ~timestamp ~fitness =
|
|||||||
param.bootstrap_accounts >>=? fun ctxt ->
|
param.bootstrap_accounts >>=? fun ctxt ->
|
||||||
Roll_storage.init_first_cycles ctxt >>=? fun ctxt ->
|
Roll_storage.init_first_cycles ctxt >>=? fun ctxt ->
|
||||||
Vote_storage.init ctxt >>=? fun ctxt ->
|
Vote_storage.init ctxt >>=? fun ctxt ->
|
||||||
|
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
|
||||||
return ctxt
|
return ctxt
|
||||||
|
|
||||||
let prepare ctxt ~level ~timestamp ~fitness =
|
let prepare ctxt ~level ~timestamp ~fitness =
|
||||||
|
@ -103,19 +103,15 @@ let begin_construction
|
|||||||
return { mode ; ctxt ; op_count = 0 ; deposit }
|
return { mode ; ctxt ; op_count = 0 ; deposit }
|
||||||
|
|
||||||
let apply_operation ({ mode ; ctxt ; op_count ; _ } as data) operation =
|
let apply_operation ({ mode ; ctxt ; op_count ; _ } as data) operation =
|
||||||
let pred_block, block_prio =
|
let predecessor =
|
||||||
match mode with
|
match mode with
|
||||||
| Partial_construction { predecessor } ->
|
| Partial_construction { predecessor }
|
||||||
predecessor, 0
|
|
||||||
| Application
|
| Application
|
||||||
{ block_header = { shell = { predecessor ; _ } ;
|
{ block_header = { shell = { predecessor ; _ } ; _ } ; _ }
|
||||||
protocol_data ; _ } ; _ }
|
| Full_construction { predecessor ; _ } ->
|
||||||
| Full_construction { predecessor ; protocol_data ; _ } ->
|
predecessor in
|
||||||
predecessor,
|
Apply.apply_operation ctxt predecessor
|
||||||
protocol_data.priority in
|
(Alpha_context.Operation.hash operation) operation >>=? fun (ctxt, _) ->
|
||||||
Apply.apply_operation ctxt pred_block block_prio
|
|
||||||
(Alpha_context.Operation.hash operation) operation
|
|
||||||
>>=? fun (ctxt, _) ->
|
|
||||||
let op_count = op_count + 1 in
|
let op_count = op_count + 1 in
|
||||||
return { data with ctxt ; op_count }
|
return { data with ctxt ; op_count }
|
||||||
|
|
||||||
|
@ -39,6 +39,12 @@ module String_index = struct
|
|||||||
| [] | _ :: _ :: _ -> None
|
| [] | _ :: _ :: _ -> None
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Last_block_priority =
|
||||||
|
Make_single_data_storage
|
||||||
|
(Raw_context)
|
||||||
|
(struct let name = ["last_block_priority"] end)
|
||||||
|
(Make_value(Int))
|
||||||
|
|
||||||
(** Contracts handling *)
|
(** Contracts handling *)
|
||||||
|
|
||||||
module Contract = struct
|
module Contract = struct
|
||||||
|
@ -20,6 +20,12 @@
|
|||||||
|
|
||||||
open Storage_sigs
|
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
|
module Roll : sig
|
||||||
|
|
||||||
(** Storage from this submodule must only be accessed through the
|
(** Storage from this submodule must only be accessed through the
|
||||||
|
@ -40,7 +40,6 @@ let operation
|
|||||||
Proto_alpha.Apply.apply_operation
|
Proto_alpha.Apply.apply_operation
|
||||||
tc
|
tc
|
||||||
pred_block_hash
|
pred_block_hash
|
||||||
0
|
|
||||||
hash
|
hash
|
||||||
operation
|
operation
|
||||||
>>=? bind_result
|
>>=? bind_result
|
||||||
|
Loading…
Reference in New Issue
Block a user