Closed rodrigo-pino closed 2 weeks ago
@rodrigo-pino Just to clarify, there is actually no sorting involved right? The comparison here is on indices to produce a list of comparison results of size union(base, native)
@marcuspang no sorting involved. The transactions are already "sorted" in the sense that they are presented in order of execution. We take that assumption as true.
Also, please write some unit tests for these as well. Try to find an elegant and simple solution, there is no urgency for this task at the moment.
Problem
Function
generate_block_comparison
will compare two list of transaction traces. This two list has always matched but it would be good to have the extra safety that we make sure we are comparing the same pair of transactions.If any of the list has a different transaction, or missing ones it can make results unreadable, something that can be fixed by smartly pairing them.
For example, having these transactions from base:
and these ones from native:
will result in:
Which doesn't reflect that "tx 3" is present in both blocks. See example 2 for what would be the ideal output.
Solution
Let's use the sorting mechanism to make the outputs a little clearer.
If there is a transaction
i
both present in native and base, they both should be compared.If there is a transaction
j
present in base but not in native and there is a transactioni
that is present in both, such thati > j
, then the comparison result ofj
(with Empty) should come beforei
. This same case applies for a transactionj
in native and not in base.If there is a transaction
j
present in base but not in native, and it does not exist any transactioni
withi > j
equal for both native and base. Then you should first compare all transactions>= j
from base with Empty. After that, compare all remaining transactions from native with Empty.Example 1
Base transactions:
Native transaction:
Comparison result:
Example 2
Base transactions:
Native transaction:
Comparison result:
Example 3
Base transactions:
Native transaction:
Comparison result:
Example 4
Base transactions:
Native transaction:
Comparison result: