Validator: always log invalid block
This commit is contained in:
parent
471006b2dd
commit
8f30934220
@ -457,7 +457,6 @@ let rec worker_loop bv =
|
|||||||
| Request_validation { net_db ; notify_new_block ; canceler ;
|
| Request_validation { net_db ; notify_new_block ; canceler ;
|
||||||
peer ; hash ; header ; operations } ->
|
peer ; hash ; header ; operations } ->
|
||||||
let net_state = Distributed_db.net_state net_db in
|
let net_state = Distributed_db.net_state net_db in
|
||||||
State.Block.known_invalid net_state hash >>= fun invalid ->
|
|
||||||
State.Block.read_opt net_state hash >>= function
|
State.Block.read_opt net_state hash >>= function
|
||||||
| Some block ->
|
| Some block ->
|
||||||
lwt_debug "previously validated block %a (after pipe)"
|
lwt_debug "previously validated block %a (after pipe)"
|
||||||
@ -468,54 +467,59 @@ let rec worker_loop bv =
|
|||||||
block ;
|
block ;
|
||||||
may_wakeup (Ok block) ;
|
may_wakeup (Ok block) ;
|
||||||
return ()
|
return ()
|
||||||
| None when invalid ->
|
|
||||||
may_wakeup (Error [(* TODO commit error and read back*)]) ;
|
|
||||||
return ()
|
|
||||||
| None ->
|
| None ->
|
||||||
begin
|
State.Block.read_invalid net_state hash >>= function
|
||||||
lwt_debug "validating block %a"
|
| Some { errors } ->
|
||||||
Block_hash.pp_short hash >>= fun () ->
|
may_wakeup (Error errors) ;
|
||||||
State.Block.read
|
return ()
|
||||||
net_state header.shell.predecessor >>=? fun pred ->
|
| None ->
|
||||||
get_proto pred hash >>=? fun proto ->
|
begin
|
||||||
(* TODO also protect with [bv.canceler]. *)
|
lwt_debug "validating block %a"
|
||||||
Lwt_utils.protect ?canceler begin fun () ->
|
Block_hash.pp_short hash >>= fun () ->
|
||||||
apply_block
|
State.Block.read
|
||||||
(Distributed_db.net_state net_db)
|
net_state header.shell.predecessor >>=? fun pred ->
|
||||||
pred proto hash header operations
|
get_proto pred hash >>=? fun proto ->
|
||||||
end
|
(* TODO also protect with [bv.canceler]. *)
|
||||||
end >>= function
|
Lwt_utils.protect ?canceler begin fun () ->
|
||||||
| Ok result -> begin
|
apply_block
|
||||||
lwt_log_info "validated block %a"
|
(Distributed_db.net_state net_db)
|
||||||
Block_hash.pp_short hash >>= fun () ->
|
pred proto hash header operations
|
||||||
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
|
end
|
||||||
Distributed_db.commit_block
|
end >>= function
|
||||||
net_db hash header operations result
|
| Ok result -> begin
|
||||||
end >>=? function
|
lwt_log_info "validated block %a"
|
||||||
| None ->
|
Block_hash.pp_short hash >>= fun () ->
|
||||||
assert false (* should not happen *)
|
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
|
||||||
| Some block ->
|
Distributed_db.commit_block
|
||||||
Protocol_validator.prefetch_and_compile_protocols
|
net_db hash header operations result
|
||||||
bv.protocol_validator
|
end >>=? function
|
||||||
?peer ~timeout:bv.protocol_timeout
|
| None ->
|
||||||
block ;
|
assert false (* should not happen *)
|
||||||
may_wakeup (Ok block) ;
|
| Some block ->
|
||||||
notify_new_block block ;
|
Protocol_validator.prefetch_and_compile_protocols
|
||||||
|
bv.protocol_validator
|
||||||
|
?peer ~timeout:bv.protocol_timeout
|
||||||
|
block ;
|
||||||
|
may_wakeup (Ok block) ;
|
||||||
|
notify_new_block block ;
|
||||||
|
return ()
|
||||||
|
end
|
||||||
|
(* TODO catch other temporary error (e.g. system errors)
|
||||||
|
and do not 'commit' them on disk... *)
|
||||||
|
| Error [Lwt_utils.Canceled | Unavailable_protocol _] as err ->
|
||||||
|
may_wakeup err ;
|
||||||
|
return ()
|
||||||
|
| Error errors as err ->
|
||||||
|
lwt_log_error "@[<v 2>Received invalid block %a:@ %a@]"
|
||||||
|
Block_hash.pp_short hash
|
||||||
|
Error_monad.pp_print_error errors >>= fun () ->
|
||||||
|
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
|
||||||
|
Distributed_db.commit_invalid_block
|
||||||
|
net_db hash header errors
|
||||||
|
end >>=? fun commited ->
|
||||||
|
assert commited ;
|
||||||
|
may_wakeup err ;
|
||||||
return ()
|
return ()
|
||||||
end
|
|
||||||
(* TODO catch other temporary error (e.g. system errors)
|
|
||||||
and do not 'commit' them on disk... *)
|
|
||||||
| Error [Lwt_utils.Canceled | Unavailable_protocol _] as err ->
|
|
||||||
may_wakeup err ;
|
|
||||||
return ()
|
|
||||||
| Error errors as err ->
|
|
||||||
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
|
|
||||||
Distributed_db.commit_invalid_block
|
|
||||||
net_db hash header errors
|
|
||||||
end >>=? fun commited ->
|
|
||||||
assert commited ;
|
|
||||||
may_wakeup err ;
|
|
||||||
return ()
|
|
||||||
end >>= function
|
end >>= function
|
||||||
| Ok () ->
|
| Ok () ->
|
||||||
worker_loop bv
|
worker_loop bv
|
||||||
|
Loading…
Reference in New Issue
Block a user