Shell: Remove net_id from the operation header.

The `branch` of the operation contains enough information to induce
the `net_id`, and the code of the validator/prevalidator is now mature
enough to efficiently determine the `net_id` of an incoming operation.
This commit is contained in:
Grégoire Henry 2017-11-14 02:41:37 +01:00 committed by Benjamin Canou
parent 4d2bc49960
commit b7deebaf42
27 changed files with 163 additions and 127 deletions

View File

@ -22,9 +22,9 @@ let inject_block cctxt ?(async = false) ?(force = false) raw operations =
call_err_service0 cctxt Services.inject_block call_err_service0 cctxt Services.inject_block
{ raw ; blocking = not async ; force ; operations } { raw ; blocking = not async ; force ; operations }
let inject_operation cctxt ?(async = false) ?force operation = let inject_operation cctxt ?(async = false) ?force ?net_id operation =
call_err_service0 cctxt Services.inject_operation call_err_service0 cctxt Services.inject_operation
(operation, not async, force) (operation, not async, net_id, force)
let inject_protocol cctxt ?(async = false) ?force protocol = let inject_protocol cctxt ?(async = false) ?force protocol =
call_err_service0 cctxt Services.inject_protocol call_err_service0 cctxt Services.inject_protocol

View File

@ -30,7 +30,7 @@ val inject_block:
val inject_operation: val inject_operation:
config -> config ->
?async:bool -> ?force:bool -> ?async:bool -> ?force:bool -> ?net_id:Net_id.t ->
MBytes.t -> MBytes.t ->
Operation_hash.t tzresult Lwt.t Operation_hash.t tzresult Lwt.t

View File

@ -122,7 +122,6 @@ let inject_endorsement cctxt
Client_node_rpcs.Blocks.info cctxt.rpc_config block >>=? fun bi -> Client_node_rpcs.Blocks.info cctxt.rpc_config block >>=? fun bi ->
Client_proto_rpcs.Helpers.Forge.Delegate.endorsement cctxt.rpc_config Client_proto_rpcs.Helpers.Forge.Delegate.endorsement cctxt.rpc_config
block block
~net_id:bi.net_id
~branch:bi.hash ~branch:bi.hash
~source ~source
~block:bi.hash ~block:bi.hash
@ -130,7 +129,8 @@ let inject_endorsement cctxt
() >>=? fun bytes -> () >>=? fun bytes ->
let signed_bytes = Ed25519.Signature.append src_sk bytes in let signed_bytes = Ed25519.Signature.append src_sk bytes in
Client_node_rpcs.inject_operation Client_node_rpcs.inject_operation
cctxt.rpc_config ?force ?async signed_bytes >>=? fun oph -> cctxt.rpc_config ?force ?async ~net_id:bi.net_id
signed_bytes >>=? fun oph ->
State.record_endorsement cctxt level bi.hash slot oph >>=? fun () -> State.record_endorsement cctxt level bi.hash slot oph >>=? fun () ->
return oph return oph

View File

@ -17,8 +17,10 @@ let inject_seed_nonce_revelation rpc_config block ?force ?async nonces =
let block = Client_rpcs.last_mined_block block in let block = Client_rpcs.last_mined_block block in
Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi -> Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi ->
Client_proto_rpcs.Helpers.Forge.Anonymous.operations rpc_config Client_proto_rpcs.Helpers.Forge.Anonymous.operations rpc_config
block ~net_id:bi.net_id ~branch:bi.hash operations >>=? fun bytes -> block ~branch:bi.hash operations >>=? fun bytes ->
Client_node_rpcs.inject_operation rpc_config ?force ?async bytes >>=? fun oph -> Client_node_rpcs.inject_operation
rpc_config ?force ?async ~net_id:bi.net_id
bytes >>=? fun oph ->
return oph return oph
let forge_seed_nonce_revelation let forge_seed_nonce_revelation

View File

