Get rid of forced operation injection

This commit is contained in:
Benjamin Canou 2017-11-23 16:39:33 +01:00 committed by Grégoire Henry
parent dee86fb462
commit 566a92197b
20 changed files with 82 additions and 116 deletions

View File

@ -24,9 +24,9 @@ let inject_block cctxt
call_err_service0 cctxt Services.inject_block call_err_service0 cctxt Services.inject_block
{ raw ; blocking = not async ; force ; net_id ; operations } { raw ; blocking = not async ; force ; net_id ; operations }
let inject_operation cctxt ?(async = false) ?force ?net_id operation = let inject_operation cctxt ?(async = false) ?net_id operation =
call_err_service0 cctxt Services.inject_operation call_err_service0 cctxt Services.inject_operation
(operation, not async, net_id, force) (operation, not async, net_id)
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

@ -28,7 +28,7 @@ val inject_block:
val inject_operation: val inject_operation:
#Client_rpcs.ctxt -> #Client_rpcs.ctxt ->
?async:bool -> ?force:bool -> ?net_id:Net_id.t -> ?async:bool -> ?net_id:Net_id.t ->
MBytes.t -> MBytes.t ->
Operation_hash.t tzresult Lwt.t Operation_hash.t tzresult Lwt.t

View File

@ -89,7 +89,7 @@ let get_signing_slots cctxt ?max_priority block delegate level =
return slots return slots
let inject_endorsement (cctxt : Client_commands.full_context) let inject_endorsement (cctxt : Client_commands.full_context)
block level ?async ?force block level ?async
src_sk source slot = src_sk source slot =
let block = Client_rpcs.last_baked_block block in let block = Client_rpcs.last_baked_block block in
Client_node_rpcs.Blocks.info cctxt block >>=? fun bi -> Client_node_rpcs.Blocks.info cctxt block >>=? fun bi ->
@ -102,7 +102,7 @@ let inject_endorsement (cctxt : Client_commands.full_context)
() >>=? 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 ?force ?async ~net_id:bi.net_id signed_bytes >>=? fun oph -> cctxt ?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
@ -122,7 +122,7 @@ let check_endorsement cctxt level slot =
let forge_endorsement (cctxt : Client_commands.full_context) let forge_endorsement (cctxt : Client_commands.full_context)
block ?(force = false) block
~src_sk ?slot ?max_priority src_pk = ~src_sk ?slot ?max_priority src_pk =
let block = Client_rpcs.last_baked_block block in let block = Client_rpcs.last_baked_block block in
let src_pkh = Ed25519.Public_key.hash src_pk in let src_pkh = Ed25519.Public_key.hash src_pk in
@ -136,12 +136,9 @@ let forge_endorsement (cctxt : Client_commands.full_context)
| slot::_ -> return slot | slot::_ -> return slot
| [] -> cctxt#error "No slot found at level %a" Raw_level.pp level | [] -> cctxt#error "No slot found at level %a" Raw_level.pp level
end >>=? fun slot -> end >>=? fun slot ->
begin check_endorsement cctxt level slot >>=? fun () ->
if force then return ()
else check_endorsement cctxt level slot
end >>=? fun () ->
inject_endorsement cctxt inject_endorsement cctxt
block level ~force block level
src_sk src_pk slot src_sk src_pk slot
@ -290,7 +287,7 @@ let endorse cctxt state =
lwt_debug "Endorsing %a for %s (slot %d)!" lwt_debug "Endorsing %a for %s (slot %d)!"
Block_hash.pp_short hash name slot >>= fun () -> Block_hash.pp_short hash name slot >>= fun () ->
inject_endorsement cctxt inject_endorsement cctxt
b level ~async:true ~force:true b level ~async:true
sk pk slot >>=? fun oph -> sk pk slot >>=? fun oph ->
cctxt#message cctxt#message
"Injected endorsement for block '%a' \ "Injected endorsement for block '%a' \

View File

