Alpha/Baker: dissociate overflowing ops from the set of wished operations

This commit is contained in:
Vincent Botbol 2018-10-03 10:36:35 +02:00 committed by Grégoire Henry
parent 8490e01b07
commit d93d2a9b65
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2

View File

@ -240,12 +240,14 @@ let trim_manager_operations ~max_size ~hard_gas_limit_per_block manager_operatio
(* We classify operations, sort managers operation by interest and add bad ones at the end *) (* We classify operations, sort managers operation by interest and add bad ones at the end *)
(* Hypothesis : we suppose that the received manager operations have a valid gas_limit *) (* Hypothesis : we suppose that the received manager operations have a valid gas_limit *)
(** [classify_operations] classify the operation in 5 lists indexed as such : (** [classify_operations] classify the operation in 4 lists indexed as such :
- 0 -> Endorsements - 0 -> Endorsements
- 1 -> Votes and proposals - 1 -> Votes and proposals
- 2 -> Anonymous operations - 2 -> Anonymous operations
- 3 -> High-priority manager operations - 3 -> High-priority manager operations.
- 4 -> Low-priority manager operations *) Returns two list :
- A desired set of operations to be included
- Potentially overflowing operations *)
let classify_operations let classify_operations
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
~block ~block
@ -261,7 +263,7 @@ let classify_operations
) ops ) ops
in in
let validation_passes_len = List.length Proto_alpha.Main.validation_passes in let validation_passes_len = List.length Proto_alpha.Main.validation_passes in
let t = Array.make (validation_passes_len + 1) [] in let t = Array.make validation_passes_len [] in
List.iter List.iter
(fun (op: Proto_alpha.operation) -> (fun (op: Proto_alpha.operation) ->
List.iter List.iter
@ -269,7 +271,6 @@ let classify_operations
(Main.acceptable_passes op)) (Main.acceptable_passes op))
ops ; ops ;
let t = Array.map List.rev t in let t = Array.map List.rev t in
(* Retrieve the optimist maximum paying manager operations *) (* Retrieve the optimist maximum paying manager operations *)
let manager_operations = t.(managers_index) in let manager_operations = t.(managers_index) in
let { Alpha_environment.Updater.max_size } = let { Alpha_environment.Updater.max_size } =
@ -280,8 +281,7 @@ let classify_operations
trim_manager_operations ~max_size ~hard_gas_limit_per_block (List.map fst ordered_operations) trim_manager_operations ~max_size ~hard_gas_limit_per_block (List.map fst ordered_operations)
>>=? fun (desired_manager_operations, overflowing_manager_operations) -> >>=? fun (desired_manager_operations, overflowing_manager_operations) ->
t.(managers_index) <- desired_manager_operations ; t.(managers_index) <- desired_manager_operations ;
t.(validation_passes_len) <- overflowing_manager_operations ; return ((Array.to_list t), overflowing_manager_operations)
return (Array.to_list t)
let parse (op : Operation.raw) : Operation.packed = let parse (op : Operation.raw) : Operation.packed =
let protocol_data = let protocol_data =
@ -401,7 +401,7 @@ let filter_and_apply_operations
block_info block_info
~timestamp ~timestamp
?protocol_data ?protocol_data
(operations : packed_operation list list) = ((operations : packed_operation list list), overflowing_operations) =
let open Client_baking_simulator in let open Client_baking_simulator in
lwt_debug Tag.DSL.(fun f -> lwt_debug Tag.DSL.(fun f ->
f "Starting client-side validation %a" f "Starting client-side validation %a"
@ -424,11 +424,6 @@ let filter_and_apply_operations
let votes = List.nth operations votes_index in let votes = List.nth operations votes_index in
let anonymous = List.nth operations anonymous_index in let anonymous = List.nth operations anonymous_index in
let managers = List.nth operations managers_index in let managers = List.nth operations managers_index in
let bad_managers =
if List.length operations > managers_index + 1 then
List.nth operations (managers_index + 1)
else []
in
let validate_operation inc op = let validate_operation inc op =
add_operation inc op >>= function add_operation inc op >>= function
| Error errs -> | Error errs ->
@ -461,8 +456,8 @@ let filter_and_apply_operations
filter_valid_operations inc anonymous >>=? fun (inc, anonymous) -> filter_valid_operations inc anonymous >>=? fun (inc, anonymous) ->
(* Retrieve the correct index order *) (* Retrieve the correct index order *)
let managers = List.sort Proto_alpha.compare_operations managers in let managers = List.sort Proto_alpha.compare_operations managers in
let bad_managers = List.sort Proto_alpha.compare_operations bad_managers in let overflowing_operations = List.sort Proto_alpha.compare_operations overflowing_operations in
filter_valid_operations inc (managers @ bad_managers) >>=? fun (inc, managers) -> filter_valid_operations inc (managers @ overflowing_operations) >>=? fun (inc, managers) ->
(* Gives a chance to the endorser to fund their deposit in the current block *) (* Gives a chance to the endorser to fund their deposit in the current block *)
filter_map_s (is_valid_endorsement inc) endorsements >>=? fun endorsements -> filter_map_s (is_valid_endorsement inc) endorsements >>=? fun endorsements ->
finalize_construction inc >>=? fun _ -> finalize_construction inc >>=? fun _ ->
@ -554,7 +549,8 @@ let forge_block
let protocol_data = forge_faked_protocol_data ~priority ~seed_nonce_hash in let protocol_data = forge_faked_protocol_data ~priority ~seed_nonce_hash in
Alpha_services.Constants.all cctxt (`Main, block) >>=? Alpha_services.Constants.all cctxt (`Main, block) >>=?
fun Constants.{ parametric = { hard_gas_limit_per_block ; endorsers_per_block } } -> fun Constants.{ parametric = { hard_gas_limit_per_block ; endorsers_per_block } } ->
classify_operations cctxt ~hard_gas_limit_per_block ~block:block ~fee_threshold operations_arg >>=? fun operations -> classify_operations cctxt ~hard_gas_limit_per_block ~block:block ~fee_threshold operations_arg
>>=? fun (operations, overflowing_ops) ->
(* Ensure that we retain operations up to the quota *) (* Ensure that we retain operations up to the quota *)
let quota : Alpha_environment.Updater.quota list = Main.validation_passes in let quota : Alpha_environment.Updater.quota list = Main.validation_passes in
let endorsements = List.sub let endorsements = List.sub
@ -603,7 +599,7 @@ let forge_block
max_waiting_time = 0 ; max_waiting_time = 0 ;
fee_threshold = Tez.zero ; fee_threshold = Tez.zero ;
} in } in
filter_and_apply_operations ~timestamp ~protocol_data state bi operations filter_and_apply_operations ~timestamp ~protocol_data state bi (operations, overflowing_ops)
>>=? fun (final_context, validation_result, operations) -> >>=? fun (final_context, validation_result, operations) ->
finalize_block_header final_context ~timestamp validation_result operations >>=? fun shell_header -> finalize_block_header final_context ~timestamp validation_result operations >>=? fun shell_header ->
return (shell_header, List.map (List.map forge) operations) return (shell_header, List.map (List.map forge) operations)
@ -756,8 +752,8 @@ let build_block
| Some operations -> | Some operations ->
tzforce state.constants >>=? fun Constants.{ parametric = { hard_gas_limit_per_block } } -> tzforce state.constants >>=? fun Constants.{ parametric = { hard_gas_limit_per_block } } ->
classify_operations cctxt classify_operations cctxt
~hard_gas_limit_per_block ~fee_threshold:state.fee_threshold ~block operations >>=? fun operations -> ~hard_gas_limit_per_block ~fee_threshold:state.fee_threshold ~block operations
>>=? fun (operations, overflowing_ops) ->
let next_version = let next_version =
match Tezos_base.Block_header.get_forced_protocol_upgrade ~level:(Raw_level.to_int32 next_level.Level.level) with match Tezos_base.Block_header.get_forced_protocol_upgrade ~level:(Raw_level.to_int32 next_level.Level.level) with
| None -> bi.next_protocol | None -> bi.next_protocol
@ -766,12 +762,13 @@ let build_block
if Protocol_hash.(Proto_alpha.hash <> next_version) then if Protocol_hash.(Proto_alpha.hash <> next_version) then
(* Let the shell validate this *) (* Let the shell validate this *)
shell_prevalidation cctxt ~chain ~block seed_nonce_hash shell_prevalidation cctxt ~chain ~block seed_nonce_hash
(List.sub operations 4) slot operations slot
else else
let protocol_data = forge_faked_protocol_data ~priority ~seed_nonce_hash in let protocol_data = forge_faked_protocol_data ~priority ~seed_nonce_hash in
filter_and_apply_operations ~timestamp ~protocol_data state bi operations >>= function filter_and_apply_operations ~timestamp ~protocol_data state bi (operations, overflowing_ops)
>>= function
| Error errs -> | Error errs ->
lwt_log_info Tag.DSL.(fun f -> lwt_log_error Tag.DSL.(fun f ->
f "Client-side validation: error while filtering invalid operations :@\n@[<v 4>%a@]" f "Client-side validation: error while filtering invalid operations :@\n@[<v 4>%a@]"
-% t event "client_side_validation_error" -% t event "client_side_validation_error"
-% a errs_tag errs) >>= fun () -> -% a errs_tag errs) >>= fun () ->
@ -779,7 +776,7 @@ let build_block
f "Building a block using shell validation" f "Building a block using shell validation"
-% t event "shell_prevalidation_notice") >>= fun () -> -% t event "shell_prevalidation_notice") >>= fun () ->
shell_prevalidation cctxt ~chain ~block seed_nonce_hash shell_prevalidation cctxt ~chain ~block seed_nonce_hash
(List.sub operations 4) slot operations slot
| Ok (final_context, validation_result, operations) -> | Ok (final_context, validation_result, operations) ->
lwt_debug Tag.DSL.(fun f -> lwt_debug Tag.DSL.(fun f ->
f "Try forging locally the block header for %a (slot %d) for %s (%a)" f "Try forging locally the block header for %a (slot %d) for %s (%a)"