@ -60,7 +60,7 @@ let transfer rpc_config
let counter = Int32.succ pcounter in let counter = Int32.succ pcounter in
Client_proto_rpcs.Helpers.Forge.Manager.transaction Client_proto_rpcs.Helpers.Forge.Manager.transaction
rpc_config block rpc_config block
~net_id ~branch ~source ~sourcePubKey:src_pk ~counter ~amount ~branch ~source ~sourcePubKey:src_pk ~counter ~amount
~destination ?parameters ~fee () >>=? fun bytes -> ~destination ?parameters ~fee () >>=? fun bytes ->
Client_node_rpcs.Blocks.predecessor rpc_config block >>=? fun predecessor -> Client_node_rpcs.Blocks.predecessor rpc_config block >>=? fun predecessor ->
let signature = Ed25519.sign src_sk bytes in let signature = Ed25519.sign src_sk bytes in
@ -69,11 +69,11 @@ let transfer rpc_config
Client_proto_rpcs.Helpers.apply_operation rpc_config block Client_proto_rpcs.Helpers.apply_operation rpc_config block
predecessor oph bytes (Some signature) >>=? fun contracts -> predecessor oph bytes (Some signature) >>=? fun contracts ->
Client_node_rpcs.inject_operation Client_node_rpcs.inject_operation
rpc_config ?force signed_bytes >>=? fun injected_oph -> rpc_config ?force ~net_id signed_bytes >>=? fun injected_oph ->
assert (Operation_hash.equal oph injected_oph) ; assert (Operation_hash.equal oph injected_oph) ;
return (oph, contracts) return (oph, contracts)
let originate rpc_config ?force ~block ?signature bytes = let originate rpc_config ?force ?net_id ~block ?signature bytes =
let signed_bytes = let signed_bytes =
match signature with match signature with
| None -> bytes | None -> bytes
@ -84,7 +84,7 @@ let originate rpc_config ?force ~block ?signature bytes =
predecessor oph bytes signature >>=? function predecessor oph bytes signature >>=? function
| [ contract ] -> | [ contract ] ->
Client_node_rpcs.inject_operation Client_node_rpcs.inject_operation
rpc_config ?force signed_bytes >>=? fun injected_oph -> rpc_config ?force ?net_id signed_bytes >>=? fun injected_oph ->
assert (Operation_hash.equal oph injected_oph) ; assert (Operation_hash.equal oph injected_oph) ;
return (oph, contract) return (oph, contract)
| contracts -> | contracts ->
@ -101,11 +101,11 @@ let originate_account rpc_config
rpc_config block source >>=? fun pcounter -> rpc_config block source >>=? fun pcounter ->
let counter = Int32.succ pcounter in let counter = Int32.succ pcounter in
Client_proto_rpcs.Helpers.Forge.Manager.origination rpc_config block Client_proto_rpcs.Helpers.Forge.Manager.origination rpc_config block
~net_id ~branch ~source ~sourcePubKey:src_pk ~managerPubKey:manager_pkh ~branch ~source ~sourcePubKey:src_pk ~managerPubKey:manager_pkh
~counter ~balance ?spendable ~counter ~balance ?spendable
?delegatable ?delegatePubKey:delegate ~fee () >>=? fun bytes -> ?delegatable ?delegatePubKey:delegate ~fee () >>=? fun bytes ->
let signature = Ed25519.sign src_sk bytes in let signature = Ed25519.sign src_sk bytes in
originate rpc_config ?force ~block ~signature bytes originate rpc_config ?force ~block ~net_id ~signature bytes
let originate_contract rpc_config let originate_contract rpc_config
block ?force ?branch block ?force ?branch
@ -117,18 +117,18 @@ let originate_contract rpc_config
let counter = Int32.succ pcounter in let counter = Int32.succ pcounter in
get_branch rpc_config block branch >>=? fun (net_id, branch) -> get_branch rpc_config block branch >>=? fun (net_id, branch) ->
Client_proto_rpcs.Helpers.Forge.Manager.origination rpc_config block Client_proto_rpcs.Helpers.Forge.Manager.origination rpc_config block
~net_id ~branch ~source ~sourcePubKey:src_pk ~managerPubKey:manager_pkh ~branch ~source ~sourcePubKey:src_pk ~managerPubKey:manager_pkh
~counter ~balance ~spendable:spendable ~counter ~balance ~spendable:spendable
?delegatable ?delegatePubKey ?delegatable ?delegatePubKey
~script:{ code ; storage } ~fee () >>=? fun bytes -> ~script:{ code ; storage } ~fee () >>=? fun bytes ->
let signature = Ed25519.sign src_sk bytes in let signature = Ed25519.sign src_sk bytes in
originate rpc_config ?force ~block ~signature bytes originate rpc_config ?force ~net_id ~block ~signature bytes
let faucet rpc_config block ?force ?branch ~manager_pkh () = let faucet rpc_config block ?force ?branch ~manager_pkh () =
get_branch rpc_config block branch >>=? fun (net_id, branch) -> get_branch rpc_config block branch >>=? fun (net_id, branch) ->
Client_proto_rpcs.Helpers.Forge.Anonymous.faucet Client_proto_rpcs.Helpers.Forge.Anonymous.faucet
rpc_config block ~net_id ~branch ~id:manager_pkh () >>=? fun bytes -> rpc_config block ~branch ~id:manager_pkh () >>=? fun bytes ->
originate rpc_config ?force ~block bytes originate rpc_config ?force ~net_id ~block bytes
let delegate_contract rpc_config let delegate_contract rpc_config
block ?force ?branch block ?force ?branch
@ -139,13 +139,13 @@ let delegate_contract rpc_config
rpc_config block source >>=? fun pcounter -> rpc_config block source >>=? fun pcounter ->
let counter = Int32.succ pcounter in let counter = Int32.succ pcounter in
Client_proto_rpcs.Helpers.Forge.Manager.delegation rpc_config block Client_proto_rpcs.Helpers.Forge.Manager.delegation rpc_config block
~net_id ~branch ~source ?sourcePubKey:src_pk ~counter ~fee delegate_opt ~branch ~source ?sourcePubKey:src_pk ~counter ~fee delegate_opt
>>=? fun bytes -> >>=? fun bytes ->
let signature = Environment.Ed25519.sign manager_sk bytes in let signature = Environment.Ed25519.sign manager_sk bytes in
let signed_bytes = MBytes.concat bytes signature in let signed_bytes = MBytes.concat bytes signature in
let oph = Operation_hash.hash_bytes [ signed_bytes ] in let oph = Operation_hash.hash_bytes [ signed_bytes ] in
Client_node_rpcs.inject_operation Client_node_rpcs.inject_operation
rpc_config ?force signed_bytes >>=? fun injected_oph -> rpc_config ?force ~net_id signed_bytes >>=? fun injected_oph ->
assert (Operation_hash.equal oph injected_oph) ; assert (Operation_hash.equal oph injected_oph) ;
return oph return oph
@ -218,17 +218,17 @@ let group =
{ Cli_entries.name = "context" ; { Cli_entries.name = "context" ;
title = "Block contextual commands (see option -block)" } title = "Block contextual commands (see option -block)" }
let dictate rpc_config block command seckey = let dictate rpc_config ?force block command seckey =
let block = Client_rpcs.last_mined_block block in let block = Client_rpcs.last_mined_block block in
Client_node_rpcs.Blocks.info Client_node_rpcs.Blocks.info
rpc_config block >>=? fun { net_id ; hash = branch } -> rpc_config block >>=? fun { net_id ; hash = branch } ->
Client_proto_rpcs.Helpers.Forge.Dictator.operation Client_proto_rpcs.Helpers.Forge.Dictator.operation
rpc_config block ~net_id ~branch command >>=? fun bytes -> rpc_config block ~branch command >>=? fun bytes ->
let signature = Ed25519.sign seckey bytes in let signature = Ed25519.sign seckey bytes in
let signed_bytes = MBytes.concat bytes signature in let signed_bytes = MBytes.concat bytes signature in
let oph = Operation_hash.hash_bytes [ signed_bytes ] in let oph = Operation_hash.hash_bytes [ signed_bytes ] in
Client_node_rpcs.inject_operation Client_node_rpcs.inject_operation
rpc_config signed_bytes >>=? fun injected_oph -> rpc_config ?force ~net_id signed_bytes >>=? fun injected_oph ->
assert (Operation_hash.equal oph injected_oph) ; assert (Operation_hash.equal oph injected_oph) ;
return oph return oph

