diff --git a/etherlink/bin_floodgate/floodgate.ml b/etherlink/bin_floodgate/floodgate.ml index 73eef2d9c4a4cd470e825af9261c649c99fca79c..53d52ec779201433142e02fa49001a378f77df62 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 af09740786dd9e2a61fa865a4698e41e4d209226..db563167e2a33d6ab7fa2c3d24a0298b32a27df7 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 97bec6f33e0563b81d8e1c30024a6917a18b4b35..ce4a59524673439a825ae99bf225fd45f76dbd74 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