Shell: enforce the context hash of the block header

This commit is contained in:
Grégoire Henry 2017-12-05 15:19:25 +01:00 committed by Grégoire
parent 009d562e08
commit ae82f2b279
3 changed files with 24 additions and 3 deletions

View File

@ -486,8 +486,6 @@ let rec worker_loop bv =
end
end >>= function
| Ok result -> begin
lwt_log_info "validated block %a"
Block_hash.pp_short hash >>= fun () ->
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
Distributed_db.commit_block
net_db hash header operations result
@ -495,6 +493,8 @@ let rec worker_loop bv =
| None ->
assert false (* should not happen *)
| Some block ->
lwt_log_info "validated block %a"
Block_hash.pp_short hash >>= fun () ->
Protocol_validator.prefetch_and_compile_protocols
bv.protocol_validator
?peer ~timeout:bv.protocol_timeout

View File

@ -441,6 +441,22 @@ module Block = struct
read_exn net_state header.shell.predecessor >>= fun block ->
Lwt.return (Some block)
type error += Inconsistent_hash of Context_hash.t * Context_hash.t
let () =
Error_monad.register_error_kind
`Permanent
~id:"inconsistentContextHash"
~title:"Inconsistent commit hash"
~description:
"When commiting the context of a block, the announced context \
hash was not the one computed at commit time."
Data_encoding.(obj2
(req "wrong_context_hash" Context_hash.encoding)
(req "expected_context_hash" Context_hash.encoding))
(function Inconsistent_hash (got, exp) -> Some (got, exp) | _ -> None)
(fun (got, exp) -> Inconsistent_hash (got, exp))
let store
net_state block_header operations
{ Updater.context ; message ; max_operations_ttl ;
@ -457,6 +473,9 @@ module Block = struct
else begin
Context.commit
~time:block_header.shell.timestamp ?message context >>= fun commit ->
fail_unless
(Context_hash.equal block_header.shell.context commit)
(Inconsistent_hash (commit, block_header.shell.context)) >>=? fun () ->
let contents = {
Store.Block.header = block_header ;
message ;

View File

@ -104,6 +104,8 @@ module Block : sig
val read_opt: Net.t -> Block_hash.t -> block option Lwt.t
val read_exn: Net.t -> Block_hash.t -> block Lwt.t
type error += Inconsistent_hash of Context_hash.t * Context_hash.t
val store:
Net.t ->
Block_header.t ->