From 0c467d86af3b9d8c41581bc996ab437b4f1014c2 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Fri, 7 Mar 2025 16:34:14 +0100 Subject: [PATCH] Floodgate: Report observed TPS every 60s --- etherlink/bin_floodgate/floodgate.ml | 19 +++++++++++++++++-- etherlink/bin_floodgate/floodgate_events.ml | 15 +++++++++++++++ etherlink/bin_floodgate/floodgate_events.mli | 5 +++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/etherlink/bin_floodgate/floodgate.ml b/etherlink/bin_floodgate/floodgate.ml index 73eef2d9c4a4..53d52ec77920 100644 --- a/etherlink/bin_floodgate/floodgate.ml +++ b/etherlink/bin_floodgate/floodgate.ml @@ -57,6 +57,19 @@ let send_transaction_and_wait ~infos ~gas_limit ~from ~to_ ~value = in result +let transactions_count = ref 0 + +let rec report_tps () = + let open Lwt_syntax in + let start = Time.System.now () in + transactions_count := 0 ; + let* () = Lwt_unix.sleep 60. in + let stop = Time.System.now () in + let* () = + Floodgate_events.measured_tps !transactions_count (Ptime.diff stop start) + in + report_tps () + let rec spam_with_account ~token ~infos ~gas_limit account = let open Lwt_syntax in let start = ref (Time.System.now ()) in @@ -293,7 +306,9 @@ let run ~scenario ~relay_endpoint ~rpc_endpoint ~controller ~max_active_eoa let*! () = Floodgate_events.received_blueprint number in let* () = match Blueprint_decoder.transaction_hashes blueprint with - | Ok hashes -> List.iter_es Tx_queue.confirm hashes + | Ok hashes -> + transactions_count := !transactions_count + List.length hashes ; + List.iter_es Tx_queue.confirm hashes | Error _ -> return_unit in return `Continue) @@ -324,5 +339,5 @@ let run ~scenario ~relay_endpoint ~rpc_endpoint ~controller ~max_active_eoa (Seq.ints 0 |> Stdlib.Seq.take max_active_eoa) in Lwt_result.ok (Floodgate_events.setup_completed ()) - in + and* () = report_tps () in return_unit diff --git a/etherlink/bin_floodgate/floodgate_events.ml b/etherlink/bin_floodgate/floodgate_events.ml index af09740786dd..db563167e2a3 100644 --- a/etherlink/bin_floodgate/floodgate_events.ml +++ b/etherlink/bin_floodgate/floodgate_events.ml @@ -122,6 +122,17 @@ let deploy_erc20 = ~level:Notice ("address", Data_encoding.string) +let measured_tps = + declare_2 + ~alternative_color:Green + ~section + ~name:"measured_tps" + ~msg:"measured {tps} transactions per second over the past {duration}" + ~level:Notice + ~pp2:Ptime.Span.pp + ("tps", Data_encoding.float) + ("duration", Time.System.Span.encoding) + let rpc_error = declare_2 ~section @@ -162,3 +173,7 @@ let deploy_erc20 address = emit deploy_erc20 address let rpc_error (error : Rpc_encodings.JSONRPC.error) = emit rpc_error (Int32.of_int error.code, error.message) + +let measured_tps transactions_count duration = + let tps = Float.of_int transactions_count /. Ptime.Span.to_float_s duration in + emit measured_tps (tps, duration) diff --git a/etherlink/bin_floodgate/floodgate_events.mli b/etherlink/bin_floodgate/floodgate_events.mli index 97bec6f33e05..ce4a59524673 100644 --- a/etherlink/bin_floodgate/floodgate_events.mli +++ b/etherlink/bin_floodgate/floodgate_events.mli @@ -58,3 +58,8 @@ val deploy_erc20 : string -> unit Lwt.t (** [rpc_error error] advertises an RPC produced the error [error]. *) val rpc_error : Rpc_encodings.JSONRPC.error -> unit Lwt.t + +(** [measured_tps transactions_count duration] advertises that Floodgate has + been able to inject [transaction_counts] transactions over the given + [duration]. *) +val measured_tps : int -> Ptime.span -> unit Lwt.t -- GitLab