@ -10,7 +10,6 @@
val forge_endorsement: val forge_endorsement:
Client_commands.full_context -> Client_commands.full_context ->
Client_proto_rpcs.block -> Client_proto_rpcs.block ->
?force:bool ->
src_sk:secret_key -> src_sk:secret_key ->
?slot:int -> ?slot:int ->
?max_priority:int -> ?max_priority:int ->

View File

@ -379,7 +379,7 @@ let insert_block
begin begin
safe_get_unrevealed_nonces cctxt (`Hash bi.hash) >>= fun nonces -> safe_get_unrevealed_nonces cctxt (`Hash bi.hash) >>= fun nonces ->
Client_baking_revelation.forge_seed_nonce_revelation Client_baking_revelation.forge_seed_nonce_revelation
cctxt ~force:true (`Hash bi.hash) (List.map snd nonces) cctxt (`Hash bi.hash) (List.map snd nonces)
end >>= fun _ignore_error -> end >>= fun _ignore_error ->
if Fitness.compare state.best.fitness bi.fitness < 0 then begin if Fitness.compare state.best.fitness bi.fitness < 0 then begin
state.best <- bi ; state.best <- bi ;

View File

@ -30,10 +30,10 @@ let bake_block (cctxt : Client_commands.full_context) block
cctxt#message "Injected block %a" Block_hash.pp_short block_hash >>= fun () -> cctxt#message "Injected block %a" Block_hash.pp_short block_hash >>= fun () ->
return () return ()
let endorse_block cctxt ?force ?max_priority delegate = let endorse_block cctxt ?max_priority delegate =
Client_keys.get_key cctxt delegate >>=? fun (_src_name, src_pk, src_sk) -> Client_keys.get_key cctxt delegate >>=? fun (_src_name, src_pk, src_sk) ->
Client_baking_endorsement.forge_endorsement cctxt Client_baking_endorsement.forge_endorsement cctxt
cctxt#block ?force ?max_priority ~src_sk src_pk >>=? fun oph -> cctxt#block ?max_priority ~src_sk src_pk >>=? fun oph ->
cctxt#answer "Operation successfully injected in the node." >>= fun () -> cctxt#answer "Operation successfully injected in the node." >>= fun () ->
cctxt#answer "Operation hash is '%a'." Operation_hash.pp oph >>= fun () -> cctxt#answer "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
return () return ()
@ -49,14 +49,14 @@ let get_predecessor_cycle (cctxt : #Client_commands.logger) cycle =
Cycle.pp cycle Cycle.pp cycle
| Some cycle -> Lwt.return cycle | Some cycle -> Lwt.return cycle
let do_reveal cctxt ?force block blocks = let do_reveal cctxt block blocks =
let nonces = List.map snd blocks in let nonces = List.map snd blocks in
Client_baking_revelation.forge_seed_nonce_revelation cctxt Client_baking_revelation.forge_seed_nonce_revelation cctxt
block ?force nonces >>=? fun () -> block nonces >>=? fun () ->
Client_proto_nonces.dels cctxt (List.map fst blocks) >>=? fun () -> Client_proto_nonces.dels cctxt (List.map fst blocks) >>=? fun () ->
return () return ()
let reveal_block_nonces (cctxt : Client_commands.full_context) ?force block_hashes = let reveal_block_nonces (cctxt : Client_commands.full_context) block_hashes =
Lwt_list.filter_map_p Lwt_list.filter_map_p
(fun hash -> (fun hash ->
Lwt.catch Lwt.catch
@ -80,13 +80,13 @@ let reveal_block_nonces (cctxt : Client_commands.full_context) ?force block_hash
| Some nonce -> | Some nonce ->
return (Some (bi.hash, (bi.level.level, nonce)))) return (Some (bi.hash, (bi.level.level, nonce))))
block_infos >>=? fun blocks -> block_infos >>=? fun blocks ->
do_reveal cctxt ?force cctxt#block blocks do_reveal cctxt cctxt#block blocks
let reveal_nonces cctxt ?force () = let reveal_nonces cctxt () =
let block = Client_rpcs.last_baked_block cctxt#block in let block = Client_rpcs.last_baked_block cctxt#block in
Client_baking_forge.get_unrevealed_nonces Client_baking_forge.get_unrevealed_nonces
cctxt ?force block >>=? fun nonces -> cctxt block >>=? fun nonces ->
do_reveal cctxt ?force cctxt#block nonces do_reveal cctxt cctxt#block nonces
let run_daemon cctxt ?max_priority ~endorsement_delay delegates ~endorsement ~baking ~denunciation = let run_daemon cctxt ?max_priority ~endorsement_delay delegates ~endorsement ~baking ~denunciation =
Client_baking_daemon.run cctxt Client_baking_daemon.run cctxt

View File

@ -21,7 +21,6 @@ val bake_block:
(** Endorse a block *) (** Endorse a block *)
val endorse_block: val endorse_block:
Client_commands.full_context -> Client_commands.full_context ->
?force:bool ->
?max_priority:int -> ?max_priority:int ->
Client_keys.Public_key_hash.t -> Client_keys.Public_key_hash.t ->
unit Error_monad.tzresult Lwt.t unit Error_monad.tzresult Lwt.t
@ -35,14 +34,12 @@ val get_predecessor_cycle:
(** Reveal the nonces used to bake each block in the given list *) (** Reveal the nonces used to bake each block in the given list *)
val reveal_block_nonces : val reveal_block_nonces :
Client_commands.full_context -> Client_commands.full_context ->
?force:bool ->
Block_hash.t list -> Block_hash.t list ->
unit Error_monad.tzresult Lwt.t unit Error_monad.tzresult Lwt.t
(** Reveal all unrevealed nonces *) (** Reveal all unrevealed nonces *)
val reveal_nonces : val reveal_nonces :
Client_commands.full_context -> Client_commands.full_context ->
?force:bool ->
unit -> unit ->
unit Error_monad.tzresult Lwt.t unit Error_monad.tzresult Lwt.t

View File

@ -29,14 +29,13 @@ let commands () =
else (endorsement, baking, denunciation) in else (endorsement, baking, denunciation) in
run_daemon cctxt ?max_priority ~endorsement_delay ~endorsement ~baking ~denunciation delegates) ; run_daemon cctxt ?max_priority ~endorsement_delay ~endorsement ~baking ~denunciation delegates) ;
command ~group ~desc: "Forge and inject an endorsement operation" command ~group ~desc: "Forge and inject an endorsement operation"
(args2 force_switch max_priority_arg) (args1 max_priority_arg)
(prefixes [ "endorse"; "for" ] (prefixes [ "endorse"; "for" ]
@@ Client_keys.Public_key_hash.alias_param @@ Client_keys.Public_key_hash.alias_param
~name:"baker" ~desc: "name of the delegate owning the endorsement right" ~name:"baker" ~desc: "name of the delegate owning the endorsement right"
@@ stop) @@ stop)
(fun (force, max_priority) (_, delegate) cctxt -> (fun max_priority (_, delegate) cctxt ->
endorse_block cctxt endorse_block cctxt ?max_priority delegate) ;
~force ?max_priority delegate) ;
command ~group ~desc: "Forge and inject block using the delegate rights" command ~group ~desc: "Forge and inject block using the delegate rights"
(args3 max_priority_arg force_switch free_baking_switch) (args3 max_priority_arg force_switch free_baking_switch)
(prefixes [ "bake"; "for" ] (prefixes [ "bake"; "for" ]
@ -47,16 +46,15 @@ let commands () =
bake_block cctxt cctxt#block bake_block cctxt cctxt#block
~force ?max_priority ~free_baking delegate) ; ~force ?max_priority ~free_baking delegate) ;
command ~group ~desc: "Forge and inject a seed-nonce revelation operation" command ~group ~desc: "Forge and inject a seed-nonce revelation operation"
(args1 force_switch) no_options
(prefixes [ "reveal"; "nonce"; "for" ] (prefixes [ "reveal"; "nonce"; "for" ]
@@ seq_of_param Block_hash.param) @@ seq_of_param Block_hash.param)
(fun force block_hashes cctxt -> (fun () block_hashes cctxt ->
reveal_block_nonces cctxt reveal_block_nonces cctxt block_hashes) ;
~force block_hashes) ;
command ~group ~desc: "Forge and inject redemption operations" command ~group ~desc: "Forge and inject redemption operations"
(args1 force_switch) no_options
(prefixes [ "reveal"; "nonces" ] (prefixes [ "reveal"; "nonces" ]
@@ stop) @@ stop)
(fun force cctxt -> (fun () cctxt ->
reveal_nonces cctxt ~force ()) ; reveal_nonces cctxt ()) ;
] ]

