Alpha/Baker: ensure that anonymous operations do not overflow in the block
This commit is contained in:
parent
1368eed80c
commit
8ff740c8ee
@ -171,7 +171,12 @@ let sort_manager_operations
|
|||||||
return
|
return
|
||||||
(List.sort (fun (_, (_, _, w)) (_, (_, _, w')) -> Q.compare w' w) operations)
|
(List.sort (fun (_, (_, _, w)) (_, (_, _, w')) -> Q.compare w' w) operations)
|
||||||
|
|
||||||
let retain_operations_up_to_quota operations max_quota =
|
let retain_operations_up_to_quota operations quota =
|
||||||
|
let { T.max_op ; max_size } = quota in
|
||||||
|
let operations = match max_op with
|
||||||
|
| Some n -> List.sub operations n
|
||||||
|
| None -> operations
|
||||||
|
in
|
||||||
let exception Full of packed_operation list in
|
let exception Full of packed_operation list in
|
||||||
let operations = try
|
let operations = try
|
||||||
List.fold_left (fun (ops, size) op ->
|
List.fold_left (fun (ops, size) op ->
|
||||||
@ -179,7 +184,7 @@ let retain_operations_up_to_quota operations max_quota =
|
|||||||
Data_encoding.Binary.length Alpha_context.Operation.encoding op
|
Data_encoding.Binary.length Alpha_context.Operation.encoding op
|
||||||
in
|
in
|
||||||
let new_size = size + operation_size in
|
let new_size = size + operation_size in
|
||||||
if new_size > max_quota then
|
if new_size > max_size then
|
||||||
raise (Full ops)
|
raise (Full ops)
|
||||||
else
|
else
|
||||||
(op :: ops, new_size)
|
(op :: ops, new_size)
|
||||||
@ -360,11 +365,11 @@ let forge_block cctxt ?(chain = `Main) block
|
|||||||
endorsers_per_block in
|
endorsers_per_block in
|
||||||
let votes = retain_operations_up_to_quota
|
let votes = retain_operations_up_to_quota
|
||||||
(List.nth operations votes_index)
|
(List.nth operations votes_index)
|
||||||
(List.nth quota votes_index).max_size in
|
(List.nth quota votes_index) in
|
||||||
let anonymous =
|
let anonymous =
|
||||||
retain_operations_up_to_quota
|
retain_operations_up_to_quota
|
||||||
(List.nth operations anonymous_index)
|
(List.nth operations anonymous_index)
|
||||||
(List.nth quota anonymous_index).max_size in
|
(List.nth quota anonymous_index) in
|
||||||
(* Size/Gas check already occured in classify operations *)
|
(* Size/Gas check already occured in classify operations *)
|
||||||
let managers = List.nth operations managers_index in
|
let managers = List.nth operations managers_index in
|
||||||
let operations = [ endorsements ; votes ; anonymous ; managers ] in
|
let operations = [ endorsements ; votes ; anonymous ; managers ] in
|
||||||
@ -588,9 +593,7 @@ let filter_and_apply_operations
|
|||||||
state.index <- index ;
|
state.index <- index ;
|
||||||
return inc
|
return inc
|
||||||
end >>=? fun initial_inc ->
|
end >>=? fun initial_inc ->
|
||||||
let endorsements = List.nth operations endorsements_index
|
let endorsements = List.nth operations endorsements_index in
|
||||||
|
|
||||||
in
|
|
||||||
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
|
||||||
@ -645,11 +648,11 @@ let filter_and_apply_operations
|
|||||||
let votes =
|
let votes =
|
||||||
retain_operations_up_to_quota
|
retain_operations_up_to_quota
|
||||||
(List.rev votes)
|
(List.rev votes)
|
||||||
(List.nth quota votes_index).max_size in
|
(List.nth quota votes_index) in
|
||||||
let anonymous =
|
let anonymous =
|
||||||
retain_operations_up_to_quota
|
retain_operations_up_to_quota
|
||||||
(List.rev anonymous)
|
(List.rev anonymous)
|
||||||
(List.nth quota anonymous_index).max_size in
|
(List.nth quota anonymous_index) in
|
||||||
trim_manager_operations ~max_size:(List.nth quota managers_index).max_size
|
trim_manager_operations ~max_size:(List.nth quota managers_index).max_size
|
||||||
~hard_gas_limit_per_block managers >>=? fun (accepted_managers, _overflowing_managers) ->
|
~hard_gas_limit_per_block managers >>=? fun (accepted_managers, _overflowing_managers) ->
|
||||||
(* Retrieve the correct index order *)
|
(* Retrieve the correct index order *)
|
||||||
|
Loading…
Reference in New Issue
Block a user