Alpha/Baker: filter out outdated operations

This commit is contained in:
Vincent Botbol 2018-06-30 04:21:49 +02:00 committed by Benjamin Canou
parent c479c65cdf
commit fbefa3940d

View File

@ -212,7 +212,20 @@ 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 *)
let classify_operations ~hard_gas_limit_per_block ?threshold (ops: Proto_alpha.operation list) = let classify_operations
(cctxt : #Proto_alpha.full)
?threshold
~block
~hard_gas_limit_per_block
(ops: Proto_alpha.operation list) =
Alpha_block_services.live_blocks cctxt ~chain:`Main ~block ()
>>=? fun live_blocks ->
(* Remove operations that are too old for the mempool *)
let ops =
List.filter (fun { shell = { branch } } ->
Block_hash.Set.mem branch live_blocks
) ops
in
let t = Array.make (List.length Proto_alpha.Main.validation_passes) [] in let t = Array.make (List.length Proto_alpha.Main.validation_passes) [] in
List.iter List.iter
(fun (op: Proto_alpha.operation) -> (fun (op: Proto_alpha.operation) ->
@ -357,7 +370,7 @@ let forge_block cctxt ?(chain = `Main) 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 ~hard_gas_limit_per_block ?threshold operations_arg >>=? fun operations -> classify_operations cctxt ~hard_gas_limit_per_block ~block:block ?threshold operations_arg >>=? fun operations ->
(* 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
@ -754,7 +767,7 @@ let bake_slot
else else
None in None in
tzforce state.constants >>=? fun Constants.{ parametric = { hard_gas_limit_per_block } } -> tzforce state.constants >>=? fun Constants.{ parametric = { hard_gas_limit_per_block } } ->
classify_operations ?threshold ~hard_gas_limit_per_block operations >>=? fun operations -> classify_operations cctxt ?threshold ~hard_gas_limit_per_block ~block operations >>=? fun operations ->
(* Don't load an alpha context if the chain is still in genesis *) (* Don't load an alpha context if the chain is still in genesis *)
if Protocol_hash.(Proto_alpha.hash <> bi.next_protocol) then if Protocol_hash.(Proto_alpha.hash <> bi.next_protocol) then
(* Delegate validation to shell *) (* Delegate validation to shell *)