View File

@ -9,7 +9,7 @@
open Tezos_context open Tezos_context
let inject_seed_nonce_revelation rpc_config block ?force ?async nonces = let inject_seed_nonce_revelation rpc_config block ?async nonces =
let operations = let operations =
List.map List.map
(fun (level, nonce) -> (fun (level, nonce) ->
@ -19,13 +19,13 @@ let inject_seed_nonce_revelation rpc_config block ?force ?async nonces =
Client_proto_rpcs.Helpers.Forge.Anonymous.operations rpc_config Client_proto_rpcs.Helpers.Forge.Anonymous.operations rpc_config
block ~branch:bi.hash operations >>=? fun bytes -> block ~branch:bi.hash operations >>=? fun bytes ->
Client_node_rpcs.inject_operation Client_node_rpcs.inject_operation
rpc_config ?force ?async ~net_id:bi.net_id rpc_config ?async ~net_id:bi.net_id
bytes >>=? fun oph -> bytes >>=? fun oph ->
return oph return oph
let forge_seed_nonce_revelation let forge_seed_nonce_revelation
(cctxt: Client_commands.full_context) (cctxt: Client_commands.full_context)
block ?(force = false) nonces = block nonces =
Client_node_rpcs.Blocks.hash cctxt block >>=? fun hash -> Client_node_rpcs.Blocks.hash cctxt block >>=? fun hash ->
match nonces with match nonces with
| [] -> | [] ->
@ -33,7 +33,7 @@ let forge_seed_nonce_revelation
Block_hash.pp_short hash >>= fun () -> Block_hash.pp_short hash >>= fun () ->
return () return ()
| _ -> | _ ->
inject_seed_nonce_revelation cctxt block ~force nonces >>=? fun oph -> inject_seed_nonce_revelation cctxt block nonces >>=? fun oph ->
cctxt#answer cctxt#answer
"Operation successfully injected %d revelation(s) for %a." "Operation successfully injected %d revelation(s) for %a."
(List.length nonces) (List.length nonces)

View File

@ -10,7 +10,6 @@
val inject_seed_nonce_revelation: val inject_seed_nonce_revelation:
#Client_rpcs.ctxt -> #Client_rpcs.ctxt ->
Client_proto_rpcs.block -> Client_proto_rpcs.block ->
?force:bool ->
?async:bool -> ?async:bool ->
(Raw_level.t * Nonce.t) list -> (Raw_level.t * Nonce.t) list ->
Operation_hash.t tzresult Lwt.t Operation_hash.t tzresult Lwt.t
@ -18,6 +17,5 @@ val inject_seed_nonce_revelation:
val forge_seed_nonce_revelation: val forge_seed_nonce_revelation:
Client_commands.full_context -> Client_commands.full_context ->
Client_proto_rpcs.block -> Client_proto_rpcs.block ->
?force:bool ->
(Raw_level.t * Nonce.t) list -> (Raw_level.t * Nonce.t) list ->
unit tzresult Lwt.t unit tzresult Lwt.t

View File

@ -43,7 +43,7 @@ let parse_expression arg =
(Michelson_v1_parser.parse_expression arg)) (Michelson_v1_parser.parse_expression arg))
let transfer rpc_config let transfer rpc_config
block ?force ?branch block ?branch
~source ~src_pk ~src_sk ~destination ?arg ~amount ~fee () = ~source ~src_pk ~src_sk ~destination ?arg ~amount ~fee () =
get_branch rpc_config block branch >>=? fun (net_id, branch) -> get_branch rpc_config block branch >>=? fun (net_id, branch) ->
begin match arg with begin match arg with
@ -66,11 +66,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 ~net_id signed_bytes >>=? fun injected_oph -> rpc_config ~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 ?net_id ~block ?signature bytes = let originate rpc_config ?net_id ~block ?signature bytes =
let signed_bytes = let signed_bytes =
match signature with match signature with
| None -> bytes | None -> bytes
@ -81,7 +81,7 @@ let originate rpc_config ?force ?net_id ~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 ?net_id signed_bytes >>=? fun injected_oph -> rpc_config ?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 ->
@ -89,13 +89,8 @@ let originate rpc_config ?force ?net_id ~block ?signature bytes =
"The origination introduced %d contracts instead of one." "The origination introduced %d contracts instead of one."
(List.length contracts) (List.length contracts)
let operation_submitted_message (cctxt : #Client_commands.logger) ?(force=false) ?(contracts = []) oph = let operation_submitted_message (cctxt : #Client_commands.logger) ?(contracts = []) oph =
begin cctxt#message "Operation successfully injected in the node." >>= fun () ->
if not force then
cctxt#message "Operation successfully injected in the node."
else
Lwt.return_unit
end >>= fun () ->
cctxt#message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () -> cctxt#message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
Lwt_list.iter_s Lwt_list.iter_s
(fun c -> (fun c ->
@ -104,7 +99,7 @@ let operation_submitted_message (cctxt : #Client_commands.logger) ?(force=false)
Contract.pp c) Contract.pp c)
contracts >>= return contracts >>= return
let originate_account ?(force=false) ?branch let originate_account ?branch
~source ~src_pk ~src_sk ~manager_pkh ~source ~src_pk ~src_sk ~manager_pkh
?delegatable ?delegate ~balance ~fee block rpc_config () = ?delegatable ?delegate ~balance ~fee block rpc_config () =
get_branch rpc_config block branch >>=? fun (net_id, branch) -> get_branch rpc_config block branch >>=? fun (net_id, branch) ->
@ -116,16 +111,16 @@ let originate_account ?(force=false) ?branch
~counter ~balance ~spendable:true ~counter ~balance ~spendable:true
?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 ~net_id ~signature bytes originate rpc_config ~block ~net_id ~signature bytes
let faucet ?force ?branch ~manager_pkh block rpc_config () = let faucet ?branch ~manager_pkh block rpc_config () =
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 ~branch ~id:manager_pkh () >>=? fun bytes -> rpc_config block ~branch ~id:manager_pkh () >>=? fun bytes ->
originate rpc_config ?force ~net_id ~block bytes originate rpc_config ~net_id ~block bytes
let delegate_contract rpc_config let delegate_contract rpc_config
block ?force ?branch block ?branch
~source ?src_pk ~manager_sk ~source ?src_pk ~manager_sk
~fee delegate_opt = ~fee delegate_opt =
get_branch rpc_config block branch >>=? fun (net_id, branch) -> get_branch rpc_config block branch >>=? fun (net_id, branch) ->
@ -139,7 +134,7 @@ let delegate_contract rpc_config
let signed_bytes = Ed25519.Signature.concat bytes signature in let signed_bytes = Ed25519.Signature.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 ~net_id signed_bytes >>=? fun injected_oph -> rpc_config ~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
@ -209,7 +204,6 @@ let save_contract ~force cctxt alias_name contract =
let originate_contract let originate_contract
~fee ~fee
~delegate ~delegate
?(force=false)
?(delegatable=true) ?(delegatable=true)
?(spendable=false) ?(spendable=false)
~initial_storage ~initial_storage
@ -234,4 +228,4 @@ let originate_contract
~delegatable ?delegatePubKey:delegate ~delegatable ?delegatePubKey:delegate
~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 cctxt ~force ~block ~signature bytes originate cctxt ~block ~signature bytes

View File

@ -44,7 +44,6 @@ val set_delegate :
val operation_submitted_message : val operation_submitted_message :
#Client_commands.logger -> #Client_commands.logger ->
?force:bool ->
Operation_hash.t -> Operation_hash.t ->
unit tzresult Lwt.t unit tzresult Lwt.t
@ -55,7 +54,6 @@ val source_to_keys:
(public_key * secret_key) tzresult Lwt.t (public_key * secret_key) tzresult Lwt.t
val originate_account : val originate_account :
?force:bool ->
?branch:int -> ?branch:int ->
source:Contract.t -> source:Contract.t ->
src_pk:public_key -> src_pk:public_key ->
@ -78,7 +76,6 @@ val save_contract :
val operation_submitted_message : val operation_submitted_message :
#Client_commands.logger -> #Client_commands.logger ->
?force:bool ->
?contracts:Contract.t list -> ?contracts:Contract.t list ->
Operation_hash.t -> Operation_hash.t ->
unit tzresult Lwt.t unit tzresult Lwt.t
@ -86,7 +83,6 @@ val operation_submitted_message :
val originate_contract: val originate_contract:
fee:Tez.t -> fee:Tez.t ->
delegate:public_key_hash option -> delegate:public_key_hash option ->
?force:bool ->
?delegatable:bool -> ?delegatable:bool ->
?spendable:bool -> ?spendable:bool ->
initial_storage:string -> initial_storage:string ->
@ -100,7 +96,6 @@ val originate_contract:
(Operation_hash.t * Contract.t) tzresult Lwt.t (Operation_hash.t * Contract.t) tzresult Lwt.t
val faucet : val faucet :
?force:bool ->
?branch:int -> ?branch:int ->
manager_pkh:public_key_hash -> manager_pkh:public_key_hash ->
Client_rpcs.block -> Client_rpcs.block ->
@ -110,7 +105,6 @@ val faucet :
val transfer : val transfer :
#Client_rpcs.ctxt -> #Client_rpcs.ctxt ->
Client_proto_rpcs.block -> Client_proto_rpcs.block ->
?force:bool ->
?branch:int -> ?branch:int ->
source:Contract.t -> source:Contract.t ->
src_pk:public_key -> src_pk:public_key ->

View File

@ -116,17 +116,17 @@ let commands () =
end ; end ;
command ~group ~desc: "set the delegate of a contract" command ~group ~desc: "set the delegate of a contract"
(args2 fee_arg force_switch) (args1 fee_arg)
(prefixes [ "set" ; "delegate" ; "for" ] (prefixes [ "set" ; "delegate" ; "for" ]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ prefix "to" @@ prefix "to"
@@ Public_key_hash.alias_param @@ Public_key_hash.alias_param
~name: "mgr" ~desc: "New delegate of the contract" ~name: "mgr" ~desc: "New delegate of the contract"
@@ stop) @@ stop)
begin fun (fee, force) (_, contract) (_, delegate) cctxt -> begin fun fee (_, contract) (_, delegate) cctxt ->
source_to_keys cctxt cctxt#block contract >>=? fun (src_pk, manager_sk) -> source_to_keys cctxt cctxt#block contract >>=? fun (src_pk, manager_sk) ->
set_delegate ~fee cctxt cctxt#block contract (Some delegate) ~src_pk ~manager_sk >>=? fun oph -> set_delegate ~fee cctxt cctxt#block contract (Some delegate) ~src_pk ~manager_sk >>=? fun oph ->
operation_submitted_message cctxt ~force oph operation_submitted_message cctxt oph
end ; end ;
command ~group ~desc:"open a new account" command ~group ~desc:"open a new account"
@ -153,7 +153,6 @@ let commands () =
~fee ~fee
?delegate ?delegate
~delegatable ~delegatable
~force
~manager_pkh ~manager_pkh
~balance ~balance
~source ~source
@ -163,7 +162,7 @@ let commands () =
cctxt cctxt
() >>=? fun (oph, contract) -> () >>=? fun (oph, contract) ->
save_contract ~force cctxt alias_name contract >>=? fun () -> save_contract ~force cctxt alias_name contract >>=? fun () ->
operation_submitted_message ~force ~contracts:[ contract ] cctxt oph operation_submitted_message ~contracts:[ contract ] cctxt oph
end ; end ;
command ~group ~desc: "Launch a smart contract on the blockchain" command ~group ~desc: "Launch a smart contract on the blockchain"
@ -193,14 +192,14 @@ let commands () =
Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun { expanded = code } -> Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun { expanded = code } ->
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) -> source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
get_pkh cctxt delegate >>=? fun delegate -> get_pkh cctxt delegate >>=? fun delegate ->
originate_contract ~fee ~delegate ~force ~delegatable ~spendable ~initial_storage originate_contract ~fee ~delegate ~delegatable ~spendable ~initial_storage
~manager ~balance ~source ~src_pk ~src_sk ~code cctxt >>= fun errors -> ~manager ~balance ~source ~src_pk ~src_sk ~code cctxt >>= fun errors ->
report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function
| None -> return () | None -> return ()
| Some (oph, contract) -> | Some (oph, contract) ->
save_contract ~force cctxt alias_name contract >>=? fun () -> save_contract ~force cctxt alias_name contract >>=? fun () ->
operation_submitted_message cctxt operation_submitted_message cctxt
~force ~contracts:[contract] oph ~contracts:[contract] oph
end ; end ;
command ~group ~desc: "open a new (free) account" command ~group ~desc: "open a new (free) account"
@ -214,14 +213,14 @@ let commands () =
@@ stop) @@ stop)
begin fun force alias_name (_, manager_pkh) cctxt -> begin fun force alias_name (_, manager_pkh) cctxt ->
RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name -> RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name ->
faucet ~force ~manager_pkh cctxt#block cctxt () >>=? fun (oph, contract) -> faucet ~manager_pkh cctxt#block cctxt () >>=? fun (oph, contract) ->
operation_submitted_message cctxt operation_submitted_message cctxt
~force ~contracts:[contract] oph >>=? fun () -> ~contracts:[contract] oph >>=? fun () ->
save_contract ~force cctxt alias_name contract save_contract ~force cctxt alias_name contract
end; end;
command ~group ~desc: "transfer tokens" command ~group ~desc: "transfer tokens"
(args4 fee_arg arg_arg force_switch no_print_source_flag) (args3 fee_arg arg_arg no_print_source_flag)
(prefixes [ "transfer" ] (prefixes [ "transfer" ]
@@ tez_param @@ tez_param
~name: "qty" ~desc: "amount taken from source" ~name: "qty" ~desc: "amount taken from source"
@ -232,18 +231,18 @@ let commands () =
@@ ContractAlias.destination_param @@ ContractAlias.destination_param
~name: "dst" ~desc: "name/literal of the destination contract" ~name: "dst" ~desc: "name/literal of the destination contract"
@@ stop) @@ stop)
begin fun (fee, arg, force, no_print_source) amount (_, source) (_, destination) cctxt -> begin fun (fee, arg, no_print_source) amount (_, source) (_, destination) cctxt ->
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) -> source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
transfer ~force cctxt ~fee cctxt#block transfer cctxt ~fee cctxt#block
~source ~src_pk ~src_sk ~destination ~arg ~amount () >>= ~source ~src_pk ~src_sk ~destination ~arg ~amount () >>=
report_michelson_errors ~no_print_source ~msg:"transfer simulation failed" cctxt >>= function report_michelson_errors ~no_print_source ~msg:"transfer simulation failed" cctxt >>= function
| None -> return () | None -> return ()
| Some (oph, contracts) -> | Some (oph, contracts) ->
operation_submitted_message cctxt ~force ~contracts oph operation_submitted_message cctxt ~contracts oph
end; end;
command ~desc: "Activate a protocol" command ~desc: "Activate a protocol"
(args1 force_switch) no_options
(prefixes [ "activate" ; "protocol" ] (prefixes [ "activate" ; "protocol" ]
@@ Protocol_hash.param ~name:"version" @@ Protocol_hash.param ~name:"version"
~desc:"Protocol version (b58check)" ~desc:"Protocol version (b58check)"
@ -251,14 +250,14 @@ let commands () =
@@ Environment.Ed25519.Secret_key.param @@ Environment.Ed25519.Secret_key.param
~name:"password" ~desc:"Dictator's key" ~name:"password" ~desc:"Dictator's key"
@@ stop) @@ stop)
begin fun force hash seckey cctxt -> begin fun () hash seckey cctxt ->
dictate cctxt cctxt#block dictate cctxt cctxt#block
(Activate hash) seckey >>=? fun oph -> (Activate hash) seckey >>=? fun oph ->
operation_submitted_message cctxt ~force:force oph operation_submitted_message cctxt oph
end ; end ;
command ~desc: "Fork a test protocol" command ~desc: "Fork a test protocol"
(args1 force_switch) no_options
(prefixes [ "fork" ; "test" ; "protocol" ] (prefixes [ "fork" ; "test" ; "protocol" ]
@@ Protocol_hash.param ~name:"version" @@ Protocol_hash.param ~name:"version"
~desc:"Protocol version (b58check)" ~desc:"Protocol version (b58check)"
@ -266,10 +265,10 @@ let commands () =
@@ Environment.Ed25519.Secret_key.param @@ Environment.Ed25519.Secret_key.param
~name:"password" ~desc:"Dictator's key" ~name:"password" ~desc:"Dictator's key"
@@ stop) @@ stop)
begin fun force hash seckey cctxt -> begin fun () hash seckey cctxt ->
dictate cctxt cctxt#block dictate cctxt cctxt#block
(Activate_testnet hash) seckey >>=? fun oph -> (Activate_testnet hash) seckey >>=? fun oph ->
operation_submitted_message cctxt ~force:force oph operation_submitted_message cctxt oph
end ; end ;
] ]