View File

@ -187,25 +187,25 @@ module Helpers = struct
module Manager = struct module Manager = struct
let operations cctxt let operations cctxt
block ~net_id ~branch ~source ?sourcePubKey ~counter ~fee operations = block ~branch ~source ?sourcePubKey ~counter ~fee operations =
let ops = let ops =
Manager_operations { source ; public_key = sourcePubKey ; Manager_operations { source ; public_key = sourcePubKey ;
counter ; operations ; fee } in counter ; operations ; fee } in
(call_error_service1 cctxt Services.Helpers.Forge.operations block (call_error_service1 cctxt Services.Helpers.Forge.operations block
({net_id ; branch }, Sourced_operations ops)) ({ branch }, Sourced_operations ops))
let transaction cctxt let transaction cctxt
block ~net_id ~branch ~source ?sourcePubKey ~counter block ~branch ~source ?sourcePubKey ~counter
~amount ~destination ?parameters ~fee ()= ~amount ~destination ?parameters ~fee ()=
operations cctxt block ~net_id ~branch ~source ?sourcePubKey ~counter ~fee operations cctxt block ~branch ~source ?sourcePubKey ~counter ~fee
Tezos_context.[Transaction { amount ; parameters ; destination }] Tezos_context.[Transaction { amount ; parameters ; destination }]
let origination cctxt let origination cctxt
block ~net_id ~branch block ~branch
~source ?sourcePubKey ~counter ~source ?sourcePubKey ~counter
~managerPubKey ~balance ~managerPubKey ~balance
?(spendable = true) ?(spendable = true)
?(delegatable = true) ?(delegatable = true)
?delegatePubKey ?script ~fee () = ?delegatePubKey ?script ~fee () =
operations cctxt block ~net_id ~branch ~source ?sourcePubKey ~counter ~fee operations cctxt block ~branch ~source ?sourcePubKey ~counter ~fee
Tezos_context.[ Tezos_context.[
Origination { manager = managerPubKey ; Origination { manager = managerPubKey ;
delegate = delegatePubKey ; delegate = delegatePubKey ;
@ -215,53 +215,53 @@ module Helpers = struct
credit = balance } credit = balance }
] ]
let delegation cctxt let delegation cctxt
block ~net_id ~branch ~source ?sourcePubKey ~counter ~fee delegate = block ~branch ~source ?sourcePubKey ~counter ~fee delegate =
operations cctxt block ~net_id ~branch ~source ?sourcePubKey ~counter ~fee operations cctxt block ~branch ~source ?sourcePubKey ~counter ~fee
Tezos_context.[Delegation delegate] Tezos_context.[Delegation delegate]
end end
module Delegate = struct module Delegate = struct
let operations cctxt let operations cctxt
block ~net_id ~branch ~source operations = block ~branch ~source operations =
let ops = Delegate_operations { source ; operations } in let ops = Delegate_operations { source ; operations } in
(call_error_service1 cctxt Services.Helpers.Forge.operations block (call_error_service1 cctxt Services.Helpers.Forge.operations block
({net_id ; branch}, Sourced_operations ops)) ({ branch }, Sourced_operations ops))
let endorsement cctxt let endorsement cctxt
b ~net_id ~branch ~source ~block ~slot () = b ~branch ~source ~block ~slot () =
operations cctxt b ~net_id ~branch ~source operations cctxt b ~branch ~source
Tezos_context.[Endorsement { block ; slot }] Tezos_context.[Endorsement { block ; slot }]
let proposals cctxt let proposals cctxt
b ~net_id ~branch ~source ~period ~proposals () = b ~branch ~source ~period ~proposals () =
operations cctxt b ~net_id ~branch ~source operations cctxt b ~branch ~source
Tezos_context.[Proposals { period ; proposals }] Tezos_context.[Proposals { period ; proposals }]
let ballot cctxt let ballot cctxt
b ~net_id ~branch ~source ~period ~proposal ~ballot () = b ~branch ~source ~period ~proposal ~ballot () =
operations cctxt b ~net_id ~branch ~source operations cctxt b ~branch ~source
Tezos_context.[Ballot { period ; proposal ; ballot }] Tezos_context.[Ballot { period ; proposal ; ballot }]
end end
module Dictator = struct module Dictator = struct
let operation cctxt let operation cctxt
block ~net_id ~branch operation = block ~branch operation =
let op = Dictator_operation operation in let op = Dictator_operation operation in
(call_error_service1 cctxt Services.Helpers.Forge.operations block (call_error_service1 cctxt Services.Helpers.Forge.operations block
({net_id ; branch}, Sourced_operations op)) ({ branch }, Sourced_operations op))
let activate cctxt let activate cctxt
b ~net_id ~branch hash = b ~branch hash =
operation cctxt b ~net_id ~branch (Activate hash) operation cctxt b ~branch (Activate hash)
let activate_testnet cctxt let activate_testnet cctxt
b ~net_id ~branch hash = b ~branch hash =
operation cctxt b ~net_id ~branch (Activate_testnet hash) operation cctxt b ~branch (Activate_testnet hash)
end end
module Anonymous = struct module Anonymous = struct
let operations cctxt block ~net_id ~branch operations = let operations cctxt block ~branch operations =
(call_error_service1 cctxt Services.Helpers.Forge.operations block (call_error_service1 cctxt Services.Helpers.Forge.operations block
({net_id ; branch}, Anonymous_operations operations)) ({ branch }, Anonymous_operations operations))
let seed_nonce_revelation cctxt let seed_nonce_revelation cctxt
block ~net_id ~branch ~level ~nonce () = block ~branch ~level ~nonce () =
operations cctxt block ~net_id ~branch [Seed_nonce_revelation { level ; nonce }] operations cctxt block ~branch [Seed_nonce_revelation { level ; nonce }]
let faucet cctxt let faucet cctxt
block ~net_id ~branch ~id () = block ~branch ~id () =
let nonce = Sodium.Random.Bigbytes.generate 16 in let nonce = Sodium.Random.Bigbytes.generate 16 in
operations cctxt block ~net_id ~branch [Faucet { id ; nonce }] operations cctxt block ~branch [Faucet { id ; nonce }]
end end
let empty_proof_of_work_nonce = let empty_proof_of_work_nonce =
MBytes.of_string MBytes.of_string

