Shell: do not keep tracks of 'invalid_successors'
This commit is contained in:
parent
4de5dc717f
commit
61eb67cbca
@ -396,22 +396,6 @@ module Chain = struct
|
||||
(struct let name = ["current_head"] end)
|
||||
(Store_helpers.Make_value(Block_hash))
|
||||
|
||||
module Valid_successors =
|
||||
Store_helpers.Make_buffered_set
|
||||
(Store_helpers.Make_substore
|
||||
(Block_header.Indexed_store.Store)
|
||||
(struct let name = ["known_successors" ; "valid" ] end))
|
||||
(Block_hash)
|
||||
(Block_hash.Set)
|
||||
|
||||
module Invalid_successors =
|
||||
Store_helpers.Make_buffered_set
|
||||
(Store_helpers.Make_substore
|
||||
(Block_header.Indexed_store.Store)
|
||||
(struct let name = ["known_successors" ; "invalid"] end))
|
||||
(Block_hash)
|
||||
(Block_hash.Set)
|
||||
|
||||
module Successor_in_chain =
|
||||
Store_helpers.Make_single_store
|
||||
(Block_header.Indexed_store.Store)
|
||||
|
@ -70,16 +70,6 @@ module Chain : sig
|
||||
and type elt := Block_hash.t
|
||||
and module Set := Block_hash.Set
|
||||
|
||||
module Valid_successors : BUFFERED_SET_STORE
|
||||
with type t = store * Block_hash.t
|
||||
and type elt := Block_hash.t
|
||||
and module Set := Block_hash.Set
|
||||
|
||||
module Invalid_successors : BUFFERED_SET_STORE
|
||||
with type t = store * Block_hash.t
|
||||
and type elt := Block_hash.t
|
||||
and module Set := Block_hash.Set
|
||||
|
||||
module Successor_in_chain : SINGLE_STORE
|
||||
with type t = store * Block_hash.t
|
||||
and type value := Block_hash.t
|
||||
|
@ -123,14 +123,12 @@ and valid_block = {
|
||||
protocol: (module Updater.REGISTRED_PROTOCOL) option ;
|
||||
test_network: Context.test_network ;
|
||||
context: Context.t ;
|
||||
successors: Block_hash.Set.t ;
|
||||
invalid_successors: Block_hash.Set.t ;
|
||||
proto_header: MBytes.t ;
|
||||
}
|
||||
|
||||
let build_valid_block
|
||||
hash header operation_hashes operations
|
||||
context discovery_time successors invalid_successors =
|
||||
context discovery_time =
|
||||
Context.get_protocol context >>= fun protocol_hash ->
|
||||
Context.get_test_network context >>= fun test_network ->
|
||||
let protocol = Updater.get protocol_hash in
|
||||
@ -150,8 +148,6 @@ let build_valid_block
|
||||
protocol ;
|
||||
test_network ;
|
||||
context ;
|
||||
successors ;
|
||||
invalid_successors ;
|
||||
proto_header = header.Store.Block_header.proto ;
|
||||
} in
|
||||
Lwt.return valid_block
|
||||
@ -729,24 +725,6 @@ module Block_header = struct
|
||||
let read_operations_exn s k =
|
||||
Raw_operation_list.read_all_exn s.block_header_store k
|
||||
|
||||
let mark_invalid net hash errors =
|
||||
mark_invalid net hash errors >>= fun marked ->
|
||||
if not marked then
|
||||
Lwt.return_false
|
||||
else begin
|
||||
Raw_block_header.read_opt net.block_header_store hash >>= function
|
||||
| Some { shell = { predecessor } } ->
|
||||
Shared.use net.state begin fun state ->
|
||||
Store.Chain.Valid_successors.remove
|
||||
(state.chain_store, predecessor) hash >>= fun () ->
|
||||
Store.Chain.Invalid_successors.store
|
||||
(state.chain_store, predecessor) hash
|
||||
end >>= fun () ->
|
||||
Lwt.return_true
|
||||
| None ->
|
||||
Lwt.return_true
|
||||
end
|
||||
|
||||
module Helpers = struct
|
||||
|
||||
let check_block state h =
|
||||
@ -915,8 +893,7 @@ module Raw_net = struct
|
||||
end >>= fun context ->
|
||||
build_valid_block
|
||||
genesis.block header (lazy Lwt.return_nil) (lazy Lwt.return_nil)
|
||||
context genesis.time
|
||||
Block_hash.Set.empty Block_hash.Set.empty >>= fun genesis_block ->
|
||||
context genesis.time >>= fun genesis_block ->
|
||||
Lwt.return @@
|
||||
build
|
||||
~genesis
|
||||
@ -949,8 +926,6 @@ module Valid_block = struct
|
||||
protocol: (module Updater.REGISTRED_PROTOCOL) option ;
|
||||
test_network: Context.test_network ;
|
||||
context: Context.t ;
|
||||
successors: Block_hash.Set.t ;
|
||||
invalid_successors: Block_hash.Set.t ;
|
||||
proto_header: MBytes.t ;
|
||||
}
|
||||
type valid_block = t
|
||||
@ -962,24 +937,21 @@ module Valid_block = struct
|
||||
|
||||
let raw_read
|
||||
block operations operation_hashes
|
||||
time chain_store context_index hash =
|
||||
time context_index hash =
|
||||
Context.checkout context_index hash >>= function
|
||||
| None ->
|
||||
fail (Unknown_context hash)
|
||||
| Some context ->
|
||||
Store.Chain.Valid_successors.read_all (chain_store, hash)
|
||||
>>= fun successors ->
|
||||
Store.Chain.Invalid_successors.read_all (chain_store, hash)
|
||||
>>= fun invalid_successors ->
|
||||
build_valid_block hash block operation_hashes operations
|
||||
context time successors invalid_successors >>= fun block ->
|
||||
build_valid_block
|
||||
hash block operation_hashes operations
|
||||
context time >>= fun block ->
|
||||
return block
|
||||
|
||||
let raw_read_exn
|
||||
block operations operation_hashes
|
||||
time chain_store context_index hash =
|
||||
time context_index hash =
|
||||
raw_read block operations operation_hashes
|
||||
time chain_store context_index hash >>= function
|
||||
time context_index hash >>= function
|
||||
| Error _ -> Lwt.fail Not_found
|
||||
| Ok data -> Lwt.return data
|
||||
|
||||
@ -999,7 +971,7 @@ module Valid_block = struct
|
||||
operations)
|
||||
in
|
||||
raw_read block operations operation_hashes
|
||||
time net_state.chain_store net_state.context_index hash
|
||||
time net_state.context_index hash
|
||||
|
||||
let read_opt net net_state hash =
|
||||
read net net_state hash >>= function
|
||||
@ -1048,8 +1020,6 @@ module Valid_block = struct
|
||||
let predecessor = block.shell.predecessor in
|
||||
Store.Chain.Known_heads.remove store predecessor >>= fun () ->
|
||||
Store.Chain.Known_heads.store store hash >>= fun () ->
|
||||
Store.Chain.Valid_successors.store
|
||||
(store, predecessor) hash >>= fun () ->
|
||||
(* Build the `valid_block` value. *)
|
||||
let operation_hashes =
|
||||
lazy (Operation_list.Locked.read_all_exn block_header_store hash) in
|
||||
@ -1062,7 +1032,7 @@ module Valid_block = struct
|
||||
operations) in
|
||||
raw_read_exn
|
||||
block operations operation_hashes discovery_time
|
||||
net_state.chain_store net_state.context_index hash >>= fun valid_block ->
|
||||
net_state.context_index hash >>= fun valid_block ->
|
||||
Watcher.notify valid_block_watcher valid_block ;
|
||||
Lwt.return (Ok valid_block)
|
||||
|
||||
@ -1359,7 +1329,7 @@ module Net = struct
|
||||
Valid_block.Locked.raw_read
|
||||
genesis_shell_header (lazy Lwt.return_nil) (lazy Lwt.return_nil)
|
||||
genesis_discovery_time
|
||||
chain_store context_index genesis_hash >>=? fun genesis_block ->
|
||||
context_index genesis_hash >>=? fun genesis_block ->
|
||||
return @@
|
||||
Raw_net.build
|
||||
~genesis
|
||||
|
@ -274,9 +274,6 @@ module Valid_block : sig
|
||||
(** The current test network associated to the block. *)
|
||||
context: Context.t ;
|
||||
(** The validation context that was produced by the block validation. *)
|
||||
successors: Block_hash.Set.t ;
|
||||
invalid_successors: Block_hash.Set.t ;
|
||||
(** The set of valid successors (including forked networks). *)
|
||||
proto_header: MBytes.t;
|
||||
(** The uninterpreted protocol dependent part of the header. *)
|
||||
}
|
||||
|
@ -329,43 +329,6 @@ let test_read_block (s: state) =
|
||||
return ()
|
||||
|
||||
|
||||
(****************************************************************************)
|
||||
|
||||
(** State.successors *)
|
||||
|
||||
let compare s kind name succs l =
|
||||
if Block_hash.Set.cardinal succs <> List.length l then
|
||||
Assert.fail_msg
|
||||
"unexpected %ssuccessors size (%s: %d %d)"
|
||||
kind name (Block_hash.Set.cardinal succs) (List.length l) ;
|
||||
List.iter
|
||||
(fun bname ->
|
||||
let bh = fst @@ block s bname in
|
||||
if not (Block_hash.Set.mem bh succs) then
|
||||
Assert.fail_msg
|
||||
"missing block in %ssuccessors (%s: %s)" kind name bname)
|
||||
l
|
||||
|
||||
let test_successors s =
|
||||
let test s name expected invalid_expected =
|
||||
let b = vblock s name in
|
||||
State.Valid_block.read s.net b.hash >>= function
|
||||
| Error _ ->
|
||||
Assert.fail_msg "Failed while reading block %s" name
|
||||
| Ok { successors ; invalid_successors } ->
|
||||
compare s "" name successors expected ;
|
||||
compare s "invalid " name invalid_successors invalid_expected ;
|
||||
Lwt.return_unit
|
||||
|
||||
in
|
||||
test s "A1" ["A2"] [] >>= fun () ->
|
||||
test s "A3" ["A4";"B1"] [] >>= fun () ->
|
||||
test s "A8" [] [] >>= fun () ->
|
||||
test s "B1" ["B2"] [] >>= fun () ->
|
||||
test s "B7" ["B8"] ["C1"] >>= fun () ->
|
||||
return ()
|
||||
|
||||
|
||||
(****************************************************************************)
|
||||
|
||||
(** State.path *)
|
||||
@ -697,7 +660,6 @@ let tests : (string * (state -> unit tzresult Lwt.t)) list = [
|
||||
"init", test_init ;
|
||||
"read_operation", test_read_operation;
|
||||
"read_block", test_read_block ;
|
||||
"successors", test_successors ;
|
||||
"path", test_path ;
|
||||
"valid_path", test_valid_path ;
|
||||
"ancestor", test_ancestor ;
|
||||
|
Loading…
Reference in New Issue
Block a user