View File

@ -758,7 +758,7 @@ let inject_operation =
prevalidation context." prevalidation context."
~query: RPC_query.empty ~query: RPC_query.empty
~input: ~input:
(obj4 (obj3
(req "signedOperationContents" (req "signedOperationContents"
(describe ~title: "Tezos signed operation (hex encoded)" (describe ~title: "Tezos signed operation (hex encoded)"
bytes)) bytes))
@ -769,13 +769,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 "net_id" Net_id.encoding))
(opt "force"
(describe
~description:
"Should we inject operation that are \"branch_refused\" \
or \"branch_delayed\". (default: false)"
bool)))
~output: ~output:
(Error.wrap @@ (Error.wrap @@
describe describe

View File

@ -267,7 +267,7 @@ val inject_block:
val inject_operation: val inject_operation:
([ `POST ], unit, ([ `POST ], unit,
unit, unit, (MBytes.t * bool * Net_id.t option * bool option), unit, unit, (MBytes.t * bool * Net_id.t option),
Operation_hash.t tzresult, unit) RPC_service.t Operation_hash.t tzresult, unit) RPC_service.t
val inject_protocol: val inject_protocol:

View File

@ -10,12 +10,12 @@
open Lwt.Infix open Lwt.Infix
open Logging.Node.Worker open Logging.Node.Worker
let inject_operation validator ?force ?net_id bytes = let inject_operation validator ?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 op -> | Some op ->
Validator.inject_operation validator ?force ?net_id op Validator.inject_operation validator ?net_id op
in 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)
@ -56,7 +56,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 -> ?net_id:Net_id.t -> MBytes.t -> ?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 -> ?net_id:Net_id.t -> MBytes.t -> t -> ?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

@ -420,9 +420,9 @@ let build_rpc_directory node =
end >>= RPC_answer.return in end >>= RPC_answer.return in
RPC_directory.register0 dir Services.inject_block implementation in RPC_directory.register0 dir Services.inject_block implementation in
let dir = let dir =
let implementation () (contents, blocking, net_id, force) = let implementation () (contents, blocking, net_id) =
Node.RPC.inject_operation Node.RPC.inject_operation
node ?force ?net_id contents >>= fun (hash, wait) -> node ?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

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

View File

@ -39,6 +39,5 @@ val watcher: t -> State.Block.t Lwt_stream.t * Lwt_watcher.stopper
val inject_operation: val inject_operation:
t -> t ->
?force:bool ->
?net_id:Net_id.t -> ?net_id:Net_id.t ->
Operation.t -> unit tzresult Lwt.t Operation.t -> unit tzresult Lwt.t