View File

@ -201,7 +201,6 @@ module Helpers : sig
val operations: val operations:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:Contract.t -> source:Contract.t ->
?sourcePubKey:public_key -> ?sourcePubKey:public_key ->
@ -212,7 +211,6 @@ module Helpers : sig
val transaction: val transaction:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:Contract.t -> source:Contract.t ->
?sourcePubKey:public_key -> ?sourcePubKey:public_key ->
@ -225,7 +223,6 @@ module Helpers : sig
val origination: val origination:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:Contract.t -> source:Contract.t ->
?sourcePubKey:public_key -> ?sourcePubKey:public_key ->
@ -242,7 +239,6 @@ module Helpers : sig
val delegation: val delegation:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:Contract.t -> source:Contract.t ->
?sourcePubKey:public_key -> ?sourcePubKey:public_key ->
@ -255,21 +251,18 @@ module Helpers : sig
val operation: val operation:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
dictator_operation -> dictator_operation ->
MBytes.t tzresult Lwt.t MBytes.t tzresult Lwt.t
val activate: val activate:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
Protocol_hash.t -> Protocol_hash.t ->
MBytes.t tzresult Lwt.t MBytes.t tzresult Lwt.t
val activate_testnet: val activate_testnet:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
Protocol_hash.t -> Protocol_hash.t ->
MBytes.t tzresult Lwt.t MBytes.t tzresult Lwt.t
@ -278,7 +271,6 @@ module Helpers : sig
val operations: val operations:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:public_key -> source:public_key ->
delegate_operation list -> delegate_operation list ->
@ -286,7 +278,6 @@ module Helpers : sig
val endorsement: val endorsement:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:public_key -> source:public_key ->
block:Block_hash.t -> block:Block_hash.t ->
@ -295,7 +286,6 @@ module Helpers : sig
val proposals: val proposals:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:public_key -> source:public_key ->
period:Voting_period.t -> period:Voting_period.t ->
@ -304,7 +294,6 @@ module Helpers : sig
val ballot: val ballot:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
source:public_key -> source:public_key ->
period:Voting_period.t -> period:Voting_period.t ->
@ -316,14 +305,12 @@ module Helpers : sig
val operations: val operations:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
anonymous_operation list -> anonymous_operation list ->
MBytes.t tzresult Lwt.t MBytes.t tzresult Lwt.t
val seed_nonce_revelation: val seed_nonce_revelation:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
level:Raw_level.t -> level:Raw_level.t ->
nonce:Nonce.t -> nonce:Nonce.t ->
@ -331,7 +318,6 @@ module Helpers : sig
val faucet: val faucet:
Client_rpcs.config -> Client_rpcs.config ->
block -> block ->
net_id:Net_id.t ->
branch:Block_hash.t -> branch:Block_hash.t ->
id:public_key_hash -> id:public_key_hash ->
unit -> MBytes.t tzresult Lwt.t unit -> MBytes.t tzresult Lwt.t

