Shell: enforce the context hash of the block header
This commit is contained in:
parent
009d562e08
commit
ae82f2b279
@ -486,8 +486,6 @@ let rec worker_loop bv =
|
|||||||
end
|
end
|
||||||
end >>= function
|
end >>= function
|
||||||
| Ok result -> begin
|
| Ok result -> begin
|
||||||
lwt_log_info "validated block %a"
|
|
||||||
Block_hash.pp_short hash >>= fun () ->
|
|
||||||
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
|
Lwt_utils.protect ~canceler:bv.canceler begin fun () ->
|
||||||
Distributed_db.commit_block
|
Distributed_db.commit_block
|
||||||
net_db hash header operations result
|
net_db hash header operations result
|
||||||
@ -495,6 +493,8 @@ let rec worker_loop bv =
|
|||||||
| None ->
|
| None ->
|
||||||
assert false (* should not happen *)
|
assert false (* should not happen *)
|
||||||
| Some block ->
|
| Some block ->
|
||||||
|
lwt_log_info "validated block %a"
|
||||||
|
Block_hash.pp_short hash >>= fun () ->
|
||||||
Protocol_validator.prefetch_and_compile_protocols
|
Protocol_validator.prefetch_and_compile_protocols
|
||||||
bv.protocol_validator
|
bv.protocol_validator
|
||||||
?peer ~timeout:bv.protocol_timeout
|
?peer ~timeout:bv.protocol_timeout
|
||||||
|
@ -441,6 +441,22 @@ module Block = struct
|
|||||||
read_exn net_state header.shell.predecessor >>= fun block ->
|
read_exn net_state header.shell.predecessor >>= fun block ->
|
||||||
Lwt.return (Some 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
|
let store
|
||||||
net_state block_header operations
|
net_state block_header operations
|
||||||
{ Updater.context ; message ; max_operations_ttl ;
|
{ Updater.context ; message ; max_operations_ttl ;
|
||||||
@ -457,6 +473,9 @@ module Block = struct
|
|||||||
else begin
|
else begin
|
||||||
Context.commit
|
Context.commit
|
||||||
~time:block_header.shell.timestamp ?message context >>= fun 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 = {
|
let contents = {
|
||||||
Store.Block.header = block_header ;
|
Store.Block.header = block_header ;
|
||||||
message ;
|
message ;
|
||||||
|
@ -104,6 +104,8 @@ module Block : sig
|
|||||||
val read_opt: Net.t -> Block_hash.t -> block option Lwt.t
|
val read_opt: Net.t -> Block_hash.t -> block option Lwt.t
|
||||||
val read_exn: Net.t -> Block_hash.t -> block 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:
|
val store:
|
||||||
Net.t ->
|
Net.t ->
|
||||||
Block_header.t ->
|
Block_header.t ->
|
||||||
|
Loading…
Reference in New Issue
Block a user