Client: less RPC call while waiting for confirmations
This commit is contained in:
parent
ca1d4158a7
commit
5c9f8f00f4
@ -25,16 +25,17 @@ let wait_for_operation_inclusion
|
|||||||
|
|
||||||
(* Fetch _all_ the 'unknown' predecessors af a block. *)
|
(* Fetch _all_ the 'unknown' predecessors af a block. *)
|
||||||
|
|
||||||
let fetch_predecessors (block, _) =
|
let fetch_predecessors (hash, header) =
|
||||||
let rec loop acc block =
|
let rec loop acc (_hash, header) =
|
||||||
Block_services.Empty.Header.shell_header
|
let predecessor = header.Block_header.predecessor in
|
||||||
ctxt ~chain ~block:(`Hash (block, 0)) () >>=? fun { predecessor } ->
|
|
||||||
if Block_hash.Table.mem blocks predecessor then
|
if Block_hash.Table.mem blocks predecessor then
|
||||||
return acc
|
return acc
|
||||||
else
|
else
|
||||||
loop (predecessor :: acc) predecessor
|
Chain_services.Blocks.Header.shell_header
|
||||||
in
|
ctxt ~chain ~block:(`Hash (predecessor, 0)) () >>=? fun shell ->
|
||||||
loop [block] block >>= function
|
let block = (predecessor, shell) in
|
||||||
|
loop (block :: acc) block in
|
||||||
|
loop [hash, header.Block_header.shell] (hash, header.shell) >>= function
|
||||||
| Ok blocks -> Lwt.return blocks
|
| Ok blocks -> Lwt.return blocks
|
||||||
| Error err ->
|
| Error err ->
|
||||||
ctxt#warning
|
ctxt#warning
|
||||||
@ -46,10 +47,9 @@ let wait_for_operation_inclusion
|
|||||||
(* Check whether a block as enough confirmations. This function
|
(* Check whether a block as enough confirmations. This function
|
||||||
assumes that the block predecessor has been processed already. *)
|
assumes that the block predecessor has been processed already. *)
|
||||||
|
|
||||||
let process block =
|
let process hash header =
|
||||||
Shell_services.Blocks.hash ctxt ~chain ~block () >>=? fun hash ->
|
let block = `Hash (hash, 0) in
|
||||||
Shell_services.Blocks.Header.shell_header
|
let predecessor = header.Tezos_base.Block_header.predecessor in
|
||||||
ctxt ~chain ~block () >>=? fun { predecessor } ->
|
|
||||||
match Block_hash.Table.find blocks predecessor with
|
match Block_hash.Table.find blocks predecessor with
|
||||||
| Some (block_with_op, n) ->
|
| Some (block_with_op, n) ->
|
||||||
ctxt#answer
|
ctxt#answer
|
||||||
@ -96,7 +96,11 @@ let wait_for_operation_inclusion
|
|||||||
| Some (head, _) ->
|
| Some (head, _) ->
|
||||||
let rec loop n =
|
let rec loop n =
|
||||||
if n >= 0 then
|
if n >= 0 then
|
||||||
process (`Hash (head, n)) >>=? function
|
let block = `Hash (head, n) in
|
||||||
|
Shell_services.Blocks.hash ctxt ~chain ~block () >>=? fun hash ->
|
||||||
|
Shell_services.Blocks.Header.shell_header ctxt
|
||||||
|
~chain ~block () >>=? fun shell ->
|
||||||
|
process hash shell >>=? function
|
||||||
| Some block ->
|
| Some block ->
|
||||||
stop () ;
|
stop () ;
|
||||||
return block
|
return block
|
||||||
@ -108,8 +112,8 @@ let wait_for_operation_inclusion
|
|||||||
(fun () ->
|
(fun () ->
|
||||||
let stream = Lwt_stream.map_list_s fetch_predecessors stream in
|
let stream = Lwt_stream.map_list_s fetch_predecessors stream in
|
||||||
Lwt_stream.find_s
|
Lwt_stream.find_s
|
||||||
(fun block ->
|
(fun (hash, header) ->
|
||||||
process (`Hash (block, 0)) >>= function
|
process hash header >>= function
|
||||||
| Ok None -> Lwt.return false
|
| Ok None -> Lwt.return false
|
||||||
| Ok (Some _) -> Lwt.return true
|
| Ok (Some _) -> Lwt.return true
|
||||||
| Error err ->
|
| Error err ->
|
||||||
@ -119,7 +123,7 @@ let wait_for_operation_inclusion
|
|||||||
| exn -> Lwt.fail exn) >>=? function
|
| exn -> Lwt.fail exn) >>=? function
|
||||||
| None ->
|
| None ->
|
||||||
failwith "..."
|
failwith "..."
|
||||||
| Some hash ->
|
| Some (hash, _) ->
|
||||||
stop () ;
|
stop () ;
|
||||||
match Block_hash.Table.find_opt blocks hash with
|
match Block_hash.Table.find_opt blocks hash with
|
||||||
| None | Some None -> assert false
|
| None | Some None -> assert false
|
||||||
|
Loading…
Reference in New Issue
Block a user