View File

@ -55,7 +55,6 @@ module Fitness : DATA with type t = MBytes.t list
module Operation : sig module Operation : sig
type shell_header = { type shell_header = {
net_id: Net_id.t ;
branch: Block_hash.t ; branch: Block_hash.t ;
(** The operation is only valid in a branch containing the (** The operation is only valid in a branch containing the
block [branch]. *) block [branch]. *)

View File

@ -36,8 +36,6 @@ type t = {
type block_error = type block_error =
| Cannot_parse_operation of Operation_hash.t | Cannot_parse_operation of Operation_hash.t
| Invalid_fitness of { expected: Fitness.t ; found: Fitness.t } | Invalid_fitness of { expected: Fitness.t ; found: Fitness.t }
| Inconsistent_netid of { operation: Operation_hash.t ;
expected: Net_id.t ; found: Net_id.t }
| Non_increasing_timestamp | Non_increasing_timestamp
| Non_increasing_fitness | Non_increasing_fitness
| Invalid_level of { expected: Int32.t ; found: Int32.t } | Invalid_level of { expected: Int32.t ; found: Int32.t }
@ -147,15 +145,6 @@ let pp_block_error ppf = function
\ found %a@]" \ found %a@]"
Fitness.pp expected Fitness.pp expected
Fitness.pp found Fitness.pp found
| Inconsistent_netid { operation ; expected ; found } ->
Format.fprintf ppf
"@[<v 2>The network identifier of the operation %a is not \
\ constitent with the network identifier of the block: @ \
\ expected: %a@ \
\ found: %a@]"
Operation_hash.pp_short operation
Net_id.pp expected
Net_id.pp found
| Non_increasing_timestamp -> | Non_increasing_timestamp ->
Format.fprintf ppf "Non increasing timestamp" Format.fprintf ppf "Non increasing timestamp"
| Non_increasing_fitness -> | Non_increasing_fitness ->
@ -334,16 +323,6 @@ let apply_block
check_header pred_header hash header >>=? fun () -> check_header pred_header hash header >>=? fun () ->
let operation_hashes = List.map (List.map Operation.hash) operations in let operation_hashes = List.map (List.map Operation.hash) operations in
check_liveness net_state pred hash operation_hashes operations >>=? fun () -> check_liveness net_state pred hash operation_hashes operations >>=? fun () ->
iter_p (iter_p (fun op ->
let op_hash = Operation.hash op in
fail_unless
(Net_id.equal op.shell.net_id header.shell.net_id)
(invalid_block hash @@ Inconsistent_netid {
operation = op_hash ;
expected = header.shell.net_id ;
found = op.shell.net_id ;
})))
operations >>=? fun () ->
map2_s (map2_s begin fun op_hash raw -> map2_s (map2_s begin fun op_hash raw ->
Lwt.return (Proto.parse_operation op_hash raw) Lwt.return (Proto.parse_operation op_hash raw)
|> trace (invalid_block hash (Cannot_parse_operation op_hash)) |> trace (invalid_block hash (Cannot_parse_operation op_hash))

View File

@ -12,8 +12,6 @@ type t
type block_error = type block_error =
| Cannot_parse_operation of Operation_hash.t | Cannot_parse_operation of Operation_hash.t
| Invalid_fitness of { expected: Fitness.t ; found: Fitness.t } | Invalid_fitness of { expected: Fitness.t ; found: Fitness.t }
| Inconsistent_netid of { operation: Operation_hash.t ;
expected: Net_id.t ; found: Net_id.t }
| Non_increasing_timestamp | Non_increasing_timestamp
| Non_increasing_fitness | Non_increasing_fitness
| Invalid_level of { expected: Int32.t ; found: Int32.t } | Invalid_level of { expected: Int32.t ; found: Int32.t }

View File

@ -340,6 +340,18 @@ let state { disk } = disk
let net_state { net_state } = net_state let net_state { net_state } = net_state
let db { global_db } = global_db let db { global_db } = global_db
let find_pending_operation active_nets h =
Net_id.Table.fold
(fun _net_id net_db acc ->
match acc with
| Some _ -> acc
| None ->
if Raw_operation.Table.pending net_db.operation_db.table h then
Some net_db
else None)
active_nets
None
module P2p_reader = struct module P2p_reader = struct
let may_activate global_db state net_id f = let may_activate global_db state net_id f =
@ -473,12 +485,17 @@ module P2p_reader = struct
P2p.try_send global_db.p2p state.conn (Operation p)) P2p.try_send global_db.p2p state.conn (Operation p))
hashes hashes
| Operation operation -> | Operation operation -> begin
may_handle state operation.shell.net_id @@ fun net_db ->
let hash = Operation.hash operation in let hash = Operation.hash operation in
Raw_operation.Table.notify match find_pending_operation state.peer_active_nets hash with
net_db.operation_db.table state.gid hash operation >>= fun () -> | None ->
Lwt.return_unit (* TODO some penalty. *)
Lwt.return_unit
| Some net_db ->
Raw_operation.Table.notify
net_db.operation_db.table state.gid hash operation >>= fun () ->
Lwt.return_unit
end
| Get_protocols hashes -> | Get_protocols hashes ->
Lwt_list.iter_p Lwt_list.iter_p
@ -727,9 +744,7 @@ let inject_block_header net_db h b =
return res return res
let inject_operation net_db h op = let inject_operation net_db h op =
fail_unless assert (Operation_hash.equal h (Operation.hash op)) ;
(Net_id.equal op.Operation.shell.net_id (State.Net.id net_db.net_state))
(failure "Inconsitent net_id in operation") >>=? fun () ->
Raw_operation.Table.inject net_db.operation_db.table h op >>= fun res -> Raw_operation.Table.inject net_db.operation_db.table h op >>= fun res ->
return res return res
@ -809,6 +824,22 @@ module Block_header = struct
and type param := unit) and type param := unit)
end end
let read_block_header { disk ; active_nets } h =
State.read_block disk h >>= function
| Some b ->
Lwt.return_some (State.Block.net_id b, State.Block.header b)
| None ->
Net_id.Table.fold
(fun net_id net_db acc ->
acc >>= function
| Some _ -> acc
| None ->
Block_header.read_opt net_db h >>= function
| None -> Lwt.return_none
| Some bh -> Lwt.return_some (net_id, bh))
active_nets
Lwt.return_none
module Operation_hashes = module Operation_hashes =
Make (Raw_operation_hashes.Table) (struct Make (Raw_operation_hashes.Table) (struct
type t = net_db type t = net_db
@ -822,7 +853,7 @@ module Operations =
end) end)
module Operation = struct module Operation = struct
type t = Operation.t include Operation
include (Make (Raw_operation.Table) (struct include (Make (Raw_operation.Table) (struct
type t = net_db type t = net_db
let proj net = net.operation_db.table let proj net = net.operation_db.table

View File

@ -32,6 +32,9 @@ type net_db
for new head or new operations. *) for new head or new operations. *)
val activate: t -> State.Net.t -> net_db val activate: t -> State.Net.t -> net_db
(** Look for the database of an active network. *)
val get_net: t -> Net_id.t -> net_db option
(** Deactivate a given network. The node will notify its neighbours (** Deactivate a given network. The node will notify its neighbours
that it does not care anymore about this network. *) that it does not care anymore about this network. *)
val deactivate: net_db -> unit Lwt.t val deactivate: net_db -> unit Lwt.t
@ -178,6 +181,10 @@ module Block_header : sig
and type param := unit and type param := unit
end end
(** Lookup for block header in any active networks *)
val read_block_header:
db -> Block_hash.t -> (Net_id.t * Block_header.t) option Lwt.t
(** Index of all the operations of a given block (per validation pass). *) (** Index of all the operations of a given block (per validation pass). *)
module Operations : module Operations :
DISTRIBUTED_DB with type t := net_db DISTRIBUTED_DB with type t := net_db

View File

@ -42,6 +42,8 @@ module type DISTRIBUTED_DB = sig
val inject: t -> key -> value -> bool Lwt.t val inject: t -> key -> value -> bool Lwt.t
val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper
val pending: t -> key -> bool
end end
module type DISK_TABLE = sig module type DISK_TABLE = sig
@ -294,6 +296,12 @@ end = struct
let input = Watcher.create_input () in let input = Watcher.create_input () in
{ scheduler ; disk ; memory ; input ; global_input } { scheduler ; disk ; memory ; input ; global_input }
let pending s k =
match Memory_table.find s.memory k with
| exception Not_found -> false
| Found _ -> false
| Pending _ -> true
end end
module type REQUEST = sig module type REQUEST = sig

View File

@ -43,6 +43,8 @@ module type DISTRIBUTED_DB = sig
val inject: t -> key -> value -> bool Lwt.t val inject: t -> key -> value -> bool Lwt.t
val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper
val pending: t -> key -> bool
end end
module type DISK_TABLE = sig module type DISK_TABLE = sig

View File

@ -10,15 +10,13 @@
open Lwt.Infix open Lwt.Infix
open Logging.Node.Worker open Logging.Node.Worker
let inject_operation validator ?force bytes = let inject_operation validator ?force ?net_id bytes =
let t = let t =
match Data_encoding.Binary.of_bytes Operation.encoding bytes with match Data_encoding.Binary.of_bytes Operation.encoding bytes with
| None -> failwith "Can't parse the operation" | None -> failwith "Can't parse the operation"
| Some operation -> | Some op ->
Validator.get Validator.inject_operation validator ?force ?net_id op
validator operation.shell.net_id >>=? fun net_validator -> in
let pv = Net_validator.prevalidator net_validator in
Prevalidator.inject_operation pv ?force operation in
let hash = Operation_hash.hash_bytes [bytes] in let hash = Operation_hash.hash_bytes [bytes] in
Lwt.return (hash, t) Lwt.return (hash, t)
@ -57,7 +55,7 @@ type t = {
MBytes.t -> Operation.t list list -> MBytes.t -> Operation.t list list ->
(Block_hash.t * unit tzresult Lwt.t) tzresult Lwt.t ; (Block_hash.t * unit tzresult Lwt.t) tzresult Lwt.t ;
inject_operation: inject_operation:
?force:bool -> MBytes.t -> ?force:bool -> ?net_id:Net_id.t -> MBytes.t ->
(Operation_hash.t * unit tzresult Lwt.t) Lwt.t ; (Operation_hash.t * unit tzresult Lwt.t) Lwt.t ;
inject_protocol: inject_protocol:
?force:bool -> Protocol.t -> ?force:bool -> Protocol.t ->

View File

@ -44,7 +44,7 @@ module RPC : sig
non strictly increasing fitness. *) non strictly increasing fitness. *)
val inject_operation: val inject_operation:
t -> ?force:bool -> MBytes.t -> t -> ?force:bool -> ?net_id:Net_id.t -> MBytes.t ->
(Operation_hash.t * unit tzresult Lwt.t) Lwt.t (Operation_hash.t * unit tzresult Lwt.t) Lwt.t
val inject_protocol: val inject_protocol:
t -> ?force:bool -> Protocol.t -> t -> ?force:bool -> Protocol.t ->

View File

@ -402,8 +402,9 @@ let build_rpc_directory node =
end >>= RPC.Answer.return in end >>= RPC.Answer.return in
RPC.register0 dir Services.inject_block implementation in RPC.register0 dir Services.inject_block implementation in
let dir = let dir =
let implementation (contents, blocking, force) = let implementation (contents, blocking, net_id, force) =
Node.RPC.inject_operation node ?force contents >>= fun (hash, wait) -> Node.RPC.inject_operation
node ?force ?net_id contents >>= fun (hash, wait) ->
begin begin
(if blocking then wait else return ()) >>=? fun () -> return hash (if blocking then wait else return ()) >>=? fun () -> return hash
end >>= RPC.Answer.return in end >>= RPC.Answer.return in

View File

@ -658,7 +658,7 @@ let inject_operation =
RPCs ubder /blocks/prevalidation for more details on the \ RPCs ubder /blocks/prevalidation for more details on the \
prevalidation context." prevalidation context."
~input: ~input:
(obj3 (obj4
(req "signedOperationContents" (req "signedOperationContents"
(describe ~title: "Tezos signed operation (hex encoded)" (describe ~title: "Tezos signed operation (hex encoded)"
bytes)) bytes))
@ -669,6 +669,7 @@ let inject_operation =
(pre-)validated before answering. (default: true)" (pre-)validated before answering. (default: true)"
bool) bool)
true) true)
(opt "net_id" Net_id.encoding)
(opt "force" (opt "force"
(describe (describe
~description: ~description:

View File

@ -185,7 +185,8 @@ val inject_block:
val inject_operation: val inject_operation:
(unit, unit, (unit, unit,
(MBytes.t * bool * bool option), Operation_hash.t tzresult) RPC.service (MBytes.t * bool * Net_id.t option * bool option),
Operation_hash.t tzresult) RPC.service
val inject_protocol: val inject_protocol:
(unit, unit, (unit, unit,

View File

@ -420,7 +420,6 @@ let context pv = pv.context ()
let shutdown pv = pv.shutdown () let shutdown pv = pv.shutdown ()
let inject_operation pv ?(force = false) (op: Operation.t) = let inject_operation pv ?(force = false) (op: Operation.t) =
let net_id = State.Net.id (Distributed_db.net_state pv.net_db) in
let wrap_error h map = let wrap_error h map =
begin begin
try return (snd (Operation_hash.Map.find h map)) try return (snd (Operation_hash.Map.find h map))
@ -428,9 +427,6 @@ let inject_operation pv ?(force = false) (op: Operation.t) =
failwith "unexpected protocol result" failwith "unexpected protocol result"
end >>=? fun errors -> end >>=? fun errors ->
Lwt.return (Error errors) in Lwt.return (Error errors) in
fail_unless (Net_id.equal net_id op.shell.net_id)
(failure
"Prevalidator.inject_operation: invalid network") >>=? fun () ->
pv.prevalidate_operations force [op] >>=? function pv.prevalidate_operations force [op] >>=? function
| ([h], { applied = [h', _] }) when Operation_hash.equal h h' -> | ([h], { applied = [h', _] }) when Operation_hash.equal h h' ->
return () return ()

View File

@ -77,3 +77,31 @@ let shutdown { active_nets ; block_validator } =
let watcher { valid_block_input } = let watcher { valid_block_input } =
Watcher.create_stream valid_block_input Watcher.create_stream valid_block_input
let inject_operation v ?(force = false) ?net_id op =
begin
match net_id with
| None -> begin
Distributed_db.read_block_header
v.db op.Operation.shell.branch >>= function
| None ->
failwith "Unknown branch (%a), cannot inject the operation."
Block_hash.pp_short op.shell.branch
| Some (net_id, _bh) -> get v net_id
end
| Some net_id ->
get v net_id >>=? fun nv ->
if force then
return nv
else
Distributed_db.Block_header.known
(Net_validator.net_db nv)
op.shell.branch >>= function
| true ->
return nv
| false ->
failwith "Unknown branch (%a), cannot inject the operation."
Block_hash.pp_short op.shell.branch
end >>=? fun nv ->
let pv = Net_validator.prevalidator nv in
Prevalidator.inject_operation pv ~force op

View File

@ -35,3 +35,9 @@ val validate_block:
(** Monitor all the valid block (for all activate networks). *) (** Monitor all the valid block (for all activate networks). *)
val watcher: t -> State.Block.t Lwt_stream.t * Watcher.stopper val watcher: t -> State.Block.t Lwt_stream.t * Watcher.stopper
val inject_operation:
t ->
?force:bool ->
?net_id:Net_id.t ->
Operation.t -> unit tzresult Lwt.t

View File

@ -110,18 +110,15 @@ end
module Operation = struct module Operation = struct
type shell_header = { type shell_header = {
net_id: Net_id.t ;
branch: Block_hash.t ; branch: Block_hash.t ;
} }
let shell_header_encoding = let shell_header_encoding =
let open Data_encoding in let open Data_encoding in
conv conv
(fun { net_id ; branch } -> net_id, branch) (fun { branch } -> branch)
(fun (net_id, branch) -> { net_id ; branch }) (fun branch -> { branch })
(obj2 (obj1 (req "branch" Block_hash.encoding))
(req "net_id" Net_id.encoding)
(req "branch" Block_hash.encoding))
type t = { type t = {
shell: shell_header ; shell: shell_header ;
@ -142,7 +139,7 @@ module Operation = struct
let compare o1 o2 = let compare o1 o2 =
let (>>) x y = if x = 0 then y () else x in let (>>) x y = if x = 0 then y () else x in
Net_id.compare o1.shell.net_id o1.shell.net_id >> fun () -> Block_hash.compare o1.shell.branch o1.shell.branch >> fun () ->
MBytes.compare o1.proto o2.proto MBytes.compare o1.proto o2.proto
let equal b1 b2 = compare b1 b2 = 0 let equal b1 b2 = compare b1 b2 = 0

View File

@ -48,7 +48,6 @@ end
module Operation : sig module Operation : sig
type shell_header = { type shell_header = {
net_id: Net_id.t ;
branch: Block_hash.t ; branch: Block_hash.t ;
} }
val shell_header_encoding: shell_header Data_encoding.t val shell_header_encoding: shell_header Data_encoding.t

View File

@ -260,7 +260,6 @@ module Protocol = struct
Client_node_rpcs.Blocks.info !rpc_config block >>=? fun block_info -> Client_node_rpcs.Blocks.info !rpc_config block >>=? fun block_info ->
Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun next_level -> Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun next_level ->
Client_proto_rpcs.Helpers.Forge.Delegate.proposals !rpc_config block Client_proto_rpcs.Helpers.Forge.Delegate.proposals !rpc_config block
~net_id:block_info.net_id
~branch:block_info.hash ~branch:block_info.hash
~source:pk ~source:pk
~period:next_level.voting_period ~period:next_level.voting_period
@ -273,7 +272,6 @@ module Protocol = struct
Client_node_rpcs.Blocks.info !rpc_config block >>=? fun block_info -> Client_node_rpcs.Blocks.info !rpc_config block >>=? fun block_info ->
Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun next_level -> Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun next_level ->
Client_proto_rpcs.Helpers.Forge.Delegate.ballot !rpc_config block Client_proto_rpcs.Helpers.Forge.Delegate.ballot !rpc_config block
~net_id:block_info.net_id
~branch:block_info.hash ~branch:block_info.hash
~source:pk ~source:pk
~period:next_level.voting_period ~period:next_level.voting_period
@ -458,10 +456,9 @@ module Endorse = struct
source source
slot = slot =
let block = Client_rpcs.last_mined_block block in let block = Client_rpcs.last_mined_block block in
Client_node_rpcs.Blocks.info !rpc_config block >>=? fun { hash ; net_id } -> Client_node_rpcs.Blocks.info !rpc_config block >>=? fun { hash } ->
Client_proto_rpcs.Helpers.Forge.Delegate.endorsement !rpc_config Client_proto_rpcs.Helpers.Forge.Delegate.endorsement !rpc_config
block block
~net_id:net_id
~branch:hash ~branch:hash
~source ~source
~block:hash ~block:hash

View File

@ -54,7 +54,7 @@ let incr_timestamp timestamp =
let operation op = let operation op =
let op : Operation.t = { let op : Operation.t = {
shell = { net_id ; branch = genesis_block } ; shell = { branch = genesis_block } ;
proto = MBytes.of_string op ; proto = MBytes.of_string op ;
} in } in
Operation.hash op, Operation.hash op,

View File

@ -63,7 +63,7 @@ let net_id = Net_id.of_block_hash genesis_block
(** Operation store *) (** Operation store *)
let make proto : Tezos_data.Operation.t = let make proto : Tezos_data.Operation.t =
{ shell = { net_id ; branch = genesis_block } ; proto } { shell = { branch = genesis_block } ; proto }
let op1 = make (MBytes.of_string "Capadoce") let op1 = make (MBytes.of_string "Capadoce")
let oph1 = Tezos_data.Operation.hash op1 let oph1 = Tezos_data.Operation.hash op1