Measure time of execution of a MultiversX 's transaction

92 views Asked by At

I'm sending transactions using Python 3 and mxpy. When the transaction ends with status "success", I have in the transaction's data a timestamp that I think it is the time the transactions entered the blockchain. But, is there a way to know another timestamp with the time that the transaction was resolved?

I want to know how much time took to process a single transaction.

1

There are 1 answers

0
Brother Jder On

I would say that (at the moment I write this) computation of the processing time for a transaction is not a trivial task to perform. The reason why this is happening is because of sharding and how processing can happen cross-shard. The rough idea (as far as I understand it) is the following:

  1. retrieve the timestamp of the source shard block the transaction was first published on
  2. retrieve the timestamp of the destination shard block the transaction or the last SC Result was last published on
  3. subtract the two

You have to note the fact that a transaction can vary widely in terms of what it is purposed for. It can range from a simple value transfer from one account to another, intra-shard or cross-shard, to crazy daisy-chained operations like a Smart Contract call that in turn might call another Smart Contract and each of these might be generating Smart Contract Results which have to propagate back in a similar way a simple transaction would (these are basically also transactions). So you have to calculate from the first timestamp (usually the timestamp of the first block that included the transaction on the sender shard) all the way to the timestamp of the destination block that included the last event the transaction processing triggered.

Technical-wise, you would have to dig for those blocks via several tx data parses, cross the data between these different hashes and I believe it would go something like this:

  1. Starting from your tx hash, find the miniblock hash the tx was included in
  2. Go to the NotarizedAtSourceInMetaHash and look for the the block that included your miniblock hash inside and get its timestamp. This would be the time your transaction started its execution flow.
  3. Go to the notarizedAtDestinationInMetaHash and look for the block that included your miniblock hash inside and get the final timestamp that you should use to subtract the first timestamp from. If the Transaction has SCResults, then you have to take the notarizedAtDestinationInMetaHash of the latest produced SCResult and look for the block that includes that SCResult's hash. This would be then the last timestamp you should subtract from.

Also take this info with a bit of salt, as I'm not 100% confident that this is the right approach to do this calculation.