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)
|
(struct let name = ["current_head"] end)
|
||||||
(Store_helpers.Make_value(Block_hash))
|
(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 =
|
module Successor_in_chain =
|
||||||
Store_helpers.Make_single_store
|
Store_helpers.Make_single_store
|
||||||
(Block_header.Indexed_store.Store)
|
(Block_header.Indexed_store.Store)
|
||||||
|
@ -70,16 +70,6 @@ module Chain : sig
|
|||||||
and type elt := Block_hash.t
|
and type elt := Block_hash.t
|
||||||
and module Set := Block_hash.Set
|
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
|
module Successor_in_chain : SINGLE_STORE
|
||||||
with type t = store * Block_hash.t
|
with type t = store * Block_hash.t
|
||||||
and type value := Block_hash.t
|
and type value := Block_hash.t
|
||||||
|
@ -123,14 +123,12 @@ and valid_block = {
|
|||||||
protocol: (module Updater.REGISTRED_PROTOCOL) option ;
|
protocol: (module Updater.REGISTRED_PROTOCOL) option ;
|
||||||
test_network: Context.test_network ;
|
test_network: Context.test_network ;
|
||||||
context: Context.t ;
|
context: Context.t ;
|
||||||
successors: Block_hash.Set.t ;
|
|
||||||
invalid_successors: Block_hash.Set.t ;
|
|
||||||
proto_header: MBytes.t ;
|
proto_header: MBytes.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
let build_valid_block
|
let build_valid_block
|
||||||
hash header operation_hashes operations
|
hash header operation_hashes operations
|
||||||
context discovery_time successors invalid_successors =
|
context discovery_time =
|
||||||
Context.get_protocol context >>= fun protocol_hash ->
|
Context.get_protocol context >>= fun protocol_hash ->
|
||||||
Context.get_test_network context >>= fun test_network ->
|
Context.get_test_network context >>= fun test_network ->
|
||||||
let protocol = Updater.get protocol_hash in
|
let protocol = Updater.get protocol_hash in
|
||||||
@ -150,8 +148,6 @@ let build_valid_block
|
|||||||
protocol ;
|
protocol ;
|
||||||
test_network ;
|
test_network ;
|
||||||
context ;
|
context ;
|
||||||
successors ;
|
|
||||||
invalid_successors ;
|
|
||||||
proto_header = header.Store.Block_header.proto ;
|
proto_header = header.Store.Block_header.proto ;
|
||||||
} in
|
} in
|
||||||
Lwt.return valid_block
|
Lwt.return valid_block
|
||||||
@ -729,24 +725,6 @@ module Block_header = struct
|
|||||||
let read_operations_exn s k =
|
let read_operations_exn s k =
|
||||||
Raw_operation_list.read_all_exn s.block_header_store 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
|
module Helpers = struct
|
||||||
|
|
||||||
let check_block state h =
|
let check_block state h =
|
||||||
@ -915,8 +893,7 @@ module Raw_net = struct
|
|||||||
end >>= fun context ->
|
end >>= fun context ->
|
||||||
build_valid_block
|
build_valid_block
|
||||||
genesis.block header (lazy Lwt.return_nil) (lazy Lwt.return_nil)
|
genesis.block header (lazy Lwt.return_nil) (lazy Lwt.return_nil)
|
||||||
context genesis.time
|
context genesis.time >>= fun genesis_block ->
|
||||||
Block_hash.Set.empty Block_hash.Set.empty >>= fun genesis_block ->
|
|
||||||
Lwt.return @@
|
Lwt.return @@
|
||||||
build
|
build
|
||||||
~genesis
|
~genesis
|
||||||
@ -949,8 +926,6 @@ module Valid_block = struct
|
|||||||
protocol: (module Updater.REGISTRED_PROTOCOL) option ;
|
protocol: (module Updater.REGISTRED_PROTOCOL) option ;
|
||||||
test_network: Context.test_network ;
|
test_network: Context.test_network ;
|
||||||
context: Context.t ;
|
context: Context.t ;
|
||||||
successors: Block_hash.Set.t ;
|
|
||||||
invalid_successors: Block_hash.Set.t ;
|
|
||||||
proto_header: MBytes.t ;
|
proto_header: MBytes.t ;
|
||||||
}
|
}
|
||||||
type valid_block = t
|
type valid_block = t
|
||||||
@ -962,24 +937,21 @@ module Valid_block = struct
|
|||||||
|
|
||||||
let raw_read
|
let raw_read
|
||||||
block operations operation_hashes
|
block operations operation_hashes
|
||||||
time chain_store context_index hash =
|
time context_index hash =
|
||||||
Context.checkout context_index hash >>= function
|
Context.checkout context_index hash >>= function
|
||||||
| None ->
|
| None ->
|
||||||
fail (Unknown_context hash)
|
fail (Unknown_context hash)
|
||||||
| Some context ->
|
| Some context ->
|
||||||
Store.Chain.Valid_successors.read_all (chain_store, hash)
|
build_valid_block
|
||||||
>>= fun successors ->
|
hash block operation_hashes operations
|
||||||
Store.Chain.Invalid_successors.read_all (chain_store, hash)
|
context time >>= fun block ->
|
||||||
>>= fun invalid_successors ->
|
|
||||||
build_valid_block hash block operation_hashes operations
|
|
||||||
context time successors invalid_successors >>= fun block ->
|
|
||||||
return block
|
return block
|
||||||
|
|
||||||
let raw_read_exn
|
let raw_read_exn
|
||||||
block operations operation_hashes
|
block operations operation_hashes
|
||||||
time chain_store context_index hash =
|
time context_index hash =
|
||||||
raw_read block operations operation_hashes
|
raw_read block operations operation_hashes
|
||||||
time chain_store context_index hash >>= function
|
time context_index hash >>= function
|
||||||
| Error _ -> Lwt.fail Not_found
|
| Error _ -> Lwt.fail Not_found
|
||||||
| Ok data -> Lwt.return data
|
| Ok data -> Lwt.return data
|
||||||
|
|
||||||
@ -999,7 +971,7 @@ module Valid_block = struct
|
|||||||
operations)
|
operations)
|
||||||
in
|
in
|
||||||
raw_read block operations operation_hashes
|
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 =
|
let read_opt net net_state hash =
|
||||||
read net net_state hash >>= function
|
read net net_state hash >>= function
|
||||||
@ -1048,8 +1020,6 @@ module Valid_block = struct
|
|||||||
let predecessor = block.shell.predecessor in
|
let predecessor = block.shell.predecessor in
|
||||||
Store.Chain.Known_heads.remove store predecessor >>= fun () ->
|
Store.Chain.Known_heads.remove store predecessor >>= fun () ->
|
||||||
Store.Chain.Known_heads.store store hash >>= fun () ->
|
Store.Chain.Known_heads.store store hash >>= fun () ->
|
||||||
Store.Chain.Valid_successors.store
|
|
||||||
(store, predecessor) hash >>= fun () ->
|
|
||||||
(* Build the `valid_block` value. *)
|
(* Build the `valid_block` value. *)
|
||||||
let operation_hashes =
|
let operation_hashes =
|
||||||
lazy (Operation_list.Locked.read_all_exn block_header_store hash) in
|
lazy (Operation_list.Locked.read_all_exn block_header_store hash) in
|
||||||
@ -1062,7 +1032,7 @@ module Valid_block = struct
|
|||||||
operations) in
|
operations) in
|
||||||
raw_read_exn
|
raw_read_exn
|
||||||
block operations operation_hashes discovery_time
|
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 ;
|
Watcher.notify valid_block_watcher valid_block ;
|
||||||
Lwt.return (Ok valid_block)
|
Lwt.return (Ok valid_block)
|
||||||
|
|
||||||
@ -1359,7 +1329,7 @@ module Net = struct
|
|||||||
Valid_block.Locked.raw_read
|
Valid_block.Locked.raw_read
|
||||||
genesis_shell_header (lazy Lwt.return_nil) (lazy Lwt.return_nil)
|
genesis_shell_header (lazy Lwt.return_nil) (lazy Lwt.return_nil)
|
||||||
genesis_discovery_time
|
genesis_discovery_time
|
||||||
chain_store context_index genesis_hash >>=? fun genesis_block ->
|
context_index genesis_hash >>=? fun genesis_block ->
|
||||||
return @@
|
return @@
|
||||||
Raw_net.build
|
Raw_net.build
|
||||||
~genesis
|
~genesis
|
||||||
|
@ -274,9 +274,6 @@ module Valid_block : sig
|
|||||||
(** The current test network associated to the block. *)
|
(** The current test network associated to the block. *)
|
||||||
context: Context.t ;
|
context: Context.t ;
|
||||||
(** The validation context that was produced by the block validation. *)
|
(** 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;
|
proto_header: MBytes.t;
|
||||||
(** The uninterpreted protocol dependent part of the header. *)
|
(** The uninterpreted protocol dependent part of the header. *)
|
||||||
}
|
}
|
||||||
|
@ -329,43 +329,6 @@ let test_read_block (s: state) =
|
|||||||
return ()
|
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 *)
|
(** State.path *)
|
||||||
@ -697,7 +660,6 @@ let tests : (string * (state -> unit tzresult Lwt.t)) list = [
|
|||||||
"init", test_init ;
|
"init", test_init ;
|
||||||
"read_operation", test_read_operation;
|
"read_operation", test_read_operation;
|
||||||
"read_block", test_read_block ;
|
"read_block", test_read_block ;
|
||||||
"successors", test_successors ;
|
|
||||||
"path", test_path ;
|
"path", test_path ;
|
||||||
"valid_path", test_valid_path ;
|
"valid_path", test_valid_path ;
|
||||||
"ancestor", test_ancestor ;
|
"ancestor", test_ancestor ;
|
||||||
|
Loading…
Reference in New Issue
Block a user